From e3a6410844c1a24fa0b7670373d976dc207420cd Mon Sep 17 00:00:00 2001 From: Jaycie Ewald Date: Mon, 18 Dec 2023 18:48:18 -0600 Subject: [PATCH] rt_debug.c: Hook up to console so all cheats work --- source/console.c | 49 +--- source/rt_debug.c | 577 +++++++++++++++++++++++++--------------------- source/rt_debug.h | 3 + 3 files changed, 326 insertions(+), 303 deletions(-) diff --git a/source/console.c b/source/console.c index 1ad37c9..2616441 100644 --- a/source/console.c +++ b/source/console.c @@ -41,6 +41,7 @@ along with this program. If not, see . #include "states.h" #include "sprites.h" #include "rt_stat.h" +#include "rt_debug.h" #include "w_wad.h" #include "console.h" @@ -625,44 +626,6 @@ int _cmd_exec(int argc, char **argv) return 0; } -/* debug mode */ -int _cmd_debug(int argc, char **argv) -{ - - cmd_t *cmd; - - if (argc < 2) - { - DebugOk = 0; - console_printf("Debug Mode DISABLED!"); - } - else - { - DebugOk = 1; - console_printf("Debug Mode ENABLED!"); - } - - return 0; -} - -/* EKG command */ -int _cmd_ekg(int argc, char **argv) -{ - - cmd_t *cmd; - - if (argc < 2) - { - ludicrousgibs ^= 1; - if (ludicrousgibs) - console_printf("EKG mode on!"); - else - console_printf("EKG mode off!"); - } - return 0; -} - - /* cmdlib array */ cmd_t _cmdlib[] = { CMD("quit", "exit the game immediately", _cmd_quit), @@ -672,9 +635,7 @@ cmd_t _cmdlib[] = { CMD("help", "print help text", _cmd_help), CMD("find", "find command or variable by name", _cmd_find), CMD("dopefish", "?", _cmd_dopefish), - CMD("exec", "execute config script", _cmd_exec), - CMD("debug", "enables debug mode", _cmd_debug), - CMD("ekg", "enables Engine Killing Gibs", _cmd_ekg) + CMD("exec", "execute config script", _cmd_exec) }; /* register standard library of cmds */ @@ -1020,6 +981,10 @@ static boolean console_parse_command(char *s) if (!argv[0] || !argc) return false; + /* check for cheat */ + if (DoCheatCodeString(argv[0])) + return true; + /* check for cmd */ if ((cmd = cmd_retrieve(argv[0])) != NULL) { @@ -1117,7 +1082,7 @@ static boolean console_parse_command(char *s) } } - console_printf("\"%s\" is not a valid command or variable", s); + console_printf("\"%s\" is not a valid command, variable, or cheat", s); return false; } diff --git a/source/rt_debug.c b/source/rt_debug.c index 79b0571..db8db86 100644 --- a/source/rt_debug.c +++ b/source/rt_debug.c @@ -1139,6 +1139,289 @@ void WeaponCheat(int weapon) CheatSpawnItem(GetItemForWeapon(weapon)); } +/* +================ += += DoCheatCode () += +================ +*/ + +void DoCheatCode(int which) +{ + switch (which) + { + case ENABLECHEAT: + case ENABLECHEATALT: + EnableCheatCodes(); + break; + + case INVULNERABLE: + case INVULNERABLEALT: + DoGodMode(); + break; + + case WARP: + case WARPALT: + DoWarp(); + break; + + case ITEMS: + case ITEMSALT: + DoItemCheat(); + break; + + case SOMEITEMS: + case SOMEITEMSALT: + DoSomeItemCheat(); + break; + + case GODMODEPWUP: + case GODMODEPWUPALT: + DoGodModePowerup(); + break; + +#if (SHAREWARE == 0) + case DOGMODEPWUP: + case DOGMODEPWUPALT: + DoDogModePowerup(); + break; +#endif + + case MERCURYPWUP: + case MERCURYPWUPALT: + DoMercuryModePowerup(); + break; + + case SHROOMSPWUP: + case SHROOMSPWUPALT: + DoShroomsModePowerup(); + break; + + case ELASTOPWUP: + case ELASTOPWUPALT: + DoElastoModePowerup(); + break; + + case RESTARTGAME: + case RESTARTGAMEALT: + RestartNormal(); + break; + + case HURTPLAYER: + case HURTPLAYERALT: + HurtPlayer(); + break; + + case TOMHALLMODE: + case TOMHALLMODEALT: + gamestate.autorun = true; + AddMessage("Autorun enabled!", MSG_CHEAT); + break; + + case NORMAL: + case NORMALALT: + DoNormalThing(); + break; + + case LIGHTDIMON: + case LIGHTDIMONALT: + SetLightDiminish(false); + break; + + case LIGHTDIMOFF: + case LIGHTDIMOFFALT: + SetLightDiminish(true); + break; + + case FOGON: + case FOGONALT: + SetFog(true); + break; + + case FOGOFF: + case FOGOFFALT: + SetFog(false); + break; + + case QUITGAME: + case QUITGAMEALT: + QuitGame(); + break; + + case ENDLEVEL: + case ENDLEVELALT: + EndLevel(); + break; + + case FANDCOFF: + case FANDCOFFALT: + FloorandCeiling(false); + break; + + case FANDCON: + case FANDCONALT: + FloorandCeiling(true); + break; + + case AIMCROSS: + case AIMCROSSALT: + if (iG_aimCross == 0) + { + iG_aimCross = 1; + AddMessage("Crosshair on", MSG_GAME); + } + else + { + iG_aimCross = 0; + AddMessage("Crosshair off", MSG_GAME); + } + break; + + case BULLETARMOR: + case BULLETARMORALT: + GiveBulletProofArmor(); + break; + + case FIREARMOR: + case FIREARMORALT: + GiveAsbestoArmor(); + break; + + case GASMASK: + case GASMASKALT: + GiveGasMask(); + break; + + case OUTFIT: + case OUTFITALT: + OutfitPlayer(); + break; + + case KILLPLAYER: + case KILLPLAYERALT: + KillPlayer(); + break; + + case RESTARTLEVEL: + case RESTARTLEVELALT: + RestartCurrentLevel(); + break; + + case WEAPONTWOPISTOL: + case WEAPONTWOPISTOLALT: + WeaponCheat(wp_twopistol); + break; + + case WEAPONMP40: + case WEAPONMP40ALT: + WeaponCheat(wp_mp40); + break; + + case WEAPONBAZOOKA: + case WEAPONBAZOOKAALT: + WeaponCheat(wp_bazooka); + break; + + case WEAPONFIREBOMB: + case WEAPONFIREBOMBALT: + WeaponCheat(wp_firebomb); + break; + + case WEAPONHEAT: + case WEAPONHEATALT: + WeaponCheat(wp_heatseeker); + break; + + case WEAPONDRUNK: + case WEAPONDRUNKALT: + WeaponCheat(wp_drunk); + break; + + case WEAPONFIREWALL: + case WEAPONFIREWALLALT: + WeaponCheat(wp_firewall); + break; + + case WEAPONGOD: + case WEAPONGODALT: + WeaponCheat(wp_godhand); + break; + +#if (SHAREWARE == 0) + case WEAPONSPLIT: + case WEAPONSPLITALT: + WeaponCheat(wp_split); + break; + + case WEAPONKES: + case WEAPONKESALT: + WeaponCheat(wp_kes); + break; + + case WEAPONBAT: + case WEAPONBATALT: + WeaponCheat(wp_bat); + break; + + case WEAPONDOG: + case WEAPONDOGALT: + WeaponCheat(wp_dog); + break; +#endif + + case MISSILECAMTOGGLE: + case MISSILECAMTOGGLEALT: + ToggleMissileCam(); + break; + + case HUDTOGGLE: + case HUDTOGGLEALT: + ToggleHUD(); + break; + + case ROTATIONFUN: + ShutdownClientControls(); + RotationFun(); + StartupClientControls(); + SetupScreen(true); + break; + + case DEMORECORD: + RecordDemoQuery(); + break; + + case DEMOEND: + EndDemo(); + break; + + case DEMOPLAYBACK: + PlaybackDemoQuery(); + break; + + case CRAZYGIBS: + if (gamestate.violence == vl_excessive) + { + ludicrousgibs ^= 1; + if (ludicrousgibs == true) + AddMessage("EKG mode on!", MSG_GAME); + else + AddMessage("EKG mode off!", MSG_GAME); + } + break; + + case JUKEBOX: + case JUKEBOXALT: + DoJukeBox(); + break; + + case MAPCHEAT: + case MAPCHEATALT: + DoMapCheat(); + break; + } +} + /* ================ = @@ -1167,274 +1450,46 @@ void CheckCode(int which) // Kill last letter so the debug rtn will not keep triggering LetterQueue[start] = 0; - switch (which) - { - case ENABLECHEAT: - case ENABLECHEATALT: - EnableCheatCodes(); - break; - - case INVULNERABLE: - case INVULNERABLEALT: - DoGodMode(); - break; - - case WARP: - case WARPALT: - DoWarp(); - break; - - case ITEMS: - case ITEMSALT: - DoItemCheat(); - break; - - case SOMEITEMS: - case SOMEITEMSALT: - DoSomeItemCheat(); - break; - - case GODMODEPWUP: - case GODMODEPWUPALT: - DoGodModePowerup(); - break; + // run code + DoCheatCode(which); + } +} -#if (SHAREWARE == 0) - case DOGMODEPWUP: - case DOGMODEPWUPALT: - DoDogModePowerup(); - break; -#endif +/* +================ += += DoCheatCodeString () += +================ +*/ - case MERCURYPWUP: - case MERCURYPWUPALT: - DoMercuryModePowerup(); - break; - - case SHROOMSPWUP: - case SHROOMSPWUPALT: - DoShroomsModePowerup(); - break; - - case ELASTOPWUP: - case ELASTOPWUPALT: - DoElastoModePowerup(); - break; - - case RESTARTGAME: - case RESTARTGAMEALT: - RestartNormal(); - break; - - case HURTPLAYER: - case HURTPLAYERALT: - HurtPlayer(); - break; - - case TOMHALLMODE: - case TOMHALLMODEALT: - gamestate.autorun = true; - AddMessage("Autorun enabled!", MSG_CHEAT); - break; - - case NORMAL: - case NORMALALT: - DoNormalThing(); - break; - - case LIGHTDIMON: - case LIGHTDIMONALT: - SetLightDiminish(false); - break; - - case LIGHTDIMOFF: - case LIGHTDIMOFFALT: - SetLightDiminish(true); - break; - - case FOGON: - case FOGONALT: - SetFog(true); - break; - - case FOGOFF: - case FOGOFFALT: - SetFog(false); - break; - - case QUITGAME: - case QUITGAMEALT: - QuitGame(); - break; - - case ENDLEVEL: - case ENDLEVELALT: - EndLevel(); - break; - - case FANDCOFF: - case FANDCOFFALT: - FloorandCeiling(false); - break; - - case FANDCON: - case FANDCONALT: - FloorandCeiling(true); - break; - - case AIMCROSS: - case AIMCROSSALT: - if (iG_aimCross == 0) - { - iG_aimCross = 1; - AddMessage("Crosshair on", MSG_GAME); - } - else - { - iG_aimCross = 0; - AddMessage("Crosshair off", MSG_GAME); - } - break; - - case BULLETARMOR: - case BULLETARMORALT: - GiveBulletProofArmor(); - break; - - case FIREARMOR: - case FIREARMORALT: - GiveAsbestoArmor(); - break; - - case GASMASK: - case GASMASKALT: - GiveGasMask(); - break; - - case OUTFIT: - case OUTFITALT: - OutfitPlayer(); - break; - - case KILLPLAYER: - case KILLPLAYERALT: - KillPlayer(); - break; - - case RESTARTLEVEL: - case RESTARTLEVELALT: - RestartCurrentLevel(); - break; - - case WEAPONTWOPISTOL: - case WEAPONTWOPISTOLALT: - WeaponCheat(wp_twopistol); - break; - - case WEAPONMP40: - case WEAPONMP40ALT: - WeaponCheat(wp_mp40); - break; - - case WEAPONBAZOOKA: - case WEAPONBAZOOKAALT: - WeaponCheat(wp_bazooka); - break; - case WEAPONFIREBOMB: - case WEAPONFIREBOMBALT: - WeaponCheat(wp_firebomb); - break; - - case WEAPONHEAT: - case WEAPONHEATALT: - WeaponCheat(wp_heatseeker); - break; - - case WEAPONDRUNK: - case WEAPONDRUNKALT: - WeaponCheat(wp_drunk); - break; - - case WEAPONFIREWALL: - case WEAPONFIREWALLALT: - WeaponCheat(wp_firewall); - break; - - case WEAPONGOD: - case WEAPONGODALT: - WeaponCheat(wp_godhand); - break; +int DoCheatCodeString(char *which) +{ + int i, l, c; + char code[15]; -#if (SHAREWARE == 0) + /* iterate over all codes */ + for (i = 0; i < MAXCODES; i++) + { + /* reverse string into temp buffer */ + c = 0; + for (l = strlen(which) - 1; l >= 0; l--) + { + if (l >= 15 || c >= 15) + return 0; - case WEAPONSPLIT: - case WEAPONSPLITALT: - WeaponCheat(wp_split); - break; - - case WEAPONKES: - case WEAPONKESALT: - WeaponCheat(wp_kes); - break; - - case WEAPONBAT: - case WEAPONBATALT: - WeaponCheat(wp_bat); - break; - - case WEAPONDOG: - case WEAPONDOGALT: - WeaponCheat(wp_dog); - break; -#endif + code[c++] = toupper(which[l]); + } - case MISSILECAMTOGGLE: - case MISSILECAMTOGGLEALT: - ToggleMissileCam(); - break; - - case HUDTOGGLE: - case HUDTOGGLEALT: - ToggleHUD(); - break; - - case ROTATIONFUN: - ShutdownClientControls(); - RotationFun(); - StartupClientControls(); - SetupScreen(true); - break; - case DEMORECORD: - RecordDemoQuery(); - break; - case DEMOEND: - EndDemo(); - break; - case DEMOPLAYBACK: - PlaybackDemoQuery(); - break; - case CRAZYGIBS: - if (gamestate.violence == vl_excessive) - { - - ludicrousgibs ^= 1; - if (ludicrousgibs == true) - AddMessage("EKG mode on!", MSG_GAME); - else - AddMessage("EKG mode off!", MSG_GAME); - } - break; - - case JUKEBOX: - case JUKEBOXALT: - DoJukeBox(); - break; - case MAPCHEAT: - case MAPCHEATALT: - DoMapCheat(); - break; + /* check string */ + if (strncasecmp(code, Codes[i].code, 15) == 0) + { + DoCheatCode(i); + return 1; } } + + return 0; } /* diff --git a/source/rt_debug.h b/source/rt_debug.h index e6cb0dd..cc065b6 100644 --- a/source/rt_debug.h +++ b/source/rt_debug.h @@ -31,4 +31,7 @@ int DebugKeys(void); void CheckDebug(void); void EndDemo(void); +void DoCheatCode(int which); +int DoCheatCodeString(char *which); + #endif