mirror of
https://github.com/rehlds/reapi.git
synced 2024-12-29 08:05:36 +03:00
Fix crash: Use AMXX_Error instead LogError.
This commit is contained in:
parent
becdfd768b
commit
8a03dc1cc3
@ -45,9 +45,9 @@ static struct funcreq_t
|
|||||||
//DECLARE_REQ(GetAmxVectorNull),
|
//DECLARE_REQ(GetAmxVectorNull),
|
||||||
//DECLARE_REQ(PrintSrvConsole),
|
//DECLARE_REQ(PrintSrvConsole),
|
||||||
//DECLARE_REQ(GetModname),
|
//DECLARE_REQ(GetModname),
|
||||||
//DECLARE_REQ(GetAmxScriptName),
|
DECLARE_REQ(GetAmxScriptName),
|
||||||
//DECLARE_REQ(GetAmxScript),
|
//DECLARE_REQ(GetAmxScript),
|
||||||
//DECLARE_REQ(FindAmxScriptByAmx),
|
DECLARE_REQ(FindAmxScriptByAmx),
|
||||||
//DECLARE_REQ(FindAmxScriptByName),
|
//DECLARE_REQ(FindAmxScriptByName),
|
||||||
DECLARE_REQ(SetAmxString),
|
DECLARE_REQ(SetAmxString),
|
||||||
//DECLARE_REQ(SetAmxStringUTF8Char),
|
//DECLARE_REQ(SetAmxStringUTF8Char),
|
||||||
@ -219,6 +219,24 @@ NOINLINE void MF_LogError(AMX *amx, int err, const char *fmt, ...)
|
|||||||
g_amxxapi.LogError(amx, err, "[%s] %s", g_ModuleInfo.logtag, msg);
|
g_amxxapi.LogError(amx, err, "[%s] %s", g_ModuleInfo.logtag, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NOINLINE void AMXX_Error(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, '\\')))
|
||||||
|
scriptName++;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_amxxapi.Log("[%s] %s", scriptName, msg);
|
||||||
|
}
|
||||||
|
|
||||||
char* getAmxStringTemp(cell* src, char* dest, size_t max, size_t* len)
|
char* getAmxStringTemp(cell* src, char* dest, size_t max, size_t* len)
|
||||||
{
|
{
|
||||||
char* start = dest;
|
char* start = dest;
|
||||||
|
@ -493,6 +493,7 @@ extern amxxapi_t g_amxxapi;
|
|||||||
|
|
||||||
void MF_Log(const char *fmt, ...);
|
void MF_Log(const char *fmt, ...);
|
||||||
void MF_LogError(AMX *amx, int err, const char *fmt, ...);
|
void MF_LogError(AMX *amx, int err, const char *fmt, ...);
|
||||||
|
void AMXX_Error(AMX *amx, const char *fmt, ...);
|
||||||
char* getAmxStringTemp(cell* src, char* dest, size_t max, size_t* len = nullptr);
|
char* getAmxStringTemp(cell* src, char* dest, size_t max, size_t* len = nullptr);
|
||||||
void setAmxString(cell* dest, const char* string, size_t max);
|
void setAmxString(cell* dest, const char* string, size_t max);
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ NOINLINE R DLLEXPORT _callForward(const hook_t* hook, original_t original, volat
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(!hookCtx->retVal.set)) {
|
if (unlikely(!hookCtx->retVal.set)) {
|
||||||
g_amxxapi.LogError(fwd->GetAmx(), AMX_ERR_CALLBACK, "can't suppress original function call without new return value set");
|
AMXX_Error(fwd->GetAmx(), "%s : Can't suppress original function call without new return value set", fwd->GetCallbackName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
CHookManager g_hookManager;
|
CHookManager g_hookManager;
|
||||||
|
|
||||||
int CHookManager::addHandler(AMX* amx, int func, int forward, bool post) const
|
int CHookManager::addHandler(AMX* amx, int func, const char *funcname, int forward, bool post) const
|
||||||
{
|
{
|
||||||
auto hook = m_hooklist.getHookSafe(func);
|
auto hook = m_hooklist.getHookSafe(func);
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ int CHookManager::addHandler(AMX* amx, int func, int forward, bool post) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto& dest = post ? hook->post : hook->pre;
|
auto& dest = post ? hook->post : hook->pre;
|
||||||
dest.push_back(new CAmxxHook(amx, forward));
|
dest.push_back(new CAmxxHook(amx, funcname, forward));
|
||||||
int id = func * MAX_HOOK_FORWARDS + dest.size();
|
int id = func * MAX_HOOK_FORWARDS + dest.size();
|
||||||
return post ? -id : id; // use unsigned ids for post hooks
|
return post ? -id : id; // use unsigned ids for post hooks
|
||||||
}
|
}
|
||||||
@ -23,6 +23,11 @@ AMX* CAmxxHook::GetAmx() const
|
|||||||
return m_amx;
|
return m_amx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *CAmxxHook::GetCallbackName() const
|
||||||
|
{
|
||||||
|
return m_CallbackName;
|
||||||
|
}
|
||||||
|
|
||||||
int CAmxxHook::GetIndex() const
|
int CAmxxHook::GetIndex() const
|
||||||
{
|
{
|
||||||
return m_index;
|
return m_index;
|
||||||
|
@ -12,15 +12,22 @@ enum fwdstate
|
|||||||
class CAmxxHook
|
class CAmxxHook
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CAmxxHook(AMX* amx, int index) : m_index(index), m_state(FSTATE_ENABLED), m_amx(amx) {};
|
CAmxxHook(AMX* amx, const char *funcname, int index) : m_index(index), m_state(FSTATE_ENABLED), m_amx(amx)
|
||||||
|
{
|
||||||
|
strncpy(m_CallbackName, funcname, sizeof(m_CallbackName) - 1);
|
||||||
|
m_CallbackName[sizeof(m_CallbackName) - 1] = '\0';
|
||||||
|
};
|
||||||
|
|
||||||
int GetIndex() const;
|
int GetIndex() const;
|
||||||
fwdstate GetState() const;
|
fwdstate GetState() const;
|
||||||
AMX* GetAmx() const;
|
AMX* GetAmx() const;
|
||||||
|
const char *GetCallbackName() const;
|
||||||
|
|
||||||
void SetState(fwdstate st);
|
void SetState(fwdstate st);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_index;
|
int m_index;
|
||||||
|
char m_CallbackName[64];
|
||||||
fwdstate m_state;
|
fwdstate m_state;
|
||||||
AMX* m_amx;
|
AMX* m_amx;
|
||||||
};
|
};
|
||||||
@ -29,7 +36,7 @@ class CHookManager
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void clearHandlers() const;
|
void clearHandlers() const;
|
||||||
cell addHandler(AMX* amx, int func, int forward, bool post) const;
|
cell addHandler(AMX* amx, int func, const char *funcname, int forward, bool post) const;
|
||||||
hook_t* getHook(size_t func) const;
|
hook_t* getHook(size_t func) const;
|
||||||
CAmxxHook* getAmxxHook(cell hook) const;
|
CAmxxHook* getAmxxHook(cell hook) const;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ cell AMX_NATIVE_CALL RegisterHookChain(AMX *amx, cell *params)
|
|||||||
return INVALID_HOOKCHAIN;
|
return INVALID_HOOKCHAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
return g_hookManager.addHandler(amx, func, fwid, post != 0);
|
return g_hookManager.addHandler(amx, func, funcname, fwid, post != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user