2
0
mirror of https://github.com/rehlds/reapi.git synced 2024-12-28 15:45:31 +03:00

Update reapi sdk

HC_OVERRIDE mark as deprecated
Do safe native GetHookChainReturn
This commit is contained in:
s1lentq 2017-01-06 13:37:45 +07:00
parent adb34bb0ed
commit 30c7a76ca4
4 changed files with 22 additions and 11 deletions

View File

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

View File

@ -56,13 +56,16 @@ enum members_tables_e
#include <reapi_addons> // NOTE: 3-rd party addons
#include <reapi_version>
#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.

View File

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

View File

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