diff --git a/reapi/msvc/reapi.vcxproj b/reapi/msvc/reapi.vcxproj index f9d5fa4..5cc0a5a 100644 --- a/reapi/msvc/reapi.vcxproj +++ b/reapi/msvc/reapi.vcxproj @@ -250,6 +250,7 @@ + diff --git a/reapi/msvc/reapi.vcxproj.filters b/reapi/msvc/reapi.vcxproj.filters index 1025ad2..cc96346 100644 --- a/reapi/msvc/reapi.vcxproj.filters +++ b/reapi/msvc/reapi.vcxproj.filters @@ -824,6 +824,9 @@ src + + src + diff --git a/reapi/src/amx_hook.cpp b/reapi/src/amx_hook.cpp new file mode 100644 index 0000000..59fbb26 --- /dev/null +++ b/reapi/src/amx_hook.cpp @@ -0,0 +1,37 @@ +#include "precompiled.h" + +CAmxxHookBase::CAmxxHookBase(AMX *amx, const char *funcname, int index) : + m_index(index), + m_state(FSTATE_ENABLED), + m_amx(amx) +{ + Q_strlcpy(m_CallbackName, funcname); +} + +CAmxxHookBase::~CAmxxHookBase() +{ + if (m_index != -1) + { + g_amxxapi.UnregisterSPForward(m_index); + m_index = -1; + } +} + +void CAmxxHookBase::Error(int error, const char *fmt, ...) +{ + va_list argptr; + static char string[1024]; + va_start(argptr, fmt); + vsprintf(string, fmt, argptr); + va_end(argptr); + + auto scriptName = g_amxxapi.GetAmxScriptName(g_amxxapi.FindAmxScriptByAmx(m_amx)); + if (scriptName) + { + if ((scriptName = strrchr(scriptName, CORRECT_PATH_SEPARATOR))) + scriptName++; + } + + g_amxxapi.Log("Run time error %d (plugin \"%s\") (forward \"%s\")", error, scriptName, m_CallbackName); + g_amxxapi.Log("%s", string); +} diff --git a/reapi/src/amx_hook.h b/reapi/src/amx_hook.h index 8739b49..a43fae3 100644 --- a/reapi/src/amx_hook.h +++ b/reapi/src/amx_hook.h @@ -11,21 +11,8 @@ enum fwdstate class CAmxxHookBase { public: - ~CAmxxHookBase() - { - if (m_index != -1) { - g_amxxapi.UnregisterSPForward(m_index); - m_index = -1; - } - } - - CAmxxHookBase(AMX *amx, const char *funcname, int index) : - m_index(index), - m_state(FSTATE_ENABLED), - m_amx(amx) - { - Q_strlcpy(m_CallbackName, funcname); - } + ~CAmxxHookBase(); + CAmxxHookBase(AMX *amx, const char *funcname, int index); int GetIndex() const { return m_index; } fwdstate GetState() const { return m_state; } @@ -33,6 +20,7 @@ public: const char *GetCallbackName() const { return m_CallbackName; } void SetState(fwdstate st) { m_state = st; } + void Error(int error, const char *fmt, ...); private: int m_index; diff --git a/reapi/src/amxxmodule.cpp b/reapi/src/amxxmodule.cpp index a8d3478..0b5c8fc 100644 --- a/reapi/src/amxxmodule.cpp +++ b/reapi/src/amxxmodule.cpp @@ -221,24 +221,6 @@ NOINLINE void AMXX_LogError(AMX *amx, int err, const char *fmt, ...) g_amxxapi.LogError(amx, err, "[%s] %s", g_ModuleInfo.logtag, msg); } -NOINLINE void AMXX_Assert(AMX *amx, const char *fmt, ...) -{ - char msg[2048]; - va_list arglst; - va_start(arglst, fmt); - vsnprintf(msg, sizeof msg, fmt, arglst); - va_end(arglst); - - auto scriptName = g_amxxapi.GetAmxScriptName(g_amxxapi.FindAmxScriptByAmx(amx)); - if (scriptName) - { - if ((scriptName = strrchr(scriptName, CORRECT_PATH_SEPARATOR))) - scriptName++; - } - - g_amxxapi.LogError(amx, AMX_ERR_ASSERT, "[%s] %s", scriptName, msg); -} - char* getAmxString(cell* src, char* dest, size_t max, size_t* len) { char* start = dest; diff --git a/reapi/src/amxxmodule.h b/reapi/src/amxxmodule.h index c83a6fd..c3b0a4f 100644 --- a/reapi/src/amxxmodule.h +++ b/reapi/src/amxxmodule.h @@ -493,7 +493,6 @@ extern amxxapi_t g_amxxapi; void AMXX_Log(const char *fmt, ...); void AMXX_LogError(AMX *amx, int err, const char *fmt, ...); -void AMXX_Assert(AMX *amx, const char *fmt, ...); char* getAmxString(cell* src, char* dest, size_t max, size_t* len = nullptr); void setAmxString(cell* dest, const char* string, size_t max); diff --git a/reapi/src/hook_callback.h b/reapi/src/hook_callback.h index b29a4a9..83f60dd 100644 --- a/reapi/src/hook_callback.h +++ b/reapi/src/hook_callback.h @@ -215,7 +215,7 @@ NOINLINE R DLLEXPORT _callForward(const hook_t* hook, original_t original, f_arg } if (unlikely(!hookCtx->retVal.set)) { - AMXX_Assert(fwd->GetAmx(), "%s : Can't suppress original function call without new return value set", fwd->GetCallbackName()); + fwd->Error(AMX_ERR_ASSERT, "Can't suppress original function call without new return value set"); continue; }