From 1c5183dd18c578332f55f20cf025a96946733eef Mon Sep 17 00:00:00 2001 From: Kenzzer <14257866+kenzzer@users.noreply.github.com> Date: Sun, 17 Aug 2025 16:27:26 +0000 Subject: [PATCH] Remove SourceHook from core --- AMBuildScript | 32 ++-- bridge/include/IExtensionBridge.h | 11 +- bridge/include/IScriptManager.h | 17 +- core/ConCmdManager.cpp | 2 +- core/ConCmdManager.h | 10 +- core/ConVarManager.cpp | 34 ++-- core/ConVarManager.h | 10 +- core/ConsoleDetours.cpp | 73 ++++---- core/CoreConfig.cpp | 31 ++-- core/EventManager.cpp | 49 +++--- core/EventManager.h | 17 +- core/GameHooks.cpp | 98 +++++------ core/GameHooks.h | 30 +++- core/HalfLife2.cpp | 8 +- core/HalfLife2.h | 12 +- core/Logger.cpp | 17 +- core/Logger.h | 4 +- core/MenuManager.h | 7 +- core/MenuStyle_Radio.cpp | 4 +- core/MenuStyle_Radio.h | 10 +- core/MenuStyle_Valve.cpp | 25 +-- core/MenuStyle_Valve.h | 3 +- core/MenuVoting.h | 5 +- core/NextMap.cpp | 51 +++--- core/NextMap.h | 19 ++- core/PlayerManager.cpp | 268 ++++++++++++++---------------- core/PlayerManager.h | 64 ++++--- core/TimerSys.cpp | 13 +- core/TimerSys.h | 15 +- core/UserMessages.cpp | 119 ++++++------- core/UserMessages.h | 46 +++-- core/concmd_cleaner.cpp | 95 +++++------ core/logic/AMBuilder | 2 +- core/logic/AdminCache.cpp | 22 +-- core/logic/AdminCache.h | 18 +- core/logic/BaseWorker.cpp | 3 +- core/logic/BaseWorker.h | 4 +- core/logic/Database.cpp | 2 +- core/logic/Database.h | 10 +- core/logic/ExtensionSys.cpp | 115 +++++++------ core/logic/ExtensionSys.h | 27 ++- core/logic/GameConfigs.cpp | 19 ++- core/logic/MemoryUtils.h | 6 +- core/logic/NativeOwner.cpp | 19 ++- core/logic/NativeOwner.h | 8 +- core/logic/PhraseCollection.h | 6 +- core/logic/PluginSys.cpp | 23 ++- core/logic/PluginSys.h | 32 ++-- core/logic/RootConsoleMenu.cpp | 11 +- core/logic/RootConsoleMenu.h | 13 +- core/logic/ShareSys.cpp | 2 +- core/logic/ShareSys.h | 6 +- core/logic/Translator.h | 17 +- core/logic/smn_core.cpp | 14 +- core/logic/smn_database.cpp | 2 +- core/logic/smn_fakenatives.cpp | 4 - core/logic/smn_maplists.cpp | 14 +- core/logic/smn_menus.cpp | 25 +-- core/logic/smn_players.cpp | 19 +-- core/logic/smn_timers.cpp | 15 +- core/logic_bridge.cpp | 2 +- core/smn_console.cpp | 18 +- core/smn_halflife.cpp | 2 +- core/smn_keyvalues.cpp | 26 +-- core/smn_keyvalues.h | 4 +- core/smn_nextmap.cpp | 3 +- core/smn_usermsgs.cpp | 18 +- core/sourcemm_api.cpp | 2 - core/sourcemm_api.h | 6 +- core/sourcemod.cpp | 92 +++++----- core/sourcemod.h | 31 ++-- public/sm_queue.h | 10 +- 72 files changed, 915 insertions(+), 956 deletions(-) diff --git a/AMBuildScript b/AMBuildScript index 56faedafb..95e86fc3a 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -519,7 +519,7 @@ class SMConfig(object): compiler.cxxincludes += [ os.path.join(self.mms_root, 'core'), - os.path.join(self.mms_root, 'core', 'sourcehook'), + os.path.join(self.mms_root, 'third_party', 'khook', 'include'), ] for other_sdk in self.sdk_manifests: @@ -663,21 +663,21 @@ else: 'loader/AMBuilder', 'core/AMBuilder', 'core/logic/AMBuilder', - 'extensions/bintools/AMBuilder', - 'extensions/clientprefs/AMBuilder', - 'extensions/curl/AMBuilder', - 'extensions/cstrike/AMBuilder', - 'extensions/dhooks/AMBuilder', - 'extensions/geoip/AMBuilder', - 'extensions/mysql/AMBuilder', - 'extensions/pgsql/AMBuilder', - 'extensions/regex/AMBuilder', - 'extensions/sdkhooks/AMBuilder', - 'extensions/sdktools/AMBuilder', - 'extensions/sqlite/AMBuilder', - 'extensions/tf2/AMBuilder', - 'extensions/topmenus/AMBuilder', - 'extensions/updater/AMBuilder', + #'extensions/bintools/AMBuilder', + #'extensions/clientprefs/AMBuilder', + #'extensions/curl/AMBuilder', + #'extensions/cstrike/AMBuilder', + #'extensions/dhooks/AMBuilder', + #'extensions/geoip/AMBuilder', + #'extensions/mysql/AMBuilder', + #'extensions/pgsql/AMBuilder', + #'extensions/regex/AMBuilder', + #'extensions/sdkhooks/AMBuilder', + #'extensions/sdktools/AMBuilder', + #'extensions/sqlite/AMBuilder', + #'extensions/tf2/AMBuilder', + #'extensions/topmenus/AMBuilder', + #'extensions/updater/AMBuilder', ] if builder.backend == 'amb2': diff --git a/bridge/include/IExtensionBridge.h b/bridge/include/IExtensionBridge.h index 4b41795f6..3a2c661ad 100644 --- a/bridge/include/IExtensionBridge.h +++ b/bridge/include/IExtensionBridge.h @@ -29,13 +29,12 @@ #include #include -#include +#include struct edict_t; namespace SourceMod { -using namespace SourceHook; using namespace SourcePawn; class SMPlugin; @@ -51,8 +50,8 @@ public: virtual IExtension *GetExtensionFromIdent(IdentityToken_t *token) = 0; virtual void BindChildPlugin(IExtension *ext, SMPlugin *plugin) = 0; virtual void AddRawDependency(IExtension *myself, IdentityToken_t *token, void *iface) = 0; - virtual const CVector *ListExtensions() = 0; - virtual void FreeExtensionList(const CVector *list) = 0; + virtual const std::vector *ListExtensions() = 0; + virtual void FreeExtensionList(const std::vector *list) = 0; virtual void CallOnCoreMapEnd() = 0; }; @@ -67,13 +66,13 @@ public: { extensions_->FreeExtensionList(list_); } - const CVector *operator ->() + const std::vector *operator ->() { return list_; } private: IExtensionSys *extensions_; - const CVector *list_; + const std::vector *list_; }; } // namespace SourceMod diff --git a/bridge/include/IScriptManager.h b/bridge/include/IScriptManager.h index 2af390556..d530a3a8c 100644 --- a/bridge/include/IScriptManager.h +++ b/bridge/include/IScriptManager.h @@ -29,12 +29,11 @@ #include #include -#include -#include +#include +#include namespace SourceMod { -using namespace SourceHook; using namespace SourcePawn; class IChangeableForward; @@ -47,8 +46,8 @@ enum LibraryAction struct AutoConfig { - SourceHook::String autocfg; - SourceHook::String folder; + std::string autocfg; + std::string folder; bool create; }; @@ -82,8 +81,8 @@ public: virtual SMPlugin *FindPluginByConsoleArg(const char *text) = 0; virtual SMPlugin *FindPluginByHandle(Handle_t hndl, HandleError *errp) = 0; virtual bool UnloadPlugin(IPlugin *plugin) = 0; - virtual const CVector *ListPlugins() = 0; - virtual void FreePluginList(const CVector *list) = 0; + virtual const std::vector *ListPlugins() = 0; + virtual void FreePluginList(const std::vector *list) = 0; virtual void AddFunctionsToForward(const char *name, IChangeableForward *fwd) = 0; }; @@ -98,13 +97,13 @@ public: { scripts_->FreePluginList(list_); } - const CVector *operator ->() + const std::vector *operator ->() { return list_; } private: IScriptManager *scripts_; - const CVector *list_; + const std::vector *list_; }; } // namespace SourceMod diff --git a/core/ConCmdManager.cpp b/core/ConCmdManager.cpp index 1777cfbee..5d485dde4 100644 --- a/core/ConCmdManager.cpp +++ b/core/ConCmdManager.cpp @@ -415,7 +415,7 @@ void RegisterInPlugin(CmdHook *hook) void ConCmdManager::AddToCmdList(ConCmdInfo *info) { - List::iterator iter = m_CmdList.begin(); + auto iter = m_CmdList.begin(); ConCmdInfo *pInfo; bool inserted = false; const char *orig = NULL; diff --git a/core/ConCmdManager.h b/core/ConCmdManager.h index f3b882e29..20ce26082 100644 --- a/core/ConCmdManager.h +++ b/core/ConCmdManager.h @@ -43,16 +43,14 @@ #include "sm_globals.h" #include "sourcemm_api.h" #include -#include -#include +#include +#include #include #include #include "concmd_cleaner.h" #include "GameHooks.h" #include -using namespace SourceHook; - struct CmdHook; struct ConCmdInfo; @@ -137,7 +135,7 @@ struct ConCmdInfo }; }; -typedef List ConCmdList; +typedef std::list ConCmdList; class ConCmdManager : public SMGlobalClass, @@ -180,7 +178,7 @@ private: bool CheckAccess(int client, const char *cmd, AdminCmdInfo *pAdmin); ConCmdInfo *FindInTrie(const char *name); public: - inline const List & GetCommandList() + inline const std::list & GetCommandList() { return m_CmdList; } diff --git a/core/ConVarManager.cpp b/core/ConVarManager.cpp index dcd5d8ed0..c422771ec 100644 --- a/core/ConVarManager.cpp +++ b/core/ConVarManager.cpp @@ -30,7 +30,7 @@ #include "ConVarManager.h" #include "HalfLife2.h" #include "sm_stringutil.h" -#include +#include #include #include "logic_bridge.h" #include "sourcemod.h" @@ -40,7 +40,7 @@ ConVarManager g_ConVarManager; const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String}; -typedef List ConVarList; +typedef std::list ConVarList; NameHashSet convar_cache; enum { @@ -114,7 +114,7 @@ void ConVarManager::OnSourceModAllInitialized() void ConVarManager::OnSourceModShutdown() { - List::iterator iter = m_ConVars.begin(); + auto iter = m_ConVars.begin(); HandleSecurity sec(NULL, g_pCoreIdent); /* Iterate list of ConVarInfo structures, remove every one of them */ @@ -217,7 +217,7 @@ void ConVarManager::OnPluginUnloaded(IPlugin *plugin) } /* Clear any references to this plugin as the convar creator */ - for (List::iterator iter = m_ConVars.begin(); iter != m_ConVars.end(); ++iter) + for (auto iter = m_ConVars.begin(); iter != m_ConVars.end(); ++iter) { ConVarInfo *pInfo = (*iter); @@ -230,7 +230,7 @@ void ConVarManager::OnPluginUnloaded(IPlugin *plugin) const IPluginRuntime * pRuntime = plugin->GetRuntime(); /* Remove convar queries for this plugin that haven't returned results yet */ - for (List::iterator iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();) + for (auto iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();) { ConVarQuery &query = (*iter); if (query.pCallback->GetParentRuntime() == pRuntime) @@ -246,7 +246,7 @@ void ConVarManager::OnPluginUnloaded(IPlugin *plugin) void ConVarManager::OnClientDisconnected(int client) { /* Remove convar queries for this client that haven't returned results yet */ - for (List::iterator iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();) + for (auto iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end();) { ConVarQuery &query = (*iter); if (query.client == client) @@ -311,7 +311,6 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs const char *plname = IS_STR_FILLED(plinfo->name) ? plinfo->name : plugin->GetFilename(); ConVarList *pConVarList; - ConVarList::iterator iter; /* If no convar list... */ if (!plugin->GetProperty("ConVarList", (void **)&pConVarList)) @@ -327,7 +326,7 @@ void ConVarManager::OnRootConsoleCommand(const char *cmdname, const ICommandArgs } /* Iterate convar list and display/reset each one */ - for (iter = pConVarList->begin(); iter != pConVarList->end(); iter++) + for (auto iter = pConVarList->begin(); iter != pConVarList->end(); iter++) { /*const */ConVar *pConVar = const_cast(*iter); if (!wantReset) @@ -599,10 +598,18 @@ void ConVarManager::AddConVarToPluginList(IPlugin *plugin, const ConVar *pConVar pConVarList = new ConVarList(); plugin->SetProperty("ConVarList", pConVarList); } - else if (pConVarList->find(pConVar) != pConVarList->end()) + else { /* If convar is already in list, then don't add it */ - return; + auto iterS = pConVarList->begin(); + while (iterS != pConVarList->end() && (*iterS) != pConVar) + { + iterS++; + } + if (iterS != pConVarList->end()) + { + return; + } } /* Insert convar into list which is sorted alphabetically */ @@ -672,9 +679,9 @@ void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie, { IPluginFunction *pCallback = NULL; cell_t value = 0; - List::iterator iter; - for (iter = m_ConVarQueries.begin(); iter != m_ConVarQueries.end(); iter++) + auto iter = m_ConVarQueries.begin(); + for (; iter != m_ConVarQueries.end(); iter++) { ConVarQuery &query = (*iter); if (query.cookie == cookie) @@ -706,7 +713,8 @@ void ConVarManager::OnClientQueryFinished(QueryCvarCookie_t cookie, pCallback->PushCell(value); pCallback->Execute(&ret); - m_ConVarQueries.erase(iter); + if (iter != m_ConVarQueries.end()) + m_ConVarQueries.erase(iter); } } #endif diff --git a/core/ConVarManager.h b/core/ConVarManager.h index a613aa433..21c2b26ae 100644 --- a/core/ConVarManager.h +++ b/core/ConVarManager.h @@ -34,7 +34,7 @@ #include "sm_globals.h" #include "sourcemm_api.h" -#include +#include #include #include #include @@ -45,8 +45,6 @@ #include "PlayerManager.h" #include -using namespace SourceHook; - class IConVarChangeListener { public: @@ -63,7 +61,7 @@ struct ConVarInfo IChangeableForward *pChangeForward; /**< Forward associated with convar */ ConVar *pVar; /**< The actual convar */ IPlugin *pPlugin; /**< Originally owning plugin */ - List changeListeners; + std::list changeListeners; struct ConVarPolicy { @@ -175,8 +173,8 @@ private: static void AddConVarToPluginList(IPlugin *plugin, const ConVar *pConVar); private: HandleType_t m_ConVarType; - List m_ConVars; - List m_ConVarQueries; + std::list m_ConVars; + std::list m_ConVarQueries; }; extern ConVarManager g_ConVarManager; diff --git a/core/ConsoleDetours.cpp b/core/ConsoleDetours.cpp index 69badc43c..879789443 100644 --- a/core/ConsoleDetours.cpp +++ b/core/ConsoleDetours.cpp @@ -62,30 +62,34 @@ # include #endif -#if SOURCE_ENGINE >= SE_ORANGEBOX - SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#else - SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -#endif - class GenericCommandHooker : public IConCommandLinkListener { +#if SOURCE_ENGINE >= SE_ORANGEBOX + using CmdHook = KHook::Member; + KHook::Return Dispatch(ConCommand* this_ptr, const CCommand& args) +#else + using CmdHook = KHook::Member; + KHook::Return Dispatch(ConCommand* this_ptr) +#endif + { + cell_t res = ConsoleDetours::Dispatch(this_ptr +#if SOURCE_ENGINE >= SE_ORANGEBOX + , args +#endif + ); + if (res >= Pl_Handled) + return { KHook::Action::Supersede }; + return { KHook::Action::Ignore }; + } + struct HackInfo { void **vtable; - int hook; + CmdHook* hook; unsigned int refcount; }; - CVector vtables; + std::vector vtables; bool enabled; - SourceHook::MemFuncInfo dispatch; - - inline void **GetVirtualTable(ConCommandBase *pBase) - { - return *reinterpret_cast(reinterpret_cast(pBase) + - dispatch.thisptroffs + - dispatch.vtbloffs); - } inline bool FindVtable(void **ptr, size_t& index) { @@ -105,15 +109,14 @@ class GenericCommandHooker : public IConCommandLinkListener if (!pBase->IsCommand()) return; - ConCommand *cmd = (ConCommand*)pBase; - void **vtable = GetVirtualTable(cmd); - + ConCommand *cmd = reinterpret_cast(pBase); + void **vtable = *(void***)cmd; size_t index; if (!FindVtable(vtable, index)) { HackInfo hack; hack.vtable = vtable; - hack.hook = SH_ADD_VPHOOK(ConCommand, Dispatch, cmd, SH_MEMBER(this, &GenericCommandHooker::Dispatch), false); + hack.hook = new CmdHook(KHook::GetVtableFunction(cmd, &ConCommand::Dispatch), this, &GenericCommandHooker::Dispatch, nullptr); hack.refcount = 1; vtables.push_back(hack); } @@ -123,28 +126,13 @@ class GenericCommandHooker : public IConCommandLinkListener } } -#if SOURCE_ENGINE >= SE_ORANGEBOX - void Dispatch(const CCommand& args) -#else - void Dispatch() -#endif - { - cell_t res = ConsoleDetours::Dispatch(META_IFACEPTR(ConCommand) -#if SOURCE_ENGINE >= SE_ORANGEBOX - , args -#endif - ); - if (res >= Pl_Handled) - RETURN_META(MRES_SUPERCEDE); - } - void ReparseCommandList() { for (size_t i = 0; i < vtables.size(); i++) vtables[i].refcount = 0; for (ConCommandBaseIterator iter; iter.IsValid(); iter.Next()) MakeHookable(iter.Get()); - CVector::iterator iter = vtables.begin(); + auto iter = vtables.begin(); while (iter != vtables.end()) { if ((*iter).refcount) @@ -167,6 +155,7 @@ class GenericCommandHooker : public IConCommandLinkListener * * See bug 4018. */ + delete (*iter).hook; iter = vtables.erase(iter); } } @@ -177,7 +166,7 @@ class GenericCommandHooker : public IConCommandLinkListener return; ConCommand *cmd = (ConCommand*)pBase; - void **vtable = GetVirtualTable(cmd); + void **vtable = *(void***)(cmd); size_t index; if (!FindVtable(vtable, index)) @@ -190,8 +179,8 @@ class GenericCommandHooker : public IConCommandLinkListener vtables[index].refcount--; if (vtables[index].refcount == 0) { - SH_REMOVE_HOOK_ID(vtables[index].hook); - vtables.erase(vtables.iterAt(index)); + delete vtables[index].hook; + vtables.erase(vtables.begin() + index); } } @@ -202,9 +191,7 @@ public: bool Enable() { - SourceHook::GetFuncInfo(&ConCommand::Dispatch, dispatch); - - if (dispatch.thisptroffs < 0) + if (KHook::GetVtableIndex(&ConCommand::Dispatch) == -1) { logger->LogError("Command filter could not determine ConCommand layout"); return false; @@ -227,7 +214,7 @@ public: void Disable() { for (size_t i = 0; i < vtables.size(); i++) - SH_REMOVE_HOOK_ID(vtables[i].hook); + delete vtables[i].hook; vtables.clear(); } diff --git a/core/CoreConfig.cpp b/core/CoreConfig.cpp index f2b32f72b..5af5117c8 100644 --- a/core/CoreConfig.cpp +++ b/core/CoreConfig.cpp @@ -41,13 +41,11 @@ #include #include #include -#include +#include #include #include #include -using namespace SourceHook; - #ifdef PLATFORM_WINDOWS ConVar sm_corecfgfile("sm_corecfgfile", "addons\\sourcemod\\configs\\core.cfg", 0, "SourceMod core configuration file"); #elif defined PLATFORM_LINUX || defined PLATFORM_APPLE @@ -68,11 +66,9 @@ ConVar *g_ServerCfgFile = NULL; void CheckAndFinalizeConfigs(); #if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -void Hook_ExecDispatchPre(const CCommand &cmd) +KHook::Return Hook_ExecDispatchPre(ConCommand*, const CCommand &cmd) #else -SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -void Hook_ExecDispatchPre() +KHook::Return Hook_ExecDispatchPre(ConCommand*) #endif { #if SOURCE_ENGINE <= SE_DARKMESSIAH @@ -85,12 +81,14 @@ void Hook_ExecDispatchPre() { g_bGotTrigger = true; } + + return { KHook::Action::Ignore }; } #if SOURCE_ENGINE >= SE_ORANGEBOX -void Hook_ExecDispatchPost(const CCommand &cmd) +KHook::Return Hook_ExecDispatchPost(ConCommand*, const CCommand &cmd) #else -void Hook_ExecDispatchPost() +KHook::Return Hook_ExecDispatchPost(ConCommand*) #endif { if (g_bGotTrigger) @@ -99,8 +97,12 @@ void Hook_ExecDispatchPost() g_bServerExecd = true; CheckAndFinalizeConfigs(); } + + return { KHook::Action::Ignore }; } +KHook::Virtual gExecCommandHook(&ConCommand::Dispatch, &Hook_ExecDispatchPre, &Hook_ExecDispatchPost); + void CheckAndFinalizeConfigs() { if ((g_bServerExecd || g_ServerCfgFile == NULL) && g_bGotServerStart) @@ -134,8 +136,7 @@ void CoreConfig::OnSourceModShutdown() if (g_pExecPtr != NULL) { - SH_REMOVE_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPre), false); - SH_REMOVE_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPost), true); + gExecCommandHook.Remove(g_pExecPtr); g_pExecPtr = NULL; } } @@ -160,8 +161,7 @@ void CoreConfig::OnSourceModLevelChange(const char *mapName) g_pExecPtr = FindCommand("exec"); if (g_pExecPtr != NULL) { - SH_ADD_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPre), false); - SH_ADD_HOOK(ConCommand, Dispatch, g_pExecPtr, SH_STATIC(Hook_ExecDispatchPost), true); + gExecCommandHook.Add(g_pExecPtr); } else { @@ -396,7 +396,7 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) bool file_exists = ke::file::IsFile(file); if (!file_exists && will_create) { - List *convars = NULL; + std::list *convars = NULL; if (pl->GetProperty("ConVarList", (void **)&convars, false) && convars) { /* Attempt to create it */ @@ -407,9 +407,8 @@ bool SM_ExecuteConfig(IPlugin *pl, AutoConfig *cfg, bool can_create) fprintf(fp, "// ConVars for plugin \"%s\"\n", pl->GetFilename()); fprintf(fp, "\n\n"); - List::iterator iter; float x; - for (iter = convars->begin(); iter != convars->end(); iter++) + for (auto iter = convars->begin(); iter != convars->end(); iter++) { const ConVar *cvar = (*iter); #if SOURCE_ENGINE >= SE_ORANGEBOX diff --git a/core/EventManager.cpp b/core/EventManager.cpp index dc67d81c0..33fbbe81b 100644 --- a/core/EventManager.cpp +++ b/core/EventManager.cpp @@ -38,10 +38,8 @@ EventManager g_EventManager; -SH_DECL_HOOK2(IGameEventManager2, FireEvent, SH_NOATTRIB, 0, bool, IGameEvent *, bool); - const ParamType GAMEEVENT_PARAMS[] = {Param_Cell, Param_String, Param_Cell}; -typedef List EventHookList; +typedef std::list EventHookList; class EventForwardFilter : public IForwardFilter { @@ -57,27 +55,25 @@ public: } }; -EventManager::EventManager() : m_EventType(0) +EventManager::EventManager() : m_EventType(0), + m_FireEvent(&IGameEventManager2::FireEvent, this, &EventManager::OnFireEvent, &EventManager::OnFireEvent_Post) { } EventManager::~EventManager() { /* Free memory used by EventInfo structs if any */ - CStack::iterator iter; - for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++) + while (!m_FreeEvents.empty()) { - delete (*iter); + delete (m_FreeEvents.top()); + m_FreeEvents.pop(); } - - m_FreeEvents.popall(); } void EventManager::OnSourceModAllInitialized() { /* Add a hook for IGameEventManager2::FireEvent() */ - SH_ADD_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent), false); - SH_ADD_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent_Post), true); + m_FireEvent.Add(gameevents); HandleAccess sec; @@ -93,8 +89,7 @@ void EventManager::OnSourceModAllInitialized() void EventManager::OnSourceModShutdown() { /* Remove hook for IGameEventManager2::FireEvent() */ - SH_REMOVE_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent), false); - SH_REMOVE_HOOK(IGameEventManager2, FireEvent, gameevents, SH_MEMBER(this, &EventManager::OnFireEvent_Post), true); + m_FireEvent.Remove(gameevents); /* Remove the 'GameEvent' handle type */ handlesys->RemoveType(m_EventType, g_pCoreIdent); @@ -306,7 +301,11 @@ EventHookError EventManager::UnhookEvent(const char *name, IPluginFunction *pFun } /* Make sure the event was actually being hooked */ - if (pHookList->find(pHook) == pHookList->end()) + auto iter = pHookList->begin(); + while (iter != pHookList->end() && *iter == pHook) { + iter++; + } + if (iter == pHookList->end()) { return EventHookErr_NotActive; } @@ -335,7 +334,7 @@ EventInfo *EventManager::CreateEvent(IPluginContext *pContext, const char *name, { pInfo = new EventInfo(); } else { - pInfo = m_FreeEvents.front(); + pInfo = m_FreeEvents.top(); m_FreeEvents.pop(); } @@ -382,7 +381,7 @@ void EventManager::CancelCreatedEvent(EventInfo *pInfo) } /* IGameEventManager2::FireEvent hook */ -bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) +KHook::Return EventManager::OnFireEvent(IGameEventManager2* this_ptr, IGameEvent *pEvent, bool bDontBroadcast) { EventHook *pHook; IChangeableForward *pForward; @@ -393,7 +392,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) /* The engine accepts NULL without crashing, so to prevent a crash in SM we ignore these */ if (!pEvent) { - RETURN_META_VALUE(MRES_IGNORED, false); + return { KHook::Action::Ignore, false }; } name = pEvent->GetName(); @@ -436,7 +435,7 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) if (res >= Pl_Handled) { gameevents->FreeEvent(pEvent); - RETURN_META_VALUE(MRES_SUPERCEDE, false); + return { KHook::Action::Supersede, false }; } } else @@ -445,13 +444,13 @@ bool EventManager::OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast) } if (broadcast != bDontBroadcast) - RETURN_META_VALUE_NEWPARAMS(MRES_IGNORED, true, &IGameEventManager2::FireEvent, (pEvent, broadcast)); + return KHook::Recall(KHook::Return{ KHook::Action::Ignore, true }, this_ptr, pEvent, broadcast); - RETURN_META_VALUE(MRES_IGNORED, true); + return { KHook::Action::Ignore, true }; } /* IGameEventManager2::FireEvent post hook */ -bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) +KHook::Return EventManager::OnFireEvent_Post(IGameEventManager2*, IGameEvent *pEvent, bool bDontBroadcast) { EventHook *pHook; EventInfo info; @@ -461,10 +460,10 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) /* The engine accepts NULL without crashing, so to prevent a crash in SM we ignore these */ if (!pEvent) { - RETURN_META_VALUE(MRES_IGNORED, false); + return { KHook::Action::Ignore, false }; } - pHook = m_EventStack.front(); + pHook = m_EventStack.top(); if (pHook != NULL) { @@ -475,7 +474,7 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) if (pHook->postCopy) { info.bDontBroadcast = bDontBroadcast; - info.pEvent = m_EventCopies.front(); + info.pEvent = m_EventCopies.top(); info.pOwner = NULL; hndl = handlesys->CreateHandle(m_EventType, &info, NULL, g_pCoreIdent, NULL); @@ -512,5 +511,5 @@ bool EventManager::OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast) m_EventStack.pop(); - RETURN_META_VALUE(MRES_IGNORED, true); + return { KHook::Action::Ignore, true }; } diff --git a/core/EventManager.h b/core/EventManager.h index b14923149..fe9113dec 100644 --- a/core/EventManager.h +++ b/core/EventManager.h @@ -35,16 +35,14 @@ #include "sm_globals.h" #include "sourcemm_api.h" #include -#include -#include +#include +#include #include #include #include class IClient; -using namespace SourceHook; - struct EventInfo { EventInfo() @@ -135,14 +133,15 @@ public: void FireEventToClient(EventInfo *pInfo, IClient *pClient); void CancelCreatedEvent(EventInfo *pInfo); private: // IGameEventManager2 hooks - bool OnFireEvent(IGameEvent *pEvent, bool bDontBroadcast); - bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast); + KHook::Return OnFireEvent(IGameEventManager2*, IGameEvent *pEvent, bool bDontBroadcast); + KHook::Return OnFireEvent_Post(IGameEventManager2*, IGameEvent *pEvent, bool bDontBroadcast); private: HandleType_t m_EventType; NameHashSet m_EventHooks; - CStack m_FreeEvents; - CStack m_EventStack; - CStack m_EventCopies; + std::stack m_FreeEvents; + std::stack m_EventStack; + std::stack m_EventCopies; + KHook::Virtual m_FireEvent; }; extern EventManager g_EventManager; diff --git a/core/GameHooks.cpp b/core/GameHooks.cpp index 356e764eb..de96304d9 100644 --- a/core/GameHooks.cpp +++ b/core/GameHooks.cpp @@ -30,49 +30,33 @@ #include "command_args.h" #include "provider.h" -#if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_HOOK3_void(ICvar, CallGlobalChangeCallbacks, SH_NOATTRIB, false, ConVar *, const char *, float); -#else -SH_DECL_HOOK2_void(ICvar, CallGlobalChangeCallback, SH_NOATTRIB, false, ConVar *, const char *); -#endif - -#if SOURCE_ENGINE != SE_DARKMESSIAH -SH_DECL_HOOK5_void(IServerGameDLL, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); -SH_DECL_HOOK5_void(IServerPluginCallbacks, OnQueryCvarValueFinished, SH_NOATTRIB, 0, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *); -#endif - -#if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_HOOK1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#else -SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -#endif - -SH_DECL_HOOK1_void(IServerGameClients, SetCommandClient, SH_NOATTRIB, false, int); +KHook::Virtual CallGlobalChangeCallback_Hook(&ICvar::CallGlobalChangeCallbacks, &GameHooks::OnConVarChanged, nullptr); GameHooks::GameHooks() - : client_cvar_query_mode_(ClientCvarQueryMode::Unavailable), - last_command_client_(-1) + : +#if SOURCE_ENGINE != SE_DARKMESSIAH + m_GameDLLOnQueryCvarValueFinishedHook(&IServerGameDLL::OnQueryCvarValueFinished, this, &GameHooks::GameDLLOnQueryCvarValueFinished, nullptr), + m_VSPOnQueryCvarValueFinishedHook(&IServerPluginCallbacks::OnQueryCvarValueFinished, this, &GameHooks::VSPOnQueryCvarValueFinished, nullptr), +#endif + m_SetCommandClient(&IServerGameClients::SetCommandClient, this, &GameHooks::SetCommandClient, nullptr) + ,client_cvar_query_mode_(ClientCvarQueryMode::Unavailable) + ,last_command_client_(-1) { } void GameHooks::Start() { // Hook ICvar::CallGlobalChangeCallbacks. -#if SOURCE_ENGINE >= SE_ORANGEBOX - hooks_ += SH_ADD_HOOK(ICvar, CallGlobalChangeCallbacks, icvar, SH_STATIC(OnConVarChanged), false); -#else - hooks_ += SH_ADD_HOOK(ICvar, CallGlobalChangeCallback, icvar, SH_STATIC(OnConVarChanged), false); -#endif + CallGlobalChangeCallback_Hook.Add(icvar); // Episode 2 has this function by default, but the older versions do not. #if SOURCE_ENGINE == SE_EPISODEONE if (g_SMAPI->GetGameDLLVersion() >= 6) { - hooks_ += SH_ADD_HOOK(IServerGameDLL, OnQueryCvarValueFinished, gamedll, SH_MEMBER(this, &GameHooks::OnQueryCvarValueFinished), false); + m_GameDLLOnQueryCvarValueFinishedHook.Add(gamedll); client_cvar_query_mode_ = ClientCvarQueryMode::DLL; } #endif - - hooks_ += SH_ADD_HOOK(IServerGameClients, SetCommandClient, serverClients, SH_MEMBER(this, &GameHooks::SetCommandClient), false); + m_SetCommandClient.Add(serverClients); } void GameHooks::OnVSPReceived() @@ -84,30 +68,33 @@ void GameHooks::OnVSPReceived() return; #if SOURCE_ENGINE != SE_DARKMESSIAH - hooks_ += SH_ADD_HOOK(IServerPluginCallbacks, OnQueryCvarValueFinished, vsp_interface, SH_MEMBER(this, &GameHooks::OnQueryCvarValueFinished), false); + m_VSPOnQueryCvarValueFinishedHook.Add(vsp_interface); client_cvar_query_mode_ = ClientCvarQueryMode::VSP; #endif } void GameHooks::Shutdown() { - for (size_t i = 0; i < hooks_.size(); i++) - SH_REMOVE_HOOK_ID(hooks_[i]); - hooks_.clear(); + CallGlobalChangeCallback_Hook.Remove(icvar); + m_GameDLLOnQueryCvarValueFinishedHook.Remove(gamedll); + m_SetCommandClient.Remove(serverClients); + m_VSPOnQueryCvarValueFinishedHook.Remove(vsp_interface); client_cvar_query_mode_ = ClientCvarQueryMode::Unavailable; } #if SOURCE_ENGINE >= SE_ORANGEBOX -void GameHooks::OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue) +KHook::Return GameHooks::OnConVarChanged(ICvar*, ConVar *pConVar, const char *oldValue, float flOldValue) #else -void GameHooks::OnConVarChanged(ConVar *pConVar, const char *oldValue) +KHook::Return GameHooks::OnConVarChanged(ICvar*, ConVar *pConVar, const char *oldValue) #endif { #if SOURCE_ENGINE < SE_ORANGEBOX float flOldValue = atof(oldValue); #endif g_ConVarManager.OnConVarChanged(pConVar, oldValue, flOldValue); + + return { KHook::Action::Ignore }; } #if SOURCE_ENGINE != SE_DARKMESSIAH @@ -123,6 +110,17 @@ void GameHooks::OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPla } #endif +KHook::Return GameHooks::GameDLLOnQueryCvarValueFinished(IServerGameDLL*, QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, + const char *cvarName, const char *cvarValue) { + OnQueryCvarValueFinished(cookie, pPlayer, result, cvarName, cvarValue); + return { KHook::Action::Ignore }; +} +KHook::Return GameHooks::VSPOnQueryCvarValueFinished(IServerPluginCallbacks*, QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, + const char *cvarName, const char *cvarValue) { + OnQueryCvarValueFinished(cookie, pPlayer, result, cvarName, cvarValue); + return { KHook::Action::Ignore }; +} + ke::RefPtr GameHooks::AddCommandHook(ConCommand *cmd, const CommandHook::Callback &callback) { @@ -135,37 +133,39 @@ GameHooks::AddPostCommandHook(ConCommand *cmd, const CommandHook::Callback &call return new CommandHook(cmd, callback, true); } -void GameHooks::SetCommandClient(int client) +KHook::Return GameHooks::SetCommandClient(IServerGameClients*, int client) { last_command_client_ = client + 1; + + return { KHook::Action::Ignore }; } CommandHook::CommandHook(ConCommand *cmd, const Callback &callback, bool post) - : hook_id_(0), - callback_(callback) + : callback_(callback), + m_DispatchHook(&ConCommand::Dispatch, this, (post) ? nullptr : &CommandHook::Dispatch, (post) ? &CommandHook::Dispatch : nullptr) { - hook_id_ = SH_ADD_HOOK(ConCommand, Dispatch, cmd, SH_MEMBER(this, &CommandHook::Dispatch), post); + m_DispatchHook.Add(cmd); } CommandHook::~CommandHook() { - if (hook_id_) - SH_REMOVE_HOOK_ID(hook_id_); } -void CommandHook::Dispatch(DISPATCH_ARGS) +#if SOURCE_ENGINE >= SE_ORANGEBOX +KHook::Return CommandHook::Dispatch(ConCommand*, const CCommand& command) +#else +KHook::Return CommandHook::Dispatch(ConCommand*) +#endif { - DISPATCH_PROLOGUE; + DISPATCH_PROLOGUE EngineArgs args(command); AddRef(); bool rval = callback_(sCoreProviderImpl.CommandClient(), &args); Release(); if (rval) - RETURN_META(MRES_SUPERCEDE); -} - -void CommandHook::Zap() -{ - hook_id_ = 0; -} + { + return { KHook::Action::Supersede }; + } + return { KHook::Action::Ignore }; +} \ No newline at end of file diff --git a/core/GameHooks.h b/core/GameHooks.h index 83c8ad700..4a6b92e01 100644 --- a/core/GameHooks.h +++ b/core/GameHooks.h @@ -35,6 +35,7 @@ #include #include #include +#include class ConVar; class CCommand; @@ -68,12 +69,19 @@ public: public: CommandHook(ConCommand *cmd, const Callback &callback, bool post); ~CommandHook(); - void Dispatch(DISPATCH_ARGS); - void Zap(); +#if SOURCE_ENGINE >= SE_ORANGEBOX + KHook::Return Dispatch(ConCommand*, const CCommand&); +#else + KHook::Return Dispatch(ConCommand*); +#endif private: - int hook_id_; Callback callback_; +#if SOURCE_ENGINE >= SE_ORANGEBOX + KHook::Virtual m_DispatchHook; +#else + KHook::Virtual m_DispatchHook; +#endif }; class GameHooks @@ -97,21 +105,29 @@ public: return last_command_client_; } -private: +public: // Static callback that Valve's ConVar object executes when the convar's value changes. #if SOURCE_ENGINE >= SE_ORANGEBOX - static void OnConVarChanged(ConVar *pConVar, const char *oldValue, float flOldValue); + static KHook::Return OnConVarChanged(ICvar*, ConVar *pConVar, const char *oldValue, float flOldValue); #else - static void OnConVarChanged(ConVar *pConVar, const char *oldValue); + static KHook::Return OnConVarChanged(ICvar*, ConVar *pConVar, const char *oldValue); #endif +private: // Callback for when StartQueryCvarValue() has finished. #if SOURCE_ENGINE != SE_DARKMESSIAH void OnQueryCvarValueFinished(QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue); + KHook::Return GameDLLOnQueryCvarValueFinished(IServerGameDLL*, QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, + const char *cvarName, const char *cvarValue); + KHook::Virtual m_GameDLLOnQueryCvarValueFinishedHook; + KHook::Return VSPOnQueryCvarValueFinished(IServerPluginCallbacks*, QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result, + const char *cvarName, const char *cvarValue); + KHook::Virtual m_VSPOnQueryCvarValueFinishedHook; #endif - void SetCommandClient(int client); + KHook::Return SetCommandClient(IServerGameClients*, int client); + KHook::Virtual m_SetCommandClient; private: class HookList : public std::vector diff --git a/core/HalfLife2.cpp b/core/HalfLife2.cpp index 91a1e0aef..082412e94 100644 --- a/core/HalfLife2.cpp +++ b/core/HalfLife2.cpp @@ -756,7 +756,7 @@ void CHalfLife2::AddToFakeCliCmdQueue(int client, int userid, const char *cmd) { pFake = new DelayedFakeCliCmd; } else { - pFake = m_FreeCmds.front(); + pFake = m_FreeCmds.top(); m_FreeCmds.pop(); } @@ -852,7 +852,7 @@ const ICommandArgs *CHalfLife2::PeekCommandStack() return NULL; } - return m_CommandStack.front().args; + return m_CommandStack.top().args; } void CHalfLife2::PopCommandStack() @@ -863,9 +863,9 @@ void CHalfLife2::PopCommandStack() const char *CHalfLife2::CurrentCommandName() { #if SOURCE_ENGINE >= SE_ORANGEBOX - return m_CommandStack.front().args->Arg(0); + return m_CommandStack.top().args->Arg(0); #else - return m_CommandStack.front().cmd; + return m_CommandStack.top().cmd; #endif } diff --git a/core/HalfLife2.h b/core/HalfLife2.h index 5496a337b..bf24f12cd 100644 --- a/core/HalfLife2.h +++ b/core/HalfLife2.h @@ -32,9 +32,8 @@ #ifndef _INCLUDE_SOURCEMOD_CHALFLIFE2_H_ #define _INCLUDE_SOURCEMOD_CHALFLIFE2_H_ -#include -#include -#include +#include +#include #include #include #include @@ -54,7 +53,6 @@ namespace SourceMod { class ICommandArgs; } // namespace SourceMod -using namespace SourceHook; using namespace SourceMod; static const int ENTREF_MASK = (1 << 31); @@ -153,7 +151,7 @@ typedef NameHashSet DataMapCache; struct DelayedFakeCliCmd { - String cmd; + std::string cmd; int client; int userid; }; @@ -288,8 +286,8 @@ private: int m_SayTextMsg; int m_VGUIMenu; Queue m_CmdQueue; - CStack m_FreeCmds; - CStack m_CommandStack; + std::stack m_FreeCmds; + std::stack m_CommandStack; Queue m_DelayedKicks; void *m_pGetCommandLine; #if SOURCE_ENGINE == SE_CSGO diff --git a/core/Logger.cpp b/core/Logger.cpp index 2312e3b0d..aced8c00c 100644 --- a/core/Logger.cpp +++ b/core/Logger.cpp @@ -43,33 +43,36 @@ bool g_in_game_log_hook = false; static LoggerCore g_LoggerCore; -SH_DECL_HOOK1_void(IVEngineServer, LogPrint, SH_NOATTRIB, false, const char *); - -static void HookLogPrint(const char *message) +static KHook::Return HookLogPrint(IVEngineServer*, const char *message) { g_in_game_log_hook = true; bool stopped = logicore.callbacks->OnLogPrint(message); g_in_game_log_hook = false; if (stopped) - RETURN_META(MRES_SUPERCEDE); + { + return { KHook::Action::Supersede }; + } + return { KHook::Action::Ignore }; } +KHook::Virtual LogPrintHook(&IVEngineServer::LogPrint, &HookLogPrint, nullptr); + void LoggerCore::OnSourceModStartup(bool late) { - SH_ADD_HOOK(IVEngineServer, LogPrint, engine, SH_STATIC(HookLogPrint), false); + LogPrintHook.Add(engine); } void LoggerCore::OnSourceModAllShutdown() { - SH_REMOVE_HOOK(IVEngineServer, LogPrint, engine, SH_STATIC(HookLogPrint), false); + LogPrintHook.Remove(engine); } void Engine_LogPrintWrapper(const char *msg) { if (g_in_game_log_hook) { - ENGINE_CALL(LogPrint)(msg); + LogPrintHook.CallOriginal(engine, msg); } else { diff --git a/core/Logger.h b/core/Logger.h index a12dc9ef6..5699e19a8 100644 --- a/core/Logger.h +++ b/core/Logger.h @@ -33,11 +33,9 @@ #define _INCLUDE_SOURCEMOD_CLOGGER_H_ #include -#include +#include #include "sm_globals.h" -using namespace SourceHook; - class LoggerCore : public SMGlobalClass { public: //SMGlobalClass diff --git a/core/MenuManager.h b/core/MenuManager.h index 3c75347ef..2d9bfe44b 100644 --- a/core/MenuManager.h +++ b/core/MenuManager.h @@ -33,14 +33,11 @@ #define _INCLUDE_SOURCEMOD_MENUMANAGER_H_ #include -#include -#include -#include +#include #include "sm_globals.h" #include using namespace SourceMod; -using namespace SourceHook; class MenuManager : public IMenuManager, @@ -102,7 +99,7 @@ protected: private: int m_ShowMenu; IMenuStyle *m_pDefaultStyle; - CVector m_Styles; + std::vector m_Styles; HandleType_t m_StyleType; HandleType_t m_MenuType; std::string m_SelectSound = ""; diff --git a/core/MenuStyle_Radio.cpp b/core/MenuStyle_Radio.cpp index 035219e32..0ca5ebf9a 100644 --- a/core/MenuStyle_Radio.cpp +++ b/core/MenuStyle_Radio.cpp @@ -144,7 +144,7 @@ void CRadioStyle::OnSourceModShutdown() while (!m_FreeDisplays.empty()) { - delete m_FreeDisplays.front(); + delete m_FreeDisplays.top(); m_FreeDisplays.pop(); } } @@ -261,7 +261,7 @@ CRadioDisplay *CRadioStyle::MakeRadioDisplay(CRadioMenu *menu) } else { - display = m_FreeDisplays.front(); + display = m_FreeDisplays.top(); m_FreeDisplays.pop(); display->Reset(); } diff --git a/core/MenuStyle_Radio.h b/core/MenuStyle_Radio.h index afb356ef0..0febb8311 100644 --- a/core/MenuStyle_Radio.h +++ b/core/MenuStyle_Radio.h @@ -39,8 +39,8 @@ #include #include "UserMessages.h" #include "sm_fastlink.h" -#include -#include +#include +#include #include #include "logic/common_logic.h" #include "AutoHandleRooter.h" @@ -106,7 +106,7 @@ public: CRadioMenuPlayer *GetRadioMenuPlayer(int client); private: CRadioMenuPlayer *m_players; - CStack m_FreeDisplays; + std::stack m_FreeDisplays; }; class CRadioDisplay : public IMenuPanel @@ -133,8 +133,8 @@ public: //IMenuPanel unsigned int GetApproxMemUsage(); bool DirectSet(const char *str); private: - String m_BufferText; - String m_Title; + std::string m_BufferText; + std::string m_Title; unsigned int m_NextPos; int keys; }; diff --git a/core/MenuStyle_Valve.cpp b/core/MenuStyle_Valve.cpp index 892720984..88f7bfea4 100644 --- a/core/MenuStyle_Valve.cpp +++ b/core/MenuStyle_Valve.cpp @@ -34,15 +34,15 @@ #include "MenuStyle_Valve.h" #include "PlayerManager.h" #include "ConCmdManager.h" - -SH_DECL_HOOK4_void(IServerPluginHelpers, CreateMessage, SH_NOATTRIB, false, edict_t *, DIALOG_TYPE, KeyValues *, IServerPluginCallbacks *); +#include "engine/iserverplugin.h" ValveMenuStyle g_ValveMenuStyle; extern const char *g_OptionNumTable[]; extern const char *g_OptionCmdTable[]; -CallClass *g_pSPHCC = NULL; -ValveMenuStyle::ValveMenuStyle() : m_players(new CValveMenuPlayer[256+1]) +ValveMenuStyle::ValveMenuStyle() : + m_HookCreateMessage(&IServerPluginHelpers::CreateMessage, this, &ValveMenuStyle::HookCreateMessage, nullptr), + m_players(new CValveMenuPlayer[256+1]) { } @@ -66,31 +66,30 @@ bool ValveMenuStyle::OnClientCommand(int client, const char *cmdname, const CCom void ValveMenuStyle::OnSourceModAllInitialized() { g_Players.AddClientListener(this); - SH_ADD_HOOK(IServerPluginHelpers, CreateMessage, serverpluginhelpers, SH_MEMBER(this, &ValveMenuStyle::HookCreateMessage), false); - g_pSPHCC = SH_GET_CALLCLASS(serverpluginhelpers); + m_HookCreateMessage.Add(serverpluginhelpers); } void ValveMenuStyle::OnSourceModShutdown() { - SH_RELEASE_CALLCLASS(g_pSPHCC); - SH_REMOVE_HOOK(IServerPluginHelpers, CreateMessage, serverpluginhelpers, SH_MEMBER(this, &ValveMenuStyle::HookCreateMessage), false); + m_HookCreateMessage.Remove(serverpluginhelpers); g_Players.RemoveClientListener(this); } -void ValveMenuStyle::HookCreateMessage(edict_t *pEdict, +KHook::Return ValveMenuStyle::HookCreateMessage(IServerPluginHelpers*, + edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin) { if (type != DIALOG_MENU) { - return; + return { KHook::Action::Ignore }; } int client = IndexOfEdict(pEdict); if (client < 1 || client > 256) { - return; + return { KHook::Action::Ignore }; } CValveMenuPlayer *player = &m_players[client]; @@ -110,6 +109,7 @@ void ValveMenuStyle::HookCreateMessage(edict_t *pEdict, */ _CancelClientMenu(client, MenuCancel_Interrupted, true); } + return { KHook::Action::Ignore }; } IMenuPanel *ValveMenuStyle::CreatePanel() @@ -323,7 +323,8 @@ void CValveMenuDisplay::SendRawDisplay(int client, int priority, unsigned int ti m_pKv->SetInt("level", priority); m_pKv->SetInt("time", time ? time : 200); - SH_CALL(g_pSPHCC, &IServerPluginHelpers::CreateMessage)( + KHook::CallOriginal(&IServerPluginHelpers::CreateMessage, + serverpluginhelpers, PEntityOfEntIndex(client), DIALOG_MENU, m_pKv, diff --git a/core/MenuStyle_Valve.h b/core/MenuStyle_Valve.h index 03fa1226f..55402df79 100644 --- a/core/MenuStyle_Valve.h +++ b/core/MenuStyle_Valve.h @@ -79,7 +79,8 @@ public: //IMenuStyle unsigned int GetApproxMemUsage(); bool IsSupported() { return true; } private: - void HookCreateMessage(edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin); + KHook::Return HookCreateMessage(IServerPluginHelpers*, edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin); + KHook::Virtual m_HookCreateMessage; private: CValveMenuPlayer *m_players; }; diff --git a/core/MenuVoting.h b/core/MenuVoting.h index 7660b2943..11f299310 100644 --- a/core/MenuVoting.h +++ b/core/MenuVoting.h @@ -34,11 +34,10 @@ #include #include -#include +#include #include "sm_globals.h" #include -using namespace SourceHook; using namespace SourceMod; class VoteMenuHandler : @@ -97,7 +96,7 @@ private: unsigned int m_Clients; unsigned int m_TotalClients; unsigned int m_Items; - CVector m_Votes; + std::vector m_Votes; IBaseMenu *m_pCurMenu; bool m_bStarted; bool m_bCancelled; diff --git a/core/NextMap.cpp b/core/NextMap.cpp index 16b6b25a3..e1daad09c 100644 --- a/core/NextMap.cpp +++ b/core/NextMap.cpp @@ -34,7 +34,6 @@ #include "HalfLife2.h" #include "sourcemm_api.h" #include "sm_stringutil.h" -#include "sourcehook.h" #include "logic_bridge.h" #include "compat_wrappers.h" #include @@ -42,17 +41,7 @@ NextMapManager g_NextMap; -#if SOURCE_ENGINE != SE_DARKMESSIAH -SH_DECL_HOOK2_void(IVEngineServer, ChangeLevel, SH_NOATTRIB, 0, const char *, const char *); -#else -SH_DECL_HOOK4_void(IVEngineServer, ChangeLevel, SH_NOATTRIB, 0, const char *, const char *, const char *, bool); -#endif - -#if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#else -SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -#endif +KHook::Virtual gCommandDispatch(&ConCommand::Dispatch, CmdChangeLevelCallback, nullptr); ConCommand *changeLevelCmd = NULL; @@ -63,27 +52,25 @@ bool g_forcedChange = false; void NextMapManager::OnSourceModAllInitialized_Post() { - SH_ADD_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false); - + m_HookChangeLevel.Add(engine); ConCommand *pCmd = FindCommand("changelevel"); if (pCmd != NULL) { - SH_ADD_HOOK(ConCommand, Dispatch, pCmd, SH_STATIC(CmdChangeLevelCallback), false); + gCommandDispatch.Add(pCmd); changeLevelCmd = pCmd; } } void NextMapManager::OnSourceModShutdown() { - SH_REMOVE_HOOK(IVEngineServer, ChangeLevel, engine, SH_MEMBER(this, &NextMapManager::HookChangeLevel), false); + m_HookChangeLevel.Remove(engine); if (changeLevelCmd != NULL) { - SH_REMOVE_HOOK(ConCommand, Dispatch, changeLevelCmd, SH_STATIC(CmdChangeLevelCallback), false); + gCommandDispatch.Remove(changeLevelCmd); } - SourceHook::List::iterator iter; - iter = m_mapHistory.begin(); + auto iter = m_mapHistory.begin(); while (iter != m_mapHistory.end()) { @@ -112,15 +99,15 @@ bool NextMapManager::SetNextMap(const char *map) static char g_nextMap[PLATFORM_MAX_PATH]; #if SOURCE_ENGINE != SE_DARKMESSIAH -void NextMapManager::HookChangeLevel(const char *map, const char *unknown) +KHook::Return NextMapManager::HookChangeLevel(IVEngineServer* this_ptr, const char *map, const char *unknown) #else -void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const char *video, bool bLongLoading) +KHook::Return NextMapManager::HookChangeLevel(IVEngineServer* this_ptr, const char *map, const char *unknown, const char *video, bool bLongLoading) #endif { if (g_forcedChange) { logger->LogMessage("[SM] Changed map to \"%s\"", map); - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } const char *newmap = sm_nextmap.GetString(); @@ -135,7 +122,7 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const if (newmap[0] == '\0' || !g_HL2.IsMapValid(newmap)) { - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } logger->LogMessage("[SM] Changed map to \"%s\"", newmap); @@ -144,9 +131,9 @@ void NextMapManager::HookChangeLevel(const char *map, const char *unknown, const ke::SafeStrcpy(m_tempChangeInfo.m_changeReason, sizeof(m_tempChangeInfo.m_changeReason), "Normal level change"); #if SOURCE_ENGINE != SE_DARKMESSIAH - RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown)); + return KHook::Recall(KHook::Return{ KHook::Action::Ignore }, this_ptr, newmap, unknown); #else - RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown, video, bLongLoading)); + return KHook::Recall(KHook::Return{ KHook::Action::Ignore }, this_ptr, newmap, unknown, video, bLongLoading); #endif } @@ -186,7 +173,7 @@ void NextMapManager::OnSourceModLevelChange( const char *mapName ) historydiff = (m_mapHistory.size() * -1); } - for (SourceHook::List::iterator iter = m_mapHistory.begin(); historydiff++ < 0; iter = m_mapHistory.erase(iter)) + for (auto iter = m_mapHistory.begin(); historydiff++ < 0; iter = m_mapHistory.erase(iter)) { delete (MapChangeData *)*iter; } @@ -210,24 +197,24 @@ void NextMapManager::ForceChangeLevel( const char *mapName, const char* changeRe g_forcedChange = false; } -NextMapManager::NextMapManager() +NextMapManager::NextMapManager() : + m_HookChangeLevel(&IVEngineServer::ChangeLevel, this, &NextMapManager::HookChangeLevel, nullptr) { m_tempChangeInfo = MapChangeData(); - m_mapHistory = SourceHook::List(); } #if SOURCE_ENGINE >= SE_ORANGEBOX -void CmdChangeLevelCallback(const CCommand &command) +KHook::Return CmdChangeLevelCallback(ConCommand*, const CCommand &command) { #else -void CmdChangeLevelCallback() +KHook::Return CmdChangeLevelCallback(ConCommand*) { CCommand command; #endif if (command.ArgC() < 2) { - return; + return { KHook::Action::Ignore }; } if (g_NextMap.m_tempChangeInfo.m_mapName[0] == '\0') @@ -235,4 +222,6 @@ void CmdChangeLevelCallback() ke::SafeStrcpy(g_NextMap.m_tempChangeInfo.m_mapName, sizeof(g_NextMap.m_tempChangeInfo.m_mapName), command.Arg(1)); ke::SafeStrcpy(g_NextMap.m_tempChangeInfo.m_changeReason, sizeof(g_NextMap.m_tempChangeInfo.m_changeReason), "changelevel Command"); } + + return { KHook::Action::Ignore }; } diff --git a/core/NextMap.h b/core/NextMap.h index 2f6c0523e..e11b0cf1c 100644 --- a/core/NextMap.h +++ b/core/NextMap.h @@ -34,9 +34,10 @@ #include "sm_globals.h" #include -#include "sh_list.h" +#include #include "sm_stringutil.h" #include +#include struct MapChangeData { @@ -60,9 +61,9 @@ struct MapChangeData }; #if SOURCE_ENGINE >= SE_ORANGEBOX -void CmdChangeLevelCallback(const CCommand &command); +KHook::Return CmdChangeLevelCallback(ConCommand*, const CCommand &command); #else -void CmdChangeLevelCallback(); +KHook::Return CmdChangeLevelCallback(ConCommand*); #endif class NextMapManager : public SMGlobalClass @@ -71,9 +72,9 @@ public: NextMapManager(); #if SOURCE_ENGINE >= SE_ORANGEBOX - friend void CmdChangeLevelCallback(const CCommand &command); + friend KHook::Return CmdChangeLevelCallback(ConCommand*, const CCommand &command); #else - friend void CmdChangeLevelCallback(); + friend KHook::Return CmdChangeLevelCallback(ConCommand*); #endif void OnSourceModAllInitialized_Post(); @@ -86,13 +87,15 @@ public: void ForceChangeLevel(const char *mapName, const char* changeReason); #if SOURCE_ENGINE != SE_DARKMESSIAH - void HookChangeLevel(const char *map, const char *unknown); + KHook::Virtual m_HookChangeLevel; + KHook::Return HookChangeLevel(IVEngineServer*, const char *map, const char *unknown); #else - void HookChangeLevel(const char *map, const char *unknown, const char *video, bool bLongLoading); + KHook::Virtual m_HookChangeLevel; + KHook::Return HookChangeLevel(IVEngineServer*, const char *map, const char *unknown, const char *video, bool bLongLoading); #endif public: - SourceHook::List m_mapHistory; + std::list m_mapHistory; private: MapChangeData m_tempChangeInfo; diff --git a/core/PlayerManager.cpp b/core/PlayerManager.cpp index 1d541daa3..72663bcf3 100644 --- a/core/PlayerManager.cpp +++ b/core/PlayerManager.cpp @@ -64,38 +64,11 @@ IForward *ServerExitHibernation = NULL; const unsigned int *g_NumPlayersToAuth = NULL; int lifestate_offset = -1; -List target_processors; +std::list target_processors; ConVar sm_debug_connect("sm_debug_connect", "1", 0, "Log Debug information about potential connection issues."); -SH_DECL_HOOK5(IServerGameClients, ClientConnect, SH_NOATTRIB, 0, bool, edict_t *, const char *, const char *, char *, int); -SH_DECL_HOOK2_void(IServerGameClients, ClientPutInServer, SH_NOATTRIB, 0, edict_t *, const char *); -SH_DECL_HOOK1_void(IServerGameClients, ClientDisconnect, SH_NOATTRIB, 0, edict_t *); -#if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &); -#else -SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *); -#endif -SH_DECL_HOOK1_void(IServerGameClients, ClientSettingsChanged, SH_NOATTRIB, 0, edict_t *); - -#if SOURCE_ENGINE >= SE_EYE -SH_DECL_HOOK2_void(IServerGameClients, ClientCommandKeyValues, SH_NOATTRIB, 0, edict_t *, KeyValues *); -#endif - -SH_DECL_HOOK3_void(IServerGameDLL, ServerActivate, SH_NOATTRIB, 0, edict_t *, int, int); - -#if SOURCE_ENGINE >= SE_LEFT4DEAD -SH_DECL_HOOK1_void(IServerGameDLL, ServerHibernationUpdate, SH_NOATTRIB, 0, bool); -#elif SOURCE_ENGINE > SE_EYE // 2013/orangebox, but not original orangebox. -SH_DECL_HOOK1_void(IServerGameDLL, SetServerHibernation, SH_NOATTRIB, 0, bool); -#endif - -#if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_EXTERN1_void(ConCommand, Dispatch, SH_NOATTRIB, false, const CCommand &); -#else -SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false); -#endif -SH_DECL_HOOK2_void(IVEngineServer, ClientPrintf, SH_NOATTRIB, 0, edict_t *, const char *); +KHook::Virtual gHookCommandDispatch(&ConCommand::Dispatch, nullptr, &CmdMaxplayersCallback); static void PrintfBuffer_FrameAction(void *data) { @@ -125,7 +98,22 @@ public: } } s_KickPlayerTimer; -PlayerManager::PlayerManager() +PlayerManager::PlayerManager() : + m_HookClientConnect(&IServerGameClients::ClientConnect, this, &PlayerManager::OnClientConnect, &PlayerManager::OnClientConnect_Post), + m_HookClientPutInServer(&IServerGameClients::ClientPutInServer, this, nullptr, &PlayerManager::OnClientPutInServer), + m_HookClientDisconnect(&IServerGameClients::ClientDisconnect, this, &PlayerManager::OnClientDisconnect, &PlayerManager::OnClientDisconnect_Post), + m_HookClientCommand(&IServerGameClients::ClientCommand, this, &PlayerManager::OnClientCommand, nullptr), +#if SOURCE_ENGINE >= SE_EYE + m_HookClientCommandKeyValues(&IServerGameClients::ClientCommandKeyValues, this, &PlayerManager::OnClientCommandKeyValues, &PlayerManager::OnClientCommandKeyValues_Post), +#endif + m_HookClientSettingsChanged(&IServerGameClients::ClientSettingsChanged, this, nullptr, &PlayerManager::OnClientSettingsChanged), + m_HookServerActivate(&IServerGameDLL::ServerActivate, this, nullptr, &PlayerManager::OnServerActivate), +#if SOURCE_ENGINE >= SE_LEFT4DEAD + m_HookServerHibernationUpdate(&IServerGameDLL::ServerHibernationUpdate, this, nullptr, &PlayerManager::OnServerHibernationUpdate), +#elif SOURCE_ENGINE > SE_EYE + m_HookSetServerHibernation(&IServerGameDLL::SetServerHibernation, this, nullptr, &PlayerManager::OnServerHibernationUpdate), +#endif + m_HookClientPrintf(&IVEngineServer::ClientPrintf, this, &PlayerManager::OnClientPrintf, nullptr) { m_AuthQueue = NULL; m_bServerActivated = false; @@ -164,24 +152,21 @@ void PlayerManager::OnSourceModStartup(bool late) void PlayerManager::OnSourceModAllInitialized() { - SH_ADD_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false); - SH_ADD_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect_Post), true); - SH_ADD_HOOK(IServerGameClients, ClientPutInServer, serverClients, SH_MEMBER(this, &PlayerManager::OnClientPutInServer), true); - SH_ADD_HOOK(IServerGameClients, ClientDisconnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect), false); - SH_ADD_HOOK(IServerGameClients, ClientDisconnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect_Post), true); - SH_ADD_HOOK(IServerGameClients, ClientCommand, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommand), false); + m_HookClientConnect.Add(serverClients); + m_HookClientPutInServer.Add(serverClients); + m_HookClientDisconnect.Add(serverClients); + m_HookClientCommand.Add(serverClients); #if SOURCE_ENGINE >= SE_EYE - SH_ADD_HOOK(IServerGameClients, ClientCommandKeyValues, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommandKeyValues), false); - SH_ADD_HOOK(IServerGameClients, ClientCommandKeyValues, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommandKeyValues_Post), true); + m_HookClientCommandKeyValues.Add(serverClients); #endif - SH_ADD_HOOK(IServerGameClients, ClientSettingsChanged, serverClients, SH_MEMBER(this, &PlayerManager::OnClientSettingsChanged), true); - SH_ADD_HOOK(IServerGameDLL, ServerActivate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerActivate), true); + m_HookClientSettingsChanged.Add(serverClients); + m_HookServerActivate.Add(gamedll); #if SOURCE_ENGINE >= SE_LEFT4DEAD - SH_ADD_HOOK(IServerGameDLL, ServerHibernationUpdate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerHibernationUpdate), true); + m_HookServerHibernationUpdate.Add(gamedll); #elif SOURCE_ENGINE > SE_EYE // 2013/orangebox, but not original orangebox. - SH_ADD_HOOK(IServerGameDLL, SetServerHibernation, gamedll, SH_MEMBER(this, &PlayerManager::OnServerHibernationUpdate), true); + m_HookSetServerHibernation.Add(gamedll); #endif - SH_ADD_HOOK(IVEngineServer, ClientPrintf, engine, SH_MEMBER(this, &PlayerManager::OnClientPrintf), false); + m_HookClientPrintf.Add(engine); sharesys->AddInterface(NULL, this); @@ -214,31 +199,28 @@ void PlayerManager::OnSourceModAllInitialized() ConCommand *pCmd = FindCommand("maxplayers"); if (pCmd != NULL) { - SH_ADD_HOOK(ConCommand, Dispatch, pCmd, SH_STATIC(CmdMaxplayersCallback), true); + gHookCommandDispatch.Add(pCmd); maxplayersCmd = pCmd; } } void PlayerManager::OnSourceModShutdown() { - SH_REMOVE_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect), false); - SH_REMOVE_HOOK(IServerGameClients, ClientConnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientConnect_Post), true); - SH_REMOVE_HOOK(IServerGameClients, ClientPutInServer, serverClients, SH_MEMBER(this, &PlayerManager::OnClientPutInServer), true); - SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect), false); - SH_REMOVE_HOOK(IServerGameClients, ClientDisconnect, serverClients, SH_MEMBER(this, &PlayerManager::OnClientDisconnect_Post), true); - SH_REMOVE_HOOK(IServerGameClients, ClientCommand, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommand), false); + m_HookClientConnect.Remove(serverClients); + m_HookClientPutInServer.Remove(serverClients); + m_HookClientDisconnect.Remove(serverClients); + m_HookClientCommand.Remove(serverClients); #if SOURCE_ENGINE >= SE_EYE - SH_REMOVE_HOOK(IServerGameClients, ClientCommandKeyValues, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommandKeyValues), false); - SH_REMOVE_HOOK(IServerGameClients, ClientCommandKeyValues, serverClients, SH_MEMBER(this, &PlayerManager::OnClientCommandKeyValues_Post), true); + m_HookClientCommandKeyValues.Remove(serverClients); #endif - SH_REMOVE_HOOK(IServerGameClients, ClientSettingsChanged, serverClients, SH_MEMBER(this, &PlayerManager::OnClientSettingsChanged), true); - SH_REMOVE_HOOK(IServerGameDLL, ServerActivate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerActivate), true); + m_HookClientSettingsChanged.Remove(serverClients); + m_HookServerActivate.Remove(gamedll); #if SOURCE_ENGINE >= SE_LEFT4DEAD - SH_REMOVE_HOOK(IServerGameDLL, ServerHibernationUpdate, gamedll, SH_MEMBER(this, &PlayerManager::OnServerHibernationUpdate), true); + m_HookServerHibernationUpdate.Remove(gamedll); #elif SOURCE_ENGINE > SE_EYE // 2013/orangebox, but not original orangebox. - SH_REMOVE_HOOK(IServerGameDLL, SetServerHibernation, gamedll, SH_MEMBER(this, &PlayerManager::OnServerHibernationUpdate), true); + m_HookSetServerHibernation.Remove(gamedll); #endif - SH_REMOVE_HOOK(IVEngineServer, ClientPrintf, engine, SH_MEMBER(this, &PlayerManager::OnClientPrintf), false); + m_HookClientPrintf.Remove(engine); /* Release forwards */ forwardsys->ReleaseForward(m_clconnect); @@ -265,7 +247,7 @@ void PlayerManager::OnSourceModShutdown() if (maxplayersCmd != NULL) { - SH_REMOVE_HOOK(ConCommand, Dispatch, maxplayersCmd, SH_STATIC(CmdMaxplayersCallback), true); + gHookCommandDispatch.Remove(maxplayersCmd); } } @@ -308,7 +290,7 @@ ConfigResult PlayerManager::OnSourceModConfigChanged(const char *key, return ConfigResult_Ignore; } -void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax) +KHook::Return PlayerManager::OnServerActivate(IServerGameDLL*, edict_t *pEdictList, int edictCount, int clientMax) { static ConVar *tv_enable = icvar->FindVar("tv_enable"); #if SOURCE_ENGINE == SE_TF2 @@ -331,8 +313,7 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl m_onActivate->Execute(NULL); m_onActivate2->Execute(NULL); - List::iterator iter; - for (iter = m_hooks.begin(); iter != m_hooks.end(); iter++) + for (auto iter = m_hooks.begin(); iter != m_hooks.end(); iter++) { if ((*iter)->GetClientListenerVersion() >= 5) { @@ -348,6 +329,8 @@ void PlayerManager::OnServerActivate(edict_t *pEdictList, int edictCount, int cl } SM_ExecuteAllConfigs(); + + return { KHook::Action::Ignore }; } bool PlayerManager::IsServerActivated() @@ -434,9 +417,8 @@ void PlayerManager::RunAuthChecks() const char *steamId = pPlayer->GetSteam2Id(); /* Send to extensions */ - List::iterator iter; IClientListener *pListener; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientAuthorized(client, steamId ? steamId : authstr); @@ -492,7 +474,7 @@ void PlayerManager::RunAuthChecks() } } -bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) +KHook::Return PlayerManager::OnClientConnect(IServerGameClients* clients, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) { int client = IndexOfEdict(pEntity); CPlayer *pPlayer = &m_Players[client]; @@ -511,8 +493,8 @@ bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const logger->LogMessage("\"%s<%d><%s><>\" was already connected to the server.", pPlayer->GetName(), pPlayer->GetUserId(), pAuth); } - OnClientDisconnect(pPlayer->GetEdict()); - OnClientDisconnect_Post(pPlayer->GetEdict()); + OnClientDisconnect(clients, pPlayer->GetEdict()); + OnClientDisconnect_Post(clients, pPlayer->GetEdict()); } pPlayer->Initialize(pszName, pszAddress, pEntity); @@ -537,14 +519,13 @@ bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const pPlayer->m_OriginalLangId = pPlayer->m_LangId; } - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); if (!pListener->InterceptClientConnect(client, reject, maxrejectlen)) { - RETURN_META_VALUE(MRES_SUPERCEDE, false); + return { KHook::Action::Supersede, false }; } } @@ -568,30 +549,29 @@ bool PlayerManager::OnClientConnect(edict_t *pEntity, const char *pszName, const { if (!pPlayer->IsFakeClient()) { - RETURN_META_VALUE(MRES_SUPERCEDE, false); + return { KHook::Action::Supersede, false }; } } - return true; + return { KHook::Action::Ignore, true }; } -bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) +KHook::Return PlayerManager::OnClientConnect_Post(IServerGameClients*, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen) { int client = IndexOfEdict(pEntity); - bool orig_value = META_RESULT_ORIG_RET(bool); + bool orig_value = *(bool*)KHook::GetOriginalValuePtr(); CPlayer *pPlayer = &m_Players[client]; if (orig_value) { - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientConnected(client); if (!pPlayer->IsConnected()) { - return true; + return { KHook::Action::Ignore }; } } @@ -611,10 +591,10 @@ bool PlayerManager::OnClientConnect_Post(edict_t *pEntity, const char *pszName, InvalidatePlayer(pPlayer); } - return true; + return { KHook::Action::Ignore }; } -void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername) +KHook::Return PlayerManager::OnClientPutInServer(IServerGameClients* clients, edict_t *pEntity, const char *playername) { cell_t res; int client = IndexOfEdict(pEntity); @@ -693,21 +673,21 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername m_SourceTVUserId = userId; } - if (!OnClientConnect(pEntity, playername, "127.0.0.1", error, sizeof(error))) + if (!OnClientConnect(clients, pEntity, playername, "127.0.0.1", error, sizeof(error)).ret) { /* :TODO: kick the bot if it's rejected */ - return; + return { KHook::Action::Ignore }; } - List::iterator iter; + IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientConnected(client); /* See if bot was kicked */ if (!pPlayer->IsConnected()) { - return; + return { KHook::Action::Ignore }; } } @@ -720,7 +700,7 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername const char *steamId = pPlayer->GetSteam2Id(); /* Now do authorization */ - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientAuthorized(client, steamId ? steamId : pPlayer->m_AuthID.c_str()); @@ -751,9 +731,8 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername pPlayer->Connect(); m_PlayerCount++; - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientPutInServer(client); @@ -766,6 +745,8 @@ void PlayerManager::OnClientPutInServer(edict_t *pEntity, const char *playername { pPlayer->DoPostConnectAuthorization(); } + + return { KHook::Action::Ignore }; } void PlayerManager::OnSourceModLevelEnd() @@ -775,14 +756,14 @@ void PlayerManager::OnSourceModLevelEnd() { if (m_Players[i].IsConnected()) { - OnClientDisconnect(m_Players[i].GetEdict()); - OnClientDisconnect_Post(m_Players[i].GetEdict()); + OnClientDisconnect(serverClients, m_Players[i].GetEdict()); + OnClientDisconnect_Post(serverClients, m_Players[i].GetEdict()); } } m_PlayerCount = 0; } -void PlayerManager::OnServerHibernationUpdate(bool bHibernating) +KHook::Return PlayerManager::OnServerHibernationUpdate(IServerGameDLL*, bool bHibernating) { cell_t res; if (bHibernating) @@ -805,14 +786,16 @@ void PlayerManager::OnServerHibernationUpdate(bool bHibernating) if (pPlayer->IsSourceTV() || pPlayer->IsReplay()) continue; #endif - OnClientDisconnect(m_Players[i].GetEdict()); - OnClientDisconnect_Post(m_Players[i].GetEdict()); + OnClientDisconnect(serverClients, m_Players[i].GetEdict()); + OnClientDisconnect_Post(serverClients, m_Players[i].GetEdict()); } } } + + return { KHook::Action::Ignore }; } -void PlayerManager::OnClientDisconnect(edict_t *pEntity) +KHook::Return PlayerManager::OnClientDisconnect(IServerGameClients*, edict_t *pEntity) { cell_t res; int client = IndexOfEdict(pEntity); @@ -826,7 +809,7 @@ void PlayerManager::OnClientDisconnect(edict_t *pEntity) else { /* We don't care, prevent a double call */ - return; + return { KHook::Action::Ignore }; } if (pPlayer->WasCountedAsInGame()) @@ -834,23 +817,23 @@ void PlayerManager::OnClientDisconnect(edict_t *pEntity) m_PlayerCount--; } - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientDisconnecting(client); } + return { KHook::Action::Ignore }; } -void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity) +KHook::Return PlayerManager::OnClientDisconnect_Post(IServerGameClients*, edict_t *pEntity) { int client = IndexOfEdict(pEntity); CPlayer *pPlayer = &m_Players[client]; if (!pPlayer->IsConnected()) { /* We don't care, prevent a double call */ - return; + return { KHook::Action::Ignore }; } InvalidatePlayer(pPlayer); @@ -865,26 +848,26 @@ void PlayerManager::OnClientDisconnect_Post(edict_t *pEntity) m_cldisconnect_post->PushCell(client); m_cldisconnect_post->Execute(&res, NULL); - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnClientDisconnected(client); } + return { KHook::Action::Ignore }; } -void PlayerManager::OnClientPrintf(edict_t *pEdict, const char *szMsg) +KHook::Return PlayerManager::OnClientPrintf(IVEngineServer*, edict_t *pEdict, const char *szMsg) { int client = IndexOfEdict(pEdict); CPlayer &player = m_Players[client]; if (!player.IsConnected()) - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; INetChannel *pNetChan = static_cast(engine->GetPlayerNetInfo(client)); if (pNetChan == NULL) - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; size_t nMsgLen = strlen(szMsg); #if SOURCE_ENGINE == SE_EPISODEONE || SOURCE_ENGINE == SE_DARKMESSIAH @@ -895,7 +878,7 @@ void PlayerManager::OnClientPrintf(edict_t *pEdict, const char *szMsg) // if the msg is bigger than allowed then just let it fail if (nMsgLen + 1 >= SVC_Print_BufferSize) // +1 for NETMSG_TYPE_BITS - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; // enqueue msgs if we'd overflow the SVC_Print buffer (+7 as ceil) if (!player.m_PrintfBuffer.empty() || (nNumBitsWritten + NETMSG_TYPE_BITS + 7) / 8 + nMsgLen >= SVC_Print_BufferSize) @@ -907,10 +890,10 @@ void PlayerManager::OnClientPrintf(edict_t *pEdict, const char *szMsg) player.m_PrintfBuffer.push_back(szMsg); - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } void PlayerManager::OnPrintfFrameAction(unsigned int serial) @@ -944,7 +927,7 @@ void PlayerManager::OnPrintfFrameAction(unsigned int serial) if ((nNumBitsWritten + NETMSG_TYPE_BITS + 7) / 8 + string.length() >= SVC_Print_BufferSize) break; - SH_CALL(engine, &IVEngineServer::ClientPrintf)(player.m_pEdict, string.c_str()); + KHook::CallOriginal(&IVEngineServer::ClientPrintf, engine, player.m_pEdict, string.c_str()); player.m_PrintfBuffer.pop_front(); } @@ -1045,7 +1028,7 @@ void ListPluginsToClient(CPlayer *player, const CCommand &args) return; } - SourceHook::List m_FailList; + std::list m_FailList; size_t i = 0; for (; i < plugins->size(); i++) @@ -1077,10 +1060,10 @@ void ListPluginsToClient(CPlayer *player, const CCommand &args) } #if SOURCE_ENGINE >= SE_ORANGEBOX -void PlayerManager::OnClientCommand(edict_t *pEntity, const CCommand &args) +KHook::Return PlayerManager::OnClientCommand(IServerGameClients*, edict_t *pEntity, const CCommand &args) { #else -void PlayerManager::OnClientCommand(edict_t *pEntity) +KHook::Return PlayerManager::OnClientCommand(IServerGameClients*, edict_t *pEntity) { CCommand args; #endif @@ -1091,7 +1074,7 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) if (!pPlayer->IsConnected()) { - return; + return { KHook::Action::Ignore }; } if (strcmp(args.Arg(0), "sm") == 0) @@ -1099,12 +1082,12 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) if (args.ArgC() > 1 && strcmp(args.Arg(1), "plugins") == 0) { ListPluginsToClient(pPlayer, args); - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } else if (args.ArgC() > 1 && strcmp(args.Arg(1), "exts") == 0) { ListExtensionsToClient(pPlayer, args); - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } else if (args.ArgC() > 1 && strcmp(args.Arg(1), "credits") == 0) { @@ -1124,7 +1107,7 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) " Borja \"faluco\" Ferrer, Pavol \"PM OnoTo\" Marko"); ClientConsolePrint(pEntity, "SourceMod is open source under the GNU General Public License."); - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } ClientConsolePrint(pEntity, @@ -1135,7 +1118,7 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) "To see credits, type \"sm credits\""); ClientConsolePrint(pEntity, "Visit https://www.sourcemod.net/"); - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } EngineArgs cargs(args); @@ -1161,7 +1144,7 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) cell_t res2 = g_ConsoleDetours.InternalDispatch(client, &cargs); if (res2 >= Pl_Handled) { - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } else if (res2 > res) { @@ -1184,21 +1167,22 @@ void PlayerManager::OnClientCommand(edict_t *pEntity) if (res >= Pl_Stop) { - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res); if (res >= Pl_Handled) { - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } + return { KHook::Action::Ignore }; } #if SOURCE_ENGINE >= SE_EYE static bool s_LastCCKVAllowed = true; -void PlayerManager::OnClientCommandKeyValues(edict_t *pEntity, KeyValues *pCommand) +KHook::Return PlayerManager::OnClientCommandKeyValues(IServerGameClients*, edict_t *pEntity, KeyValues *pCommand) { int client = IndexOfEdict(pEntity); @@ -1207,12 +1191,12 @@ void PlayerManager::OnClientCommandKeyValues(edict_t *pEntity, KeyValues *pComma if (!pPlayer->IsInGame()) { - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } KeyValueStack *pStk = new KeyValueStack; pStk->pBase = pCommand; - pStk->pCurRoot.push(pStk->pBase); + pStk->pCurRoot.push_front(pStk->pBase); pStk->m_bDeleteOnDestroy = false; Handle_t hndl = handlesys->CreateHandle(g_KeyValueType, pStk, g_pCoreIdent, g_pCoreIdent, NULL); @@ -1231,19 +1215,19 @@ void PlayerManager::OnClientCommandKeyValues(edict_t *pEntity, KeyValues *pComma if (res >= Pl_Handled) { s_LastCCKVAllowed = false; - RETURN_META(MRES_SUPERCEDE); + return { KHook::Action::Supersede }; } s_LastCCKVAllowed = true; - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } -void PlayerManager::OnClientCommandKeyValues_Post(edict_t *pEntity, KeyValues *pCommand) +KHook::Return PlayerManager::OnClientCommandKeyValues_Post(IServerGameClients*, edict_t *pEntity, KeyValues *pCommand) { if (!s_LastCCKVAllowed) { - return; + return { KHook::Action::Ignore }; } int client = IndexOfEdict(pEntity); @@ -1252,12 +1236,12 @@ void PlayerManager::OnClientCommandKeyValues_Post(edict_t *pEntity, KeyValues *p if (!pPlayer->IsInGame()) { - return; + return { KHook::Action::Ignore }; } KeyValueStack *pStk = new KeyValueStack; pStk->pBase = pCommand; - pStk->pCurRoot.push(pStk->pBase); + pStk->pCurRoot.push_front(pStk->pBase); pStk->m_bDeleteOnDestroy = false; Handle_t hndl = handlesys->CreateHandle(g_KeyValueType, pStk, g_pCoreIdent, g_pCoreIdent, NULL); @@ -1272,10 +1256,12 @@ void PlayerManager::OnClientCommandKeyValues_Post(edict_t *pEntity, KeyValues *p // Deletes pStk handlesys->FreeHandle(hndl, &sec); + + return { KHook::Action::Ignore }; } #endif -void PlayerManager::OnClientSettingsChanged(edict_t *pEntity) +KHook::Return PlayerManager::OnClientSettingsChanged(IServerGameClients*, edict_t *pEntity) { cell_t res; int client = IndexOfEdict(pEntity); @@ -1283,7 +1269,7 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity) if (!pPlayer->IsConnected()) { - return; + return { KHook::Action::Ignore }; } m_clinfochanged->PushCell(client); @@ -1305,7 +1291,7 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity) char kickMsg[128]; logicore.CoreTranslate(kickMsg, sizeof(kickMsg), "%T", 2, NULL, "Name Reserved", &client); pPlayer->Kick(kickMsg); - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } } else if ((id = adminsys->FindAdminByIdentity("name", old_name)) != INVALID_ADMIN_ID) { @@ -1347,15 +1333,14 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity) new_name, pPlayer->GetUserId(), accountId & 1, accountId >> 1, networkid_force, pPlayer->GetIPAddress()); pPlayer->Kick("NetworkID spoofing detected."); - RETURN_META(MRES_IGNORED); + return { KHook::Action::Ignore }; } #endif } /* Notify Extensions */ - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); if (pListener->GetClientListenerVersion() >= 13) @@ -1363,6 +1348,7 @@ void PlayerManager::OnClientSettingsChanged(edict_t *pEntity) pListener->OnClientSettingsChanged(client); } } + return { KHook::Action::Ignore }; } void PlayerManager::OnClientLanguageChanged(int client, unsigned int language) @@ -1842,8 +1828,7 @@ void PlayerManager::ProcessCommandTarget(cmd_target_info_t *info) } } - List::iterator iter; - for (iter = target_processors.begin(); iter != target_processors.end(); iter++) + for (auto iter = target_processors.begin(); iter != target_processors.end(); iter++) { ICommandTargetProcessor *pProcessor = (*iter); if (pProcessor->ProcessCommandTarget(info)) @@ -1926,9 +1911,8 @@ void PlayerManager::MaxPlayersChanged( int newvalue /*= -1*/ ) } /* Notify Extensions */ - List::iterator iter; IClientListener *pListener = NULL; - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); if (pListener->GetClientListenerVersion() >= 8) @@ -1961,14 +1945,16 @@ int PlayerManager::GetClientFromSerial(unsigned int serial) } #if SOURCE_ENGINE >= SE_ORANGEBOX -void CmdMaxplayersCallback(const CCommand &command) +KHook::Return CmdMaxplayersCallback(ConCommand*, const CCommand &command) { #else -void CmdMaxplayersCallback() +KHook::Return CmdMaxplayersCallback(ConCommand*) { #endif g_Players.MaxPlayersChanged(); + + return { KHook::Action::Ignore }; } #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV @@ -2451,8 +2437,7 @@ void CPlayer::DoPostConnectAuthorization() { bool delay = false; - List::iterator iter; - for (iter = g_Players.m_hooks.begin(); + for (auto iter = g_Players.m_hooks.begin(); iter != g_Players.m_hooks.end(); iter++) { @@ -2511,8 +2496,7 @@ void CPlayer::NotifyPostAdminChecks() /* Block beforehand so they can't double-call */ m_bAdminCheckSignalled = true; - List::iterator iter; - for (iter = g_Players.m_hooks.begin(); + for (auto iter = g_Players.m_hooks.begin(); iter != g_Players.m_hooks.end(); iter++) { diff --git a/core/PlayerManager.h b/core/PlayerManager.h index 799ce5625..e6181305f 100644 --- a/core/PlayerManager.h +++ b/core/PlayerManager.h @@ -39,17 +39,15 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include #include #include "ConVarManager.h" #include -using namespace SourceHook; - class IClient; #define PLAYER_LIFE_UNKNOWN 0 @@ -131,9 +129,9 @@ private: bool m_IsInGame = false; bool m_IsAuthorized = false; bool m_bIsInKickQueue = false; - String m_Name; - String m_Ip; - String m_IpNoPort; + std::string m_Name; + std::string m_Ip; + std::string m_IpNoPort; std::string m_AuthID; std::string m_Steam2Id; std::string m_Steam3Id; @@ -142,7 +140,7 @@ private: edict_t *m_pEdict = nullptr; IPlayerInfo *m_Info = nullptr; IClient *m_pIClient = nullptr; - String m_LastPassword; + std::string m_LastPassword; bool m_bAdminCheckSignalled = false; int m_iIndex; unsigned int m_LangId = SOURCEMOD_LANGUAGE_ENGLISH; @@ -178,25 +176,40 @@ public: CPlayer *GetPlayerByIndex(int client) const; void RunAuthChecks(); public: - bool OnClientConnect(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); - bool OnClientConnect_Post(edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); - void OnClientPutInServer(edict_t *pEntity, char const *playername); - void OnClientDisconnect(edict_t *pEntity); - void OnClientDisconnect_Post(edict_t *pEntity); + KHook::Virtual m_HookClientConnect; + KHook::Return OnClientConnect(IServerGameClients*, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); + KHook::Return OnClientConnect_Post(IServerGameClients*, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen); + KHook::Virtual m_HookClientPutInServer; + KHook::Return OnClientPutInServer(IServerGameClients*, edict_t *pEntity, char const *playername); + KHook::Virtual m_HookClientDisconnect; + KHook::Return OnClientDisconnect(IServerGameClients*, edict_t *pEntity); + KHook::Return OnClientDisconnect_Post(IServerGameClients*, edict_t *pEntity); #if SOURCE_ENGINE >= SE_ORANGEBOX - void OnClientCommand(edict_t *pEntity, const CCommand &args); + KHook::Virtual m_HookClientCommand; + KHook::Return OnClientCommand(IServerGameClients*, edict_t *pEntity, const CCommand &args); #if SOURCE_ENGINE >= SE_EYE - void OnClientCommandKeyValues(edict_t *pEntity, KeyValues *pCommand); - void OnClientCommandKeyValues_Post(edict_t *pEntity, KeyValues *pCommand); + KHook::Virtual m_HookClientCommandKeyValues; + KHook::Return OnClientCommandKeyValues(IServerGameClients*, edict_t *pEntity, KeyValues *pCommand); + KHook::Return OnClientCommandKeyValues_Post(IServerGameClients*, edict_t *pEntity, KeyValues *pCommand); #endif #else - void OnClientCommand(edict_t *pEntity); + KHook::Virtual m_HookClientCommand; + KHook::Return OnClientCommand(IServerGameClients*, edict_t *pEntity); #endif - void OnClientSettingsChanged(edict_t *pEntity); + KHook::Virtual m_HookClientSettingsChanged; + KHook::Return OnClientSettingsChanged(IServerGameClients*, edict_t *pEntity); //void OnClientSettingsChanged_Pre(edict_t *pEntity); void OnClientLanguageChanged(int client, unsigned int language); - void OnServerHibernationUpdate(bool bHibernating); - void OnClientPrintf(edict_t *pEdict, const char *szMsg); + KHook::Virtual m_HookServerActivate; + KHook::Return OnServerActivate(IServerGameDLL*, edict_t *pEdictList, int edictCount, int clientMax); +#if SOURCE_ENGINE >= SE_LEFT4DEAD + KHook::Virtual m_HookOnServerHibernationUpdate; +#elif SOURCE_ENGINE > SE_EYE + KHook::Virtual m_HookSetServerHibernation; +#endif + KHook::Return OnServerHibernationUpdate(IServerGameDLL*, bool bHibernating); + KHook::Virtual m_HookClientPrintf; + KHook::Return OnClientPrintf(IVEngineServer*, edict_t *pEdict, const char *szMsg); void OnPrintfFrameAction(unsigned int serial); public: //IPlayerManager void AddClientListener(IClientListener *listener); @@ -242,10 +255,9 @@ public: bool HandleConVarQuery(QueryCvarCookie_t cookie, int client, EQueryCvarValueStatus result, const char *cvarName, const char *cvarValue); #endif private: - void OnServerActivate(edict_t *pEdictList, int edictCount, int clientMax); void InvalidatePlayer(CPlayer *pPlayer); private: - List m_hooks; + std::list m_hooks; IForward *m_clconnect; IForward *m_clconnect_post; IForward *m_cldisconnect; @@ -266,7 +278,7 @@ private: int m_PlayersSinceActive; bool m_bServerActivated; unsigned int *m_AuthQueue; - String m_PassInfoVar; + std::string m_PassInfoVar; bool m_QueryLang; bool m_bAuthstringValidation; // are we validating admins with steam before authorizing? bool m_bIsListenServer; @@ -282,9 +294,9 @@ private: }; #if SOURCE_ENGINE >= SE_ORANGEBOX -void CmdMaxplayersCallback(const CCommand &command); +KHook::Return CmdMaxplayersCallback(ConCommand*, const CCommand &command); #else -void CmdMaxplayersCallback(); +KHook::Return CmdMaxplayersCallback(ConCommand*); #endif extern void ClientConsolePrint(edict_t *e, const char *fmt, ...); diff --git a/core/TimerSys.cpp b/core/TimerSys.cpp index 2084b153e..f346953d5 100644 --- a/core/TimerSys.cpp +++ b/core/TimerSys.cpp @@ -177,12 +177,11 @@ TimerSystem::TimerSystem() TimerSystem::~TimerSystem() { - CStack::iterator iter; - for (iter=m_FreeTimers.begin(); iter!=m_FreeTimers.end(); iter++) + while (!m_FreeTimers.empty()) { - delete (*iter); + delete m_FreeTimers.top(); + m_FreeTimers.pop(); } - m_FreeTimers.popall(); } void TimerSystem::OnSourceModAllInitialized() @@ -304,7 +303,7 @@ ITimer *TimerSystem::CreateTimer(ITimedEvent *pCallbacks, float fInterval, void { pTimer = new ITimer; } else { - pTimer = m_FreeTimers.front(); + pTimer = m_FreeTimers.top(); m_FreeTimers.pop(); } @@ -402,7 +401,7 @@ void TimerSystem::KillTimer(ITimer *pTimer) m_FreeTimers.push(pTimer); } -CStack s_tokill; +std::stack s_tokill; void TimerSystem::RemoveMapChangeTimers() { ITimer *pTimer; @@ -428,7 +427,7 @@ void TimerSystem::RemoveMapChangeTimers() while (!s_tokill.empty()) { - KillTimer(s_tokill.front()); + KillTimer(s_tokill.top()); s_tokill.pop(); } } diff --git a/core/TimerSys.h b/core/TimerSys.h index c5a9b7588..dd5610732 100644 --- a/core/TimerSys.h +++ b/core/TimerSys.h @@ -33,16 +33,15 @@ #define _INCLUDE_SOURCEMOD_CTIMERSYS_H_ #include -#include -#include +#include +#include #include "sourcemm_api.h" #include "sm_globals.h" -using namespace SourceHook; using namespace SourceMod; -typedef List TimerList; -typedef List::iterator TimerIter; +typedef std::list TimerList; +typedef TimerList::iterator TimerIter; class SourceMod::ITimer { @@ -84,9 +83,9 @@ public: void RemoveMapChangeTimers(); void GameFrame(bool simulating); private: - List m_SingleTimers; - List m_LoopTimers; - CStack m_FreeTimers; + std::list m_SingleTimers; + std::list m_LoopTimers; + std::stack m_FreeTimers; IMapTimer *m_pMapTimer; /* This is stuff for our manual ticking escapades. */ diff --git a/core/UserMessages.cpp b/core/UserMessages.cpp index 413ae7853..eb4f23046 100644 --- a/core/UserMessages.cpp +++ b/core/UserMessages.cpp @@ -44,25 +44,19 @@ UserMessages g_UserMsgs; -#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV -SH_DECL_HOOK3_void(IVEngineServer, SendUserMessage, SH_NOATTRIB, 0, IRecipientFilter &, int, const protobuf::Message &); -#else -#if SOURCE_ENGINE >= SE_LEFT4DEAD -SH_DECL_HOOK3(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int, const char *); -#else -SH_DECL_HOOK2(IVEngineServer, UserMessageBegin, SH_NOATTRIB, 0, bf_write *, IRecipientFilter *, int); -#endif -SH_DECL_HOOK0_void(IVEngineServer, MessageEnd, SH_NOATTRIB, 0); -#endif // ==SE_CSGO || ==SE_BLADE || ==SE_MCV - UserMessages::UserMessages() #ifndef USE_PROTOBUF_USERMESSAGES - : m_InterceptBuffer(m_pBase, 2500) -{ + : m_InterceptBuffer(m_pBase, 2500), #else - : m_InterceptBuffer(NULL) -{ + : m_InterceptBuffer(NULL), #endif +#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV + m_SendUserMessage(&IVEngineServer::SendUserMessage, this, &UserMessages::OnSendUserMessage_Pre, &UserMessages::OnSendUserMessage_Post) +#else + m_UserMessageBegin(&IVEngineServer::UserMessageBegin, this, &UserMessages::OnStartMessage_Pre, &UserMessages::OnStartMessage_Post), + m_MessageEnd(&IVEngineServer::MessageEnd, this, &UserMessages::OnMessageEnd_Pre, &UserMessages::OnMessageEnd_Post) +#endif +{ m_HookCount = 0; m_InExec = false; m_InHook = false; @@ -72,12 +66,11 @@ UserMessages::UserMessages() UserMessages::~UserMessages() { - CStack::iterator iter; - for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++) + while (!m_FreeListeners.empty()) { - delete (*iter); + delete m_FreeListeners.top(); + m_FreeListeners.pop(); } - m_FreeListeners.popall(); } void UserMessages::OnSourceModStartup(bool late) @@ -98,13 +91,10 @@ void UserMessages::OnSourceModAllShutdown() if (m_HookCount) { #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false); - SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true); + m_SendUserMessage.Remove(engine); #else - SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false); - SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true); - SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false); - SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true); + m_UserMessageBegin.Remove(engine); + m_MessageEnd.Remove(engine); #endif } m_HookCount = 0; @@ -218,9 +208,9 @@ bf_write *UserMessages::StartBitBufMessage(int msg_id, const cell_t players[], u if (m_CurFlags & USERMSG_BLOCKHOOKS) { #if SOURCE_ENGINE >= SE_LEFT4DEAD - buffer = ENGINE_CALL(UserMessageBegin)(static_cast(&m_CellRecFilter), msg_id, g_SMAPI->GetUserMessage(msg_id)); + buffer = m_UserMessageBegin.CallOriginal(engine, static_cast(&m_CellRecFilter), msg_id, g_SMAPI->GetUserMessage(msg_id)); #else - buffer = ENGINE_CALL(UserMessageBegin)(static_cast(&m_CellRecFilter), msg_id); + buffer = m_UserMessageBegin.CallOriginal(engine, static_cast(&m_CellRecFilter), msg_id); #endif } else { #if SOURCE_ENGINE >= SE_LEFT4DEAD @@ -335,7 +325,7 @@ bool UserMessages::EndMessage() #else if (m_CurFlags & USERMSG_BLOCKHOOKS) { - ENGINE_CALL(MessageEnd)(); + m_MessageEnd.CallOriginal(engine); } else { engine->MessageEnd(); } @@ -413,7 +403,7 @@ bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListene { pInfo = new ListenerInfo; } else { - pInfo = m_FreeListeners.front(); + pInfo = m_FreeListeners.top(); m_FreeListeners.pop(); } @@ -425,13 +415,10 @@ bool UserMessages::InternalHook(int msg_id, IBitBufUserMessageListener *pListene if (!m_HookCount++) { #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false); - SH_ADD_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true); + m_SendUserMessage.Add(engine); #else - SH_ADD_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false); - SH_ADD_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true); - SH_ADD_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false); - SH_ADD_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true); + m_UserMessageBegin.Add(engine); + m_MessageEnd.Add(engine); #endif } @@ -504,13 +491,10 @@ void UserMessages::_DecRefCounter() if (--m_HookCount == 0) { #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Pre), false); - SH_REMOVE_HOOK(IVEngineServer, SendUserMessage, engine, SH_MEMBER(this, &UserMessages::OnSendUserMessage_Post), true); + m_SendUserMessage.Add(engine); #else - SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Pre), false); - SH_REMOVE_HOOK(IVEngineServer, UserMessageBegin, engine, SH_MEMBER(this, &UserMessages::OnStartMessage_Post), true); - SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Pre), false); - SH_REMOVE_HOOK(IVEngineServer, MessageEnd, engine, SH_MEMBER(this, &UserMessages::OnMessageEnd_Post), true); + m_UserMessageBegin.Remove(engine); + m_MessageEnd.Remove(engine); #endif } } @@ -566,18 +550,18 @@ void UserMessages::OnSendUserMessage_Post(IRecipientFilter &filter, int msg_type return; #else #define UM_RETURN_META_VALUE(res, val) \ - RETURN_META_VALUE(res, val) + return { res, val }; #define UM_RETURN_META(res) \ - RETURN_META(res) + return { res }; #endif #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV -protobuf::Message *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name) +KHook::Return UserMessages::OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name) #elif SOURCE_ENGINE >= SE_LEFT4DEAD -bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name) +KHook::Return UserMessages::OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name) #else -bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_type) +KHook::Return UserMessages::OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type) #endif { bool is_intercept_empty = m_msgIntercepts[msg_type].empty(); @@ -587,7 +571,7 @@ bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_typ || (m_InExec && (m_CurFlags & USERMSG_BLOCKHOOKS))) { m_InHook = false; - UM_RETURN_META_VALUE(MRES_IGNORED, NULL); + UM_RETURN_META_VALUE(KHook::Action::Ignore, NULL) } m_CurId = msg_type; @@ -602,27 +586,28 @@ bf_write *UserMessages::OnStartMessage_Pre(IRecipientFilter *filter, int msg_typ delete m_InterceptBuffer; m_InterceptBuffer = GetMessagePrototype(msg_type)->New(); - UM_RETURN_META_VALUE(MRES_SUPERCEDE, m_InterceptBuffer); + UM_RETURN_META_VALUE(KHook::Action::Supersede, m_InterceptBuffer) #else m_InterceptBuffer.Reset(); - UM_RETURN_META_VALUE(MRES_SUPERCEDE, &m_InterceptBuffer); + + UM_RETURN_META_VALUE(KHook::Action::Supersede, &m_InterceptBuffer) #endif } - UM_RETURN_META_VALUE(MRES_IGNORED, NULL); + UM_RETURN_META_VALUE(KHook::Action::Ignore, NULL) } #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV -protobuf::Message *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name) +KHook::Return UserMessages::OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name) #elif SOURCE_ENGINE >= SE_LEFT4DEAD -bf_write *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name) +KHook::Return UserMessages::OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name) #else -bf_write *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_type) +KHook::Return UserMessages::OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type) #endif { if (!m_InHook) { - UM_RETURN_META_VALUE(MRES_IGNORED, NULL); + UM_RETURN_META_VALUE(KHook::Action::Ignore, NULL) } #ifdef USE_PROTOBUF_USERMESSAGES @@ -631,17 +616,17 @@ bf_write *UserMessages::OnStartMessage_Post(IRecipientFilter *filter, int msg_ty else m_OrigBuffer = m_FakeEngineBuffer; #else - m_OrigBuffer = META_RESULT_ORIG_RET(bf_write *); + m_OrigBuffer = *(bf_write**)KHook::GetOriginalValuePtr(); #endif - UM_RETURN_META_VALUE(MRES_IGNORED, NULL); + UM_RETURN_META_VALUE(KHook::Action::Ignore, NULL) } -void UserMessages::OnMessageEnd_Post() +KHook::Return UserMessages::OnMessageEnd_Post(IVEngineServer*) { if (!m_InHook) { - UM_RETURN_META(MRES_IGNORED); + UM_RETURN_META(KHook::Action::Ignore) } MsgList *pList; @@ -703,13 +688,15 @@ void UserMessages::OnMessageEnd_Post() pInfo->IsHooked = false; iter++; } + + UM_RETURN_META(KHook::Action::Ignore) } -void UserMessages::OnMessageEnd_Pre() +KHook::Return UserMessages::OnMessageEnd_Pre(IVEngineServer*) { if (!m_InHook) { - UM_RETURN_META(MRES_IGNORED); + UM_RETURN_META(KHook::Action::Ignore); } MsgList *pList; @@ -778,17 +765,17 @@ void UserMessages::OnMessageEnd_Pre() if (!handled && intercepted) { #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - ENGINE_CALL(SendUserMessage)(static_cast(*m_CurRecFilter), m_CurId, *m_InterceptBuffer); + m_SendUserMessage.CallOriginal(engine, static_cast(*m_CurRecFilter), m_CurId, *m_InterceptBuffer); #else bf_write *engine_bfw; #if SOURCE_ENGINE >= SE_LEFT4DEAD - engine_bfw = ENGINE_CALL(UserMessageBegin)(m_CurRecFilter, m_CurId, g_SMAPI->GetUserMessage(m_CurId)); + engine_bfw = m_UserMessageBegin.CallOriginal(engine, m_CurRecFilter, m_CurId, g_SMAPI->GetUserMessage(m_CurId)); #else - engine_bfw = ENGINE_CALL(UserMessageBegin)(m_CurRecFilter, m_CurId); + engine_bfw = m_UserMessageBegin.CallOriginal(engine, m_CurRecFilter, m_CurId); #endif m_ReadBuffer.StartReading(m_InterceptBuffer.GetBasePointer(), m_InterceptBuffer.GetNumBytesWritten()); engine_bfw->WriteBitsFromBuffer(&m_ReadBuffer, m_InterceptBuffer.GetNumBitsWritten()); - ENGINE_CALL(MessageEnd)(); + m_MessageEnd.CallOriginal(engine); #endif // SE_CSGO || SE_BLADE || SE_MCV } @@ -828,8 +815,8 @@ void UserMessages::OnMessageEnd_Pre() #endif } - UM_RETURN_META((intercepted) ? MRES_SUPERCEDE : MRES_IGNORED); + UM_RETURN_META((intercepted) ? KHook::Action::Supersede : KHook::Action::Ignore); supercede: m_BlockEndPost = true; - UM_RETURN_META(MRES_SUPERCEDE); + UM_RETURN_META(KHook::Action::Supersede) } diff --git a/core/UserMessages.h b/core/UserMessages.h index 77cc201ba..910875c79 100644 --- a/core/UserMessages.h +++ b/core/UserMessages.h @@ -38,10 +38,9 @@ #include "sm_stringutil.h" #include "CellRecipientFilter.h" #include "sm_globals.h" -#include -#include +#include +#include -using namespace SourceHook; using namespace SourceMod; #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV @@ -72,8 +71,8 @@ struct ListenerInfo bool IsNew; }; -typedef List MsgList; -typedef List::iterator MsgIter; +typedef std::list MsgList; +typedef MsgList::iterator MsgIter; class UserMessages : public IUserMessages, @@ -103,22 +102,22 @@ public: //IUserMessages UserMessageType GetUserMessageType() const; public: #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - void OnSendUserMessage_Pre(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg); - void OnSendUserMessage_Post(IRecipientFilter &filter, int msg_type, const protobuf::Message &msg); + KHook::Return OnSendUserMessage_Pre(IVEngineServer*, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg); + KHook::Return OnSendUserMessage_Post(IVEngineServer*, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg); #endif #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - protobuf::Message *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name); - protobuf::Message *OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name); + KHook::Return OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name); + KHook::Return OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name); #elif SOURCE_ENGINE >= SE_LEFT4DEAD - bf_write *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type, const char *msg_name); - bf_write *OnStartMessage_Post(IRecipientFilter *filter, int msg_type, const char *msg_name); + KHook::Return OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name); + KHook::Return OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name); #else - bf_write *OnStartMessage_Pre(IRecipientFilter *filter, int msg_type); - bf_write *OnStartMessage_Post(IRecipientFilter *filter, int msg_type); + KHook::Return OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type); + KHook::Return OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type); #endif - void OnMessageEnd_Pre(); - void OnMessageEnd_Post(); + KHook::Return OnMessageEnd_Pre(IVEngineServer*); + KHook::Return OnMessageEnd_Post(IVEngineServer*); private: #ifdef USE_PROTOBUF_USERMESSAGES const protobuf::Message *GetMessagePrototype(int msg_type); @@ -130,9 +129,9 @@ private: #endif void _DecRefCounter(); private: - List m_msgHooks[255]; - List m_msgIntercepts[255]; - CStack m_FreeListeners; + std::list m_msgHooks[255]; + std::list m_msgIntercepts[255]; + std::stack m_FreeListeners; IRecipientFilter *m_CurRecFilter; #ifndef USE_PROTOBUF_USERMESSAGES unsigned char m_pBase[2500]; @@ -159,6 +158,17 @@ private: bool m_InExec; int m_CurFlags; int m_CurId; +protected: +#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV + KHook::Virtual m_SendUserMessage; +#else +#if SOURCE_ENGINE >= SE_LEFT4DEAD + KHook::Virtual m_UserMessageBegin; +#else + KHook::Virtual m_UserMessageBegin; +#endif + KHook::Virtual m_MessageEnd; +#endif // ==SE_CSGO || ==SE_BLADE || ==SE_MCV }; extern UserMessages g_UserMsgs; diff --git a/core/concmd_cleaner.cpp b/core/concmd_cleaner.cpp index 3488495bc..cc13c2bd1 100644 --- a/core/concmd_cleaner.cpp +++ b/core/concmd_cleaner.cpp @@ -26,7 +26,7 @@ // or . #include "sm_globals.h" -#include +#include #include #include "concmd_cleaner.h" #include "sm_stringutil.h" @@ -34,19 +34,6 @@ #include "compat_wrappers.h" #include -#if SOURCE_ENGINE >= SE_ORANGEBOX -SH_DECL_HOOK1_void(ICvar, UnregisterConCommand, SH_NOATTRIB, 0, ConCommandBase *); -#if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV -SH_DECL_HOOK2_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *, bool); -#else -SH_DECL_HOOK1_void(ICvar, RegisterConCommand, SH_NOATTRIB, 0, ConCommandBase *); -#endif -#else -SH_DECL_HOOK1_void(ICvar, RegisterConCommandBase, SH_NOATTRIB, 0, ConCommandBase *); -#endif - -using namespace SourceHook; - struct ConCommandInfo { ConCommandBase *pBase; @@ -54,7 +41,7 @@ struct ConCommandInfo char name[64]; }; -List tracked_bases; +std::list tracked_bases; IConCommandLinkListener *IConCommandLinkListener::head = NULL; ConCommandBase *FindConCommandBase(const char *name); @@ -62,30 +49,12 @@ ConCommandBase *FindConCommandBase(const char *name); class ConCommandCleaner : public SMGlobalClass { public: - void OnSourceModAllInitialized() - { -#if SOURCE_ENGINE >= SE_ORANGEBOX - SH_ADD_HOOK(ICvar, UnregisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::UnlinkConCommandBase), false); - SH_ADD_HOOK(ICvar, RegisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false); -#else - SH_ADD_HOOK(ICvar, RegisterConCommandBase, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false); -#endif - } - - void OnSourceModShutdown() - { -#if SOURCE_ENGINE >= SE_ORANGEBOX - SH_REMOVE_HOOK(ICvar, UnregisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::UnlinkConCommandBase), false); - SH_REMOVE_HOOK(ICvar, RegisterConCommand, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false); -#else - SH_REMOVE_HOOK(ICvar, RegisterConCommandBase, icvar, SH_MEMBER(this, &ConCommandCleaner::LinkConCommandBase), false); -#endif - } - #if SOURCE_ENGINE == SE_CSGO || SOURCE_ENGINE == SE_BLADE || SOURCE_ENGINE == SE_MCV - void LinkConCommandBase(ConCommandBase *pBase, bool unknown) + KHook::Virtual m_HookLinkConCommandBase; + KHook::Return LinkConCommandBase(ICvar*, ConCommandBase *pBase, bool unknown) #else - void LinkConCommandBase(ConCommandBase *pBase) + KHook::Virtual m_HookLinkConCommandBase; + KHook::Return LinkConCommandBase(ICvar*, ConCommandBase *pBase) #endif { IConCommandLinkListener *listener = IConCommandLinkListener::head; @@ -94,12 +63,15 @@ public: listener->OnLinkConCommand(pBase); listener = listener->next; } + + return { KHook::Action::Ignore }; } - void UnlinkConCommandBase(ConCommandBase *pBase) + KHook::Virtual m_HookUnlinkConCommandBase; + KHook::Return UnlinkConCommandBase(ICvar*, ConCommandBase *pBase) { ConCommandInfo *pInfo; - List::iterator iter = tracked_bases.begin(); + auto iter = tracked_bases.begin(); IConCommandLinkListener *listener = IConCommandLinkListener::head; while (listener) @@ -112,16 +84,17 @@ public: { if ((*iter)->pBase == pBase) { - pInfo = (*iter); - iter = tracked_bases.erase(iter); - pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName()); - delete pInfo; + pInfo = (*iter); + iter = tracked_bases.erase(iter); + pInfo->cls->OnUnlinkConCommandBase(pBase, pBase->GetName()); + delete pInfo; } else { - iter++; + iter++; } } + return { KHook::Action::Ignore }; } void AddTarget(ConCommandBase *pBase, IConCommandTracker *cls) @@ -137,10 +110,9 @@ public: void RemoveTarget(ConCommandBase *pBase, IConCommandTracker *cls) { - List::iterator iter; ConCommandInfo *pInfo; - iter = tracked_bases.begin(); + auto iter = tracked_bases.begin(); while (iter != tracked_bases.end()) { pInfo = (*iter); @@ -155,6 +127,35 @@ public: } } } + + virtual void OnSourceModAllInitialized() override + { +#if SOURCE_ENGINE >= SE_ORANGEBOX + m_HookUnlinkConCommandBase.Add(icvar); + m_HookLinkConCommandBase.Add(icvar); +#else + m_HookLinkConCommandBase.Add(icvar); +#endif + } + + virtual void OnSourceModShutdown() override + { +#if SOURCE_ENGINE >= SE_ORANGEBOX + m_HookUnlinkConCommandBase.Remove(icvar); + m_HookLinkConCommandBase.Remove(icvar); +#else + m_HookLinkConCommandBase.Remove(icvar); +#endif + } + + ConCommandCleaner() : +#if SOURCE_ENGINE >= SE_ORANGEBOX + m_HookLinkConCommandBase(&ICvar::RegisterConCommand, this, &ConCommandCleaner::LinkConCommandBase, nullptr), + m_HookUnlinkConCommandBase(&ICvar::UnregisterConCommand, this, &ConCommandCleaner::UnlinkConCommandBase, nullptr) +#else + m_HookLinkConCommandBase(&ICvar::RegisterConCommandBase, this, &ConCommandCleaner::LinkConCommandBase, nullptr) +#endif + {} } s_ConCmdTracker; void TrackConCommandBase(ConCommandBase *pBase, IConCommandTracker *me) @@ -169,5 +170,5 @@ void UntrackConCommandBase(ConCommandBase *pBase, IConCommandTracker *me) void Global_OnUnlinkConCommandBase(ConCommandBase *pBase) { - s_ConCmdTracker.UnlinkConCommandBase(pBase); + s_ConCmdTracker.UnlinkConCommandBase(icvar, pBase); } diff --git a/core/logic/AMBuilder b/core/logic/AMBuilder index 3af40f19d..8faf9ee3a 100644 --- a/core/logic/AMBuilder +++ b/core/logic/AMBuilder @@ -10,7 +10,7 @@ for cxx in builder.targets: os.path.join(builder.sourcePath, 'sourcepawn', 'include'), os.path.join(builder.sourcePath, 'public', 'amtl', 'amtl'), os.path.join(builder.sourcePath, 'public', 'amtl'), - os.path.join(SM.mms_root, 'core', 'sourcehook') + os.path.join(SM.mms_root, 'third_party', 'khook', 'include') ] binary.compiler.defines += [ 'SM_DEFAULT_THREADER', diff --git a/core/logic/AdminCache.cpp b/core/logic/AdminCache.cpp index 6cf9ac38b..d9f4d8125 100644 --- a/core/logic/AdminCache.cpp +++ b/core/logic/AdminCache.cpp @@ -233,8 +233,7 @@ AdminCache::~AdminCache() DumpAdminCache(AdminCache_Overrides, false); DumpAdminCache(AdminCache_Groups, false); - List::iterator iter; - for (iter=m_AuthMethods.begin(); + for (auto iter=m_AuthMethods.begin(); iter!=m_AuthMethods.end(); iter++) { @@ -759,8 +758,7 @@ bool AdminCache::GetGroupCommandOverride(GroupId id, const char *name, OverrideT AuthMethod *AdminCache::GetMethodByIndex(unsigned int index) { - List::iterator iter; - for (iter=m_AuthMethods.begin(); + for (auto iter=m_AuthMethods.begin(); iter!=m_AuthMethods.end(); iter++) { @@ -974,8 +972,7 @@ void AdminCache::InvalidateAdminCache(bool unlink_admins) } } /* Wipe the identity cache first */ - List::iterator iter; - for (iter=m_AuthMethods.begin(); + for (auto iter=m_AuthMethods.begin(); iter!=m_AuthMethods.end(); iter++) { @@ -998,7 +995,6 @@ void AdminCache::InvalidateAdminCache(bool unlink_admins) void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) { - List::iterator iter; IAdminListener *pListener; if (part == AdminCache_Overrides) @@ -1007,7 +1003,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) DumpCommandOverrideCache(Override_CommandGroup); if (rebuild && !m_destroying) { - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnRebuildOverrideCache(); @@ -1021,7 +1017,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) InvalidateGroupCache(); if (rebuild && !m_destroying) { - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnRebuildGroupCache(); @@ -1033,7 +1029,7 @@ void AdminCache::DumpAdminCache(AdminCachePart part, bool rebuild) InvalidateAdminCache(true); if (rebuild && !m_destroying) { - for (iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) + for (auto iter=m_hooks.begin(); iter!=m_hooks.end(); iter++) { pListener = (*iter); pListener->OnRebuildAdminCache((part == AdminCache_Groups)); @@ -1058,9 +1054,8 @@ const char *AdminCache::GetAdminName(AdminId id) bool AdminCache::GetMethodIndex(const char *name, unsigned int *_index) { - List::iterator iter; unsigned int index = 0; - for (iter=m_AuthMethods.begin(); + for (auto iter=m_AuthMethods.begin(); iter!=m_AuthMethods.end(); iter++,index++) { @@ -1962,8 +1957,7 @@ AdminUser *AdminCache::GetUser(AdminId aid) const char *AdminCache::GetMethodName(unsigned int index) { - List::iterator iter; - for (iter=m_AuthMethods.begin(); + for (auto iter=m_AuthMethods.begin(); iter!=m_AuthMethods.end(); iter++) { diff --git a/core/logic/AdminCache.h b/core/logic/AdminCache.h index daecd9510..09e03f241 100644 --- a/core/logic/AdminCache.h +++ b/core/logic/AdminCache.h @@ -33,16 +33,12 @@ #define _INCLUDE_SOURCEMOD_ADMINCACHE_H_ #include "common_logic.h" -#include +#include "sm_hashmap.h" #include "sm_memtable.h" -#include -#include -#include +#include "sm_namehashset.h" +#include #include -#include -#include - -using namespace SourceHook; +#include #define GRP_MAGIC_SET 0xDEADFADE #define GRP_MAGIC_UNSET 0xFACEFACE @@ -70,7 +66,7 @@ struct AdminGroup struct AuthMethod { - String name; + std::string name; StringHashMap identities; AuthMethod(const char *name) @@ -214,8 +210,8 @@ public: int m_LastGroup; int m_FreeGroupList; StringHashMap m_Groups; - List m_hooks; - List m_AuthMethods; + std::list m_hooks; + std::list m_AuthMethods; NameHashSet m_AuthTables; IForward *m_pCacheFwd; int m_FirstUser; diff --git a/core/logic/BaseWorker.cpp b/core/logic/BaseWorker.cpp index 342d4cc3e..db1be4782 100644 --- a/core/logic/BaseWorker.cpp +++ b/core/logic/BaseWorker.cpp @@ -109,10 +109,9 @@ SWThreadHandle *BaseWorker::PopThreadFromQueue() if (!m_ThreadQueue.size()) return NULL; - SourceHook::List::iterator begin; SWThreadHandle *swt; - begin = m_ThreadQueue.begin(); + auto begin = m_ThreadQueue.begin(); swt = (*begin); m_ThreadQueue.erase(begin); diff --git a/core/logic/BaseWorker.h b/core/logic/BaseWorker.h index 5e87ed63d..f72993485 100644 --- a/core/logic/BaseWorker.h +++ b/core/logic/BaseWorker.h @@ -32,7 +32,7 @@ #ifndef _INCLUDE_SOURCEMOD_BASEWORKER_H #define _INCLUDE_SOURCEMOD_BASEWORKER_H -#include "sh_list.h" +#include #include "ThreadSupport.h" #define SM_DEFAULT_THREADS_PER_FRAME 1 @@ -96,7 +96,7 @@ public: //BaseWorker virtual void AddThreadToQueue(SWThreadHandle *pHandle); virtual SWThreadHandle *PopThreadFromQueue(); protected: - SourceHook::List m_ThreadQueue; + std::list m_ThreadQueue; unsigned int m_perFrame; volatile WorkerState m_state; IThreadWorkerCallbacks *m_pHooks; diff --git a/core/logic/Database.cpp b/core/logic/Database.cpp index e9a520495..1628ab2b1 100644 --- a/core/logic/Database.cpp +++ b/core/logic/Database.cpp @@ -204,7 +204,7 @@ void DBManager::RemoveDriver(IDBDriver *pDriver) { if (m_drivers[i] == pDriver) { - m_drivers.erase(m_drivers.iterAt(i)); + m_drivers.erase(m_drivers.begin() + i); break; } } diff --git a/core/logic/Database.h b/core/logic/Database.h index cdd06fe0e..e279d4e68 100644 --- a/core/logic/Database.h +++ b/core/logic/Database.h @@ -33,9 +33,9 @@ #define _INCLUDE_DATABASE_MANAGER_H_ #include "common_logic.h" -#include +#include #include -#include +#include #include #include #include @@ -46,8 +46,6 @@ #include #include "DatabaseConfBuilder.h" -using namespace SourceHook; - class DBManager : public IDBManager, @@ -98,12 +96,12 @@ private: void ClearConfigs(); void KillWorkerThread(); private: - CVector m_drivers; + std::vector m_drivers; /* Threading stuff */ PrioQueue m_OpQueue; Queue m_ThinkQueue; - CVector m_drSafety; /* which drivers are safe? */ + std::vector m_drSafety; /* which drivers are safe? */ std::unique_ptr m_Worker; std::condition_variable m_QueueEvent; std::mutex m_ThinkLock; diff --git a/core/logic/ExtensionSys.cpp b/core/logic/ExtensionSys.cpp index 4406a7943..a3a5bd149 100644 --- a/core/logic/ExtensionSys.cpp +++ b/core/logic/ExtensionSys.cpp @@ -346,7 +346,15 @@ void CExtension::MarkAllLoaded() void CExtension::AddPlugin(CPlugin *pPlugin) { /* Unfortunately we have to do this :( */ - if (m_Dependents.find(pPlugin) == m_Dependents.end()) + auto iter = m_Dependents.begin(); + while (iter != m_Dependents.end()) { + if ((*iter) == pPlugin) { + break; + } else { + iter++; + } + } + if (iter == m_Dependents.end()) { m_Dependents.push_back(pPlugin); } @@ -389,7 +397,12 @@ bool CLocalExtension::IsLoaded() void CExtension::AddDependency(const IfaceInfo *pInfo) { - if (m_Deps.find(*pInfo) == m_Deps.end()) + auto iter = m_Deps.begin(); + while (iter != m_Deps.end() && !((*iter) == (*pInfo))) + { + iter++; + } + if (iter == m_Deps.end()) { m_Deps.push_back(*pInfo); } @@ -401,8 +414,7 @@ void CExtension::AddChildDependent(CExtension *pOther, SMInterface *iface) info.iface = iface; info.owner = pOther; - List::iterator iter; - for (iter = m_ChildDeps.begin(); + for (auto iter = m_ChildDeps.begin(); iter != m_ChildDeps.end(); iter++) { @@ -482,7 +494,7 @@ void CExtensionManager::OnSourceModShutdown() void CExtensionManager::Shutdown() { - List::iterator iter; + auto iter = m_Libs.begin(); while ((iter = m_Libs.begin()) != m_Libs.end()) { @@ -575,14 +587,13 @@ IExtension *CExtensionManager::LoadAutoExtension(const char *path, bool bErrorOn IExtension *CExtensionManager::FindExtensionByFile(const char *file) { - List::iterator iter; CExtension *pExt; /* Chomp off the path */ char lookup[PLATFORM_MAX_PATH]; libsys->GetFileFromPath(lookup, sizeof(lookup), file); - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { pExt = (*iter); if (pExt->IsSameFile(lookup)) @@ -596,12 +607,11 @@ IExtension *CExtensionManager::FindExtensionByFile(const char *file) IExtension *CExtensionManager::FindExtensionByName(const char *ext) { - List::iterator iter; CExtension *pExt; IExtensionInterface *pAPI; const char *name; - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { pExt = (*iter); if (!pExt->IsLoaded()) @@ -710,9 +720,7 @@ void CExtensionManager::BindChildPlugin(IExtension *pParent, SMPlugin *pPlugin) void CExtensionManager::OnPluginDestroyed(IPlugin *plugin) { - List::iterator iter; - - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { (*iter)->DropRefsTo(static_cast(plugin)); } @@ -725,7 +733,7 @@ CExtension *CExtensionManager::FindByOrder(unsigned int num) return NULL; } - List::iterator iter = m_Libs.begin(); + auto iter = m_Libs.begin(); while (iter != m_Libs.end()) { @@ -745,8 +753,12 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) return false; CExtension *pExt = (CExtension *)_pExt; - - if (m_Libs.find(pExt) == m_Libs.end()) + auto iter = m_Libs.begin(); + while (iter != m_Libs.end() && (*iter) != pExt) + { + iter++; + } + if (iter == m_Libs.end()) return false; /* Tell it to unload */ @@ -760,13 +772,13 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) g_ShareSys.RemoveInterfaces(_pExt); m_Libs.remove(pExt); - List UnloadQueue; + std::list UnloadQueue; /* Handle dependencies */ if (pExt->IsLoaded()) { /* Unload any dependent plugins */ - List::iterator p_iter = pExt->m_Dependents.begin(); + auto p_iter = pExt->m_Dependents.begin(); while (p_iter != pExt->m_Dependents.end()) { /* We have to manually unlink ourselves here, since we're no longer being managed */ @@ -774,8 +786,7 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) p_iter = pExt->m_Dependents.erase(p_iter); } - List::iterator s_iter; - for (s_iter = pExt->m_Libraries.begin(); + for (auto s_iter = pExt->m_Libraries.begin(); s_iter != pExt->m_Libraries.end(); s_iter++) { @@ -783,10 +794,9 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) } /* Notify and/or unload all dependencies */ - List::iterator c_iter; CExtension *pDep; IExtensionInterface *pAPI; - for (c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++) + for (auto c_iter = m_Libs.begin(); c_iter != m_Libs.end(); c_iter++) { pDep = (*c_iter); if ((pAPI=pDep->GetAPI()) == NULL) @@ -795,7 +805,7 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) continue; /* Now, get its dependency list */ bool dropped = false; - List::iterator i_iter = pDep->m_Deps.begin(); + auto i_iter = pDep->m_Deps.begin(); while (i_iter != pDep->m_Deps.end()) { if ((*i_iter).owner == _pExt) @@ -850,8 +860,7 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) pExt->Unload(); delete pExt; - List::iterator iter; - for (iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++) + for (auto iter=UnloadQueue.begin(); iter!=UnloadQueue.end(); iter++) { /* NOTE: This is safe because the unload function backs out of anything not present */ UnloadExtension((*iter)); @@ -862,10 +871,9 @@ bool CExtensionManager::UnloadExtension(IExtension *_pExt) void CExtensionManager::MarkAllLoaded() { - List::iterator iter; CExtension *pExt; - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { pExt = (*iter); if (!pExt->IsLoaded()) @@ -900,7 +908,6 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand const char *cmd = command->Arg(2); if (strcmp(cmd, "list") == 0) { - List::iterator iter; CExtension *pExt; unsigned int num = 1; @@ -922,7 +929,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand break; } } - for (iter = m_Libs.begin(); iter != m_Libs.end(); iter++,num++) + for (auto iter = m_Libs.begin(); iter != m_Libs.end(); iter++,num++) { pExt = (*iter); if (pExt->IsLoaded()) @@ -1011,7 +1018,7 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand return; } - List::iterator iter = m_Libs.begin(); + auto iter = m_Libs.begin(); CExtension *pExt = NULL; while (iter != m_Libs.end()) { @@ -1114,23 +1121,21 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand } else { - List plugins; + std::list plugins; if (pExt->m_ChildDeps.size()) { rootmenu->ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename()); - List::iterator iter; CExtension *pOther; /* Get list of all extensions */ - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { - List::iterator i_iter; pOther = (*iter); if (!pOther->IsLoaded() || pOther == pExt) { continue; } /* Get their dependencies */ - for (i_iter=pOther->m_Deps.begin(); + for (auto i_iter=pOther->m_Deps.begin(); i_iter!=pOther->m_Deps.end(); i_iter++) { @@ -1144,12 +1149,16 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand { rootmenu->ConsolePrint(" -> %s", pOther->GetFilename()); /* Add to plugin unload list */ - List::iterator p_iter; - for (p_iter=pOther->m_Dependents.begin(); + for (auto p_iter=pOther->m_Dependents.begin(); p_iter!=pOther->m_Dependents.end(); p_iter++) { - if (plugins.find((*p_iter)) == plugins.end()) + auto iterS = plugins.begin(); + while (iterS != plugins.end() && (*iterS) != (*p_iter)) + { + iterS++; + } + if (iterS == plugins.end()) { plugins.push_back((*p_iter)); } @@ -1161,17 +1170,21 @@ void CExtensionManager::OnRootConsoleCommand(const char *cmdname, const ICommand if (pExt->m_Dependents.size()) { rootmenu->ConsolePrint("[SM] Unloading %s will unload the following plugins: ", pExt->GetFilename()); - List::iterator iter; CPlugin *pPlugin; - for (iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++) + for (auto iter = pExt->m_Dependents.begin(); iter != pExt->m_Dependents.end(); iter++) { pPlugin = (*iter); - if (plugins.find(pPlugin) == plugins.end()) + auto iterS = plugins.begin(); + while (iterS != plugins.end() && (*iterS) != (pPlugin)) + { + iterS++; + } + if (iterS == plugins.end()) { plugins.push_back(pPlugin); } } - for (iter = plugins.begin(); iter != plugins.end(); iter++) + for (auto iter = plugins.begin(); iter != plugins.end(); iter++) { pPlugin = (*iter); rootmenu->ConsolePrint(" -> %s", pPlugin->GetFilename()); @@ -1267,12 +1280,12 @@ bool CExtensionManager::LibraryExists(const char *library) { CExtension *pExt; - for (List::iterator iter = m_Libs.begin(); + for (auto iter = m_Libs.begin(); iter != m_Libs.end(); iter++) { pExt = (*iter); - for (List::iterator s_iter = pExt->m_Libraries.begin(); + for (auto s_iter = pExt->m_Libraries.begin(); s_iter != pExt->m_Libraries.end(); s_iter++) { @@ -1315,9 +1328,8 @@ IExtension *CExtensionManager::LoadExternal(IExtensionInterface *pInterface, void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax) { IExtensionInterface *pAPI; - List::iterator iter; - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { if ((pAPI = (*iter)->GetAPI()) == NULL) { @@ -1333,9 +1345,8 @@ void CExtensionManager::CallOnCoreMapStart(edict_t *pEdictList, int edictCount, void CExtensionManager::CallOnCoreMapEnd() { IExtensionInterface *pAPI; - List::iterator iter; - for (iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) + for (auto iter=m_Libs.begin(); iter!=m_Libs.end(); iter++) { if ((pAPI = (*iter)->GetAPI()) == NULL) { @@ -1348,17 +1359,17 @@ void CExtensionManager::CallOnCoreMapEnd() } } -const CVector *CExtensionManager::ListExtensions() +const std::vector *CExtensionManager::ListExtensions() { - CVector *list = new CVector(); - for (List::iterator iter = m_Libs.begin(); iter != m_Libs.end(); iter++) + std::vector *list = new std::vector(); + for (auto iter = m_Libs.begin(); iter != m_Libs.end(); iter++) list->push_back(*iter); return list; } -void CExtensionManager::FreeExtensionList(const CVector *list) +void CExtensionManager::FreeExtensionList(const std::vector *list) { - delete const_cast *>(list); + delete const_cast *>(list); } bool CLocalExtension::IsSameFile(const char *file) diff --git a/core/logic/ExtensionSys.h b/core/logic/ExtensionSys.h index 6687057cc..64d978a29 100644 --- a/core/logic/ExtensionSys.h +++ b/core/logic/ExtensionSys.h @@ -34,8 +34,8 @@ #include #include -#include -#include +#include +#include #include "common_logic.h" #include #include @@ -46,7 +46,6 @@ class CPlayer; using namespace SourceMod; -using namespace SourceHook; class CExtension; @@ -95,14 +94,14 @@ protected: protected: IdentityToken_t *m_pIdentToken; IExtensionInterface *m_pAPI; - String m_File; - String m_RealFile; - String m_Path; - String m_Error; - List m_Deps; /** Dependencies */ - List m_ChildDeps; /** Children who might depend on us */ - List m_Interfaces; - List m_Libraries; + std::string m_File; + std::string m_RealFile; + std::string m_Path; + std::string m_Error; + std::list m_Deps; /** Dependencies */ + std::list m_ChildDeps; /** Children who might depend on us */ + std::list m_Interfaces; + std::list m_Libraries; unsigned int unload_code; bool m_bFullyLoaded; bool m_bRequired; @@ -178,8 +177,8 @@ public: void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax); void CallOnCoreMapEnd(); void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface); - const CVector *ListExtensions(); - void FreeExtensionList(const CVector *list); + const std::vector *ListExtensions(); + void FreeExtensionList(const std::vector *list); public: CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); void Shutdown(); @@ -191,7 +190,7 @@ public: private: CExtension *FindByOrder(unsigned int num); private: - List m_Libs; + std::list m_Libs; }; extern CExtensionManager g_Extensions; diff --git a/core/logic/GameConfigs.cpp b/core/logic/GameConfigs.cpp index 64018008d..704efca5c 100644 --- a/core/logic/GameConfigs.cpp +++ b/core/logic/GameConfigs.cpp @@ -31,8 +31,8 @@ #include #include #include -#include -#include +#include +#include #include "GameConfigs.h" #include "stringutil.h" #include @@ -53,8 +53,6 @@ #include #endif -using namespace SourceHook; - GameConfigManager g_GameConfigs; IGameConfig *g_pGameConf = NULL; static char g_Game[256]; @@ -791,7 +789,11 @@ public: (!had_game && matched_engine) || (matched_engine && matched_game)) { - if (fileList->find(cur_file) == fileList->end()) + auto iterS = fileList->begin(); + while (iterS != fileList->end() && (*iterS) != cur_file) { + iterS++; + } + if (iterS == fileList->end()) { fileList->push_back(cur_file); } @@ -806,7 +808,7 @@ public: return SMCResult_Continue; } public: - List *fileList; + std::list *fileList; unsigned int state; unsigned int ignoreLevel; char cur_file[PLATFORM_MAX_PATH]; @@ -857,7 +859,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength) /* Otherwise, it's time to parse the master. */ SMCError err; SMCStates state = {0, 0}; - List fileList; + std::list fileList; master_reader.fileList = &fileList; const char *pEngine[2] = { m_pBaseEngine, m_pEngine }; @@ -885,8 +887,7 @@ bool CGameConfig::Reparse(char *error, size_t maxlength) } /* Go through each file we found and parse it. */ - List::iterator iter; - for (iter = fileList.begin(); iter != fileList.end(); iter++) + for (auto iter = fileList.begin(); iter != fileList.end(); iter++) { ke::SafeSprintf(path, sizeof(path), "%s/%s", m_File, (*iter).c_str()); if (!EnterFile(path, error, maxlength)) diff --git a/core/logic/MemoryUtils.h b/core/logic/MemoryUtils.h index f7eeaafd2..97d2727bb 100644 --- a/core/logic/MemoryUtils.h +++ b/core/logic/MemoryUtils.h @@ -35,10 +35,8 @@ #include #include #if defined PLATFORM_LINUX || defined PLATFORM_APPLE -#include +#include #include "sm_symtable.h" - -using namespace SourceHook; #endif using namespace SourceMod; @@ -79,7 +77,7 @@ public: const DynLibInfo *GetLibraryInfo(const void *libPtr); #if defined PLATFORM_LINUX || defined PLATFORM_APPLE private: - CVector m_SymTables; + std::vector m_SymTables; #ifdef PLATFORM_APPLE struct dyld_all_image_infos *m_ImageList; SInt32 m_OSXMajor; diff --git a/core/logic/NativeOwner.cpp b/core/logic/NativeOwner.cpp index bdb415f80..cfc164abf 100644 --- a/core/logic/NativeOwner.cpp +++ b/core/logic/NativeOwner.cpp @@ -48,8 +48,17 @@ unsigned int CNativeOwner::GetMarkSerial() void CNativeOwner::AddDependent(CPlugin *pPlugin) { - if (m_Dependents.find(pPlugin) == m_Dependents.end()) + auto iter = m_Dependents.begin(); + while (iter != m_Dependents.end()) { + if ((*iter) == pPlugin) { + break; + } else { + iter++; + } + } + if (iter == m_Dependents.end()) { m_Dependents.push_back(pPlugin); + } } void CNativeOwner::AddWeakRef(const WeakNative & ref) @@ -79,10 +88,8 @@ void CNativeOwner::UnbindWeakRef(const WeakNative &ref) void CNativeOwner::DropEverything() { - List::iterator iter; - /* Unbind and remove all weak references to us */ - iter = m_WeakRefs.begin(); + auto iter = m_WeakRefs.begin(); while (iter != m_WeakRefs.end()) { UnbindWeakRef((*iter)); @@ -104,9 +111,7 @@ void CNativeOwner::DropEverything() void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin) { - List::iterator iter; - - iter = m_WeakRefs.begin(); + auto iter = m_WeakRefs.begin(); while (iter != m_WeakRefs.end()) { WeakNative & ref = (*iter); diff --git a/core/logic/NativeOwner.h b/core/logic/NativeOwner.h index bc25d4b01..139a49e2f 100644 --- a/core/logic/NativeOwner.h +++ b/core/logic/NativeOwner.h @@ -32,7 +32,7 @@ #define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_ #include -#include +#include #include #include "common_logic.h" #include "Native.h" @@ -55,8 +55,6 @@ struct WeakNative uint32_t idx; }; -using namespace SourceHook; - class CNativeOwner { public: @@ -76,9 +74,9 @@ private: void DropWeakRefsTo(CPlugin *pPlugin); void UnbindWeakRef(const WeakNative & ref); protected: - List m_Dependents; + std::list m_Dependents; unsigned int m_nMarkSerial; - List m_WeakRefs; + std::list m_WeakRefs; std::vector m_natives; std::vector > m_fakes; }; diff --git a/core/logic/PhraseCollection.h b/core/logic/PhraseCollection.h index bf14e190f..22be38b20 100644 --- a/core/logic/PhraseCollection.h +++ b/core/logic/PhraseCollection.h @@ -32,11 +32,9 @@ #ifndef _INCLUDE_SOURCEMOD_PHRASECOLLECTION_H_ #define _INCLUDE_SOURCEMOD_PHRASECOLLECTION_H_ -#include -#include +#include #include -using namespace SourceHook; using namespace SourceMod; class CPhraseCollection : public IPhraseCollection @@ -60,7 +58,7 @@ public: size_t *pOutLength, const char **pFailPhrase); private: - CVector m_Files; + std::vector m_Files; }; #endif //_INCLUDE_SOURCEMOD_PHRASECOLLECTION_H_ diff --git a/core/logic/PluginSys.cpp b/core/logic/PluginSys.cpp index 33f1c3af3..1b6f687f3 100644 --- a/core/logic/PluginSys.cpp +++ b/core/logic/PluginSys.cpp @@ -668,7 +668,11 @@ void CPlugin::DependencyDropped(CPlugin *pOwner) return; for (auto lib_iter=pOwner->m_Libraries.begin(); lib_iter!=pOwner->m_Libraries.end(); lib_iter++) { - if (m_RequiredLibs.find(*lib_iter) != m_RequiredLibs.end()) { + auto iterS = m_RequiredLibs.begin(); + while (iterS != m_RequiredLibs.end() && (*iterS) != *lib_iter) { + iterS++; + } + if (iterS != m_RequiredLibs.end()) { m_LibraryMissing = true; break; } @@ -739,10 +743,9 @@ void CPlugin::AddConfig(bool autoCreate, const char *cfg, const char *folder) void CPlugin::DropEverything() { CPlugin *pOther; - List::iterator wk_iter; /* Tell everyone that depends on us that we're about to drop */ - for (List::iterator iter = m_Dependents.begin(); + for (auto iter = m_Dependents.begin(); iter != m_Dependents.end(); iter++) { @@ -1184,7 +1187,11 @@ void CPlugin::ForEachLibrary(ke::Function callback) void CPlugin::AddRequiredLib(const char *name) { - if (m_RequiredLibs.find(name) == m_RequiredLibs.end()) + auto iterS = m_RequiredLibs.begin(); + while (iterS != m_RequiredLibs.end() && (*iterS) != name) { + iterS++; + } + if (iterS == m_RequiredLibs.end()) m_RequiredLibs.push_back(name); } @@ -2274,9 +2281,9 @@ void CPluginManager::SyncMaxClients(int max_clients) (*iter)->SyncMaxClients(max_clients); } -const CVector *CPluginManager::ListPlugins() +const std::vector *CPluginManager::ListPlugins() { - CVector *list = new CVector(); + std::vector *list = new std::vector(); for (PluginIter iter(m_plugins); !iter.done(); iter.next()) list->push_back((*iter)); @@ -2284,9 +2291,9 @@ const CVector *CPluginManager::ListPlugins() return list; } -void CPluginManager::FreePluginList(const CVector *list) +void CPluginManager::FreePluginList(const std::vector *list) { - delete const_cast *>(list); + delete const_cast *>(list); } void CPluginManager::ForEachPlugin(ke::Function callback) diff --git a/core/logic/PluginSys.h b/core/logic/PluginSys.h index 1afbf5217..50a5e2acd 100644 --- a/core/logic/PluginSys.h +++ b/core/logic/PluginSys.h @@ -41,10 +41,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "common_logic.h" #include #include @@ -61,8 +61,6 @@ class CPlayer; -using namespace SourceHook; - enum LoadRes { LoadRes_Successful, @@ -196,7 +194,15 @@ public: m_Libraries.push_back(name); } inline bool HasLibrary(const char *name) { - return m_Libraries.find(name) != m_Libraries.end(); + auto iter = m_Libraries.begin(); + while (iter != m_Libraries.end()) { + if (strcmp((*iter).c_str(), name) == 0) { + break; + } else { + iter++; + } + } + return iter != m_Libraries.end(); } void LibraryActions(LibraryAction action); void SyncMaxClients(int max_clients); @@ -275,13 +281,13 @@ private: IPluginContext *m_pContext; sp_pubvar_t *m_MaxClientsVar; StringHashMap m_Props; - CVector m_configs; - List m_Libraries; + std::vector m_configs; + std::list m_Libraries; bool m_bGotAllLoaded; int m_FileVersion; // Information that survives past eviction. - List m_RequiredLibs; + std::list m_RequiredLibs; IdentityToken_t *m_ident; time_t m_LastFileModTime; Handle_t m_handle; @@ -355,8 +361,8 @@ public: //IScriptManager SMPlugin *FindPluginByHandle(Handle_t hndl, HandleError *errp) { return static_cast(PluginFromHandle(hndl, errp)); } - const CVector *ListPlugins(); - void FreePluginList(const CVector *plugins); + const std::vector *ListPlugins(); + void FreePluginList(const std::vector *plugins); public: //SMGlobalClass void OnSourceModAllInitialized(); @@ -513,7 +519,7 @@ private: IdentityToken_t *m_MyIdent; /* Dynamic native stuff */ - List m_Natives; + std::list m_Natives; bool m_LoadingLocked; diff --git a/core/logic/RootConsoleMenu.cpp b/core/logic/RootConsoleMenu.cpp index fb6857bf2..331d0bb39 100644 --- a/core/logic/RootConsoleMenu.cpp +++ b/core/logic/RootConsoleMenu.cpp @@ -42,8 +42,7 @@ RootConsoleMenu::RootConsoleMenu() RootConsoleMenu::~RootConsoleMenu() { - List::iterator iter; - for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) + for (auto iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) { delete (*iter); } @@ -100,7 +99,7 @@ bool RootConsoleMenu::AddRootConsoleCommand3(const char *cmd, return false; /* Sort this into the menu */ - List::iterator iter = m_Menu.begin(); + auto iter = m_Menu.begin(); ConsoleEntry *pEntry; bool inserted = false; while (iter != m_Menu.end()) @@ -137,9 +136,8 @@ bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleComm { m_Commands.remove(cmd); - List::iterator iter; ConsoleEntry *pEntry; - for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) + for (auto iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) { pEntry = (*iter); if (pEntry->command.compare(cmd) == 0) @@ -200,9 +198,8 @@ void RootConsoleMenu::GotRootCmd(const ICommandArgs *cmd) ConsolePrint("SourceMod Menu:"); ConsolePrint("Usage: sm [arguments]"); - List::iterator iter; ConsoleEntry *pEntry; - for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) + for (auto iter=m_Menu.begin(); iter!=m_Menu.end(); iter++) { pEntry = (*iter); DrawGenericOption(pEntry->command.c_str(), pEntry->description.c_str()); diff --git a/core/logic/RootConsoleMenu.h b/core/logic/RootConsoleMenu.h index c240a488f..c02e7093b 100644 --- a/core/logic/RootConsoleMenu.h +++ b/core/logic/RootConsoleMenu.h @@ -28,18 +28,17 @@ #define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_ #include "common_logic.h" +#include "sm_namehashset.h" #include -#include -#include -#include +#include +#include using namespace SourceMod; -using namespace SourceHook; struct ConsoleEntry { - String command; - String description; + std::string command; + std::string description; IRootConsoleCommand *cmd; static inline bool matches(const char *name, const ConsoleEntry *entry) @@ -84,7 +83,7 @@ public: void GotRootCmd(const ICommandArgs *cmd); private: NameHashSet m_Commands; - List m_Menu; + std::list m_Menu; }; extern RootConsoleMenu g_RootMenu; diff --git a/core/logic/ShareSys.cpp b/core/logic/ShareSys.cpp index fd998b39e..259d59195 100644 --- a/core/logic/ShareSys.cpp +++ b/core/logic/ShareSys.cpp @@ -232,7 +232,7 @@ void ShareSystem::DestroyIdentType(IdentityType_t type) void ShareSystem::RemoveInterfaces(IExtension *pExtension) { - List::iterator iter = m_Interfaces.begin(); + auto iter = m_Interfaces.begin(); while (iter != m_Interfaces.end()) { diff --git a/core/logic/ShareSys.h b/core/logic/ShareSys.h index cc431cb77..78f132d34 100644 --- a/core/logic/ShareSys.h +++ b/core/logic/ShareSys.h @@ -37,14 +37,12 @@ #include #include #include -#include +#include #include #include #include "common_logic.h" #include "Native.h" -using namespace SourceHook; - namespace SourceMod { struct IdentityToken_t @@ -133,7 +131,7 @@ private: private: typedef NameHashSet, Native> NativeCache; - List m_Interfaces; + std::list m_Interfaces; HandleType_t m_TypeRoot; IdentityToken_t m_IdentRoot; HandleType_t m_IfaceType; diff --git a/core/logic/Translator.h b/core/logic/Translator.h index 5cd57dfbb..8070b21b6 100644 --- a/core/logic/Translator.h +++ b/core/logic/Translator.h @@ -34,17 +34,16 @@ #include "common_logic.h" #include -#include -#include #include "sm_memtable.h" #include "ITextParsers.h" #include #include "PhraseCollection.h" +#include +#include /* :TODO: write a templatized version of tries? */ using namespace SourceMod; -using namespace SourceHook; class Translator; enum PhraseParseState @@ -83,15 +82,15 @@ private: void ParseWarning(const char *message, ...); private: StringHashMap m_PhraseLookup; - String m_File; + std::string m_File; Translator *m_pTranslator; PhraseParseState m_ParseState; int m_CurPhrase; BaseMemTable *m_pMemory; BaseStringTable *m_pStringTab; unsigned int m_LangCount; - String m_ParseError; - String m_LastPhraseString; + std::string m_ParseError; + std::string m_LastPhraseString; bool m_FileLogged; }; @@ -152,13 +151,13 @@ public: //ITranslator private: bool AddLanguage(const char *langcode, const char *description); private: - CVector m_Languages; - CVector m_Files; + std::vector m_Languages; + std::vector m_Files; BaseStringTable *m_pStringTab; StringHashMap m_LCodeLookup; StringHashMap m_LAliases; bool m_InLanguageSection; - String m_CustomError; + std::string m_CustomError; unsigned int m_ServerLang; char m_InitialLang[4]; }; diff --git a/core/logic/smn_core.cpp b/core/logic/smn_core.cpp index 67bf66c89..16ab2a562 100644 --- a/core/logic/smn_core.cpp +++ b/core/logic/smn_core.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include "common_logic.h" #include "Logger.h" @@ -43,9 +44,6 @@ #include #include -#include -#include - #if defined PLATFORM_WINDOWS #include #include "sm_invalidparamhandler.h" @@ -54,12 +52,12 @@ #include #include #endif +#include #include #include #include #include #include -#include using namespace SourceMod; using namespace SourcePawn; @@ -128,7 +126,7 @@ class CMMPluginIterator public IPluginsListener { public: - CMMPluginIterator(const CVector *list) + CMMPluginIterator(const std::vector *list) : m_hasStarted(false) { for(auto iter = list->begin(); iter != list->end(); ++iter) { @@ -925,21 +923,21 @@ static cell_t StoreToAddress(IPluginContext *pContext, const cell_t *params) case NumberType_Int8: if (updateMemAccess) { - SourceHook::SetMemAccess(addr, sizeof(uint8_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); + KHook::Memory::SetAccess(addr, sizeof(uint8_t), KHook::Memory::Flags::READ | KHook::Memory::Flags::EXECUTE | KHook::Memory::Flags::WRITE); } *reinterpret_cast(addr) = data; break; case NumberType_Int16: if (updateMemAccess) { - SourceHook::SetMemAccess(addr, sizeof(uint16_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); + KHook::Memory::SetAccess(addr, sizeof(uint16_t), KHook::Memory::Flags::READ | KHook::Memory::Flags::EXECUTE | KHook::Memory::Flags::WRITE); } *reinterpret_cast(addr) = data; break; case NumberType_Int32: if (updateMemAccess) { - SourceHook::SetMemAccess(addr, sizeof(uint32_t), SH_MEM_READ|SH_MEM_WRITE|SH_MEM_EXEC); + KHook::Memory::SetAccess(addr, sizeof(uint32_t), KHook::Memory::Flags::READ | KHook::Memory::Flags::EXECUTE | KHook::Memory::Flags::WRITE); } *reinterpret_cast(addr) = data; break; diff --git a/core/logic/smn_database.cpp b/core/logic/smn_database.cpp index 505cb6d69..8a97ea9a1 100644 --- a/core/logic/smn_database.cpp +++ b/core/logic/smn_database.cpp @@ -290,7 +290,7 @@ public: private: IDatabase *m_pDatabase; IPluginFunction *m_pFunction; - String m_Query; + std::string m_Query; cell_t m_Data; IPlugin *me; IQuery *m_pQuery; diff --git a/core/logic/smn_fakenatives.cpp b/core/logic/smn_fakenatives.cpp index e68e527a6..25a3f055e 100644 --- a/core/logic/smn_fakenatives.cpp +++ b/core/logic/smn_fakenatives.cpp @@ -29,16 +29,12 @@ * Version: $Id$ */ -#include -#include #include #include "common_logic.h" #include "ShareSys.h" #include "PluginSys.h" #include "sprintf.h" -using namespace SourceHook; - static cell_t s_curparams[SP_MAX_EXEC_PARAMS+1]; static FakeNative *s_curnative = NULL; static IPluginContext *s_curcaller = NULL; diff --git a/core/logic/smn_maplists.cpp b/core/logic/smn_maplists.cpp index 2a1e1f179..071e87003 100644 --- a/core/logic/smn_maplists.cpp +++ b/core/logic/smn_maplists.cpp @@ -29,7 +29,7 @@ * Version: $Id$ */ -#include +#include #include #include "common_logic.h" #include "CellArray.h" @@ -42,8 +42,6 @@ #include #include -using namespace SourceHook; - struct maplist_info_t { bool bIsCompat; @@ -168,7 +166,7 @@ public: m_pMapCycleFile = bridge->FindConVar("mapcyclefile"); /* Dump everything we know about. */ - List compat; + std::list compat; DumpCache(&compat); /* All this is to add the default entry back in. */ @@ -206,7 +204,7 @@ public: } /* Now, re-add compat stuff back in if we can. */ - List::iterator iter = compat.begin(); + auto iter = compat.begin(); while (iter != compat.end()) { if (m_ListLookup.contains((*iter)->name)) @@ -666,11 +664,11 @@ private: return true; } - void DumpCache(List *compat_list) + void DumpCache(std::list *compat_list) { m_ListLookup.clear(); - List::iterator iter = m_MapLists.begin(); + auto iter = m_MapLists.begin(); while (iter != m_MapLists.end()) { if (compat_list != NULL && (*iter)->bIsCompat) @@ -690,7 +688,7 @@ private: time_t m_ConfigLastChanged; ConVar *m_pMapCycleFile; NameHashSet m_ListLookup; - List m_MapLists; + std::list m_MapLists; MapListState m_CurState; unsigned int m_IgnoreLevel; maplist_info_t *m_pCurMapList; diff --git a/core/logic/smn_menus.cpp b/core/logic/smn_menus.cpp index 152215ebe..5ad5bf9de 100644 --- a/core/logic/smn_menus.cpp +++ b/core/logic/smn_menus.cpp @@ -30,7 +30,6 @@ */ #include "common_logic.h" -#include #include #include #include "DebugReporter.h" @@ -40,6 +39,8 @@ #include #include #include +#include +#include #if defined CreateMenu #undef CreateMenu @@ -175,13 +176,13 @@ public: while (!m_FreePanelHandlers.empty()) { - delete m_FreePanelHandlers.front(); + delete m_FreePanelHandlers.top(); m_FreePanelHandlers.pop(); } while (!m_FreeMenuHandlers.empty()) { - delete m_FreeMenuHandlers.front(); + delete m_FreeMenuHandlers.top(); m_FreeMenuHandlers.pop(); } } @@ -213,12 +214,12 @@ public: */ virtual void OnPluginUnloaded(IPlugin *plugin) { - for (size_t i = 0; i < m_PanelHandlers.size(); i++) + for (auto e : m_PanelHandlers) { - if (m_PanelHandlers[i]->m_pPlugin == plugin) + if (e->m_pPlugin == plugin) { - m_PanelHandlers[i]->m_pPlugin = NULL; - m_PanelHandlers[i]->m_pFunc = NULL; + e->m_pPlugin = nullptr; + e->m_pFunc = nullptr; } } } @@ -241,7 +242,7 @@ public: handler = new CPanelHandler; m_PanelHandlers.push_back(handler); } else { - handler = m_FreePanelHandlers.front(); + handler = m_FreePanelHandlers.top(); m_FreePanelHandlers.pop(); } handler->m_pFunc = pFunction; @@ -263,7 +264,7 @@ public: { handler = new CMenuHandler(pFunction, flags); } else { - handler = m_FreeMenuHandlers.front(); + handler = m_FreeMenuHandlers.top(); m_FreeMenuHandlers.pop(); handler->m_pBasic = pFunction; handler->m_Flags = flags; @@ -280,9 +281,9 @@ public: private: HandleType_t m_PanelType; HandleType_t m_TempPanelType; - CStack m_FreePanelHandlers; - CStack m_FreeMenuHandlers; - CVector m_PanelHandlers; + std::stack m_FreePanelHandlers; + std::stack m_FreeMenuHandlers; + std::list m_PanelHandlers; } g_MenuHelpers; /** diff --git a/core/logic/smn_players.cpp b/core/logic/smn_players.cpp index 4fdb5304f..abd705fd2 100644 --- a/core/logic/smn_players.cpp +++ b/core/logic/smn_players.cpp @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include #include "GameConfigs.h" #include "CellArray.h" #include "AutoHandleRooter.h" @@ -46,7 +46,6 @@ #include #include -using namespace SourceHook; using namespace SourceMod; #ifndef PRIu64 @@ -75,9 +74,9 @@ class PlayerLogicHelpers : struct SimpleMultiTargetFilter { IPlugin *plugin; - SourceHook::String pattern; + std::string pattern; IPluginFunction *fun; - SourceHook::String phrase; + std::string phrase; bool phraseIsML; SimpleMultiTargetFilter(IPlugin *plugin, const char *pattern, IPluginFunction *fun, @@ -87,7 +86,7 @@ class PlayerLogicHelpers : } }; - List simpleMultis; + std::list simpleMultis; bool filterEnabled; public: @@ -107,7 +106,7 @@ public: void RemoveMultiTargetFilter(const char *pattern, IPluginFunction *fun) { - List::iterator iter = simpleMultis.begin(); + auto iter = simpleMultis.begin(); while (iter != simpleMultis.end()) { if ((*iter)->fun == fun && strcmp((*iter)->pattern.c_str(), pattern) == 0) { @@ -127,9 +126,7 @@ public: public: //ICommandTargetProcessor bool ProcessCommandTarget(cmd_target_info_t *info) { - List::iterator iter; - - for (iter = simpleMultis.begin(); iter != simpleMultis.end(); iter++) { + for (auto iter = simpleMultis.begin(); iter != simpleMultis.end(); iter++) { SimpleMultiTargetFilter *smtf = (*iter); if (strcmp(smtf->pattern.c_str(), info->pattern) == 0) { CellArray *array = new CellArray(1); @@ -206,7 +203,7 @@ public: //IPluginsListener void OnPluginDestroyed(IPlugin *plugin) { - List::iterator iter = simpleMultis.begin(); + auto iter = simpleMultis.begin(); while (iter != simpleMultis.end()) { if ((*iter)->plugin != plugin) { diff --git a/core/logic/smn_timers.cpp b/core/logic/smn_timers.cpp index 631d4d41f..855f87a6c 100644 --- a/core/logic/smn_timers.cpp +++ b/core/logic/smn_timers.cpp @@ -34,12 +34,10 @@ #include #include #include -#include +#include #include "DebugReporter.h" #include -using namespace SourceHook; - #define TIMER_DATA_HNDL_CLOSE (1<<9) #define TIMER_HNDL_CLOSE (1<<9) @@ -74,17 +72,16 @@ public: TimerInfo *CreateTimerInfo(); void DeleteTimerInfo(TimerInfo *pInfo); private: - CStack m_FreeTimers; + std::stack m_FreeTimers; }; TimerNatives::~TimerNatives() { - CStack::iterator iter; - for (iter=m_FreeTimers.begin(); iter!=m_FreeTimers.end(); iter++) + while (!m_FreeTimers.empty()) { - delete (*iter); + delete m_FreeTimers.top(); + m_FreeTimers.pop(); } - m_FreeTimers.popall(); } void TimerNatives::OnSourceModAllInitialized() @@ -118,7 +115,7 @@ TimerInfo *TimerNatives::CreateTimerInfo() { pInfo = new TimerInfo; } else { - pInfo = m_FreeTimers.front(); + pInfo = m_FreeTimers.top(); m_FreeTimers.pop(); } diff --git a/core/logic_bridge.cpp b/core/logic_bridge.cpp index 4e0e8d88a..89a7a2ef2 100644 --- a/core/logic_bridge.cpp +++ b/core/logic_bridge.cpp @@ -454,7 +454,7 @@ bool CoreProviderImpl::GetGameName(char *buffer, size_t maxlength) const char *CoreProviderImpl::GetGameDescription() { - return SERVER_CALL(GetGameDescription)(); + return KHook::CallOriginal(&IServerGameDLL::GetGameDescription, gamedll); } const char *CoreProviderImpl::GetSourceEngineName() diff --git a/core/smn_console.cpp b/core/smn_console.cpp index 29b830a86..e97056ae4 100644 --- a/core/smn_console.cpp +++ b/core/smn_console.cpp @@ -79,7 +79,7 @@ HandleType_t htConCmdIter = 0; struct GlobCmdIter { bool started; - List::iterator iter; + std::list::iterator iter; }; class ConsoleHelpers : @@ -1056,7 +1056,7 @@ static cell_t ReadCommandIterator(IPluginContext *pContext, const cell_t *params return pContext->ThrowNativeError("Invalid GlobCmdIter Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + std::list& cmds = const_cast(g_ConCmds.GetCommandList()); if (!iter->started) { @@ -1356,7 +1356,7 @@ static cell_t FakeClientCommandKeyValues(IPluginContext *pContext, const cell_t if (g_Players.InClientCommandKeyValuesHook()) { - SH_CALL(serverClients, &IServerGameClients::ClientCommandKeyValues)(pPlayer->GetEdict(), pStk->pBase); + KHook::CallOriginal(&IServerGameClients::ClientCommandKeyValues, serverClients, pPlayer->GetEdict(), pStk->pBase); } else { @@ -1395,7 +1395,7 @@ static cell_t sm_CommandIteratorNext(IPluginContext *pContext, const cell_t *par return pContext->ThrowNativeError("Invalid CommandIterator Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + std::list& cmds = const_cast(g_ConCmds.GetCommandList()); if (!iter->started) { @@ -1427,7 +1427,7 @@ static cell_t sm_CommandIteratorAdminFlags(IPluginContext *pContext, const cell_ { return pContext->ThrowNativeError("Invalid CommandIterator Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + const std::list &cmds = g_ConCmds.GetCommandList(); if (!iter->started || iter->iter == cmds.end()) { return pContext->ThrowNativeError("Invalid CommandIterator position"); @@ -1448,7 +1448,7 @@ static cell_t sm_CommandIteratorConVarFlags(IPluginContext *pContext, const cell { return pContext->ThrowNativeError("Invalid CommandIterator Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + const std::list &cmds = g_ConCmds.GetCommandList(); if (!iter->started || iter->iter == cmds.end()) { return pContext->ThrowNativeError("Invalid CommandIterator position"); @@ -1469,7 +1469,7 @@ static cell_t sm_CommandIteratorGetDesc(IPluginContext *pContext, const cell_t * { return pContext->ThrowNativeError("Invalid CommandIterator Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + const std::list &cmds = g_ConCmds.GetCommandList(); if (!iter->started || iter->iter == cmds.end()) { return pContext->ThrowNativeError("Invalid CommandIterator position"); @@ -1492,7 +1492,7 @@ static cell_t sm_CommandIteratorGetName(IPluginContext *pContext, const cell_t * { return pContext->ThrowNativeError("Invalid CommandIterator Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + const std::list &cmds = g_ConCmds.GetCommandList(); if (!iter->started || iter->iter == cmds.end()) { return pContext->ThrowNativeError("Invalid CommandIterator position"); @@ -1515,7 +1515,7 @@ static cell_t sm_CommandIteratorPlugin(IPluginContext *pContext, const cell_t *p { return pContext->ThrowNativeError("Invalid CommandIterator Handle %x", params[1]); } - const List &cmds = g_ConCmds.GetCommandList(); + const std::list &cmds = g_ConCmds.GetCommandList(); if (!iter->started || iter->iter == cmds.end()) { return pContext->ThrowNativeError("Invalid CommandIterator position"); diff --git a/core/smn_halflife.cpp b/core/smn_halflife.cpp index f72b71960..21fdcc210 100644 --- a/core/smn_halflife.cpp +++ b/core/smn_halflife.cpp @@ -181,7 +181,7 @@ static cell_t GetGameDescription(IPluginContext *pContext, const cell_t *params) { description = gamedll->GetGameDescription(); } else { - description = SERVER_CALL(GetGameDescription)(); + description = KHook::CallOriginal(&IServerGameDLL::GetGameDescription, gamedll); } size_t numBytes; diff --git a/core/smn_keyvalues.cpp b/core/smn_keyvalues.cpp index c6eddc36a..3f2ff022c 100644 --- a/core/smn_keyvalues.cpp +++ b/core/smn_keyvalues.cpp @@ -499,7 +499,7 @@ static cell_t smn_CreateKeyValues(IPluginContext *pCtx, const cell_t *params) is_empty = (firstkey[0] == '\0'); pStk = new KeyValueStack; pStk->pBase = new KeyValues(name, is_empty ? NULL : firstkey, (is_empty||(firstvalue[0]=='\0')) ? NULL : firstvalue); - pStk->pCurRoot.push(pStk->pBase); + pStk->pCurRoot.push_front(pStk->pBase); return handlesys->CreateHandle(g_KeyValueType, pStk, pCtx->GetIdentity(), g_pCoreIdent, NULL); } @@ -529,7 +529,7 @@ static cell_t smn_KvJumpToKey(IPluginContext *pCtx, const cell_t *params) { return 0; } - pStk->pCurRoot.push(pSubKey); + pStk->pCurRoot.push_front(pSubKey); return 1; } @@ -556,7 +556,7 @@ static cell_t smn_KvJumpToKeySymbol(IPluginContext *pCtx, const cell_t *params) { return 0; } - pStk->pCurRoot.push(pSubKey); + pStk->pCurRoot.push_front(pSubKey); return 1; } @@ -590,7 +590,7 @@ static cell_t smn_KvGotoFirstSubKey(IPluginContext *pCtx, const cell_t *params) { return 0; } - pStk->pCurRoot.push(pFirstSubKey); + pStk->pCurRoot.push_front(pFirstSubKey); return 1; } @@ -622,8 +622,8 @@ static cell_t smn_KvGotoNextKey(IPluginContext *pCtx, const cell_t *params) { return 0; } - pStk->pCurRoot.pop(); - pStk->pCurRoot.push(pSubKey); + pStk->pCurRoot.pop_front(); + pStk->pCurRoot.push_front(pSubKey); return 1; } @@ -648,7 +648,7 @@ static cell_t smn_KvGoBack(IPluginContext *pCtx, const cell_t *params) { return 0; } - pStk->pCurRoot.pop(); + pStk->pCurRoot.pop_front(); return 1; } @@ -674,7 +674,7 @@ static cell_t smn_KvRewind(IPluginContext *pCtx, const cell_t *params) { while (pStk->pCurRoot.size() > 1) { - pStk->pCurRoot.pop(); + pStk->pCurRoot.pop_front(); } } else @@ -682,7 +682,7 @@ static cell_t smn_KvRewind(IPluginContext *pCtx, const cell_t *params) auto root = pStk->pCurRoot.begin(); if (root != pStk->pCurRoot.end()) { - pStk->pCurRoot.push(*root); + pStk->pCurRoot.push_front(*root); } } @@ -897,7 +897,7 @@ static cell_t smn_KvDeleteThis(IPluginContext *pContext, const cell_t *params) } KeyValues *pValues = pStk->pCurRoot.front(); - pStk->pCurRoot.pop(); + pStk->pCurRoot.pop_front(); KeyValues *pRoot = pStk->pCurRoot.front(); /* We have to manually verify this since Valve sucks @@ -914,7 +914,7 @@ static cell_t smn_KvDeleteThis(IPluginContext *pContext, const cell_t *params) pValues->deleteThis(); if (pNext) { - pStk->pCurRoot.push(pNext); + pStk->pCurRoot.push_front(pNext); return 1; } else { return -1; @@ -924,7 +924,7 @@ static cell_t smn_KvDeleteThis(IPluginContext *pContext, const cell_t *params) } /* Push this back on :( */ - pStk->pCurRoot.push(pValues); + pStk->pCurRoot.push_front(pValues); return 0; } @@ -988,7 +988,7 @@ static cell_t smn_KvSavePosition(IPluginContext *pContext, const cell_t *params) } KeyValues *pValues = pStk->pCurRoot.front(); - pStk->pCurRoot.push(pValues); + pStk->pCurRoot.push_front(pValues); return 1; } diff --git a/core/smn_keyvalues.h b/core/smn_keyvalues.h index 61e83f3ab..d799d7cc3 100644 --- a/core/smn_keyvalues.h +++ b/core/smn_keyvalues.h @@ -33,7 +33,7 @@ #define _INCLUDE_SOURCEMOD_KVWRAPPER_H_ #include -#include +#include using namespace SourceMod; @@ -42,7 +42,7 @@ class KeyValues; struct KeyValueStack { KeyValues *pBase; - SourceHook::CStack pCurRoot; + std::deque pCurRoot; bool m_bDeleteOnDestroy = true; }; diff --git a/core/smn_nextmap.cpp b/core/smn_nextmap.cpp index ef6f4ab28..c9a640552 100644 --- a/core/smn_nextmap.cpp +++ b/core/smn_nextmap.cpp @@ -79,8 +79,7 @@ static cell_t sm_GetMapHistory(IPluginContext *pCtx, const cell_t *params) return pCtx->ThrowNativeError("Invalid Map History Index"); } - SourceHook::List::iterator iter; - iter = g_NextMap.m_mapHistory.end(); + auto iter = g_NextMap.m_mapHistory.end(); iter--; for (int i=0; i MsgWrapperList; -typedef List::iterator MsgWrapperIter; +typedef std::list MsgWrapperList; +typedef MsgWrapperList::iterator MsgWrapperIter; class UsrMessageNatives : public SMGlobalClass, @@ -72,17 +72,15 @@ public: bool FindListener(int msgid, IPluginContext *pCtx, IPluginFunction *pHook, bool intercept, MsgWrapperIter *iter); bool DeleteListener(IPluginContext *pCtx, MsgWrapperIter iter); private: - CStack m_FreeListeners; + std::stack m_FreeListeners; }; UsrMessageNatives::~UsrMessageNatives() { - CStack::iterator iter; - for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++) - { - delete (*iter); + while (!m_FreeListeners.empty()) { + delete m_FreeListeners.top(); + m_FreeListeners.pop(); } - m_FreeListeners.popall(); } void UsrMessageNatives::OnSourceModAllInitialized() @@ -175,13 +173,13 @@ MsgListenerWrapper *UsrMessageNatives::CreateListener(IPluginContext *pCtx) { pListener = new MsgListenerWrapper; } else { - pListener = m_FreeListeners.front(); + pListener = m_FreeListeners.top(); m_FreeListeners.pop(); } if (!pl->GetProperty("MsgListeners", reinterpret_cast(&pList))) { - pList = new List; + pList = new std::list; pl->SetProperty("MsgListeners", pList); } diff --git a/core/sourcemm_api.cpp b/core/sourcemm_api.cpp index a80107999..6fcb8de64 100644 --- a/core/sourcemm_api.cpp +++ b/core/sourcemm_api.cpp @@ -48,8 +48,6 @@ ISmmPluginManager *g_pMMPlugins = NULL; CGlobalVars *gpGlobals = NULL; ICvar *icvar = NULL; IGameEventManager2 *gameevents = NULL; -CallClass *enginePatch = NULL; -CallClass *gamedllPatch = NULL; IPlayerInfoManager *playerinfo = NULL; IBaseFileSystem *basefilesystem = NULL; IFileSystem *filesystem = NULL; diff --git a/core/sourcemm_api.h b/core/sourcemm_api.h index 68372a10c..ee8b34974 100644 --- a/core/sourcemm_api.h +++ b/core/sourcemm_api.h @@ -40,6 +40,7 @@ #include #include #include +#include /** * @file Contains wrappers around required Metamod:Source API exports @@ -78,8 +79,6 @@ extern ICvar *icvar; extern ISmmPluginManager *g_pMMPlugins; extern CGlobalVars *gpGlobals; extern IGameEventManager2 *gameevents; -extern SourceHook::CallClass *enginePatch; -extern SourceHook::CallClass *gamedllPatch; extern IPlayerInfoManager *playerinfo; extern IBaseFileSystem *basefilesystem; extern IFileSystem *filesystem; @@ -91,9 +90,6 @@ extern IServerPluginHelpers *serverpluginhelpers; extern IServerPluginCallbacks *vsp_interface; extern int vsp_version; -#define ENGINE_CALL(func) SH_CALL(enginePatch, &IVEngineServer::func) -#define SERVER_CALL(func) SH_CALL(gamedllPatch, &IServerGameDLL::func) - PLUGIN_GLOBALVARS(); #endif //_INCLUDE_SOURCEMOD_MM_API_H_ diff --git a/core/sourcemod.cpp b/core/sourcemod.cpp index be595032e..1bc23f12f 100644 --- a/core/sourcemod.cpp +++ b/core/sourcemod.cpp @@ -32,7 +32,7 @@ #include #include "sourcemod.h" #include "sourcemm_api.h" -#include +#include #include "CoreConfig.h" #include "Logger.h" #include "sm_stringutil.h" @@ -49,17 +49,12 @@ #include #include -SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool); -SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false); -SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, false, bool); -SH_DECL_HOOK1_void(IServerGameDLL, Think, SH_NOATTRIB, false, bool); -SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char *); -SH_DECL_HOOK0(IVEngineServer, GetMapEntitiesString, SH_NOATTRIB, 0, const char *); +/**/ SourceModBase g_SourceMod; ke::RefPtr g_JIT; -SourceHook::String g_BaseDir; +std::string g_BaseDir; ISourcePawnEngine *g_pSourcePawn = NULL; ISourcePawnEngine2 *g_pSourcePawn2 = NULL; ISourcePawnEnvironment *g_pPawnEnv = NULL; @@ -93,13 +88,32 @@ void ShutdownJIT() g_JIT = nullptr; } -SourceModBase::SourceModBase() +SourceModBase::SourceModBase() : + m_HookLevelInit(&IServerGameDLL::LevelInit, this, &SourceModBase::Hook_LevelInit, nullptr), + m_HookLevelShutdown(&IServerGameDLL::LevelShutdown, this, &SourceModBase::Hook_LevelShutdown, nullptr), + m_HookGameFrame(&IServerGameDLL::GameFrame, this, &SourceModBase::Hook_GameFrame, nullptr), + m_HookThink(&IServerGameDLL::Think, this, &SourceModBase::Hook_Think, nullptr), + m_HookGetMapEntitiesString(&IVEngineServer::GetMapEntitiesString, this, &SourceModBase::Hook_GetMapEntitiesString, nullptr) { m_IsMapLoading = false; m_ExecPluginReload = false; m_GotBasePath = false; } +KHook::Return SourceModBase::Hook_GameFrame(IServerGameDLL*, bool simulating) +{ + g_Timers.GameFrame(simulating); + + return { KHook::Action::Ignore }; +} + +KHook::Return SourceModBase::Hook_Think(IServerGameDLL*, bool simulating) +{ + logicore.callbacks->OnThink(simulating); + + return { KHook::Action::Ignore }; +} + ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, const char *value, ConfigSource source, @@ -278,8 +292,8 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late sSourceModInitialized = true; /* Hook this now so we can detect startup without calling StartSourceMod() */ - SH_ADD_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false); - SH_ADD_HOOK(IVEngineServer, GetMapEntitiesString, engine, SH_MEMBER(this, &SourceModBase::GetMapEntitiesString), false); + m_HookLevelInit.Add(gamedll); + m_HookGetMapEntitiesString.Add(engine); /* Only load if we're not late */ if (!late) @@ -292,11 +306,8 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late void SourceModBase::StartSourceMod(bool late) { - SH_ADD_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SourceModBase::LevelShutdown), false); - SH_ADD_HOOK(IServerGameDLL, GameFrame, gamedll, SH_MEMBER(&g_Timers, &TimerSystem::GameFrame), false); - - enginePatch = SH_GET_CALLCLASS(engine); - gamedllPatch = SH_GET_CALLCLASS(gamedll); + m_HookLevelShutdown.Add(gamedll); + m_HookGameFrame.Add(gamedll); sCoreProviderImpl.InitializeBridge(); @@ -370,12 +381,11 @@ void SourceModBase::StartSourceMod(bool late) { g_pPawnEnv->EnableDebugBreak(); } - - SH_ADD_HOOK(IServerGameDLL, Think, gamedll, SH_MEMBER(logicore.callbacks, &IProviderCallbacks::OnThink), false); + m_HookThink.Add(gamedll); } static bool g_LevelEndBarrier = false; -bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) +KHook::Return SourceModBase::Hook_LevelInit(IServerGameDLL*, char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) { /* Seed rand() globally per map */ srand(time(NULL)); @@ -436,23 +446,23 @@ bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, ch if (!success) { logger->LogError("Map entity lump parsing for %s failed with error code %d on position %d", pMapName, parseError, position); - RETURN_META_VALUE(MRES_IGNORED, true); + return { KHook::Action::Ignore }; } - RETURN_META_VALUE_NEWPARAMS(MRES_HANDLED, true, &IServerGameDLL::LevelInit, (pMapName, logicore.GetEntityLumpString(), pOldLevel, pLandmarkName, loadGame, background)); + return KHook::Recall(KHook::Return{KHook::Action::Override, true}, (pMapName, logicore.GetEntityLumpString(), pOldLevel, pLandmarkName, loadGame, background)); } -const char *SourceModBase::GetMapEntitiesString() +KHook::Return SourceModBase::Hook_GetMapEntitiesString(IVEngineServer*) { const char *pNewMapEntities = logicore.GetEntityLumpString(); if (pNewMapEntities != nullptr) { - RETURN_META_VALUE(MRES_SUPERCEDE, pNewMapEntities); + return { KHook::Action::Supersede, pNewMapEntities }; } - RETURN_META_VALUE(MRES_IGNORED, NULL); + return { KHook::Action::Ignore }; } -void SourceModBase::LevelShutdown() +KHook::Return SourceModBase::Hook_LevelShutdown(IServerGameDLL*) { if (g_LevelEndBarrier) { @@ -479,6 +489,8 @@ void SourceModBase::LevelShutdown() scripts->RefreshAll(); m_ExecPluginReload = false; } + + return { KHook::Action::Ignore }; } bool SourceModBase::IsMapLoading() const @@ -563,13 +575,13 @@ void SourceModBase::CloseSourceMod() if (!sSourceModInitialized) return; - SH_REMOVE_HOOK(IServerGameDLL, LevelInit, gamedll, SH_MEMBER(this, &SourceModBase::LevelInit), false); - SH_REMOVE_HOOK(IVEngineServer, GetMapEntitiesString, engine, SH_MEMBER(this, &SourceModBase::GetMapEntitiesString), false); + m_HookLevelInit.Remove(gamedll); + m_HookGetMapEntitiesString.Remove(engine); if (g_Loaded) { /* Force a level end */ - LevelShutdown(); + Hook_LevelShutdown(gamedll); ShutdownServices(); } @@ -616,21 +628,9 @@ void SourceModBase::ShutdownServices() pBase = pBase->m_pGlobalClassNext; } - if (enginePatch) - { - SH_RELEASE_CALLCLASS(enginePatch); - enginePatch = NULL; - } - - if (gamedllPatch) - { - SH_RELEASE_CALLCLASS(gamedllPatch); - gamedllPatch = NULL; - } - - SH_REMOVE_HOOK(IServerGameDLL, LevelShutdown, gamedll, SH_MEMBER(this, &SourceModBase::LevelShutdown), false); - SH_REMOVE_HOOK(IServerGameDLL, GameFrame, gamedll, SH_MEMBER(&g_Timers, &TimerSystem::GameFrame), false); - SH_REMOVE_HOOK(IServerGameDLL, Think, gamedll, SH_MEMBER(logicore.callbacks, &IProviderCallbacks::OnThink), false); + m_HookLevelShutdown.Remove(gamedll); + m_HookGameFrame.Remove(gamedll); + m_HookThink.Remove(gamedll); } void SourceModBase::LogMessage(IExtension *pExt, const char *format, ...) @@ -765,7 +765,7 @@ void SourceModBase::RemoveGameFrameHook(GAME_FRAME_HOOK hook) { if (m_frame_hooks[i] == hook) { - m_frame_hooks.erase(m_frame_hooks.iterAt(i)); + m_frame_hooks.erase(m_frame_hooks.begin() + i); return; } } @@ -821,9 +821,7 @@ int SourceModBase::GetPluginId() int SourceModBase::GetShApiVersion() { - int api, impl; - g_SMAPI->GetShVersions(api, impl); - + int api = 999, impl = 999; return api; } diff --git a/core/sourcemod.h b/core/sourcemod.h index 0b4eb23e9..a934bd667 100644 --- a/core/sourcemod.h +++ b/core/sourcemod.h @@ -34,10 +34,9 @@ #include "sm_globals.h" #include -#include -#include - -using namespace SourceHook; +#include +#include +#include #if defined _DEBUG # define IF_DEBUG_SPEW @@ -76,16 +75,6 @@ public: */ void CloseSourceMod(); - /** - * @brief Map change hook - */ - bool LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background); - - /** - * @brief Level shutdown hook - */ - void LevelShutdown(); - /** * @brief Returns whether or not a map load is in progress */ @@ -140,7 +129,6 @@ public: // ISourceMod private: void ShutdownServices(); private: - const char* GetMapEntitiesString(); char m_SMBaseDir[PLATFORM_MAX_PATH]; char m_SMRelDir[PLATFORM_MAX_PATH]; char m_ModDir[32]; @@ -149,7 +137,18 @@ private: bool m_ExecOnMapEnd; unsigned int m_target; bool m_GotBasePath; - CVector m_frame_hooks; + std::vector m_frame_hooks; +protected: + KHook::Virtual m_HookLevelInit; + KHook::Return Hook_LevelInit(class IServerGameDLL*, char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background); + KHook::Virtual m_HookLevelShutdown; + KHook::Return Hook_LevelShutdown(class IServerGameDLL*); + KHook::Virtual m_HookGameFrame; + KHook::Return Hook_GameFrame(class IServerGameDLL*, bool); + KHook::Virtual m_HookThink; + KHook::Return Hook_Think(class IServerGameDLL*, bool); + KHook::Virtual m_HookGetMapEntitiesString; + KHook::Return Hook_GetMapEntitiesString(class IVEngineServer*); }; void UTIL_ConsolePrintVa(const char *fmt, va_list ap); diff --git a/public/sm_queue.h b/public/sm_queue.h index ff46a583a..fa76fede2 100644 --- a/public/sm_queue.h +++ b/public/sm_queue.h @@ -34,9 +34,7 @@ #include #include -#include - -using namespace SourceHook; +#include /* A circular, doubly-linked List with one sentinel node @@ -109,7 +107,7 @@ public: while (!m_FreeNodes.empty()) { - free(m_FreeNodes.front()); + free(m_FreeNodes.top()); m_FreeNodes.pop(); } } @@ -122,7 +120,7 @@ public: { node = (QueueNode *)malloc(sizeof(QueueNode)); } else { - node = m_FreeNodes.front(); + node = m_FreeNodes.top(); m_FreeNodes.pop(); } @@ -169,7 +167,7 @@ public: private: QueueNode *m_Head; size_t m_Size; - CStack m_FreeNodes; + std::stack m_FreeNodes; public: class iterator {