@@ -39,7 +39,7 @@ A **hook** is a method to intercept function calls. You can:
3939
4040Use ` DataType ` enum to describe argument and return types:
4141
42- ```
42+ ``` c++
4343enum class DataType : uint8_t {
4444 Void, Bool, Int8, UInt8, Int16, UInt16,
4545 Int32, UInt32, Int64, UInt64,
@@ -57,7 +57,7 @@ Use these consistently when describing function signatures to the hook APIs.
5757
5858Use `HookDetour` to hook a global/static function:
5959
60- ```
60+ ```c++
6161Callback* HookDetour(void* pFunc, DataType returnType, const plg::vector<DataType>& args, int varIndex);
6262```
6363
@@ -68,7 +68,7 @@ Callback* HookDetour(void* pFunc, DataType returnType, const plg::vector<DataTyp
6868
6969** Example:**
7070
71- ```
71+ ``` c++
7272void * targetFunc = (void *) &DoSomething;
7373plg::vector<DataType> args = { DataType::Int32, DataType::Pointer };
7474Callback* cb = HookDetour(targetFunc, DataType::Void, args, -1);
@@ -80,19 +80,19 @@ Callback* cb = HookDetour(targetFunc, DataType::Void, args, -1);
8080
8181Hook a method from an object’s vtable:
8282
83- ```
83+ ```c++
8484Callback* HookVirtual(void* pClass, int index, DataType returnType, const plg::vector<DataType>& args, int varIndex);
8585```
8686
8787** Example:**
8888
89- ```
89+ ``` c++
9090Callback* cb = HookVirtual(someObj, 3 , DataType::Bool, { DataType::Pointer }, -1);
9191```
9292
9393You can also get the vtable index from a function pointer:
9494
95- ```
95+ ```c++
9696int index = GetVTableIndex((void*) &MyClass::MyMethod);
9797```
9898
@@ -106,7 +106,7 @@ Getting the vtable index requires knowledge of the class layout and may not be p
106106
107107Instead of using vtable index:
108108
109- ```
109+ ``` c++
110110Callback* HookVirtualByFunc (void* pClass, void* pFunc, DataType returnType, const vector<DataType >& args, int varIndex);
111111```
112112
@@ -126,7 +126,7 @@ Callback* HookVirtualByFunc(void* pClass, void* pFunc, DataType returnType, cons
126126
127127### 1. Register Callback
128128
129- ```
129+ ```c++
130130bool AddCallback(Callback* cb, CallbackType type, CallbackHandler handler);
131131```
132132
@@ -135,15 +135,15 @@ bool AddCallback(Callback* cb, CallbackType type, CallbackHandler handler);
135135
136136** Handler Signature:**
137137
138- ```
138+ ``` c++
139139ReturnAction myHandler (Callback* cb, const Parameters* params, int32_t count, const Return* ret, CallbackType type);
140140```
141141
142142Use this to inspect or modify arguments and returns.
143143
144144### 2. ReturnAction
145145
146- ```
146+ ```c++
147147enum class ReturnAction : int32_t {
148148 Ignored, // Don't interfere
149149 Handled, // Interfere but call real function
@@ -158,27 +158,27 @@ enum class ReturnAction : int32_t {
158158
159159### Getting arguments:
160160
161- ```
161+ ``` c++
162162int val = GetArgumentInt32(params, 0 );
163163void * ptr = GetArgumentPointer(params, 1 );
164164```
165165
166166### Setting arguments:
167167
168- ```
168+ ``` c++
169169SetArgumentInt32 (params, 0, 42);
170170SetArgumentPointer(params, 1, myPtr);
171171```
172172
173173### Getting return value:
174174
175- ```
175+ ```c++
176176float retVal = GetReturnFloat(ret);
177177```
178178
179179### Overriding return:
180180
181- ```
181+ ``` c++
182182SetReturnFloat (ret, 1.0f);
183183return ReturnAction::Supercede;
184184```
@@ -189,7 +189,7 @@ return ReturnAction::Supercede;
189189
190190Hook `int Add(int a, int b)` and modify result:
191191
192- ```
192+ ```c++
193193ReturnAction preAdd(Callback* cb, const Parameters* params, int32_t count, const Return* ret, CallbackType type) {
194194 int32_t a = GetArgumentInt32(params, 0);
195195 int32_t b = GetArgumentInt32(params, 1);
@@ -224,7 +224,7 @@ void setup() {
224224
225225## Summary
226226
227- : read-mode { title =" Polyhook Header " to =" https://github.com/untrustedmodders/plugify-source-2/blob/main/plugify/polyhook.hpp " }
227+ : read-more { title =" Polyhook Header " to =" https://github.com/untrustedmodders/plugify-source-2/blob/main/plugify/polyhook.hpp " }
228228
229229| Action | Function |
230230| ---------------------| -------------------------------------------|
0 commit comments