-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspells.cpp
355 lines (339 loc) · 9.23 KB
/
spells.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
#include "stdafx.h"
#include "unit.h"
int (__cdecl *spellAccept)(int SpellType,void *Caster,void *CasterMB2,void *Carrier,
SpellTargetBlock *Block,int Power);
int (__cdecl *spellGetPower)(int Spell,void *Caster);
// âûêëþ÷àåò ñïåëë ïîñòîÿííîãî äåéñòâèÿ
void (__cdecl *spellCancelDurSpell)(int Spell,void *Caster);
// ñíèìàåò êàêîé-ëèáî áàôô
void (__cdecl *spellBuffOff)(void *Target,int BuffN);
int (__cdecl *spellDefHasFlags)(int Spell,DWORD Flags);
void (__cdecl *createSpellFly)(void *Caster,void *Target,int Spell);
void (__cdecl *applyToTarget)(void *Target,int Buff,int Delay,int SpellPower);
int (__cdecl *myCastSpellByUser)(int Spell, void *Caster, SpellTargetBlock *TargetBlock);
//
extern int (__cdecl *audSyllStartSpeak)(int SpellN);
extern bigUnitStruct **unitCreatedList;
extern DWORD *GameFlags;
namespace
{
int buffApplyL(lua_State*L)
{
if (lua_type(L,1)!=LUA_TLIGHTUSERDATA || lua_type(L,2)!=LUA_TNUMBER || lua_type(L,3)!=LUA_TNUMBER)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
int Buff=lua_tointeger(L,2);
if (Buff<0 || Buff>31)
return 0;
int delay=lua_tointeger(L,3);
if (delay<0)
return 0;
applyToTarget(lua_touserdata(L,1),Buff,delay,5);
return 0;
}
/// êîëäóåò ñïåëë êåì-òî (ñïèñàíî ñ íîêñà)
/// êîãäà ìîá ÷åãî-íèòü êîëäóåò - ìû îá ýòîì óçíàåì
int myCastSpellByUserPlayer(int Spell, void *Caster, SpellTargetBlock *TargetBlock)
{
bool check=true;
if (*GameFlags & 0x1000!=0) // åñëè íîêñêâåñò òî íàôãè ïðîâåðêó
return myCastSpellByUser(Spell, Caster, TargetBlock);
if(spellDefHasFlags(Spell,0x200400)==1 && Spell!=34 && (Spell<75 || Spell>114))
{
if(Caster!=TargetBlock->target && spellDefHasFlags(Spell,0x600)==1)
check=false;
if(Caster==TargetBlock->target && spellDefHasFlags(Spell,0x600)==0)
check=false;
}
if(check)
return myCastSpellByUser(Spell, Caster, TargetBlock);
else
{
// Çäåñü ìîæíî áóäåò çàîäíî êèêàòü èëè áàíèòü íàðóøèòåëÿ
return 1;
}
}
int myCastSpellByUserMob(int Spell, void *Caster, SpellTargetBlock *TargetBlock)
{
int R,Top=lua_gettop(L);
lua_getglobal(L,"unitOnCastList");
lua_pushlightuserdata(L,Caster);
if (lua_type(L,-2)!=LUA_TNIL)
lua_gettable(L,-2);
if (spellDefHasFlags(Spell,0x20))
{
spellBuffOff(Caster,0x00);
spellBuffOff(Caster,0x17);
spellCancelDurSpell(0x43,Caster);//âûêëþ÷àåì ùèò
}
if (
spellDefHasFlags(Spell,0x04) &&// íóæíî äåëàòü ìóõó
TargetBlock->target!=Caster // ìû íå â ñåáÿ êîëäóåì
)
{
createSpellFly(Caster,TargetBlock->target,Spell);
//Ùà ìû íàéäåì ýòó ìóõó ïîêà îíà íå óëåòåëà
if (lua_type(L,-1)==LUA_TFUNCTION)
{
bigUnitStruct *B=*unitCreatedList;
for (;B!=NULL;B=(bigUnitStruct *)B->nextUnit)
{
if (B->parentUnit!=Caster)
continue; // íå íàøà
if (B->thingType!=0x3BB)
continue; // íå ìóõà
break;/// 99% ÷òî îíà âîîáùå ïåðâàÿ â ñïèñêå, ò.ê. åå òîëüêî ÷òî ñîçäàëè
}
if (B) // åñëè ìóõó íå íàøëè - òàê ñ÷èòàåì ÷òî íå ñêîëäîâàëîñü
{
lua_pushinteger(L,Spell);
lua_pushlightuserdata(L,Caster);
lua_pushlightuserdata(L,TargetBlock->target);
lua_pushlightuserdata(L,B);
lua_pushnumber(L,TargetBlock->targX);
lua_pushnumber(L,TargetBlock->targY);
lua_pcall(L,6,0,0);
}
}
R=1;
}
else
{
R=spellAccept(Spell,Caster,Caster,Caster,
TargetBlock, spellGetPower(Spell,Caster));
lua_pushinteger(L,Spell);
lua_pushlightuserdata(L,Caster);
lua_pushlightuserdata(L,TargetBlock->target);
lua_pushnil(L);
lua_pushnumber(L,TargetBlock->targX);
lua_pushnumber(L,TargetBlock->targY);
lua_pcall(L,6,0,0);
}
lua_settop(L,Top);
return R;
}
int spellBuff(lua_State *L)
{
return 0;
}
int spellApplyL(lua_State *L)
{
/// Êîìó,×åãî,×åì, [ÎòÊîãî,ÃäåX,ÃäåY,[SpellPower=3], Ïðîìåæóòî÷íûé]
if (
(lua_type(L,1)!=LUA_TLIGHTUSERDATA)||
(lua_type(L,2)!=LUA_TNUMBER)||
(lua_type(L,3)!=LUA_TLIGHTUSERDATA)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
void *Targ=lua_touserdata(L,1);
int Type=lua_tointeger(L,2);
void *Carrier=lua_touserdata(L,3);
void *Source=0,*Thru=0;
SpellTargetBlock Bk;
int i=4;
if (lua_type(L,i)==LUA_TLIGHTUSERDATA)
Source=lua_touserdata(L,i);
i++;
if (lua_type(L,i)==LUA_TNUMBER)
{
Bk.targX=lua_tonumber(L,i);
i++;
if(lua_type(L,i)!=LUA_TNUMBER)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
Bk.targY=lua_tonumber(L,i);
i++;
}
else
{
BYTE *B=(BYTE *)Targ;
if(Targ!=NULL)
{
if (( 0!=(0x4 & B[8]) ))
{
B+=0x2EC;//êîíòðîëëåð
B=*((BYTE**)B);B+=0x114;//ïëýåðèíôî
B=*((BYTE**)B);B+=0x8EC;
Bk.targX=*((int*)B);B+=4;
Bk.targY=*((int*)B);
}
else
{
B+=0x38;
Bk.targX=*((float*)B);B+=4;
Bk.targY=*((float*)B);
}
}
else
{
Bk.targX=Bk.targY=0;
}
}
int Power=3;
if (lua_type(L,i)==LUA_TNUMBER)
{
Power=lua_tointeger(L,i);
i++;
}
if (lua_type(L,i)==LUA_TLIGHTUSERDATA)
Thru=lua_touserdata(L,i);
if(Thru==NULL)
Thru=Source;
if(Source==NULL)
{
Source=Thru=Carrier;
}
Bk.target=Targ;
int R=spellAccept(Type,Source,Thru,Carrier,&Bk,Power);
lua_pushinteger(L,R);
return 1;
}
int spellSync(lua_State *L)
{
int Top=lua_gettop(L);
byte Buf[250],*P=Buf;
int Size;
P+=UNIPACKET_HEAD;
Size=0;
getClientVar("spellData");
lua_pushnil(L);
SendBuffer Out;
while (0!=lua_next(L,-2))
{
if (lua_type(L,-2)!=LUA_TNUMBER)
{
lua_pop(L,1);
continue;
}
int Spell=lua_tointeger(L,-2);
*((DWORD*)P)=Spell;
if (lua_type(L,-1)==LUA_TNUMBER)
{
}
netUniPacket(upSpellSync,P,Size);
netSendNotOne(Buf,P-Buf,NULL); /// ïîñûëàåò âñåì êëèåíòàì êðîìå îäíîãî
}
lua_settop(L,Top);
return 0;
}
}
extern void InjectOffs(DWORD Addr,void *Fn);
extern void (__cdecl *netPriMsg)(void *PlayerUnit,char *String,int Flag);
extern DWORD *GameFlags;
/// äëÿ êàñòîìíîé ëîâóøêè íàäî áóäåò ïðîñòî þçàòü äðóãîé ñïåëë
/// Åùå íàäî ðàçîñëàòü netReportSpellStat âñåì âîêðóã
void spellServDoCustom(int SpellArr[5],bool OnSelf,BYTE *MyPlayer,BYTE *MyUc)
{
int Top=lua_gettop(L);
getClientVar("spellData");
lua_pushinteger(L,SpellArr[0]);
lua_gettable(L,-2);
if (lua_type(L,-1)!=LUA_TTABLE)
{
lua_settop(L,Top);
return;
}
lua_getfield(L,Top+2,"mana");
int ManaCost=lua_tointeger(L,-1);
char TextBuf[80]="";
BYTE *PlayerInfo=*((BYTE**)(MyUc+0x114));
do
{
if ( 1 & *((DWORD*)(PlayerInfo+0xE60)))
{
lua_getfield(L,Top+2,"mayObserver");
if (0==lua_toboolean(L,-1))
{
netPriMsg(MyPlayer,"GeneralPrint:NoSpellWarningGeneral",0);
break;
}
} else if ( 2 & *((DWORD*)(PlayerInfo+0xE60)))
{
lua_getfield(L,Top+2,"mayPosessed");
if (0==lua_toboolean(L,-1))
{
netPriMsg(MyPlayer,"GeneralPrint:ConjureNoSpellWarning1",0);
break;
}
}
if ( 0x80 & *GameFlags)
{
lua_getfield(L,Top+2,"mayInChat");
if (0==lua_toboolean(L,-1))
{
break;
}
}
BYTE *Target=*((BYTE**)(MyUc+0x120));
lua_newtable(L); /// âíóòðåííèå äàííûå ñïåëà - äëÿ ïðîäîëæèòåëüíûõ è ò.ï.
lua_getfield(L,Top+2,"flags");
lua_getfield(L,Top+2,"servOnStart");
int X=lua_type(L,-1);
if (lua_type(L,-1)!=LUA_TFUNCTION)
{
sprintf(TextBuf,"Unimod: 'spellData[0x%x].servOnStart' not a function",SpellArr[0]);
conPrintI(TextBuf);
break;
}
lua_getfield(L,LUA_REGISTRYINDEX,"server");
lua_setfenv(L,-2);
if (lua_tointeger(L,-2) & 0x20) /// Íàø ñïåëë èìååò öåëü - íàäî äåëàòü ìóõó
{
if (Target!=NULL)
{
if ( 0x10000000 & (*(DWORD*)(Target+0x154)) ) /// öåëü çàùèùåíà îò ìàãèè - íè÷åãî íå äåëàåì
{
break;
}
}
}
else
{
lua_pushlightuserdata(L,MyPlayer);
lua_pushnumber(L,*((int*)(PlayerInfo+0x8EC))); // x
lua_pushnumber(L,*((int*)(PlayerInfo+0x8F0))); // y
if (Target) lua_pushlightuserdata(L,Target);
else lua_pushnil(L);
lua_pushvalue(L,-7); // data
if (0!=lua_pcall(L,5,1,0))// player,targX,targY,targetUnit,data -> success
{
conPrintI(lua_tostring(L,-1));
}
if (0!=lua_toboolean(L,-1)) //ñïåëë óäàëñÿ
{
/// íàäî ñîõðàíèòü äàííûå, îòíÿòü ìàíó è ò.ï.
byte Buf[10],*P=Buf;
netUniPacket(upSpellStart,P,sizeof(DWORD));
*((DWORD*)P)=SpellArr[0];
netSendNotOne(Buf,P-Buf,MyUc); /// ïîñûëàåò âñåì êëèåíòàì êðîìå îäíîãî
}
}
} while(0);
lua_settop(L,Top);
}
void spellsInit()
{
ASSIGN(spellAccept,0x004FD400);
ASSIGN(spellGetPower,0x004FE7B0);
ASSIGN(spellCancelDurSpell,0x004FEB10);
ASSIGN(spellBuffOff,0x004FF5B0);
ASSIGN(spellDefHasFlags,0x00424A50);
ASSIGN(createSpellFly,0x004FDDA0);
ASSIGN(applyToTarget,0x004FF380);
ASSIGN(myCastSpellByUser,0x004FDD20);
InjectOffs(0x00541337+1,&myCastSpellByUserMob);
InjectOffs(0x004FB425+1,&myCastSpellByUserPlayer);
registerserver("spellSync",&spellSync);
registerserver("spellApply",&spellApplyL);
registerserver("spellBuff",&spellBuff);
registerserver("buffApply",&buffApplyL);
lua_newtable(L);// â òàáëèöó áóäåì êëàñòü èíòåðåñíûõ íàì ìîáîâ
registerServerVar("unitOnCastList");
}