extensions/sdktools/hooks.cpp
changeset 3084 db8d1162e9cf
parent 2910 e8f6e9f3401a
child 3344 9007dacc012d
     1.1 --- a/extensions/sdktools/hooks.cpp	Thu Jul 15 15:19:14 2010 -0500
     1.2 +++ b/extensions/sdktools/hooks.cpp	Sun Jul 18 15:43:56 2010 -0400
     1.3 @@ -34,6 +34,7 @@
     1.4  
     1.5  CHookManager g_Hooks;
     1.6  static bool PRCH_enabled = false;
     1.7 +static bool PRCH_used = false;
     1.8  
     1.9  SH_DECL_MANUALHOOK2_void(PlayerRunCmdHook, 0, 0, 0, CUserCmd *, IMoveHelper *);
    1.10  
    1.11 @@ -51,12 +52,16 @@
    1.12  		PRCH_enabled = true;
    1.13  	}
    1.14  
    1.15 +	plsys->AddPluginsListener(this);
    1.16 +
    1.17  	m_usercmdsFwd = forwards->CreateForward("OnPlayerRunCmd", ET_Event, 6, NULL, Param_Cell, Param_CellByRef, Param_CellByRef, Param_Array, Param_Array, Param_CellByRef);
    1.18  }
    1.19  
    1.20  void CHookManager::Shutdown()
    1.21  {
    1.22  	forwards->ReleaseForward(m_usercmdsFwd);
    1.23 +
    1.24 +	plsys->RemovePluginsListener(this);
    1.25  }
    1.26  
    1.27  void CHookManager::OnClientPutInServer(int client)
    1.28 @@ -64,6 +69,9 @@
    1.29  	if (!PRCH_enabled)
    1.30  		return;
    1.31  
    1.32 +	if (!PRCH_used)
    1.33 +		return;
    1.34 +
    1.35  	edict_t *pEdict = PEntityOfEntIndex(client);
    1.36  	if (!pEdict)
    1.37  	{
    1.38 @@ -90,6 +98,9 @@
    1.39  	if (!PRCH_enabled)
    1.40  		return;
    1.41  
    1.42 +	if (!PRCH_used)
    1.43 +		return;
    1.44 +
    1.45  	edict_t *pEdict = PEntityOfEntIndex(client);
    1.46  	if (!pEdict)
    1.47  	{
    1.48 @@ -165,3 +176,49 @@
    1.49  
    1.50  	RETURN_META(MRES_IGNORED);
    1.51  }
    1.52 +
    1.53 +void CHookManager::OnPluginLoaded(IPlugin *plugin)
    1.54 +{
    1.55 +	if (!PRCH_enabled)
    1.56 +		return;
    1.57 +
    1.58 +	if (PRCH_used)
    1.59 +		return;
    1.60 +
    1.61 +	if (!m_usercmdsFwd->GetFunctionCount())
    1.62 +		return;
    1.63 +
    1.64 +	PRCH_used = true;
    1.65 +
    1.66 +	int MaxClients = playerhelpers->GetMaxClients();
    1.67 +	for (int i = 1; i <= MaxClients; i++)
    1.68 +	{
    1.69 +		if (playerhelpers->GetGamePlayer(i)->IsInGame())
    1.70 +		{
    1.71 +			OnClientPutInServer(i);
    1.72 +		}
    1.73 +	}
    1.74 +}
    1.75 +
    1.76 +void CHookManager::OnPluginUnloaded(IPlugin *plugin)
    1.77 +{
    1.78 +	if (!PRCH_enabled)
    1.79 +		return;
    1.80 +
    1.81 +	if (!PRCH_used)
    1.82 +		return;
    1.83 +
    1.84 +	if (m_usercmdsFwd->GetFunctionCount())
    1.85 +		return;
    1.86 +
    1.87 +	int MaxClients = playerhelpers->GetMaxClients();
    1.88 +	for (int i = 1; i <= MaxClients; i++)
    1.89 +	{
    1.90 +		if (playerhelpers->GetGamePlayer(i)->IsInGame())
    1.91 +		{
    1.92 +			OnClientDisconnecting(i);
    1.93 +		}
    1.94 +	}
    1.95 +
    1.96 +	PRCH_used = false;
    1.97 +}