2
0
mirror of https://github.com/rehlds/reapi.git synced 2025-01-13 23:28:07 +03:00

Add new return type for amxx forwards

This commit is contained in:
s1lentq 2024-08-07 17:55:49 +07:00
parent 8f9e7c16cb
commit 592ebca528
2 changed files with 26 additions and 15 deletions

View File

@ -120,8 +120,11 @@ enum
{
HC_CONTINUE = 0, // Plugin didn't take any action
HC_SUPERCEDE, // Skip real function, use my return value
HC_BREAK // Skip all forwards and 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 plugins
HC_BYPASS // Skip calls for all following AMXX plugins, but call the original function
// @note Warning: In PRE skips all forwards including POST forwards
};
/**

View File

@ -5,10 +5,13 @@
// hookchain return type
enum HookChainState
{
HC_CONTINUE = 0, // plugin didn't take any action
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.
HC_CONTINUE = 0, // Plugin didn't take any action
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
HC_BYPASS // Skip calls for all following AMXX plugins, but call the original function
// @note Warning: In PRE skips all forwards including POST forwards
};
// api types
@ -168,15 +171,17 @@ NOINLINE void DLLEXPORT _callVoidForward(hook_t* hook, original_t original, f_ar
if (likely(fwd->GetState() == FSTATE_ENABLED))
{
hookCtx->SetId(fwd->GetIndex()); // set current handler hook
auto ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
int ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
hookCtx->ResetId();
if (unlikely(ret == HC_BREAK)) {
if (unlikely(ret == HC_BREAK))
return;
}
if (unlikely(ret > hc_state))
hc_state = ret;
if (unlikely(ret == HC_BYPASS))
break;
}
}
@ -187,16 +192,19 @@ NOINLINE void DLLEXPORT _callVoidForward(hook_t* hook, original_t original, f_ar
hook->wasCalled = true;
}
for (auto fwd : hook->post)
if (hc_state != HC_BYPASS)
{
if (likely(fwd->GetState() == FSTATE_ENABLED))
for (auto fwd : hook->post)
{
hookCtx->SetId(fwd->GetIndex()); // set current handler hook
auto ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
hookCtx->ResetId();
if (likely(fwd->GetState() == FSTATE_ENABLED))
{
hookCtx->SetId(fwd->GetIndex()); // set current handler hook
int ret = g_amxxapi.ExecuteForward(fwd->GetFwdIndex(), std::forward<f_args &&>(args)...);
hookCtx->ResetId();
if (unlikely(ret == HC_BREAK))
break;
if (unlikely(ret == HC_BREAK || ret == HC_BYPASS))
break;
}
}
}