diff --git a/amxmodx/debugger.cpp b/amxmodx/debugger.cpp index e0f29ec8..90d5729a 100755 --- a/amxmodx/debugger.cpp +++ b/amxmodx/debugger.cpp @@ -935,8 +935,9 @@ int Handler::HandleModule(const char *module) */ cell hea_addr, *phys_addr, retval; + Debugger *pd; - DisableDebugHandler(m_pAmx); + pd = DisableDebugHandler(m_pAmx); //temporarily set prenit m_pAmx->flags |= AMX_FLAG_PRENIT; @@ -945,7 +946,7 @@ int Handler::HandleModule(const char *module) amx_Release(m_pAmx, hea_addr); m_pAmx->flags &= ~AMX_FLAG_PRENIT; - EnableDebugHandler(m_pAmx); + EnableDebugHandler(m_pAmx, pd); if (err != AMX_ERR_NONE) return 0; @@ -1012,7 +1013,7 @@ int Handler::HandleNative(const char *native, int index, int trap) if (pDebugger && trap) pDebugger->EndExec(); else if (pDebugger && !trap) - EnableDebugHandler(m_pAmx); + EnableDebugHandler(m_pAmx, pDebugger); amx_Release(m_pAmx, hea_addr); diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index 3846a851..7df0d412 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -454,7 +454,8 @@ int set_amxnatives(AMX* amx, char error[128]) int idx, err; cell retval; - DisableDebugHandler(amx); + Debugger *pd; + pd = DisableDebugHandler(amx); if (amx_FindPublic(amx, "plugin_natives", &idx) == AMX_ERR_NONE) { @@ -465,7 +466,7 @@ int set_amxnatives(AMX* amx, char error[128]) } } - EnableDebugHandler(amx); + EnableDebugHandler(amx, pd); amx->flags &= ~(AMX_FLAG_PRENIT); @@ -1783,20 +1784,24 @@ void *Module_ReqFnptr(const char *funcName) return NULL; } -void DisableDebugHandler(AMX *amx) +Debugger *DisableDebugHandler(AMX *amx) { + Debugger *pd = static_cast(amx->userdata[UD_DEBUGGER]); + + amx->userdata[UD_DEBUGGER] = NULL; + amx->flags &= ~(AMX_FLAG_DEBUG); amx_SetDebugHook(amx, NULL); + + return pd; } -void EnableDebugHandler(AMX *amx) +void EnableDebugHandler(AMX *amx, Debugger *pd) { - if (amx->flags & AMX_FLAG_DEBUG) - { - if (amx->userdata[UD_DEBUGGER] != NULL) - { - amx_SetDebugHook(amx, &Debugger::DebugHook); - } - } + if (pd) + amx->flags |= AMX_FLAG_DEBUG; + + amx->userdata[UD_DEBUGGER] = pd; + amx_SetDebugHook(amx, &Debugger::DebugHook); } #if !defined MEMORY_TEST && !defined WIN32 diff --git a/amxmodx/modules.h b/amxmodx/modules.h index 05895548..4019bc34 100755 --- a/amxmodx/modules.h +++ b/amxmodx/modules.h @@ -73,8 +73,11 @@ typedef enum int CheckModules(AMX *amx, char error[128]); const char *StrCaseStr(const char *as, const char *bs); -void DisableDebugHandler(AMX *amx); -void EnableDebugHandler(AMX *amx); + +class Debugger; +Debugger *DisableDebugHandler(AMX *amx); +void EnableDebugHandler(AMX *amx, Debugger *pd); + const char* GetFileName(AMX *amx); #endif // __MODULES_H__