-
Notifications
You must be signed in to change notification settings - Fork 3
/
bugsAndChips.cpp
386 lines (346 loc) · 7.45 KB
/
bugsAndChips.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
#include "stdafx.h"
#include "unit.h"
extern void (__cdecl *netClientSend) (int PlrN,int Dir,//1 - êëèåíòó
void *Buf,int BufSize);
extern void (__cdecl *wndShowHide)(void *Wnd,int Hide);
extern DWORD *frameCounter;
void (__cdecl *sub_4C31D0) (int netCode);
void (__cdecl *sub_4C3147)();
void (__cdecl *sub_4C2BF0)();
void (__cdecl *cliSummondWndLoad) ();
void (__cdecl *wndSummonCreateList) (void*);
BYTE *wndSummonUsed;
int wndConjSummonMsg;
int *creatureSummonCommandAll;
struct creatureWhatDo
{
int commandAll;
int mobNetCode[4];
int command[4];
};
creatureWhatDo myCreatureList;
namespace
{
void __declspec(naked) asmDeathBallBugGs() // äëÿ GreatSword
{
__asm
{
call noxUnitSetOwner
add esp,0Ch
cmp [ebx+4],02C2h
jnz exitL
mov eax,[ebx+2DCh] // òåïåðü ýòî âðåìÿ ïîñëåäíåãî êîëëàéäà
mov ecx,frameCounter
mov ecx,[ecx+0]
test eax,eax // åñëè ó íàñ òàì 0, òî ïèøåì âðåìÿ è âûõîäèì
jnz l1
obnul:
mov [ebx+2DCh],ecx
mov [ebx+2E0h],0
jmp exitL
l1: // åñëè íå íîëü òî ñìîòðèì ÷òî è äåéñòâóåì
sub ecx,eax
cmp ecx,4
ja obnul // åñëè ïðîøëî áîëüøå 4 êàäðîâ
mov ecx,[ebx+2E0h]
inc ecx
mov [ebx+2E0h],ecx
cmp ecx,3
jna exitL
push ebx
call noxDeleteObject //óäàëÿåì íàêîíåö
add esp,4
exitL:
push 004E1C92h
ret
}
}
void __declspec(naked) asmDeathBallBugSh() // äëÿ Shield
{
__asm
{
call noxUnitSetOwner
add esp,0Ch
cmp [ebx+4],02C2h
jnz exitL
mov eax,[ebx+2DCh] // òåïåðü ýòî âðåìÿ ïîñëåäíåãî êîëëàéäà
mov ecx,frameCounter
mov ecx,[ecx+0]
test eax,eax // åñëè ó íàñ òàì 0, òî ïèøåì âðåìÿ è âûõîäèì
jnz l1
obnul:
mov [ebx+2DCh],ecx
mov [ebx+2E0h],0
jmp exitL
l1: // åñëè íå íîëü òî ñìîòðèì ÷òî è äåéñòâóåì
sub ecx,eax
cmp ecx,4
ja obnul // åñëè ïðîøëî áîëüøå 4 êàäðîâ
mov ecx,[ebx+2E0h]
inc ecx
mov [ebx+2E0h],ecx
cmp ecx,3
jna exitL
push ebx
call noxDeleteObject //óäàëÿåì íàêîíåö
add esp,4
exitL:
push 004E1BDEh
ret
}
}
void __declspec(naked) asmConjSummonEnotherCmp() // äîáàâëÿåì ÏÊÌ
{
__asm
{
cmp eax,9
mov wndConjSummonMsg,eax
jnz l1
push 004C2B32h
ret
l1:
xor eax,eax
add esp,10h
retn
}
}
struct creatureCommand
{
BYTE msg;
short netCodeMob;
short whatDo;
};
void __cdecl conjSummonDo(int A,void *B)
{
BYTE *M=*((BYTE**)wndSummonUsed);
int Top=lua_gettop(L);
getServerVar("creatureSummonWhatDo");
if (lua_type(L,-1)==LUA_TNIL)
{
wndSummonCreateList(B);
lua_settop(L,Top);
return;
}
int ForHunt=0;
if (lua_tointeger(L,-1)==1)
ForHunt=1;
creatureCommand P;
P.msg=0x78;
P.netCodeMob=(short)*((BYTE**)M);
int command=0;
if (A==1)
P.whatDo=0; // èñïàðèòüñÿ
else
{
for (int i=0;i<4;i++)
{
if (P.netCodeMob==myCreatureList.mobNetCode[i])
{
command=myCreatureList.command[i];
if (command<3)
P.whatDo=4;
else if(command>=4+ForHunt)
P.whatDo=3;
else
P.whatDo=myCreatureList.command[i]+1;
myCreatureList.command[i]=P.whatDo;
}
}
}
netClientSend(0x1F,0,&P,4);
lua_settop(L,Top);
}
void __declspec(naked) asmConjSummonDo() // êîãäà íàæàëè íà ìîáà
{
__asm
{
add esp,4
push eax
mov eax,wndConjSummonMsg
cmp eax,9
jz l1
push 0
call conjSummonDo
jmp lex
l1: // åñëè ÏÊÌ òî óáèâàåì ìîáà
push 1
call conjSummonDo
lex: // âûõîäèì èç ñàáû
add esp,8
push 004C2BBEh
ret
}
}
void __cdecl conjSummonCreate(int netCode)
{
for (int i=0;i<4;i++)
{
if (myCreatureList.mobNetCode[i]==0)
{
myCreatureList.mobNetCode[i]=netCode;
myCreatureList.command[i]=myCreatureList.commandAll;
return;
}
}
}
void __declspec(naked) asmConjSummonCreate() // êîãäà ñîçäàëè ìîáà ïðîãîíÿåì åãî
{
__asm
{
push esi
call conjSummonCreate
add esp,4
call cliSummondWndLoad
push 0049179Fh
ret
}
}
void __cdecl ConjSummonDoAll()
{
int c=myCreatureList.commandAll;
for (int i=0;i<4;i++)
myCreatureList.command[i]=c;
if (c==0)
myCreatureList.commandAll=4;
}
void __declspec(naked) asmConjSummonDoAll() // êîãäà îòïðîâëÿåì êîìàíäó âñåì
{
__asm
{
xor eax,eax
mov al,cl
mov [myCreatureList+0],eax
call ConjSummonDoAll
call netClientSend
push 004C2AD1h
ret
}
}
void __cdecl ConjSummonLoadWnd()
{
myCreatureList.commandAll=4;
for (int i=0;i<4;i++)
{
myCreatureList.command[i]=0;
myCreatureList.mobNetCode[i]=0;
}
}
void __declspec(naked) asmConjSummonLoadWnd() // êîãäà çàðãðóæàåòñÿ îêíà âñå ê ÷åðòó îáíóëÿåì
{
__asm
{
call wndShowHide
call ConjSummonLoadWnd
push 004C1FA6h
ret
}
}
void __cdecl ConjSummonDieOrBanish(int netCode)
{
for (int i=0;i<4;i++)
{
if (myCreatureList.mobNetCode[i]==netCode)
myCreatureList.mobNetCode[i]=0;
}
}
void __declspec(naked) asmConjSummonDieOrBanish() // êîãäà ìîá ñäûõàåò
{
__asm
{
push edi
call ConjSummonDieOrBanish
add esp,4
call sub_4C31D0
push 004C314Ch
ret
}
}
void __cdecl fixCastFieball(float *A,float *B)
{
float *X=*((float**)A);
int *XMouse=*((int**)B);
float *Y=X+1;
int *YMouse=XMouse+1;
int cosA=*XMouse-*X;
int sinA=*YMouse-*Y;
float dist=sqrt((float)(cosA^2+sinA^2));
*A=dist/cosA;
*B=dist/sinA;
}
void __declspec(naked) asmFixCastFireball() // 0052C7CD
{
__asm
{
// edi - unit
test byte ptr [edi+8],4 // èãðîê ëè? Ìàëî-ëè ÷òî, ìá ó ìåíÿ ïàðàíîÿ
jz l1
/* mov edx,edi
add edx,0x38
push edx
mov edx,esp
mov ecx,[edi+0x2ec]
mov ecx,[ecx+0x114]
add ecx,0x8ec
push ecx
push esp
push edx
call fixCastFieball
add esp,8
mov edx,[esp]
mov ecx,[esp+4]
add esp,8 */
mov ecx,[edi+0x2ec]
mov ecx,[ecx+0x114]
sub esp,4
fild [ecx+0x8ec]
fsub [edi+0x38]
fld st // x-x1
fmul st,st
fstp [esp]
fild [ecx+0x8f0]
fsub [edi+0x3c]
fld st // y-y1
fmul st,st
fadd [esp]
fsqrt
fld st
fdivp st(2),st
fdivp st(2),st
fstp [esp] //cos
mov edx,[esp]
fstp [esp] //sin
mov ecx,[esp]
add esp,4
l1: // exit, êàê òî áëèí òàê è íàçâàë, óäèâëÿëñÿ ïî÷åìó íîêñ çàêðûâàåòñÿ
push 0052C7D9h
ret
}
}
}
extern void InjectOffs(DWORD Addr,void *Fn);
extern void InjectJumpTo(DWORD Addr,void *Fn);
void topicOverrideInit()
{
byte nop[2] = { 0x90, 0x90 };
//InjectData(0x0040C29B, nop, 2);
}
void bugsInit()
{
ASSIGN(wndSummonUsed,0x00716E88);
ASSIGN(creatureSummonCommandAll,0x005B4080);
ASSIGN(sub_4C2BF0,0x004C2BF0);
ASSIGN(sub_4C3147,0x004C3147);
ASSIGN(sub_4C31D0,0x004C31D0);
ASSIGN(wndSummonCreateList,0x004C2560);
ASSIGN(cliSummondWndLoad,0x004C2E50);
InjectJumpTo(0x004E1C8A,&asmDeathBallBugGs);
InjectJumpTo(0x004E1BD6,&asmDeathBallBugSh);
InjectJumpTo(0x004C2BC7,&asmConjSummonEnotherCmp); // äåëàåì âîçìîæíîñòü ÏÊÌ
InjectJumpTo(0x004C2BB6,&asmConjSummonDo); // ñòàâèì âìåñòî ñïèñêà íàøè 2 ïðèêîëüíûå øòóêè
InjectJumpTo(0x0049179A,&asmConjSummonCreate);
InjectJumpTo(0x004C2ACC,&asmConjSummonDoAll);
InjectJumpTo(0x004C3147,&asmConjSummonDieOrBanish);
InjectJumpTo(0x004C1FA1,&asmConjSummonLoadWnd);
// InjectJumpTo(0x0052C7CD,&asmFixCastFireball);
topicOverrideInit();
}