-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdllmain.cpp
308 lines (273 loc) · 4.23 KB
/
dllmain.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
#include <Windows.h>
#include "Functions.h"
#include "Original.h"
void __stdcall Hook(DWORD Address, void* Function)
{
DWORD OldProt;
VirtualProtect((LPVOID)Address, 5, PAGE_EXECUTE_READWRITE, &OldProt);
DWORD Offset = (DWORD)Function - Address - 5;// Relative offset
*(BYTE*)Address = 0xE9;// Set to jmp
*(DWORD*)(Address + 1) = Offset;
DWORD Temp;
VirtualProtect((LPVOID)Address, 5, OldProt, &Temp);
}
void __declspec(naked) PLANTADDED()
{
__asm
{
pop ebx
pop ecx
push eax
push eax
call PlantAdded
pop eax
ret 0x10
}
}
void __declspec(naked) PLANTUPDATING()
{
__asm
{
push eax
call PlantUpdating
ret
}
}
void __declspec(naked) ZOMBIEEATING()
{
__asm
{
pop eax// Return addr
pop edx// Zombie*
push ecx// Plant*
push edx// Zombie*
push eax// Return addr
jmp ZombieEating
}
}
CONST DWORD _F0 = 0x463E49;
__declspec(naked) void __stdcall Original::PlantUpdate(Plant*)
{
__asm
{
pop ecx// Return addr
pop eax// Plant*
push ecx// Return addr
push ebx
mov ebx, eax
mov dl, byte ptr [ebx + 0x144]
jmp _F0
}
}
CONST DWORD _F1 = 0x465A96;
__declspec(naked) void __stdcall Original::PlantDraw(Plant*, Sexy::Graphics*)
{
__asm
{
push ebp
mov ebp, esp
and esp, 0xFFFFFFF8
jmp _F1
}
}
CONST DWORD _F2 = 0x466E08;
__declspec(naked) void __stdcall Original::PlantShoot(Plant*, Zombie*, int, bool)
{
__asm
{
sub esp, 0x1C
push ebx
mov ebx, [esp + 0x30]
jmp _F2
}
}
CONST DWORD _F3 = 0x52FB47;
__declspec(naked) void __stdcall Original::BitePlant(Zombie*, Plant*)
{
__asm
{
pop edx // Return addr
pop eax // Zombie*
pop ecx // Plant*
push eax // Zombie*
push edx // Return addr
push -1
push 0x64F598
jmp _F3
}
}
CONST DWORD _F4 = 0x452CB7;
__declspec(naked) void ONLOAD()
{
__asm
{
push ecx
push ecx
call GameLoaded
pop ecx
push -1
push 0x64F348
jmp _F4
}
}
__declspec(naked) void ONNEWZOMB()
{
__asm
{
push eax
push eax
call ZombieAdded
pop eax
ret 0x8
}
}
__declspec(naked) void ZOMBUPDATE()
{
__asm
{
push eax
call ZombieUpdating
ret
}
}
__declspec(naked) void ZOMBDRAW()
{
__asm
{
push [esp + 0x4]
push ebx
call ZombieDrawing
ret 0x4
}
}
__declspec(naked) void NEWPROJ()
{
__asm
{
push eax
push eax
call ProjectileAdded
pop eax
ret 0x14
}
}
__declspec(naked) void PROJUPD()
{
__asm
{
push eax
call ProjectileUpdating
ret
}
}
__declspec(naked) void PROJCOLL()
{
__asm
{
push eax
push ecx
call ProjectileColliding
ret
}
}
CONST DWORD _F5 = 0x46E006;
__declspec(naked) void __stdcall Original::ProjectileCollide(Projectile*, Zombie*)
{
__asm
{
pop edx// Ret
pop ecx
pop eax
push edx
sub esp, 0x14
push ebx
push ebp
push esi
jmp _F5
}
}
CONST DWORD _F6 = 0x46E546;
__declspec(naked) void __stdcall Original::ProjectileDraw(Projectile*, Sexy::Graphics*)
{
__asm
{
push ebp
mov ebp, esp
and esp, -0x8
jmp _F6
}
}
CONST DWORD _F7 = 0x46E468;
__declspec(naked) void __stdcall Original::ProjectileUpdate(Projectile*)
{
__asm
{
pop edx// Ret
pop eax// this*
push edx
push ecx
push esi
mov esi, eax
add [esi + 0x60], 01
jmp _F7
}
}
CONST DWORD _F8 = 0x52E2E6;
__declspec(naked) void __stdcall Original::ZombieDraw(Zombie*, Sexy::Graphics*)
{
__asm
{
push ebx
push [esp + 0xC]
mov ebx, [esp + 0xC]
mov eax, fs: [00000000]
call _F8
pop ebx
ret 0x8
}
}
CONST DWORD _F9 = 0x52AE66;
__declspec(naked) void __stdcall Original::ZombieUpdate(Zombie*)
{
__asm
{
pop edx// Ret
pop eax// this*
push edx
push ebp
mov ebp, esp
and esp, -0x8
jmp _F9
}
}
BOOL APIENTRY DllMain
(
HMODULE ModHandle,
DWORD CallReason,
LPVOID Reserved
)
{
if (CallReason != DLL_PROCESS_ATTACH) return TRUE;
// Hooks
Hook(0x452CB0, ONLOAD);
// Plant
Hook(0x40D19B, PLANTADDED);
Hook(0x463E40, PLANTUPDATING);
Hook(0x466E00, PlantShooting);
Hook(0x465A90, PlantDrawing);
// Zombie
Hook(0x52FB40, ZOMBIEEATING);
Hook(0x52AE60, ZOMBUPDATE);
Hook(0x40DE90, ONNEWZOMB);
Hook(0x52E2E0, ZOMBDRAW);
// Projectile
Hook(0x40D653, NEWPROJ);
Hook(0x46E460, PROJUPD);
Hook(0x46E000, PROJCOLL);
Hook(0x46E540, ProjectileDrawing);
AllocConsole();
FILE* O = nullptr;
freopen_s(&O, "CONOUT$", "w", stdout);
SetConsoleTitleA("LunaIO");
return TRUE;
}