Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
30aac9c
Introduce KHook
Kenzzer Apr 17, 2025
e18ef8e
Fix incorrect submodule
Kenzzer Apr 17, 2025
af194b7
Add khooks to source 2 provider
Kenzzer Apr 19, 2025
b44c40b
update khook
Kenzzer Apr 19, 2025
edbbaae
Fix provider_source_console & dota2 compilation
Kenzzer Apr 19, 2025
1496109
expose khook to plugins
Kenzzer Apr 23, 2025
43dbf7f
Fix errors from rebase
Kenzzer Apr 23, 2025
209551a
update submodule
Kenzzer Apr 23, 2025
c7c432f
move submodule to third_party directory
Kenzzer Apr 29, 2025
5d6bc15
update submodule to latest commit
Kenzzer Apr 29, 2025
c531ad8
Fix submodule name + fix invalid function call
Kenzzer Apr 29, 2025
3292bb8
Fix const-ness issue, and stabilise virtual function api
Kenzzer Apr 29, 2025
53ffcc9
update submodule
Kenzzer Apr 29, 2025
f35f977
Fix erroneous definition for khook global var
Kenzzer Apr 29, 2025
0117b9a
Slow down metamod load + fix memory flags
Kenzzer Aug 14, 2025
b8d39b4
Fix deadlock + Fix crash on x86
Kenzzer Aug 14, 2025
a7489d7
Re-allow metamod to load fast
Kenzzer Aug 14, 2025
1c21904
Update sample extension to use khook
Kenzzer Aug 15, 2025
61cac47
Fix another deadlock
Kenzzer Aug 15, 2025
82d2c9b
Update s2 sample extension to khook
Kenzzer Aug 15, 2025
869b003
Supercede -> Supersede + Call original helper
Kenzzer Aug 15, 2025
f3d5252
Make gamedll bridge more legible
Kenzzer Aug 15, 2025
8bc2503
Fix hook callback mistake + fix s2 sample compilation
Kenzzer Aug 15, 2025
1871039
Add Hook recall feature
Kenzzer Aug 16, 2025
782ff5c
Add Recall feature to x86
Kenzzer Aug 17, 2025
aae2a67
Add thread safety to return value
Kenzzer Aug 27, 2025
26ca52f
Remove GetHookAction
Kenzzer Aug 27, 2025
3eec27f
Bump khook submodule
Kenzzer Jan 28, 2026
a11ff6d
Supersede
Kenzzer Jan 28, 2026
847f80b
Use real global virtual hook
Kenzzer Jan 28, 2026
adf1847
Fix incorrect __exported__khook declaration
Kenzzer Feb 24, 2026
8d3da59
Update khook submodule
Kenzzer Feb 24, 2026
04b6999
Update khook submodule
Kenzzer Mar 7, 2026
e87794b
Bump khook submodule
Kenzzer Mar 11, 2026
b6878fb
Make KHook::CallOriginal & KHook::Recall super strict
Kenzzer Mar 11, 2026
a86701c
Simplify CallOriginal, Recall & GetVtableIndex
Kenzzer Mar 12, 2026
0d28392
Bump KHook
Kenzzer Apr 12, 2026
469ea72
Adapt new changes to khook
Kenzzer Jun 1, 2026
b1ff9a6
Disable SH testing
Kenzzer Jun 1, 2026
f49ccd9
Only allow LevelInit to fire once
Kenzzer Jun 1, 2026
4a76da5
Bump KHook
Kenzzer Jun 1, 2026
fc9ee7a
Bump khook
Kenzzer Jun 4, 2026
5a7ea46
Fix stack size calculation on windows x86_64
Kenzzer Jun 4, 2026
ba910bc
Added KHook::LookupSignature
Kenzzer Jun 20, 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
36 changes: 1 addition & 35 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,4 @@ jobs:
--enable-optimize \
--sdks=${{ join(fromJSON(env.SDKS), ',') }} \
'--hl2sdk-root=${{ steps.path_helper.outputs.dependencies }}'
ambuild

- name: Test SourceHook (Optimized)
working-directory: metamod-source
shell: bash
# SourceHook tests are busted on Windows
continue-on-error: ${{ startsWith(runner.os, 'Windows') }}
run: |
mkdir build-sh-opt && cd build-sh-opt
python3 ../configure.py --enable-optimize --enable-tests --sdks=
ambuild
cd ./core/sourcehook/test/test_sourcehook
if [ -d "${{ matrix.os_short }}-x86" ]; then
./${{ matrix.os_short }}-x86/test_sourcehook -v
fi
if [ -d "${{ matrix.os_short }}-x86_64" ]; then
./${{ matrix.os_short }}-x86_64/test_sourcehook -v
fi

- name: Test SourceHook (Debug)
working-directory: metamod-source
shell: bash
# SourceHook tests are busted on Windows
continue-on-error: ${{ startsWith(runner.os, 'Windows') }}
run: |
mkdir build-sh-debug && cd build-sh-debug
python3 ../configure.py --enable-debug --enable-tests --sdks=
ambuild
cd ./core/sourcehook/test/test_sourcehook
if [ -d "${{ matrix.os_short }}-x86" ]; then
./${{ matrix.os_short }}-x86/test_sourcehook -v
fi
if [ -d "${{ matrix.os_short }}-x86_64" ]; then
./${{ matrix.os_short }}-x86_64/test_sourcehook -v
fi
ambuild
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "hl2sdk-manifests"]
path = hl2sdk-manifests
url = https://github.com/alliedmodders/hl2sdk-manifests
[submodule "third_party/khook"]
path = third_party/khook
url = https://github.com/Kenzzer/KHook
5 changes: 3 additions & 2 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class MMSConfig(object):
self.versionlib = None
self.all_targets = []
self.target_archs = set()
self.libsafetyhook = {}
self.libkhook = {}

if builder.options.targets:
target_archs = builder.options.targets.split(',')
Expand Down Expand Up @@ -325,7 +327,6 @@ class MMSConfig(object):

cxx.cxxincludes += [
os.path.join(context.currentSourcePath),
os.path.join(context.currentSourcePath, 'sourcehook'),
os.path.join(context.sourcePath, 'loader'),
]

Expand Down Expand Up @@ -370,7 +371,6 @@ BuildScripts = [
]
if getattr(builder.options, 'enable_tests', False):
BuildScripts += [
'core/sourcehook/test/AMBuilder',
'loader/test/AMBuilder',
]

Expand All @@ -379,6 +379,7 @@ if builder.backend == 'amb2':
'support/buildbot/PackageScript',
]

builder.Build(['third_party/khook/AMBuilder', 'third_party/khook/third_party/safetyhook/AMBuilder'], { 'KHook': MMS, 'SafetyHook': MMS })
builder.Build(BuildScripts, { 'MMS': MMS })

if builder.options.breakpad_dump:
Expand Down
20 changes: 9 additions & 11 deletions core/AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ for sdk_target in MMS.sdk_targets:

name = 'metamod.' + sdk['extension']
binary = MMS.HL2Library(builder, cxx, name, sdk)
binary.compiler.cxxincludes += [os.path.join(builder.sourcePath, 'third_party', 'khook', 'include')]

binary.compiler.defines += ['KHOOK_STANDALONE', 'KHOOK_EXPORT']
for task in MMS.libkhook:
if task.target.arch == binary.compiler.target.arch:
binary.compiler.linkflags += [task.binary]
for task in MMS.libsafetyhook:
if task.target.arch == binary.compiler.target.arch:
binary.compiler.linkflags += [task.binary]

binary.sources += [
'metamod.cpp',
Expand All @@ -15,12 +24,6 @@ for sdk_target in MMS.sdk_targets:
'metamod_plugins.cpp',
'metamod_util.cpp',
'provider/provider_base.cpp',
'sourcehook/sourcehook.cpp',
'sourcehook/sourcehook_impl_chookidman.cpp',
'sourcehook/sourcehook_impl_chookmaninfo.cpp',
'sourcehook/sourcehook_impl_cproto.cpp',
'sourcehook/sourcehook_impl_cvfnptr.cpp',
'sourcehook/sourcehook_hookmangen.cpp',
'gamedll_bridge.cpp'
]

Expand All @@ -38,10 +41,5 @@ for sdk_target in MMS.sdk_targets:
'vsp_bridge.cpp'
]
binary.compiler.defines += ['_ALLOW_KEYWORD_MACROS']

if cxx.target.arch == 'x86':
binary.sources += ['sourcehook/sourcehook_hookmangen_x86.cpp']
elif binary.compiler.target.arch == 'x86_64' and binary.compiler.target.platform != 'linux':
binary.sources += ['sourcehook/sourcehook_hookmangen_x86_64.cpp']
nodes = builder.Add(binary)
MMS.binaries += [nodes]
13 changes: 2 additions & 11 deletions core/ISmmAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

#include <cstdarg>

#include "sourcehook.h"
#include "IPluginManager.h"

#if defined META_NO_HL2SDK
Expand All @@ -57,6 +56,7 @@ typedef ConCommandBase ProviderConCommand;
#endif
#endif

#define MMIFACE_KHOOK "IKHook" /**< IKHook Pointer */
#define MMIFACE_SOURCEHOOK "ISourceHook" /**< ISourceHook Pointer */
#define MMIFACE_PLMANAGER "IPluginManager" /**< SourceMM Plugin Functions */
#define MMIFACE_SH_HOOKMANAUTOGEN "IHookManagerAutoGen" /**< SourceHook::IHookManagerAutoGen Pointer */
Expand Down Expand Up @@ -189,14 +189,6 @@ namespace SourceMM
*/
virtual void GetApiVersions(int &major, int &minor, int &plvers, int &plmin) =0;

/**
* @brief Returns sourcehook API version and implementation version.
*
* @param shvers Filled with the SourceHook API version number.
* @param shimpl Filled with the SourceHook implementation number.
*/
virtual void GetShVersions(int &shvers, int &shimpl) =0;

/**
* @brief Adds a Metamod listener.
*
Expand Down Expand Up @@ -467,5 +459,4 @@ using namespace SourceMM;
* 1.6.0 Added API for Orange Box. Broke backwards compatibility.
*/

#endif //_INCLUDE_ISMM_API_H

#endif //_INCLUDE_ISMM_API_H
8 changes: 4 additions & 4 deletions core/ISmmPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* The pure-virtual ISmmPlugin callbacks must be implemented for the load to load.
*/

#include "sourcehook.h"
#include "IPluginManager.h"
#include "ISmmAPI.h"
#include "ISmmPluginExt.h"
Expand Down Expand Up @@ -487,11 +486,12 @@ using namespace SourceMM;
#define PL_EXPOSURE_FUNC(name, var) EXPOSE_SINGLE_INTERFACE_GLOBALVAR(ISmmPlugin, ISmmPlugin, METAMOD_PLAPI_NAME, var);
#endif

#include "khook.hpp"
#define PLUGIN_EXPOSE(name, var) \
ISmmAPI *g_SMAPI = NULL; \
ISmmPlugin *g_PLAPI = NULL; \
PluginId g_PLID = (PluginId)0; \
SourceHook::ISourceHook *g_SHPtr = NULL; \
namespace KHook { KHook::IKHook* __exported__khook = nullptr; } \
PL_EXPOSURE_FUNC(name, var)


Expand All @@ -503,7 +503,7 @@ using namespace SourceMM;
* to use values like g_SHPtr in other files.
*/
#define PLUGIN_GLOBALVARS() \
extern SourceHook::ISourceHook *g_SHPtr; \
namespace KHook { extern KHook::IKHook* __exported__khook; } \
extern ISmmAPI *g_SMAPI; \
extern ISmmPlugin *g_PLAPI; \
extern PluginId g_PLID;
Expand All @@ -513,7 +513,7 @@ using namespace SourceMM;
*/
#define PLUGIN_SAVEVARS() \
g_SMAPI = ismm; \
g_SHPtr = static_cast<SourceHook::ISourceHook *>(ismm->MetaFactory(MMIFACE_SOURCEHOOK, NULL, NULL)); \
KHook::__exported__khook = static_cast<KHook::IKHook*>(ismm->MetaFactory(MMIFACE_KHOOK, nullptr, nullptr)); \
g_PLAPI = static_cast<ISmmPlugin *>(this); \
g_PLID = id;

Expand Down
2 changes: 0 additions & 2 deletions core/ISmmPluginExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ struct MetamodVersionInfo
{
int api_major; /**< ISmmAPI major version */
int api_minor; /**< ISmmAPI minor version */
int sh_iface; /**< SourceHook interface version */
int sh_impl; /**< SourceHook implementation version */
int pl_min; /**< Plugin API minimum version */
int pl_max; /**< Plugin API maximum version */
int source_engine; /**< Source Engine version (SOURCE_* constants) */
Expand Down
14 changes: 5 additions & 9 deletions core/gamedll_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "metamod_util.h"
#include "loader_bridge.h"
#include "provider/provider_base.h"
#include "khook.hpp"

using namespace SourceMM;

Expand Down Expand Up @@ -62,18 +63,13 @@ class GameDllBridge : public IGameDllBridge
}
virtual void DLLInit_Post(int *isgdUnload)
{
SourceHook::MemFuncInfo mfi;

mfi.isVirtual = false;
#ifdef META_IS_SOURCE2
SourceHook::GetFuncInfo(&ISource2ServerConfig::Disconnect, mfi);
auto mfi = KHook::GetVtableIndex(&ISource2ServerConfig::Disconnect);
#else
SourceHook::GetFuncInfo(&IServerGameDLL::DLLShutdown, mfi);
auto mfi = KHook::GetVtableIndex(&IServerGameDLL::DLLShutdown);
#endif
assert(mfi.isVirtual);
assert(mfi.vtbloffs == 0);
assert(mfi.thisptroffs == 0);
*isgdUnload = mfi.vtblindex;
assert(mfi != -1);
*isgdUnload = mfi;

g_PluginMngr.SetAllLoaded();
}
Expand Down
Loading
Loading