summaryrefslogtreecommitdiffstats
path: root/src/hooks.h
blob: 084698f889dee0edb6acbe07e868ec17e39aac5a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef HL2H_HOOKS_H
#define HL2H_HOOKS_H

#include <cstddef>

// 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