From 5fc89085d6aadd0b264e37de0001a5d9d3adbb27 Mon Sep 17 00:00:00 2001 From: Steve Dudenhoeffer Date: Wed, 9 May 2007 14:58:55 +0000 Subject: [PATCH] Added the ability to change parameters on the fly. Added GetHamReturnStatus() --- dlls/hamsandwich/DataHandler.cpp | 132 +++++++++++- dlls/hamsandwich/DataHandler.h | 87 +++++--- dlls/hamsandwich/ham_utils.h | 4 + dlls/hamsandwich/hook_callbacks.cpp | 250 ++++++++++++++++++----- dlls/hamsandwich/hook_callbacks.h | 4 +- dlls/hamsandwich/hook_native.cpp | 10 +- dlls/hamsandwich/include/hamsandwich.inc | 20 +- 7 files changed, 410 insertions(+), 97 deletions(-) diff --git a/dlls/hamsandwich/DataHandler.cpp b/dlls/hamsandwich/DataHandler.cpp index 554c2493..87b12c24 100644 --- a/dlls/hamsandwich/DataHandler.cpp +++ b/dlls/hamsandwich/DataHandler.cpp @@ -12,7 +12,7 @@ CStack< Data * > ReturnStack; CStack< Data * > OrigReturnStack; CStack< CVector< Data * > * > ParamStack; - +CStack< int * > ReturnStatus; #define CHECK_STACK(__STACK__) \ if ( ( __STACK__ ).size() <= 0) \ { \ @@ -38,7 +38,10 @@ static const char *returntypes[] = "float", "vector", "string", - "cbase", + "entity", + "entity", + "traceresult" + "" }; static cell AMX_NATIVE_CALL GetHamReturnInteger(AMX *amx, cell *params) @@ -89,20 +92,20 @@ static cell AMX_NATIVE_CALL GetOrigHamReturnVector(AMX *amx, cell *params) int ret=dat->GetVector(MF_GetAmxAddr(amx, params[1])); PARSE_RETURN(); } -static cell AMX_NATIVE_CALL GetHamReturnCbase(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL GetHamReturnEntity(AMX *amx, cell *params) { CHECK_STACK(ReturnStack); Data *dat=ReturnStack.front(); - int ret=dat->GetCbase(MF_GetAmxAddr(amx, params[1])); + int ret=dat->GetEntity(MF_GetAmxAddr(amx, params[1])); PARSE_RETURN(); } -static cell AMX_NATIVE_CALL GetOrigHamReturnCbase(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL GetOrigHamReturnEntity(AMX *amx, cell *params) { CHECK_STACK(OrigReturnStack); Data *dat=OrigReturnStack.front(); - int ret=dat->GetCbase(MF_GetAmxAddr(amx, params[1])); + int ret=dat->GetEntity(MF_GetAmxAddr(amx, params[1])); PARSE_RETURN(); } static cell AMX_NATIVE_CALL GetHamReturnString(AMX *amx, cell *params) @@ -145,12 +148,12 @@ static cell AMX_NATIVE_CALL SetHamReturnVector(AMX *amx, cell *params) int ret=dat->SetVector(MF_GetAmxAddr(amx, params[1])); PARSE_RETURN(); } -static cell AMX_NATIVE_CALL SetHamReturnCbase(AMX *amx, cell *params) +static cell AMX_NATIVE_CALL SetHamReturnEntity(AMX *amx, cell *params) { CHECK_STACK(ReturnStack); Data *dat=ReturnStack.front(); - int ret=dat->SetCbase(¶ms[1]); + int ret=dat->SetEntity(¶ms[1]); PARSE_RETURN(); } static cell AMX_NATIVE_CALL SetHamReturnString(AMX *amx, cell *params) @@ -161,23 +164,130 @@ static cell AMX_NATIVE_CALL SetHamReturnString(AMX *amx, cell *params) int ret=dat->SetString(MF_GetAmxAddr(amx, params[1])); PARSE_RETURN(); } +static cell AMX_NATIVE_CALL SetHamParamInteger(AMX *amx, cell *params) +{ + CHECK_STACK(ParamStack); + CVector *vec=ParamStack.front(); + if (vec->size() < (unsigned)params[1]) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid parameter number, got %d, expected %d", params[1], vec->size()); + return 0; + } + Data *dat=vec->at(params[1] - 1); + + int ret=dat->SetInt(¶ms[2]); + PARSE_RETURN(); +} +static cell AMX_NATIVE_CALL SetHamParamTraceResult(AMX *amx, cell *params) +{ + if (params[2] == 0) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Null traceresult provided."); + + return 0; + } + CHECK_STACK(ParamStack); + CVector *vec=ParamStack.front(); + if (vec->size() < (unsigned)params[1]) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid parameter number, got %d, expected %d", params[1], vec->size()); + return 0; + } + Data *dat=vec->at(params[1] - 1); + + int ret=dat->SetInt(¶ms[2]); + PARSE_RETURN(); +} +static cell AMX_NATIVE_CALL SetHamParamFloat(AMX *amx, cell *params) +{ + CHECK_STACK(ParamStack); + CVector *vec=ParamStack.front(); + if (vec->size() < (unsigned)params[1] || params[1] < 1) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid parameter number, got %d, expected %d", params[1], vec->size()); + return 0; + } + Data *dat=vec->at(params[1] - 1); + + int ret=dat->SetFloat(¶ms[2]); + PARSE_RETURN(); +} +static cell AMX_NATIVE_CALL SetHamParamVector(AMX *amx, cell *params) +{ + CHECK_STACK(ParamStack); + CVector *vec=ParamStack.front(); + if (vec->size() < (unsigned)params[1]) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid parameter number, got %d, expected %d", params[1], vec->size()); + return 0; + } + Data *dat=vec->at(params[1] - 1); + + int ret=dat->SetVector(MF_GetAmxAddr(amx, params[2])); + PARSE_RETURN(); +} +static cell AMX_NATIVE_CALL SetHamParamEntity(AMX *amx, cell *params) +{ + CHECK_STACK(ParamStack); + CVector *vec=ParamStack.front(); + if (vec->size() < (unsigned)params[1]) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid parameter number, got %d, expected %d", params[1], vec->size()); + return 0; + } + Data *dat=vec->at(params[1] - 1); + + int ret=dat->SetEntity(¶ms[2]); + PARSE_RETURN(); +} +static cell AMX_NATIVE_CALL SetHamParamString(AMX *amx, cell *params) +{ + CHECK_STACK(ParamStack); + CVector *vec=ParamStack.front(); + if (vec->size() < (unsigned)params[1]) + { + MF_LogError(amx, AMX_ERR_NATIVE, "Invalid parameter number, got %d, expected %d", params[1], vec->size()); + return 0; + } + Data *dat=vec->at(params[1] - 1); + + int ret=dat->SetString(MF_GetAmxAddr(amx, params[2])); + PARSE_RETURN(); +} +static cell AMX_NATIVE_CALL GetHamReturnStatus(AMX *amx, cell *params) +{ + CHECK_STACK(ReturnStatus); + int *i=ReturnStatus.front(); + + return *i; +} AMX_NATIVE_INFO ReturnNatives[] = { { "GetHamReturnInteger", GetHamReturnInteger }, { "GetHamReturnFloat", GetHamReturnFloat }, { "GetHamReturnVector", GetHamReturnVector }, - { "GetHamReturnCbase", GetHamReturnCbase }, + { "GetHamReturnEntity", GetHamReturnEntity }, { "GetHamReturnString", GetHamReturnString }, { "GetOrigHamReturnInteger", GetOrigHamReturnInteger }, { "GetOrigHamReturnFloat", GetOrigHamReturnFloat }, { "GetOrigHamReturnVector", GetOrigHamReturnVector }, - { "GetOrigHamReturnCbase", GetOrigHamReturnCbase }, + { "GetOrigHamReturnEntity", GetOrigHamReturnEntity }, { "GetOrigHamReturnString", GetOrigHamReturnString }, { "SetHamReturnInteger", SetHamReturnInteger }, { "SetHamReturnFloat", SetHamReturnFloat }, { "SetHamReturnVector", SetHamReturnVector }, - { "SetHamReturnCbase", SetHamReturnCbase }, + { "SetHamReturnEntity", SetHamReturnEntity }, { "SetHamReturnString", SetHamReturnString }, + + { "GetHamReturnStatus", GetHamReturnStatus }, + + { "SetHamParamInteger", SetHamParamInteger }, + { "SetHamParamFloat", SetHamParamFloat }, + { "SetHamParamVector", SetHamParamVector }, + { "SetHamParamEntity", SetHamParamEntity }, + { "SetHamParamString", SetHamParamString }, + { "SetHamParamTraceResult", SetHamParamTraceResult }, + { NULL, NULL }, }; diff --git a/dlls/hamsandwich/DataHandler.h b/dlls/hamsandwich/DataHandler.h index 2a4bb109..5f142778 100644 --- a/dlls/hamsandwich/DataHandler.h +++ b/dlls/hamsandwich/DataHandler.h @@ -13,7 +13,9 @@ enum RET_FLOAT, RET_VECTOR, RET_STRING, - RET_CBASE + RET_CBASE, + RET_ENTVAR, + RET_TRACE }; // Container for return and parameter data. // Contains a void pointer, and a flag telling what it contains. @@ -21,6 +23,7 @@ class Data { private: void *m_data; + int *m_index; int m_type; bool IsSet(void) @@ -34,10 +37,13 @@ private: }; public: - Data() : m_data(NULL), m_type(RET_VOID) + Data() : m_data(NULL), m_index(NULL), m_type(RET_VOID) { /* nothing */ }; - Data(int type, void *ptr) : m_data(ptr), m_type(type) + Data(int type, void *ptr) : m_data(ptr), m_index(NULL), m_type(type) + { /* nothing */ }; + + Data(int type, void *ptr, int *cptr) : m_data(ptr), m_index(NULL), m_type(type) { /* nothing */ }; ~Data() @@ -57,13 +63,18 @@ public: { return -2; } - if (!IsType(RET_INTEGER)) + if (IsType(RET_INTEGER)) { - return -1; + *(reinterpret_cast(m_data))=*data; + return 0; + } + else if (IsType(RET_TRACE)) + { + *(reinterpret_cast(m_data))=*data; + return 0; } - *(reinterpret_cast(m_data))=*data; - return 0; + return -1; }; int SetFloat(cell *data) @@ -135,20 +146,33 @@ public: return 0; }; - int SetCbase(cell *data) + int SetEntity(cell *data) { if (!IsSet()) { return -2; } - if (!IsType(RET_CBASE)) + if (IsType(RET_CBASE)) { - return -1; + *(reinterpret_cast(m_data))=IndexToPrivate(*data); + if (m_index != 0) + { + *m_index=*data; + } + + return 0; } + else if (IsType(RET_ENTVAR)) + { + *(reinterpret_cast(m_data))=IndexToEntvar(*data); + if (m_index != 0) + { + *m_index=*data; + } - *(reinterpret_cast(m_data))=IndexToPrivate(*data); - - return 0; + return 0; + } + return -1; }; int GetInt(cell *data) @@ -157,13 +181,20 @@ public: { return -2; } - if (!IsType(RET_INTEGER)) + if (IsType(RET_INTEGER)) { - return -1; - } - *data=*(reinterpret_cast(m_data)); + *data=*(reinterpret_cast(m_data)); - return 0; + return 0; + } + else if (IsType(RET_TRACE)) + { + *data=*(reinterpret_cast(m_data)); + + return 0; + } + + return -1; }; int GetFloat(cell *data) { @@ -215,24 +246,30 @@ public: }; return 0; }; - int GetCbase(cell *data) + int GetEntity(cell *data) { if (!IsSet()) { return -2; } - if (!IsType(RET_CBASE)) + if (IsType(RET_CBASE)) { - return -1; - } - *data=PrivateToIndex(m_data); + *data=PrivateToIndex(m_data); - return 0; + return 0; + } + else if (IsType(RET_ENTVAR)) + { + *data=EntvarToIndex(reinterpret_cast(m_data)); + + return 0; + } + return -1; } }; extern CStack< Data * > ReturnStack; extern CStack< Data * > OrigReturnStack; extern CStack< CVector< Data * > * > ParamStack; - +extern CStack< int * > ReturnStatus; #endif diff --git a/dlls/hamsandwich/ham_utils.h b/dlls/hamsandwich/ham_utils.h index 99492d34..356873f1 100644 --- a/dlls/hamsandwich/ham_utils.h +++ b/dlls/hamsandwich/ham_utils.h @@ -77,6 +77,10 @@ inline void *IndexToPrivate(int index) { return INDEXENT_NEW(index)->pvPrivateData; }; +inline entvars_t *IndexToEntvar(int index) +{ + return &(INDEXENT_NEW(index)->v); +}; inline int EntvarToIndex(entvars_t *pev) { diff --git a/dlls/hamsandwich/hook_callbacks.cpp b/dlls/hamsandwich/hook_callbacks.cpp index 2314cb4d..659cfd76 100644 --- a/dlls/hamsandwich/hook_callbacks.cpp +++ b/dlls/hamsandwich/hook_callbacks.cpp @@ -24,6 +24,7 @@ extern bool gDoForwards; +// Return value pushes #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)); @@ -31,14 +32,41 @@ extern bool gDoForwards; #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)); +// Pop off return values #define POP() delete ReturnStack.front(); ReturnStack.pop(); delete OrigReturnStack.front(); OrigReturnStack.pop(); +// Parameter value pushes +#define MAKE_VECTOR() \ + int iThis=PrivateToIndex(pthis); \ + CVector *__vec=new CVector; \ + ParamStack.push(__vec); \ + P_CBASE(pthis, iThis) + +#define P_INT(___PARAM) __vec->push_back(new Data(RET_INTEGER, (void *) & (___PARAM))); +#define P_FLOAT(___PARAM) __vec->push_back(new Data(RET_FLOAT, (void *) & (___PARAM))); +#define P_VECTOR(___PARAM) __vec->push_back(new Data(RET_VECTOR, (void *) & (___PARAM))); +#define P_STR(___PARAM) __vec->push_back(new Data(RET_STRING, (void *) & (___PARAM))); +#define P_CBASE(__PARAM, __INDEX) __vec->push_back(new Data(RET_CBASE, (void *) & (__PARAM), reinterpret_cast(& (__INDEX)))); +#define P_ENTVAR(__PARAM, __INDEX) __vec->push_back(new Data(RET_ENTVAR, (void *) & (__PARAM), reinterpret_cast(& (__INDEX)))); +#define P_TRACE(__PARAM) __vec->push_back(new Data(RET_TRACE, (void *) (__PARAM))); +#define P_PTRVECTOR(__PARAM) __vec->push_back(new Data(RET_VECTOR, (void *) (__PARAM))); +#define P_PTRFLOAT(__PARAM) __vec->push_back(new Data(RET_FLOAT, (void *) (__PARAM))); + +#define KILL_VECTOR() \ + CVector::iterator end=__vec->end(); \ + for (CVector::iterator i=__vec->begin(); i!=end; ++i) \ + { \ + delete (*i); \ + } \ + delete __vec; \ + ParamStack.pop(); + #define PRE_START() \ bool DoForwards=gDoForwards; \ gDoForwards=true; \ int result=HAM_UNSET; \ + ReturnStatus.push(&result); \ int thisresult=HAM_UNSET; \ - int iThis=PrivateToIndex(pthis); \ if (DoForwards) \ { \ CVector::iterator end=hook->pre.end(); \ @@ -75,7 +103,8 @@ extern bool gDoForwards; ); \ } \ } \ - } + } \ + ReturnStatus.pop(); #define CHECK_RETURN() \ @@ -89,11 +118,21 @@ extern bool gDoForwards; { \ return origret.c_str(); \ } +#define CHECK_RETURN_VEC() \ + if (thisresult < HAM_OVERRIDE) \ + { \ + memcpy(out, &origret, sizeof(Vector)); \ + return; \ + } + void Hook_Void_Void(Hook *hook, void *pthis) { PUSH_VOID() + + MAKE_VECTOR() + PRE_START() PRE_END() @@ -105,6 +144,8 @@ void Hook_Void_Void(Hook *hook, void *pthis) POST_START() POST_END() + + KILL_VECTOR() POP() } int Hook_Int_Void(Hook *hook, void *pthis) @@ -113,6 +154,10 @@ int Hook_Int_Void(Hook *hook, void *pthis) int origret=0; PUSH_INT() + + MAKE_VECTOR() + + PRE_START() PRE_END() @@ -126,7 +171,9 @@ int Hook_Int_Void(Hook *hook, void *pthis) POST_START() POST_END() + KILL_VECTOR() POP() + CHECK_RETURN() return ret; } @@ -134,8 +181,13 @@ int Hook_Int_Void(Hook *hook, void *pthis) void Hook_Void_Entvar(Hook *hook, void *pthis, entvars_t *entvar) { PUSH_VOID() + int iOther=EntvarToIndex(entvar); + MAKE_VECTOR() + + P_ENTVAR(entvar, iOther) + PRE_START() , iOther PRE_END() @@ -150,6 +202,7 @@ void Hook_Void_Entvar(Hook *hook, void *pthis, entvars_t *entvar) , iOther POST_END() + KILL_VECTOR() POP() } @@ -159,6 +212,10 @@ void Hook_Void_Cbase(Hook *hook, void *pthis, void *other) PUSH_VOID() int iOther=PrivateToIndex(other); + MAKE_VECTOR() + + P_CBASE(other, iOther) + PRE_START() , iOther PRE_END() @@ -173,6 +230,7 @@ void Hook_Void_Cbase(Hook *hook, void *pthis, void *other) , iOther POST_END() + KILL_VECTOR() POP() } @@ -181,6 +239,12 @@ int Hook_Int_Float_Int(Hook *hook, void *pthis, float f1, int i1) int ret=0; int origret=0; PUSH_INT() + + MAKE_VECTOR() + + P_FLOAT(f1) + P_INT(i1) + PRE_START() , f1, i1 PRE_END() @@ -195,8 +259,9 @@ int Hook_Int_Float_Int(Hook *hook, void *pthis, float f1, int i1) , f1, i1 POST_END() - POP(); - CHECK_RETURN(); + KILL_VECTOR() + POP() + CHECK_RETURN() return ret; } @@ -205,6 +270,11 @@ void Hook_Void_Entvar_Int(Hook *hook, void *pthis, entvars_t *ev1, int i1) PUSH_VOID() int iOther=EntvarToIndex(ev1); + MAKE_VECTOR() + + P_ENTVAR(ev1, iOther) + P_INT(i1) + PRE_START() , iOther, i1 PRE_END() @@ -218,6 +288,8 @@ void Hook_Void_Entvar_Int(Hook *hook, void *pthis, entvars_t *ev1, int i1) POST_START() , iOther, i1 POST_END() + + KILL_VECTOR() POP() } @@ -229,6 +301,11 @@ int Hook_Int_Cbase(Hook *hook, void *pthis, void *cb1) PUSH_INT() int iOther=PrivateToIndex(cb1); + + MAKE_VECTOR() + + P_CBASE(cb1, iOther) + PRE_START() , iOther PRE_END() @@ -242,6 +319,7 @@ int Hook_Int_Cbase(Hook *hook, void *pthis, void *cb1) , iOther POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -250,6 +328,12 @@ int Hook_Int_Cbase(Hook *hook, void *pthis, void *cb1) void Hook_Void_Int_Int(Hook *hook, void *pthis, int i1, int i2) { PUSH_VOID() + + MAKE_VECTOR() + + P_INT(i1) + P_INT(i2) + PRE_START() ,i1, i2 PRE_END() @@ -262,6 +346,8 @@ void Hook_Void_Int_Int(Hook *hook, void *pthis, int i1, int i2) POST_START() ,i1, i2 POST_END() + + KILL_VECTOR() POP() } @@ -270,19 +356,29 @@ int Hook_Int_Int_Str_Int(Hook *hook, void *pthis, int i1, const char *sz1, int i int ret=0; int origret=0; PUSH_INT() + + String a=sz1; + + MAKE_VECTOR() + + P_INT(i1) + P_STR(a) + P_INT(i2) + PRE_START() - ,i1, sz1, i2 + ,i1, a.c_str(), i2 PRE_END() #if defined _WIN32 - origret=reinterpret_cast(hook->func)(pthis, 0, i1, sz1, i2); + origret=reinterpret_cast(hook->func)(pthis, 0, i1, a.c_str(), i2); #elif defined __linux__ - origret=reinterpret_cast(hook->func)(pthis, i1, sz1, i2); + origret=reinterpret_cast(hook->func)(pthis, i1, a.c_str(), i2); #endif POST_START() - ,i1, sz1, i2 + ,i1, a.c_str(), i2 POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -293,7 +389,12 @@ int Hook_Int_Int(Hook *hook, void *pthis, int i1) int ret=0; int origret=0; PUSH_INT() + + + MAKE_VECTOR() + P_INT(i1) + PRE_START() ,i1 PRE_END() @@ -308,6 +409,7 @@ int Hook_Int_Int(Hook *hook, void *pthis, int i1) ,i1 POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -321,6 +423,9 @@ int Hook_Int_Entvar(Hook *hook, void *pthis, entvars_t *ev1) PUSH_INT() int iOther=EntvarToIndex(ev1); + MAKE_VECTOR() + P_ENTVAR(ev1, iOther) + PRE_START() ,iOther PRE_END() @@ -335,6 +440,7 @@ int Hook_Int_Entvar(Hook *hook, void *pthis, entvars_t *ev1) , iOther POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -351,6 +457,11 @@ int Hook_Int_Entvar_Entvar_Float_Int(Hook *hook, void *pthis, entvars_t *inflict int iInflictor=EntvarToIndex(inflictor); int iAttacker=EntvarToIndex(attacker); + MAKE_VECTOR() + P_ENTVAR(inflictor, iInflictor) + P_ENTVAR(attacker, iAttacker) + P_FLOAT(damage) + P_INT(damagebits) PRE_START() ,iInflictor, iAttacker, damage, damagebits @@ -367,6 +478,7 @@ int Hook_Int_Entvar_Entvar_Float_Int(Hook *hook, void *pthis, entvars_t *inflict ,iInflictor, iAttacker, damage, damagebits POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -375,6 +487,10 @@ int Hook_Int_Entvar_Entvar_Float_Int(Hook *hook, void *pthis, entvars_t *inflict void Hook_Void_Int(Hook *hook, void *pthis, int i1) { PUSH_VOID() + + MAKE_VECTOR() + P_INT(i1) + PRE_START() , i1 PRE_END() @@ -389,6 +505,7 @@ void Hook_Void_Int(Hook *hook, void *pthis, int i1) ,i1 POST_END() + KILL_VECTOR() POP() } @@ -398,6 +515,11 @@ void Hook_Void_Cbase_Cbase_Int_Float(Hook *hook, void *pthis, void *cb1, void *c int iCaller=PrivateToIndex(cb1); int iActivator=PrivateToIndex(cb2); + MAKE_VECTOR() + P_CBASE(cb1, iCaller) + P_CBASE(cb2, iActivator) + P_INT(i1) + P_FLOAT(f1) PRE_START() ,iCaller, iActivator, i1, f1 @@ -414,6 +536,7 @@ void Hook_Void_Cbase_Cbase_Int_Float(Hook *hook, void *pthis, void *cb1, void *c ,iCaller, iActivator, i1, f1 POST_END() + KILL_VECTOR() POP() } @@ -421,13 +544,16 @@ void Hook_Void_Entvar_Float_Vector_Trace_Int(Hook *hook, void *pthis, entvars_t { PUSH_VOID() int iev1=EntvarToIndex(ev1); - cell cvec[3]; - cvec[0]=amx_ftoc2(v1.x); - cvec[1]=amx_ftoc2(v1.y); - cvec[2]=amx_ftoc2(v1.z); + + MAKE_VECTOR() + P_ENTVAR(ev1, iev1) + P_FLOAT(f1) + P_VECTOR(v1) + P_TRACE(tr1) + P_INT(i1) PRE_START() - ,iev1, f1, MF_PrepareCellArrayA(cvec, 3, false), tr1, i1 + ,iev1, f1, MF_PrepareCellArrayA(reinterpret_cast(&v1), 3, false), tr1, i1 PRE_END() #if defined _WIN32 @@ -437,22 +563,25 @@ void Hook_Void_Entvar_Float_Vector_Trace_Int(Hook *hook, void *pthis, entvars_t #endif POST_START() - , iev1, f1, MF_PrepareCellArrayA(cvec, 3, false), tr1, i1 + , iev1, f1, MF_PrepareCellArrayA(reinterpret_cast(&v1), 3, false), tr1, i1 POST_END() + KILL_VECTOR() 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); - cvec[2]=amx_ftoc2(v1.z); + + MAKE_VECTOR() + P_FLOAT(f1) + P_VECTOR(v1) + P_TRACE(tr1) + P_INT(i1) PRE_START() - , f1, MF_PrepareCellArrayA(cvec, 3, false), tr1, i1 + , f1, MF_PrepareCellArrayA(reinterpret_cast(&v1), 3, false), tr1, i1 PRE_END() #if defined _WIN32 @@ -462,14 +591,19 @@ void Hook_Void_Float_Vector_TraceResult_Int(Hook *hook, void *pthis, float f1, V #endif POST_START() - , f1, MF_PrepareCellArrayA(cvec, 3, false), tr1, i1 + , f1, MF_PrepareCellArrayA(reinterpret_cast(&v1), 3, false), tr1, i1 POST_END() + + KILL_VECTOR() POP() } const char *Hook_Str_Void(Hook *hook, void *pthis) { String ret; String origret; + + MAKE_VECTOR() + PUSH_STRING() PRE_START() PRE_END() @@ -483,6 +617,7 @@ const char *Hook_Str_Void(Hook *hook, void *pthis) POST_START() POST_END() + KILL_VECTOR() POP() CHECK_RETURN_STR(); return ret.c_str(); @@ -494,6 +629,9 @@ void *Hook_Cbase_Void(Hook *hook, void *pthis) void *ret=NULL; void *origret=NULL; PUSH_CBASE() + + MAKE_VECTOR() + PRE_START() PRE_END() @@ -506,6 +644,7 @@ void *Hook_Cbase_Void(Hook *hook, void *pthis) POST_START() POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -513,13 +652,15 @@ void *Hook_Cbase_Void(Hook *hook, void *pthis) } -Vector Hook_Vector_Void(Hook *hook, void *pthis) +void Hook_Vector_Void(Hook *hook, Vector *out, void *pthis) { Vector ret; Vector origret; PUSH_VECTOR() + MAKE_VECTOR() + memset(&ret, 0x0, sizeof(Vector)); memset(&origret, 0x0, sizeof(Vector)); @@ -527,52 +668,52 @@ Vector Hook_Vector_Void(Hook *hook, void *pthis) PRE_END() #if defined _WIN32 - origret=reinterpret_cast(hook->func)(pthis, 0); + reinterpret_cast(hook->func)(pthis, 0, &origret); #elif defined __linux__ - origret=reinterpret_cast(hook->func)(pthis); + reinterpret_cast(hook->func)(&origret, pthis); #endif POST_START() POST_END() + KILL_VECTOR() POP() - CHECK_RETURN() - return ret; + CHECK_RETURN_VEC() + memcpy(out, &ret, sizeof(Vector)); } -Vector Hook_Vector_pVector(Hook *hook, void *pthis, Vector *v1) +void Hook_Vector_pVector(Hook *hook, Vector *out, void *pthis, Vector *v1) { Vector ret; Vector origret; PUSH_VECTOR() + MAKE_VECTOR() + P_PTRVECTOR(v1) + memset(&ret, 0x0, sizeof(Vector)); memset(&origret, 0x0, sizeof(Vector)); - cell cv1[3]; - cv1[0]=amx_ftoc2(v1->x); - cv1[1]=amx_ftoc2(v1->y); - cv1[2]=amx_ftoc2(v1->z); - PRE_START() - , MF_PrepareCellArrayA(cv1, 3, false) + , MF_PrepareCellArrayA(reinterpret_cast(v1), 3, false) PRE_END() #if defined _WIN32 - origret=reinterpret_cast(hook->func)(pthis, 0, v1); + reinterpret_cast(hook->func)(pthis, 0, &origret, v1); #elif defined __linux__ - origret=reinterpret_cast(hook->func)(pthis, v1); + reinterpret_cast(hook->func)(&origret, pthis, v1); #endif POST_START() - , MF_PrepareCellArrayA(cv1, 3, false) + , MF_PrepareCellArrayA(reinterpret_cast(v1), 3, false) POST_END() + KILL_VECTOR() POP() - CHECK_RETURN() - return ret; + CHECK_RETURN_VEC() + memcpy(out, &ret, sizeof(Vector)); } @@ -582,14 +723,11 @@ int Hook_Int_pVector(Hook *hook, void *pthis, Vector *v1) int origret=0; PUSH_INT() - cell cv1[3]; - - cv1[0]=amx_ftoc2(v1->x); - cv1[1]=amx_ftoc2(v1->y); - cv1[2]=amx_ftoc2(v1->z); + MAKE_VECTOR() + P_PTRVECTOR(v1) PRE_START() - , MF_PrepareCellArrayA(cv1, 3, false) + , MF_PrepareCellArrayA(reinterpret_cast(v1), 3, false) PRE_END() #if defined _WIN32 @@ -599,9 +737,10 @@ int Hook_Int_pVector(Hook *hook, void *pthis, Vector *v1) #endif POST_START() - , MF_PrepareCellArrayA(cv1, 3, false) + , MF_PrepareCellArrayA(reinterpret_cast(v1), 3, false) POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -613,6 +752,11 @@ void Hook_Void_Entvar_Float_Float(Hook *hook, void *pthis, entvars_t *ev1, float PUSH_VOID() cell cev1=EntvarToIndex(ev1); + MAKE_VECTOR() + P_ENTVAR(ev1, cev1) + P_FLOAT(f1) + P_FLOAT(f2) + PRE_START() , cev1, f1, f2 PRE_END() @@ -627,6 +771,7 @@ void Hook_Void_Entvar_Float_Float(Hook *hook, void *pthis, entvars_t *ev1, float , cev1, f1, f2 POST_END() + KILL_VECTOR() POP() } @@ -636,11 +781,13 @@ int Hook_Int_pFloat_pFloat(Hook *hook, void *pthis, float *f1, float *f2) int origret=0; PUSH_INT() - cell cf1=amx_ftoc2(f1 == NULL ? 0.0 : *f1); - cell cf2=amx_ftoc2(f2 == NULL ? 0.0 : *f2); + + MAKE_VECTOR() + P_PTRFLOAT(f1) + P_PTRFLOAT(f2) PRE_START() - , cf1, cf2 + , f1 != NULL ? *f1 : 0, f2 != NULL ? *f2 : 0 PRE_END() #if defined _WIN32 @@ -650,9 +797,10 @@ int Hook_Int_pFloat_pFloat(Hook *hook, void *pthis, float *f1, float *f2) #endif POST_START() - , cf1, cf2 + , f1 != NULL ? *f1 : 0, f2 != NULL ? *f2 : 0 POST_END() + KILL_VECTOR() POP() CHECK_RETURN() return ret; @@ -663,6 +811,10 @@ void Hook_Void_Entvar_Float(Hook *hook, void *pthis, entvars_t *ev1, float f1) PUSH_VOID() cell cev1=EntvarToIndex(ev1); + MAKE_VECTOR() + P_ENTVAR(ev1, cev1) + P_FLOAT(f1) + PRE_START() , cev1, f1 PRE_END() @@ -676,6 +828,8 @@ void Hook_Void_Entvar_Float(Hook *hook, void *pthis, entvars_t *ev1, float f1) POST_START() , cev1, f1 POST_END() + + KILL_VECTOR() POP() } diff --git a/dlls/hamsandwich/hook_callbacks.h b/dlls/hamsandwich/hook_callbacks.h index cc44a025..bab95b4d 100644 --- a/dlls/hamsandwich/hook_callbacks.h +++ b/dlls/hamsandwich/hook_callbacks.h @@ -49,9 +49,9 @@ const char *Hook_Str_Void(Hook *hook, void *pthis); void *Hook_Cbase_Void(Hook *hook, void *pthis); -Vector Hook_Vector_Void(Hook *hook, void *pthis); +void Hook_Vector_Void(Hook *hook, Vector *out, void *pthis); -Vector Hook_Vector_pVector(Hook *hook, void *pthis, Vector *v1); +void Hook_Vector_pVector(Hook *hook, Vector *out, void *pthis, Vector *v1); int Hook_Int_pVector(Hook *hook, void *pthis, Vector *v1); diff --git a/dlls/hamsandwich/hook_native.cpp b/dlls/hamsandwich/hook_native.cpp index ce6bf139..bac6afd0 100644 --- a/dlls/hamsandwich/hook_native.cpp +++ b/dlls/hamsandwich/hook_native.cpp @@ -77,11 +77,11 @@ hook_t hooklist[] = { 0, 0, "fbecomeprone", false, 0, V(Int_Void) }, // FBecomeProne - // TODO: These - { 0, 0, "center", false, 0, V(Vector_Void) }, // Center - { 0, 0, "eyeposition", false, 0, V(Vector_Void) }, // EyePosition - { 0, 0, "earposition", false, 0, V(Vector_Void) }, // EarPosition - { 0, 0, "bodytarget", false, 1, V(Vector_pVector) }, // BodyTarget + // Vectors are over 2 registers large, so they get passed weird + { 0, 0, "center", true, 1, V(Vector_Void) }, // Center + { 0, 0, "eyeposition", true, 1, V(Vector_Void) }, // EyePosition + { 0, 0, "earposition", true, 1, V(Vector_Void) }, // EarPosition + { 0, 0, "bodytarget", true, 2, V(Vector_pVector) }, // BodyTarget { 0, 0, "illumination", false, 0, V(Int_Void) }, // Illumination { 0, 0, "fvisible", false, 1, V(Int_Cbase) }, // FVisible { 0, 0, "fvecvisible", false, 1, V(Int_pVector) }, // FVecVisible diff --git a/dlls/hamsandwich/include/hamsandwich.inc b/dlls/hamsandwich/include/hamsandwich.inc index 4498ef24..66c6ffea 100644 --- a/dlls/hamsandwich/include/hamsandwich.inc +++ b/dlls/hamsandwich/include/hamsandwich.inc @@ -518,21 +518,29 @@ native ExecuteHam(Ham:function, this, any:...); native ExecuteHamB(Ham:function, this, any:...); +native GetHamReturnStatus(); +native SetHamParamInteger(which, value); +native SetHamParamFloat(which, Float:value); +native SetHamParamVector(which, const Float:value[3]); +native SetHamParamEntity(which, value); +native SetHamParamString(which, const output[]); +native SetHamParamTraceResult(which, tr_handle); + native GetHamReturnInteger(&output); native GetHamReturnFloat(&Float:output); native GetHamReturnVector(Float:output[3]); -native GetHamReturnCbase(&output); +native GetHamReturnEntity(&output); native GetHamReturnString(output[], size); native GetOrigHamReturnInteger(&output); native GetOrigHamReturnFloat(&Float:output); native GetOrigHamReturnVector(Float:output[3]); native GetOrigHamReturnCbase(&output); native GetOrigHamReturnString(output[], size); -native SetHamReturnInteger(output); -native SetHamReturnFloat(Float:output); -native SetHamReturnVector(const Float:output[3]); -native SetHamReturnCbase(output); -native SetHamReturnString(const output[]); +native SetHamReturnInteger(value); +native SetHamReturnFloat(Float:value); +native SetHamReturnVector(const Float:value[3]); +native SetHamReturnEntity(value); +native SetHamReturnString(const value[]); /**