-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathgsc_player.cpp
801 lines (677 loc) · 23.1 KB
/
gsc_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
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
#include "gsc_player.hpp"
#if COMPILE_PLAYER == 1
#if COD_VERSION == COD2_1_0
int playerStates = 0x086F1480; // search 'winner'
int sizeOfPlayer = 0x28A4;
#elif COD_VERSION == COD2_1_2
int playerStates = 0x08705480; // as in game initialisation "------- Game Initializati"
int sizeOfPlayer = 0x28A4;
// memset(&playerStates_8705480, 0, 0xA2900u);
// then we need a bit math: 0xA2900 / 64 = 0x28A4
#elif COD_VERSION == COD2_1_3
// 8716558 pointed on that!! and that i found in setorigin() with ida decompiler
// looked it up and it points to game_initialization_8109096()
int playerStates = 0x087a2500;
int sizeOfPlayer = 0x28A4;
#elif COD_VERSION == COD4_1_7
/*
memset((void *)0x841F260, 0, 0x9D000u);
v836f6c4 = 138539616;
v836f8a4 = *(_DWORD *)(v84bc268 + 12);
memset((void *)0x84BC3A0, 0, 0xC6100u); // bottom = playerstates
*/
int playerStates = 0x084BC3A0;
int sizeOfPlayer = 0x3184;
#elif COD_VERSION == COD4_1_7_L
int playerStates = 0x084BD120;
int sizeOfPlayer = 0x3184;
#else
#warning int playerStates int sizeOfPlayer
int playerStates = NULL;
int sizeOfPlayer = NULL;
#endif
#if COD_VERSION == COD2_1_0
int gentities = 0x08665480;
int gentities_size = 560;
#elif COD_VERSION == COD2_1_2
int gentities = 0x08679380;
int gentities_size = 560;
#elif COD_VERSION == COD2_1_3
int gentities = 0x08716400;
int gentities_size = 560;
#elif COD_VERSION == COD4_1_7
int gentities = 0x0841F260;
int gentities_size = 628;
#elif COD_VERSION == COD4_1_7_L
int gentities = 0x0841FFE0;
int gentities_size = 628;
#else
#warning int gentities int gentities_size
int gentities = NULL;
int gentities_size = NULL;
#endif
#define PLAYERSTATE(playerid) (playerStates + playerid * sizeOfPlayer)
#if COD_VERSION == COD2_1_0 || COD_VERSION == COD2_1_2 || COD_VERSION == COD2_1_3
#define PLAYERSTATE_VELOCITY(playerid) (PLAYERSTATE(playerid) + 0x20)
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
#define PLAYERSTATE_VELOCITY(playerid) (PLAYERSTATE(playerid) + 40)
#else
#warning NO PLAYERSTATE_VELOCITY!
#define PLAYERSTATE_VELOCITY(playerid) 0
#endif
#if COD_VERSION == COD2_1_0
int playerinfo_base = 0x0841FB0C;
int playerinfo_size = 0x78F14;
#elif COD_VERSION == COD2_1_2
int playerinfo_base = 0x0842200C;
int playerinfo_size = 0x79064;
#elif COD_VERSION == COD2_1_3
int playerinfo_base = 0x0842308C;
int playerinfo_size = 0xB1064;
#elif COD_VERSION == COD4_1_7
int playerinfo_base = 0x090B420C;
int playerinfo_size = 0x2958F;
#elif COD_VERSION == COD4_1_7_L
int playerinfo_base = 0x090B4F8C;
int playerinfo_size = 0x2958F;
#else
#warning PLAYERBASE() got no working addresses
int playerinfo_base = 0x0;
int playerinfo_size = 0x0;
#endif
#if COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
#define PLAYERBASE(playerid) (playerinfo_base + playerid * playerinfo_size)
#else
#define PLAYERBASE(playerid) (*(int*)(playerinfo_base) + playerid * playerinfo_size)
#endif
int clientaddress_to_num(int address) {
return (address - playerStates) / sizeOfPlayer;
}
int gentityaddress_to_num(int client) {
return (client - gentities) / gentities_size;
}
void gsc_player_velocity_set(int id) {
float velocity[3];
if ( ! stackGetParams("v", &velocity)) {
printf("scriptengine> wrongs args for gsc_player_velocity_add(vector velocity);\n");
stackPushUndefined();
return;
}
float *player_0_velocity_x = (float *)(PLAYERSTATE_VELOCITY(id) + 0);
float *player_0_velocity_y = (float *)(PLAYERSTATE_VELOCITY(id) + 4);
float *player_0_velocity_z = (float *)(PLAYERSTATE_VELOCITY(id) + 8);
*player_0_velocity_x = velocity[0];
*player_0_velocity_y = velocity[1];
*player_0_velocity_z = velocity[2];
stackReturnInt(1);
}
void gsc_player_clientuserinfochanged(int id)
{
stackPushInt(changeClientUserinfo(id));
}
void gsc_player_velocity_add(int id) {
float velocity[3];
if ( ! stackGetParams("v", &velocity)) {
printf("scriptengine> wrongs args for gsc_player_velocity_add(vector velocity);\n");
stackPushUndefined();
return;
}
float *player_0_velocity_x = (float *)(PLAYERSTATE_VELOCITY(id) + 0);
float *player_0_velocity_y = (float *)(PLAYERSTATE_VELOCITY(id) + 4);
float *player_0_velocity_z = (float *)(PLAYERSTATE_VELOCITY(id) + 8);
*player_0_velocity_x += velocity[0];
*player_0_velocity_y += velocity[1];
*player_0_velocity_z += velocity[2];
stackReturnInt(1);
}
void gsc_get_userinfo(int id)
{
char* key;
char* val;
if(!stackGetParamString(0, &key))
{
printf("First param needs to be a string for get_userinfo\n");
stackPushUndefined();
return;
}
int entity = PLAYERBASE(id);
val = Info_ValueForKey((char*)entity+12, key);
if(strlen(val))
stackPushString(val);
else
stackPushUndefined();
}
void gsc_set_userinfo(int id)
{
char* key;
char* value;
if(!stackGetParamString(0, &key))
{
printf("First param needs to be a string for get_userinfo\n");
stackPushUndefined();
return;
}
if(!stackGetParamString(1, &value))
{
printf("second param needs to be a string for get_userinfo\n");
stackPushUndefined();
return;
}
int entity = PLAYERBASE(id);
Info_SetValueForKey((char*)entity + 12, key, value);
stackPushUndefined();
}
void gsc_player_velocity_get(int id) {
//int currentPlayer = playerStates + id * sizeOfPlayer;
float *vectorVelocity = (float *)PLAYERSTATE_VELOCITY(id); // (currentPlayer + 0x20);
stackReturnVector(vectorVelocity);
}
// aimButtonPressed (toggleads or +speed/-speed)
void gsc_player_button_ads(int id) {
int currentPlayer = playerStates + id * sizeOfPlayer;
unsigned char *aim_address = (unsigned char *)(currentPlayer + 0x26CD);
int aimButtonPressed = *aim_address & 0xF0; // just the first 4 bits tell the state
stackReturnInt(aimButtonPressed);
}
void gsc_player_button_left(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26FD);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FA7);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int leftButtonPressed = (*aim_address & 0x81)==0x81;
stackReturnInt(leftButtonPressed);
}
void gsc_player_button_right(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26FD);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FA7);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int rightButtonPressed = (*aim_address & 0x7F)==0x7F;
stackReturnInt(rightButtonPressed);
}
void gsc_player_button_forward(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26FC);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FA6);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int forwardButtonPressed = (*aim_address & 0x7F)==0x7F;
stackReturnInt(forwardButtonPressed);
}
void gsc_player_button_back(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26FC);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FA6);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int backButtonPressed = (*aim_address & 0x81)==0x81;
stackReturnInt(backButtonPressed);
}
void gsc_player_button_leanleft(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26E8);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FB4);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int leanleftButtonPressed = (*aim_address & 0x40)==0x40;
stackReturnInt(leanleftButtonPressed);
}
void gsc_player_button_leanright(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26E8);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FB4);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int leanrightButtonPressed = (*aim_address & 0x80)==0x80;
stackReturnInt(leanrightButtonPressed);
}
void gsc_player_button_jump(int id) {
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x26E9);
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(id) + 0x2FB5);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int jumpButtonPressed = (*aim_address & 0x04)==0x04;
stackReturnInt(jumpButtonPressed);
}
/*
CoD2 = 26E8 == leanleft:40 leanright:80
CoD4 = 26E9 == jump:04
CoD2 = 26FC == forward:7f backward:81
CoD2 = 26FD == left:81 right:7f
CoD4 = 2FA6 == forward:7f backward:81
CoD4 = 2FA7 == left:81 right:7f
CoD4 = 2FB4 == leanleft:40 leanright:80
CoD4 = 2FB5 == jump:04
*/
void gsc_player_stance_get(int id) {
int entity = gentities + id * gentities_size;
unsigned char *stance_address = (unsigned char *)(entity + 8);
int code = *stance_address & 0x0F; // just the last 4 bits tell the state
char *stance = "";
switch (code) {
case 0: stance = "stand"; break; // also in spec
case 2: stance = "stand"; break;
case 4: stance = "duck"; break;
case 6: stance = "duck"; break;
case 8: stance = "lie"; break;
case 10: stance = "lie"; break;
default: printf("unknown stance for player id=%d, code=%d\n", id, code);
}
stackPushString(stance);
}
void gsc_player_spectatorclient_get(int id) {
int spectatorClient = *(unsigned char *)(PLAYERSTATE(id) + 0xCC);
//printf("spectator client: %x=%d\n", entity, spectatorClient);
// ups, its ALWAYS returning a real id
// when i have 2 bots, then i got id 2, when i spec "myself" it will return 2, also when i play myself
//if ( ! spectatorClient)
// return stackPushUndefined();
stackPushEntity(gentities + spectatorClient * gentities_size);
}
void gsc_player_getip(int id) {
#if COD_VERSION == COD2_1_0
int info_ip_offset = 0x6E5C8;
#elif COD_VERSION == COD2_1_2
int info_ip_offset = 0x6E6D8;
#elif COD_VERSION == COD2_1_3
int info_ip_offset = 0x6E6D8;
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
int info_ip_offset = 0x9;
#else
#warning gsc_player_getip() got no working addresses
int info_ip_offset = 0x0;
#endif
char tmp[64];
unsigned int ip_a, ip_b, ip_c, ip_d;
#if COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
char iphex[9];
snprintf(iphex, 9, "%08x", ((int *)PLAYERBASE(id))[info_ip_offset]);
sscanf(iphex, "%2x%2x%2x%2x", &ip_d, &ip_c, &ip_b, &ip_a);
#else
int info_player = PLAYERBASE(id);
ip_a = *(unsigned char *)(info_player + info_ip_offset + 0);
ip_b = *(unsigned char *)(info_player + info_ip_offset + 1); // dafuq, its +1 but in IDA its +4 step :S
ip_c = *(unsigned char *)(info_player + info_ip_offset + 2);
ip_d = *(unsigned char *)(info_player + info_ip_offset + 3);
//int port = *(unsigned char *)(info_player + info_ip_offset + 16);
//snprintf(tmp, 64, "%d.%d.%d.%d:%d", ip_a, ip_b, ip_c, ip_d, port);
#endif
snprintf(tmp, 64, "%d.%d.%d.%d", ip_a, ip_b, ip_c, ip_d);
stackPushString(tmp);
}
void gsc_player_getping(int id) {
#if COD_VERSION == COD2_1_0
int info_ping_offset = 0x6E5A4;
#elif COD_VERSION == COD2_1_2
int info_ping_offset = 0x6E6B4;
#elif COD_VERSION == COD2_1_3
int info_ping_offset = 0x6E6B4;
#elif COD_VERSION == COD4_1_7 || COD_VERSION == COD4_1_7_L
int info_ping_offset = 0x804EC;
#else
#warning gsc_player_getport() got no working addresses
int info_ping_offset = 0x0;
#endif
int ping = *(unsigned int *)(PLAYERBASE(id) + info_ping_offset);
stackPushInt(ping);
}
void gsc_player_ClientCommand(int id) {
stackPushInt(ClientCommand(id));
}
int getSVSTime()
{
#if COD_VERSION == COD2_1_0
int info_start = *(int *)0x0841FB04;
#elif COD_VERSION == COD2_1_2
int info_start = *(int *)0x08422004;
#elif COD_VERSION == COD2_1_3
int info_start = *(int *)0x08423084;
#else
#warning getSVSTime() got no working addresses
int info_start = *(int *)0x0;
#endif
return info_start;
}
void gsc_player_getLastConnectTime(int id) {
#if COD_VERSION == COD2_1_0
int info_connecttime_offset = 0x20D14;
#elif COD_VERSION == COD2_1_2
int info_connecttime_offset = 0x20E24;
#elif COD_VERSION == COD2_1_3
int info_connecttime_offset = 0x20E24;
#else
#warning gsc_player_getLastConnectTime() got no working addresses
int info_connecttime_offset = 0x0;
#endif
int lastconnect = getSVSTime() - *(unsigned int *)(PLAYERBASE(id) + info_connecttime_offset);
stackPushInt(lastconnect);
}
int getLastPacketTime(int id) {
#if COD_VERSION == COD2_1_0
int info_lastmsg_offset = 0x20D10;
#elif COD_VERSION == COD2_1_2
int info_lastmsg_offset = 0x20E20;
#elif COD_VERSION == COD2_1_3
int info_lastmsg_offset = 0x20E20;
#else
#warning getLastPacketTime() got no working addresses
int info_lastmsg_offset = 0x0;
#endif
return (PLAYERBASE(id) + info_lastmsg_offset);
}
void gsc_player_getLastMSG(int id) {
int lastmsg = getSVSTime() - *(unsigned int *)getLastPacketTime(id);
stackPushInt(lastmsg);
}
void gsc_player_getclientstate(int id) {
int info_player = PLAYERBASE(id);
stackPushInt(*(int*)info_player);
}
int getAddressType(int id) {
#if COD_VERSION == COD2_1_0
int info_addresstype_offset = 0x6E5C4;
#elif COD_VERSION == COD2_1_2
int info_addresstype_offset = 0x6E6D4;
#elif COD_VERSION == COD2_1_3
int info_addresstype_offset = 0x6E6D4;
#else
#warning gsc_player_addresstype() got no working addresses
int info_addresstype_offset = 0x0;
#endif
int addrtype = *(unsigned int *)(PLAYERBASE(id) + info_addresstype_offset);
}
void gsc_player_addresstype(int id) {
stackPushInt(getAddressType(id));
}
void gsc_player_renameclient(int id) {
char * key;
if ( ! stackGetParams("s", &key)) {
printf("scriptengine> ERROR: gsc_player_renameclient(): param \"key\"[1] has to be an string!\n");
stackPushUndefined();
return;
}
int info_player = PLAYERBASE(id);
Info_SetValueForKey((char *)(info_player + 12), "name", key);
char * name = (char *)(info_player + 134216);
memcpy(&name[0], key, 32);
name[31] = '\0';
printf("name = %s\n", name);
stackPushInt(1);
}
void gsc_player_outofbandprint(int id) {
char* cmd; // print\ninsert test message here!!!\n
if ( ! stackGetParams("s", &cmd)) {
printf("scriptengine> ERROR: gsc_player_outofbandprint(): param \"cmd\"[1] has to be an string!\n");
stackPushUndefined();
return;
}
#if COD_VERSION == COD2_1_0
int remoteaddress_offset = 452036;
#else
int remoteaddress_offset = 452308;
#endif
int info_player = PLAYERBASE(id);
netadr_t * from = (netadr_t*)(info_player + remoteaddress_offset);
NET_OutOfBandPrint(0, *from, cmd); // 0 = SERVER, 1 = CLIENT
stackReturnInt(1);
}
void gsc_player_connectionlesspacket(int id) {
char* cmd; // rcon pass status
if ( ! stackGetParams("s", &cmd)) {
printf("scriptengine> ERROR: gsc_player_connectionlesspacket(): param \"cmd\"[1] has to be an string!\n");
stackPushUndefined();
return;
}
char message[1024];
message[0] = -1;
message[1] = -1;
message[2] = -1;
message[3] = -1;
message[4] = 0;
strcat(message, cmd);
msg_t msg;
msg.data = message;
msg.maxsize = 131072;
msg.cursize = strlen(msg.data)+1;
msg.readcount = 0;
msg.overflowed = false;
msg.bit = 0;
#if COD_VERSION == COD2_1_0
int remoteaddress_offset = 452036;
#else
int remoteaddress_offset = 452308;
#endif
int info_player = PLAYERBASE(id);
netadr_t * from = (netadr_t*)(info_player + remoteaddress_offset);
SV_ConnectionlessPacket(*from, &msg);
stackReturnInt(1);
}
void gsc_player_resetNextReliableTime(int id) {
#if COD_VERSION == COD2_1_0
int offset = 134412;
#else
int offset = 134684;
#endif
*(int *)(PLAYERBASE(id) + offset) = 0;
stackPushInt(0);
}
void gsc_player_ismantling(int id) {
int flags = PLAYERSTATE(id) + 0xc;
if(*(int*)flags & 4) //oi m8 im mantling
stackPushInt(1);
else
stackPushInt(0);
}
void gsc_player_isonladder(int id) {
int flags = PLAYERSTATE(id) + 0xc;
if(*(int*)flags & 32)
stackPushInt(1);
else
stackPushInt(0);
}
typedef long double (*calc_player_speed_t)(int a1, int a2);
#if COD_VERSION == COD2_1_0
calc_player_speed_t calc_player_speed = (calc_player_speed_t)0x080DF534;
#elif COD_VERSION == COD2_1_2
calc_player_speed_t calc_player_speed = (calc_player_speed_t)0x080E1B14;
#elif COD_VERSION == COD2_1_3
calc_player_speed_t calc_player_speed = (calc_player_speed_t)0x080E1C58;
#else
#warning calc_player_speed_t calc_player_speed = NULL;
calc_player_speed_t calc_player_speed = (calc_player_speed_t)NULL;
#endif
typedef void (*calc_client_speed_t)(int client);
#if COD_VERSION == COD2_1_0
calc_client_speed_t calc_client_speed = (calc_client_speed_t)0x0811FB7A;
#elif COD_VERSION == COD2_1_2
calc_client_speed_t calc_client_speed = (calc_client_speed_t)0x08121EAE;
#elif COD_VERSION == COD2_1_3
calc_client_speed_t calc_client_speed = (calc_client_speed_t)0x0812200A;
#else
#warning calc_client_speed_t calc_client_speed = NULL;
calc_client_speed_t calc_client_speed = (calc_client_speed_t)NULL;
#endif
float player_movespeedscale[64] = {0};
int player_g_speed[64] = {0};
int player_g_gravity[64] = {0};
long double hook_player_setmovespeed(int client, int a2) {
float speed = calc_player_speed(client, a2);
int id = clientaddress_to_num(*(int*)client);
if(speed > 0 && player_movespeedscale[id] > 0 && player_movespeedscale[id] != 1)
return speed * player_movespeedscale[id];
else
return speed;
}
void gsc_player_setmovespeedscale(int id) {
float scale;
if ( ! stackGetParams("f", &scale)) {
printf("scriptengine> ERROR: gsc_player_setmovespeedscale(): param \"scale\"[1] has to be an float!\n");
stackPushUndefined();
return;
}
if (scale <= 0) {
printf("scriptengine> ERROR: gsc_player_setmovespeedscale(): param \"scale\"[1] must be above zero!\n");
stackPushUndefined();
return;
}
player_movespeedscale[id] = scale;
stackPushInt(1);
}
void gsc_player_setg_gravity(int id) {
int gravity;
if ( ! stackGetParams("i", &gravity)) {
printf("scriptengine> ERROR: gsc_player_setg_gravity(): param \"gravity\"[1] has to be an int!\n");
stackPushUndefined();
return;
}
if (gravity < 0) {
printf("scriptengine> ERROR: gsc_player_setg_gravity(): param \"gravity\"[1] must be equal or above zero!\n");
stackPushUndefined();
return;
}
player_g_gravity[id] = gravity;
stackPushInt(1);
}
void gsc_player_setg_speed(int id) {
int speed;
if ( ! stackGetParams("i", &speed)) {
printf("scriptengine> ERROR: gsc_player_setg_speed(): param \"speed\"[1] has to be an int!\n");
stackPushUndefined();
return;
}
if (speed < 0) {
printf("scriptengine> ERROR: gsc_player_setg_speed(): param \"speed\"[1] must be equal or above zero!\n");
stackPushUndefined();
return;
}
player_g_speed[id] = speed;
stackPushInt(1);
}
void hook_player_g_speed(int client) {
int player = *(int *)(client + 344);
int id = gentityaddress_to_num(client);
int newgravity = player_g_gravity[id];
if(newgravity > 0)
*(int *)(player + 72) = newgravity;
int newspeed = player_g_speed[id];
if(newspeed > 0)
*(int *)(player + 80) = newspeed;
calc_client_speed(client);
}
void gsc_player_setweaponfiremeleedelay(int id) {
int delay;
if ( ! stackGetParams("i", &delay)) {
printf("scriptengine> ERROR: gsc_player_setweaponfiremeleedelay(): param \"delay\"[1] has to be an int!\n");
stackPushUndefined();
return;
}
if(delay < 0) {
printf("scriptengine> ERROR: gsc_player_setweaponfiremeleedelay(): param \"delay\"[1] must be equal or above zero!\n");
stackPushUndefined();
return;
}
int state = PLAYERSTATE(id);
int* weapondelay = (int *)(state + 0x34);
*weapondelay = delay;
*(int *)(state + 216) = 11;
}
// entity functions (could be in own file, but atm not many pure entity functions)
void gsc_entity_setalive(int id) { // as in isAlive?
int isAlive;
if ( ! stackGetParams("i", &isAlive)) {
printf("scriptengine> ERROR: gsc_player_setalive(): param \"isAlive\"[1] has to be an integer!\n");
stackPushUndefined();
return;
}
*(char *)(gentities + gentities_size*id + 353) = isAlive;
stackReturnInt(1);
}
void gsc_entity_setbounds(int id) {
float width, height;
if ( ! stackGetParams("ff", &width, &height)) {
printf("scriptengine> ERROR: please specify width and height to gsc_entity_setbounds()\n");
stackPushUndefined();
return;
}
*(float*)(gentities + gentities_size*id + 280) = height;
*(float*)(gentities + gentities_size*id + 276) = width;
*(float*)(gentities + gentities_size*id + 272) = width;
*(float*)(gentities + gentities_size*id + 264) = -width;
*(float*)(gentities + gentities_size*id + 260) = -width;
printf("id=%d height=%f width=%f\n", id, height, width);
stackReturnInt(1);
}
void gsc_free_slot() {
int id = 0;
if(!stackGetParamInt(0, &id)) {
printf("Param 0 needs to be an int for free_slot\n");
stackPushUndefined();
return;
}
int entity = PLAYERBASE(id);
*(int*)entity = 0; //CS_FREE
stackPushUndefined();
}
void gsc_kick_slot() {
int id;
char* msg;
char* reason;
if ( ! stackGetParams("is", &id, &msg)) {
printf("scriptengine> ERROR: gsc_kick_slot(): param \"id\"[1] has to be an int!\n");
printf("scriptengine> ERROR: gsc_kick_slot(): param \"msg\"[2] has to be an string!\n");
stackPushUndefined();
return;
}
if(getAddressType(id) == NA_LOOPBACK) {
stackReturnInt(0);
return; // host
}
#if COD_VERSION == COD2_1_0
int guid_offset = 0x765F4;
#elif COD_VERSION == COD2_1_2
int guid_offset = 0x76704;
#elif COD_VERSION == COD2_1_3
int guid_offset = 0xAE704;
#else
#warning gsc_kick_slot() got no working addresses for guid_offset
int guid_offset = 0x0;
#endif
int entity = PLAYERBASE(id);
char* name = Info_ValueForKey((char*)entity+12, "name"); // read before drop client resets the userinfo
int guid = *(int*)(entity + guid_offset);
SV_DropClient(entity, msg);
int * lastPacketTime = (int*)getLastPacketTime(id);
*lastPacketTime = getSVSTime(); // in case there is a funny zombie (copied from Q3)
if(!stackGetParamString(2, &reason)) {
Com_Printf("%s (guid %i) was kicked\n", name, guid);
stackReturnInt(1);
return;
}
Com_Printf("%s (guid %i) was kicked for %s\n", name, guid, reason);
stackReturnInt(1);
}
#endif