Fixed PlayerRunCmd being hooked when not used. (bug 3990, r=fyren)

This commit is contained in:
Nicholas Hastings 2010-07-18 15:43:56 -04:00
parent a366096ef4
commit be2bbec526
2 changed files with 61 additions and 1 deletions

View File

@ -34,6 +34,7 @@
CHookManager g_Hooks;
static bool PRCH_enabled = false;
static bool PRCH_used = false;
SH_DECL_MANUALHOOK2_void(PlayerRunCmdHook, 0, 0, 0, CUserCmd *, IMoveHelper *);
@ -51,12 +52,16 @@ void CHookManager::Initialize()
PRCH_enabled = true;
}
plsys->AddPluginsListener(this);
m_usercmdsFwd = forwards->CreateForward("OnPlayerRunCmd", ET_Event, 6, NULL, Param_Cell, Param_CellByRef, Param_CellByRef, Param_Array, Param_Array, Param_CellByRef);
}
void CHookManager::Shutdown()
{
forwards->ReleaseForward(m_usercmdsFwd);
plsys->RemovePluginsListener(this);
}
void CHookManager::OnClientPutInServer(int client)
@ -64,6 +69,9 @@ void CHookManager::OnClientPutInServer(int client)
if (!PRCH_enabled)
return;
if (!PRCH_used)
return;
edict_t *pEdict = PEntityOfEntIndex(client);
if (!pEdict)
{
@ -90,6 +98,9 @@ void CHookManager::OnClientDisconnecting(int client)
if (!PRCH_enabled)
return;
if (!PRCH_used)
return;
edict_t *pEdict = PEntityOfEntIndex(client);
if (!pEdict)
{
@ -165,3 +176,49 @@ void CHookManager::PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper)
RETURN_META(MRES_IGNORED);
}
void CHookManager::OnPluginLoaded(IPlugin *plugin)
{
if (!PRCH_enabled)
return;
if (PRCH_used)
return;
if (!m_usercmdsFwd->GetFunctionCount())
return;
PRCH_used = true;
int MaxClients = playerhelpers->GetMaxClients();
for (int i = 1; i <= MaxClients; i++)
{
if (playerhelpers->GetGamePlayer(i)->IsInGame())
{
OnClientPutInServer(i);
}
}
}
void CHookManager::OnPluginUnloaded(IPlugin *plugin)
{
if (!PRCH_enabled)
return;
if (!PRCH_used)
return;
if (m_usercmdsFwd->GetFunctionCount())
return;
int MaxClients = playerhelpers->GetMaxClients();
for (int i = 1; i <= MaxClients; i++)
{
if (playerhelpers->GetGamePlayer(i)->IsInGame())
{
OnClientDisconnecting(i);
}
}
PRCH_used = false;
}

View File

@ -40,7 +40,7 @@
#include "usercmd.h"
#include "extension.h"
class CHookManager
class CHookManager : IPluginsListener
{
public:
CHookManager();
@ -49,6 +49,9 @@ public:
void OnClientPutInServer(int client);
void OnClientDisconnecting(int client);
void PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper);
public: //IPluginsListener
void OnPluginLoaded(IPlugin *plugin);
void OnPluginUnloaded(IPlugin *plugin);
private:
IForward *m_usercmdsFwd;