Added return type modification / retrieval.

Added HAM_{IGNORED,HANDLED,OVERRIDE,SUPERCEDE} to include file.

Added the ability to disable and re-enable hooks.
This commit is contained in:
Steve Dudenhoeffer
2007-05-08 17:26:51 +00:00
parent 4e2493759e
commit f747acdc7c
11 changed files with 906 additions and 58 deletions

View File

@@ -9,6 +9,8 @@
#include "CVector.h"
#include "CString.h"
#include "sh_stack.h"
#include "hook.h"
#include "forward.h"
@@ -16,10 +18,21 @@
#include "ham_const.h"
#include "ham_utils.h"
#include "DataHandler.h"
extern bool gDoForwards;
#define PUSH_VOID() ReturnStack.push(new Data(RET_VOID, NULL)); OrigReturnStack.push(new Data(RET_VOID, NULL));
#define PUSH_INT() ReturnStack.push(new Data(RET_INTEGER, (void *)&ret)); OrigReturnStack.push(new Data(RET_INTEGER, (void *)&origret));
#define PUSH_FLOAT() ReturnStack.push(new Data(RET_FLOAT, (void *)&ret)); OrigReturnStack.push(new Data(RET_FLOAT, (void *)&origret));
#define PUSH_VECTOR() ReturnStack.push(new Data(RET_VECTOR, (void *)&ret)); OrigReturnStack.push(new Data(RET_VECTOR, (void *)&origret));
#define PUSH_CBASE() ReturnStack.push(new Data(RET_CBASE, (void *)&ret)); OrigReturnStack.push(new Data(RET_CBASE, (void *)&origret));
#define PUSH_STRING() ReturnStack.push(new Data(RET_STRING, (void *)&ret)); OrigReturnStack.push(new Data(RET_STRING, (void *)&origret));
#define POP() delete ReturnStack.front(); ReturnStack.pop(); delete OrigReturnStack.front(); OrigReturnStack.pop();
#define PRE_START() \
bool DoForwards=gDoForwards; \
gDoForwards=true; \
@@ -65,8 +78,22 @@ extern bool gDoForwards;
}
#define CHECK_RETURN() \
if (thisresult < HAM_OVERRIDE) \
{ \
return origret; \
}
#define CHECK_RETURN_STR() \
if (thisresult < HAM_OVERRIDE) \
{ \
return origret.c_str(); \
}
void Hook_Void_Void(Hook *hook, void *pthis)
{
PUSH_VOID()
PRE_START()
PRE_END()
@@ -78,29 +105,35 @@ void Hook_Void_Void(Hook *hook, void *pthis)
POST_START()
POST_END()
POP()
}
int Hook_Int_Void(Hook *hook, void *pthis)
{
int ireturn=0;
int ret=0;
int origret=0;
PUSH_INT()
PRE_START()
PRE_END()
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*,int)>(hook->func)(pthis,0);
origret=reinterpret_cast<int (__fastcall*)(void*,int)>(hook->func)(pthis,0);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*)>(hook->func)(pthis);
origret=reinterpret_cast<int (*)(void*)>(hook->func)(pthis);
#endif
POST_START()
POST_END()
return ireturn;
POP()
CHECK_RETURN()
return ret;
}
void Hook_Void_Entvar(Hook *hook, void *pthis, entvars_t *entvar)
{
PUSH_VOID()
int iOther=EntvarToIndex(entvar);
PRE_START()
@@ -117,10 +150,13 @@ void Hook_Void_Entvar(Hook *hook, void *pthis, entvars_t *entvar)
, iOther
POST_END()
POP()
}
void Hook_Void_Cbase(Hook *hook, void *pthis, void *other)
{
PUSH_VOID()
int iOther=PrivateToIndex(other);
PRE_START()
@@ -137,31 +173,36 @@ void Hook_Void_Cbase(Hook *hook, void *pthis, void *other)
, iOther
POST_END()
POP()
}
int Hook_Int_Float_Int(Hook *hook, void *pthis, float f1, int i1)
{
int ireturn=0;
int ret=0;
int origret=0;
PUSH_INT()
PRE_START()
, f1, i1
PRE_END()
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*, int, float, int)>(hook->func)(pthis, 0, f1, i1);
origret=reinterpret_cast<int (__fastcall*)(void*, int, float, int)>(hook->func)(pthis, 0, f1, i1);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*, float, int)>(hook->func)(pthis, f1, i1);
origret=reinterpret_cast<int (*)(void*, float, int)>(hook->func)(pthis, f1, i1);
#endif
POST_START()
, f1, i1
POST_END()
return ireturn;
POP();
CHECK_RETURN();
return ret;
}
void Hook_Void_Entvar_Int(Hook *hook, void *pthis, entvars_t *ev1, int i1)
{
PUSH_VOID()
int iOther=EntvarToIndex(ev1);
PRE_START()
@@ -177,30 +218,38 @@ void Hook_Void_Entvar_Int(Hook *hook, void *pthis, entvars_t *ev1, int i1)
POST_START()
, iOther, i1
POST_END()
POP()
}
int Hook_Int_Cbase(Hook *hook, void *pthis, void *cb1)
{
int ret=0;
int origret=0;
PUSH_INT()
int iOther=PrivateToIndex(cb1);
int ireturn=0;
PRE_START()
, iOther
PRE_END()
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*, int, void *)>(hook->func)(pthis, 0, cb1);
origret=reinterpret_cast<int (__fastcall*)(void*, int, void *)>(hook->func)(pthis, 0, cb1);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*, void *)>(hook->func)(pthis, cb1);
origret=reinterpret_cast<int (*)(void*, void *)>(hook->func)(pthis, cb1);
#endif
POST_START()
, iOther
POST_END()
return ireturn;
POP()
CHECK_RETURN()
return ret;
}
void Hook_Void_Int_Int(Hook *hook, void *pthis, int i1, int i2)
{
PUSH_VOID()
PRE_START()
,i1, i2
PRE_END()
@@ -213,51 +262,63 @@ void Hook_Void_Int_Int(Hook *hook, void *pthis, int i1, int i2)
POST_START()
,i1, i2
POST_END()
POP()
}
int Hook_Int_Int_Str_Int(Hook *hook, void *pthis, int i1, const char *sz1, int i2)
{
int ireturn=0;
int ret=0;
int origret=0;
PUSH_INT()
PRE_START()
,i1, sz1, i2
PRE_END()
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*, int, int, const char *, int)>(hook->func)(pthis, 0, i1, sz1, i2);
origret=reinterpret_cast<int (__fastcall*)(void*, int, int, const char *, int)>(hook->func)(pthis, 0, i1, sz1, i2);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*, int, const char *, int)>(hook->func)(pthis, i1, sz1, i2);
origret=reinterpret_cast<int (*)(void*, int, const char *, int)>(hook->func)(pthis, i1, sz1, i2);
#endif
POST_START()
,i1, sz1, i2
POST_END()
return ireturn;
POP()
CHECK_RETURN()
return ret;
}
int Hook_Int_Int(Hook *hook, void *pthis, int i1)
{
int ireturn=0;
int ret=0;
int origret=0;
PUSH_INT()
PRE_START()
,i1
PRE_END()
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*, int, int)>(hook->func)(pthis, 0, i1);
origret=reinterpret_cast<int (__fastcall*)(void*, int, int)>(hook->func)(pthis, 0, i1);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*, int)>(hook->func)(pthis, i1);
origret=reinterpret_cast<int (*)(void*, int)>(hook->func)(pthis, i1);
#endif
POST_START()
,i1
POST_END()
return ireturn;
POP()
CHECK_RETURN()
return ret;
}
int Hook_Int_Entvar(Hook *hook, void *pthis, entvars_t *ev1)
{
int ireturn=0;
int ret=0;
int origret=0;
PUSH_INT()
int iOther=EntvarToIndex(ev1);
PRE_START()
@@ -265,16 +326,18 @@ int Hook_Int_Entvar(Hook *hook, void *pthis, entvars_t *ev1)
PRE_END()
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*, int, entvars_t *)>(hook->func)(pthis, 0, ev1);
origret=reinterpret_cast<int (__fastcall*)(void*, int, entvars_t *)>(hook->func)(pthis, 0, ev1);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*, entvars_t *)>(hook->func)(pthis, ev1);
origret=reinterpret_cast<int (*)(void*, entvars_t *)>(hook->func)(pthis, ev1);
#endif
POST_START()
, iOther
POST_END()
return ireturn;
POP()
CHECK_RETURN()
return ret;
}
@@ -282,7 +345,9 @@ int Hook_Int_Entvar(Hook *hook, void *pthis, entvars_t *ev1)
// Takedamage
int Hook_Int_Entvar_Entvar_Float_Int(Hook *hook, void *pthis, entvars_t *inflictor, entvars_t *attacker, float damage, int damagebits)
{
int ireturn=0;
int ret=0;
int origret=0;
PUSH_INT()
int iInflictor=EntvarToIndex(inflictor);
int iAttacker=EntvarToIndex(attacker);
@@ -293,20 +358,23 @@ int Hook_Int_Entvar_Entvar_Float_Int(Hook *hook, void *pthis, entvars_t *inflict
#if defined _WIN32
ireturn=reinterpret_cast<int (__fastcall*)(void*, int, entvars_t *, entvars_t *, float, int)>(hook->func)(pthis, 0, inflictor, attacker, damage, damagebits);
origret=reinterpret_cast<int (__fastcall*)(void*, int, entvars_t *, entvars_t *, float, int)>(hook->func)(pthis, 0, inflictor, attacker, damage, damagebits);
#elif defined __linux__
ireturn=reinterpret_cast<int (*)(void*, entvars_t *, entvars_t *, float, int)>(hook->func)(pthis, inflictor, attacker, damage, damagebits);
origret=reinterpret_cast<int (*)(void*, entvars_t *, entvars_t *, float, int)>(hook->func)(pthis, inflictor, attacker, damage, damagebits);
#endif
POST_START()
,iInflictor, iAttacker, damage, damagebits
POST_END()
return ireturn;
POP()
CHECK_RETURN()
return ret;
}
void Hook_Void_Int(Hook *hook, void *pthis, int i1)
{
PUSH_VOID()
PRE_START()
, i1
PRE_END()
@@ -321,10 +389,12 @@ void Hook_Void_Int(Hook *hook, void *pthis, int i1)
,i1
POST_END()
POP()
}
void Hook_Void_Cbase_Cbase_Int_Float(Hook *hook, void *pthis, void *cb1, void *cb2, int i1, float f1)
{
PUSH_VOID()
int iCaller=PrivateToIndex(cb1);
int iActivator=PrivateToIndex(cb2);
@@ -344,10 +414,12 @@ void Hook_Void_Cbase_Cbase_Int_Float(Hook *hook, void *pthis, void *cb1, void *c
,iCaller, iActivator, i1, f1
POST_END()
POP()
}
void Hook_Void_Entvar_Float_Vector_Trace_Int(Hook *hook, void *pthis, entvars_t *ev1, float f1, Vector v1, TraceResult *tr1, int i1)
{
PUSH_VOID()
int iev1=EntvarToIndex(ev1);
cell cvec[3];
cvec[0]=amx_ftoc2(v1.x);
@@ -367,10 +439,13 @@ void Hook_Void_Entvar_Float_Vector_Trace_Int(Hook *hook, void *pthis, entvars_t
POST_START()
, iev1, f1, MF_PrepareCellArrayA(cvec, 3, false), tr1, i1
POST_END()
POP()
}
void Hook_Void_Float_Vector_TraceResult_Int(Hook *hook, void *pthis, float f1, Vector v1, TraceResult *tr1, int i1)
{
PUSH_VOID()
cell cvec[3];
cvec[0]=amx_ftoc2(v1.x);
cvec[1]=amx_ftoc2(v1.y);
@@ -389,41 +464,50 @@ void Hook_Void_Float_Vector_TraceResult_Int(Hook *hook, void *pthis, float f1, V
POST_START()
, f1, MF_PrepareCellArrayA(cvec, 3, false), tr1, i1
POST_END()
POP()
}
const char *Hook_Str_Void(Hook *hook, void *pthis)
{
const char *ret=NULL;
String ret;
String origret;
PUSH_STRING()
PRE_START()
PRE_END()
#if defined _WIN32
ret=reinterpret_cast<const char *(__fastcall*)(void*, int)>(hook->func)(pthis, 0);
origret.assign(reinterpret_cast<const char *(__fastcall*)(void*, int)>(hook->func)(pthis, 0));
#elif defined __linux__
ret=reinterpret_cast<const char *(*)(void*)>(hook->func)(pthis);
origret.assign(reinterpret_cast<const char *(*)(void*)>(hook->func)(pthis));
#endif
POST_START()
POST_END()
return ret;
POP()
CHECK_RETURN_STR();
return ret.c_str();
}
void *Hook_Cbase_Void(Hook *hook, void *pthis)
{
void *ret=NULL;
void *origret=NULL;
PUSH_CBASE()
PRE_START()
PRE_END()
#if defined _WIN32
ret=reinterpret_cast<void *(__fastcall*)(void*, int)>(hook->func)(pthis, 0);
origret=reinterpret_cast<void *(__fastcall*)(void*, int)>(hook->func)(pthis, 0);
#elif defined __linux__
ret=reinterpret_cast<void *(*)(void*)>(hook->func)(pthis);
origret=reinterpret_cast<void *(*)(void*)>(hook->func)(pthis);
#endif
POST_START()
POST_END()
POP()
CHECK_RETURN()
return ret;
}
@@ -432,21 +516,27 @@ void *Hook_Cbase_Void(Hook *hook, void *pthis)
Vector Hook_Vector_Void(Hook *hook, void *pthis)
{
Vector ret;
Vector origret;
PUSH_VECTOR()
memset(&ret, 0x0, sizeof(Vector));
memset(&origret, 0x0, sizeof(Vector));
PRE_START()
PRE_END()
#if defined _WIN32
ret=reinterpret_cast<Vector (__fastcall*)(void*, int)>(hook->func)(pthis, 0);
origret=reinterpret_cast<Vector (__fastcall*)(void*, int)>(hook->func)(pthis, 0);
#elif defined __linux__
ret=reinterpret_cast<Vector (*)(void*)>(hook->func)(pthis);
origret=reinterpret_cast<Vector (*)(void*)>(hook->func)(pthis);
#endif
POST_START()
POST_END()
POP()
CHECK_RETURN()
return ret;
}
@@ -454,8 +544,12 @@ Vector Hook_Vector_Void(Hook *hook, void *pthis)
Vector Hook_Vector_pVector(Hook *hook, void *pthis, Vector *v1)
{
Vector ret;
Vector origret;
PUSH_VECTOR()
memset(&ret, 0x0, sizeof(Vector));
memset(&origret, 0x0, sizeof(Vector));
cell cv1[3];
cv1[0]=amx_ftoc2(v1->x);
@@ -467,15 +561,17 @@ Vector Hook_Vector_pVector(Hook *hook, void *pthis, Vector *v1)
PRE_END()
#if defined _WIN32
ret=reinterpret_cast<Vector (__fastcall*)(void*, int, Vector *)>(hook->func)(pthis, 0, v1);
origret=reinterpret_cast<Vector (__fastcall*)(void*, int, Vector *)>(hook->func)(pthis, 0, v1);
#elif defined __linux__
ret=reinterpret_cast<Vector (*)(void*, Vector *)>(hook->func)(pthis, v1);
origret=reinterpret_cast<Vector (*)(void*, Vector *)>(hook->func)(pthis, v1);
#endif
POST_START()
, MF_PrepareCellArrayA(cv1, 3, false)
POST_END()
POP()
CHECK_RETURN()
return ret;
}
@@ -483,6 +579,8 @@ Vector Hook_Vector_pVector(Hook *hook, void *pthis, Vector *v1)
int Hook_Int_pVector(Hook *hook, void *pthis, Vector *v1)
{
int ret=0;
int origret=0;
PUSH_INT()
cell cv1[3];
@@ -495,21 +593,24 @@ int Hook_Int_pVector(Hook *hook, void *pthis, Vector *v1)
PRE_END()
#if defined _WIN32
ret=reinterpret_cast<int (__fastcall*)(void*, int, Vector *)>(hook->func)(pthis, 0, v1);
origret=reinterpret_cast<int (__fastcall*)(void*, int, Vector *)>(hook->func)(pthis, 0, v1);
#elif defined __linux__
ret=reinterpret_cast<int (*)(void*, Vector *)>(hook->func)(pthis, v1);
origret=reinterpret_cast<int (*)(void*, Vector *)>(hook->func)(pthis, v1);
#endif
POST_START()
, MF_PrepareCellArrayA(cv1, 3, false)
POST_END()
POP()
CHECK_RETURN()
return ret;
}
void Hook_Void_Entvar_Float_Float(Hook *hook, void *pthis, entvars_t *ev1, float f1, float f2)
{
PUSH_VOID()
cell cev1=EntvarToIndex(ev1);
PRE_START()
@@ -526,11 +627,14 @@ void Hook_Void_Entvar_Float_Float(Hook *hook, void *pthis, entvars_t *ev1, float
, cev1, f1, f2
POST_END()
POP()
}
int Hook_Int_pFloat_pFloat(Hook *hook, void *pthis, float *f1, float *f2)
{
int ret=0;
int origret=0;
PUSH_INT()
cell cf1=amx_ftoc2(f1 == NULL ? 0.0 : *f1);
cell cf2=amx_ftoc2(f2 == NULL ? 0.0 : *f2);
@@ -540,20 +644,23 @@ int Hook_Int_pFloat_pFloat(Hook *hook, void *pthis, float *f1, float *f2)
PRE_END()
#if defined _WIN32
ret=reinterpret_cast<int (__fastcall*)(void *, int, float *, float *)>(hook->func)(pthis, 0, f1, f2);
origret=reinterpret_cast<int (__fastcall*)(void *, int, float *, float *)>(hook->func)(pthis, 0, f1, f2);
#elif defined __linux__
ret=reinterpret_cast<int (*)(void *, float *, float *)>(hook->func)(pthis, f1, f2);
origret=reinterpret_cast<int (*)(void *, float *, float *)>(hook->func)(pthis, f1, f2);
#endif
POST_START()
, cf1, cf2
POST_END()
POP()
CHECK_RETURN()
return ret;
}
void Hook_Void_Entvar_Float(Hook *hook, void *pthis, entvars_t *ev1, float f1)
{
PUSH_VOID()
cell cev1=EntvarToIndex(ev1);
PRE_START()
@@ -569,5 +676,6 @@ void Hook_Void_Entvar_Float(Hook *hook, void *pthis, entvars_t *ev1, float f1)
POST_START()
, cev1, f1
POST_END()
POP()
}