Added checks to avoid crashing in some natives before map start (bug 5119, r=fyren).
authorNicholas Hastings <skamonkey@gmail.com>
Tue Oct 11 22:50:21 2011 -0400 (2011-10-11)
changeset 340198f3a34c1396
parent 3400 6e39456566fe
child 3402 a459183ce707
Added checks to avoid crashing in some natives before map start (bug 5119, r=fyren).
core/PluginSys.cpp
core/smn_halflife.cpp
core/sourcemod.cpp
core/sourcemod.h
extensions/sdktools/vnatives.cpp
public/ISourceMod.h
     1.1 --- a/core/PluginSys.cpp	Tue Oct 11 19:50:53 2011 -0400
     1.2 +++ b/core/PluginSys.cpp	Tue Oct 11 22:50:21 2011 -0400
     1.3 @@ -372,7 +372,7 @@
     1.4  		pFunction->Execute(&result);
     1.5  	}
     1.6  
     1.7 -	if (g_OnMapStarted)
     1.8 +	if (g_SourceMod.IsMapRunning())
     1.9  	{
    1.10  		if ((pFunction = m_pRuntime->GetFunctionByName("OnMapStart")) != NULL)
    1.11  		{
     2.1 --- a/core/smn_halflife.cpp	Tue Oct 11 19:50:53 2011 -0400
     2.2 +++ b/core/smn_halflife.cpp	Tue Oct 11 22:50:21 2011 -0400
     2.3 @@ -89,6 +89,11 @@
     2.4  
     2.5  static cell_t CreateFakeClient(IPluginContext *pContext, const cell_t *params)
     2.6  {
     2.7 +	if (!g_SourceMod.IsMapRunning())
     2.8 +	{
     2.9 +		return pContext->ThrowNativeError("Cannot create fakeclient when no map is active");
    2.10 +	}
    2.11 +
    2.12  	char *netname;
    2.13  
    2.14  	pContext->LocalToString(params[1], &netname);
     3.1 --- a/core/sourcemod.cpp	Tue Oct 11 19:50:53 2011 -0400
     3.2 +++ b/core/sourcemod.cpp	Tue Oct 11 22:50:21 2011 -0400
     3.3 @@ -745,5 +745,10 @@
     3.4  	return api;
     3.5  }
     3.6  
     3.7 +bool SourceModBase::IsMapRunning()
     3.8 +{
     3.9 +	return g_OnMapStarted;
    3.10 +}
    3.11 +
    3.12  SMGlobalClass *SMGlobalClass::head = NULL;
    3.13  
     4.1 --- a/core/sourcemod.h	Tue Oct 11 19:50:53 2011 -0400
     4.2 +++ b/core/sourcemod.h	Tue Oct 11 22:50:21 2011 -0400
     4.3 @@ -135,6 +135,7 @@
     4.4  	const char *GetCoreConfigValue(const char *key);
     4.5  	int GetPluginId();
     4.6  	int GetShApiVersion();
     4.7 +	bool IsMapRunning();
     4.8  private:
     4.9  	CStack<CDataPack *> m_freepacks;
    4.10  	char m_SMBaseDir[PLATFORM_MAX_PATH];
     5.1 --- a/extensions/sdktools/vnatives.cpp	Tue Oct 11 19:50:53 2011 -0400
     5.2 +++ b/extensions/sdktools/vnatives.cpp	Tue Oct 11 22:50:21 2011 -0400
     5.3 @@ -760,6 +760,11 @@
     5.4  #if SOURCE_ENGINE >= SE_ORANGEBOX
     5.5  static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
     5.6  {
     5.7 +	if (!g_pSM->IsMapRunning())
     5.8 +	{
     5.9 +		return pContext->ThrowNativeError("Cannot create new entity when no map is running");
    5.10 +	}
    5.11 +
    5.12  	char *classname;
    5.13  	pContext->LocalToString(params[1], &classname);
    5.14  	CBaseEntity *pEntity = (CBaseEntity *)servertools->CreateEntityByName(classname);
    5.15 @@ -768,6 +773,11 @@
    5.16  #else
    5.17  static cell_t CreateEntityByName(IPluginContext *pContext, const cell_t *params)
    5.18  {
    5.19 +	if (!g_pSM->IsMapRunning())
    5.20 +	{
    5.21 +		return pContext->ThrowNativeError("Cannot create new entity when no map is running");
    5.22 +	}
    5.23 +
    5.24  	static ValveCall *pCall = NULL;
    5.25  	if (!pCall)
    5.26  	{
     6.1 --- a/public/ISourceMod.h	Tue Oct 11 19:50:53 2011 -0400
     6.2 +++ b/public/ISourceMod.h	Tue Oct 11 22:50:21 2011 -0400
     6.3 @@ -43,7 +43,7 @@
     6.4  #include <time.h>
     6.5  
     6.6  #define SMINTERFACE_SOURCEMOD_NAME		"ISourceMod"
     6.7 -#define SMINTERFACE_SOURCEMOD_VERSION	12
     6.8 +#define SMINTERFACE_SOURCEMOD_VERSION	13
     6.9  
    6.10  /**
    6.11  * @brief Forward declaration of the KeyValues class.
    6.12 @@ -311,6 +311,13 @@
    6.13  		 * @return			SourceHook API version number.
    6.14  		 */
    6.15  		virtual int GetShApiVersion() = 0;
    6.16 +
    6.17 +		/**
    6.18 +		 * @brief Returns whether or not a map is currently running.
    6.19 +		 *
    6.20 +		 * @return			True if a map is currently running, otherwise false.
    6.21 +		 */
    6.22 +		virtual bool IsMapRunning() = 0;
    6.23  	};
    6.24  }
    6.25