Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
439ee4e
Add global function hook + make typing stricter
Kenzzer Jan 28, 2026
4330ed4
Allow Virtual/Member/Function class hook to have multiple context poi…
Kenzzer Feb 1, 2026
9ecc194
Fix deadlocks from recall
Kenzzer Feb 24, 2026
4d667e7
Fix compilation warnings
Kenzzer Feb 28, 2026
4a2f7cd
Add googletest suite (#8)
KitRifty Mar 1, 2026
2d0322d
Update khook.hpp
Kenzzer Mar 7, 2026
ff19206
Make KHook::CallOriginal & KHook::Recall super strict
Kenzzer Mar 11, 2026
b7e06cd
Simplify CallOriginal, Recall & GetVtableIndex
Kenzzer Mar 12, 2026
264728e
Add virtual dtor to __Hook
Kenzzer Apr 12, 2026
6d487b3
Fix-up setup logic for virtual hooks
Kenzzer Apr 24, 2026
c890dce
Add many args test (#10)
KitRifty Apr 28, 2026
ab607f3
Allow dynamic stack sizes
Kenzzer Apr 29, 2026
458445c
Fix-up template args issue
Kenzzer Apr 29, 2026
fbfd574
Refactor Build/FillMFP functions
Kenzzer Apr 29, 2026
d2efc7a
Experiment with setting STACK_SAFETY_BUFFER to 128 bytes
Kenzzer Apr 30, 2026
a54a730
Add debug print for tests
Kenzzer Apr 30, 2026
44fb685
Update GetVtableFunction
Kenzzer Jun 1, 2026
816f904
Remove some overloads
Kenzzer Jun 4, 2026
b1ee886
Update workflow
Kenzzer Jun 4, 2026
e3047d1
Fix stack size calculation
Kenzzer Jun 4, 2026
b3f1a81
Remove constexpr qualifier
Kenzzer Jun 4, 2026
e75dfd4
Fix up CI
Kenzzer Jun 4, 2026
40fca5e
[Win64] Fix stack copying for high-level classes (#11)
KitRifty Jun 6, 2026
4399736
Fix warnings. errors on linux compilation (#12)
KitRifty Jun 7, 2026
a537900
Add WasOriginalFunctionSkipped
Kenzzer Jun 11, 2026
b9318d6
Fix compilation mistakes
Kenzzer Jun 11, 2026
7f34dc0
Fix errorneous call to std::abort
Kenzzer Jun 11, 2026
bc0be3f
Add KHook::LookupSignatures
Kenzzer Jun 20, 2026
f9b3109
Use static cast instead
Kenzzer Jun 20, 2026
32a04b8
Add workflow_dispatch trigger to CI workflow
Kenzzer Jun 21, 2026
512ca9d
Fixes found while integrating KHook with SourceMod (#13)
Mikusch Jun 23, 2026
7d7e7c0
Remove unused stack_size variable
Kenzzer Jun 27, 2026
8b006a2
Bump safetyhook
Kenzzer Jun 27, 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
21 changes: 14 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ on:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
arch: [x86, x86_64]
include:
- os: ubuntu-latest
cc: clang
Expand All @@ -19,7 +21,7 @@ jobs:
cc: msvc
fail-fast: false

name: ${{ matrix.os }} - ${{ matrix.cc }}
name: ${{ matrix.os }} - ${{ matrix.cc }} (${{ matrix.arch }})
runs-on: ${{ matrix.os }}

steps:
Expand All @@ -42,26 +44,25 @@ jobs:
run: |
python -m pip install --upgrade pip setuptools wheel

- uses: actions/checkout@v4
- uses: actions/checkout@v6
name: Repository checkout
with:
fetch-depth: 0
submodules: recursive
path: repository

- uses: actions/checkout@v4
- uses: actions/checkout@v6
name: AMBuild checkout
with:
repository: alliedmodders/ambuild
ref: fe8c99ccd24fa926bf6ac6b9935a5fc03df06a72
ref: 25a23ac92307eb1e181fd3e7d9385412d4034532
fetch-depth: 0
submodules: recursive
path: ambuild

- name: Setup AMBuild
shell: bash
run: |
cd "${{ env.CACHE_PATH }}"
python -m pip install ./ambuild

- name: Select clang compiler
Expand All @@ -78,5 +79,11 @@ jobs:
run: |
mkdir build
cd build
python ../configure.py
ambuild
python ../configure.py --targets ${{ matrix.arch }} --enable-tests
ambuild

- name: Test
shell: bash
working-directory: repository
run: |
python ./test.py --target ${{ matrix.arch }} --skip-build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build/
.vscode/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[submodule "third_party/safetyhook"]
path = third_party/safetyhook
url = https://github.com/alliedmodders/safetyhook
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/gtest-parallel"]
path = third_party/gtest-parallel
url = https://github.com/google/gtest-parallel.git
13 changes: 12 additions & 1 deletion AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ class KHook(object):
self.all_targets = []
self.libsafetyhook = {}
self.libkhook = {}
self.libgtest = {}
self.test_binaries = []

def configure(self):
target_archs = []
if builder.options.targets:
Expand All @@ -29,9 +32,17 @@ class KHook(object):
cxx.cxxflags += [
'/std:c++17'
]
if getattr(builder.options, 'enable_tests', False):
cxx.defines += ['KHOOK_TESTS']


KH = KHook()
KH.configure()
builder.Build('third_party/safetyhook/AMBuilder', {'SafetyHook': KH})
builder.Build('AMBuilder', {'KHook': KH})
builder.Build('AMBuilder', {'KHook': KH})

if getattr(builder.options, 'enable_tests', False):
builder.Build('test/AMBuilder.gtest', {'GTest': KH})
builder.Build('test/AMBuilder', {'TestRunner': KH, 'KHook': KH, 'SafetyHook': KH})

builder.Build('PackageScript', {'KHook': KH})
3 changes: 2 additions & 1 deletion AMBuilder
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def AddSourceFilesFromDir(path, files):

libkhook = builder.StaticLibraryProject('khook')
libkhook.sources = AddSourceFilesFromDir(os.path.join(builder.currentSourcePath, 'src'),[
"detour.cpp"
"detour.cpp",
"ranges.cpp"
])

for compiler in KHook.all_targets:
Expand Down
19 changes: 19 additions & 0 deletions PackageScript
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import os

builder.SetBuildFolder('package')

folder_list = [
'x86',
'x86_64'
]

folder_map = {}
for folder in folder_list:
norm_folder = os.path.normpath(folder)
folder_map[folder] = builder.AddFolder(norm_folder)

for cxx_task in KHook.test_binaries:
if cxx_task.target.arch == 'x86_64':
builder.AddCopy(cxx_task.binary, folder_map['x86_64'])
else:
builder.AddCopy(cxx_task.binary, folder_map['x86'])
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,8 @@ All hooks can be configured through the use of the function `Configure`.

## Testing

There is currently no test suite.
The test suite uses the [GoogleTest](https://github.com/google/googletest) framework and can be built by configuring AMBuild with the `--enable-tests` flag. Tests must be executed in parallel with [gtest-parallel](https://github.com/google/gtest-parallel) in their own processes to avoid conflicts with each other.

To execute the test suite, run the `test.py` script with the `--target` argument specifying the target architecture to test, `x86` for 32-bit or `x86_64` for 64-bit. For example, to test the 64-bit target, run `python test.py --target x86_64`. The script will handle building the tests and executing them in parallel.

For more options, run `python test.py --help`.
2 changes: 2 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
parser = run.BuildParser(sourcePath = sys.path[0], api='2.2')
parser.options.add_argument('--targets', type=str, dest='targets', default=None,
help="Override the target architecture (use commas to separate multiple targets).")
parser.options.add_argument('--enable-tests', default=False, dest='enable_tests', action='store_true',
help='Build tests.')
parser.Configure()
Loading
Loading