diff -r a022964a0803 -r 1c0acf43cc0c extensions/tf2/extension.cpp --- a/extensions/tf2/extension.cpp Thu Feb 26 12:42:59 2009 +1300 +++ b/extensions/tf2/extension.cpp Fri Feb 27 10:19:46 2009 +1300 @@ -102,12 +102,16 @@ sharesys->AddNatives(myself, g_TFNatives); sharesys->RegisterLibrary(myself, "tf2"); + plsys->AddPluginsListener(this); + playerhelpers->RegisterCommandTargetProcessor(this); g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef); g_pCVar = icvar; + m_DetoursEnabled = false; + return true; } @@ -137,16 +141,14 @@ gameconfs->CloseGameConfigFile(g_pGameConf); playerhelpers->UnregisterCommandTargetProcessor(this); - forwards->ReleaseForward(g_critForward); + plsys->RemovePluginsListener(this); - RemoveDetours(); + forwards->ReleaseForward(g_critForward); } void TF2Tools::SDK_OnAllLoaded() { SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools); - - InitialiseDetours(); } bool TF2Tools::RegisterConCommandBase(ConCommandBase *pVar) @@ -187,7 +189,6 @@ g_resourceEntity = FindResourceEntity(); } - bool TF2Tools::ProcessCommandTarget(cmd_target_info_t *info) { int max_clients; @@ -283,6 +284,23 @@ return true; } +void TF2Tools::OnPluginLoaded(IPlugin *plugin) +{ + if (!m_DetoursEnabled && g_critForward->GetFunctionCount()) + { + InitialiseDetours(); + m_DetoursEnabled = true; + } +} + +void TF2Tools::OnPluginUnloaded(IPlugin *plugin) +{ + if (m_DetoursEnabled && !g_critForward->GetFunctionCount()) + { + RemoveDetours(); + m_DetoursEnabled = false; + } +} int FindResourceEntity() { return FindEntityByNetClass(-1, "CTFPlayerResource");