Skip to content

Commit 6ab20c5

Browse files
committed
fix: add code highlight to guide
1 parent d0b6a9f commit 6ab20c5

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

content/6.plugins/3.polyhook/3.guide.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ A **hook** is a method to intercept function calls. You can:
3939

4040
Use `DataType` enum to describe argument and return types:
4141

42-
```
42+
```c++
4343
enum 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
5858
Use `HookDetour` to hook a global/static function:
5959
60-
```
60+
```c++
6161
Callback* 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++
7272
void* targetFunc = (void*) &DoSomething;
7373
plg::vector<DataType> args = { DataType::Int32, DataType::Pointer };
7474
Callback* cb = HookDetour(targetFunc, DataType::Void, args, -1);
@@ -80,19 +80,19 @@ Callback* cb = HookDetour(targetFunc, DataType::Void, args, -1);
8080
8181
Hook a method from an object’s vtable:
8282
83-
```
83+
```c++
8484
Callback* HookVirtual(void* pClass, int index, DataType returnType, const plg::vector<DataType>& args, int varIndex);
8585
```
8686

8787
**Example:**
8888

89-
```
89+
```c++
9090
Callback* cb = HookVirtual(someObj, 3, DataType::Bool, { DataType::Pointer }, -1);
9191
```
9292
9393
You can also get the vtable index from a function pointer:
9494
95-
```
95+
```c++
9696
int 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

107107
Instead of using vtable index:
108108

109-
```
109+
```c++
110110
Callback* 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++
130130
bool 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++
139139
ReturnAction myHandler(Callback* cb, const Parameters* params, int32_t count, const Return* ret, CallbackType type);
140140
```
141141
142142
Use this to inspect or modify arguments and returns.
143143
144144
### 2. ReturnAction
145145
146-
```
146+
```c++
147147
enum 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++
162162
int val = GetArgumentInt32(params, 0);
163163
void* ptr = GetArgumentPointer(params, 1);
164164
```
165165

166166
### Setting arguments:
167167

168-
```
168+
```c++
169169
SetArgumentInt32(params, 0, 42);
170170
SetArgumentPointer(params, 1, myPtr);
171171
```
172172
173173
### Getting return value:
174174
175-
```
175+
```c++
176176
float retVal = GetReturnFloat(ret);
177177
```
178178

179179
### Overriding return:
180180

181-
```
181+
```c++
182182
SetReturnFloat(ret, 1.0f);
183183
return ReturnAction::Supercede;
184184
```
@@ -189,7 +189,7 @@ return ReturnAction::Supercede;
189189
190190
Hook `int Add(int a, int b)` and modify result:
191191
192-
```
192+
```c++
193193
ReturnAction 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

Comments
 (0)