Added checks to avoid crashing in some natives before map start (bug 5119, r=fyren).

This commit is contained in:
Nicholas Hastings 2011-10-11 22:50:21 -04:00
parent 45f68840ed
commit 67163e14e6
6 changed files with 30 additions and 2 deletions

View File

@ -372,7 +372,7 @@ void CPlugin::Call_OnAllPluginsLoaded()
pFunction->Execute(&result); pFunction->Execute(&result);
} }
if (g_OnMapStarted) if (g_SourceMod.IsMapRunning())
{ {
if ((pFunction = m_pRuntime->GetFunctionByName("OnMapStart")) != NULL) if ((pFunction = m_pRuntime->GetFunctionByName("OnMapStart")) != NULL)
{ {

View File

@ -89,6 +89,11 @@ static cell_t GetGameTime(IPluginContext *pContext, const cell_t *params)
static cell_t CreateFakeClient(IPluginContext *pContext, const cell_t *params) static cell_t CreateFakeClient(IPluginContext *pContext, const cell_t *params)
{ {
if (!g_SourceMod.IsMapRunning())
{
return pContext->ThrowNativeError("Cannot create fakeclient when no map is active");
}
char *netname; char *netname;
pContext->LocalToString(params[1], &netname); pContext->LocalToString(params[1], &netname);

View File

@ -745,5 +745,10 @@ int SourceModBase::GetShApiVersion()
return api; return api;
} }
bool SourceModBase::IsMapRunning()
{
return g_OnMapStarted;
}
SMGlobalClass *SMGlobalClass::head = NULL; SMGlobalClass *SMGlobalClass::head = NULL;

View File

@ -135,6 +135,7 @@ public: // ISourceMod
const char *GetCoreConfigValue(const char *key); const char *GetCoreConfigValue(const char *key);
int GetPluginId(); int GetPluginId();
int GetShApiVersion(); int GetShApiVersion();
bool IsMapRunning();
private: private:
CStack<CDataPack *> m_freepacks; CStack<CDataPack *> m_freepacks;
char m_SMBaseDir[PLATFORM_MAX_PATH]; char m_SMBaseDir[PLATFORM_MAX_PATH];

View File

@ -760,6 +760,11 @@ static cell_t FindEntityByClassname(IPluginContext *pContext, const cell_t *para
#if SOURCE_ENGINE >= SE_ORANGEBOX #if SOURCE_ENGINE >= SE_ORANGEBOX
static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params) static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
{ {
if (!g_pSM->IsMapRunning())
{
return pContext->ThrowNativeError("Cannot create new entity when no map is running");
}
char *classname; char *classname;
pContext->LocalToString(params[1], &classname); pContext->LocalToString(params[1], &classname);
CBaseEntity *pEntity = (CBaseEntity *)servertools->CreateEntityByName(classname); CBaseEntity *pEntity = (CBaseEntity *)servertools->CreateEntityByName(classname);
@ -768,6 +773,11 @@ static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
#else #else
static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params) static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
{ {
if (!g_pSM->IsMapRunning())
{
return pContext->ThrowNativeError("Cannot create new entity when no map is running");
}
static ValveCall *pCall = NULL; static ValveCall *pCall = NULL;
if (!pCall) if (!pCall)
{ {

View File

@ -43,7 +43,7 @@
#include <time.h> #include <time.h>
#define SMINTERFACE_SOURCEMOD_NAME "ISourceMod" #define SMINTERFACE_SOURCEMOD_NAME "ISourceMod"
#define SMINTERFACE_SOURCEMOD_VERSION 12 #define SMINTERFACE_SOURCEMOD_VERSION 13
/** /**
* @brief Forward declaration of the KeyValues class. * @brief Forward declaration of the KeyValues class.
@ -311,6 +311,13 @@ namespace SourceMod
* @return SourceHook API version number. * @return SourceHook API version number.
*/ */
virtual int GetShApiVersion() = 0; virtual int GetShApiVersion() = 0;
/**
* @brief Returns whether or not a map is currently running.
*
* @return True if a map is currently running, otherwise false.
*/
virtual bool IsMapRunning() = 0;
}; };
} }