Change SDKHooks to VTable Hooks (bug 6070, r=psychonic).

This commit is contained in:
Kyle Sanderson 2014-03-23 22:11:06 -06:00
parent ee595978f8
commit 9abac06e85
4 changed files with 680 additions and 527 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,6 +6,8 @@
#include <IBinTools.h>
#include <convar.h>
#include <sh_list.h>
#include <amtl/am-vector.h>
#include <vtable_hook_helper.h>
#include <iplayerinfo.h>
#include <shareddefs.h>
@ -106,14 +108,29 @@ class IPhysicsObject;
class CDmgAccumulator;
typedef CBaseEntity CBaseCombatWeapon;
class HookList
struct HookList
{
public:
int entity;
SDKHookType type;
IPluginFunction *callback;
};
class CVTableList
{
public:
CVTableList() : vtablehook(NULL)
{
};
~CVTableList()
{
delete vtablehook;
};
public:
CVTableHook *vtablehook;
ke::Vector<HookList> hooks;
};
class IEntityListener
{
public:
@ -235,13 +252,13 @@ public:
/**
* Functions
*/
cell_t Call(int entity, SDKHookType type, int other=-2);
cell_t Call(CBaseEntity *pEnt, SDKHookType type, int other=-2);
cell_t Call(int entity, SDKHookType type, int other=INVALID_EHANDLE_INDEX);
cell_t Call(CBaseEntity *pEnt, SDKHookType type, int other=INVALID_EHANDLE_INDEX);
cell_t Call(CBaseEntity *pEnt, SDKHookType type, CBaseEntity *pOther);
void SetupHooks();
HookReturn Hook(int entity, SDKHookType type, IPluginFunction *callback);
void Unhook(int index);
HookReturn Hook(int entity, SDKHookType type, IPluginFunction *pCallback);
void Unhook(int entity, SDKHookType type, IPluginFunction *pCallback);
/**
* IServerGameDLL & IVEngineServer Hook Handlers
@ -309,11 +326,12 @@ public:
bool Hook_WeaponSwitchPost(CBaseCombatWeapon *pWeapon, int viewmodelindex);
private:
void RemoveEntityHooks(CBaseEntity *pEnt);
void Unhook(CBaseEntity *pEntity);
void Unhook(IPluginContext *pContext);
};
extern CGlobalVars *gpGlobals;
extern CUtlVector<HookList> g_HookList;
extern ke::Vector<CVTableList *> g_HookList[SDKHook_MAXHOOKS];
extern ICvar *icvar;
#endif // _INCLUDE_SOURCEMOD_EXTENSION_PROPER_H_

View File

@ -93,12 +93,7 @@ cell_t Native_Unhook(IPluginContext *pContext, const cell_t *params)
int entity = (int)params[1];
SDKHookType type = (SDKHookType)params[2];
IPluginFunction *callback = pContext->GetFunctionById(params[3]);
for(int i = g_HookList.Count() - 1; i >= 0; i--)
{
if(g_HookList[i].entity == entity && g_HookList[i].type == type && g_HookList[i].callback == callback)
g_Interface.Unhook(i);
}
g_Interface.Unhook(entity, type, callback);
return 0;
}

View File

@ -96,6 +96,16 @@ public:
{
return (this->GetVTablePtr() == other->GetVTablePtr());
}
bool operator != (CVTableHook &other)
{
return (this->GetVTablePtr() != other.GetVTablePtr());
}
bool operator != (CVTableHook *other)
{
return (this->GetVTablePtr() != other->GetVTablePtr());
}
private:
void *vtableptr;
int hookid;