forked from kungfooman/libcod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsc_player.cpp
executable file
·638 lines (567 loc) · 19.8 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
#include "gsc_player.hpp"
#if COMPILE_PLAYER == 1
#if COD2_VERSION == COD2_VERSION_1_0
int playerStates = 0x086F1480; // search 'winner'
int sizeOfPlayer = 0x28A4;
#elif COD2_VERSION == COD2_VERSION_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 COD2_VERSION == COD2_VERSION_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;
#else
#warning int playerStates int sizeOfPlayer
int playerStates = NULL;
int sizeOfPlayer = NULL;
#endif
#if COD2_VERSION == COD2_VERSION_1_0
int gentities = 0x08665480;
int gentities_size = 560;
#elif COD2_VERSION == COD2_VERSION_1_2
int gentities = 0x08679380;
int gentities_size = 560;
#elif COD2_VERSION == COD2_VERSION_1_3
int gentities = 0x08716400;
int gentities_size = 560;
#else
#warning int gentities int gentities_size
int gentities = NULL;
int gentities_size = NULL;
#endif
#define PLAYERSTATE(playerid) (playerStates + playerid * sizeOfPlayer)
#if COD2_VERSION == COD2_VERSION_1_0 || COD2_VERSION == COD2_VERSION_1_2 || COD2_VERSION == COD2_VERSION_1_3
#define PLAYERSTATE_VELOCITY(playerid) (PLAYERSTATE(playerid) + 0x20)
#elif COD_VERSION == COD4_1_7
#define PLAYERSTATE_VELOCITY(playerid) (PLAYERSTATE(playerid) + 40)
#else
#warning NO PLAYERSTATE_VELOCITY!
#define PLAYERSTATE_VELOCITY(playerid) 0
#endif
/*
======
ENTITY
======
*/
void EntCmd_setBounds(int a1) {
float w, h;
stackGetParamFloat(0, &w);
stackGetParamFloat(1, &h);
int base = gentities + gentities_size * a1;
*(float*)(base + 280) = h;
*(float*)(base + 276) = w;
*(float*)(base + 272) = w;
*(float*)(base + 264) = -w;
*(float*)(base + 260) = -w;
}
void EntCmd_setFloat(int self) {
int off;
stackGetParamInt(0, &off);
float f;
stackGetParamFloat(1, &f);
int base = gentities + self * gentities_size;
*(float*)(base + off) = f;
}
void EntCmd_getFloat(int self) {
int off;
stackGetParamInt(0, &off);
int base = gentities + self * gentities_size;
stackPushFloat(*(float*)(base+off));
}
int gsc_player_velocity_set()
{
int playerid;
float velocity_x, velocity_y, velocity_z;
if (stackGetNumberOfParams() < 5) // function, playerid, x, y, z
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
if (!stackGetParamFloat(2, &velocity_x))
{
printf_hide("scriptengine> ERROR: closer(): param \"velocity_x\"[2] has to be an float!\n");
return stackReturnInt(0);
}
if (!stackGetParamFloat(3, &velocity_y))
{
printf_hide("scriptengine> ERROR: closer(): param \"velocity_y\"[3] has to be an float!\n");
return stackReturnInt(0);
}
if (!stackGetParamFloat(4, &velocity_z))
{
printf_hide("scriptengine> ERROR: closer(): param \"velocity_z\"[4] has to be an float!\n");
return stackReturnInt(0);
}
//int currentPlayer = playerStates + playerid * sizeOfPlayer;
float *player_0_velocity_x = (float *)(PLAYERSTATE_VELOCITY(playerid) + 0);
float *player_0_velocity_y = (float *)(PLAYERSTATE_VELOCITY(playerid) + 4);
float *player_0_velocity_z = (float *)(PLAYERSTATE_VELOCITY(playerid) + 8);
*player_0_velocity_x = velocity_x;
*player_0_velocity_y = velocity_y;
*player_0_velocity_z = velocity_z;
// todo: let it fail if no player...
return stackReturnInt(1);
}
int gsc_player_velocity_add()
{
int playerid;
float velocity_x, velocity_y, velocity_z;
if (stackGetNumberOfParams() < 5) // function, playerid, x, y, z
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
if (!stackGetParamFloat(2, &velocity_x))
{
printf_hide("scriptengine> ERROR: closer(): param \"velocity_x\"[2] has to be an float!\n");
return stackReturnInt(0);
}
if (!stackGetParamFloat(3, &velocity_y))
{
printf_hide("scriptengine> ERROR: closer(): param \"velocity_y\"[3] has to be an float!\n");
return stackReturnInt(0);
}
if (!stackGetParamFloat(4, &velocity_z))
{
printf_hide("scriptengine> ERROR: closer(): param \"velocity_z\"[4] has to be an float!\n");
return stackReturnInt(0);
}
float *player_0_velocity_x = (float *)(PLAYERSTATE_VELOCITY(playerid) + 0);
float *player_0_velocity_y = (float *)(PLAYERSTATE_VELOCITY(playerid) + 4);
float *player_0_velocity_z = (float *)(PLAYERSTATE_VELOCITY(playerid) + 8);
//int currentPlayer = playerStates + playerid * sizeOfPlayer;
//float *player_0_velocity_x = (float *)(currentPlayer + 40);
//float *player_0_velocity_y = (float *)(currentPlayer + 44);
//float *player_0_velocity_z = (float *)(currentPlayer + 48);
//printf("z:%.2f\n", *player_0_velocity_z);
*player_0_velocity_x += velocity_x;
*player_0_velocity_y += velocity_y;
*player_0_velocity_z += velocity_z;
// todo: let it fail if no player...
return stackReturnInt(1);
}
int gsc_player_velocity_get()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
//int currentPlayer = playerStates + playerid * sizeOfPlayer;
float *vectorVelocity = (float *)PLAYERSTATE_VELOCITY(playerid); // (currentPlayer + 0x20);
return stackReturnVector(vectorVelocity);
// todo: return undefined if no player
// return stackReturnInt(1);
}
// aimButtonPressed (toggleads or +speed/-speed)
int gsc_player_button_ads()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
int currentPlayer = playerStates + playerid * sizeOfPlayer;
unsigned char *aim_address = (unsigned char *)(currentPlayer + 0x26CD);
int aimButtonPressed = *aim_address & 0xF0; // just the first 4 bits tell the state
return stackReturnInt(aimButtonPressed);
// todo: return undefined if no player
// return stackReturnInt(1);
}
int gsc_player_button_left()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26FD);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FA7);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int leftButtonPressed = (*aim_address & 0x81)==0x81;
return stackReturnInt(leftButtonPressed);
}
int gsc_player_button_right()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26FD);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FA7);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int rightButtonPressed = (*aim_address & 0x7F)==0x7F;
return stackReturnInt(rightButtonPressed);
}
int gsc_player_button_forward()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26FC);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FA6);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int forwardButtonPressed = (*aim_address & 0x7F)==0x7F;
return stackReturnInt(forwardButtonPressed);
}
int gsc_player_button_back()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26FC);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FA6);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int backButtonPressed = (*aim_address & 0x81)==0x81;
return stackReturnInt(backButtonPressed);
}
int gsc_player_button_leanleft()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26E8);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FB4);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int leanleftButtonPressed = (*aim_address & 0x40)==0x40;
return stackReturnInt(leanleftButtonPressed);
}
int gsc_player_button_leanright()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26E8);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FB4);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int leanrightButtonPressed = (*aim_address & 0x80)==0x80;
return stackReturnInt(leanrightButtonPressed);
}
int gsc_player_button_jump()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
#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(playerid) + 0x26E9);
#elif COD_VERSION == COD4_1_7
unsigned char *aim_address = (unsigned char *)(PLAYERSTATE(playerid) + 0x2FB5);
#else
#warning unsigned char *aim_address = (unsigned char *)(NULL);
unsigned char *aim_address = (unsigned char *)(NULL);
#endif
int jumpButtonPressed = (*aim_address & 0x04)==0x04;
return 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
*/
int gsc_player_state_alive_set() // as in isAlive?
{
int playerid;
int isAlive;
if (stackGetNumberOfParams() < 3) // function, playerid, isAlive
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(2, &isAlive))
{
printf_hide("scriptengine> ERROR: closer(): param \"isAlive\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
*(char *)(gentities + gentities_size*playerid + 353) = isAlive;
return stackReturnInt(0);
}
int gsc_player_stance_get()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackReturnInt(0);
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackReturnInt(0);
}
int entity = gentities + playerid * gentities_size;
unsigned char *stance_address = (unsigned char *)(entity + 8);
int stance = *stance_address & 0x0F; // just the last 4 bits tell the state
return stackReturnInt(stance);
// todo: return undefined if no player
// return stackReturnInt(1);
}
int gsc_player_spectatorclient_get()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 5 arguments to closer()\n");
return stackPushUndefined();
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackPushUndefined();
}
int entity = playerStates + playerid * sizeOfPlayer;
int spectatorClient = *(unsigned char *)(entity + 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();
return stackPushEntity(gentities + spectatorClient * gentities_size);
}
void PlayerCmd_GetUserInfoKey(int self) {
void (*SV_GetUserinfo)(int, char*, int);
*((int *)(&SV_GetUserinfo)) = 0x8092B00;
char* (*Info_ValueForKey)(char*, char*);
*((int *)(&Info_ValueForKey)) = 0x80B7FC4;
char userinfo[1024];
SV_GetUserinfo(self, userinfo, sizeof(userinfo));
if(!userinfo) {
stackPushString("");
return;
}
char* key;
stackGetParamString(0, &key);
char* value = Info_ValueForKey(userinfo, key);
if(!value)
stackPushString("");
else
stackPushString(value);
}
void PlayerCmd_GetSpectatorClients(int self) {
int entity;
int spectating;
int array = alloc_object_and_push_to_array();
//int maxclients = Cvar_VariableValue("sv_maxclients");
for(unsigned int i = 0; i < 64; i++) { //hardcoding since cba to find cvar_variablevalue or maxclients offset
entity = playerStates + i * sizeOfPlayer;
if(!*(int*)entity)
continue;
spectating = *(unsigned char *)(entity + 0xCC);
if(spectating != self)
continue;
stackPushEntity(gentities + i * gentities_size);
push_previous_var_in_array_sub();
}
}
int gsc_player_getip()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 2 arguments to gsc_player_getip()\n");
return stackPushUndefined();
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackPushUndefined();
}
#if COD2_VERSION == COD2_VERSION_1_0
int info_base = *(int *)0x0841FB0C;
int info_size = 0x78F14;
int info_ip_offset = 0x6E5C8;
int info_port_offset = 0x6E5A4;
#elif COD2_VERSION == COD2_VERSION_1_2
int info_base = *(int *)0x0842200C;
int info_size = 0x79064;
int info_ip_offset = 0x6E6D8;
int info_port_offset = 0x6E6B4;
#elif COD2_VERSION == COD2_VERSION_1_3
int info_base = *(int *)0x0842308C;
int info_size = 0xB1064;
int info_ip_offset = 0x6E6D8;
int info_port_offset = 0x6E6B4;
#else
#warning gsc_player_getip() got no working addresses
int info_base = *(int *)0x0;
int info_size = 0x0;
int info_ip_offset = 0x0;
int info_port_offset = 0x0;
#endif
int info_player = info_base + playerid * info_size;
int ip_a = *(unsigned char *)(info_player + info_ip_offset + 0);
int ip_b = *(unsigned char *)(info_player + info_ip_offset + 1); // dafuq, its +1 but in IDA its +4 step :S
int ip_c = *(unsigned char *)(info_player + info_ip_offset + 2);
int ip_d = *(unsigned char *)(info_player + info_ip_offset + 3);
//int port = *(unsigned char *)(info_player + info_ip_offset + 16);
char tmp[64];
snprintf(tmp, 64, "%d.%d.%d.%d", ip_a, ip_b, ip_c, ip_d);
//snprintf(tmp, 64, "%d.%d.%d.%d:%d", ip_a, ip_b, ip_c, ip_d, port);
return stackPushString(tmp);
}
int gsc_player_getping()
{
int playerid;
if (stackGetNumberOfParams() < 2) // function, playerid
{
printf_hide("scriptengine> ERROR: please specify atleast 2 arguments to gsc_player_getip()\n");
return stackPushUndefined();
}
if (!stackGetParamInt(1, &playerid))
{
printf_hide("scriptengine> ERROR: closer(): param \"playerid\"[1] has to be an integer!\n");
return stackPushUndefined();
}
#if COD2_VERSION == COD2_VERSION_1_0
int info_base = *(int *)0x0841FB0C;
int info_size = 0x78F14;
int info_ip_offset = 0x6E5C8;
int info_port_offset = 0x6E5A4;
#elif COD2_VERSION == COD2_VERSION_1_2
int info_base = *(int *)0x0842200C;
int info_size = 0x79064;
int info_ip_offset = 0x6E6D8;
int info_port_offset = 0x6E6B4;
#elif COD2_VERSION == COD2_VERSION_1_3
int info_base = *(int *)0x0842308C;
int info_size = 0xB1064;
int info_ip_offset = 0x6E6D8;
int info_port_offset = 0x6E6B4;
#else
#warning gsc_player_getip() got no working addresses
int info_base = *(int *)0x0;
int info_size = 0x0;
int info_ip_offset = 0x0;
int info_port_offset = 0x0;
#endif
int info_player = info_base + playerid * info_size;
int ping = *(unsigned int *)(info_player + info_port_offset);
return stackPushInt(ping);
}
#endif