From 9f0724dcd25a06c5674d30d045dc485a341253b1 Mon Sep 17 00:00:00 2001 From: salmonik Date: Fri, 6 Nov 2026 16:19:25 +0100 Subject: 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). --- src/hooks.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/hooks.h (limited to 'src/hooks.h') 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 @@ +#ifndef HL2H_HOOKS_H +#define HL2H_HOOKS_H + +#include + +// One patched vtable slot. `original` receives the untouched function pointer +// (it may be null if the caller does not need it). +struct VtablePatch { + int slot; + void *replacement; + void **original; +}; + +// Clone `iface`'s vtable (preserving the Itanium ABI header), apply all +// patches, and install the clone on the object. All slots belong to the same +// interface. Returns false and leaves the object untouched if cloning fails or +// any slot is out of range. +bool hooks_install_vtable(void *iface, size_t slots, const VtablePatch *patches, + int count); + +// Restore every patched interface's original vtable in reverse install order. +// Intended for tests and shutdown; the cheat normally lives as long as the +// process does. +void hooks_restore_all(); + +int hooks_installed_count(); + +#endif -- cgit v1.2.3