From a1ad9e1acff49c26d17f72a61e11edfa30a67c37 Mon Sep 17 00:00:00 2001 From: Mikusch Date: Fri, 22 Apr 2022 11:49:46 +0200 Subject: [PATCH] Fix TF2_OnIsHolidayActive forward not getting called after map change (#1752) * Fix TF2_IsHolidayActive forward not getting called after map change * Rename function to Unhook --- extensions/tf2/holiday.cpp | 16 ++++++++-------- extensions/tf2/holiday.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/extensions/tf2/holiday.cpp b/extensions/tf2/holiday.cpp index 714858cf..282b5ea9 100644 --- a/extensions/tf2/holiday.cpp +++ b/extensions/tf2/holiday.cpp @@ -55,7 +55,7 @@ void HolidayManager::OnSDKLoad(bool bLate) void HolidayManager::OnSDKUnload() { - UnhookIfNecessary(); + Unhook(); SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &HolidayManager::Hook_LevelShutdown), false); plsys->RemovePluginsListener(this); @@ -72,7 +72,7 @@ void HolidayManager::OnServerActivated() void HolidayManager::Hook_LevelShutdown() { // GameRules is going away momentarily. Unhook before it does. - UnhookIfNecessary(); + Unhook(); m_bInMap = false; } @@ -112,16 +112,12 @@ void HolidayManager::HookIfNecessary() m_iHookID = SH_ADD_MANUALHOOK(IsHolidayActive, pGameRules, SH_MEMBER(this, &HolidayManager::Hook_IsHolidayActive), false); } -void HolidayManager::UnhookIfNecessary() +void HolidayManager::Unhook() { // Not hooked if (!m_iHookID) return; - // We're still wanted - if (m_isHolidayForward->GetFunctionCount() > 0) - return; - SH_REMOVE_HOOK_ID(m_iHookID); m_iHookID = 0; } @@ -165,7 +161,11 @@ void HolidayManager::OnPluginLoaded(IPlugin *plugin) void HolidayManager::OnPluginUnloaded(IPlugin *plugin) { - UnhookIfNecessary(); + // We're still wanted + if (m_isHolidayForward->GetFunctionCount() > 0) + return; + + Unhook(); } bool HolidayManager::Hook_IsHolidayActive(int holiday) diff --git a/extensions/tf2/holiday.h b/extensions/tf2/holiday.h index 7457b7d6..f0e357dc 100644 --- a/extensions/tf2/holiday.h +++ b/extensions/tf2/holiday.h @@ -57,7 +57,7 @@ private: bool IsHookEnabled() const { return m_iHookID != 0; } void *GetGameRules(); void HookIfNecessary(); - void UnhookIfNecessary(); + void Unhook(); private: int m_iHookID;