From c5845d46da8c67d465595a0a9f074091ee54258b Mon Sep 17 00:00:00 2001 From: RD42 <42702181+dashr9230@users.noreply.github.com> Date: Fri, 12 Apr 2024 22:09:26 +0800 Subject: [PATCH] [server] Update CPlugins constructor --- server/netgame.h | 2 ++ server/plugincommon.h | 6 ++++ server/plugininternal.h | 9 ++++++ server/plugins.cpp | 66 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 82 insertions(+), 1 deletion(-) diff --git a/server/netgame.h b/server/netgame.h index 36d947a..26c9c94 100644 --- a/server/netgame.h +++ b/server/netgame.h @@ -73,6 +73,8 @@ public: CPlayerPool * GetPlayerPool() { return m_pPlayerPool; }; RakServerInterface * GetRakServer() { return m_pRak; }; + CGameMode * GetGameMode() { return m_pGameMode; }; + CFilterScripts * GetFilterScripts() { return m_pFilterScripts; }; void LoadAllFilterscripts(); diff --git a/server/plugincommon.h b/server/plugincommon.h index bd787e9..b15463c 100644 --- a/server/plugincommon.h +++ b/server/plugincommon.h @@ -2,6 +2,8 @@ #ifndef _PLUGINCOMMON_H_INCLUDED #define _PLUGINCOMMON_H_INCLUDED +//---------------------------------------------------------- + enum PLUGIN_DATA_TYPE { // For some debugging @@ -9,8 +11,12 @@ enum PLUGIN_DATA_TYPE // AMX PLUGIN_DATA_AMX_EXPORTS = 0x10, // void* AmxFunctionTable[] (see PLUGIN_AMX_EXPORT) + PLUGIN_DATA_CALLPUBLIC_FS = 0x11, // int (*AmxCallPublicFilterScript)(char *szFunctionName) + PLUGIN_DATA_CALLPUBLIC_GM = 0x12, // int (*AmxCallPublicGameMode)(char *szFunctionName) }; +//---------------------------------------------------------- + enum PLUGIN_AMX_EXPORT { PLUGIN_AMX_EXPORT_Align16 = 0, diff --git a/server/plugininternal.h b/server/plugininternal.h index 7afb0fe..41dc442 100644 --- a/server/plugininternal.h +++ b/server/plugininternal.h @@ -5,4 +5,13 @@ #define MAX_PLUGIN_DATA 256 #define MAX_PLUGIN_AMX_EXPORT 44 +enum PLUGIN_DATA_TYPE_INTERNAL +{ + PLUGIN_DATA_NETGAME = 0xE1, // CNetGame* GetNetGame(); + PLUGIN_DATA_RAKSERVER = 0xE2, // RakServerInterface* PluginGetRakServer() + PLUGIN_DATA_LOADFSCRIPT = 0xE3, // bool LoadFilterscriptFromMemory(char* pFileName, char* pFileData) + PLUGIN_DATA_UNLOADFSCRIPT = 0xE5, // bool UnloadFilterScript(char* pFileName) + PLUGIN_DATA_CONSOLE = 0xE4, // CConsole* GetConsole(); +}; + #endif diff --git a/server/plugins.cpp b/server/plugins.cpp index 0cb33f9..37586cb 100644 --- a/server/plugins.cpp +++ b/server/plugins.cpp @@ -1,6 +1,61 @@ #include "main.h" +//--------------------------------------- +// Some Helpers + +extern "C" RakServerInterface* PluginGetRakServer() +{ + if (pNetGame != NULL) + return pNetGame->GetRakServer(); + else + return NULL; +} + +extern "C" CNetGame* PluginGetNetGame() +{ + return pNetGame; +} + +extern "C" CConsole* PluginGetConsole() +{ + return pConsole; +} + +extern "C" bool PluginUnloadFilterScript(char* pFileName) +{ + if (pNetGame != NULL) + return pNetGame->GetFilterScripts()->UnloadOneFilterScript(pFileName); + else + return false; +} + +extern "C" bool PluginLoadFilterScriptFromMemory(char* pFileName, char* pFileData) +{ + if (pNetGame != NULL) + return pNetGame->GetFilterScripts()->LoadFilterScriptFromMemory(pFileName, pFileData); + else + return false; +} + +extern "C" int PluginCallPublicFS(char *szFunctionName) +{ + if (pNetGame != NULL) + return pNetGame->GetFilterScripts()->CallPublic(szFunctionName); + else + return 0; +} + +extern "C" int PluginCallPublicGM(char *szFunctionName) +{ + if (pNetGame != NULL && pNetGame->GetGameMode()) + return pNetGame->GetGameMode()->CallPublic(szFunctionName); + else + return 0; +} + +//--------------------------------------- + CPlugins::CPlugins() { // Set up the table of AMX functions to be exported @@ -57,10 +112,19 @@ CPlugins::CPlugins() m_PluginData[PLUGIN_DATA_LOGPRINTF] = (void*)&logprintf; m_PluginData[PLUGIN_DATA_AMX_EXPORTS] = m_AMXExports; + m_PluginData[PLUGIN_DATA_CALLPUBLIC_FS] = (void*)&PluginCallPublicFS; + m_PluginData[PLUGIN_DATA_CALLPUBLIC_GM] = (void*)&PluginCallPublicGM; - // TODO: CPlugins::CPlugins W: 0046A1D0 L: constructor + // Internals + m_PluginData[PLUGIN_DATA_NETGAME] = (void*)&PluginGetNetGame; + m_PluginData[PLUGIN_DATA_CONSOLE] = (void*)&PluginGetConsole; + m_PluginData[PLUGIN_DATA_RAKSERVER] = (void*)&PluginGetRakServer; + m_PluginData[PLUGIN_DATA_LOADFSCRIPT] = (void*)&PluginLoadFilterScriptFromMemory; + m_PluginData[PLUGIN_DATA_UNLOADFSCRIPT] = (void*)&PluginUnloadFilterScript; } +//--------------------------------------- + CPlugins::~CPlugins() { // TODO: CPlugins::~CPlugins W: 00469DB0 L: 080D20E0