Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
9f6e084
Remove SourceHook from core
Kenzzer Aug 17, 2025
d80d5ed
Remove CDetour
Kenzzer Aug 17, 2025
82c4206
Add guard rails around Recalls
Kenzzer Aug 17, 2025
8aee4da
Fix compilation
Kenzzer Aug 17, 2025
db68bbc
Strip sourcehook from bintools
Kenzzer Aug 17, 2025
eaac3da
Strip sourcehook from clientprefs
Kenzzer Aug 17, 2025
c9937e0
Strip sourcehook from PGSQL
Kenzzer Aug 17, 2025
f10313b
Strip sourcehook from SQLite
Kenzzer Aug 17, 2025
6c58664
Strip sourcehook from Regex
Kenzzer Aug 17, 2025
55508aa
Strip sourcehook from Updater
Kenzzer Aug 17, 2025
47ad591
Re-enable compilation for GeoIP & Curl
Kenzzer Aug 17, 2025
5b5bc08
Strip sourcehook from SDKHooks
Kenzzer Aug 18, 2025
8622c59
Remove Safetyhook(CDetour)
Kenzzer Aug 18, 2025
a96290c
Strip sourcehook from SDKTools Part 1
Kenzzer Aug 18, 2025
417f346
Strip sourcehook from SDKTools
Kenzzer Aug 19, 2025
a830a11
Remove unnecessary includes to SDKTools
Kenzzer Aug 19, 2025
c47fea0
Blow up dhooks
Kenzzer Aug 19, 2025
3c49ecb
Begin re-impl of dhooks
Kenzzer Sep 18, 2025
cd41c10
Implement basic callback logic
Kenzzer Sep 18, 2025
1241c8b
Add recall support
Kenzzer Sep 19, 2025
dcbc54b
Implem DHookReturn
Kenzzer Sep 19, 2025
d2e2583
Finish DHookParam implem
Kenzzer Sep 19, 2025
9017a56
Move dhookparam/return natives to its own file
Kenzzer Sep 19, 2025
09d98e9
Add gamedata parser
Kenzzer Sep 28, 2025
ebd7b51
use the new khook functions
Kenzzer Feb 1, 2026
86e42e4
Add/update dhook handles
Kenzzer Feb 1, 2026
2b6244c
Reconcile with master rebase
Kenzzer Feb 1, 2026
b52dd5a
Progress towards DynamicDetour
Kenzzer Feb 3, 2026
12fdd41
Start work on DynamicDetour.Enable
Kenzzer Feb 5, 2026
70466e9
Finalise DynamicDetour natives
Kenzzer Feb 7, 2026
632b785
Define remaining undefined symbols
Kenzzer Feb 21, 2026
dde733f
Add missing functions to bintools
Kenzzer Feb 24, 2026
6385361
Strip SourceHook from topmenus
Kenzzer Feb 24, 2026
73ccda4
Fix dhooks loading
Kenzzer Feb 24, 2026
70df0f5
Strip SourceHook from game.tf2
Kenzzer Feb 25, 2026
657b3fd
Update metamod dependency for CI
Kenzzer Feb 26, 2026
569323a
Fix invalid hook name on CSS/CSGO
Kenzzer Feb 26, 2026
a0373be
Fix initialising order
Kenzzer Feb 25, 2026
a8b8972
Fix wrong vtable offset calculation in bintools
Kenzzer Mar 1, 2026
8ca8822
Default init addr to nullptr
Kenzzer Mar 1, 2026
365c2e3
Fix SDKHooks not fireing
Kenzzer Mar 1, 2026
a893d45
Enable dhooks natives
Kenzzer Mar 1, 2026
10e10e6
Fix this ptr crash in Dynamic Detour & make call original
Kenzzer Mar 1, 2026
9560f3a
Update hl2sdk-manifests
Kenzzer Mar 7, 2026
a6e1603
Start implementing DynamicHook natives
Kenzzer Mar 7, 2026
44e80c6
Limit dhooks compilation to linux x64 for now
Kenzzer Mar 7, 2026
a564d02
Fix var name error in PlayerManager.cpp
Kenzzer Mar 7, 2026
a1a0769
Remove detour callbacks on dynamicdetour deletion
Kenzzer Mar 7, 2026
9139e54
Finalise DynamicHook natives
Kenzzer Mar 7, 2026
32fc9e9
DHooks: Add support for void return on System V x64
Kenzzer Mar 9, 2026
d59b189
DHooks: Allow registration of DynamicHooks
Kenzzer Mar 9, 2026
af994d8
DHooks: Add automatic virtual hook cleanup
Kenzzer Mar 9, 2026
400b2ac
DHooks: Skip some unnecessary steps in hook cleanup
Kenzzer Mar 9, 2026
864d3a6
Make checkout-deps update submodules if they exist
Kenzzer Mar 11, 2026
a5e34c3
Update with latest khook changes
Kenzzer Mar 11, 2026
f6184f1
Make mock compile against khook branch of metamod
Kenzzer Mar 11, 2026
42f1ab2
Correct hook function name for pre-orangebox games
Kenzzer Mar 11, 2026
ca04979
Correct SDKHooks::Hook_GetGameDescription
Kenzzer Mar 11, 2026
c23a9cf
Strip remaining of sourcehook
Kenzzer Mar 12, 2026
56f811c
Fix compilation for l4d2 & csgo
Kenzzer Mar 12, 2026
5eb1b37
Fix incorrect dhook callback removal
Kenzzer Mar 14, 2026
34d1fed
Push int64 Address under dhook callbacks
Kenzzer Mar 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
DEPENDENCIES_FOLDER: dependencies
DEPENDENCIES_ROOT: ${{ github.workspace }}/dependencies
MYSQL_VERSION: '5.7'
MMSOURCE_VERSION: '1.12'
MMSOURCE_VERSION: '2.0'
steps:
- uses: actions/checkout@v6
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/mocktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
name: Clone metamod-source
with:
repository: alliedmodders/metamod-source
ref: k/sourcehook_alternative
submodules: recursive
path: metamod-source

Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
[submodule "hl2sdk-manifests"]
path = hl2sdk-manifests
url = https://github.com/alliedmodders/hl2sdk-manifests.git
[submodule "public/safetyhook"]
path = public/safetyhook
url = https://github.com/alliedmodders/safetyhook
[submodule "core/logic/libaddrz"]
path = core/logic/libaddrz
url = https://github.com/dvander/libaddrz.git
38 changes: 8 additions & 30 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class SMConfig(object):
self.target_archs = set()
self.enable_asan = getattr(builder.options, 'enable_asan', False)
self.asan_libs = {}
self.libsafetyhook = {}

if builder.options.targets:
target_archs = builder.options.targets.split(',')
Expand Down Expand Up @@ -128,7 +127,7 @@ class SMConfig(object):
if builder.options.mms_path:
self.mms_root = builder.options.mms_path
else:
self.mms_root = ResolveEnvPath('MMSOURCE112', 'mmsource-1.12')
self.mms_root = ResolveEnvPath('MMSOURCE200', 'mmsource-2.0')
if not self.mms_root:
self.mms_root = ResolveEnvPath('MMSOURCE', 'metamod-source')
if not self.mms_root:
Expand Down Expand Up @@ -499,6 +498,11 @@ class SMConfig(object):
os.path.join(builder.sourcePath, 'public', 'amtl', 'amtl'),
os.path.join(builder.sourcePath, 'public', 'amtl'),
]

compiler.cxxincludes += [
os.path.join(self.mms_root, 'core'),
os.path.join(self.mms_root, 'third_party', 'khook', 'include'),
]
return compiler

def ExtLibrary(self, context, compiler, name):
Expand All @@ -517,29 +521,13 @@ class SMConfig(object):
compiler = binary.compiler
SetArchFlags(compiler)

compiler.cxxincludes += [
os.path.join(self.mms_root, 'core'),
os.path.join(self.mms_root, 'core', 'sourcehook'),
]

for other_sdk in self.sdk_manifests:
compiler.defines += ['SE_{}={}'.format(other_sdk['define'], other_sdk['code'])]

SdkHelpers.configureCxx(context, binary, sdk)

return binary

def AddCDetour(self, binary):
public_path = os.path.join(builder.sourcePath, 'public')
binary.sources += [ os.path.join(public_path, 'CDetour', 'detours.cpp') ]
binary.compiler.cxxincludes += [ os.path.join(public_path, 'safetyhook', 'include') ]

for task in self.libsafetyhook:
if task.target.arch == binary.compiler.target.arch:
binary.compiler.linkflags += [task.binary]
return
raise Exception('No suitable build of safetyhook was found.')

def HL2Library(self, context, compiler, name, sdk):
binary = self.Library(context, compiler, name)
self.ConfigureForExtension(context, binary.compiler)
Expand Down Expand Up @@ -588,16 +576,6 @@ if SM.use_auto_versioning():
{ 'SM': SM }
)

class SafetyHookShim(object):
def __init__(self):
self.all_targets = {}
self.libsafetyhook = {}

SafetyHook = SafetyHookShim()
SafetyHook.all_targets = SM.all_targets
builder.Build('public/safetyhook/AMBuilder', {'SafetyHook': SafetyHook })
SM.libsafetyhook = SafetyHook.libsafetyhook

class SPRoot(object):
def __init__(self):
self.generated_headers = SM.generated_headers
Expand Down Expand Up @@ -666,10 +644,10 @@ else:
'extensions/bintools/AMBuilder',
'extensions/clientprefs/AMBuilder',
'extensions/curl/AMBuilder',
'extensions/cstrike/AMBuilder',
#'extensions/cstrike/AMBuilder',
'extensions/dhooks/AMBuilder',
'extensions/geoip/AMBuilder',
'extensions/mysql/AMBuilder',
#'extensions/mysql/AMBuilder',
'extensions/pgsql/AMBuilder',
'extensions/regex/AMBuilder',
'extensions/sdkhooks/AMBuilder',
Expand Down
11 changes: 5 additions & 6 deletions bridge/include/IExtensionBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -51,8 +50,8 @@ class IExtensionSys : public IExtensionManager
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;
};

Expand All @@ -67,13 +66,13 @@ class AutoExtensionList
{
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
Expand Down
17 changes: 8 additions & 9 deletions bridge/include/IScriptManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -47,8 +46,8 @@ enum LibraryAction

struct AutoConfig
{
SourceHook::String autocfg;
SourceHook::String folder;
std::string autocfg;
std::string folder;
bool create;
};

Expand Down Expand Up @@ -82,8 +81,8 @@ class IScriptManager
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;
};

Expand All @@ -98,13 +97,13 @@ class AutoPluginList
{
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
Expand Down
2 changes: 1 addition & 1 deletion core/ConCmdManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 4 additions & 6 deletions core/ConCmdManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -137,7 +135,7 @@ struct ConCmdInfo
};
};

typedef List<ConCmdInfo *> ConCmdList;
typedef std::list<ConCmdInfo *> ConCmdList;

class ConCmdManager :
public SMGlobalClass,
Expand Down Expand Up @@ -180,7 +178,7 @@ class ConCmdManager :
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;
}
Expand Down
34 changes: 21 additions & 13 deletions core/ConVarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading
Loading