From d526c6401f4198269342e5d75896bdf70e0d129a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 3 Aug 2020 20:51:31 +0200 Subject: [PATCH] - use the generic cheat system for Blood. --- source/blood/src/blood.cpp | 2 + source/blood/src/d_menu.cpp | 2 +- source/blood/src/endgame.cpp | 2 +- source/blood/src/loadsave.cpp | 2 +- source/blood/src/messages.cpp | 149 ++++++++++++++------------------ source/blood/src/messages.h | 104 ++++++++++------------ source/blood/src/osdcmd.cpp | 38 ++------ source/core/cheathandler.cpp | 11 ++- source/games/duke/src/ccmds.cpp | 11 --- source/sw/src/osdcmds.cpp | 2 +- 10 files changed, 136 insertions(+), 187 deletions(-) diff --git a/source/blood/src/blood.cpp b/source/blood/src/blood.cpp index 276e014c9..a62db11f6 100644 --- a/source/blood/src/blood.cpp +++ b/source/blood/src/blood.cpp @@ -63,6 +63,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS void LocalKeys(void); +void InitCheats(); char bAddUserMap = false; bool bNoDemo = false; @@ -734,6 +735,7 @@ static const char* actions[] = { static void app_init() { + InitCheats(); buttonMap.SetButtons(actions, NUM_ACTIONS); memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS)); gGameOptions.nMonsterSettings = !userConfig.nomonsters; diff --git a/source/blood/src/d_menu.cpp b/source/blood/src/d_menu.cpp index fde52516f..32e890ac1 100644 --- a/source/blood/src/d_menu.cpp +++ b/source/blood/src/d_menu.cpp @@ -255,7 +255,7 @@ void GameInterface::StartGame(FNewGameStartup& gs) gSkill = gs.Skill; gGameOptions.nLevel = gs.Level; gStartNewGame = true; - gCheatMgr.sub_5BCF4(); + cheatReset(); } FSavegameInfo GameInterface::GetSaveSig() diff --git a/source/blood/src/endgame.cpp b/source/blood/src/endgame.cpp index da088c9c9..60d0b571f 100644 --- a/source/blood/src/endgame.cpp +++ b/source/blood/src/endgame.cpp @@ -100,7 +100,7 @@ void CEndGameMgr::Draw(void) if (gGameOptions.nGameType == 0) { DrawMenuCaption(GStrings("TXTB_LEVELSTATS")); - if (CCheatMgr::m_bPlayerCheated) + if (bPlayerCheated) { viewDrawText(3, GStrings("TXTB_CHEATED"), 160, 32, -128, 0, 1, 1); } diff --git a/source/blood/src/loadsave.cpp b/source/blood/src/loadsave.cpp index d41f07ea1..fab54d998 100644 --- a/source/blood/src/loadsave.cpp +++ b/source/blood/src/loadsave.cpp @@ -678,7 +678,7 @@ void MyLoadSave::Load(void) psky_t *skyInfo = tileSetupSky(DEFAULTPSKY); Read(skyInfo, sizeof(*skyInfo)); skyInfo->combinedtile = -1; - gCheatMgr.sub_5BCF4(); + cheatReset(); } diff --git a/source/blood/src/messages.cpp b/source/blood/src/messages.cpp index 34e1a0399..af07499ee 100644 --- a/source/blood/src/messages.cpp +++ b/source/blood/src/messages.cpp @@ -37,11 +37,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "player.h" #include "view.h" #include "gstrings.h" +#include "cheathandler.h" BEGIN_BLD_NS CPlayerMsg gPlayerMsg; -CCheatMgr gCheatMgr; void sub_5A928(void) { @@ -361,89 +361,20 @@ bool CPlayerMsg::IsWhitespaceOnly(const char * const pzString) return true; } -CCheatMgr::CHEATINFO CCheatMgr::s_CheatInfo[] = { - {"NQLGB", kCheatMpkfa, 0 }, // MPKFA (Invincibility) - {"DBQJONZBTT", kCheatCapInMyAss, 0 }, // CAPINMYASS (Disable invincibility ) - {"OPDBQJONZBTT", kCheatNoCapInMyAss, 0 }, // NOCAPINMYASS (Invincibility) - {"J!XBOOB!CF!MJLF!LFWJO", kCheatNoCapInMyAss, 0 }, // I WANNA BE LIKE KEVIN (Invincibility) - {"JEBIP", kCheatIdaho, 0 }, // IDAHO (All weapons and full ammo) - {"NPOUBOB", kCheatMontana, 0 }, // MONTANA (All weapons, full ammo and all items) - {"HSJTXPME", kCheatGriswold, 0 }, // GRISWOLD (Full armor (same effect as getting super armor)) - {"FENBSL", kCheatEdmark, 0 }, // EDMARK (Does a lot of fire damage to you (if you have 200HP and 200 fire armor then you can survive). Displays the message "THOSE WERE THE DAYS".) - {"UFRVJMB", kCheatTequila, 0 }, // TEQUILA (Guns akimbo power-up) - {"CVO[", kCheatBunz, 0 }, // BUNZ (All weapons, full ammo, and guns akimbo power-up) - {"GVOLZ!TIPFT", kCheatFunkyShoes, 0 }, // FUNKY SHOES (Gives jump boots item and activates it) - {"HBUFLFFQFS", kCheatGateKeeper, 0 }, // GATEKEEPER (Sets the you cheated flag to true, at the end of the level you will see that you have cheated) - {"LFZNBTUFS", kCheatKeyMaster, 0 }, // KEYMASTER (All keys) - {"KPKP", kCheatJoJo, 0 }, // JOJO (Drunk mode (same effect as getting bitten by red spider)) - {"TBUDIFM", kCheatSatchel, 0 }, // SATCHEL (Full inventory) - {"TQPSL", kCheatSpork, 0 }, // SPORK (200% health (same effect as getting life seed)) - {"POFSJOH", kCheatOneRing, 0 }, // ONERING (Cloak of invisibility power-up) - {"NBSJP", kCheatMario, 1 }, // MARIO (Warp to level E M, e.g.: MARIO 1 3 will take you to Phantom Express) - {"DBMHPO", kCheatCalgon, 1 }, // CALGON (Jumps to next level or can be used like MARIO with parameters) - {"LFWPSLJBO", kCheatKevorkian, 0 }, // KEVORKIAN (Does a lot of physical damage to you (if you have 200HP and 200 fire armor then you can survive). Displays the message "KEVORKIAN APPROVES".) - {"NDHFF", kCheatMcGee, 0 }, // MCGEE (Sets you on fire. Displays the message "YOU'RE FIRED".) - {"LSVFHFS", kCheatKrueger, 0 }, // KRUEGER (200% health, but sets you on fire. Displays the message "FLAME RETARDANT".) - {"DIFFTFIFBE", kCheatCheeseHead, 0 }, // CHEESEHEAD (100% diving suit) - {"DPVTUFBV", kCheatCousteau, 0 }, // COUSTEAU (200% health and diving suit) - {"WPPSIFFT", kCheatVoorhees, 0 }, // VOORHEES (Death mask power-up) - {"MBSB!DSPGU", kCheatLaraCroft, 0 }, // LARA CROFT (All weapons and infinite ammo. Displays the message "LARA RULES". Typing it the second time will lose all weapons and ammo.) - {"IPOHLPOH", kCheatHongKong, 0 }, // HONGKONG (All weapons and infinite ammo) - {"GSBOLFOTUFJO", kCheatFrankenstein, 0 }, // FRANKENSTEIN (100% med-kit) - {"TUFSOP", kCheatSterno, 0 }, // STERNO (Temporary blindness (same effect as getting bitten by green spider)) - {"DMBSJDF", kCheatClarice, 0 }, // CLARICE (Gives 100% body armor, 100% fire armor, 100% spirit armor) - {"GPSL!ZPV", kCheatForkYou, 0 }, // FORK YOU (Drunk mode, 1HP, no armor, no weapons, no ammo, no items, no keys, no map, guns akimbo power-up) - {"MJFCFSNBO", kCheatLieberMan, 0 }, // LIEBERMAN (Sets the you cheated flag to true, at the end of the level you will see that you have cheated) - {"FWB!HBMMJ", kCheatEvaGalli, 0 }, // EVA GALLI (Disable/enable clipping (grant the ability to walk through walls)) - {"SBUF", kCheatRate, 0 }, // RATE (Display frame rate (doesn't count as a cheat)) - {"HPPOJFT", kCheatGoonies, 0 }, // GOONIES (Enable full map. Displays the message "YOU HAVE THE MAP".) - {"TQJFMCFSH", kCheatSpielberg, 1 }, // SPIELBERG (Disables all cheats. If number values corresponding to a level and episode number are entered after the cheat word (i.e. "spielberg 1 3" for Phantom Express), you will be spawned to said level and the game will begin recording a demo from your actions.) -}; +bool bPlayerCheated = false; -bool CCheatMgr::m_bPlayerCheated = false; - -bool CCheatMgr::Check(char *pzString) -{ - char buffer[80]; - strcpy(buffer, pzString); - for (size_t i = 0; i < strlen(pzString); i++) - buffer[i]++; - for (int i = 0; i < 36; i++) - { - int nCheatLen = strlen(s_CheatInfo[i].pzString); - if (s_CheatInfo[i].flags & 1) - { - if (!strnicmp(buffer, s_CheatInfo[i].pzString, nCheatLen)) - { - Process(s_CheatInfo[i].id, buffer+nCheatLen); - return true; - } - } - if (!strcmp(buffer, s_CheatInfo[i].pzString)) - { - Process(s_CheatInfo[i].id, NULL); - return true; - } - } - return false; -} - -int parseArgs(char *pzArgs, int *nArg1, int *nArg2) +static int parseArgs(char *pzArgs, int *nArg1, int *nArg2) { if (!nArg1 || !nArg2) return -1; - int nLength = strlen(pzArgs); - for (int i = 0; i < nLength; i++) - pzArgs[i]--; - int stat = sscanf(pzArgs, " %d %d", nArg1, nArg2); - if (stat == 2 && (*nArg1 == 0 || *nArg2 == 0)) - return -1; - *nArg1 = ClipRange(*nArg1-1, 0, gEpisodeCount-1); - *nArg2 = ClipRange(*nArg2-1, 0, gEpisodeInfo[*nArg1].nLevels-1); - return stat; + *nArg1 = pzArgs[0] - '0' - 1; + *nArg2 = (pzArgs[1] - '0')*10+(pzArgs[2]-'0') - 1; + *nArg1 = ClipRange(*nArg1, 0, gEpisodeCount-1); + *nArg2 = ClipRange(*nArg2, 0, gEpisodeInfo[*nArg1].nLevels-1); + return 2; } -void CCheatMgr::Process(CCheatMgr::CHEATCODE nCheatCode, char* pzArgs) +void ProcessCheat(CHEATCODE nCheatCode, char* pzArgs) { dassert(nCheatCode > kCheatNone && nCheatCode < kCheatMax); @@ -609,12 +540,59 @@ void CCheatMgr::Process(CCheatMgr::CHEATCODE nCheatCode, char* pzArgs) default: break; } - m_bPlayerCheated = true; + bPlayerCheated = true; } -void CCheatMgr::sub_5BCF4(void) +template bool doCheat(cheatseq_t *c) { - m_bPlayerCheated = 0; + ProcessCheat(code, (char*)c->Args); + return true; +} + + +static cheatseq_t s_CheatInfo[] = { + {"MPKFA", doCheat, 0 }, // MPKFA (Invincibility) + {"CAPINMYASS", doCheat, 0 }, // CAPINMYASS (Disable invincibility ) + {"NOCAPINMYASS", doCheat, 0 }, // NOCAPINMYASS (Invincibility) + {"I WANNA BE LIKE KEVIN", doCheat, 0 }, // I WANNA BE LIKE KEVIN (Invincibility) + {"IDAHO", doCheat, 0 }, // IDAHO (All weapons and full ammo) + {"MONTANA", doCheat, 0 }, // MONTANA (All weapons, full ammo and all items) + {"GRISWOLD", doCheat, 0 }, // GRISWOLD (Full armor (same effect as getting super armor)) + {"EDMARK", doCheat, 0 }, // EDMARK (Does a lot of fire damage to you (if you have 200HP and 200 fire armor then you can survive). Displays the message "THOSE WERE THE DAYS".) + {"TEQUILA", doCheat, 0 }, // TEQUILA (Guns akimbo power-up) + {"BUNZ[", doCheat, 0 }, // BUNZ (All weapons, full ammo, and guns akimbo power-up) + {"FUNKY SHOES", doCheat, 0 }, // FUNKY SHOES (Gives jump boots item and activates it) + {"GATEKEEPER", doCheat, 0 }, // GATEKEEPER (Sets the you cheated flag to true, at the end of the level you will see that you have cheated) + {"KEYMASTER", doCheat, 0 }, // KEYMASTER (All keys) + {"JOJO", doCheat, 0 }, // JOJO (Drunk mode (same effect as getting bitten by red spider)) + {"SATCHEL", doCheat, 0 }, // SATCHEL (Full inventory) + {"SPORK", doCheat, 0 }, // SPORK (200% health (same effect as getting life seed)) + {"ONERING", doCheat, 0 }, // ONERING (Cloak of invisibility power-up) + {"MARIO###", doCheat, 0 }, // MARIO (Warp to level E M, e.g.: MARIO 1 3 will take you to Phantom Express) + {"CALGON", doCheat, 0 }, // CALGON (Jumps to next level or can be used like MARIO with parameters) + {"KEVORKIAN", doCheat, 0 }, // KEVORKIAN (Does a lot of physical damage to you (if you have 200HP and 200 fire armor then you can survive). Displays the message "KEVORKIAN APPROVES".) + {"MCGEE", doCheat, 0 }, // MCGEE (Sets you on fire. Displays the message "YOU'RE FIRED".) + {"KRUEGER", doCheat, 0 }, // KRUEGER (200% health, but sets you on fire. Displays the message "FLAME RETARDANT".) + {"CHEESEHEAD", doCheat, 0 }, // CHEESEHEAD (100% diving suit) + {"COUSTEAU", doCheat, 0 }, // COUSTEAU (200% health and diving suit) + {"VOORHEES", doCheat, 0 }, // VOORHEES (Death mask power-up) + {"LARA CROFT", doCheat, 0 }, // LARA CROFT (All weapons and infinite ammo. Displays the message "LARA RULES". Typing it the second time will lose all weapons and ammo.) + {"HONGKONG", doCheat, 0 }, // HONGKONG (All weapons and infinite ammo) + {"FRANKENSTEIN", doCheat, 0 }, // FRANKENSTEIN (100% med-kit) + {"STERNO", doCheat, 0 }, // STERNO (Temporary blindness (same effect as getting bitten by green spider)) + {"CLARICE", doCheat, 0 }, // CLARICE (Gives 100% body armor, 100% fire armor, 100% spirit armor) + {"FORK YOU", doCheat, 0 }, // FORK YOU (Drunk mode, 1HP, no armor, no weapons, no ammo, no items, no keys, no map, guns akimbo power-up) + {"LIEBERMAN", doCheat, 0 }, // LIEBERMAN (Sets the you cheated flag to true, at the end of the level you will see that you have cheated) + {"EVA GALLI", doCheat, 0 }, // EVA GALLI (Disable/enable clipping (grant the ability to walk through walls)) + {"RATE", doCheat, 1 }, // RATE (Display frame rate (doesn't count as a cheat)) + {"GOONIES", doCheat, 0 }, // GOONIES (Enable full map. Displays the message "YOU HAVE THE MAP".) + //{"SPIELBERG", doCheatparms[0], "health")) { actHealDude(gMe->pXSprite, 200, 200); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; return CCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "weapons")) { SetWeapons(true); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; return CCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "ammo")) { SetAmmo(true); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; return CCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "armor")) { SetArmor(true); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; return CCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "keys")) { SetKeys(true); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; return CCMD_OK; } else if (!Bstrcasecmp(parm->parms[0], "inventory")) { SetToys(true); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; return CCMD_OK; } return CCMD_SHOWHELP; @@ -152,7 +152,7 @@ static int osdcmd_god(CCmdFuncPtr UNUSED(parm)) if (numplayers == 1 && gamestate == GS_LEVEL) { SetGodMode(!gMe->godMode); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; } else Printf("god: Not in a single-player game.\n"); @@ -167,7 +167,7 @@ static int osdcmd_noclip(CCmdFuncPtr UNUSED(parm)) if (numplayers == 1 && gamestate == GS_LEVEL) { SetClipMode(!gNoClip); - gCheatMgr.m_bPlayerCheated = true; + bPlayerCheated = true; } else { @@ -177,24 +177,6 @@ static int osdcmd_noclip(CCmdFuncPtr UNUSED(parm)) return CCMD_OK; } -static int osdcmd_activatecheat(CCmdFuncPtr parm) -{ - FString CheatEntry; - if (parm->numparms != 1) - return CCMD_SHOWHELP; - - CheatEntry = (char*)(parm->parms[0]); - CheatEntry.ToUpper(); - - if (gCheatMgr.Check((char*)(CheatEntry.GetChars()))) - return CCMD_OK; - else - { - Printf("Unrecognized cheat!: %s\n", parm->parms[0]); - return CCMD_OK; - } -} - static int osdcmd_levelwarp(CCmdFuncPtr parm) { if (parm->numparms != 2) @@ -218,8 +200,6 @@ int32_t registerosdcommands(void) C_RegisterFunction("god","god: toggles god mode", osdcmd_god); C_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip); - C_RegisterFunction("activatecheat","activatecheat : activates a classic cheat code", osdcmd_activatecheat); - C_RegisterFunction("levelwarp","levelwarp : warp to episode 'e' and map 'm'", osdcmd_levelwarp); return 0; diff --git a/source/core/cheathandler.cpp b/source/core/cheathandler.cpp index bdd9e215f..85412a0cc 100644 --- a/source/core/cheathandler.cpp +++ b/source/core/cheathandler.cpp @@ -29,6 +29,7 @@ #include "cheathandler.h" #include "printf.h" #include "gamestruct.h" +#include "utf8.h" static cheatseq_t *cheatlist; static int numcheats; @@ -62,7 +63,7 @@ static bool CheatAddKey (cheatseq_t *cheat, uint8_t key, bool *eat) cheat->Args[cheat->CurrentArg++] = key; cheat->Pos++; } - else if (key == *cheat->Pos) + else if (upperforlower[key] == upperforlower[*cheat->Pos]) { cheat->Pos++; } @@ -138,3 +139,11 @@ void PlaybackCheat(const char *p) Printf("activatecheat: Cheats not allowed.\n"); } + +CCMD(activatecheat) +{ + if (argv.argc() != 1) + Printf("activatecheat : activates a classic cheat code\n"); + else + PlaybackCheat(argv[0]); +} diff --git a/source/games/duke/src/ccmds.cpp b/source/games/duke/src/ccmds.cpp index bf7879af3..3425763ce 100644 --- a/source/games/duke/src/ccmds.cpp +++ b/source/games/duke/src/ccmds.cpp @@ -120,16 +120,6 @@ static int ccmd_map(CCmdFuncPtr parm) return CCMD_OK; } - -static int ccmd_activatecheat(CCmdFuncPtr parm) -{ - if (parm->numparms != 1) - return CCMD_SHOWHELP; - - PlaybackCheat(parm->parms[0]); - return CCMD_OK; -} - static int ccmd_god(CCmdFuncPtr) { if (numplayers == 1 && ps[myconnectindex].gm & MODE_GAME) @@ -280,7 +270,6 @@ int registerosdcommands(void) C_RegisterFunction("give","give : gives requested item", ccmd_give); C_RegisterFunction("god","god: toggles god mode", ccmd_god); - C_RegisterFunction("activatecheat","activatecheat : activates a cheat code", ccmd_activatecheat); C_RegisterFunction("noclip","noclip: toggles clipping mode", ccmd_noclip); C_RegisterFunction("restartmap", "restartmap: restarts the current map", ccmd_restartmap); diff --git a/source/sw/src/osdcmds.cpp b/source/sw/src/osdcmds.cpp index c838ea2ca..3c0098bc2 100644 --- a/source/sw/src/osdcmds.cpp +++ b/source/sw/src/osdcmds.cpp @@ -281,7 +281,7 @@ int32_t registerosdcommands(void) C_RegisterFunction("map","map : loads the given map", osdcmd_map); C_RegisterFunction("give","give : gives requested item", osdcmd_give); C_RegisterFunction("god","god: toggles god mode", osdcmd_god); - C_RegisterFunction("activatecheat","activatecheat : activates a classic cheat code", osdcmd_activatecheat); +// C_RegisterFunction("activatecheat","activatecheat : activates a classic cheat code", osdcmd_activatecheat); C_RegisterFunction("noclip","noclip: toggles clipping mode", osdcmd_noclip);