Added the ability to change parameters on the fly.

Added GetHamReturnStatus()
This commit is contained in:
Steve Dudenhoeffer 2007-05-09 14:58:55 +00:00
parent f747acdc7c
commit 5fc89085d6
7 changed files with 410 additions and 97 deletions

View File

@ -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(&params[1]);
int ret=dat->SetEntity(&params[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<Data *> *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(&params[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<Data *> *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(&params[2]);
PARSE_RETURN();
}
static cell AMX_NATIVE_CALL SetHamParamFloat(AMX *amx, cell *params)
{
CHECK_STACK(ParamStack);
CVector<Data *> *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(&params[2]);
PARSE_RETURN();
}
static cell AMX_NATIVE_CALL SetHamParamVector(AMX *amx, cell *params)
{
CHECK_STACK(ParamStack);
CVector<Data *> *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<Data *> *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(&params[2]);
PARSE_RETURN();
}
static cell AMX_NATIVE_CALL SetHamParamString(AMX *amx, cell *params)
{
CHECK_STACK(ParamStack);
CVector<Data *> *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 },
};

View File

@ -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<int *>(m_data))=*data;
return 0;
}
else if (IsType(RET_TRACE))
{
*(reinterpret_cast<int *>(m_data))=*data;
return 0;
}
*(reinterpret_cast<int *>(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<void **>(m_data))=IndexToPrivate(*data);
if (m_index != 0)
{
*m_index=*data;
}
return 0;
}
else if (IsType(RET_ENTVAR))
{
*(reinterpret_cast<entvars_t **>(m_data))=IndexToEntvar(*data);
if (m_index != 0)
{
*m_index=*data;
}
*(reinterpret_cast<void **>(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<int *>(m_data));
*data=*(reinterpret_cast<int *>(m_data));
return 0;
return 0;
}
else if (IsType(RET_TRACE))
{
*data=*(reinterpret_cast<int *>(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<entvars_t *>(m_data));
return 0;
}
return -1;
}
};
extern CStack< Data * > ReturnStack;
extern CStack< Data * > OrigReturnStack;
extern CStack< CVector< Data * > * > ParamStack;
extern CStack< int * > ReturnStatus;
#endif

View File

@ -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)
{

View File

@ -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<Data *> *__vec=new CVector<Data *>; \
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<int *>(& (__INDEX))));
#define P_ENTVAR(__PARAM, __INDEX) __vec->push_back(new Data(RET_ENTVAR, (void *) & (__PARAM), reinterpret_cast<int *>(& (__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<Data *>::iterator end=__vec->end(); \
for (CVector<Data *>::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<Forward*>::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<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, a.c_str(), i2);
#elif defined __linux__
origret=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, 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<cell *>(&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<cell *>(&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<cell *>(&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<cell *>(&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<Vector (__fastcall*)(void*, int)>(hook->func)(pthis, 0);
reinterpret_cast<void (__fastcall*)(void*, int, Vector *)>(hook->func)(pthis, 0, &origret);
#elif defined __linux__
origret=reinterpret_cast<Vector (*)(void*)>(hook->func)(pthis);
reinterpret_cast<void (*)(Vector *, void*)>(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<cell *>(v1), 3, false)
PRE_END()
#if defined _WIN32
origret=reinterpret_cast<Vector (__fastcall*)(void*, int, Vector *)>(hook->func)(pthis, 0, v1);
reinterpret_cast<void (__fastcall*)(void*, int, Vector *, Vector *)>(hook->func)(pthis, 0, &origret, v1);
#elif defined __linux__
origret=reinterpret_cast<Vector (*)(void*, Vector *)>(hook->func)(pthis, v1);
reinterpret_cast<void (*)(Vector *, void*, Vector *)>(hook->func)(&origret, pthis, v1);
#endif
POST_START()
, MF_PrepareCellArrayA(cv1, 3, false)
, MF_PrepareCellArrayA(reinterpret_cast<cell *>(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<cell *>(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<cell *>(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()
}

View File

@ -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);

View File

@ -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

View File

@ -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[]);
/**