Remove SourceHook from core

This commit is contained in:
Kenzzer 2025-08-17 16:27:26 +00:00
parent 92fb9f62dd
commit 1c5183dd18
No known key found for this signature in database
GPG Key ID: 64C3FD4332686DC1
72 changed files with 915 additions and 956 deletions

View File

@ -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':

View File

@ -29,13 +29,12 @@
#include <sp_vm_api.h>
#include <IExtensionSys.h>
#include <sh_vector.h>
#include <vector>
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<IExtension *> *ListExtensions() = 0;
virtual void FreeExtensionList(const CVector<IExtension *> *list) = 0;
virtual const std::vector<IExtension *> *ListExtensions() = 0;
virtual void FreeExtensionList(const std::vector<IExtension *> *list) = 0;
virtual void CallOnCoreMapEnd() = 0;
};
@ -67,13 +66,13 @@ public:
{
extensions_->FreeExtensionList(list_);
}
const CVector<IExtension *> *operator ->()
const std::vector<IExtension *> *operator ->()
{
return list_;
}
private:
IExtensionSys *extensions_;
const CVector<IExtension *> *list_;
const std::vector<IExtension *> *list_;
};
} // namespace SourceMod

View File

@ -29,12 +29,11 @@
#include <sp_vm_api.h>
#include <IPluginSys.h>
#include <sh_vector.h>
#include <sh_string.h>
#include <vector>
#include <string>
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<SMPlugin *> *ListPlugins() = 0;
virtual void FreePluginList(const CVector<SMPlugin *> *list) = 0;
virtual const std::vector<SMPlugin *> *ListPlugins() = 0;
virtual void FreePluginList(const std::vector<SMPlugin *> *list) = 0;
virtual void AddFunctionsToForward(const char *name, IChangeableForward *fwd) = 0;
};
@ -98,13 +97,13 @@ public:
{
scripts_->FreePluginList(list_);
}
const CVector<SMPlugin *> *operator ->()
const std::vector<SMPlugin *> *operator ->()
{
return list_;
}
private:
IScriptManager *scripts_;
const CVector<SMPlugin *> *list_;
const std::vector<SMPlugin *> *list_;
};
} // namespace SourceMod

View File

@ -415,7 +415,7 @@ void RegisterInPlugin(CmdHook *hook)
void ConCmdManager::AddToCmdList(ConCmdInfo *info)
{
List<ConCmdInfo *>::iterator iter = m_CmdList.begin();
auto iter = m_CmdList.begin();
ConCmdInfo *pInfo;
bool inserted = false;
const char *orig = NULL;

View File

@ -43,16 +43,14 @@
#include "sm_globals.h"
#include "sourcemm_api.h"
#include <IForwardSys.h>
#include <sh_list.h>
#include <sh_string.h>
#include <list>
#include <string>
#include <IRootConsoleMenu.h>
#include <IAdminSystem.h>
#include "concmd_cleaner.h"
#include "GameHooks.h"
#include <sm_namehashset.h>
using namespace SourceHook;
struct CmdHook;
struct ConCmdInfo;
@ -137,7 +135,7 @@ struct ConCmdInfo
};
};
typedef List<ConCmdInfo *> ConCmdList;
typedef std::list<ConCmdInfo *> 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<ConCmdInfo *> & GetCommandList()
inline const std::list<ConCmdInfo *> & GetCommandList()
{
return m_CmdList;
}

View File

@ -30,7 +30,7 @@
#include "ConVarManager.h"
#include "HalfLife2.h"
#include "sm_stringutil.h"
#include <sh_vector.h>
#include <vector>
#include <sm_namehashset.h>
#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<const ConVar *> ConVarList;
typedef std::list<const ConVar *> ConVarList;
NameHashSet<ConVarInfo *, ConVarInfo::ConVarPolicy> convar_cache;
enum {
@ -114,7 +114,7 @@ void ConVarManager::OnSourceModAllInitialized()
void ConVarManager::OnSourceModShutdown()
{
List<ConVarInfo *>::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<ConVarInfo *>::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<ConVarQuery>::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<ConVarQuery>::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<ConVar *>(*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<ConVarQuery>::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

View File

@ -34,7 +34,7 @@
#include "sm_globals.h"
#include "sourcemm_api.h"
#include <sh_list.h>
#include <list>
#include <IPluginSys.h>
#include <IForwardSys.h>
#include <IHandleSys.h>
@ -45,8 +45,6 @@
#include "PlayerManager.h"
#include <sm_hashmap.h>
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<IConVarChangeListener *> changeListeners;
std::list<IConVarChangeListener *> changeListeners;
struct ConVarPolicy
{
@ -175,8 +173,8 @@ private:
static void AddConVarToPluginList(IPlugin *plugin, const ConVar *pConVar);
private:
HandleType_t m_ConVarType;
List<ConVarInfo *> m_ConVars;
List<ConVarQuery> m_ConVarQueries;
std::list<ConVarInfo *> m_ConVars;
std::list<ConVarQuery> m_ConVarQueries;
};
extern ConVarManager g_ConVarManager;

View File

@ -62,30 +62,34 @@
# include <unistd.h>
#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<ConCommand, void, const CCommand&>;
KHook::Return<void> Dispatch(ConCommand* this_ptr, const CCommand& args)
#else
using CmdHook = KHook::Member<ConCommand, void>;
KHook::Return<void> 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<HackInfo> vtables;
std::vector<HackInfo> vtables;
bool enabled;
SourceHook::MemFuncInfo dispatch;
inline void **GetVirtualTable(ConCommandBase *pBase)
{
return *reinterpret_cast<void***>(reinterpret_cast<char*>(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<ConCommand*>(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<HackInfo>::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();
}

View File

@ -41,13 +41,11 @@
#include <sourcemod_version.h>
#include <amtl/os/am-path.h>
#include <amtl/os/am-fsutil.h>
#include <sh_list.h>
#include <list>
#include <IForwardSys.h>
#include <bridge/include/IScriptManager.h>
#include <bridge/include/ILogger.h>
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<void> Hook_ExecDispatchPre(ConCommand*, const CCommand &cmd)
#else
SH_DECL_EXTERN0_void(ConCommand, Dispatch, SH_NOATTRIB, false);
void Hook_ExecDispatchPre()
KHook::Return<void> 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<void> Hook_ExecDispatchPost(ConCommand*, const CCommand &cmd)
#else
void Hook_ExecDispatchPost()
KHook::Return<void> 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<const ConVar *> *convars = NULL;
std::list<const ConVar *> *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<const ConVar *>::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

View File

@ -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<EventHook *> EventHookList;
typedef std::list<EventHook *> 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<EventInfo *>::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<bool> 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<bool>{ 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<bool> 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 };
}

View File

@ -35,16 +35,14 @@
#include "sm_globals.h"
#include "sourcemm_api.h"
#include <sm_namehashset.h>
#include <sh_list.h>
#include <sh_stack.h>
#include <list>
#include <stack>
#include <IHandleSys.h>
#include <IForwardSys.h>
#include <IPluginSys.h>
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<bool> OnFireEvent(IGameEventManager2*, IGameEvent *pEvent, bool bDontBroadcast);
KHook::Return<bool> OnFireEvent_Post(IGameEventManager2*, IGameEvent *pEvent, bool bDontBroadcast);
private:
HandleType_t m_EventType;
NameHashSet<EventHook *> m_EventHooks;
CStack<EventInfo *> m_FreeEvents;
CStack<EventHook *> m_EventStack;
CStack<IGameEvent *> m_EventCopies;
std::stack<EventInfo *> m_FreeEvents;
std::stack<EventHook *> m_EventStack;
std::stack<IGameEvent *> m_EventCopies;
KHook::Virtual<IGameEventManager2, bool, IGameEvent*, bool> m_FireEvent;
};
extern EventManager g_EventManager;

View File

@ -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<void> GameHooks::OnConVarChanged(ICvar*, ConVar *pConVar, const char *oldValue, float flOldValue)
#else
void GameHooks::OnConVarChanged(ConVar *pConVar, const char *oldValue)
KHook::Return<void> 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<void> 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<void> 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<CommandHook>
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<void> 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<void> CommandHook::Dispatch(ConCommand*, const CCommand& command)
#else
KHook::Return<void> 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 };
}

View File

@ -35,6 +35,7 @@
#include <amtl/am-refcounting.h>
#include <amtl/am-vector.h>
#include <amtl/am-function.h>
#include <khook.hpp>
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<void> Dispatch(ConCommand*, const CCommand&);
#else
KHook::Return<void> Dispatch(ConCommand*);
#endif
private:
int hook_id_;
Callback callback_;
#if SOURCE_ENGINE >= SE_ORANGEBOX
KHook::Virtual<ConCommand, void, const CCommand&> m_DispatchHook;
#else
KHook::Virtual<ConCommand, void> 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<void> OnConVarChanged(ICvar*, ConVar *pConVar, const char *oldValue, float flOldValue);
#else
static void OnConVarChanged(ConVar *pConVar, const char *oldValue);
static KHook::Return<void> 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<void> GameDLLOnQueryCvarValueFinished(IServerGameDLL*, QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
const char *cvarName, const char *cvarValue);
KHook::Virtual<IServerGameDLL, void, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *> m_GameDLLOnQueryCvarValueFinishedHook;
KHook::Return<void> VSPOnQueryCvarValueFinished(IServerPluginCallbacks*, QueryCvarCookie_t cookie, edict_t *pPlayer, EQueryCvarValueStatus result,
const char *cvarName, const char *cvarValue);
KHook::Virtual<IServerPluginCallbacks, void, QueryCvarCookie_t, edict_t *, EQueryCvarValueStatus, const char *, const char *> m_VSPOnQueryCvarValueFinishedHook;
#endif
void SetCommandClient(int client);
KHook::Return<void> SetCommandClient(IServerGameClients*, int client);
KHook::Virtual<IServerGameClients, void, int> m_SetCommandClient;
private:
class HookList : public std::vector<int>

View File

@ -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
}

View File

@ -32,9 +32,8 @@
#ifndef _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
#define _INCLUDE_SOURCEMOD_CHALFLIFE2_H_
#include <sh_list.h>
#include <sh_string.h>
#include <sh_tinyhash.h>
#include <list>
#include <string>
#include <am-utility.h>
#include <am-hashset.h>
#include <am-hashmap.h>
@ -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<DataMapCacheInfo> DataMapCache;
struct DelayedFakeCliCmd
{
String cmd;
std::string cmd;
int client;
int userid;
};
@ -288,8 +286,8 @@ private:
int m_SayTextMsg;
int m_VGUIMenu;
Queue<DelayedFakeCliCmd *> m_CmdQueue;
CStack<DelayedFakeCliCmd *> m_FreeCmds;
CStack<CachedCommandInfo> m_CommandStack;
std::stack<DelayedFakeCliCmd *> m_FreeCmds;
std::stack<CachedCommandInfo> m_CommandStack;
Queue<DelayedKickInfo> m_DelayedKicks;
void *m_pGetCommandLine;
#if SOURCE_ENGINE == SE_CSGO

View File

@ -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<void> 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
{

View File

@ -33,11 +33,9 @@
#define _INCLUDE_SOURCEMOD_CLOGGER_H_
#include <stdio.h>
#include <sh_string.h>
#include <string>
#include "sm_globals.h"
using namespace SourceHook;
class LoggerCore : public SMGlobalClass
{
public: //SMGlobalClass

View File

@ -33,14 +33,11 @@
#define _INCLUDE_SOURCEMOD_MENUMANAGER_H_
#include <IMenuManager.h>
#include <sh_vector.h>
#include <sh_stack.h>
#include <sh_list.h>
#include <vector>
#include "sm_globals.h"
#include <string>
using namespace SourceMod;
using namespace SourceHook;
class MenuManager :
public IMenuManager,
@ -102,7 +99,7 @@ protected:
private:
int m_ShowMenu;
IMenuStyle *m_pDefaultStyle;
CVector<IMenuStyle *> m_Styles;
std::vector<IMenuStyle *> m_Styles;
HandleType_t m_StyleType;
HandleType_t m_MenuType;
std::string m_SelectSound = "";

View File

@ -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();
}

View File

@ -39,8 +39,8 @@
#include <IPlayerHelpers.h>
#include "UserMessages.h"
#include "sm_fastlink.h"
#include <sh_stack.h>
#include <sh_string.h>
#include <stack>
#include <string>
#include <compat_wrappers.h>
#include "logic/common_logic.h"
#include "AutoHandleRooter.h"
@ -106,7 +106,7 @@ public:
CRadioMenuPlayer *GetRadioMenuPlayer(int client);
private:
CRadioMenuPlayer *m_players;
CStack<CRadioDisplay *> m_FreeDisplays;
std::stack<CRadioDisplay *> 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;
};

View File

@ -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<IServerPluginHelpers> *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<void> 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,

View File

@ -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<void> HookCreateMessage(IServerPluginHelpers*, edict_t *pEdict, DIALOG_TYPE type, KeyValues *kv, IServerPluginCallbacks *plugin);
KHook::Virtual<IServerPluginHelpers, void, edict_t*, DIALOG_TYPE, KeyValues*, IServerPluginCallbacks*> m_HookCreateMessage;
private:
CValveMenuPlayer *m_players;
};

View File

@ -34,11 +34,10 @@
#include <IMenuManager.h>
#include <IPlayerHelpers.h>
#include <sh_vector.h>
#include <vector>
#include "sm_globals.h"
#include <TimerSys.h>
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<unsigned int> m_Votes;
std::vector<unsigned int> m_Votes;
IBaseMenu *m_pCurMenu;
bool m_bStarted;
bool m_bCancelled;

View File

@ -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 <time.h>
@ -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<MapChangeData *>::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<void> 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<void> 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<void>{ KHook::Action::Ignore }, this_ptr, newmap, unknown);
#else
RETURN_META_NEWPARAMS(MRES_IGNORED, &IVEngineServer::ChangeLevel, (newmap, unknown, video, bLongLoading));
return KHook::Recall(KHook::Return<void>{ 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<MapChangeData *>::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<MapChangeData *>();
}
#if SOURCE_ENGINE >= SE_ORANGEBOX
void CmdChangeLevelCallback(const CCommand &command)
KHook::Return<void> CmdChangeLevelCallback(ConCommand*, const CCommand &command)
{
#else
void CmdChangeLevelCallback()
KHook::Return<void> 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 };
}

View File

@ -34,9 +34,10 @@
#include "sm_globals.h"
#include <eiface.h>
#include "sh_list.h"
#include <list>
#include "sm_stringutil.h"
#include <amtl/am-string.h>
#include <khook.hpp>
struct MapChangeData
{
@ -60,9 +61,9 @@ struct MapChangeData
};
#if SOURCE_ENGINE >= SE_ORANGEBOX
void CmdChangeLevelCallback(const CCommand &command);
KHook::Return<void> CmdChangeLevelCallback(ConCommand*, const CCommand &command);
#else
void CmdChangeLevelCallback();
KHook::Return<void> 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<void> CmdChangeLevelCallback(ConCommand*, const CCommand &command);
#else
friend void CmdChangeLevelCallback();
friend KHook::Return<void> 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<IVEngineServer, void, const char*, const char*> m_HookChangeLevel;
KHook::Return<void> HookChangeLevel(IVEngineServer*, const char *map, const char *unknown);
#else
void HookChangeLevel(const char *map, const char *unknown, const char *video, bool bLongLoading);
KHook::Virtual<IVEngineServer, void, const char*, const char*, const char*, bool> m_HookChangeLevel;
KHook::Return<void> HookChangeLevel(IVEngineServer*, const char *map, const char *unknown, const char *video, bool bLongLoading);
#endif
public:
SourceHook::List<MapChangeData *> m_mapHistory;
std::list<MapChangeData *> m_mapHistory;
private:
MapChangeData m_tempChangeInfo;

View File

@ -64,38 +64,11 @@ IForward *ServerExitHibernation = NULL;
const unsigned int *g_NumPlayersToAuth = NULL;
int lifestate_offset = -1;
List<ICommandTargetProcessor *> target_processors;
std::list<ICommandTargetProcessor *> 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<void> 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<IClientListener *>::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<IClientListener *>::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<bool> 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<IClientListener *>::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<bool> 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<IClientListener *>::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<void> 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<IClientListener *>::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<IClientListener *>::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<void> 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<void> 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<IClientListener *>::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<void> 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<IClientListener *>::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<void> 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<INetChannel *>(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<SMPlugin *> m_FailList;
std::list<SMPlugin *> 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<void> PlayerManager::OnClientCommand(IServerGameClients*, edict_t *pEntity, const CCommand &args)
{
#else
void PlayerManager::OnClientCommand(edict_t *pEntity)
KHook::Return<void> 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<void> 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<void> 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<void> 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<IClientListener *>::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<ICommandTargetProcessor *>::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<IClientListener *>::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<void> CmdMaxplayersCallback(ConCommand*, const CCommand &command)
{
#else
void CmdMaxplayersCallback()
KHook::Return<void> 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<IClientListener *>::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<IClientListener *>::iterator iter;
for (iter = g_Players.m_hooks.begin();
for (auto iter = g_Players.m_hooks.begin();
iter != g_Players.m_hooks.end();
iter++)
{

View File

@ -39,17 +39,15 @@
#include <IPlayerHelpers.h>
#include <IAdminSystem.h>
#include <ITranslator.h>
#include <sh_string.h>
#include <sh_list.h>
#include <sh_vector.h>
#include <string>
#include <list>
#include <vector>
#include <am-string.h>
#include <am-deque.h>
#include "ConVarManager.h"
#include <steam/steamclientpublic.h>
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<IServerGameClients, bool, edict_t*, const char*, const char*, char*, int> m_HookClientConnect;
KHook::Return<bool> OnClientConnect(IServerGameClients*, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
KHook::Return<bool> OnClientConnect_Post(IServerGameClients*, edict_t *pEntity, const char *pszName, const char *pszAddress, char *reject, int maxrejectlen);
KHook::Virtual<IServerGameClients, void, edict_t*, const char*> m_HookClientPutInServer;
KHook::Return<void> OnClientPutInServer(IServerGameClients*, edict_t *pEntity, char const *playername);
KHook::Virtual<IServerGameClients, void, edict_t*> m_HookClientDisconnect;
KHook::Return<void> OnClientDisconnect(IServerGameClients*, edict_t *pEntity);
KHook::Return<void> OnClientDisconnect_Post(IServerGameClients*, edict_t *pEntity);
#if SOURCE_ENGINE >= SE_ORANGEBOX
void OnClientCommand(edict_t *pEntity, const CCommand &args);
KHook::Virtual<IServerGameClients, void, edict_t*, const CCommand&> m_HookClientCommand;
KHook::Return<void> 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<IServerGameClients, void, edict_t*, KeyValues*> m_HookClientCommandKeyValues;
KHook::Return<void> OnClientCommandKeyValues(IServerGameClients*, edict_t *pEntity, KeyValues *pCommand);
KHook::Return<void> OnClientCommandKeyValues_Post(IServerGameClients*, edict_t *pEntity, KeyValues *pCommand);
#endif
#else
void OnClientCommand(edict_t *pEntity);
KHook::Virtual<IServerGameClients, void, edict_t*> m_HookClientCommand;
KHook::Return<void> OnClientCommand(IServerGameClients*, edict_t *pEntity);
#endif
void OnClientSettingsChanged(edict_t *pEntity);
KHook::Virtual<IServerGameClients, void, edict_t*> m_HookClientSettingsChanged;
KHook::Return<void> 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<IServerGameDLL, void, edict_t*, int, int> m_HookServerActivate;
KHook::Return<void> OnServerActivate(IServerGameDLL*, edict_t *pEdictList, int edictCount, int clientMax);
#if SOURCE_ENGINE >= SE_LEFT4DEAD
KHook::Virtual<IServerGameDLL, void, bool> m_HookOnServerHibernationUpdate;
#elif SOURCE_ENGINE > SE_EYE
KHook::Virtual<IServerGameDLL, void, bool> m_HookSetServerHibernation;
#endif
KHook::Return<void> OnServerHibernationUpdate(IServerGameDLL*, bool bHibernating);
KHook::Virtual<IVEngineServer, void, edict_t*, const char*> m_HookClientPrintf;
KHook::Return<void> 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<IClientListener *> m_hooks;
std::list<IClientListener *> 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<void> CmdMaxplayersCallback(ConCommand*, const CCommand &command);
#else
void CmdMaxplayersCallback();
KHook::Return<void> CmdMaxplayersCallback(ConCommand*);
#endif
extern void ClientConsolePrint(edict_t *e, const char *fmt, ...);

View File

@ -177,12 +177,11 @@ TimerSystem::TimerSystem()
TimerSystem::~TimerSystem()
{
CStack<ITimer *>::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<ITimer *> s_tokill;
std::stack<ITimer *> 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();
}
}

View File

@ -33,16 +33,15 @@
#define _INCLUDE_SOURCEMOD_CTIMERSYS_H_
#include <ITimerSystem.h>
#include <sh_stack.h>
#include <sh_list.h>
#include <stack>
#include <list>
#include "sourcemm_api.h"
#include "sm_globals.h"
using namespace SourceHook;
using namespace SourceMod;
typedef List<ITimer *> TimerList;
typedef List<ITimer *>::iterator TimerIter;
typedef std::list<ITimer *> TimerList;
typedef TimerList::iterator TimerIter;
class SourceMod::ITimer
{
@ -84,9 +83,9 @@ public:
void RemoveMapChangeTimers();
void GameFrame(bool simulating);
private:
List<ITimer *> m_SingleTimers;
List<ITimer *> m_LoopTimers;
CStack<ITimer *> m_FreeTimers;
std::list<ITimer *> m_SingleTimers;
std::list<ITimer *> m_LoopTimers;
std::stack<ITimer *> m_FreeTimers;
IMapTimer *m_pMapTimer;
/* This is stuff for our manual ticking escapades. */

View File

@ -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<ListenerInfo *>::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<IRecipientFilter *>(&m_CellRecFilter), msg_id, g_SMAPI->GetUserMessage(msg_id));
buffer = m_UserMessageBegin.CallOriginal(engine, static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id, g_SMAPI->GetUserMessage(msg_id));
#else
buffer = ENGINE_CALL(UserMessageBegin)(static_cast<IRecipientFilter *>(&m_CellRecFilter), msg_id);
buffer = m_UserMessageBegin.CallOriginal(engine, static_cast<IRecipientFilter *>(&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<protobuf::Message*> 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<bf_write*> 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<bf_write*> 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<protobuf::Message*> 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<bf_write*> 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<bf_write*> 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<void> 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<void> 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<IRecipientFilter &>(*m_CurRecFilter), m_CurId, *m_InterceptBuffer);
m_SendUserMessage.CallOriginal(engine, static_cast<IRecipientFilter &>(*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)
}

View File

@ -38,10 +38,9 @@
#include "sm_stringutil.h"
#include "CellRecipientFilter.h"
#include "sm_globals.h"
#include <sh_list.h>
#include <sh_stack.h>
#include <list>
#include <stack>
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<ListenerInfo *> MsgList;
typedef List<ListenerInfo *>::iterator MsgIter;
typedef std::list<ListenerInfo *> 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<void> OnSendUserMessage_Pre(IVEngineServer*, IRecipientFilter &filter, int msg_type, const protobuf::Message &msg);
KHook::Return<void> 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<protobuf::Message*> OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name);
KHook::Return<protobuf::Message*> 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<bf_write*> OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type, const char *msg_name);
KHook::Return<bf_write*> 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<bf_write*> OnStartMessage_Pre(IVEngineServer*, IRecipientFilter *filter, int msg_type);
KHook::Return<bf_write*> OnStartMessage_Post(IVEngineServer*, IRecipientFilter *filter, int msg_type);
#endif
void OnMessageEnd_Pre();
void OnMessageEnd_Post();
KHook::Return<void> OnMessageEnd_Pre(IVEngineServer*);
KHook::Return<void> 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<ListenerInfo *> m_msgHooks[255];
List<ListenerInfo *> m_msgIntercepts[255];
CStack<ListenerInfo *> m_FreeListeners;
std::list<ListenerInfo *> m_msgHooks[255];
std::list<ListenerInfo *> m_msgIntercepts[255];
std::stack<ListenerInfo *> 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<IVEngineServer, void, IRecipientFilter&, int, const protobuf::Message&> m_SendUserMessage;
#else
#if SOURCE_ENGINE >= SE_LEFT4DEAD
KHook::Virtual<IVEngineServer, bf_write*, IRecipientFilter*, int, const char*> m_UserMessageBegin;
#else
KHook::Virtual<IVEngineServer, bf_write*, IRecipientFilter*, int> m_UserMessageBegin;
#endif
KHook::Virtual<IVEngineServer, void> m_MessageEnd;
#endif // ==SE_CSGO || ==SE_BLADE || ==SE_MCV
};
extern UserMessages g_UserMsgs;

View File

@ -26,7 +26,7 @@
// or <http://www.sourcemod.net/license.php>.
#include "sm_globals.h"
#include <sh_list.h>
#include <list>
#include <convar.h>
#include "concmd_cleaner.h"
#include "sm_stringutil.h"
@ -34,19 +34,6 @@
#include "compat_wrappers.h"
#include <amtl/am-string.h>
#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<ConCommandInfo *> tracked_bases;
std::list<ConCommandInfo *> 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<ICvar, void, ConCommandBase*, bool> m_HookLinkConCommandBase;
KHook::Return<void> LinkConCommandBase(ICvar*, ConCommandBase *pBase, bool unknown)
#else
void LinkConCommandBase(ConCommandBase *pBase)
KHook::Virtual<ICvar, void, ConCommandBase*> m_HookLinkConCommandBase;
KHook::Return<void> 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<ICvar, void, ConCommandBase*> m_HookUnlinkConCommandBase;
KHook::Return<void> UnlinkConCommandBase(ICvar*, ConCommandBase *pBase)
{
ConCommandInfo *pInfo;
List<ConCommandInfo *>::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<ConCommandInfo *>::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);
}

View File

@ -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',

View File

@ -233,8 +233,7 @@ AdminCache::~AdminCache()
DumpAdminCache(AdminCache_Overrides, false);
DumpAdminCache(AdminCache_Groups, false);
List<AuthMethod *>::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<AuthMethod *>::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<AuthMethod *>::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<IAdminListener *>::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<AuthMethod *>::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<AuthMethod *>::iterator iter;
for (iter=m_AuthMethods.begin();
for (auto iter=m_AuthMethods.begin();
iter!=m_AuthMethods.end();
iter++)
{

View File

@ -33,16 +33,12 @@
#define _INCLUDE_SOURCEMOD_ADMINCACHE_H_
#include "common_logic.h"
#include <IAdminSystem.h>
#include "sm_hashmap.h"
#include "sm_memtable.h"
#include <sm_trie.h>
#include <sh_list.h>
#include <sh_string.h>
#include "sm_namehashset.h"
#include <IAdminSystem.h>
#include <IForwardSys.h>
#include <sm_hashmap.h>
#include <sm_namehashset.h>
using namespace SourceHook;
#include <list>
#define GRP_MAGIC_SET 0xDEADFADE
#define GRP_MAGIC_UNSET 0xFACEFACE
@ -70,7 +66,7 @@ struct AdminGroup
struct AuthMethod
{
String name;
std::string name;
StringHashMap<AdminId> identities;
AuthMethod(const char *name)
@ -214,8 +210,8 @@ public:
int m_LastGroup;
int m_FreeGroupList;
StringHashMap<GroupId> m_Groups;
List<IAdminListener *> m_hooks;
List<AuthMethod *> m_AuthMethods;
std::list<IAdminListener *> m_hooks;
std::list<AuthMethod *> m_AuthMethods;
NameHashSet<AuthMethod *> m_AuthTables;
IForward *m_pCacheFwd;
int m_FirstUser;

View File

@ -109,10 +109,9 @@ SWThreadHandle *BaseWorker::PopThreadFromQueue()
if (!m_ThreadQueue.size())
return NULL;
SourceHook::List<SWThreadHandle *>::iterator begin;
SWThreadHandle *swt;
begin = m_ThreadQueue.begin();
auto begin = m_ThreadQueue.begin();
swt = (*begin);
m_ThreadQueue.erase(begin);

View File

@ -32,7 +32,7 @@
#ifndef _INCLUDE_SOURCEMOD_BASEWORKER_H
#define _INCLUDE_SOURCEMOD_BASEWORKER_H
#include "sh_list.h"
#include <list>
#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<SWThreadHandle *> m_ThreadQueue;
std::list<SWThreadHandle *> m_ThreadQueue;
unsigned int m_perFrame;
volatile WorkerState m_state;
IThreadWorkerCallbacks *m_pHooks;

View File

@ -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;
}
}

View File

@ -33,9 +33,9 @@
#define _INCLUDE_DATABASE_MANAGER_H_
#include "common_logic.h"
#include <sh_vector.h>
#include <vector>
#include <am-string.h>
#include <sh_list.h>
#include <list>
#include <IThreader.h>
#include <IPluginSys.h>
#include <condition_variable>
@ -46,8 +46,6 @@
#include <am-refcounting.h>
#include "DatabaseConfBuilder.h"
using namespace SourceHook;
class DBManager :
public IDBManager,
@ -98,12 +96,12 @@ private:
void ClearConfigs();
void KillWorkerThread();
private:
CVector<IDBDriver *> m_drivers;
std::vector<IDBDriver *> m_drivers;
/* Threading stuff */
PrioQueue<IDBThreadOperation *> m_OpQueue;
Queue<IDBThreadOperation *> m_ThinkQueue;
CVector<bool> m_drSafety; /* which drivers are safe? */
std::vector<bool> m_drSafety; /* which drivers are safe? */
std::unique_ptr<std::thread> m_Worker;
std::condition_variable m_QueueEvent;
std::mutex m_ThinkLock;

View File

@ -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<IfaceInfo>::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<CExtension *>::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<CExtension *>::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<CExtension *>::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<CExtension *>::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<CPlugin *>(plugin));
}
@ -725,7 +733,7 @@ CExtension *CExtensionManager::FindByOrder(unsigned int num)
return NULL;
}
List<CExtension *>::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<CExtension *> UnloadQueue;
std::list<CExtension *> UnloadQueue;
/* Handle dependencies */
if (pExt->IsLoaded())
{
/* Unload any dependent plugins */
List<CPlugin *>::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<String>::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<CExtension *>::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<IfaceInfo>::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<CExtension *>::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<CExtension *>::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<CExtension *>::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<CExtension *>::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<CPlugin *> plugins;
std::list<CPlugin *> plugins;
if (pExt->m_ChildDeps.size())
{
rootmenu->ConsolePrint("[SM] Unloading %s will unload the following extensions: ", pExt->GetFilename());
List<CExtension *>::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<IfaceInfo>::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<CPlugin *>::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<CPlugin *>::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<CExtension *>::iterator iter = m_Libs.begin();
for (auto iter = m_Libs.begin();
iter != m_Libs.end();
iter++)
{
pExt = (*iter);
for (List<String>::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<CExtension *>::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<CExtension *>::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<IExtension *> *CExtensionManager::ListExtensions()
const std::vector<IExtension *> *CExtensionManager::ListExtensions()
{
CVector<IExtension *> *list = new CVector<IExtension *>();
for (List<CExtension *>::iterator iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
std::vector<IExtension *> *list = new std::vector<IExtension *>();
for (auto iter = m_Libs.begin(); iter != m_Libs.end(); iter++)
list->push_back(*iter);
return list;
}
void CExtensionManager::FreeExtensionList(const CVector<IExtension *> *list)
void CExtensionManager::FreeExtensionList(const std::vector<IExtension *> *list)
{
delete const_cast<CVector<IExtension *> *>(list);
delete const_cast<std::vector<IExtension *> *>(list);
}
bool CLocalExtension::IsSameFile(const char *file)

View File

@ -34,8 +34,8 @@
#include <IExtensionSys.h>
#include <ILibrarySys.h>
#include <sh_list.h>
#include <sh_string.h>
#include <list>
#include <string>
#include "common_logic.h"
#include <IPluginSys.h>
#include <IRootConsoleMenu.h>
@ -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<IfaceInfo> m_Deps; /** Dependencies */
List<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
List<SMInterface *> m_Interfaces;
List<String> m_Libraries;
std::string m_File;
std::string m_RealFile;
std::string m_Path;
std::string m_Error;
std::list<IfaceInfo> m_Deps; /** Dependencies */
std::list<IfaceInfo> m_ChildDeps; /** Children who might depend on us */
std::list<SMInterface *> m_Interfaces;
std::list<std::string> 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<IExtension *> *ListExtensions();
void FreeExtensionList(const CVector<IExtension *> *list);
const std::vector<IExtension *> *ListExtensions();
void FreeExtensionList(const std::vector<IExtension *> *list);
public:
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
void Shutdown();
@ -191,7 +190,7 @@ public:
private:
CExtension *FindByOrder(unsigned int num);
private:
List<CExtension *> m_Libs;
std::list<CExtension *> m_Libs;
};
extern CExtensionManager g_Extensions;

View File

@ -31,8 +31,8 @@
#include <string.h>
#include <stdlib.h>
#include <sstream>
#include <sh_list.h>
#include <sh_string.h>
#include <list>
#include <string>
#include "GameConfigs.h"
#include "stringutil.h"
#include <IGameHelpers.h>
@ -53,8 +53,6 @@
#include <dlfcn.h>
#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<String> *fileList;
std::list<std::string> *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<String> fileList;
std::list<std::string> 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<String>::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))

View File

@ -35,10 +35,8 @@
#include <am-hashmap.h>
#include <memory>
#if defined PLATFORM_LINUX || defined PLATFORM_APPLE
#include <sh_vector.h>
#include <vector>
#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<LibSymbolTable *> m_SymTables;
std::vector<LibSymbolTable *> m_SymTables;
#ifdef PLATFORM_APPLE
struct dyld_all_image_infos *m_ImageList;
SInt32 m_OSXMajor;

View File

@ -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<WeakNative>::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<WeakNative>::iterator iter;
iter = m_WeakRefs.begin();
auto iter = m_WeakRefs.begin();
while (iter != m_WeakRefs.end())
{
WeakNative & ref = (*iter);

View File

@ -32,7 +32,7 @@
#define _INCLUDE_SOURCEMOD_NATIVE_OWNER_H_
#include <sp_vm_types.h>
#include <sh_list.h>
#include <list>
#include <am-vector.h>
#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<CPlugin *> m_Dependents;
std::list<CPlugin *> m_Dependents;
unsigned int m_nMarkSerial;
List<WeakNative> m_WeakRefs;
std::list<WeakNative> m_WeakRefs;
std::vector<const sp_nativeinfo_t *> m_natives;
std::vector<ke::RefPtr<Native> > m_fakes;
};

View File

@ -32,11 +32,9 @@
#ifndef _INCLUDE_SOURCEMOD_PHRASECOLLECTION_H_
#define _INCLUDE_SOURCEMOD_PHRASECOLLECTION_H_
#include <string.h>
#include <sh_vector.h>
#include <vector>
#include <ITranslator.h>
using namespace SourceHook;
using namespace SourceMod;
class CPhraseCollection : public IPhraseCollection
@ -60,7 +58,7 @@ public:
size_t *pOutLength,
const char **pFailPhrase);
private:
CVector<IPhraseFile *> m_Files;
std::vector<IPhraseFile *> m_Files;
};
#endif //_INCLUDE_SOURCEMOD_PHRASECOLLECTION_H_

View File

@ -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<WeakNative>::iterator wk_iter;
/* Tell everyone that depends on us that we're about to drop */
for (List<CPlugin *>::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<void(const char *)> 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<SMPlugin *> *CPluginManager::ListPlugins()
const std::vector<SMPlugin *> *CPluginManager::ListPlugins()
{
CVector<SMPlugin *> *list = new CVector<SMPlugin *>();
std::vector<SMPlugin *> *list = new std::vector<SMPlugin *>();
for (PluginIter iter(m_plugins); !iter.done(); iter.next())
list->push_back((*iter));
@ -2284,9 +2291,9 @@ const CVector<SMPlugin *> *CPluginManager::ListPlugins()
return list;
}
void CPluginManager::FreePluginList(const CVector<SMPlugin *> *list)
void CPluginManager::FreePluginList(const std::vector<SMPlugin *> *list)
{
delete const_cast<CVector<SMPlugin *> *>(list);
delete const_cast<std::vector<SMPlugin *> *>(list);
}
void CPluginManager::ForEachPlugin(ke::Function<void(CPlugin *)> callback)

View File

@ -41,10 +41,10 @@
#include <IPluginSys.h>
#include <IHandleSys.h>
#include <IForwardSys.h>
#include <sh_list.h>
#include <sh_stack.h>
#include <sh_vector.h>
#include <sh_string.h>
#include <list>
#include <stack>
#include <vector>
#include <string>
#include "common_logic.h"
#include <IRootConsoleMenu.h>
#include <sm_hashmap.h>
@ -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<void *> m_Props;
CVector<AutoConfig *> m_configs;
List<String> m_Libraries;
std::vector<AutoConfig *> m_configs;
std::list<std::string> m_Libraries;
bool m_bGotAllLoaded;
int m_FileVersion;
// Information that survives past eviction.
List<String> m_RequiredLibs;
std::list<std::string> 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<SMPlugin *>(PluginFromHandle(hndl, errp));
}
const CVector<SMPlugin *> *ListPlugins();
void FreePluginList(const CVector<SMPlugin *> *plugins);
const std::vector<SMPlugin *> *ListPlugins();
void FreePluginList(const std::vector<SMPlugin *> *plugins);
public: //SMGlobalClass
void OnSourceModAllInitialized();
@ -513,7 +519,7 @@ private:
IdentityToken_t *m_MyIdent;
/* Dynamic native stuff */
List<FakeNative *> m_Natives;
std::list<FakeNative *> m_Natives;
bool m_LoadingLocked;

View File

@ -42,8 +42,7 @@ RootConsoleMenu::RootConsoleMenu()
RootConsoleMenu::~RootConsoleMenu()
{
List<ConsoleEntry *>::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<ConsoleEntry *>::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<ConsoleEntry *>::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 <command> [arguments]");
List<ConsoleEntry *>::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());

View File

@ -28,18 +28,17 @@
#define _INCLUDE_SOURCEMOD_ROOT_CONSOLE_MENU_IMPL_H_
#include "common_logic.h"
#include "sm_namehashset.h"
#include <IRootConsoleMenu.h>
#include <sh_list.h>
#include <sh_string.h>
#include <sm_namehashset.h>
#include <string>
#include <list>
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<ConsoleEntry *> m_Commands;
List<ConsoleEntry *> m_Menu;
std::list<ConsoleEntry *> m_Menu;
};
extern RootConsoleMenu g_RootMenu;

View File

@ -232,7 +232,7 @@ void ShareSystem::DestroyIdentType(IdentityType_t type)
void ShareSystem::RemoveInterfaces(IExtension *pExtension)
{
List<IfaceInfo>::iterator iter = m_Interfaces.begin();
auto iter = m_Interfaces.begin();
while (iter != m_Interfaces.end())
{

View File

@ -37,14 +37,12 @@
#include <am-string.h>
#include <am-utility.h>
#include <am-refcounting.h>
#include <sh_list.h>
#include <list>
#include <sm_hashmap.h>
#include <sm_namehashset.h>
#include "common_logic.h"
#include "Native.h"
using namespace SourceHook;
namespace SourceMod
{
struct IdentityToken_t
@ -133,7 +131,7 @@ private:
private:
typedef NameHashSet<ke::RefPtr<Native>, Native> NativeCache;
List<IfaceInfo> m_Interfaces;
std::list<IfaceInfo> m_Interfaces;
HandleType_t m_TypeRoot;
IdentityToken_t m_IdentRoot;
HandleType_t m_IfaceType;

View File

@ -34,17 +34,16 @@
#include "common_logic.h"
#include <sm_hashmap.h>
#include <sh_string.h>
#include <sh_vector.h>
#include "sm_memtable.h"
#include "ITextParsers.h"
#include <ITranslator.h>
#include "PhraseCollection.h"
#include <vector>
#include <string>
/* :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<int> 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<Language *> m_Languages;
CVector<CPhraseFile *> m_Files;
std::vector<Language *> m_Languages;
std::vector<CPhraseFile *> m_Files;
BaseStringTable *m_pStringTab;
StringHashMap<unsigned int> m_LCodeLookup;
StringHashMap<unsigned int> m_LAliases;
bool m_InLanguageSection;
String m_CustomError;
std::string m_CustomError;
unsigned int m_ServerLang;
char m_InitialLang[4];
};

View File

@ -35,6 +35,7 @@
#include <iomanip>
#include <sstream>
#include <list>
#include <vector>
#include "common_logic.h"
#include "Logger.h"
@ -43,9 +44,6 @@
#include <DebugReporter.h>
#include <FrameIterator.h>
#include <sourcehook.h>
#include <sh_memory.h>
#if defined PLATFORM_WINDOWS
#include <windows.h>
#include "sm_invalidparamhandler.h"
@ -54,12 +52,12 @@
#include <unistd.h>
#include <sys/times.h>
#endif
#include <khook/memory.hpp>
#include <IForwardSys.h>
#include <ILibrarySys.h>
#include <bridge/include/CoreProvider.h>
#include <bridge/include/IScriptManager.h>
#include <bridge/include/IExtensionBridge.h>
#include <sh_vector.h>
using namespace SourceMod;
using namespace SourcePawn;
@ -128,7 +126,7 @@ class CMMPluginIterator
public IPluginsListener
{
public:
CMMPluginIterator(const CVector<SMPlugin *> *list)
CMMPluginIterator(const std::vector<SMPlugin *> *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<uint8_t*>(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<uint16_t*>(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<uint32_t*>(addr) = data;
break;

View File

@ -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;

View File

@ -29,16 +29,12 @@
* Version: $Id$
*/
#include <sh_list.h>
#include <sh_string.h>
#include <ISourceMod.h>
#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;

View File

@ -29,7 +29,7 @@
* Version: $Id$
*/
#include <sh_list.h>
#include <list>
#include <sm_namehashset.h>
#include "common_logic.h"
#include "CellArray.h"
@ -42,8 +42,6 @@
#include <bridge/include/ILogger.h>
#include <bridge/include/IFileSystemBridge.h>
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<maplist_info_t *> compat;
std::list<maplist_info_t *> 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<maplist_info_t *>::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<maplist_info_t *> *compat_list)
void DumpCache(std::list<maplist_info_t *> *compat_list)
{
m_ListLookup.clear();
List<maplist_info_t *>::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<maplist_info_t *> m_ListLookup;
List<maplist_info_t *> m_MapLists;
std::list<maplist_info_t *> m_MapLists;
MapListState m_CurState;
unsigned int m_IgnoreLevel;
maplist_info_t *m_pCurMapList;

View File

@ -30,7 +30,6 @@
*/
#include "common_logic.h"
#include <sh_stack.h>
#include <IMenuManager.h>
#include <IPlayerHelpers.h>
#include "DebugReporter.h"
@ -40,6 +39,8 @@
#include <ISourceMod.h>
#include <stdlib.h>
#include <bridge/include/IScriptManager.h>
#include <stack>
#include <list>
#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<CPanelHandler *> m_FreePanelHandlers;
CStack<CMenuHandler *> m_FreeMenuHandlers;
CVector<CPanelHandler *> m_PanelHandlers;
std::stack<CPanelHandler *> m_FreePanelHandlers;
std::stack<CMenuHandler *> m_FreeMenuHandlers;
std::list<CPanelHandler *> m_PanelHandlers;
} g_MenuHelpers;
/**

View File

@ -35,8 +35,8 @@
#include <IGameHelpers.h>
#include <ISourceMod.h>
#include <ITranslator.h>
#include <sh_string.h>
#include <sh_list.h>
#include <string>
#include <list>
#include "GameConfigs.h"
#include "CellArray.h"
#include "AutoHandleRooter.h"
@ -46,7 +46,6 @@
#include <bridge/include/CoreProvider.h>
#include <bridge/include/IVEngineServerBridge.h>
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<SimpleMultiTargetFilter *> simpleMultis;
std::list<SimpleMultiTargetFilter *> simpleMultis;
bool filterEnabled;
public:
@ -107,7 +106,7 @@ public:
void RemoveMultiTargetFilter(const char *pattern, IPluginFunction *fun)
{
List<SimpleMultiTargetFilter *>::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<SimpleMultiTargetFilter *>::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<SimpleMultiTargetFilter *>::iterator iter = simpleMultis.begin();
auto iter = simpleMultis.begin();
while (iter != simpleMultis.end()) {
if ((*iter)->plugin != plugin) {

View File

@ -34,12 +34,10 @@
#include <IHandleSys.h>
#include <ITimerSystem.h>
#include <IPluginSys.h>
#include <sh_stack.h>
#include <stack>
#include "DebugReporter.h"
#include <bridge/include/CoreProvider.h>
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<TimerInfo *> m_FreeTimers;
std::stack<TimerInfo *> m_FreeTimers;
};
TimerNatives::~TimerNatives()
{
CStack<TimerInfo *>::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();
}

View File

@ -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()

View File

@ -79,7 +79,7 @@ HandleType_t htConCmdIter = 0;
struct GlobCmdIter
{
bool started;
List<ConCmdInfo *>::iterator iter;
std::list<ConCmdInfo *>::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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
std::list<ConCmdInfo *>& cmds = const_cast<decltype(cmds)>(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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
std::list<ConCmdInfo *>& cmds = const_cast<decltype(cmds)>(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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
const std::list<ConCmdInfo *> &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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
const std::list<ConCmdInfo *> &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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
const std::list<ConCmdInfo *> &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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
const std::list<ConCmdInfo *> &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<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
const std::list<ConCmdInfo *> &cmds = g_ConCmds.GetCommandList();
if (!iter->started || iter->iter == cmds.end())
{
return pContext->ThrowNativeError("Invalid CommandIterator position");

View File

@ -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;

View File

@ -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;
}

View File

@ -33,7 +33,7 @@
#define _INCLUDE_SOURCEMOD_KVWRAPPER_H_
#include <IHandleSys.h>
#include <sh_stack.h>
#include <deque>
using namespace SourceMod;
@ -42,7 +42,7 @@ class KeyValues;
struct KeyValueStack
{
KeyValues *pBase;
SourceHook::CStack<KeyValues *> pCurRoot;
std::deque<KeyValues *> pCurRoot;
bool m_bDeleteOnDestroy = true;
};

View File

@ -79,8 +79,7 @@ static cell_t sm_GetMapHistory(IPluginContext *pCtx, const cell_t *params)
return pCtx->ThrowNativeError("Invalid Map History Index");
}
SourceHook::List<MapChangeData *>::iterator iter;
iter = g_NextMap.m_mapHistory.end();
auto iter = g_NextMap.m_mapHistory.end();
iter--;
for (int i=0; i<params[1]; i++)

View File

@ -51,8 +51,8 @@ bf_read g_ReadBitBuf;
int g_MsgPlayers[SM_MAXPLAYERS+1];
bool g_IsMsgInExec = false;
typedef List<MsgListenerWrapper *> MsgWrapperList;
typedef List<MsgListenerWrapper *>::iterator MsgWrapperIter;
typedef std::list<MsgListenerWrapper *> 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<MsgListenerWrapper *> m_FreeListeners;
std::stack<MsgListenerWrapper *> m_FreeListeners;
};
UsrMessageNatives::~UsrMessageNatives()
{
CStack<MsgListenerWrapper *>::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<void **>(&pList)))
{
pList = new List<MsgListenerWrapper *>;
pList = new std::list<MsgListenerWrapper *>;
pl->SetProperty("MsgListeners", pList);
}

View File

@ -48,8 +48,6 @@ ISmmPluginManager *g_pMMPlugins = NULL;
CGlobalVars *gpGlobals = NULL;
ICvar *icvar = NULL;
IGameEventManager2 *gameevents = NULL;
CallClass<IVEngineServer> *enginePatch = NULL;
CallClass<IServerGameDLL> *gamedllPatch = NULL;
IPlayerInfoManager *playerinfo = NULL;
IBaseFileSystem *basefilesystem = NULL;
IFileSystem *filesystem = NULL;

View File

@ -40,6 +40,7 @@
#include <filesystem.h>
#include <IEngineSound.h>
#include <toolframework/itoolentity.h>
#include <khook.hpp>
/**
* @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<IVEngineServer> *enginePatch;
extern SourceHook::CallClass<IServerGameDLL> *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_

View File

@ -32,7 +32,7 @@
#include <stdio.h>
#include "sourcemod.h"
#include "sourcemm_api.h"
#include <sh_string.h>
#include <string>
#include "CoreConfig.h"
#include "Logger.h"
#include "sm_stringutil.h"
@ -49,17 +49,12 @@
#include <bridge/include/IProviderCallbacks.h>
#include <bridge/include/ILogger.h>
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<ke::SharedLib> 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<void> SourceModBase::Hook_GameFrame(IServerGameDLL*, bool simulating)
{
g_Timers.GameFrame(simulating);
return { KHook::Action::Ignore };
}
KHook::Return<void> 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<bool> 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<bool>{KHook::Action::Override, true}, (pMapName, logicore.GetEntityLumpString(), pOldLevel, pLandmarkName, loadGame, background));
}
const char *SourceModBase::GetMapEntitiesString()
KHook::Return<const char*> 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<void> 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;
}

View File

@ -34,10 +34,9 @@
#include "sm_globals.h"
#include <ISourceMod.h>
#include <sh_stack.h>
#include <sh_vector.h>
using namespace SourceHook;
#include <stack>
#include <vector>
#include <khook.hpp>
#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<GAME_FRAME_HOOK> m_frame_hooks;
std::vector<GAME_FRAME_HOOK> m_frame_hooks;
protected:
KHook::Virtual<class IServerGameDLL, bool, const char *, const char *, const char *, const char *, bool, bool> m_HookLevelInit;
KHook::Return<bool> Hook_LevelInit(class IServerGameDLL*, char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background);
KHook::Virtual<class IServerGameDLL, void> m_HookLevelShutdown;
KHook::Return<void> Hook_LevelShutdown(class IServerGameDLL*);
KHook::Virtual<class IServerGameDLL, void, bool> m_HookGameFrame;
KHook::Return<void> Hook_GameFrame(class IServerGameDLL*, bool);
KHook::Virtual<class IServerGameDLL, void, bool> m_HookThink;
KHook::Return<void> Hook_Think(class IServerGameDLL*, bool);
KHook::Virtual<class IVEngineServer, const char*> m_HookGetMapEntitiesString;
KHook::Return<const char*> Hook_GetMapEntitiesString(class IVEngineServer*);
};
void UTIL_ConsolePrintVa(const char *fmt, va_list ap);

View File

@ -34,9 +34,7 @@
#include <new>
#include <stdlib.h>
#include <sh_stack.h>
using namespace SourceHook;
#include <stack>
/*
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<QueueNode *> m_FreeNodes;
std::stack<QueueNode *> m_FreeNodes;
public:
class iterator
{