forked from noah-/d2bs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD2Intercepts.cpp
420 lines (348 loc) · 8.87 KB
/
D2Intercepts.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#include "D2Handlers.h"
#include "D2Ptrs.h"
#include "D2BS.h"
#include "Helpers.h"
#include <shlwapi.h>
void __declspec(naked) RealmPacketRecv_Interception() {
__asm {
test esi, esi
jz block
pushad
call RealmPacketRecv
cmp eax, 0
popad
je Block
call esi
Block:
ret
}
}
void __declspec(naked) GamePacketReceived_Intercept() {
__asm {
pushad;
call GamePacketReceived;
test eax, eax;
popad;
jnz OldCode;
mov edx, 0;
OldCode:
mov eax, [esp + 4];
push eax;
call D2NET_ReceivePacket_I;
ret 4;
}
}
void __declspec(naked) GamePacketSent_Interception() {
__asm {
pushf
pushad;
mov ecx, [esp + 0x22 + 4 + 0xC];
mov edx, [esp + 0x22 + 4 + 0x4];
call GamePacketSent;
test eax, eax;
popad;
jnz OldCode;
mov[esp + 0x4 + 4 + 2], 0;
OldCode:
popf
jnz good
xor eax, eax
pop ebp
ret 0Ch
good :
jmp D2CLIENT_SendPacket_II
}
}
void GameDraw_Intercept(void) {
GameDraw();
}
void __declspec(naked) GameInput_Intercept() {
__asm {
pushad
mov ecx, ebx
call GameInput
cmp eax, -1
popad
je BlockIt
call D2CLIENT_InputCall_I
ret
BlockIt:
xor eax,eax
ret
}
}
UnitAny* GetSelectedUnit_Intercept(void) {
if (Vars.bClickAction) {
if (Vars.dwSelectedUnitId) {
UnitAny* pUnit = D2CLIENT_FindUnit(Vars.dwSelectedUnitId, Vars.dwSelectedUnitType);
return pUnit;
}
return NULL;
}
return D2CLIENT_GetSelectedUnit();
}
void __declspec(naked) Whisper_Intercept() {
__asm
{
mov [esp-674h-4+4], edi
pop edi
sub esp, 678h
pushad
mov ecx, ebx
mov edx, [ebp+8]
call WhisperHandler
popad
// jmp D2MULTI_WhisperIntercept_Jump
jmp edi
}
}
VOID __declspec(naked) ChatPacketRecv_Interception() {
__asm {
mov edx, [ebp + 8]
mov ecx, ebx
pushad
sub ecx, 4
add edx, 4
call ChatPacketRecv
test eax, eax
popad
je Block
call edi
Block:
ret
}
}
void __declspec(naked) GameAttack_Intercept() {
__asm {
pushad
mov ecx, esi // attack struct
call GameAttack
cmp eax, -1
popad
je OldCode
call D2CLIENT_GetSelectedUnit
cmp eax, 0
je OldCode
mov [esp+0x08+0x4+0x4], 1 // bool unit
OldCode:
mov eax, [p_D2CLIENT_MouseY]
mov eax, [eax]
retn
}
}
void __declspec(naked) PlayerAssignment_Intercept() {
__asm
{
FNOP
CALL D2CLIENT_AssignPlayer_I
MOV ECX, EAX
CALL GamePlayerAssignment
RETN
}
}
void __declspec(naked) GameCrashFix_Intercept() {
__asm {
CMP ECX, 0
JE Skip
MOV DWORD PTR DS:[ECX+0x10],EDX
Skip:
MOV DWORD PTR DS:[EAX+0xC],0
RETN
}
}
void GameDrawOOG_Intercept(void) {
GameDrawOOG();
}
void __declspec(naked) CongratsScreen_Intercept(void) {
__asm
{
call D2CLIENT_CongratsScreen_I
pushad
call SetMaxDiff
popad
retn
}
}
void __declspec(naked) GameActChange_Intercept(void) {
__asm
{
POP EAX
PUSH ESI
XOR ESI, ESI
CMP [Vars.bChangedAct], 0
MOV [Vars.bChangedAct], 0
JMP EAX
}
}
void __declspec(naked) GameActChange2_Intercept(void) {
__asm
{
MOV ESP, EBP
POP EBP
MOV [Vars.bChangedAct], 1
retn
}
}
void __declspec(naked) GameLeave_Intercept(void) {
__asm
{
call GameLeave
jmp D2CLIENT_GameLeave_I
}
}
void __declspec(naked) ChannelInput_Intercept(void) {
__asm {
push ecx
mov ecx, esi
call ChannelInput
test eax, eax
pop ecx
jz SkipInput
call D2MULTI_ChannelInput_I
SkipInput:
ret
}
}
void __declspec(naked) AddUnit_Intercept(UnitAny* lpUnit) {
__asm
{
call [D2CLIENT_GameAddUnit_I]
pushad
push esi
call AddUnit
popad
retn
}
}
void __declspec(naked) RemoveUnit_Intercept(UnitAny* lpUnit) {
__asm {
pushad
push dword ptr ds:[esi+edx*4]
call RemoveUnit
popad
mov eax,dword ptr ds:[ecx+0xE4]
mov DWORD PTR ds:[esi+edx*4], eax
retn
}
}
VOID __declspec(naked) __fastcall ClassicSTUB() {
*p_BNCLIENT_ClassicKey = Vars.szClassic;
__asm {
jmp BNCLIENT_DClass;
}
}
VOID __declspec(naked) __fastcall LodSTUB() {
*p_BNCLIENT_XPacKey = Vars.szLod;
__asm {
jmp BNCLIENT_DLod;
}
}
void __declspec(naked) FailToJoin() {
__asm
{
cmp esi, 4000;
ret;
}
}
int EraseCacheFiles() {
CHAR path[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH, path);
CHAR szSearch[MAX_PATH];
memset(szSearch, 0x00, MAX_PATH);
strcpy_s(szSearch, path);
PathAppendA(szSearch, "\\*.dat");
WIN32_FIND_DATAA FindFileData;
HANDLE hFind = FindFirstFileA(szSearch, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE) {
do {
char FilePath[MAX_PATH];
memset(FilePath, 0x00, MAX_PATH);
strcpy_s(FilePath, path);
PathAppendA(FilePath, FindFileData.cFileName);
DeleteFileA(FilePath);
} while (FindNextFileA(hFind, &FindFileData));
FindClose(hFind);
}
return 0;
}
HMODULE __stdcall Multi(LPSTR Class, LPSTR Window) {
return 0;
}
HANDLE __stdcall Windowname(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int x, int y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu,
HINSTANCE hInstance, LPVOID lpParam) {
WCHAR szWindowName[200] = L"D2";
WCHAR szClassName[200] = L"CNAME";
if (wcslen(Vars.szTitle) > 1)
wcscpy_s(szWindowName, _countof(szWindowName), Vars.szTitle);
WCHAR* wClassName = AnsiToUnicode(lpClassName);
wcscpy_s(szClassName, _countof(szClassName), wClassName);
delete[] wClassName;
return CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
}
HANDLE __stdcall CacheFix(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) {
EraseCacheFiles();
CHAR path[MAX_PATH];
GetCurrentDirectoryA(MAX_PATH, path);
if (Vars.bCacheFix) {
char szTitle[128];
GetWindowText(D2GFX_GetHwnd(), szTitle, 128);
CHAR Def[100] = "";
if (strlen(szTitle) > 1) {
sprintf_s(Def, "\\bncache%d.dat", szTitle);
strcat_s(path, Def);
} else {
srand(GetTickCount());
sprintf_s(Def, "\\bncache%d.dat", rand() % 0x2000);
strcat_s(path, Def);
}
} else
strcat_s(path, "\\bncache.dat");
return CreateFileA(path, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
}
WINUSERAPI
int WINAPI MessageBoxA(__in_opt HWND hWnd, __in_opt LPCSTR lpText, __in_opt LPCSTR lpCaption, __in UINT uType);
int WINAPI LogMessageBoxA_Intercept(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) {
GetStackWalk();
char* dllAddrs;
Log(L"Error message box, caption: \"%hs\", message:\n%hs\n%hs", lpCaption, lpText, dllAddrs = DllLoadAddrStrs());
free(dllAddrs);
return MessageBoxA(hWnd, lpText, lpCaption, uType);
}
#include <DbgHelp.h>
LONG WINAPI MyUnhandledExceptionFilter(_In_ struct _EXCEPTION_POINTERS* ExceptionInfo) {
// NOT WORKING ONE, WORKING ONE IS IN Helpers.cpp
MessageBox(NULL, "QWE", "QWE", MB_OK);
HANDLE hFile = INVALID_HANDLE_VALUE;
for (int i = 0; hFile == INVALID_HANDLE_VALUE; ++i) {
char fname[100];
sprintf_s(fname, "Crash%03d.dump", i);
hFile = CreateFile(fname, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL);
}
DWORD ProcessId = GetCurrentProcessId();
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS /*READ_CONTROL | PROCESS_VM_READ*/, TRUE, ProcessId);
MINIDUMP_EXCEPTION_INFORMATION ExceptionParam;
ExceptionParam.ThreadId = GetCurrentThreadId();
ExceptionParam.ExceptionPointers = ExceptionInfo;
ExceptionParam.ClientPointers = TRUE;
MiniDumpWriteDump(hProcess, ProcessId, hFile, MiniDumpNormal, &ExceptionParam, NULL, NULL);
CloseHandle(hFile);
exit(0);
return EXCEPTION_EXECUTE_HANDLER;
}
// FogException(6, (int)&Default, a3, "Unrecoverable internal error %08x", a2);
void FogException() {
__try {
RaiseException(1, // exception code
0, // continuable exception
0, NULL);
} __except (UnhandledExceptionFilter(GetExceptionInformation())) {
exit(0);
exit(0);
}
}
char __fastcall ErrorReportLaunch(const char* crash_file, int a2) {
GetStackWalk();
Log(L"Crash File: %hs\n", crash_file);
exit(0);
}