-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcgame.cpp
558 lines (446 loc) · 12.1 KB
/
cgame.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
#include "shared.h"
#include "client.h"
#include "render.h"
#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
typedef enum {
CG_R_ADDREFENTITYTOSCREEN = 61,
CG_GETDOBJ = 162,
e_cgame_trap_end
} e_cgame_trap;
/* notepad ++ search for regex for e.g more parms with specific syscall num with
_30074898\([^,]*, 61
*/
typedef void(*CG_ServerCommand_t)();
CG_ServerCommand_t CG_ServerCommand;
const char* disliked_vars[] = {
"r_showimages",
"name",
"cl_allowdownload",
"version",
"cg_norender",
"cl_avidemo",
NULL };
#define M_DrawShadowString(x,y,font,fontscale,color,text,a,b,c) \
RE_SetColor(vColorBlack); \
SCR_DrawString(x + 1,y + 1,font,fontscale,vColorBlack,text,a,b,c); \
RE_SetColor(color); \
SCR_DrawString(x,y,font,fontscale,color,text,a,b,c); \
RE_SetColor(NULL);
DWORD cgame_mp;
class ChatMessage {
public:
std::string msg;
time_t addtime;
ChatMessage() {
addtime = time(NULL);
}
};
std::vector<ChatMessage> chatmessages;
void CG_RemoveChatEscapeChar(char *s) {
char *src, *dest;
for (src = s, dest = s; *src; src++) {
if( *src == '^' && isdigit(*(src + 1)) || isdigit(*src) && src != s && *(src - 1) == '^')
continue;
if (*src != 25 && *src >= 32 && *src <= 126)
*dest++ = *src;
}
*dest = 0;
}
char *(*CG_Argv)(int) = nullptr;
void myCG_ServerCommand(void) {
int argc = Cmd_Argc();
#if 0
Com_Printf("^2CG_ServerCommand: ");
for (int i = 0; i < argc; i++)
Com_Printf("%s ", Cmd_Argv(i));
Com_Printf("\n");
#endif
if (argc > 0) {
char* cmd = Cmd_Argv(0);
if (strlen(cmd) > 0) {
if ((*cmd == 'h' || *cmd == 'i')) {
} else if (*cmd == 'b') {
Com_DPrintf("[CG_ParseScores] b ");
for (size_t i = 0; i < argc; i++) {
Com_DPrintf("%s ", Cmd_Argv(i));
}
Com_DPrintf("\n");
} else if (*cmd == 'v') {
if (argc > 1) {
char* var = Cmd_Argv(1);
for (int i = 0; disliked_vars[i]; i++) {
if (!strcmp(disliked_vars[i], var))
return; // kindly fuck off please (c) php
}
}
}
}
}
CG_ServerCommand();
}
void pm_aimflag() {
int *pm = (int*)(cgame_mp + 0x19D570);
int *ps = (int*)*pm;
int *gclient = (int*)*ps;
int *v4 = (int *)(ps + 12);
int val = *(int*)(gclient + 21); //336? 84*4=336 /84/4=21??
if (val == 1023) {
*v4 |= 0x20;
return;
}
void(*call)();
*(int*)&call = CGAME_OFF(0x3000FB80);
call();
}
#define cg_crosshairClientNum (*(int*)CGAME_OFF(0x3020C8C8))
#define cg_renderingThirdPerson (*(int*)CGAME_OFF(0x30207158))
typedef enum {
TEAM_FREE,
TEAM_AXIS,
TEAM_ALLIES,
TEAM_SPECTATOR,
TEAM_NUM_TEAMS
} team_t;
static const char *teamStrings[] = { "TEAM_FREE", "Axis", "Allies", "Spectator" };
typedef struct {
int snapsFlags;
int ping;
int serverTime;
//rest
} snapshot_t;
typedef struct {
int unk;
int infoValid;
int clientNum;
char name[32];
team_t team;
//down here model names and attachments and rest of client info
} clientInfo_t;
typedef struct {
float alpha;
int clientNum;
time_t time;
team_t team;
} fadeStatus_t;
#define MAX_LAST_NUMS 5
static fadeStatus_t lastNums[MAX_LAST_NUMS] = { 0 };
static int lastNumsIndex = 0;
static clientInfo_t *other_info = NULL, *info = NULL;
static int *cent;
#define CLIENTINFO_SIZE 0x448
void R_AddDebugString(float *origin, float *color, float fontScale, const char* str) {
__asm {
push str
push fontScale
mov ebx, origin
mov edi, color
mov eax, 0x4E0A40
call eax
add esp, 8
}
}
void CG_DrawCrosshairNames() {
cg_crosshairClientNum = 65;
float(*CG_ScanForCrosshairEntity)();
*(int*)&CG_ScanForCrosshairEntity = CGAME_OFF(0x30016E50);
CG_ScanForCrosshairEntity();
if (cg_crosshairClientNum > 64)
return;
other_info = (clientInfo_t*)(0x448 * cg_crosshairClientNum + CGAME_OFF(0x3018BC0C));
info = (clientInfo_t*)(0x448 * *(int*)(*(int*)CGAME_OFF(0x301E2160) + 184) + CGAME_OFF(0x3018BC0C));
if (other_info->team == TEAM_ALLIES || other_info->team == TEAM_AXIS) {
if (!*(int*)CGAME_OFF(0x3020BA24) && !*(int*)CGAME_OFF(0x3020BA28)) {
return;
}
else if (other_info->team == info->team || info->team == TEAM_SPECTATOR) {
for (int i = 0; i < MAX_LAST_NUMS; i++) {
if (lastNums[i].alpha > 0 && lastNums[i].clientNum == cg_crosshairClientNum) {
lastNums[i].alpha = 1;
return;
}
}
lastNumsIndex = (lastNumsIndex + 1) % MAX_LAST_NUMS;
fadeStatus_t *st = &lastNums[lastNumsIndex];
st->clientNum = cg_crosshairClientNum;
st->time = *cls_realtime;
st->alpha = 1;
st->team = other_info->team;
//float *origin = (float*)FILE_OFF(0x301E2188); //my origin
//R_AddDebugString(origin,color,2,other_info->name);
}
}
}
void __cdecl cg_playersprites_sub() {
other_info = NULL;
for (int i = 0; i < MAX_LAST_NUMS; i++) {
fadeStatus_t *st = &lastNums[i];
if (st->clientNum != *(int*)((int)cent + 144))
continue;
if (st->alpha <= 0) {
st->time = 0;
st->alpha = 0;
st->clientNum = 65;
continue;
}
if (*cls_realtime - st->time > 350) {
st->alpha -= 0.1;
st->time = *cls_realtime;
}
other_info = (clientInfo_t*)(0x448 * st->clientNum + CGAME_OFF(0x3018BC0C));
#ifndef SMALLCHAR_WIDTH
#define SMALLCHAR_WIDTH 48
#endif
vec4_t color = { 1, 1, 1, st->alpha };
vec3_t org = { 0 };
org[0] = *(float*)((int)cent + 504);
org[1] = *(float*)((int)cent + 508);
org[2] = *(float*)((int)cent + 512) + 80;
char tmp_name[64] = { 0 };
strcpy(tmp_name, other_info->name);
R_AddDebugString(org, color, .5, Q_CleanStr(tmp_name));
}
}
void(*CG_PlayerSprites)();
void _CG_PlayerSprites() {
__asm mov cent, eax
CG_PlayerSprites();
cg_playersprites_sub();
}
void CG_SetHeadNames(int flag) {
if (!cgame_mp)
return;
if (*cls_state != 6) // CA_ACTIVE
return;
static char org_bytes[2][5] = {
{ 0xA1, 0x2C, 0x90, 0x1D, 0x30 },
{ 0xE8, 0xED, 0xF1, 0xFF, 0xFF }
};
if (!flag) {
_memcpy((void*)CGAME_OFF(0x30016F70), &org_bytes[0], 5);
_memcpy((void*)CGAME_OFF(0x300282DE), &org_bytes[1], 5);
return;
}
__jmp(CGAME_OFF(0x30016F70), (int)CG_DrawCrosshairNames);
__call(CGAME_OFF(0x300282DE), (int)_CG_PlayerSprites);
}
void ParseVector(char *s, vec3_t out) {
if (!s || !*s)
return;
if (strlen(s) > 200)
return;
char b[128] = { 0 };
int outN = 0, bi = 0;
for (int i = 0; s[i] != '\0'; i++) {
if ((i != 0 && s[i] == ' ') || s[i + 1] == '\0') {
out[outN++] = atof(b);
memset(b, 0, sizeof(b));
bi = 0;
}
else {
b[bi++] = s[i];
}
}
}
char *PrintVector(vec3_t v) {
return va("x: %f, y: %f, z: %f", v[0], v[1], v[2]);
}
#define M_DrawShadowedString(x, y, fontscale, fontcolor, text) \
SCR_DrawString(x+2,y+2, 1, fontscale, vColorBlack, text, NULL, NULL, NULL); \
SCR_DrawString(x,y,1,fontscale,fontcolor,text,NULL,NULL,NULL);
#pragma pack(push, 1)
typedef struct {
int clientNum;
int score;
int ping;
int deaths;
char *clientName;
int statusicon;
} clientScoreInfo_t;
#pragma pack(pop)
#include <algorithm>
void CG_KeyEvent(int key, int down, unsigned time) {
if (keys[key].repeats > 1)
return;
if (!down)
return;
if (!cgame_mp)
return;
}
extern cvar_t *cg_drawheadnames;
void CG_SCR_DrawScreenField(int stereoFrame) {
if (cg_drawheadnames->modified) {
void CG_SetHeadNames(int flag);
CG_SetHeadNames(cg_drawheadnames->integer);
}
}
void CG_DrawDisconnect() {
cvar_t* xui_interrupted = Cvar_Get("cg_xui_interrupted", "0", CVAR_ARCHIVE);
if (xui_interrupted->integer) {
void(*call)();
*(int*)&call = CGAME_OFF(0x30015450);
call();
}
}
void CG_DrawFPS(float y) {
cvar_t* xui_fps = Cvar_Get("cg_xui_fps", "1", CVAR_ARCHIVE);
if (xui_fps->integer) {
cvar_t* x = Cvar_Get("cg_xui_fps_x", "597", CVAR_ARCHIVE); // uh this x y values just look good with my hp bar
cvar_t* y = Cvar_Get("cg_xui_fps_y", "8", CVAR_ARCHIVE);
#define FPS_FRAMES 4
static int previousTimes[FPS_FRAMES];
static int index;
int i, total;
int fps;
static int previous;
int t, frameTime;
t = timeGetTime();
frameTime = t - previous;
previous = t;
previousTimes[index % FPS_FRAMES] = frameTime;
index++;
if (index > FPS_FRAMES) {
total = 0;
for (i = 0; i < FPS_FRAMES; i++) {
total += previousTimes[i];
}
if (!total) {
total = 1;
}
fps = 1000 * FPS_FRAMES / total;
M_DrawShadowString(x->integer, y->integer, 1, .20, vColorWhite, va("FPS: %d", fps), NULL, NULL, NULL);
}
} else {
void(*call)(float);
*(int*)&call = CGAME_OFF(0x30014A00);
call(y);
}
}
void CG_Obituary(int ent) {
if (!Cvar_VariableIntegerValue("cg_x_obituary")) return;
void(*call)(int);
*(int*)(&call) = CGAME_OFF(0x3001D6C0);
call(ent);
}
void PM_ClipVelocity(vec3_t in, vec3_t normal, vec3_t out) {
float backoff;
float change;
int i;
float overbounce = 1.001f;
backoff = DotProduct(in, normal);
if (backoff < 0) {
backoff *= overbounce;
}
else {
backoff /= overbounce;
}
for (i = 0; i < 3; i++) {
change = normal[i] * backoff;
out[i] = in[i] - change;
}
}
// xoxor4d
void PM_ProjectVelocity(vec3_t in, vec3_t normal, vec3_t out) {
float speedXY, DotNormalXY, normalisedNormalXY, projectionZ, projectionXYZ;
speedXY = in[1] * in[1] + in[0] * in[0];
if ((normal[2]) < 0.001f || (speedXY == 0.0f)) {
VectorCopy(in, out);
}
else {
DotNormalXY = normal[1] * in[1] + in[0] * normal[0];
normalisedNormalXY = -DotNormalXY / normal[2];
projectionZ = in[2] * in[2] + speedXY;
projectionXYZ = sqrtf((projectionZ / (speedXY + normalisedNormalXY * normalisedNormalXY)));
if (projectionXYZ < 1.0f || normalisedNormalXY < 0.0f || in[2] > 0.0f) {
out[0] = projectionXYZ * in[0];
out[1] = projectionXYZ * in[1];
out[2] = projectionXYZ * normalisedNormalXY;
}
}
}
uint32_t PM_Bounce(vec3_t in, vec3_t normal, vec3_t out) {
int x_cl_bounce = atoi(Info_ValueForKey(cs1, "x_cl_bounce"));
if (x_cl_bounce) {
PM_ProjectVelocity(in, normal, out);
}
else {
PM_ClipVelocity(in, normal, out);
}
return CGAME_OFF(0x3000D830);
}
__declspec(naked) void PM_Bounce_Stub()
{
__asm
{
push esi; // out
push ecx; // normal
push edx; // in
call PM_Bounce;
add esp, 12;
push eax
retn;
}
}
static void (*PM_CheckForChangeWeapon)();
static void (*PM_BeginWeaponChange)(int, int);
static void (*PM_FinishWeaponChange)();
void _PM_CheckForChangeWeapon()
{
int* pm = (int*)(cgame_mp + 0x19D570);
pmove_t* xm = *(pmove_t**)(int)pm;
if ((xm->ps->pm_flags & 0x20000))
{
int* weapon = (int*)((int)xm->ps + 176);
if (*weapon)
{
PM_BeginWeaponChange(*weapon, 0);
}
return;
}
PM_CheckForChangeWeapon();
}
void _PM_FinishWeaponChange()
{
int* pm = (int*)(cgame_mp + 0x19D570);
pmove_t* xm = *(pmove_t**)(int)pm;
if ((xm->ps->pm_flags & 0x20000))
{
int* weapon = (int*)((int)xm->ps + 176);
if (*weapon)
{
*weapon = 0;
}
return;
}
PM_FinishWeaponChange();
}
void CG_Init(DWORD base) {
cgame_mp = base;
CG_ServerCommand = (CG_ServerCommand_t)(cgame_mp + 0x2E0D0);
CG_Argv = (char*(*)(int))CGAME_OFF(0x30020960);
XUNLOCK((void*)CGAME_OFF(0x3020C8C8), sizeof(int));
XUNLOCK((void*)CGAME_OFF(0x3020C8C8), sizeof(int)); //crosshairnumber
__call(CGAME_OFF(0x3002E5A6), (int)myCG_ServerCommand);
__call(CGAME_OFF(0x3000C799), (int)pm_aimflag);
__call(CGAME_OFF(0x3000C7B8), (int)pm_aimflag);
__call(CGAME_OFF(0x3000C7D2), (int)pm_aimflag);
__call(CGAME_OFF(0x3000C7FF), (int)pm_aimflag);
__call(CGAME_OFF(0x3000C858), (int)pm_aimflag);
__call(CGAME_OFF(0x3000C893), (int)pm_aimflag);
CG_PlayerSprites = (void(*)())CGAME_OFF(0x300274D0);
__call(CGAME_OFF(0x300159CC), (int)CG_DrawDisconnect);
__call(CGAME_OFF(0x300159D4), (int)CG_DrawDisconnect);
__call(CGAME_OFF(0x3001509E), (int)CG_DrawFPS);
__call(CGAME_OFF(0x3001E6A1), (int)CG_Obituary);
*(UINT32*)CGAME_OFF(0x300749EC) = CVAR_ARCHIVE; // Enable cg_fov
*(UINT32*)CGAME_OFF(0x30074EBC) = CVAR_ARCHIVE; // Enable cg_thirdperson
void CG_SetHeadNames(int flag);
CG_SetHeadNames(cg_drawheadnames->integer);
__jmp(CGAME_OFF(0x3000D82B), (int)PM_Bounce_Stub);
__nop(CGAME_OFF(0x30065550), 1); //weapon 32 fix
__call(CGAME_OFF(0x30011C25), (int)_PM_CheckForChangeWeapon);
__call(CGAME_OFF(0x30011CB4), (int)_PM_FinishWeaponChange);
PM_CheckForChangeWeapon = (void(*)())CGAME_OFF(0x300112E0);
PM_BeginWeaponChange = (void(*)(int, int))CGAME_OFF(0x30010570);
PM_FinishWeaponChange = (void(*)())CGAME_OFF(0x300107c0);
}