Fixed PlayerRunCmd being hooked when not used. (bug 3990, r=fyren)
This commit is contained in:
parent
a366096ef4
commit
be2bbec526
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
CHookManager g_Hooks;
|
CHookManager g_Hooks;
|
||||||
static bool PRCH_enabled = false;
|
static bool PRCH_enabled = false;
|
||||||
|
static bool PRCH_used = false;
|
||||||
|
|
||||||
SH_DECL_MANUALHOOK2_void(PlayerRunCmdHook, 0, 0, 0, CUserCmd *, IMoveHelper *);
|
SH_DECL_MANUALHOOK2_void(PlayerRunCmdHook, 0, 0, 0, CUserCmd *, IMoveHelper *);
|
||||||
|
|
||||||
@ -51,12 +52,16 @@ void CHookManager::Initialize()
|
|||||||
PRCH_enabled = true;
|
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);
|
m_usercmdsFwd = forwards->CreateForward("OnPlayerRunCmd", ET_Event, 6, NULL, Param_Cell, Param_CellByRef, Param_CellByRef, Param_Array, Param_Array, Param_CellByRef);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHookManager::Shutdown()
|
void CHookManager::Shutdown()
|
||||||
{
|
{
|
||||||
forwards->ReleaseForward(m_usercmdsFwd);
|
forwards->ReleaseForward(m_usercmdsFwd);
|
||||||
|
|
||||||
|
plsys->RemovePluginsListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHookManager::OnClientPutInServer(int client)
|
void CHookManager::OnClientPutInServer(int client)
|
||||||
@ -64,6 +69,9 @@ void CHookManager::OnClientPutInServer(int client)
|
|||||||
if (!PRCH_enabled)
|
if (!PRCH_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!PRCH_used)
|
||||||
|
return;
|
||||||
|
|
||||||
edict_t *pEdict = PEntityOfEntIndex(client);
|
edict_t *pEdict = PEntityOfEntIndex(client);
|
||||||
if (!pEdict)
|
if (!pEdict)
|
||||||
{
|
{
|
||||||
@ -90,6 +98,9 @@ void CHookManager::OnClientDisconnecting(int client)
|
|||||||
if (!PRCH_enabled)
|
if (!PRCH_enabled)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (!PRCH_used)
|
||||||
|
return;
|
||||||
|
|
||||||
edict_t *pEdict = PEntityOfEntIndex(client);
|
edict_t *pEdict = PEntityOfEntIndex(client);
|
||||||
if (!pEdict)
|
if (!pEdict)
|
||||||
{
|
{
|
||||||
@ -165,3 +176,49 @@ void CHookManager::PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper)
|
|||||||
|
|
||||||
RETURN_META(MRES_IGNORED);
|
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;
|
||||||
|
}
|
||||||
|
@ -40,7 +40,7 @@
|
|||||||
#include "usercmd.h"
|
#include "usercmd.h"
|
||||||
#include "extension.h"
|
#include "extension.h"
|
||||||
|
|
||||||
class CHookManager
|
class CHookManager : IPluginsListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CHookManager();
|
CHookManager();
|
||||||
@ -49,6 +49,9 @@ public:
|
|||||||
void OnClientPutInServer(int client);
|
void OnClientPutInServer(int client);
|
||||||
void OnClientDisconnecting(int client);
|
void OnClientDisconnecting(int client);
|
||||||
void PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper);
|
void PlayerRunCmd(CUserCmd *ucmd, IMoveHelper *moveHelper);
|
||||||
|
public: //IPluginsListener
|
||||||
|
void OnPluginLoaded(IPlugin *plugin);
|
||||||
|
void OnPluginUnloaded(IPlugin *plugin);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
IForward *m_usercmdsFwd;
|
IForward *m_usercmdsFwd;
|
||||||
|
Loading…
Reference in New Issue
Block a user