From 5753c397d18b355a68442d4625a55500be80b3df Mon Sep 17 00:00:00 2001 From: asmodai Date: Thu, 8 Jun 2017 03:15:22 +0300 Subject: [PATCH] Small refactoring --- metamod/src/engine_t.h | 6 ++++-- metamod/src/metamod.cpp | 17 +++++++---------- metamod/src/metamod.h | 3 --- metamod/src/mplugin.cpp | 2 +- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/metamod/src/engine_t.h b/metamod/src/engine_t.h index ff8802e..d456724 100644 --- a/metamod/src/engine_t.h +++ b/metamod/src/engine_t.h @@ -3,13 +3,15 @@ // Our structure for storing engine references. struct engine_t { - engine_t() : funcs(nullptr), globals(nullptr), pl_funcs(nullptr) + engine_t() : funcs(nullptr), globals(nullptr) { + memset(&pl_funcs, 0, sizeof pl_funcs); } enginefuncs_t* funcs; // engine funcs globalvars_t* globals; // engine globals - enginefuncs_t* pl_funcs; // "modified" eng funcs we give to plugins + // Our modified version of the engine funcs, to give to plugins. + enginefuncs_t pl_funcs; // "modified" eng funcs we give to plugins }; extern engine_t g_engine; diff --git a/metamod/src/metamod.cpp b/metamod/src/metamod.cpp index 1ebdb87..30a9490 100644 --- a/metamod/src/metamod.cpp +++ b/metamod/src/metamod.cpp @@ -20,8 +20,6 @@ gamedll_t g_GameDLL; ALIGN16 meta_globals_t g_metaGlobals; -enginefuncs_t g_plugin_engfuncs; - MPluginList *g_plugins; MRegCmdList *g_regCmds; MRegCvarList *g_regCvars; @@ -157,16 +155,15 @@ void metamod_startup() // Copy, and store pointer in g_engine struct. Yes, we could just store // the actual engine_t struct in g_engine, but then it wouldn't be a // pointer to match the other g_engfuncs. - g_plugin_engfuncs = *g_engine.funcs; - g_engine.pl_funcs = &g_plugin_engfuncs; + g_engine.pl_funcs = *g_engine.funcs; // substitute our special versions of various commands - g_engine.pl_funcs->pfnAddServerCommand = meta_AddServerCommand; - g_engine.pl_funcs->pfnCVarRegister = meta_CVarRegister; - g_engine.pl_funcs->pfnCvar_RegisterVariable = meta_CVarRegister; - g_engine.pl_funcs->pfnRegUserMsg = meta_RegUserMsg; + g_engine.pl_funcs.pfnAddServerCommand = meta_AddServerCommand; + g_engine.pl_funcs.pfnCVarRegister = meta_CVarRegister; + g_engine.pl_funcs.pfnCvar_RegisterVariable = meta_CVarRegister; + g_engine.pl_funcs.pfnRegUserMsg = meta_RegUserMsg; - if (g_engine.pl_funcs->pfnQueryClientCvarValue) - g_engine.pl_funcs->pfnQueryClientCvarValue = meta_QueryClientCvarValue; + if (g_engine.pl_funcs.pfnQueryClientCvarValue) + g_engine.pl_funcs.pfnQueryClientCvarValue = meta_QueryClientCvarValue; // Before, we loaded plugins before loading the game DLL, so that if no // plugins caught engine functions, we could pass engine funcs straight diff --git a/metamod/src/metamod.h b/metamod/src/metamod.h index 4cd80f9..7c03e94 100644 --- a/metamod/src/metamod.h +++ b/metamod/src/metamod.h @@ -34,9 +34,6 @@ extern gamedll_t g_GameDLL; extern enginefuncs_t g_engfuncs; extern globalvars_t* gpGlobals; -// Our modified version of the engine funcs, to give to plugins. -extern enginefuncs_t g_plugin_engfuncs; - // g_config structure. extern MConfig* g_config; diff --git a/metamod/src/mplugin.cpp b/metamod/src/mplugin.cpp index 3bb7a67..11b4364 100644 --- a/metamod/src/mplugin.cpp +++ b/metamod/src/mplugin.cpp @@ -785,7 +785,7 @@ bool MPlugin::query() return false; } - pfn_give_engfuncs(g_engine.pl_funcs, g_engine.globals); + pfn_give_engfuncs(&g_engine.pl_funcs, g_engine.globals); META_DEBUG(6, "dll: Plugin '%s': Called GiveFnptrsToDll()", m_desc); // Call plugin's Meta_Query(), to pass our meta interface version, and get