From 1b43cdddd59ebeb6ea76721ba953370476478f0f Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 27 Feb 2022 10:11:55 -0500 Subject: [PATCH 1/8] Allow saving in modified games. --- src/d_main.c | 6 ++++ src/d_netcmd.c | 6 ++-- src/f_finale.c | 17 +++------ src/g_game.c | 97 +++++++++++++++++++++++++++++++++----------------- src/hu_stuff.c | 2 +- src/m_cond.c | 3 -- src/m_menu.c | 30 ++++++---------- src/p_inter.c | 2 +- src/p_mobj.c | 6 +--- src/p_setup.c | 6 ++-- src/p_spec.c | 2 +- src/y_inter.c | 4 +-- 12 files changed, 97 insertions(+), 84 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 3566e7f3d..b1f09aaa8 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1473,6 +1473,12 @@ void D_SRB2Main(void) //--------------------------------------------------------- CONFIG.CFG M_FirstLoadConfig(); // WARNING : this do a "COM_BufExecute()" + if (M_CheckParm("-gamedata") && M_IsNextParm()) + { + // Moved from G_LoadGameData itself, as it would cause some crazy + // confusion issues when loading mods. + strlcpy(gamedatafilename, M_GetNextParm(), sizeof gamedatafilename); + } G_LoadGameData(); #if defined (__unix__) || defined (UNIXCOMMON) || defined (HAVE_SDL) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4e90db0dc..73bfe9e17 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -4613,11 +4613,11 @@ static void Fishcake_OnChange(void) static void Command_Isgamemodified_f(void) { if (savemoddata) - CONS_Printf(M_GetText("modifiedgame is true, but you can save emblem and time data in this mod.\n")); + CONS_Printf(M_GetText("modifiedgame is true, but you can save time data in this mod.\n")); else if (modifiedgame) - CONS_Printf(M_GetText("modifiedgame is true, extras will not be unlocked\n")); + CONS_Printf(M_GetText("modifiedgame is true, time data can't be saved\n")); else - CONS_Printf(M_GetText("modifiedgame is false, you can unlock extras\n")); + CONS_Printf(M_GetText("modifiedgame is false, you can save time data\n")); } static void Command_Cheats_f(void) diff --git a/src/f_finale.c b/src/f_finale.c index bca8e3ba6..73f6281a1 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1575,7 +1575,9 @@ void F_GameEvaluationDrawer(void) { V_DrawString(8, 16, V_YELLOWMAP, "Unlocked:"); - if (!(netgame) && (!modifiedgame || savemoddata)) + if (netgame) + V_DrawString(8, 96, V_YELLOWMAP, "Multiplayer games\ncan't unlock\nextras!"); + else { INT32 startcoord = 32; @@ -1590,10 +1592,6 @@ void F_GameEvaluationDrawer(void) } } } - else if (netgame) - V_DrawString(8, 96, V_YELLOWMAP, "Multiplayer games\ncan't unlock\nextras!"); - else - V_DrawString(8, 96, V_YELLOWMAP, "Modified games\ncan't unlock\nextras!"); } #endif @@ -1657,7 +1655,7 @@ void F_GameEvaluationTicker(void) HU_DoCEcho("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Multiplayer games can't unlock extras!"); S_StartSound(NULL, sfx_s3k68); } - else if (!modifiedgame || savemoddata) + else { ++timesBeaten; @@ -1672,13 +1670,6 @@ void F_GameEvaluationTicker(void) G_SaveGameData(); } - else - { - HU_SetCEchoFlags(V_YELLOWMAP|V_RETURN8); - HU_SetCEchoDuration(6); - HU_DoCEcho("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\Modified games can't unlock extras!"); - S_StartSound(NULL, sfx_s3k68); - } } } diff --git a/src/g_game.c b/src/g_game.c index 349d90558..edddcc050 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -755,7 +755,7 @@ void G_SetGameModified(boolean silent) savemoddata = false; if (!silent) - CONS_Alert(CONS_NOTICE, M_GetText("Game must be restarted to record statistics.\n")); + CONS_Alert(CONS_NOTICE, M_GetText("Game must be restarted to play Record Attack.\n")); // If in record attack recording, cancel it. if (modeattacking) @@ -3826,8 +3826,7 @@ static void G_UpdateVisited(void) { boolean spec = G_IsSpecialStage(gamemap); // Update visitation flags? - if ((!modifiedgame || savemoddata) // Not modified - && !multiplayer && !demoplayback && (gametype == GT_COOP) // SP/RA/NiGHTS mode + if (!multiplayer && !demoplayback && (gametype == GT_COOP) // SP/RA/NiGHTS mode && !stagefailed) // Did not fail the stage { UINT8 earnedEmblems; @@ -3895,14 +3894,18 @@ static void G_HandleSaveLevel(void) remove(liveeventbackup); cursaveslot = 0; } - else if ((!modifiedgame || savemoddata) && !(netgame || multiplayer || ultimatemode || demorecording || metalrecording || modeattacking)) + else if (!(netgame || multiplayer || ultimatemode || demorecording || metalrecording || modeattacking)) + { G_SaveGame((UINT32)cursaveslot, spstage_start); + } } } // and doing THIS here means you don't lose your progress if you close the game mid-intermission else if (!(ultimatemode || netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) - && (!modifiedgame || savemoddata) && cursaveslot > 0 && CanSaveLevel(lastmap+1)) + && cursaveslot > 0 && CanSaveLevel(lastmap+1)) + { G_SaveGame((UINT32)cursaveslot, lastmap+1); // not nextmap+1 to route around special stages + } } // @@ -4178,8 +4181,10 @@ static void G_DoContinued(void) tokenlist = 0; token = 0; - if (!(netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) && (!modifiedgame || savemoddata) && cursaveslot > 0) + if (!(netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) && cursaveslot > 0) + { G_SaveGameOver((UINT32)cursaveslot, true); + } // Reset # of lives pl->lives = (ultimatemode) ? 1 : startinglivesbalance[numgameovers]; @@ -4244,13 +4249,17 @@ void G_LoadGameSettings(void) S_InitRuntimeSounds(); } +#define GAMEDATA_ID 0x86E4A27C // Change every major version, as usual +#define COMPAT_GAMEDATA_ID 0xFCAFE211 // Can be removed entirely for 2.3 + // G_LoadGameData // Loads the main data file, which stores information such as emblems found, etc. void G_LoadGameData(void) { size_t length; INT32 i, j; - UINT8 modded = false; + + UINT32 versionID; UINT8 rtemp; //For records @@ -4261,6 +4270,9 @@ void G_LoadGameData(void) UINT8 recmares; INT32 curmare; + // Stop saving, until we successfully load it again. + gamedataloaded = false; + // Clear things so previously read gamedata doesn't transfer // to new gamedata G_ClearRecords(); // main and nights records @@ -4268,27 +4280,35 @@ void G_LoadGameData(void) totalplaytime = 0; // total play time (separate from all) if (M_CheckParm("-nodata")) - return; // Don't load. - - // Allow saving of gamedata beyond this point - gamedataloaded = true; - - if (M_CheckParm("-gamedata") && M_IsNextParm()) { - strlcpy(gamedatafilename, M_GetNextParm(), sizeof gamedatafilename); + // Don't load at all. + return; } if (M_CheckParm("-resetdata")) - return; // Don't load (essentially, reset). + { + // Don't load, but do save. (essentially, reset) + gamedataloaded = true; + return; + } length = FIL_ReadFile(va(pandf, srb2home, gamedatafilename), &savebuffer); - if (!length) // Aw, no game data. Their loss! + if (!length) + { + // No gamedata. We can save a new one. + gamedataloaded = true; return; + } save_p = savebuffer; // Version check - if (READUINT32(save_p) != 0xFCAFE211) + versionID = READUINT32(save_p); + if (versionID != GAMEDATA_ID +#ifdef COMPAT_GAMEDATA_ID // backwards compat behavior + && versionID != COMPAT_GAMEDATA_ID +#endif + ) { const char *gdfolder = "the SRB2 folder"; if (strcmp(srb2home,".")) @@ -4301,13 +4321,26 @@ void G_LoadGameData(void) totalplaytime = READUINT32(save_p); - modded = READUINT8(save_p); +#ifdef COMPAT_GAMEDATA_ID + // Ignore for backwards compat, it'll get fixed when saving. + if (versionID == COMPAT_GAMEDATA_ID) + { + // Old files use a UINT8 here. + READUINT8(save_p); + } + else +#endif + { + // Quick & dirty hash for what mod this save file is for. + UINT32 modID = READUINT32(save_p); + UINT32 expectedID = quickncasehash(timeattackfolder, sizeof timeattackfolder); - // Aha! Someone's been screwing with the save file! - if ((modded && !savemoddata)) - goto datacorrupt; - else if (modded != true && modded != false) - goto datacorrupt; + if (modID != expectedID) + { + // Aha! Someone's been screwing with the save file! + goto datacorrupt; + } + } // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) @@ -4393,6 +4426,12 @@ void G_LoadGameData(void) Z_Free(savebuffer); save_p = NULL; + // Don't consider loaded until it's a success! + // It used to do this much earlier, but this would cause the gamedata to + // save over itself when it I_Errors from the corruption landing point below, + // which can accidentally delete players' legitimate data if the code ever has any tiny mistakes! + gamedataloaded = true; + // Silent update unlockables in case they're out of sync with conditions M_SilentUpdateUnlockablesAndEmblems(); @@ -4432,20 +4471,12 @@ void G_SaveGameData(void) return; } - if (modifiedgame && !savemoddata) - { - free(savebuffer); - save_p = savebuffer = NULL; - return; - } - // Version test - WRITEUINT32(save_p, 0xFCAFE211); + WRITEUINT32(save_p, GAMEDATA_ID); WRITEUINT32(save_p, totalplaytime); - btemp = (UINT8)(savemoddata || modifiedgame); - WRITEUINT8(save_p, btemp); + WRITEUINT32(save_p, quickncasehash(timeattackfolder, sizeof timeattackfolder)); // TODO put another cipher on these things? meh, I don't care... for (i = 0; i < NUMMAPS; i++) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index c037abcd7..ebef02319 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -2994,7 +2994,7 @@ static void HU_DrawCoopOverlay(void) V_DrawSmallScaledPatch(148, 172, 0, tokenicon); } - if (LUA_HudEnabled(hud_tabemblems) && (!modifiedgame || savemoddata)) + if (LUA_HudEnabled(hud_tabemblems)) { V_DrawString(160, 144, 0, va("- %d/%d", M_CountEmblems(), numemblems+numextraemblems)); V_DrawScaledPatch(128, 144 - emblemicon->height/4, 0, emblemicon); diff --git a/src/m_cond.c b/src/m_cond.c index 1406317c5..58ee71fec 100644 --- a/src/m_cond.c +++ b/src/m_cond.c @@ -200,9 +200,6 @@ UINT8 M_UpdateUnlockablesAndExtraEmblems(void) char cechoText[992] = ""; UINT8 cechoLines = 0; - if (modifiedgame && !savemoddata) - return false; - M_CheckUnlockConditions(); // Go through extra emblems diff --git a/src/m_menu.c b/src/m_menu.c index 83b788fd5..55733e552 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -757,12 +757,12 @@ static menuitem_t SR_EmblemHintMenu[] = static menuitem_t SP_MainMenu[] = { // Note: If changing the positions here, also change them in M_SinglePlayerMenu() - {IT_CALL | IT_STRING, NULL, "Start Game", M_LoadGame, 76}, - {IT_SECRET, NULL, "Record Attack", M_TimeAttack, 84}, - {IT_SECRET, NULL, "NiGHTS Mode", M_NightsAttack, 92}, - {IT_SECRET, NULL, "Marathon Run", M_Marathon, 100}, - {IT_CALL | IT_STRING, NULL, "Tutorial", M_StartTutorial, 108}, - {IT_CALL | IT_STRING | IT_CALL_NOTMODIFIED, NULL, "Statistics", M_Statistics, 116} + {IT_CALL | IT_STRING, NULL, "Start Game", M_LoadGame, 76}, + {IT_SECRET, NULL, "Record Attack", M_TimeAttack, 84}, + {IT_SECRET, NULL, "NiGHTS Mode", M_NightsAttack, 92}, + {IT_SECRET, NULL, "Marathon Run", M_Marathon, 100}, + {IT_CALL | IT_STRING, NULL, "Tutorial", M_StartTutorial, 108}, + {IT_CALL | IT_STRING, NULL, "Statistics", M_Statistics, 116} }; enum @@ -3514,9 +3514,11 @@ boolean M_Responder(event_t *ev) { if (((currentMenu->menuitems[itemOn].status & IT_TYPE)==IT_CALL || (currentMenu->menuitems[itemOn].status & IT_TYPE)==IT_SUBMENU) - && (currentMenu->menuitems[itemOn].status & IT_CALLTYPE)) + && (currentMenu->menuitems[itemOn].status & IT_CALLTYPE)) { #ifndef DEVELOP + // TODO: Replays are scary, so I left the remaining instances of this alone. + // It'd be nice to get rid of this once and for all though! if (((currentMenu->menuitems[itemOn].status & IT_CALLTYPE) & IT_CALL_NOTMODIFIED) && modifiedgame && !savemoddata) { S_StartSound(NULL, sfx_skid); @@ -8701,12 +8703,6 @@ static void M_DrawLoad(void) loadgameoffset = 0; M_DrawLoadGameData(); - - if (modifiedgame && !savemoddata) - { - V_DrawCenteredThinString(BASEVIDWIDTH/2, 184, 0, "\x85WARNING: \x80The game is modified."); - V_DrawCenteredThinString(BASEVIDWIDTH/2, 192, 0, "Progress will not be saved."); - } } // @@ -9008,18 +9004,12 @@ static void M_HandleLoadSave(INT32 choice) break; case KEY_ENTER: - if (ultimate_selectable && saveSlotSelected == NOSAVESLOT && !savemoddata && !modifiedgame) + if (ultimate_selectable && saveSlotSelected == NOSAVESLOT) { loadgamescroll = 0; S_StartSound(NULL, sfx_skid); M_StartMessage("Are you sure you want to play\n\x85ultimate mode\x80? It isn't remotely fair,\nand you don't even get an emblem for it.\n\n(Press 'Y' to confirm)\n",M_SaveGameUltimateResponse,MM_YESNO); } - else if (saveSlotSelected != NOSAVESLOT && savegameinfo[saveSlotSelected-1].lives == -42 && !(!modifiedgame || savemoddata)) - { - loadgamescroll = 0; - S_StartSound(NULL, sfx_skid); - M_StartMessage(M_GetText("This cannot be done in a modified game.\n\n(Press a key)\n"), NULL, MM_NOTHING); - } else if (saveSlotSelected == NOSAVESLOT || savegameinfo[saveSlotSelected-1].lives != -666) // don't allow loading of "bad saves" { loadgamescroll = 0; diff --git a/src/p_inter.c b/src/p_inter.c index dd3e0f9c2..1094c3045 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2583,7 +2583,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget if (!(netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) && numgameovers < maxgameovers) { numgameovers++; - if ((!modifiedgame || savemoddata) && cursaveslot > 0) + if (cursaveslot > 0) G_SaveGameOver((UINT32)cursaveslot, (target->player->continues <= 0)); } } diff --git a/src/p_mobj.c b/src/p_mobj.c index 4533a2ce8..ac91e0f7f 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11972,11 +11972,7 @@ static boolean P_AllowMobjSpawn(mapthing_t* mthing, mobjtype_t i) break; case MT_EMBLEM: if (netgame || multiplayer) - return false; // Single player - - if (modifiedgame && !savemoddata) - return false; // No cheating!! - + return false; // Single player (You're next on my shit list) break; default: break; diff --git a/src/p_setup.c b/src/p_setup.c index deb308da2..c41a5d94e 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -7746,7 +7746,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) nextmapoverride = 0; skipstats = 0; - if (!(netgame || multiplayer || demoplayback) && (!modifiedgame || savemoddata)) + if (!(netgame || multiplayer || demoplayback)) mapvisited[gamemap-1] |= MV_VISITED; else if (netgame || multiplayer) mapvisited[gamemap-1] |= MV_MP; // you want to record that you've been there this session, but not permanently @@ -7764,8 +7764,10 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) { // I'd love to do this in the menu code instead of here, but everything's a mess and I can't guarantee saving proper player struct info before the first act's started. You could probably refactor it, but it'd be a lot of effort. Easier to just work off known good code. ~toast 22/06/2020 if (!(ultimatemode || netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking || marathonmode) - && (!modifiedgame || savemoddata) && cursaveslot > 0) + && cursaveslot > 0) + { G_SaveGame((UINT32)cursaveslot, gamemap); + } // If you're looking for saving sp file progression (distinct from G_SaveGameOver), check G_DoCompleted. } lastmaploaded = gamemap; // HAS to be set after saving!! diff --git a/src/p_spec.c b/src/p_spec.c index 82337d2f6..94659e0d7 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2937,7 +2937,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 441: // Trigger unlockable - if ((!modifiedgame || savemoddata) && !(netgame || multiplayer)) + if (!(netgame || multiplayer)) { INT32 trigid = line->args[0]; diff --git a/src/y_inter.c b/src/y_inter.c index 7faceff50..e0f246eee 100644 --- a/src/y_inter.c +++ b/src/y_inter.c @@ -1092,7 +1092,7 @@ void Y_Ticker(void) S_StartSound(NULL, (gottoken ? sfx_token : sfx_chchng)); // cha-ching! // Update when done with tally - if ((!modifiedgame || savemoddata) && !(netgame || multiplayer) && !demoplayback) + if (!(netgame || multiplayer) && !demoplayback) { if (M_UpdateUnlockablesAndExtraEmblems()) S_StartSound(NULL, sfx_s3k68); @@ -1223,7 +1223,7 @@ void Y_Ticker(void) S_StartSound(NULL, (gottoken ? sfx_token : sfx_chchng)); // cha-ching! // Update when done with tally - if ((!modifiedgame || savemoddata) && !(netgame || multiplayer) && !demoplayback) + if (!(netgame || multiplayer) && !demoplayback) { if (M_UpdateUnlockablesAndExtraEmblems()) S_StartSound(NULL, sfx_s3k68); From bcfe0da8fc10ed8b3417a11e2dcdb26aeda9bd1f Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 27 Feb 2022 10:22:44 -0500 Subject: [PATCH 2/8] Use old modded behavior when loading old files, instead of ignoring Let's not pretend script-kiddie edited old files are now perfectly A-OK :p --- src/g_game.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index edddcc050..892802d91 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4322,11 +4322,20 @@ void G_LoadGameData(void) totalplaytime = READUINT32(save_p); #ifdef COMPAT_GAMEDATA_ID - // Ignore for backwards compat, it'll get fixed when saving. if (versionID == COMPAT_GAMEDATA_ID) { - // Old files use a UINT8 here. - READUINT8(save_p); + // We'll temporarily use the old condition when loading an older file. + // The proper mod-specific hash will get saved in afterwards. + boolean modded = READUINT8(save_p); + + if (modded && !savemoddata) + { + goto datacorrupt; + } + else if (modded != true && modded != false) + { + goto datacorrupt; + } } else #endif From 4a520e63c67bfe8d9a8320553d1fd71908df3243 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 27 Feb 2022 10:33:58 -0500 Subject: [PATCH 3/8] Don't allow a gamedata named the same as the default time attack folder That'd be kinda scary! --- src/deh_soc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/deh_soc.c b/src/deh_soc.c index 583776ee7..db427b349 100644 --- a/src/deh_soc.c +++ b/src/deh_soc.c @@ -2901,7 +2901,9 @@ static boolean GoodDataFileName(const char *s) p = s + strlen(s) - strlen(tail); if (p <= s) return false; // too short if (!fasticmp(p, tail)) return false; // doesn't end in .dat - if (fasticmp(s, "gamedata.dat")) return false; + + if (fasticmp(s, "gamedata.dat")) return false; // Don't overwrite default gamedata + if (fasticmp(s, "main.dat")) return false; // Don't overwrite default time attack replays return true; } From a22fa1c455cea774946f7032fd74e2e8155c9d9d Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 28 Feb 2022 12:43:00 -0500 Subject: [PATCH 4/8] Compromise on cheats setting modified game Instead of modifying the game, cheats now set a separate "cheats were used in this session" variable, which returns some of the old behavior. HOWEVER, cheats will STILL allow spawning / collecting emblems & unlocking unlockables. Cheats will purely prevent saving progress. (It was always frustrating that devmode would make debugging unlockable features harder...) Lastly, the function to set no-saving was exposed to Lua (`G_SetUsedCheats(silent)`). Just thought it'd be useful for large-scale gamedata-using mods that want to add their own cheat commands. --- src/d_clisrv.c | 3 +++ src/d_clisrv.h | 1 + src/d_main.c | 2 +- src/d_netcmd.c | 20 ++++++++++---------- src/doomstat.h | 1 + src/g_game.c | 31 ++++++++++++++++++++++++++++--- src/g_game.h | 1 + src/lua_baselib.c | 11 +++++++++++ src/lua_script.c | 3 +++ src/m_cheat.c | 20 ++++++++++---------- src/m_menu.c | 20 ++++++++++++++++---- src/p_inter.c | 2 +- src/p_setup.c | 2 +- 13 files changed, 87 insertions(+), 30 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 4cd6333c5..f95b952f3 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1448,6 +1448,7 @@ static boolean SV_SendServerConfig(INT32 node) netbuffer->u.servercfg.gamestate = (UINT8)gamestate; netbuffer->u.servercfg.gametype = (UINT8)gametype; netbuffer->u.servercfg.modifiedgame = (UINT8)modifiedgame; + netbuffer->u.servercfg.usedCheats = (UINT8)usedCheats; memcpy(netbuffer->u.servercfg.server_context, server_context, 8); @@ -4341,6 +4342,8 @@ static void HandlePacketFromAwayNode(SINT8 node) maketic = gametic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); G_SetGametype(netbuffer->u.servercfg.gametype); modifiedgame = netbuffer->u.servercfg.modifiedgame; + if (netbuffer->u.servercfg.usedCheats) + G_SetUsedCheats(true); memcpy(server_context, netbuffer->u.servercfg.server_context, 8); } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index e07864122..f3896c7ea 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -158,6 +158,7 @@ typedef struct UINT8 gametype; UINT8 modifiedgame; + UINT8 usedCheats; char server_context[8]; // Unique context id, generated at server startup. } ATTRPACK serverconfig_pak; diff --git a/src/d_main.c b/src/d_main.c index b1f09aaa8..9df1d8fab 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1506,7 +1506,7 @@ void D_SRB2Main(void) else { if (!M_CheckParm("-server")) - G_SetGameModified(true); + G_SetUsedCheats(true); autostart = true; } } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 73bfe9e17..847f97341 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -1877,7 +1877,7 @@ static void Command_Map_f(void) const char *gametypename; boolean newresetplayers; - boolean mustmodifygame; + boolean wouldSetCheats; INT32 newmapnum; @@ -1898,11 +1898,11 @@ static void Command_Map_f(void) option_gametype = COM_CheckPartialParm("-g"); newresetplayers = ! COM_CheckParm("-noresetplayers"); - mustmodifygame = - !( netgame || multiplayer ) && - (!modifiedgame || savemoddata ); + wouldSetCheats = + !( netgame || multiplayer ) && + !( usedCheats ); - if (mustmodifygame && !option_force) + if (wouldSetCheats && !option_force) { /* May want to be more descriptive? */ CONS_Printf(M_GetText("Sorry, level change disabled in single player.\n")); @@ -1956,9 +1956,9 @@ static void Command_Map_f(void) return; } - if (mustmodifygame && option_force) + if (wouldSetCheats && option_force) { - G_SetGameModified(false); + G_SetUsedCheats(false); } // new gametype value @@ -4259,7 +4259,7 @@ static void Ringslinger_OnChange(void) } if (cv_ringslinger.value) // Only if it's been turned on - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } static void Gravity_OnChange(void) @@ -4280,7 +4280,7 @@ static void Gravity_OnChange(void) #endif if (!CV_IsSetToDefault(&cv_gravity)) - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); gravity = cv_gravity.value; } @@ -4596,7 +4596,7 @@ static void Fishcake_OnChange(void) // so don't make modifiedgame always on! if (cv_debug) { - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } else if (cv_debug != cv_fishcake.value) diff --git a/src/doomstat.h b/src/doomstat.h index bce43416b..490054cf9 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -75,6 +75,7 @@ extern SINT8 startinglivesbalance[maxgameovers+1]; extern boolean modifiedgame; extern UINT16 mainwads; extern boolean savemoddata; // This mod saves time/emblem data. +extern boolean usedCheats; extern boolean disableSpeedAdjust; // Don't alter the duration of player states if true extern boolean imcontinuing; // Temporary flag while continuing extern boolean metalrecording; diff --git a/src/g_game.c b/src/g_game.c index 892802d91..e75bb433e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -96,6 +96,7 @@ SINT8 startinglivesbalance[maxgameovers+1] = {3, 5, 7, 9, 12, 15, 20, 25, 30, 40 UINT16 mainwads = 0; boolean modifiedgame; // Set if homebrew PWAD stuff has been added. boolean savemoddata = false; +boolean usedCheats = false; // Set when a gamedata-preventing cheat command is used. UINT8 paused; UINT8 modeattacking = ATTACKING_NONE; boolean disableSpeedAdjust = false; @@ -764,6 +765,23 @@ void G_SetGameModified(boolean silent) Command_ExitGame_f(); } +void G_SetUsedCheats(boolean silent) +{ + if (usedCheats) + return; + + usedCheats = true; + + if (!silent) + CONS_Alert(CONS_NOTICE, M_GetText("Game must be restarted to save progress.\n")); + + // If in record attack recording, cancel it. + if (modeattacking) + M_EndModeAttackRun(); + else if (marathonmode) + Command_ExitGame_f(); +} + /** Builds an original game map name from a map number. * The complexity is due to MAPA0-MAPZZ. * @@ -3894,7 +3912,7 @@ static void G_HandleSaveLevel(void) remove(liveeventbackup); cursaveslot = 0; } - else if (!(netgame || multiplayer || ultimatemode || demorecording || metalrecording || modeattacking)) + else if (!usedCheats && !(netgame || multiplayer || ultimatemode || demorecording || metalrecording || modeattacking)) { G_SaveGame((UINT32)cursaveslot, spstage_start); } @@ -3902,7 +3920,7 @@ static void G_HandleSaveLevel(void) } // and doing THIS here means you don't lose your progress if you close the game mid-intermission else if (!(ultimatemode || netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) - && cursaveslot > 0 && CanSaveLevel(lastmap+1)) + && !usedCheats && cursaveslot > 0 && CanSaveLevel(lastmap+1)) { G_SaveGame((UINT32)cursaveslot, lastmap+1); // not nextmap+1 to route around special stages } @@ -4181,7 +4199,7 @@ static void G_DoContinued(void) tokenlist = 0; token = 0; - if (!(netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) && cursaveslot > 0) + if (!(netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) && !usedCheats && cursaveslot > 0) { G_SaveGameOver((UINT32)cursaveslot, true); } @@ -4480,6 +4498,13 @@ void G_SaveGameData(void) return; } + if (usedCheats) + { + free(savebuffer); + save_p = savebuffer = NULL; + return; + } + // Version test WRITEUINT32(save_p, GAMEDATA_ID); diff --git a/src/g_game.h b/src/g_game.h index dca043f2e..a781e23f9 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -243,6 +243,7 @@ void G_LoadGameData(void); void G_LoadGameSettings(void); void G_SetGameModified(boolean silent); +void G_SetUsedCheats(boolean silent); void G_SetGamestate(gamestate_t newstate); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 29adb478a..031a155d2 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3612,6 +3612,16 @@ static int lib_gRemovePlayer(lua_State *L) } +static int lib_gSetUsedCheats(lua_State *L) +{ + // Let large-scale level packs using Lua be able to add cheat commands. + boolean silent = lua_optboolean(L, 1); + //NOHUD + //INLEVEL + G_SetUsedCheats(silent); + return 0; +} + static int Lcheckmapnumber (lua_State *L, int idx, const char *fun) { if (ISINLEVEL) @@ -4213,6 +4223,7 @@ static luaL_Reg lib[] = { {"G_AddGametype", lib_gAddGametype}, {"G_AddPlayer", lib_gAddPlayer}, {"G_RemovePlayer", lib_gRemovePlayer}, + {"G_SetUsedCheats", lib_gSetUsedCheats}, {"G_BuildMapName",lib_gBuildMapName}, {"G_BuildMapTitle",lib_gBuildMapTitle}, {"G_FindMap",lib_gFindMap}, diff --git a/src/lua_script.c b/src/lua_script.c index 4d4071545..5f16bca8a 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -204,6 +204,9 @@ int LUA_PushGlobals(lua_State *L, const char *word) } else if (fastcmp(word,"modifiedgame")) { lua_pushboolean(L, modifiedgame && !savemoddata); return 1; + } else if (fastcmp(word,"usedCheats")) { + lua_pushboolean(L, usedCheats); + return 1; } else if (fastcmp(word,"menuactive")) { lua_pushboolean(L, menuactive); return 1; diff --git a/src/m_cheat.c b/src/m_cheat.c index 89c8009ae..78fb3a505 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -81,7 +81,7 @@ static UINT8 cheatf_warp(void) S_StartSound(0, sfx_itemup); // Temporarily unlock stuff. - G_SetGameModified(false); + G_SetUsedCheats(false); unlockables[31].unlocked = true; // credits unlockables[30].unlocked = true; // sound test unlockables[28].unlocked = true; // level select @@ -106,7 +106,7 @@ static UINT8 cheatf_devmode(void) S_StartSound(0, sfx_itemup); // Just unlock all the things and turn on -debug and console devmode. - G_SetGameModified(false); + G_SetUsedCheats(false); for (i = 0; i < MAXUNLOCKABLES; i++) unlockables[i].unlocked = true; devparm = true; @@ -275,7 +275,7 @@ void Command_CheatNoClip_f(void) plyr->pflags ^= PF_NOCLIP; CONS_Printf(M_GetText("No Clipping %s\n"), plyr->pflags & PF_NOCLIP ? M_GetText("On") : M_GetText("Off")); - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } void Command_CheatGod_f(void) @@ -290,7 +290,7 @@ void Command_CheatGod_f(void) plyr->pflags ^= PF_GODMODE; CONS_Printf(M_GetText("Cheese Mode %s\n"), plyr->pflags & PF_GODMODE ? M_GetText("On") : M_GetText("Off")); - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } void Command_CheatNoTarget_f(void) @@ -305,7 +305,7 @@ void Command_CheatNoTarget_f(void) plyr->pflags ^= PF_INVIS; CONS_Printf(M_GetText("SEP Field %s\n"), plyr->pflags & PF_INVIS ? M_GetText("On") : M_GetText("Off")); - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } void Command_Scale_f(void) @@ -879,7 +879,7 @@ void Command_Devmode_f(void) return; } - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } void Command_Setrings_f(void) @@ -905,7 +905,7 @@ void Command_Setrings_f(void) // no totalsphere addition to revert } - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } } @@ -928,7 +928,7 @@ void Command_Setlives_f(void) P_GivePlayerLives(&players[consoleplayer], atoi(COM_Argv(1))); } - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } } @@ -955,7 +955,7 @@ void Command_Setcontinues_f(void) players[consoleplayer].continues = numcontinues; - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } } @@ -1446,7 +1446,7 @@ void Command_ObjectPlace_f(void) REQUIRE_SINGLEPLAYER; REQUIRE_NOULTIMATE; - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); silent = COM_CheckParm("-silent"); diff --git a/src/m_menu.c b/src/m_menu.c index 55733e552..81567662a 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -7082,7 +7082,7 @@ static void M_AllowSuper(INT32 choice) M_StartMessage(M_GetText("You are now capable of turning super.\nRemember to get all the emeralds!\n"),NULL,MM_NOTHING); SR_PandorasBox[6].status = IT_GRAYEDOUT; - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } static void M_GetAllEmeralds(INT32 choice) @@ -7093,7 +7093,7 @@ static void M_GetAllEmeralds(INT32 choice) M_StartMessage(M_GetText("You now have all 7 emeralds.\nUse them wisely.\nWith great power comes great ring drain.\n"),NULL,MM_NOTHING); SR_PandorasBox[7].status = IT_GRAYEDOUT; - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } static void M_DestroyRobotsResponse(INT32 ch) @@ -7104,7 +7104,7 @@ static void M_DestroyRobotsResponse(INT32 ch) // Destroy all robots P_DestroyRobots(); - G_SetGameModified(multiplayer); + G_SetUsedCheats(false); } static void M_DestroyRobots(INT32 choice) @@ -8703,6 +8703,12 @@ static void M_DrawLoad(void) loadgameoffset = 0; M_DrawLoadGameData(); + + if (usedCheats) + { + V_DrawCenteredThinString(BASEVIDWIDTH/2, 184, 0, "\x85WARNING:\x80 Cheats have been activated."); + V_DrawCenteredThinString(BASEVIDWIDTH/2, 192, 0, "Progress will not be saved."); + } } // @@ -9004,12 +9010,18 @@ static void M_HandleLoadSave(INT32 choice) break; case KEY_ENTER: - if (ultimate_selectable && saveSlotSelected == NOSAVESLOT) + if (ultimate_selectable && saveSlotSelected == NOSAVESLOT && !usedCheats) { loadgamescroll = 0; S_StartSound(NULL, sfx_skid); M_StartMessage("Are you sure you want to play\n\x85ultimate mode\x80? It isn't remotely fair,\nand you don't even get an emblem for it.\n\n(Press 'Y' to confirm)\n",M_SaveGameUltimateResponse,MM_YESNO); } + else if (saveSlotSelected != NOSAVESLOT && savegameinfo[saveSlotSelected-1].lives == -42 && usedCheats) + { + loadgamescroll = 0; + S_StartSound(NULL, sfx_skid); + M_StartMessage(M_GetText("This cannot be done in a cheated game.\n\n(Press a key)\n"), NULL, MM_NOTHING); + } else if (saveSlotSelected == NOSAVESLOT || savegameinfo[saveSlotSelected-1].lives != -666) // don't allow loading of "bad saves" { loadgamescroll = 0; diff --git a/src/p_inter.c b/src/p_inter.c index 1094c3045..b86bb39a6 100644 --- a/src/p_inter.c +++ b/src/p_inter.c @@ -2583,7 +2583,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget if (!(netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking) && numgameovers < maxgameovers) { numgameovers++; - if (cursaveslot > 0) + if (!usedCheats && cursaveslot > 0) G_SaveGameOver((UINT32)cursaveslot, (target->player->continues <= 0)); } } diff --git a/src/p_setup.c b/src/p_setup.c index c41a5d94e..a965c5142 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -7764,7 +7764,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate) { // I'd love to do this in the menu code instead of here, but everything's a mess and I can't guarantee saving proper player struct info before the first act's started. You could probably refactor it, but it'd be a lot of effort. Easier to just work off known good code. ~toast 22/06/2020 if (!(ultimatemode || netgame || multiplayer || demoplayback || demorecording || metalrecording || modeattacking || marathonmode) - && cursaveslot > 0) + && !usedCheats && cursaveslot > 0) { G_SaveGame((UINT32)cursaveslot, gamemap); } From f082acbbdbc6dcb535804c4c050f0a95ea3fb773 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Mon, 28 Feb 2022 12:48:18 -0500 Subject: [PATCH 5/8] Don't allow Record Attack in cheated games --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 81567662a..6d1dec19e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3519,7 +3519,7 @@ boolean M_Responder(event_t *ev) #ifndef DEVELOP // TODO: Replays are scary, so I left the remaining instances of this alone. // It'd be nice to get rid of this once and for all though! - if (((currentMenu->menuitems[itemOn].status & IT_CALLTYPE) & IT_CALL_NOTMODIFIED) && modifiedgame && !savemoddata) + if (((currentMenu->menuitems[itemOn].status & IT_CALLTYPE) & IT_CALL_NOTMODIFIED) && (modifiedgame && !savemoddata) && !usedCheats) { S_StartSound(NULL, sfx_skid); M_StartMessage(M_GetText("This cannot be done in a modified game.\n\n(Press a key)\n"), NULL, MM_NOTHING); From 947dbda045929e0577a52a898bd40e71a6066ac1 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 3 Mar 2022 10:48:44 -0500 Subject: [PATCH 6/8] Use savemoddata for ultimate file check --- src/m_menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 6d1dec19e..c5c49a7b8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9010,7 +9010,7 @@ static void M_HandleLoadSave(INT32 choice) break; case KEY_ENTER: - if (ultimate_selectable && saveSlotSelected == NOSAVESLOT && !usedCheats) + if (ultimate_selectable && saveSlotSelected == NOSAVESLOT && !savemoddata) { loadgamescroll = 0; S_StartSound(NULL, sfx_skid); From d3ff5342dd4cec3583523a8d53e6d1d6f7b7b591 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Sun, 1 May 2022 19:34:18 -0400 Subject: [PATCH 7/8] Minor adjustments --- src/m_cheat.c | 6 ------ src/m_menu.c | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/m_cheat.c b/src/m_cheat.c index 78fb3a505..18a5a8609 100644 --- a/src/m_cheat.c +++ b/src/m_cheat.c @@ -72,9 +72,6 @@ static UINT8 cheatf_ultimate(void) static UINT8 cheatf_warp(void) { - if (modifiedgame) - return 0; - if (menuactive && currentMenu != &MainDef) return 0; // Only on the main menu! @@ -97,9 +94,6 @@ static UINT8 cheatf_devmode(void) { UINT8 i; - if (modifiedgame) - return 0; - if (menuactive && currentMenu != &MainDef) return 0; // Only on the main menu! diff --git a/src/m_menu.c b/src/m_menu.c index c5c49a7b8..d26712f1e 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6711,7 +6711,7 @@ static void M_DrawAddons(void) // draw save icon x = BASEVIDWIDTH - x - 16; - V_DrawSmallScaledPatch(x, y + 4, ((!modifiedgame || savemoddata) ? 0 : V_TRANSLUCENT), addonsp[NUM_EXT+4]); + V_DrawSmallScaledPatch(x, y + 4, (!usedCheats ? 0 : V_TRANSLUCENT), addonsp[NUM_EXT+4]); if (modifiedgame) V_DrawSmallScaledPatch(x, y + 4, 0, addonsp[NUM_EXT+2]); From 5103253e0b3828db68e1d58a6d3d0749d90ba8e2 Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Wed, 12 Oct 2022 00:57:15 -0400 Subject: [PATCH 8/8] Allow unlockable executors again --- src/p_spec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 94659e0d7..810a7cd3f 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -1797,7 +1797,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller { // Unlockable triggers required INT32 trigid = triggerline->args[1]; - if ((modifiedgame && !savemoddata) || (netgame || multiplayer)) + if (netgame || multiplayer) return false; else if (trigid < 0 || trigid > 31) // limited by 32 bit variable { @@ -1812,7 +1812,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller { // An unlockable itself must be unlocked! INT32 unlockid = triggerline->args[1]; - if ((modifiedgame && !savemoddata) || (netgame || multiplayer)) + if (netgame || multiplayer) return false; else if (unlockid < 0 || unlockid >= MAXUNLOCKABLES) // limited by unlockable count {