forked from BloodSharp/sxe-base-v8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
offset.cpp
385 lines (345 loc) · 9.1 KB
/
offset.cpp
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
#include "client.h"
DWORD retaddress;
BOOL utilsCompareData(const BYTE* pData, const BYTE* bMask, const char* pszMask)
{
for (; *pszMask; ++pszMask, ++pData, ++bMask)
if (*pszMask == 'x' && *pData != *bMask)
return FALSE;
return (*pszMask) == 0;
}
DWORD utilsFindPattern(DWORD dwAddress, DWORD dwLen, BYTE* bMask, char* pszMask)
{
for (DWORD i = 0; i < dwLen; i++)
if (utilsCompareData((BYTE*)(dwAddress + i), bMask, pszMask))
return (DWORD)(dwAddress + i);
return 0;
}
LPVOID DetourCreateType(PBYTE pbTargetFunction, PBYTE pbDetourFunction, INT intSize, INT intType)
{
DWORD dwProtect;
PBYTE pbDetour = (PBYTE)malloc(intSize + 5);
INT i;
VirtualProtect(pbTargetFunction, intSize, PAGE_EXECUTE_READWRITE, &dwProtect);
memcpy(pbDetour, pbTargetFunction, intSize);
pbDetour += intSize;
*(BYTE*)(pbDetour + 0) = 0xE9;
*(DWORD*)(pbDetour + 1) = (DWORD)(pbTargetFunction + intSize - pbDetour) - 5;
switch (intType)
{
case 1:
*(BYTE*)(pbTargetFunction + 0) = 0xB8;
*(DWORD*)(pbTargetFunction + 1) = (DWORD)(pbDetourFunction);
*(WORD*)(pbTargetFunction + 5) = 0xE0FF;
i = 7;
break;
case 2:
*(WORD*)(pbTargetFunction + 0) = 0xC033;
*(WORD*)(pbTargetFunction + 2) = 0xC085;
*(WORD*)(pbTargetFunction + 4) = 0x840F;
*(DWORD*)(pbTargetFunction + 6) = (DWORD)(pbDetourFunction - pbTargetFunction) - 10;
i = 10;
break;
case 3:
*(WORD*)(pbTargetFunction + 0) = 0xDB33;
*(WORD*)(pbTargetFunction + 2) = 0xDB85;
*(WORD*)(pbTargetFunction + 4) = 0x840F;
*(DWORD*)(pbTargetFunction + 6) = (DWORD)(pbDetourFunction - pbTargetFunction) - 10;
i = 10;
break;
case 4:
*(WORD*)(pbTargetFunction + 0) = 0xC933;
*(WORD*)(pbTargetFunction + 2) = 0xC985;
*(WORD*)(pbTargetFunction + 4) = 0x840F;
*(DWORD*)(pbTargetFunction + 6) = (DWORD)(pbDetourFunction - pbTargetFunction) - 10;
i = 10;
break;
case 5:
*(WORD*)(pbTargetFunction + 0) = 0xD233;
*(WORD*)(pbTargetFunction + 2) = 0xD285;
*(WORD*)(pbTargetFunction + 4) = 0x840F;
*(DWORD*)(pbTargetFunction + 6) = (DWORD)(pbDetourFunction - pbTargetFunction) - 10;
i = 10;
break;
}
for (; i < intSize; i++)* (BYTE*)(pbTargetFunction + i) = 0x90;
VirtualProtect(pbTargetFunction, intSize, dwProtect, &dwProtect);
return (pbDetour - intSize);
}
__declspec(naked)void Gateway2_HUD_Frame(void)
{
__asm
{
call HUD_Frame;
jmp retaddress;
}
}
DWORD Frame = (DWORD)& Gateway2_HUD_Frame;
__declspec(naked)void Gateway1_HUD_Frame(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x0C] ;
mov retaddress, esi;
push Frame
pop esi;
mov dword ptr ss : [esp + 0x0C] , esi;
pop esi;
ret;
}
}
__declspec(naked)void Gateway2_V_CalcRefdef(void)
{
__asm
{
call PostV_CalcRefdef;
jmp retaddress;
}
}
DWORD CalcRef = (DWORD)& Gateway2_V_CalcRefdef;
__declspec(naked)void Gateway1_V_CalcRefdef(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x10] ;
push esi;
call PreV_CalcRefdef;
add esp, 4;
mov esi, dword ptr ss : [esp + 0x0c] ;
mov retaddress, esi;
push CalcRef;
pop esi;
mov dword ptr ss : [esp + 0x0c] , esi;
pop esi;
ret;
}
}
__declspec(naked)void Gateway2_CL_CreateMove(void)
{
__asm
{
call CL_CreateMove;
jmp retaddress;
}
}
DWORD CreateMove = (DWORD)& Gateway2_CL_CreateMove;
__declspec(naked)void Gateway1_CL_CreateMove(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x28] ;
mov retaddress, esi;
push CreateMove;
pop esi;
mov dword ptr ss : [esp + 0x28] , esi;
pop esi;
ret;
}
}
__declspec(naked)void Gateway2_HUD_Redraw(void)
{
__asm
{
call HUD_Redraw;
jmp retaddress;
}
}
DWORD Redraw = (DWORD)& Gateway2_HUD_Redraw;
__declspec(naked)void Gateway1_HUD_Redraw(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x10] ;
mov retaddress, esi;
push Redraw
pop esi;
mov dword ptr ss : [esp + 0x10] , esi;
pop esi;
ret;
}
}
__declspec(naked)void Gateway2_HUD_PostRunCmd(void)
{
__asm
{
call HUD_PostRunCmd;
jmp retaddress;
}
}
DWORD PostRunCmd = (DWORD)& Gateway2_HUD_PostRunCmd;
__declspec(naked)void Gateway1_HUD_PostRunCmd(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x38] ;
mov retaddress, esi;
push PostRunCmd
pop esi;
mov dword ptr ss : [esp + 0x38] , esi;
pop esi;
ret;
}
}
__declspec(naked)void Gateway2_HUD_PlayerMove(void)
{
__asm
{
call HUD_PlayerMove;
jmp retaddress;
}
}
DWORD PlayerMove = (DWORD)& Gateway2_HUD_PlayerMove;
__declspec(naked)void Gateway1_HUD_PlayerMove(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x10] ;
mov retaddress, esi;
push PlayerMove
pop esi;
mov dword ptr ss : [esp + 0x10] , esi;
pop esi;
ret;
}
}
extern int AddEntResult;
__declspec(naked)void Gateway2_HUD_AddEntity(void)
{
__asm
{
mov AddEntResult, eax;
call HUD_AddEntity;
mov eax, AddEntResult;
jmp retaddress;
}
}
DWORD AddEnt = (DWORD)& Gateway2_HUD_AddEntity;
__declspec(naked)void Gateway1_HUD_AddEntity(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x14] ;
mov retaddress, esi;
push AddEnt
pop esi;
mov dword ptr ss : [esp + 0x14] , esi;
pop esi;
ret;
}
}
extern int KeyEventResult;
__declspec(naked)void Gateway2_HUD_Key_Event(void)
{
__asm
{
mov KeyEventResult, eax;
call HUD_Key_Event;
mov eax, KeyEventResult;
jmp retaddress;
}
}
DWORD KeyEvent = (DWORD)& Gateway2_HUD_Key_Event;
__declspec(naked)void Gateway1_HUD_Key_Event(void)
{
__asm
{
push esi;
mov esi, dword ptr ss : [esp + 0x14] ;
mov retaddress, esi;
push KeyEvent
pop esi;
mov dword ptr ss : [esp + 0x14] , esi;
pop esi;
ret;
}
}
#define CompareMemory(Buff1, Buff2, Size) __comparemem((const unsigned char*) Buff1, (const unsigned char*) Buff2, (unsigned int) Size)
bool __comparemem(const unsigned char* Buff1, const unsigned char* Buff2, unsigned int Size)
{
for (unsigned int i = 0; i < Size; i++, Buff2++, Buff1++)
{
if ((*Buff1 != *Buff2) && (*Buff2 != 0xFF))
return false;
}
return true;
}
#define FindMemoryClone(start, end, clone, clonesize) __findmemoryclone((const unsigned long) start, (const unsigned long) end, (const unsigned long) clone, (unsigned int) clonesize)
void* __findmemoryclone(const unsigned long start, const unsigned long end, const unsigned long clone, unsigned int clonesize)
{
for (unsigned long ul = (unsigned long)start; (ul + clonesize) < end; ul++)
{
if (CompareMemory(ul, clone, clonesize))
return (void*)ul;
}
return NULL;
}
#define FindReference(start, end, address, type) __findreference((const unsigned long) start, (const unsigned long) end, (const unsigned long) address, (const unsigned char) type)
void* __findreference(const unsigned long start, const unsigned long end, const unsigned long address, const unsigned char type)
{
unsigned char Pattern[5];
if (type == 1)
{
Pattern[0] = 0x68;
*(unsigned long*)& Pattern[1] = address;
}
return FindMemoryClone(start, end, Pattern, sizeof(Pattern) - 1);
}
#define CompareMemory2(Buff1, Buff2, Size) __comparemem2((const UCHAR *)Buff1, (const UCHAR *)Buff2, (UINT)Size)
BOOL __comparemem2(const UCHAR* buff1, const UCHAR* buff2, UINT size)
{
for (UINT i = 0; i < size; i++, buff1++, buff2++)
{
if ((*buff1 != *buff2) && (*buff2 != 0xFF))
return FALSE;
}
return TRUE;
}
#define FindMemoryClone2(Start, End, Clone, Size) __findmemoryclone2((const ULONG)Start, (const ULONG)End, (const ULONG)Clone, (UINT)Size)
ULONG __findmemoryclone2(const ULONG start, const ULONG end, const ULONG clone, UINT size)
{
for (ULONG ul = start; (ul + size) < end; ul++)
{
if (CompareMemory2(ul, clone, size))
return ul;
}
return NULL;
}
#define FindReference2(Start, End, Address) __findreference2((const ULONG)Start, (const ULONG)End, (const ULONG)Address)
ULONG __findreference2(const ULONG start, const ULONG end, const ULONG address)
{
UCHAR Pattern[5];
Pattern[0] = 0x68;
*(ULONG*)& Pattern[1] = address;
return FindMemoryClone2(start, end, Pattern, sizeof(Pattern) - 1);
}
void* OffsetStudio(DWORD Base, DWORD Size)
{
PCHAR ModelrString = "cl_himodels";
ModelrString = (char*)FindMemoryClone(Base, Base + Size, ModelrString, strlen(ModelrString));
if (ModelrString == NULL)
return NULL;
void* pInit = (void*)FindReference(Base, Base + Size, ModelrString, 1);
if (pInit == NULL)
return NULL;
for (unsigned char* b = (unsigned char*)pInit; (DWORD)b > ((DWORD)pInit - 0x10); b--)
{
if (*(b - 1) == 0x90 && *(b - 2) == 0x90)
return (void*)((DWORD)FindMemoryClone(Base, Base + Size, &b, sizeof(DWORD)) - sizeof(DWORD));
}
return NULL;
}
void* SpeedHackPtr(DWORD Base, DWORD Size)
{
DWORD Old = NULL;
PCHAR String = "Texture load: %6.1fms";
DWORD Address = (DWORD)FindMemoryClone(Base, Base + Size, String, strlen(String));
void* SpeedPtr = (void*) * (DWORD*)(FindReference2(Base, Base + Size, Address) - 7);
VirtualProtect(SpeedPtr, sizeof(double), PAGE_READWRITE, &Old);
return SpeedPtr;
}