SDKTools: Clear gamerules pointer on level shutdown (#1755)

* Clear gamerules pointer on level shutdown

* Move LevelShutdown up
This commit is contained in:
Mikusch 2022-04-22 11:48:21 +02:00 committed by GitHub
parent 441259e36a
commit a877a4475b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 0 deletions

View File

@ -54,6 +54,7 @@
*/
SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
#if SOURCE_ENGINE == SE_CSS || SOURCE_ENGINE == SE_CSGO
SH_DECL_HOOK1_void_vafmt(IVEngineServer, ClientCommand, SH_NOATTRIB, 0, edict_t *);
#endif
@ -174,6 +175,7 @@ bool SDKTools::SDK_OnLoad(char *error, size_t maxlength, bool late)
CONVAR_REGISTER(this);
SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SDKTools::LevelInit), true);
SH_ADD_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SDKTools::LevelShutdown), true);
playerhelpers->RegisterCommandTargetProcessor(this);
@ -274,6 +276,7 @@ void SDKTools::SDK_OnUnload()
plsys->RemovePluginsListener(&g_OutputManager);
SH_REMOVE_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SDKTools::LevelInit), true);
SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SDKTools::LevelShutdown), true);
if (enginePatch)
{
@ -447,6 +450,11 @@ bool SDKTools::LevelInit(char const *pMapName, char const *pMapEntities, char co
RETURN_META_VALUE(MRES_IGNORED, true);
}
void SDKTools::LevelShutdown()
{
ClearValveGlobals();
}
bool SDKTools::ProcessCommandTarget(cmd_target_info_t *info)
{
IGamePlayer *pAdmin = info->admin ? playerhelpers->GetGamePlayer(info->admin) : NULL;

View File

@ -131,6 +131,7 @@ public: //ICommandTargetProcessor
bool ProcessCommandTarget(cmd_target_info_t *info);
public:
bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
void LevelShutdown();
void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax);
public:
bool HasAnyLevelInited() { return m_bAnyLevelInited; }

View File

@ -151,6 +151,11 @@ void UpdateValveGlobals()
}
}
void ClearValveGlobals()
{
s_pGameRules = nullptr;
}
size_t UTIL_StringToSignature(const char *str, char buffer[], size_t maxlength)
{
size_t real_bytes = 0;

View File

@ -38,6 +38,7 @@ extern CBaseHandle g_ResourceEntity;
void InitializeValveGlobals();
void UpdateValveGlobals();
void ClearValveGlobals();
void GetIServer();
void *GameRules();