From 7f2fdf3fe198978c9012624f00ae829c99e7332e Mon Sep 17 00:00:00 2001 From: Asher Baker Date: Sat, 17 Jul 2021 18:09:23 +0100 Subject: [PATCH] Add OnMapInit forward and deprecate OnLevelInit The change in behaviour to the OnLevelInit forward params isn't obvious when compiling a plugin, deprecate it to make it a lot more obvious that something has changed. Some plugins rely just on the timing of OnLevelInit rather than doing anything with the entity lump, for these plugins offer a new OnMapInit forward that is implemented in core rather than sdkhooks. If / when we offer a new entity lump manipulation API in the future this'll be the forward where it can be used to make changes. --- core/sourcemod.cpp | 26 +++++++++++++++++++++----- plugins/include/sdkhooks.inc | 1 + plugins/include/sourcemod.inc | 10 +++++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index 3af647a8..eb55ed75 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -63,7 +63,8 @@ ISourcePawnEngine *g_pSourcePawn = NULL; ISourcePawnEngine2 *g_pSourcePawn2 = NULL; ISourcePawnEnvironment *g_pPawnEnv = NULL; IdentityToken_t *g_pCoreIdent = NULL; -IForward *g_pOnMapEnd = NULL; +IForward *g_pOnMapInit = nullptr; +IForward *g_pOnMapEnd = nullptr; IGameConfig *g_pGameConf = NULL; bool g_Loaded = false; bool sm_show_debug_spew = false; @@ -403,6 +404,11 @@ bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, ch pBase = pBase->m_pGlobalClassNext; } + if (!g_pOnMapInit) + { + g_pOnMapInit = forwardsys->CreateForward("OnMapInit", ET_Ignore, 1, NULL, Param_String); + } + if (!g_pOnMapEnd) { g_pOnMapEnd = forwardsys->CreateForward("OnMapEnd", ET_Ignore, 0, NULL); @@ -410,6 +416,9 @@ bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, ch g_LevelEndBarrier = true; + g_pOnMapInit->PushString(pMapName); + g_pOnMapInit->Execute(); + RETURN_META_VALUE(MRES_IGNORED, true); } @@ -424,10 +433,8 @@ void SourceModBase::LevelShutdown() next = next->m_pGlobalClassNext; } - if (g_pOnMapEnd != NULL) - { - g_pOnMapEnd->Execute(NULL); - } + g_pOnMapEnd->Execute(); + extsys->CallOnCoreMapEnd(); g_Timers.RemoveMapChangeTimers(); @@ -548,8 +555,17 @@ void SourceModBase::ShutdownServices() /* Unload extensions */ extsys->Shutdown(); + if (g_pOnMapInit) + { + forwardsys->ReleaseForward(g_pOnMapInit); + g_pOnMapInit = nullptr; + } + if (g_pOnMapEnd) + { forwardsys->ReleaseForward(g_pOnMapEnd); + g_pOnMapEnd = nullptr; + } /* Notify! */ SMGlobalClass *pBase = SMGlobalClass::head; diff --git a/plugins/include/sdkhooks.inc b/plugins/include/sdkhooks.inc index a2508b1b..ca163fad 100644 --- a/plugins/include/sdkhooks.inc +++ b/plugins/include/sdkhooks.inc @@ -382,6 +382,7 @@ forward Action OnGetGameDescription(char gameDesc[64]); * @param mapEntities Unused, always empty * @return Unused, return value is ignored */ +#pragma deprecated Use OnMapInit() instead forward Action OnLevelInit(const char[] mapName, char mapEntities[2097152]); /** diff --git a/plugins/include/sourcemod.inc b/plugins/include/sourcemod.inc index 71262d7d..37137a67 100644 --- a/plugins/include/sourcemod.inc +++ b/plugins/include/sourcemod.inc @@ -182,10 +182,14 @@ forward void OnPluginPauseChange(bool pause); forward void OnGameFrame(); /** - * Called when the map is loaded. + * Called when the map starts loading. * - * @note This used to be OnServerLoad(), which is now deprecated. - * Plugins still using the old forward will work. + * @param mapName Name of the map + */ +forward void OnMapInit(const char[] mapName); + +/** + * Called when the map is loaded. */ forward void OnMapStart();