102 Patches: Detours to the Rescue
C reference for DttR maintainers and modders.
Loading...
Searching...
No Matches
dttr_runtime.h
Go to the documentation of this file.
1
3
4#ifndef DTTR_RUNTIME_H
5#define DTTR_RUNTIME_H
6
7#include <stdbool.h>
8#include <stddef.h>
9#include <stdint.h>
10#include <string.h>
11
12#include <windows.h>
13
14#include <dttr_versions.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20typedef uintptr_t (*DTTR_Core_SigscanFn)(HMODULE mod, const char *sig, const char *mask);
21
24
25typedef struct DTTR_Core_Context {
26 HMODULE game_module;
28 uint32_t struct_size;
29 uint32_t abi_version;
30 uint32_t flags;
31 const void *reserved[4];
33
34typedef DTTR_Core_Hook *(*DTTR_Core_HookFunctionFn)(
35 uintptr_t addr,
36 // Minimum prologue bytes for the hook injection site. Pass 0 for auto.
37 int prologue_size,
38 void *handler,
39 void **out_original
40);
41
43 *(*DTTR_Core_HookPointerFn)(uintptr_t addr, void *new_value, void **out_original);
44
46 *(*DTTR_Core_PatchBytesFn)(uintptr_t addr, const uint8_t *bytes, size_t size);
47
51
65
66// Purpose-agnostic declaration/definition helpers for private consumer storage.
67// These helpers only declare or define storage owned by the consumer.
68#define DTTR_DECLARE_STORAGE(type, name) extern type name;
69#define DTTR_DEFINE_STORAGE(type, name) type name;
70
71#define DTTR_DECLARE_HOOK_STORAGE(name) \
72 extern uintptr_t name##_site; \
73 extern DTTR_Core_Hook *name##_handle;
74#define DTTR_DEFINE_HOOK_STORAGE(name) \
75 uintptr_t name##_site; \
76 DTTR_Core_Hook *name##_handle;
77
78#define DTTR_STORAGE_SLOT(type, name) DTTR_DECLARE_STORAGE(type, name)
79#define DTTR_HOOK_STORAGE_SLOT(name) DTTR_DECLARE_HOOK_STORAGE(name)
80
89 uintptr_t addr,
90 int prologue_size,
91 void *handler,
92 void **out_original
93);
94
101 uintptr_t addr,
102 void *new_value,
103 void **out_original
104);
105
112 uintptr_t addr,
113 const uint8_t *bytes,
114 size_t size
115);
116
120
125
130
134bool DTTR_Core_HookDetachOwnerChecked(void *owner);
135
144void *DTTR_Core_HookSetOwner(void *owner);
145
148void DTTR_Core_HookDetachOwner(void *owner);
149
152
156
162uintptr_t DTTR_Core_HookSigscan(HMODULE mod, const char *sig, const char *mask);
163
169uintptr_t DTTR_Core_HookCachedSigscan(HMODULE mod, const char *sig, const char *mask);
170
171#ifdef __cplusplus
172}
173#endif
174
175#endif // DTTR_RUNTIME_H
const DWORD size
void(* DTTR_Core_UnhookFn)(DTTR_Core_Hook *hook)
DTTR_Core_Hook *(* DTTR_Core_HookFunctionFn)(uintptr_t addr, int prologue_size, void *handler, void **out_original)
DTTR_Core_Hook * DTTR_Core_HookAttachPointer(uintptr_t addr, void *new_value, void **out_original)
DTTR_Core_Hook *(* DTTR_Core_PatchBytesFn)(uintptr_t addr, const uint8_t *bytes, size_t size)
bool DTTR_Core_HookIsActive(DTTR_Core_Hook *hook)
bool DTTR_Core_HookDetachOwnerChecked(void *owner)
DTTR_Core_Hook * DTTR_Core_HookAttachFunction(uintptr_t addr, int prologue_size, void *handler, void **out_original)
DTTR_Core_Hook * DTTR_Core_HookPatchBytes(uintptr_t addr, const uint8_t *bytes, size_t size)
uintptr_t(* DTTR_Core_SigscanFn)(HMODULE mod, const char *sig, const char *mask)
bool DTTR_Core_HookCleanupAllChecked()
void DTTR_Core_HookCleanupAll()
Detach all remaining hooks and free the sigscan cache.
uintptr_t DTTR_Core_HookCachedSigscan(HMODULE mod, const char *sig, const char *mask)
void DTTR_Core_HookDetach(DTTR_Core_Hook *hook)
uintptr_t DTTR_Core_HookSigscan(HMODULE mod, const char *sig, const char *mask)
bool(* DTTR_Core_UnhookCheckedFn)(DTTR_Core_Hook *hook)
DTTR_Core_Hook *(* DTTR_Core_HookPointerFn)(uintptr_t addr, void *new_value, void **out_original)
bool DTTR_Core_HookDetachChecked(DTTR_Core_Hook *hook)
void DTTR_Core_HookDetachOwner(void *owner)
void * DTTR_Core_HookSetOwner(void *owner)
bool(* DTTR_Core_HookIsActiveFn)(DTTR_Core_Hook *hook)
uint32_t struct_size
uint32_t flags
DTTR_Core_UnhookCheckedFn unhook_checked
DTTR_Core_HookFunctionFn hook_function
DTTR_Core_UnhookFn unhook
const void * reserved[4]
DTTR_Core_HookIsActiveFn hook_is_active
DTTR_Core_HookPointerFn hook_pointer
uint32_t abi_version
DTTR_Core_SigscanFn sigscan
DTTR_Core_PatchBytesFn patch_bytes
const void * reserved[4]
const DTTR_Core_API * api