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
This commit is contained in:
Mikusch 2022-04-22 11:49:46 +02:00 committed by GitHub
parent a877a4475b
commit a1ad9e1acf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 9 deletions

View File

@ -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)

View File

@ -57,7 +57,7 @@ private:
bool IsHookEnabled() const { return m_iHookID != 0; }
void *GetGameRules();
void HookIfNecessary();
void UnhookIfNecessary();
void Unhook();
private:
int m_iHookID;