Code:
#include "amxxmodule.h"
#include <windows.h>
#define HOOK_Spawn 0
void *pOriginalFunction = NULL;
void Hook_Spawn()
{
//save this pointer
void *pthis;
__asm mov pthis, ecx;
//pre hook
SERVER_PRINT("::Spawn(void) prehook!\n");
//call original function
__asm mov ecx, pthis;
__asm call [pOriginalFunction];
//post hook
SERVER_PRINT("::Spawn(void) posthook!\n");
}
void Hook()
{
//get classname of the entity you want to hook
const char *classname = CMD_ARGV(1);
edict_t *pEdict = CREATE_ENTITY();
CALL_GAME_ENTITY(PLID, classname, &pEdict->v);
if(pEdict->pvPrivateData == NULL)
{
REMOVE_ENTITY(pEdict);
return;
}
//get this pointer
void *pthis = pEdict->pvPrivateData;
//get vtable
void **vtbl = *(void ***)pthis;
REMOVE_ENTITY(pEdict);
if(vtbl == NULL)
return;
int **ivtbl = (int **)vtbl;
//get the original function
pOriginalFunction = (void *)ivtbl[HOOK_Spawn];
//patch original function to our function
DWORD oldflags;
if(VirtualProtect(&ivtbl[HOOK_Spawn], sizeof(int *), PAGE_READWRITE, &oldflags))
{
ivtbl[HOOK_Spawn] = (int *)Hook_Spawn;
}
}
void OnMetaAttach()
{
REG_SVR_COMMAND("hook", Hook);
}
ecx store this pointer, you need to do some calculate to get the edict_t *
in windows this calc is
Code:
mov eax, [ecx + 4]; get this->pev
mov eax, [eax + 520]; get pev->pContainingEntity
mov pEdict, eax
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>