Skip to content

Commit 3967cfc

Browse files
feat: add cmds (#11)
* feat: add cmds - `noclip` - `ufo` - `god`
1 parent 987f02f commit 3967cfc

File tree

2 files changed

+924
-0
lines changed

2 files changed

+924
-0
lines changed

src/game/mp_main.cpp

+103
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,14 @@ namespace mp
227227
CL_ConsolePrint_t CL_ConsolePrint = reinterpret_cast<CL_ConsolePrint_t>(0x822E4D18);
228228
CL_GamepadButtonEvent_t CL_GamepadButtonEvent = reinterpret_cast<CL_GamepadButtonEvent_t>(0x822DD1E8);
229229

230+
ClientCommand_t ClientCommand = reinterpret_cast<ClientCommand_t>(0x8227DCF0);
231+
230232
Cmd_AddCommandInternal_t Cmd_AddCommandInternal = reinterpret_cast<Cmd_AddCommandInternal_t>(0x8223ADE0);
231233
Cmd_ExecFromFastFile_t Cmd_ExecFromFastFile = reinterpret_cast<Cmd_ExecFromFastFile_t>(0x8223AF40);
232234
Cbuf_ExecuteBuffer_t Cbuf_ExecuteBuffer = reinterpret_cast<Cbuf_ExecuteBuffer_t>(0x8223AAE8);
233235

236+
CheatsOk_t CheatsOk = reinterpret_cast<CheatsOk_t>(0x8227BF40);
237+
234238
Com_Printf_t Com_Printf = reinterpret_cast<Com_Printf_t>(0x82237000);
235239
Com_PrintError_t Com_PrintError = reinterpret_cast<Com_PrintError_t>(0x82235C50);
236240
Com_PrintWarning_t Com_PrintWarning = reinterpret_cast<Com_PrintWarning_t>(0x822356B8);
@@ -240,15 +244,24 @@ namespace mp
240244
DB_FindXAssetHeader_t DB_FindXAssetHeader = reinterpret_cast<DB_FindXAssetHeader_t>(0x822A0298);
241245
DB_GetAllXAssetOfType_FastFile_t DB_GetAllXAssetOfType_FastFile = reinterpret_cast<DB_GetAllXAssetOfType_FastFile_t>(0x8229E8E0);
242246

247+
I_strnicmp_t I_strnicmp = reinterpret_cast<I_strnicmp_t>(0x821CDA98);
248+
243249
Load_MapEntsPtr_t Load_MapEntsPtr = reinterpret_cast<Load_MapEntsPtr_t>(0x822A9648);
244250

245251
R_GetImageList_t R_GetImageList = reinterpret_cast<R_GetImageList_t>(0x82152A58);
246252
R_StreamLoadFileSynchronously_t R_StreamLoadFileSynchronously = reinterpret_cast<R_StreamLoadFileSynchronously_t>(0x82151510);
247253

248254
Scr_ReadFile_FastFile_t Scr_ReadFile_FastFile = reinterpret_cast<Scr_ReadFile_FastFile_t>(0x82221220);
249255

256+
SV_Cmd_ArgvBuffer_t SV_Cmd_ArgvBuffer = reinterpret_cast<SV_Cmd_ArgvBuffer_t>(0x82239F48);
257+
SV_GameSendServerCommand_t SV_GameSendServerCommand = reinterpret_cast<SV_GameSendServerCommand_t>(0x82204BB8);
258+
SV_SendServerCommand_t SV_SendServerCommand = reinterpret_cast<SV_SendServerCommand_t>(0x821FFE30);
259+
260+
va_t va = reinterpret_cast<va_t>(0x821CD858);
261+
250262
// Variables
251263
auto cmd_functions = reinterpret_cast<cmd_function_s *>(0x82A2335C);
264+
auto g_entities = reinterpret_cast<gentity_s *>(0x8287CD08);
252265

253266
Detour CL_ConsolePrint_Detour;
254267

@@ -281,6 +294,93 @@ namespace mp
281294
}
282295
}
283296

297+
void Cmd_UFO_f(gentity_s *ent)
298+
{
299+
if (!CheatsOk(ent))
300+
return;
301+
302+
gclient_s *client = ent->client;
303+
304+
bool enableUFO = !client->ufo;
305+
client->ufo = enableUFO;
306+
307+
const char *message = enableUFO ? "GAME_UFOON" : "GAME_UFOOFF";
308+
309+
// Format the command string (note: 101 is ASCII for 'e')
310+
const char *commandString = va("%c \"%s\"", 101, message);
311+
312+
int entityIndex = ent - g_entities;
313+
314+
if (entityIndex == -1)
315+
SV_SendServerCommand(0, SV_CMD_CAN_IGNORE, "%s", commandString);
316+
else
317+
SV_GameSendServerCommand(entityIndex, SV_CMD_CAN_IGNORE, commandString);
318+
}
319+
320+
void Cmd_Noclip_f(gentity_s *ent)
321+
{
322+
if (!CheatsOk(ent))
323+
return;
324+
325+
gclient_s *client = ent->client;
326+
327+
bool enableNoclip = !client->noclip;
328+
client->noclip = enableNoclip;
329+
330+
const char *message = enableNoclip ? "GAME_NOCLIPON" : "GAME_NOCLIPOFF";
331+
332+
// Format the command string (note: 101 is ASCII for 'e')
333+
const char *commandString = va("%c \"%s\"", 101, message);
334+
335+
int entityIndex = ent - g_entities;
336+
337+
if (entityIndex == -1)
338+
SV_SendServerCommand(0, SV_CMD_CAN_IGNORE, "%s", commandString);
339+
else
340+
SV_GameSendServerCommand(entityIndex, SV_CMD_CAN_IGNORE, commandString);
341+
}
342+
343+
void Cmd_God_f(gentity_s *ent)
344+
{
345+
if (!CheatsOk(ent))
346+
return;
347+
348+
// Toggle god mode flag (bit 0)
349+
ent->flags ^= 1;
350+
351+
bool godModeEnabled = (ent->flags & 1) != 0;
352+
const char *message = godModeEnabled ? "GAME_GODMODE_ON" : "GAME_GODMODE_OFF";
353+
354+
// Format command string (101 is ASCII for 'e')
355+
const char *commandString = va("%c \"%s\"", 101, message);
356+
357+
int entityIndex = ent - g_entities;
358+
359+
if (entityIndex == -1)
360+
SV_SendServerCommand(0, SV_CMD_CAN_IGNORE, "%s", commandString);
361+
else
362+
SV_GameSendServerCommand(entityIndex, SV_CMD_CAN_IGNORE, commandString);
363+
}
364+
365+
Detour ClientCommand_Detour;
366+
367+
void ClientCommand_Hook(int clientNum)
368+
{
369+
gentity_s *ent = &g_entities[clientNum];
370+
371+
char cmd[1032];
372+
SV_Cmd_ArgvBuffer(0, cmd, 1024);
373+
374+
if (I_strnicmp(cmd, "noclip", 6) == 0)
375+
Cmd_Noclip_f(ent);
376+
else if (I_strnicmp(cmd, "ufo", 3) == 0)
377+
Cmd_UFO_f(ent);
378+
else if (I_strnicmp(cmd, "god", 3) == 0)
379+
Cmd_God_f(ent);
380+
else
381+
ClientCommand_Detour.GetOriginal<decltype(ClientCommand)>()(clientNum);
382+
}
383+
284384
Detour Load_MapEntsPtr_Detour;
285385

286386
void Load_MapEntsPtr_Hook()
@@ -1331,6 +1431,9 @@ namespace mp
13311431
{
13321432
xbox::DbgPrint("Initializing MP\n");
13331433

1434+
ClientCommand_Detour = Detour(ClientCommand, ClientCommand_Hook);
1435+
ClientCommand_Detour.Install();
1436+
13341437
CL_ConsolePrint_Detour = Detour(CL_ConsolePrint, CL_ConsolePrint_Hook);
13351438
CL_ConsolePrint_Detour.Install();
13361439

0 commit comments

Comments
 (0)