summaryrefslogtreecommitdiffstats
path: root/src/hooks.h
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-11-06 16:19:25 +0100
committersalmonik <salmonik@tuta.io>2026-11-06 16:19:25 +0100
commit9f0724dcd25a06c5674d30d045dc485a341253b1 (patch)
treee7587dd03c0b164113d3b879b18d81fccf332c05 /src/hooks.h
parentChams: leave engine-forced material passes alone (diff)
downloadhl2h-9f0724dcd25a06c5674d30d045dc485a341253b1.tar.gz
hl2h-9f0724dcd25a06c5674d30d045dc485a341253b1.zip
Hooks: central vtable install with restore support
Move vtable patching into hooks.cpp: one call clones the table, validates every slot, records the originals and installs the clone. Installs happen from the setup, game and paint threads, so the bookkeeping is mutex-protected. Client, CInput, IVModelRender, IStudioRender and ISurface all use it, and hooks_restore_all() can now put every interface back (previously impossible).
Diffstat (limited to 'src/hooks.h')
-rw-r--r--src/hooks.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/hooks.h b/src/hooks.h
new file mode 100644
index 0000000..084698f
--- /dev/null
+++ b/src/hooks.h
@@ -0,0 +1,28 @@
1#ifndef HL2H_HOOKS_H
2#define HL2H_HOOKS_H
3
4#include <cstddef>
5
6// One patched vtable slot. `original` receives the untouched function pointer
7// (it may be null if the caller does not need it).
8struct VtablePatch {
9 int slot;
10 void *replacement;
11 void **original;
12};
13
14// Clone `iface`'s vtable (preserving the Itanium ABI header), apply all
15// patches, and install the clone on the object. All slots belong to the same
16// interface. Returns false and leaves the object untouched if cloning fails or
17// any slot is out of range.
18bool hooks_install_vtable(void *iface, size_t slots, const VtablePatch *patches,
19 int count);
20
21// Restore every patched interface's original vtable in reverse install order.
22// Intended for tests and shutdown; the cheat normally lives as long as the
23// process does.
24void hooks_restore_all();
25
26int hooks_installed_count();
27
28#endif