-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.cpp
307 lines (259 loc) · 7.31 KB
/
main.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
#include "main.h"
#include "UnitMap.h"
#include "Player.h"
typedef int (__cdecl* tUL)();
tUL g_updateLightHook = (tUL)0x431A00;
int __cdecl UpdateLightHook()
{
int ret = g_updateLightHook();
float* test = (float*)0x2EE9670;
*test = 1;
return ret;
}
Player *plr;
DWORD WINAPI bot(LPVOID lpBuffer);
//These two functions have been posted across forums everywhere, not sure who i could give credit to on these
bool Compare(const BYTE* pData, const BYTE* bMask, const char* szMask)
{
for(;*szMask;++szMask,++pData,++bMask)
if(*szMask=='x' && *pData!=*bMask) return 0;
return (*szMask) == NULL;
}
DWORD FindPattern(DWORD dwAddress, DWORD dwLen, BYTE *bMask, char * szMask)
{
for(DWORD i=0; i<dwLen; i++)
if (Compare((BYTE*)(dwAddress+i),bMask,szMask)) return (DWORD)(dwAddress+i);
return 0;
}
BOOL key[256];
DWORD WINAPI InputHandler(LPVOID lpBuffer)
{
while(true)
{
if(GetAsyncKeyState(VK_F11) & 0x8000)
{
key[VK_F11] = true;
}
else
{
if(key[VK_F11])
{
CreateThread(0, 0, bot, 0, 0, 0);
key[VK_F11] = false;
}
}
Sleep(10);
}
return 0;
}
BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hinstDLL);
createConsole();
UnitMap::Initialize();
uint8 SendPacketNeedle[] = {0x81, 0x3D, 0x00, 0x00, 0x00, 0x03, 0x00, 0x96,
0x00, 0x00, 0x0F, 0x85, 0xAC, 0x00, 0x00, 0x00,
0xA1, 0x00, 0x00, 0x00, 0x01, 0xC1, 0xE0, 0x06,
0x0F, 0xB7, 0x88, 0x00, 0x00, 0x00, 0x00, 0x56};
char SendPacketMask[] = "xx???x?x??xxxxxxx???xxxxxxx???xx";
uint8 EncryptNeedle[] = {0x8B, 0x44, 0x24, 0x04, 0x56, 0x8B, 0xF1, 0x89,
0x46, 0x10, 0x80, 0x30, 0xAA, 0x8B, 0x46, 0x10,
0x80, 0x38, 0xAA, 0x0F, 0x84, 0xA5, 0x00, 0x00,
0x00, 0x57, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x25};
char EncryptMask[] = "xxxxxxxxxxxxxxxxxxxxxxxxxx????xx";
uint8 DecryptNeedle[] = {0x56, 0x8B, 0x74, 0x24, 0x08, 0x89, 0x71, 0x10,
0x0F, 0xB6, 0x16, 0x0F, 0xB6, 0x46, 0x01, 0x03,
0xC2, 0x8B, 0x51, 0x28, 0x25, 0xFF, 0x00, 0x00,
0x00, 0x89, 0x41, 0x04, 0x0F, 0xB6, 0x04, 0x10};
char DecryptMask[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
//dwModuleStartAddr is set as the encrypt address for 1.191
//sendpacket/encrypt/decrypt should never be before this address ever again
//Between 1.145 & 1.191, addresses shifted about 0xB320
DWORD dwModuleStartAddr = (DWORD)GetModuleHandle("Xenimus.exe") + 0x26600;
DWORD addrSendPacket = FindPattern(dwModuleStartAddr, 0xA000, SendPacketNeedle, SendPacketMask);
oSendPacket = (tSendPacket)addrSendPacket;
DWORD addrEncrypt = FindPattern(dwModuleStartAddr, 0xA000, EncryptNeedle, EncryptMask);
oEncrypt = (tEncrypt)addrEncrypt;
DWORD addrDecrypt = FindPattern(dwModuleStartAddr, 0xA000, DecryptNeedle, DecryptMask);
oDecrypt = (tDecrypt)addrDecrypt;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
printf("creating encrypt detour %x -> %x\n", addrEncrypt, encryptHook);
DetourAttach(&(PVOID&)oEncrypt, encryptHook);
printf("creating decrypt detour %x -> %x\n", addrDecrypt, decryptHook);
DetourAttach(&(PVOID&)oDecrypt, decryptHook);
printf("creating UpdateLight detour %x -> %x\n", g_updateLightHook, UpdateLightHook);
DetourAttach(&(PVOID&)g_updateLightHook, UpdateLightHook);
DetourTransactionCommit();
bRunning = true;
CreateThread(0, 0, InPacketsProcesser, 0, 0, 0);
CreateThread(0, 0, InputHandler, 0, 0, 0);
plr = new Player;
plr->Initialize(addrSendPacket);
}
if(fdwReason == DLL_PROCESS_DETACH)
{
bRunning = false;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID&)oEncrypt, encryptHook);
DetourDetach(&(PVOID&)oDecrypt, decryptHook);
DetourDetach(&(PVOID&)g_updateLightHook, UpdateLightHook);
DetourTransactionCommit();
delete plr;
UnitMap::Destroy();
}
return TRUE;
}
int __fastcall encryptHook(void *pthis, void* unk, uint8* packet, int len)
{
if(packet[0] == 0x25 && packet[6] == 0x04) //Quest Log Request
{
if(packet[10] == 0x00 && packet[11] == 0x00) //Almost always means its sent by the program
bShowLog = false;
}
return oEncrypt(pthis, packet, len);
}
int __fastcall decryptHook(void *pthis, void* unk, uint8* packet, int len)
{
int decryptres = oDecrypt(pthis, packet, len);
if (packet[0] == 0x00)
return decryptres;
if(packet[0] == 0x1E)
{
if(!bShowLog)
{
packet[0] = 0xFF;
bShowLog = true;
}
plr->ParseQuestLog(*(QuestLog*)&packet[2]);
return decryptres;
}
PDATA data;
data.packet = new uint8[len];
memcpy(data.packet, packet, len);
data.len = len;
inPackets.push(data);
return decryptres;
}
DWORD WINAPI InPacketsProcesser(LPVOID lpBuffer)
{
while(bRunning)
{
if(!inPackets.empty()) //If there are packets in the queue
{
uint8* packet = inPackets.front().packet;
//Do whatever with packet here
if(packet[0] == 0x1F)
{
plr->LoginData(*(InitialLoginData*)&packet[2]);
}
else if(packet[0] == 0x03)
{
handleUpdatePacket(packet, inPackets.front().len);
}
else if(packet[0] == 0x42) //Quest Packet
{
plr->ParseQuestText(packet);
}
free(packet);
inPackets.pop();
}
Sleep(10);
}
return 0;
}
void createConsole()
{
AllocConsole();
int hCrt, i;
FILE *hf;
hCrt = _open_osfhandle((long) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT);
hf = _fdopen( hCrt, "w" );
*stdout = *hf;
i = setvbuf( stdout, NULL, _IONBF, 0 );
}
void handleUpdatePacket(uint8* data, int len)
{
UpdatePacketSelf update = *(UpdatePacketSelf*)&data[2];
plr->Update(update);
int offset = 24;
if(update.numInRangeDynamicObjects > 0)
{
for(int i = 0; i < update.numInRangeDynamicObjects; i++)
{
if(data[offset] == 0x01) offset += 8;
else if(data[offset] == 0x02) offset += 12;
else if(data[offset] == 0x03) offset += 6;
}
}
if(update.numInRangeSpellEffects > 0)
{
for(int x = 0; x < update.numInRangeSpellEffects; x++)
{
if(data[offset] >= 240) offset += 12;
else offset += 8;
}
}
UnitMap::SetAllOutOfRange();
if(update.numInRangeUnits > 0)
{
for(int i = 0; i < update.numInRangeUnits; i++)
{
uint16 id = (data[offset+1] << 8) + data[offset];
uint16 trueid = id & 0x7FFF;
UnitMap::SetUnitInRange(trueid);
offset += 2;
if(id & 0x8000)
continue;
else
{
uint8 updateflag = data[offset];
offset += 1;
if(updateflag & 0x01)
{
UnitMap::UpdateUnitsMovement(trueid, *(UpdatePacketUnitMovement*)&data[offset]);
offset += 5;
}
if(updateflag & 0x02)
{
UnitMap::UpdateUnitsAuras(trueid, *(UpdatePacketUnitAuras*)&data[offset]);
offset += 3;
}
if(updateflag & 0x04)
{
UnitMap::UpdateUnitsModel(trueid, *(UpdatePacketUnitModels*)&data[offset]);
offset += 8;
}
if(updateflag & 0x08)
{
UnitMap::UpdateUnitsAnim(trueid, *(UpdatePacketUnitAnim*)&data[offset]);
offset += 1;
}
if(updateflag & 0x10)
{
UnitMap::UpdateUnitsSpellEffect(trueid, *(UpdatePacketUnitSpellEffect*)&data[offset]);
offset += 1;
}
if(updateflag & 0x20)
{
offset += 1 + data[offset];
}
}
}
}
UnitMap::CleanUnits();
//UnitMap::OutputUnitMap();
}
DWORD WINAPI bot(LPVOID lpBuffer)
{
while(true)
{
plr->StartGuardianTask();
plr->PlayerCharge();
plr->KillGuardians();
}
return 0;
}