This repository has been archived by the owner on May 9, 2022. It is now read-only.
forked from Evengard/UniMod
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayer.cpp
434 lines (398 loc) · 9.78 KB
/
player.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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#include "stdafx.h"
#include "unit.h"
#include "player.h"
#include <vector>
void (__cdecl *playerObserveCre)(void *Player,void *Creature);
void (__cdecl *playerObserveCreUndo)(void *Player);
void (__cdecl *sub_4FC2B0) (void*);
void (__cdecl *sub_4E6040) (void*);
/// íå âïîëíå ïîíÿòíàÿ ôóíêöèÿ
void *(__cdecl *netUnitFromPacketMB)(int NetIdx);
extern int (__cdecl *printCentered)(wchar_t *Text);
/*
âî âñåëåííîì ñîñòîÿíèè íàäî ôèëüòðîâàòü ñîîáùåíèå 0x79 òðó ñïåëë è äåëàòü íà íåãî
îáõîä äî 0051C16C, ïîäìåíèâ èñòî÷íèê
*/
// ýòî ôóíêöèè, êîòîðûå ïðèíèìàþò êîìàíäû èãðîêîâ
void *(*playerControlBufferFirst)(int N);
void *(*playerControlBufferNext)(int N, void *Prev);
void *(__cdecl *playerAtCursor) (void *Player);
extern DWORD *GameFlags;
DWORD *dword_834ABC=(DWORD*)0x834ABC;
extern void *(__cdecl *noxGetTeamFirst)();
extern void *(__cdecl *noxGetTeamNext)(void *Prev);
extern void (__cdecl *noxTeamDelete)(void *TeamPtr,int SendClient);
extern int (__cdecl *noxGetUnitsInRect)(FloatRect *Rect, void (__cdecl *SomeFn)(void *Unit, void *Arg), void *Arg);
extern void (__cdecl* noxCreateAt)(unitBigStructPtr Obj,unitBigStructPtr ParentUnit, float X,float Y);
extern void (__cdecl *serverFlagsSet)(DWORD V);
extern wchar_t *(__cdecl *noxTeamDefaultName)(int color);
extern void *(__cdecl *noxTeamCreate)(int N);
extern void (__cdecl *teamSendTeam)(void *TeamPtr);
extern int teamAutoAssign(lua_State *L);
namespace
{
void __cdecl onPlayerJoin(void *Player)
{
int Top=lua_gettop(L);
getServerVar("playerOnJoin");
if (lua_isfunction(L,-1))
{
lua_pushlightuserdata(L,Player);
if (0!=lua_pcall(L,1,0,0))
conPrintI(lua_tostring(L,-1));
}
lua_settop(L,Top);
}
int __declspec(naked) onPlayerJoinTrap(DWORD TestVal)
{
__asm
{
push ebp
call onPlayerJoin
add esp,4
mov ecx,GameFlags
mov eax,[ecx]
and eax,[esp+4]
ret
};//ïðîñòî ýòî áûëà ôóíêöèÿ CheckGameFlags :)
}
void __cdecl onPlayerLeaveObs(void *Player)
{
int Top=lua_gettop(L);
getServerVar("playerOnLeaveObs");
if (lua_isfunction(L,-1))
{
lua_pushlightuserdata(L,Player);
if (0!=lua_pcall(L,1,0,0))
conPrintI(lua_tostring(L,-1));
}
lua_settop(L,Top);
}
void __declspec(naked) onPlayerLeaveObservTrap()
{
__asm
{
push edi
call onPlayerLeaveObs
add esp,4
call sub_4E6040
push 4E6658h
ret
}
}
void __cdecl onPlayerGoObs(void *Player)
{
int Top=lua_gettop(L);
getServerVar("playerOnGoObs");
if (lua_isfunction(L,-1))
{
lua_pushlightuserdata(L,Player);
if (0!=lua_pcall(L,1,0,0))
conPrintI(lua_tostring(L,-1));
}
lua_settop(L,Top);
}
void __declspec(naked) onPlayerGoObservTrap()
{
__asm
{
push ebp
call onPlayerGoObs
add esp,4
call sub_4FC2B0
push 4E6896h
ret
}
}
void __cdecl onPlayerDie(bigUnitStruct *Player)
{
int Top=lua_gettop(L);
getServerVar("playerOnDie");
if (lua_isfunction(L,-1))
{
lua_pushlightuserdata(L,Player);
Player=unitDamageFindParent(Player->unitDamaged);
if (Player==0)
lua_pushnil(L);
else
lua_pushlightuserdata(L,Player);
if (0!=lua_pcall(L,2,0,0))
conPrintI(lua_tostring(L,-1));
}
lua_settop(L,Top);
}
int __declspec(naked) onPlayerDieTrap()
{
__asm
{
mov eax,[esp+4]
push eax
call onPlayerDie
add esp,4
mov eax,dword_834ABC
push 54D2B5h
ret
};
}
void * __cdecl ControlBufferGrab(void *Player,int N,void *Ret)
{
bool Skip=false;
int Top=lua_gettop(L);
do
{
getServerVar("playerOnInput");
if (!lua_istable(L,-1))
break;
lua_pushlightuserdata(L,Player);
lua_gettable(L,-2);
if (!lua_isfunction(L,-1))
break;
do
{
lua_pushvalue(L,-1);
lua_pushlightuserdata(L,Player);
lua_pushinteger(L,*((DWORD*)((BYTE*)Ret+8)) );//Code
BYTE *Targ=(BYTE*)((bigUnitStruct*)Player)->unitController;
Targ=*((BYTE **)(Targ+0x120));
if (Targ)
lua_pushlightuserdata(L,Targ);
else
lua_pushnil(L);
if (0==lua_pcall(L,3,1,0))
Skip=lua_toboolean(L,-1);
else
{
conPrintI(lua_tostring(L,-1));
break;
}
if (Skip)
Ret=(BYTE*)playerControlBufferNext(N,Ret);
else
break;
lua_pop(L,1);
}while(Ret!=0);
}
while (0);
lua_settop(L,Top);
return Ret;
}
// À ýòî ôèëüòðû, êîòîðûå ìû âìåñòî íèõ âñòàâèì
// 6=lclick, 2 = rclick 7=jump
void __declspec(naked) *myPlayerControlBufferFirst(int N)
{
__asm {
push [esp+4]
call playerControlBufferFirst
add esp,4
test eax,eax
jz l1
push eax
push [esp+8]
push edi
call ControlBufferGrab
add esp,0xC
l1:
ret
};
}
void __declspec(naked) *myPlayerControlBufferNext(int N, void *PrevBuf)
{
__asm {
push [esp+8]
push [esp+8]
call playerControlBufferNext
add esp,8
test eax,eax
jz l1
push eax
push [esp+0x8]
push edi
call ControlBufferGrab
add esp,0xC
l1:
ret
};
}
int playerLookL(lua_State *L)
{
if (
(lua_type(L,1)!=LUA_TLIGHTUSERDATA)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
if (
(lua_type(L,2)==LUA_TNIL)
)
{
playerObserveCreUndo(lua_touserdata(L,1));
return 0;
}
if(lua_type(L,2)!=LUA_TLIGHTUSERDATA)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
if (lua_type(L,3)==LUA_TFUNCTION)
{
}
playerObserveCre(lua_touserdata(L,1),lua_touserdata(L,2));
return 0;
}
int __cdecl clientOnJoin(wchar_t *A,wchar_t *B)
{
int Top=lua_gettop(L);
getClientVar("clientOnJoin");
if (lua_type(L,-1)==LUA_TFUNCTION)
{
lua_pcall(L,0,0,0);
}
lua_settop(L,Top);
return wcscmp(A,B);
}
void* __cdecl teamKotrGetFirstValidTeam()
{
BYTE* team = (BYTE*)noxGetTeamFirst();
if(team!=NULL)
{
BYTE* teamCrown = *((BYTE**)(team+0x4C));
if(teamCrown==NULL)
{
noxTeamDelete((void*)team,1);
teamAutoAssign(L);
return teamKotrGetFirstValidTeam();
}
}
return (void*)team;
}
void* __cdecl teamKotrGetNextValidTeam(void* prevTeam)
{
BYTE* team = (BYTE*)noxGetTeamNext(prevTeam);
if(team!=NULL)
{
BYTE* teamCrown = *((BYTE**)(team+0x4C));
if(teamCrown==NULL)
{
noxTeamDelete((void*)team,1);
teamAutoAssign(L);
return teamKotrGetFirstValidTeam();
}
}
return (void*)team;
}
void* __cdecl teamCreateNewCorrectly()
{
void *R=NULL;
R=noxTeamCreate(0);
if(*GameFlags&0x800)
{}
else
{
if (R==NULL)
{
return R;
}
serverFlagsSet(4);/// âêëþ÷àåì òèìû
wchar_t* RR=NULL;
RR=noxTeamDefaultName(((byte*)R)[0x38]);//Ïîëó÷àåì äåôîëòíîå íàçâàíèå òèìû - òî ÷òî çàïèñàíî â CSF-êå, íà îñíîâàíèè öâåòà òèìû
memcpy(R, RR, 0x28);
((byte*)R)[0x44]=1;
teamSendTeam(R); //Òóò çàïèñûâàåòñÿ èíôîðìàöèÿ î íàëè÷èè òèìû âîîáùå - îäíàêî ÍÀÇÂÀÍÈÅ òèìû íå ïîñûëàåòñÿ íà êëèåíò - êëèåíò þçàåò ÑÂΨ ÄÅÔÎËÒÍÎÅ íàçâàíèå (!)
}
return R;
}
int playerMouseL(lua_State *L)
{
if ( (lua_type(L,1)!=LUA_TLIGHTUSERDATA) )
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
void *P=lua_touserdata(L,1);
void *Q=playerFirstUnit();
for (;Q!=NULL;Q=playerNextUnit(Q))
{
if (Q==P) break;
}
if (Q==NULL)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
BYTE *B=(BYTE *)P;B+=0x2EC;//êîíòðîëëåð
B=*((BYTE**)B);B+=0x114;//ïëýåðèíôî?
B=*((BYTE**)B);B+=0x8EC;
lua_pushinteger(L,*((int*)B));B+=4;
lua_pushinteger(L,*((int*)B));
return 2;
}
}
/// Âûçûâàåòñÿ ïåðåä ïîïûòêîé êîëäîâàòü ñïåëë
/// åñëè 0 - âñå êàê îáû÷íî (ïðîâåðêè íà ÷àò, íà ñàììîí è ò.ï.)
/// åñëè 1 - êîëäóåì
/// åñëè -1 - íåò
extern "C" int __cdecl playerOnTrySpell(bigUnitStruct *Unit,byte *Uc,spellPacket *Pckt)
{
int Top=lua_gettop(L);
do
{
lua_getglobal(L,"playerOnSpell");
if (lua_isnil(L,-1))
break;
lua_pushlightuserdata(L,Unit);
lua_gettable(L,-2);
if (!lua_isfunction(L,-1))
break;
lua_pushlightuserdata(L,Unit);
void *Targ=*((void**)(Uc+0x120));/// òåêóùàÿ öåëü èãðîêà
if (Targ)
lua_pushlightuserdata(L, Targ );
else
lua_pushnil(L);
byte *Pi=(byte *)(*((void**)(Uc+0x114)));
Pi+=0x8EC;
lua_pushboolean(L,Pckt->Dir);
lua_pushinteger(L,Pckt->Spells[0]);
lua_pushnumber(L,*((DWORD *)Pi));Pi+=4;
lua_pushnumber(L,*((DWORD *)Pi));
if (0==lua_pcall(L,6,1,0))
{
int R=lua_tointeger(L,-1);
lua_settop(L,Top);
return R;
}
}while(0);
lua_settop(L,Top);
return 0;
}
extern void InjectOffs(DWORD Addr,void *Fn);
extern void InjectJumpTo(DWORD Addr,void *Fn);
void playerInit()
{
ASSIGN(playerControlBufferFirst,0x0051AB50);
ASSIGN(playerAtCursor,0x0054AFA2);
ASSIGN(playerControlBufferNext,0x0051ABC0);
ASSIGN(playerObserveCre,0x4DDE80);
ASSIGN(playerObserveCreUndo,0x4DDEF0);
ASSIGN(netUnitFromPacketMB,0x0004ECCB0);
ASSIGN(sub_4FC2B0,0x4FC2B0);
ASSIGN(sub_4E6040,0x4E6040);
lua_newtable(L);
registerServerVar("playerOnSpell");//ñþäà êëàäåì ðåàêöèè íà ñïåëëû ïëååðà
lua_newtable(L);
registerServerVar("playerOnInput"); // ñþäà ðåàêöèè íà äåéñòâèÿ ïëååðà
InjectOffs(0x004E637F+1,&myPlayerControlBufferFirst);
InjectOffs(0x004E639E+1,&myPlayerControlBufferFirst);
InjectOffs(0x004E67D2+1,&myPlayerControlBufferNext);
InjectOffs(0x004DD94B+1,&onPlayerJoinTrap);
InjectOffs(0x00491EB0+1,&clientOnJoin);
InjectOffs(0x004D216B+1,&teamKotrGetFirstValidTeam);
InjectOffs(0x004D220A+1,&teamKotrGetNextValidTeam);
InjectOffs(0x00419234+1,&teamCreateNewCorrectly);
InjectJumpTo(0x54D2B0,&onPlayerDieTrap);
InjectJumpTo(0x4E6891,&onPlayerGoObservTrap);
InjectJumpTo(0x4E6653,&onPlayerLeaveObservTrap);
registerserver("playerLook",&playerLookL);
registerserver("playerMouse",&playerMouseL);
}