From 68196d694d879e0367b995d11e1d4807d4852438 Mon Sep 17 00:00:00 2001 From: s1lentq Date: Thu, 22 Apr 2021 22:47:20 +0700 Subject: [PATCH] hook_list.cpp: Reworked argument parser reapi_gamedll_const.inc: fix AMXX compiler warning --- .../scripting/include/reapi_gamedll_const.inc | 3 + reapi/src/hook_list.cpp | 74 ++++++++++--------- 2 files changed, 44 insertions(+), 33 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc index 71bece9..c578af1 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi_gamedll_const.inc @@ -34,6 +34,9 @@ #define m_Shield_hEntToIgnoreTouchesFrom m_Shield_EntToIgnoreTouchesFrom #define RG_CBasePlayer_RemoveSpawnProtection RG_CBasePlayer_RemoveProtection #define RG_CBasePlayer_SetSpawnProtection RG_CBasePlayer_SetProtection + #define RG_CBasePlayerWeapon_DefaultDeploy RG_CBaseWeapon_DefDeploy + #define RG_CBasePlayerWeapon_DefaultReload RG_CBaseWeapon_DefReload + #define RG_CBasePlayerWeapon_DefaultShotgunReload RG_CBaseWeapon_DefShotgunReload #endif /** diff --git a/reapi/src/hook_list.cpp b/reapi/src/hook_list.cpp index 36e307b..568293e 100644 --- a/reapi/src/hook_list.cpp +++ b/reapi/src/hook_list.cpp @@ -20,45 +20,53 @@ inline size_t getFwdParamType(void(*)(const char *)) { return FP_STRI inline size_t getFwdParamType(void(*)(char *)) { return FP_STRING; } inline size_t getFwdParamType(void(*)(IResourceBuffer*)) { return FP_CELL; } -template +template inline size_t getFwdParamType(void(*)(T *)) { return FP_CELL; } -template -void setupParamTypes(size_t param_types[], void (*)()) -{ - param_types[current] = FP_DONE; -} - -template -void setupParamTypes(size_t param_types[], void(*)(T, t_args...)) -{ - void (*func)(T) = nullptr; - param_types[current] = getFwdParamType(func); - void (*next)(t_args...) = nullptr; - setupParamTypes(param_types, next); -} - -template -struct regargs -{ - regargs(void (*)(f_args...)) - { - void (*func)(f_args...) = nullptr; - setupParamTypes(types, func); - } - - size_t types[sizeof...(f_args) + 1]; // + FP_DONE -}; - struct regfunc { - template + template + struct regargs + { + regargs() + { + void (*func)(f_args...) = nullptr; + setArgs(args, func); + } + + template + int Register(AMX *amx, const char *name, std::index_sequence) const + { + return g_amxxapi.RegisterSPForwardByName(amx, name, args[Is]...); + } + + protected: + template + void setArgs(size_t param_types[], void (*)()) + { + param_types[current] = FP_DONE; + } + + template + void setArgs(size_t param_types[], void (*)(T, t_args...)) + { + void (*func)(T) = nullptr; + param_types[current] = getFwdParamType(func); + void (*next)(t_args...) = nullptr; + setArgs(param_types, next); + } + + private: + size_t args[sizeof...(f_args) + 1]; // + FP_DONE + }; + + template regfunc(R (*)(T, f_args...)) { - func = [](AMX *amx, const char *name) { - void (*func)(f_args...) = nullptr; - regargs args(func); - return g_amxxapi.RegisterSPForwardByName(amx, name, args); + func = [](AMX *amx, const char *name) + { + regargs args; + return args.Register(amx, name, std::make_index_sequence{}); }; }