-
Notifications
You must be signed in to change notification settings - Fork 3
/
score.cpp
899 lines (852 loc) · 20.9 KB
/
score.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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
#include "stdafx.h"
#include "unit.h"
#include "player.h"
#include <deque>
#include <algorithm>
#include "winsock2.h"
extern void *(__cdecl *serverGetGameDataBySel)();
/*
Çäåñü íà÷èñëåíèå/ïîëó÷åíèå ôðàãîâ è ò.ï.
*/
extern DWORD *GameFlags;
extern int playersListL(lua_State *L);
void teamCreateDefault(int TeamNum, bool notRestrict);
int minTeams=2;
bool restrictTeams=false;
int (__cdecl *netReportScore)(void *Player);
void (__cdecl *playerAddFragDeathmatch)(void *Victim,void *Attacker,void *A,void *B);
int (__cdecl *noxTeamCanPlayGame)(); // åñòü ëè äîñòàòî÷íî èãðîêîâ â êîìàíäå è ò.ï.
void *(__cdecl *netCommonByCode)(int NetCode);
void *(__cdecl *noxGetTeamFirst)();
void *(__cdecl *noxGetTeamNext)(void *Prev);
void *(__cdecl *noxGetTeamByN)(int N);
void (__cdecl *netSendTeamFrags)(void *Team,int Frags);
void *(__cdecl *noxTeamCreate)(int N);
void (__cdecl *noxCreateAtImpl)(int TeamID, void* Common, bool wasInTeam, int netCode, int unknown);
void (__cdecl *noxTeamChange)(void* Common, void* teamPtr, int netCode, int unknown);
void (__cdecl *noxTeamDelete)(void *TeamPtr,int SendClient);
void (__cdecl *teamSendTeam)(void *TeamPtr);
void (__cdecl *noxTeamUpdate)(void *newName, void *TeamPtr);
void (__cdecl *serverFlagsSet)(DWORD V);
void (__cdecl *serverFlagsClear)(DWORD V);
wchar_t *(__cdecl *noxTeamDefaultName)(int color);
extern byte authorisedState[0x20];
extern char* authorisedLogins[0x20];
void* noxNetStructList;
namespace
{
int scoreFragLimitL(lua_State*L)
{
ServerData* servdata = (ServerData*)serverGetGameDataBySel();
unsigned int fraglimit = servdata->fragLimit;
lua_pushnumber(L, fraglimit);
return 1;
}
int scoreTimeLimitL(lua_State*L)
{
ServerData* servdata = (ServerData*)serverGetGameDataBySel();
unsigned int timelimit = servdata->timeLimitMB;
lua_pushnumber(L, timelimit);
return 1;
}
struct pTeam
{
char name[20];
char gap_14[20];
__int16 nameLastChar;
char gap_2a[2];
int firstAllyTeam;
int membersCount;
int teamFrags;
char teamColorNMB;
char teamId;
char teamId2;
char gap_3b[1];
void* somePtr;
int field_40;
int haveNameMB;
int flagPtr;
int field_4C;
};
int teamCanPlayGameImpl() // ÷òîáû ìîæíî áûëî
{
int Top=lua_gettop(L);
getServerVar("teamCanStart");
int Ret=0;
if (lua_type(L,-1)!=LUA_TNIL)
Ret=(lua_toboolean(L,-1))?2:1;
lua_settop(L,Top);
return Ret;
}
int __declspec(naked) teamCanPlayGame()
{
__asm
{
call teamCanPlayGameImpl
test eax,eax
jz l1
dec eax
ret
l1:
push ebx
push edi
push 4
xor ebx,ebx
push 0x0040A8A6
ret
};
}
int noxTeamNumber()
{
int i=0;
for (pTeam *Test=(pTeam *)noxGetTeamFirst();Test!=NULL;Test=(pTeam *)noxGetTeamNext(Test))
{
i++;
}
return i;
}
int teamGet(lua_State *L)
{
lua_settop(L,2);
if ((lua_type(L,1)==LUA_TNUMBER) || (lua_type(L,1)==LUA_TLIGHTUSERDATA))
{
pTeam *Team=0;
if ((lua_type(L,1)==LUA_TNUMBER))
Team=(pTeam *)noxGetTeamByN(lua_tointeger(L,1));
else
Team=(pTeam *)lua_touserdata(L,1);
if (!Team)
{
lua_pushnil(L);
return 1;
}
lua_newtable(L);
lua_pushinteger(L,Team->teamId);
lua_setfield(L,-2,"id");
char TeamName[0x20]={0};
wcstombs(TeamName,(wchar_t*)Team,0x14);
lua_pushstring(L,TeamName);
lua_setfield(L,-2,"name");
lua_pushinteger(L,Team->teamColorNMB);
lua_setfield(L,-2,"color");
lua_pushinteger(L,Team->membersCount);
lua_setfield(L,-2,"membersCount");
lua_pushinteger(L,Team->teamFrags);
lua_setfield(L,-2,"score");
if ( lua_toboolean(L,2)==1) /// åñëè õîòÿò þçåðäàò
{
lua_pushlightuserdata(L,Team);
lua_setfield(L,-2,"teamPtr");
if (Team->somePtr)
lua_pushlightuserdata(L,Team->somePtr);
else
lua_pushnil(L);
lua_setfield(L,-2,"flagPtr");
}
return 1;
}
lua_newtable(L);
pTeam *Test=(pTeam *)noxGetTeamFirst();
for (int i=1;Test!=NULL;Test=(pTeam *)noxGetTeamNext(Test),i++)
{
//lua_pushinteger(L,Test->teamId);
//lua_pushvalue(L,2);
pTeam *Team=Test;
if (!Team)
{
lua_pushnil(L);
return 1;
}
lua_newtable(L);
lua_pushinteger(L,Team->teamId);
lua_setfield(L,-2,"id");
char TeamName[0x20]={0};
wcstombs(TeamName,(wchar_t*)Team,0x14);
lua_pushstring(L,TeamName);
lua_setfield(L,-2,"name");
lua_pushinteger(L,Team->teamColorNMB);
lua_setfield(L,-2,"color");
lua_pushinteger(L,Team->membersCount);
lua_setfield(L,-2,"membersCount");
lua_pushinteger(L,Team->teamFrags);
lua_setfield(L,-2,"score");
if ( lua_toboolean(L,2)==1) /// åñëè õîòÿò þçåðäàò
{
lua_pushlightuserdata(L,Team);
lua_setfield(L,-2,"teamPtr");
if (Team->somePtr)
lua_pushlightuserdata(L,Team->somePtr);
else
lua_pushnil(L);
lua_setfield(L,-2,"flagPtr");
}
lua_pushinteger(L,i);
lua_pushvalue(L,-2);
lua_settable(L,3);/// ýòî òàáëèöà
lua_settop(L,3);//2 + 1
}
return 1;
}
int playerGetByName(lua_State *L)
{
if(lua_type(L, -1)==LUA_TSTRING)
{
const char *S=lua_tostring(L,-1);
bool found=false;
for(void *Pl=playerFirstUnit(); Pl!=0; Pl=playerNextUnit(Pl))
{
void **PP=(void **)(((char*)Pl)+0x2EC);
PP=(void**)(((char*)*PP)+0x114);
byte *P=(byte*)(*PP);
char Name[0x50]={0};
wcstombs(Name,((wchar_t*)(P+0x1260)),0x50);
if(strcmp(Name,S)==0)
{
found=true;
lua_pushlightuserdata(L, Pl);
break;
}
}
if(found==false)
{
lua_pushstring(L,"not found!");
lua_error_(L);
}
}
else
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
return 1;
}
int playerGetByWOL(lua_State *L)
{
if(lua_type(L, -1)==LUA_TSTRING)
{
const char *S=lua_tostring(L,-1);
bool found=false;
for(void *Pl=playerFirstUnit(); Pl!=0; Pl=playerNextUnit(Pl))
{
void **PP=(void **)(((char*)Pl)+0x2EC);
PP=(void**)(((char*)*PP)+0x114);
byte *P=(byte*)(*PP);
char WOL[0x20]={0};
strncpy(WOL,((char*)(P+0x830)),0x20);
if(strcmp(WOL,S)==0)
{
found=true;
lua_pushlightuserdata(L, Pl);
break;
}
}
if(found==false)
{
lua_pushstring(L,"not found!");
lua_error_(L);
}
}
else
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
return 1;
}
int playerInfo(lua_State *L)
{
lua_settop(L,1);
if (
(lua_type(L,1)!=LUA_TLIGHTUSERDATA)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
DWORD *DW=(DWORD*)lua_touserdata(L,1);
if (0==(DW[2] & 0x4))
{
lua_pushstring(L,"wrong args: unit is not a player!");
lua_error_(L);
}
BYTE *unit=(BYTE*)lua_touserdata(L,1);
void **PP=(void **)(((char*)unit)+0x2EC);
PP=(void**)(((char*)*PP)+0x114);
byte *P=(byte*)(*PP);
lua_newtable(L);
lua_pushinteger(L,*((short*)(P+0x864)));
lua_setfield(L,-2,"ping");
lua_pushinteger(L,*((int*)(P+0x858)));
lua_setfield(L,-2,"score");
lua_pushinteger(L,(*((int*)(P+0xE60)))&0x1);
lua_setfield(L,-2,"isObserver");
char Name[0x50]={0};
wcstombs(Name,((wchar_t*)(P+0x1260)),0x50);
lua_pushstring(L,Name);
lua_setfield(L,-2,"name");
char WOL[0x20]={0};
strncpy(WOL,((char*)(P+0x830)),0x20);
lua_pushstring(L,WOL);
lua_setfield(L,-2,"wol");
byte idx = *((byte*)(P+0x810));
lua_pushinteger(L,idx);
lua_setfield(L,-2,"idx");
void* netStructListPlayer;
if(idx<0x1F)
{
netStructListPlayer=(byte*)noxNetStructList+(1+idx)*4;
BYTE* addrStruct = *((BYTE**)netStructListPlayer);
in_addr* address=(in_addr*)(addrStruct+8);
lua_pushstring(L,inet_ntoa(*address));
}
else
lua_pushstring(L,"127.0.0.1");
lua_setfield(L,-2,"ip");
int Class=*((byte*)(P+0x8CB));
lua_pushinteger(L,Class);
lua_setfield(L,-2,"class");
if (Class==0)
lua_pushstring(L,"WAR");
else if (Class==1)
lua_pushstring(L,"WIZ");
else if (Class==2)
lua_pushstring(L,"CON");
else
lua_pushstring(L,"UNK");
lua_setfield(L,-2,"className");
int NetCode=*((short*)(P+0x80C));
byte *Common=(byte *)netCommonByCode(NetCode);
lua_pushinteger(L,NetCode);
lua_setfield(L,-2,"netcode");
byte playerIdx = *((byte*)(P+0x810));
if(authorisedState[playerIdx]==4)
lua_pushstring(L,authorisedLogins[playerIdx]);
else
lua_pushstring(L,"");
lua_setfield(L,-2,"login");
int TeamId=*((int*)(unit+0x34));
byte *Team=NULL;
if (TeamId>0)
{
Team=(byte *)noxGetTeamByN(TeamId);
}
if (Team!=NULL)
{
lua_pushinteger(L,TeamId);
lua_setfield(L,-2,"teamId");
wcstombs(Name,(wchar_t*)Team,0x14);
lua_pushstring(L,Name);
lua_setfield(L,-2,"teamName");
lua_pushinteger(L,*((int *)(Team+0x34)));
lua_setfield(L,-2,"teamScore");
}
return 1;
}
void *teamGetByLua(lua_State *L)
{
if (
(lua_type(L,1)!=LUA_TLIGHTUSERDATA) &&
(lua_type(L,1)!=LUA_TNUMBER)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
void *Team=0;
if (lua_type(L,1)==LUA_TLIGHTUSERDATA)
{
Team=lua_touserdata(L,1);
void *Test=noxGetTeamFirst();
for (;Test!=NULL;Test=noxGetTeamNext(Test))
{
if (Test==Team)
break;
}
if (Test==NULL)
{
lua_pushstring(L,"wrong args - not a team!");
lua_error_(L);
}
}
else
{
Team=noxGetTeamByN(lua_tointeger(L,1));
if (Team==NULL)
{
lua_pushstring(L,"wrong args: wrong team N!");
lua_error_(L);
}
}
return Team;
}
int teamDelete(lua_State *L)
{
void* teamPtr=teamGetByLua(L);
bool allowDelete=true;
if(restrictTeams==true)
{
for(int i=1; i<=minTeams; i++)
{
void* TeamTest=noxGetTeamByN(i);
if(TeamTest==teamPtr)
{
allowDelete=false;
break;
}
}
}
if(allowDelete==true)
noxTeamDelete(teamPtr,1);
else
{
lua_pushstring(L,"Can't delete first teams on that map!");
lua_error_(L);
}
void *Test=noxGetTeamFirst();
if (Test==NULL)
serverFlagsClear(4);/// âûêëþ÷àåì òèìû
return 0;
}
int teamCreateDefaultL(lua_State *L)
{
int param=0;
bool param2=false;
if (lua_type(L,1)==LUA_TNUMBER)
{
lua_newtable(L);
lua_pushvalue(L,1);
lua_setfield(L,-2,"limit");
lua_remove(L,1);
}
if(lua_type(L,1)==LUA_TTABLE)
{
lua_getfield(L,1,"limit");
if (lua_type(L,-1)==LUA_TNUMBER)
{
param=lua_tointeger(L,-1);
}
lua_getfield(L,1,"norestrict");
if (lua_type(L,-1)!=LUA_TNIL)
{
param2=lua_toboolean(L,-1);
}
}
teamCreateDefault(param, param2);
return 0;
}
int teamCreate(lua_State *L)
{
void *R=NULL;
lua_settop(L,2);
int id=0;
if (lua_type(L,1)==LUA_TTABLE)
{
lua_getfield(L,1,"id");
id=lua_tointeger(L,-1);
}
bool newTeam=false;
if (id>0)
{
R=noxGetTeamByN(id);
}
else
{
newTeam=true;
R=noxTeamCreate(id);
}
if (R==NULL)
{
lua_pushnil(L);
return 1;
}
serverFlagsSet(4);/// âêëþ÷àåì òèìû
wchar_t* RR=NULL;
bool RRR=false;//Ôëàã ïîñûëàòü ëè íà ÊËÈÅÍÒ èìÿ òèìû
if (lua_type(L,1)==LUA_TTABLE)
{
lua_getfield(L,1,"color");
if (!lua_isnil(L,-1))
{
((byte*)R)[0x38]=lua_tointeger(L,-1);
}
lua_getfield(L,1,"name");
const char *S=lua_tostring(L,-1);
if (S)
{
mbstowcs((wchar_t*)R,S,0x14);
RR = (wchar_t*)R;
((byte*)R)[0x44]=1;
RRR=true;
}
else if(newTeam==true)
{
RR=noxTeamDefaultName(((byte*)R)[0x38]);//Ïîëó÷àåì äåôîëòíîå íàçâàíèå òèìû - òî ÷òî çàïèñàíî â CSF-êå, íà îñíîâàíèè öâåòà òèìû
memcpy(R, RR, 0x28);
((byte*)R)[0x44]=1;
}
}
else if(newTeam==true)
{
RR=noxTeamDefaultName(((byte*)R)[0x38]);//Ïîëó÷àåì äåôîëòíîå íàçâàíèå òèìû - òî ÷òî çàïèñàíî â CSF-êå, íà îñíîâàíèè öâåòà òèìû
memcpy(R, RR, 0x28);
((byte*)R)[0x44]=1;
}
teamSendTeam(R); //Òóò çàïèñûâàåòñÿ èíôîðìàöèÿ î íàëè÷èè òèìû âîîáùå - îäíàêî ÍÀÇÂÀÍÈÅ òèìû íå ïîñûëàåòñÿ íà êëèåíò - êëèåíò þçàåò ÑÂΨ ÄÅÔÎËÒÍÎÅ íàçâàíèå (!)
if(RRR==true)
noxTeamUpdate(RR, R); //Îáíîâëåíèå ÈÌÅÍÈ òèìû íà êëèåíòàõ - ïîñëå ÷åãî èìÿ òèìû ó êëèåíòîâ óæå íå äåôîëòíîå, à èìåííî òî, ÷òî ïðèøëî ñ ñåðâåðà
lua_pushlightuserdata(L,R);
return 1;
}
int teamScore(lua_State *L)
{
void *Team=teamGetByLua(L);
int *Ret=(int *)(((char*)Team)+0x34);
lua_settop(L,2);
lua_pushinteger(L,*Ret);
if (lua_type(L,2)!=LUA_TNIL)
{
*Ret=lua_tointeger(L,2);
netSendTeamFrags(Team,*Ret);
}
return 1;
}
int teamName(lua_State *L)
{
void *Team=teamGetByLua(L);
return 1;
}
int playerScore(lua_State *L)
{
if (
(lua_type(L,1)!=LUA_TLIGHTUSERDATA)
)
{
lua_pushstring(L,"wrong args!");
lua_error_(L);
}
DWORD *DW=(DWORD*)lua_touserdata(L,1);
if (0==(DW[2] & 0x4))
{
lua_pushstring(L,"wrong args: unit is not a player!");
lua_error_(L);
}
void **P=(void **)(((char*)lua_touserdata(L,1))+0x2EC);
P=(void**)(((char*)*P)+0x114);
int *Ret=(int *)(((char*)*P)+0x858);
lua_settop(L,2);
lua_pushinteger(L,*Ret);
if (lua_type(L,2)!=LUA_TNIL)
{
*Ret=lua_tointeger(L,2);
netReportScore(lua_touserdata(L,1));
}
return 1;
}
int teamAssign(lua_State *L)
{
if (lua_type(L,1)==LUA_TTABLE)
{
lua_getfield(L,1,"team");
if (
(lua_type(L,-1)!=LUA_TLIGHTUSERDATA) &&
(lua_type(L,-1)!=LUA_TNUMBER)
)
{
lua_pushstring(L,"wrong team args!");
lua_error_(L);
}
pTeam *Team=0;
if (lua_type(L,-1)==LUA_TLIGHTUSERDATA)
{
Team=(pTeam*)lua_touserdata(L,-1);
void *Test=noxGetTeamFirst();
for (;Test!=NULL;Test=noxGetTeamNext(Test))
{
if (Test==Team)
break;
}
if (Test==NULL)
{
lua_pushstring(L,"wrong args - not a team!");
lua_error_(L);
}
}
else
{
Team=(pTeam*)noxGetTeamByN(lua_tointeger(L,-1));
if (Team==NULL)
{
lua_pushstring(L,"wrong args: wrong team N!");
lua_error_(L);
}
}
lua_getfield(L,1,"player");
if (
(lua_type(L,-1)!=LUA_TLIGHTUSERDATA)
)
{
lua_pushstring(L,"wrong player args!");
lua_error_(L);
}
DWORD *DW=(DWORD*)lua_touserdata(L,-1);
if (0==(DW[2] & 0x4))
{
lua_pushstring(L,"wrong args: unit is not a player!");
lua_error_(L);
}
void **PP=(void **)(((char*)lua_touserdata(L,-1))+0x2EC);
PP=(void**)(((char*)*PP)+0x114);
byte *P=(byte*)(*PP);
if(((*((short*)(P+0xE60)))&0x1)==1)
{
lua_pushstring(L,"wrong args: player is observer!");
lua_error_(L);
}
int NetCode=*((short*)(P+0x80C));
byte *Common=(byte *)netCommonByCode(NetCode);
int TeamId=*(Common+4);
void *TeamTest=NULL;
TeamTest=(byte *)noxGetTeamByN(TeamId);
if(TeamTest!=NULL)
{
noxTeamChange((void*) Common, (void*) Team, NetCode, 1);
}
else
{
noxCreateAtImpl(Team->teamId, (void*)Common, 1, NetCode, 1);
}
}
return 1;
}
void __cdecl onDeathmatchFrag(void *Victim,void *Attacker,void *A,void *B)
{
int Top=lua_gettop(L);
do
{
getServerVar("onDeathmatchFrag");
if (!lua_isfunction(L,-1))
break;
if (Victim==NULL)
lua_pushnil(L);
else
lua_pushlightuserdata(L,Victim);
if (Attacker==NULL)
lua_pushnil(L);
else
lua_pushlightuserdata(L,Attacker);
if (A==NULL)
lua_pushnil(L);
else
lua_pushlightuserdata(L,A);
if (B==NULL)
lua_pushnil(L);
else
lua_pushlightuserdata(L,B);
lua_pcall(L,4,1,0);
if (lua_type(L,-1)==LUA_TNIL ||
(lua_type(L,-1)==LUA_TBOOLEAN && (0==lua_toboolean(L,-1)))
)
break;
lua_settop(L,Top);
return;
}
while(0);
lua_settop(L,Top);
playerAddFragDeathmatch(Victim,Attacker,A,B);
}
}
int teamAutoAssign(lua_State *L)
{
playersListL(L); //1 - table
if(lua_type(L, -1)==LUA_TTABLE)
{
std::deque<void*> players;
int i=1;
while(true)
{
lua_pushinteger(L, i);
lua_gettable(L, -2);
if(lua_type(L, -1)!=LUA_TLIGHTUSERDATA)
break;
players.push_back(lua_touserdata(L, -1));
i++;
lua_remove(L, -1);
}
lua_remove(L,-1);
random_shuffle(players.begin(), players.end());
std::deque<void*> teamsList;
if(noxGetTeamFirst()==NULL)
return 1;
teamsList.push_back(noxGetTeamFirst());
while(true)
{
if(noxGetTeamNext(teamsList.back())!=NULL)
teamsList.push_back(noxGetTeamNext(teamsList.back()));
else
break;
}
random_shuffle(teamsList.begin(), teamsList.end());
while(!players.empty())
{
std::deque<void*> teams(teamsList);
if(teams.empty()==true)
break;
for (pTeam *Team=(pTeam*)teams.front();Team!=NULL;Team=(pTeam*)teams.front())
{
/*lua_newtable(L);
lua_pushlightuserdata(L, Team);
lua_setfield(L, -2, "team");
lua_pushlightuserdata(L, players.front());
lua_setfield(L, -2, "player");*/
void **PP=(void **)(((char*)players.front())+0x2EC);
PP=(void**)(((char*)*PP)+0x114);
byte *P=(byte*)(*PP);
if(((*((short*)(P+0xE60)))&0x1)==0) //Ïðîâåðêà íà îáñåðâ
{
int NetCode=*((short*)(P+0x80C));
byte *Common=(byte *)netCommonByCode(NetCode);
int TeamId=*(Common+4);
void *TeamTest=NULL;
TeamTest=(byte *)noxGetTeamByN(TeamId);
if(TeamTest!=NULL)
{
noxTeamChange((void*) Common, (void*) Team, NetCode, 1);
}
else
{
noxCreateAtImpl(Team->teamId, (void*)Common, 1, NetCode, 1);
}
}
players.pop_front();
teams.pop_front();
if(players.empty())
break;
if(teams.empty())
break;
}
}
}
return 1;
}
extern int httpGet(lua_State *L);
extern void InjectOffs(DWORD Addr,void *Fn);
extern void InjectJumpTo(DWORD Addr,void *Fn);
extern "C" void scoreInit(lua_State *L);
void scoreInit(lua_State *L)
{
ASSIGN(serverFlagsClear,0x00417D70);
ASSIGN(serverFlagsSet,0x00417D50);
ASSIGN(netReportScore,0x004D8EF0);
ASSIGN(noxTeamCanPlayGame,0x0040A8A0);
ASSIGN(playerAddFragDeathmatch,0x0054D980);
ASSIGN(noxGetTeamFirst,0x00418B10);
ASSIGN(noxGetTeamNext,0x00418B60);
ASSIGN(noxGetTeamByN,0x00418AB0);
ASSIGN(netSendTeamFrags,0x00419090);
ASSIGN(noxTeamCreate,0x004186D0);
ASSIGN(noxTeamDelete,0x00418F20);
ASSIGN(noxTeamUpdate,0x00418CD0);
ASSIGN(noxCreateAtImpl,0x004191D0);
ASSIGN(noxTeamChange,0x004196D0);
ASSIGN(teamSendTeam,0x004184D0);
ASSIGN(netCommonByCode,0x00418C80);
ASSIGN(noxTeamDefaultName,0x00418C20);
ASSIGN(noxNetStructList, 0x0097EC60);
InjectJumpTo(0x0040A8A0,teamCanPlayGame);
InjectOffs(0x0054D588+1,onDeathmatchFrag);
registerserver("playerScore",&playerScore);
registerserver("teamScore",&teamScore);
registerserver("teamGet",&teamGet);
registerserver("teamCreateDefault",&teamCreateDefaultL);
registerserver("teamCreate",&teamCreate);
registerserver("teamDelete",&teamDelete);
registerserver("teamAssign",&teamAssign);
registerserver("teamAutoAssign",&teamAutoAssign);
registerclient("playerInfo",&playerInfo);
registerclient("playerGetByName",&playerGetByName);
registerclient("playerGetByWOL",&playerGetByWOL);
registerclient("httpGet",&httpGet);
registerclient("scoreFragLimit", &scoreFragLimitL);
registerclient("scoreTimeLimit", &scoreTimeLimitL);
}
void teamCreateDefault(int minTeamsParam=0, bool doNotSetRestriction=false)
{
if(minTeamsParam>0 && minTeamsParam<17)
{
minTeams=minTeamsParam;
if(doNotSetRestriction==false)
restrictTeams=true;
}
else if(minTeamsParam<0)
{
minTeams=2;
restrictTeams=false;
return;
}
for(int i=1; i<=minTeams; i++)
{
if(noxGetTeamByN(i)==NULL)
{
void *R=NULL;
R=noxTeamCreate(0);
serverFlagsSet(4);/// âêëþ÷àåì òèìû
wchar_t* RR=NULL;
RR=noxTeamDefaultName(((byte*)R)[0x38]);//Ïîëó÷àåì äåôîëòíîå íàçâàíèå òèìû - òî ÷òî çàïèñàíî â CSF-êå, íà îñíîâàíèè öâåòà òèìû
memcpy(R, RR, 0x28);
((byte*)R)[0x44]=1;
teamSendTeam(R);
}
}
if(noxTeamNumber()>minTeams)
{
void *Test=noxGetTeamFirst();
for(int i=1;Test!=NULL;Test=noxGetTeamNext(Test))
{
if(i>minTeams)
{
noxTeamDelete(Test,1);
}
i++;
}
return;
}/*
while(noxTeamNumber()<2)
{
void *R=NULL;
R=noxTeamCreate(0);
serverFlagsSet(4);/// âêëþ÷àåì òèìû
wchar_t* RR=NULL;
RR=noxTeamDefaultName(((byte*)R)[0x38]);//Ïîëó÷àåì äåôîëòíîå íàçâàíèå òèìû - òî ÷òî çàïèñàíî â CSF-êå, íà îñíîâàíèè öâåòà òèìû
memcpy(R, RR, 0x28);
((byte*)R)[0x44]=1;
teamSendTeam(R);
}*/
return;
/*
for(int i=8;i>0;i--)
{
void* Team=NULL;
Team=noxGetTeamByN(i);
if(Team!=NULL)
{
noxTeamDelete(Team,1);
}
if(i==3)
{
serverFlagsClear(4);
}
if(i<3)
{
void *R=NULL;
R=noxTeamCreate(i);
serverFlagsSet(4);
char teamName[0x14]={0};
itoa(i,teamName,10);
mbstowcs((wchar_t*)R,teamName,0x14);
wchar_t* RR = (wchar_t*)R;
((byte*)R)[0x44]=1;
teamSendTeam(R);
noxTeamUpdate(RR, R);
}
}*/
}