From 6fb4fc67798cdec65c4454f6a1bbe2974b1faa4c Mon Sep 17 00:00:00 2001 From: asmodai Date: Mon, 6 Jun 2016 17:55:07 +0300 Subject: [PATCH] Fixed names collision with fakemeta Fixed hookctx for recursive hookchain calls --- .../extra/amxmodx/scripting/include/reapi.inc | 8 ++-- .../scripting/include/reapi_engine.inc | 8 ++-- .../scripting/include/reapi_engine_const.inc | 2 +- reapi/src/hook_callback.h | 42 ++++++++++++------- reapi/src/member_list.cpp | 2 +- reapi/src/member_list.h | 4 +- reapi/src/natives/natives_misc.cpp | 8 ++-- 7 files changed, 43 insertions(+), 31 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index 0723fc5..aa1affc 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -113,7 +113,7 @@ native SetHookChainArg(number, AType:type, any:...); * @return 1/0 * */ -native is_rehlds(); +native bool:is_rehlds(); /* * Check if the regamedll is available @@ -121,7 +121,7 @@ native is_rehlds(); * @return 1/0 * */ -native is_regamedll(); +native bool:is_regamedll(); /* * Check if the reunion is available @@ -129,7 +129,7 @@ native is_regamedll(); * @return 1/0 * */ -native is_has_reunion(); +native bool:has_reunion(); /* * Check if the vtc is available @@ -137,7 +137,7 @@ native is_has_reunion(); * @return 1/0 * */ -native is_has_vtc(); +native bool:has_vtc(); /* * This is the callback from the module that gives major/minor versions for verifying compatibility reapi API versions diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc index da3bc09..b9d4a7b 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine.inc @@ -20,15 +20,15 @@ native any:get_entvar(const index, const EntVars:var, any:...); /* * Sets usercmd data. -* Use the var_* EntVars enum +* Use the ucmd_* UCmd enum */ -native set_ucmd(const ucmd, const UserCmd:var, any:...); +native set_ucmd(const ucmd, const UCmd:var, any:...); /* * Returns entvar data from an entity. -* Use the var_* EntVars enum +* Use the ucmd_* UCmd enum */ -native any:get_ucmd(const ucmd, const UserCmd:var, any:...); +native any:get_ucmd(const ucmd, const UCmd:var, any:...); /* * Set name of the map diff --git a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc index 31cedd3..752a1e8 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_engine_const.inc @@ -1024,7 +1024,7 @@ enum EntVars var_euser4 }; -enum UserCmd +enum UCmd { /* * Description: - diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index 4c88ed9..bd31217 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -50,23 +50,41 @@ inline AType getApiType(T *) { return ATYPE_INTEGER; } #define MAX_ARGS 12u +template +void setupArgTypes(AType args_type[MAX_ARGS], T1, T2, T3, T4, t_args... args) +{ + *(uint32 *)&args_type[current] = getApiType(T1()) | (getApiType(T2()) << 8) | (getApiType(T3()) << 16) | (getApiType(T4()) << 24); + if (sizeof...(args) && current + 1 < MAX_ARGS) + setupArgTypes(args_type, args...); +} + +template +void setupArgTypes(AType args_type[MAX_ARGS], T1, T2, T3) +{ + *(uint32 *)&args_type[current] = getApiType(T1()) | (getApiType(T2()) << 8) | (getApiType(T3()) << 16); +} + +template +void setupArgTypes(AType args_type[MAX_ARGS], T1, T2) +{ + *(uint16 *)&args_type[current] = getApiType(T1()) | (getApiType(T2()) << 8); +} + +template +void setupArgTypes(AType args_type[MAX_ARGS], T) +{ + args_type[current] = getApiType(T()); +} + template void setupArgTypes(AType args_type[MAX_ARGS]) { } -template -void setupArgTypes(AType args_type[MAX_ARGS], T, t_args... args) -{ - args_type[current] = getApiType(T()); - if (sizeof...(args) && current + 1 < MAX_ARGS) - setupArgTypes(args_type, args...); -} - struct hookctx_t { template - hookctx_t(size_t arg_count, t_args... args) : args_ptr() + hookctx_t(size_t arg_count, t_args... args) { args_count = min(arg_count, MAX_ARGS); setupArgTypes(args_type, args...); @@ -128,9 +146,6 @@ NOINLINE void DLLEXPORT _callVoidForward(const hook_t* hook, original_t original template void callVoidForward(size_t func, original_t original, f_args... args) { -#ifndef _WIN32 - static -#endif hookctx_t hookCtx(sizeof...(args), args...); g_hookCtx = &hookCtx; @@ -193,9 +208,6 @@ NOINLINE R DLLEXPORT _callForward(const hook_t* hook, original_t original, volat template R callForward(size_t func, original_t original, f_args... args) { -#ifndef _WIN32 - static -#endif hookctx_t hookCtx(sizeof...(args), args...); g_hookCtx = &hookCtx; diff --git a/reapi/src/member_list.cpp b/reapi/src/member_list.cpp index 5edfcee..fe2f38a 100644 --- a/reapi/src/member_list.cpp +++ b/reapi/src/member_list.cpp @@ -3,7 +3,7 @@ #define CLASS_MEMBERS(cx, mx, pref) ((!(pref##mx & (MAX_REGION_RANGE - 1)) ? regmember::current_cell = 1, true : false) || (pref##mx & (MAX_REGION_RANGE - 1)) == regmember::current_cell++) ? regmember([](member_t* ptr){ decltype(##cx::##mx) f = {};ptr->size = getTypeSize(f);ptr->max_size = sizeof(f);ptr->offset = offsetof(##cx, ##mx);ptr->type = getMemberType(f);}) : regmember(#mx) #define GM_MEMBERS(mx) CLASS_MEMBERS(CHalfLifeMultiplay, mx,) -#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CVoiceGameMgr, mx,) +#define GM_VOICE_MEMBERS(mx) CLASS_MEMBERS(CVoiceGameMgr, mx,) #define BASE_MEMBERS(mx) CLASS_MEMBERS(CBaseEntity, mx,) #define ANIM_MEMBERS(mx) CLASS_MEMBERS(CBaseAnimating, mx,) #define MONST_MEMBERS(mx) CLASS_MEMBERS(CBaseMonster, mx,) diff --git a/reapi/src/member_list.h b/reapi/src/member_list.h index 07eba09..4ce0385 100644 --- a/reapi/src/member_list.h +++ b/reapi/src/member_list.h @@ -5,7 +5,7 @@ // member types enum MType { - MEMBER_FLOAT = 0, // Any floating popm_value + MEMBER_FLOAT = 0, // Any floating point value MEMBER_DOUBLE, // double value MEMBER_ENTITY, // An entity offset (EOFFSET) MEMBER_CLASSPTR, // CBaseEntity * @@ -13,7 +13,7 @@ enum MType MEMBER_EVARS, // EVARS * MEMBER_EDICT, // edict_t *, or edict_t * (same thing) MEMBER_VECTOR, // Any vector - MEMBER_STRING, // pm_*, pm_[] + MEMBER_STRING, // char *, char [] MEMBER_QSTRING, // quake string, like string_t MEMBER_RSTRING, // reverse of qstring to string MEMBER_INTEGER, // Any integer or enum diff --git a/reapi/src/natives/natives_misc.cpp b/reapi/src/natives/natives_misc.cpp index 4f9b4d9..aa27b06 100644 --- a/reapi/src/natives/natives_misc.cpp +++ b/reapi/src/natives/natives_misc.cpp @@ -1330,7 +1330,7 @@ cell AMX_NATIVE_CALL is_regamedll(AMX *amx, cell *params) * * native is_has_reunion(); */ -cell AMX_NATIVE_CALL is_has_reunion(AMX *amx, cell *params) +cell AMX_NATIVE_CALL has_reunion(AMX *amx, cell *params) { return (cell)api_cfg.hasReunion(); } @@ -1342,7 +1342,7 @@ cell AMX_NATIVE_CALL is_has_reunion(AMX *amx, cell *params) * * native is_has_vtc(); */ -cell AMX_NATIVE_CALL is_has_vtc(AMX *amx, cell *params) +cell AMX_NATIVE_CALL has_vtc(AMX *amx, cell *params) { return (cell)api_cfg.hasVTC(); } @@ -1351,8 +1351,8 @@ AMX_NATIVE_INFO Misc_Natives_Checks[] = { { "is_rehlds", is_rehlds }, { "is_regamedll", is_regamedll }, - { "is_has_reunion", is_has_reunion }, - { "is_has_vtc", is_has_vtc } + { "has_reunion", has_reunion }, + { "has_vtc", has_vtc } }; void RegisterNatives_Misc()