diff --git a/core/AMBuilder b/core/AMBuilder index 9d9480ed..54d8a838 100644 --- a/core/AMBuilder +++ b/core/AMBuilder @@ -86,7 +86,6 @@ for i in SM.sdkInfo: 'smn_core.cpp', 'smn_hudtext.cpp', 'smn_usermsgs.cpp', - 'DebugReporter.cpp', 'MenuStyle_Base.cpp', 'ShareSys.cpp', 'smn_database.cpp', diff --git a/core/ForwardSys.cpp b/core/ForwardSys.cpp index 09b2b9f6..e85be0c1 100644 --- a/core/ForwardSys.cpp +++ b/core/ForwardSys.cpp @@ -35,7 +35,7 @@ #include "ForwardSys.h" #include "PluginSys.h" #include "ShareSys.h" -#include "DebugReporter.h" +#include "logic_bridge.h" CForwardManager g_Forwards; @@ -356,7 +356,7 @@ int CForward::Execute(cell_t *result, IForwardFilter *filter) if (err != SP_ERROR_NONE) { - g_DbgReporter.GenerateError(func->GetParentContext(), + logicore.GenerateError(func->GetParentContext(), func->GetFunctionID(), err, "Failed to push parameter while executing forward"); diff --git a/core/logic/AMBuilder b/core/logic/AMBuilder index 69d2f56d..e3817c2f 100644 --- a/core/logic/AMBuilder +++ b/core/logic/AMBuilder @@ -49,7 +49,8 @@ files = [ 'smn_gameconfigs.cpp', 'GameConfigs.cpp', 'sm_crc32.cpp', - 'smn_profiler.cpp' + 'smn_profiler.cpp', + 'DebugReporter.cpp' ] if AMBuild.target['platform'] == 'windows': files.append('thread/WinThreads.cpp') diff --git a/core/DebugReporter.cpp b/core/logic/DebugReporter.cpp similarity index 63% rename from core/DebugReporter.cpp rename to core/logic/DebugReporter.cpp index 86a37065..54fc155c 100644 --- a/core/DebugReporter.cpp +++ b/core/logic/DebugReporter.cpp @@ -29,10 +29,8 @@ * Version: $Id$ */ +#include #include "DebugReporter.h" -#include "Logger.h" -#include "PluginSys.h" -#include "sm_stringutil.h" DebugReport g_DbgReporter; @@ -47,10 +45,10 @@ void DebugReport::OnDebugSpew(const char *msg, ...) char buffer[512]; va_start(ap, msg); - UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap); + smcore.FormatArgs(buffer, sizeof(buffer), msg, ap); va_end(ap); - g_Logger.LogMessage("[SM] %s", buffer); + smcore.Log("[SM] %s", buffer); } void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, const char *message, ...) @@ -65,19 +63,19 @@ void DebugReport::GenerateError(IPluginContext *ctx, cell_t func_idx, int err, c void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, const char *message, va_list ap) { char buffer[512]; - UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); + smcore.FormatArgs(buffer, sizeof(buffer), message, ap); - const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename(); + const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename(); const char *error = g_pSourcePawn2->GetErrorString(err); if (error) { - g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error); + smcore.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error); } else { - g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err); + smcore.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err); } - g_Logger.LogError("[SM] %s", buffer); + smcore.LogError("[SM] %s", buffer); if (func_idx != -1) { @@ -87,7 +85,7 @@ void DebugReport::GenerateErrorVA(IPluginContext *ctx, cell_t func_idx, int err, sp_public_t *function; if (ctx->GetRuntime()->GetPublicByIndex(func_idx, &function) == SP_ERROR_NONE) { - g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name); + smcore.LogError("[SM] Unable to call function \"%s\" due to above error(s).", function->name); } } } @@ -99,26 +97,26 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr char buffer[512]; va_start(ap, message); - UTIL_FormatArgs(buffer, sizeof(buffer), message, ap); + smcore.FormatArgs(buffer, sizeof(buffer), message, ap); va_end(ap); - const char *plname = g_PluginSys.FindPluginByContext(pContext->GetContext())->GetFilename(); + const char *plname = pluginsys->FindPluginByContext(pContext->GetContext())->GetFilename(); const char *error = g_pSourcePawn2->GetErrorString(err); if (error) { - g_Logger.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error); + smcore.LogError("[SM] Plugin \"%s\" encountered error %d: %s", plname, err, error); } else { - g_Logger.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err); + smcore.LogError("[SM] Plugin \"%s\" encountered unknown error %d", plname, err); } - g_Logger.LogError("[SM] %s", buffer); + smcore.LogError("[SM] %s", buffer); IPluginDebugInfo *pDebug; if ((pDebug = pContext->GetRuntime()->GetDebugInfo()) == NULL) { - g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname); - g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on", + smcore.LogError("[SM] Debug mode is not enabled for \"%s\"", plname); + smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on", _GetPluginIndex(pContext)); return; } @@ -126,21 +124,21 @@ void DebugReport::GenerateCodeError(IPluginContext *pContext, uint32_t code_addr const char *name; if (pDebug->LookupFunction(code_addr, &name) == SP_ERROR_NONE) { - g_Logger.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name); + smcore.LogError("[SM] Unable to call function \"%s\" due to above error(s).", name); } else { - g_Logger.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr); + smcore.LogError("[SM] Unable to call function (name unknown, address \"%x\").", code_addr); } } void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *error) { const char *lastname; - const char *plname = g_PluginSys.FindPluginByContext(ctx->GetContext())->GetFilename(); + const char *plname = pluginsys->FindPluginByContext(ctx->GetContext())->GetFilename(); int n_err = error->GetErrorCode(); if (n_err != SP_ERROR_NATIVE) { - g_Logger.LogError("[SM] Plugin encountered error %d: %s", + smcore.LogError("[SM] Plugin encountered error %d: %s", n_err, error->GetErrorString()); } @@ -150,26 +148,26 @@ void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *erro const char *custerr; if ((custerr=error->GetCustomErrorString()) != NULL) { - g_Logger.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr); + smcore.LogError("[SM] Native \"%s\" reported: %s", lastname, custerr); } else { - g_Logger.LogError("[SM] Native \"%s\" encountered a generic error.", lastname); + smcore.LogError("[SM] Native \"%s\" encountered a generic error.", lastname); } } if (!error->DebugInfoAvailable()) { - g_Logger.LogError("[SM] Debug mode is not enabled for \"%s\"", plname); - g_Logger.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on", + smcore.LogError("[SM] Debug mode is not enabled for \"%s\"", plname); + smcore.LogError("[SM] To enable debug mode, edit plugin_settings.cfg, or type: sm plugins debug %d on", _GetPluginIndex(ctx)); return; } CallStackInfo stk_info; int i = 0; - g_Logger.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname); + smcore.LogError("[SM] Displaying call stack trace for plugin \"%s\":", plname); while (error->GetTraceInfo(&stk_info)) { - g_Logger.LogError("[SM] [%d] Line %d, %s::%s()", + smcore.LogError("[SM] [%d] Line %d, %s::%s()", i++, stk_info.line, stk_info.filename, @@ -180,7 +178,7 @@ void DebugReport::OnContextExecuteError(IPluginContext *ctx, IContextTrace *erro int DebugReport::_GetPluginIndex(IPluginContext *ctx) { int id = 1; - IPluginIterator *iter = g_PluginSys.GetPluginIterator(); + IPluginIterator *iter = pluginsys->GetPluginIterator(); for (; iter->MorePlugins(); iter->NextPlugin(), id++) { @@ -196,6 +194,6 @@ int DebugReport::_GetPluginIndex(IPluginContext *ctx) /* If we don't know which plugin this is, it's one being loaded. Fake its index for now. */ - return g_PluginSys.GetPluginCount() + 1; + return pluginsys->GetPluginCount() + 1; } diff --git a/core/DebugReporter.h b/core/logic/DebugReporter.h similarity index 96% rename from core/DebugReporter.h rename to core/logic/DebugReporter.h index 4817dec8..ac4d97a9 100644 --- a/core/DebugReporter.h +++ b/core/logic/DebugReporter.h @@ -33,7 +33,7 @@ #define _INCLUDE_SOURCEMOD_CDBGREPORTER_H_ #include "sp_vm_api.h" -#include "sm_globals.h" +#include "common_logic.h" class DebugReport : public SMGlobalClass, diff --git a/core/logic/common_logic.cpp b/core/logic/common_logic.cpp index 19bfc1ec..43a40513 100644 --- a/core/logic/common_logic.cpp +++ b/core/logic/common_logic.cpp @@ -41,6 +41,7 @@ #include "ThreadSupport.h" #include "Translator.h" #include "GameConfigs.h" +#include "DebugReporter.h" sm_core_t smcore; IHandleSys *handlesys; @@ -59,6 +60,8 @@ ServerGlobals serverGlobals; IPlayerManager *playerhelpers; IAdminSystem *adminsys; IGameHelpers *gamehelpers; +ISourcePawnEngine *g_pSourcePawn; +ISourcePawnEngine2 *g_pSourcePawn2; static void AddCorePhraseFile(const char *filename) { @@ -73,6 +76,14 @@ static IGameConfig *GetCoreGameConfig() // Defined in smn_filesystem.cpp. extern bool OnLogPrint(const char *msg); +static void GenerateError(IPluginContext *ctx, cell_t idx, int err, const char *msg, ...) +{ + va_list ap; + va_start(ap, msg); + g_DbgReporter.GenerateErrorVA(ctx, idx, err, msg, ap); + va_end(ap); +} + static sm_logic_t logic = { NULL, @@ -86,7 +97,9 @@ static sm_logic_t logic = UTIL_ReplaceEx, UTIL_DecodeHexString, GetCoreGameConfig, - OnLogPrint + OnLogPrint, + &g_DbgReporter, + GenerateError }; static void logic_init(const sm_core_t* core, sm_logic_t* _logic) @@ -110,6 +123,8 @@ static void logic_init(const sm_core_t* core, sm_logic_t* _logic) playerhelpers = core->playerhelpers; adminsys = core->adminsys; gamehelpers = core->gamehelpers; + g_pSourcePawn = core->spe1; + g_pSourcePawn2 = core->spe2; } PLATFORM_EXTERN_C ITextParsers *get_textparsers() diff --git a/core/logic/intercom.h b/core/logic/intercom.h index 8b570621..8f484a82 100644 --- a/core/logic/intercom.h +++ b/core/logic/intercom.h @@ -42,7 +42,7 @@ using namespace SourceMod; * Add 1 to the RHS of this expression to bump the intercom file * This is to prevent mismatching core/logic binaries */ -#define SM_LOGIC_MAGIC (0x0F47C0DE - 17) +#define SM_LOGIC_MAGIC (0x0F47C0DE - 18) #if defined SM_LOGIC class IVEngineServer @@ -99,6 +99,8 @@ struct sm_core_t IPlayerManager *playerhelpers; IAdminSystem *adminsys; IGameHelpers *gamehelpers; + ISourcePawnEngine *spe1; + ISourcePawnEngine2 *spe2; /* Functions */ void (*AddNatives)(sp_nativeinfo_t* nlist); ConVar * (*FindConVar)(const char*); @@ -111,7 +113,7 @@ struct sm_core_t bool (*FileExists)(const char *path); const char * (*GetCvarString)(ConVar*); size_t (*Format)(char*, size_t, const char*, ...); - void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...); + size_t (*FormatArgs)(char*, size_t, const char*,va_list ap); bool (*gnprintf)(char *, size_t, const char *, IPhraseCollection *, void **, unsigned int, unsigned int &, size_t *, const char **); size_t (*atcprintf)(char *, size_t, const char *, IPluginContext *, const cell_t *, int *); @@ -141,6 +143,8 @@ struct sm_logic_t size_t (*DecodeHexString)(unsigned char *, size_t, const char *); IGameConfig * (*GetCoreGameConfig)(); bool (*OnLogPrint)(const char *msg); // true to supercede + IDebugListener *debugger; + void (*GenerateError)(IPluginContext *, cell_t, int, const char *, ...); }; typedef void (*LogicInitFunction)(const sm_core_t *core, sm_logic_t *logic); diff --git a/core/logic/smn_timers.cpp b/core/logic/smn_timers.cpp index 75dbb2f9..636fbbab 100644 --- a/core/logic/smn_timers.cpp +++ b/core/logic/smn_timers.cpp @@ -35,6 +35,7 @@ #include #include #include +#include "DebugReporter.h" using namespace SourceHook; @@ -155,7 +156,7 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData) { if ((herr=handlesys->FreeHandle(usrhndl, &sec)) != HandleError_None) { - smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), + g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), SP_ERROR_NATIVE, "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE", usrhndl, herr); @@ -166,7 +167,7 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData) { if ((herr=handlesys->FreeHandle(pInfo->TimerHandle, &sec)) != HandleError_None) { - smcore.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), + g_DbgReporter.GenerateError(pInfo->pContext, pInfo->Hook->GetFunctionID(), SP_ERROR_NATIVE, "Invalid timer handle %x (error %d) during timer end, displayed function is timer callback, not the stack trace", pInfo->TimerHandle, herr); diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 108c8597..37e4393b 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -45,7 +45,6 @@ #include "ForwardSys.h" #include "TimerSys.h" #include "logic_bridge.h" -#include "DebugReporter.h" #include "PlayerManager.h" #include "AdminCache.h" #include "HalfLife2.h" @@ -135,15 +134,6 @@ static bool file_exists(const char *path) return basefilesystem->FileExists(path); } -static void generate_error(IPluginContext *ctx, cell_t func_idx, int err, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - g_DbgReporter.GenerateErrorVA(ctx, func_idx, err, fmt, ap); - va_end(ap); -} - static const char *get_cvar_string(ConVar* cvar) { return cvar->GetString(); @@ -234,6 +224,8 @@ static sm_core_t core_bridge = &g_Players, &g_Admins, &g_HL2, + g_pSourcePawn, + g_pSourcePawn2, /* Functions */ add_natives, find_convar, @@ -246,7 +238,7 @@ static sm_core_t core_bridge = file_exists, get_cvar_string, UTIL_Format, - generate_error, + UTIL_FormatArgs, gnprintf, atcprintf, get_game_name, diff --git a/core/smn_menus.cpp b/core/smn_menus.cpp index 9aa856da..06dac35f 100644 --- a/core/smn_menus.cpp +++ b/core/smn_menus.cpp @@ -31,7 +31,6 @@ #include "sm_globals.h" #include -#include "DebugReporter.h" #include "MenuManager.h" #include "MenuStyle_Valve.h" #include "MenuStyle_Radio.h" @@ -44,6 +43,7 @@ #include "Logger.h" #endif #include "ChatTriggers.h" +#include "logic_bridge.h" #if defined CreateMenu #undef CreateMenu @@ -470,7 +470,7 @@ void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t * if ((err = pContext->HeapAlloc(client_array_size, &client_array_address, &client_array_base)) != SP_ERROR_NONE) { - g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t)); + logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for client list.", client_array_size * sizeof(cell_t)); no_call = true; } else { cell_t target_offs = sizeof(cell_t) * results->num_clients; @@ -503,7 +503,7 @@ void CMenuHandler::OnMenuVoteResults(IBaseMenu *menu, const menu_vote_result_t * if ((err = pContext->HeapAlloc(item_array_size, &item_array_address, &item_array_base)) != SP_ERROR_NONE) { - g_DbgReporter.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size); + logicore.GenerateError(pContext, m_fnVoteResult, err, "Menu callback could not allocate %d bytes for item list.", item_array_size); no_call = true; } else { cell_t target_offs = sizeof(cell_t) * results->num_items; diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index b9fff452..9e430737 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -45,7 +45,6 @@ #include "ForwardSys.h" #include "TimerSys.h" #include -#include "DebugReporter.h" #include "frame_hooks.h" #include "logic_bridge.h" @@ -242,7 +241,7 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late return false; } - g_pSourcePawn2->SetDebugListener(&g_DbgReporter); + g_pSourcePawn2->SetDebugListener(logicore.debugger); /* Hook this now so we can detect startup without calling StartSourceMod() */ SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);