extensions/tf2/extension.cpp
changeset 2619 1c0acf43cc0c
parent 2600 f78e5656cc6f
child 2783 5f333027ef04
     1.1 --- a/extensions/tf2/extension.cpp	Thu Feb 26 12:42:59 2009 +1300
     1.2 +++ b/extensions/tf2/extension.cpp	Fri Feb 27 10:19:46 2009 +1300
     1.3 @@ -102,12 +102,16 @@
     1.4  	sharesys->AddNatives(myself, g_TFNatives);
     1.5  	sharesys->RegisterLibrary(myself, "tf2");
     1.6  
     1.7 +	plsys->AddPluginsListener(this);
     1.8 +
     1.9  	playerhelpers->RegisterCommandTargetProcessor(this);
    1.10  
    1.11  	g_critForward = forwards->CreateForward("TF2_CalcIsAttackCritical", ET_Hook, 4, NULL, Param_Cell, Param_Cell, Param_String, Param_CellByRef);
    1.12  
    1.13  	g_pCVar = icvar;
    1.14  
    1.15 +	m_DetoursEnabled = false;
    1.16 +
    1.17  	return true;
    1.18  }
    1.19  
    1.20 @@ -137,16 +141,14 @@
    1.21  	gameconfs->CloseGameConfigFile(g_pGameConf);
    1.22  	playerhelpers->UnregisterCommandTargetProcessor(this);
    1.23  
    1.24 -	forwards->ReleaseForward(g_critForward);
    1.25 +	plsys->RemovePluginsListener(this);
    1.26  
    1.27 -	RemoveDetours();
    1.28 +	forwards->ReleaseForward(g_critForward);
    1.29  }
    1.30  
    1.31  void TF2Tools::SDK_OnAllLoaded()
    1.32  {
    1.33  	SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
    1.34 -
    1.35 -	InitialiseDetours();
    1.36  }
    1.37  
    1.38  bool TF2Tools::RegisterConCommandBase(ConCommandBase *pVar)
    1.39 @@ -187,7 +189,6 @@
    1.40  	g_resourceEntity = FindResourceEntity();
    1.41  }
    1.42  
    1.43 -
    1.44  bool TF2Tools::ProcessCommandTarget(cmd_target_info_t *info)
    1.45  {
    1.46  	int max_clients;
    1.47 @@ -283,6 +284,23 @@
    1.48  	return true;
    1.49  }
    1.50  
    1.51 +void TF2Tools::OnPluginLoaded(IPlugin *plugin)
    1.52 +{
    1.53 +	if (!m_DetoursEnabled && g_critForward->GetFunctionCount())
    1.54 +	{
    1.55 +		InitialiseDetours();
    1.56 +		m_DetoursEnabled = true;
    1.57 +	}
    1.58 +}
    1.59 +
    1.60 +void TF2Tools::OnPluginUnloaded(IPlugin *plugin)
    1.61 +{
    1.62 +	if (m_DetoursEnabled && !g_critForward->GetFunctionCount())
    1.63 +	{
    1.64 +		RemoveDetours();
    1.65 +		m_DetoursEnabled = false;
    1.66 +	}
    1.67 +}
    1.68  int FindResourceEntity()
    1.69  {
    1.70  	return FindEntityByNetClass(-1, "CTFPlayerResource");