From 30c7a76ca4c1d8af38b042b9e3ab34a9005d67df Mon Sep 17 00:00:00 2001 From: s1lentq Date: Fri, 6 Jan 2017 13:37:45 +0700 Subject: [PATCH] Update reapi sdk HC_OVERRIDE mark as deprecated Do safe native GetHookChainReturn --- .../extra/amxmodx/scripting/include/cssdk_const.inc | 2 ++ reapi/extra/amxmodx/scripting/include/reapi.inc | 11 +++++++---- reapi/src/hook_callback.h | 8 ++++---- reapi/src/natives/natives_hookchains.cpp | 12 +++++++++--- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc index 7177027..6ea5dea 100644 --- a/reapi/extra/amxmodx/scripting/include/cssdk_const.inc +++ b/reapi/extra/amxmodx/scripting/include/cssdk_const.inc @@ -687,6 +687,8 @@ enum RewardType RT_NONE, RT_ROUND_BONUS, RT_PLAYER_RESET, + RT_PLAYER_JOIN, + RT_PLAYER_SPEC_JOIN, RT_PLAYER_BOUGHT_SOMETHING, RT_HOSTAGE_TOOK, RT_HOSTAGE_RESCUED, diff --git a/reapi/extra/amxmodx/scripting/include/reapi.inc b/reapi/extra/amxmodx/scripting/include/reapi.inc index a4ff183..24b9740 100644 --- a/reapi/extra/amxmodx/scripting/include/reapi.inc +++ b/reapi/extra/amxmodx/scripting/include/reapi.inc @@ -56,13 +56,16 @@ enum members_tables_e #include // NOTE: 3-rd party addons #include +#pragma deprecated Use HC_CONTINUE or anything. +#define HC_OVERRIDE 0 + // hookchain return type enum { HC_CONTINUE = 0, // plugin didn't take any action - HC_OVERRIDE, // call real function, but use my return value HC_SUPERCEDE, // skip real function, use my return value - HC_BREAK // skip a call each forward in AMXX plugins + HC_BREAK // skip all forwards and real function, use my return value + // @note Warning: Be very careful using this type of return will skip calls for all following AMXX the plugins. }; // hookchain types @@ -113,7 +116,6 @@ native bool:EnableHookChain(HookChain:hook); /* * Sets the return value of a hookchain. -* This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. * * @param type To specify the type ATYPE_*, look at the enum AType * @param value The value to set the return to. @@ -125,11 +127,12 @@ native SetHookChainReturn(AType:type, any:...); * Gets the return value of the current hookchain. * This has no effect in pre hookchain. * +* @param type To specify the type ATYPE_*, look at the enum AType * @param [maxlen] Max length of string (optional) * @return If an integer or boolean or one byte or float, array or everything else is passed via 1rd argument and more * */ -native any:GetHookChainReturn(any:...); +native any:GetHookChainReturn(AType:type, any:...); /* * Set hookchain argument. diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index f56f7ed..82d5d92 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -4,9 +4,9 @@ enum HookChainState { HC_CONTINUE = 0, // plugin didn't take any action - HC_OVERRIDE, // call real function, but use my return value HC_SUPERCEDE, // skip real function, use my return value HC_BREAK // skip all forwards and real function, use my return value + // @note Warning: Be very careful using this type of return will skip calls for all following AMXX the plugins. }; // api types @@ -236,10 +236,10 @@ NOINLINE R DLLEXPORT _callForward(const hook_t* hook, original_t original, volat auto retVal = original(args...); g_hookCtx = hookCtx; - if (likely(hc_state != HC_OVERRIDE)) + if (unlikely(!hookCtx->retVal.set)) { hookCtx->retVal._integer = *(int *)&retVal; - - hookCtx->retVal.set = true; + hookCtx->retVal.set = true; + } } for (auto fwd : hook->post) { diff --git a/reapi/src/natives/natives_hookchains.cpp b/reapi/src/natives/natives_hookchains.cpp index 1ff2a57..ca545fc 100644 --- a/reapi/src/natives/natives_hookchains.cpp +++ b/reapi/src/natives/natives_hookchains.cpp @@ -100,7 +100,6 @@ cell AMX_NATIVE_CALL DisableHookChain(AMX *amx, cell *params) /* * Sets the return value of a hookchain. -* This needs to be used in conjunction with RH_OVERRIDE or RH_SUPERCEDE. * * @param type To specify the type ATYPE_*, look at the enum AType * @param value The value to set the return to. @@ -164,10 +163,11 @@ cell AMX_NATIVE_CALL SetHookChainReturn(AMX *amx, cell *params) * Gets the return value of the current hookchain. * This has no effect in pre hookchain. * +* @param type To specify the type ATYPE_*, look at the enum AType * @param [maxlen] Max length of string (optional) * @return If an integer or boolean or one byte or float, array or everything else is passed via 1rd argument and more * -* native any:GetHookChainReturn(any:...); +* native any:GetHookChainReturn(AType:type, any:...); */ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) { @@ -177,9 +177,15 @@ cell AMX_NATIVE_CALL GetHookChainReturn(AMX *amx, cell *params) return FALSE; } - enum args_e { arg_count, arg_value, arg_maxlen }; + enum args_e { arg_count, arg_type, arg_value, arg_maxlen }; auto& retVal = g_hookCtx->retVal; + if (unlikely(params[arg_type] != retVal.type)) + { + MF_LogError(amx, AMX_ERR_NATIVE, "%s: trying to set return value with incompatible type.", __FUNCTION__); + return FALSE; + } + if (unlikely(!retVal.set)) { MF_LogError(amx, AMX_ERR_NATIVE, "%s: return value isn't set.", __FUNCTION__);