From a877a4475b713bd7ba6bc6551829b7ded051aab6 Mon Sep 17 00:00:00 2001 From: Mikusch Date: Fri, 22 Apr 2022 11:48:21 +0200 Subject: [PATCH] SDKTools: Clear gamerules pointer on level shutdown (#1755) * Clear gamerules pointer on level shutdown * Move LevelShutdown up --- extensions/sdktools/extension.cpp | 8 ++++++++ extensions/sdktools/extension.h | 1 + extensions/sdktools/vglobals.cpp | 5 +++++ extensions/sdktools/vglobals.h | 1 + 4 files changed, 15 insertions(+) diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index 889fe0c4..5be699f9 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -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; diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index 4e28514e..78088b09 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -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; } diff --git a/extensions/sdktools/vglobals.cpp b/extensions/sdktools/vglobals.cpp index 41bb042a..6d9d2c3f 100644 --- a/extensions/sdktools/vglobals.cpp +++ b/extensions/sdktools/vglobals.cpp @@ -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; diff --git a/extensions/sdktools/vglobals.h b/extensions/sdktools/vglobals.h index 1b6e045f..2a893f02 100644 --- a/extensions/sdktools/vglobals.h +++ b/extensions/sdktools/vglobals.h @@ -38,6 +38,7 @@ extern CBaseHandle g_ResourceEntity; void InitializeValveGlobals(); void UpdateValveGlobals(); +void ClearValveGlobals(); void GetIServer(); void *GameRules();