From 07e1c9e9934068806188766d91c9c401199e142c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 13 Jan 2025 10:47:38 +0100 Subject: [PATCH] make game use seperate save when addons are loaded so you can record attack and it will also keep saving to statistics also added a few things it now keeps track of TODO: unfuck the statistics page and add a 2nd one perhaps? due to space reasons menucode is hell --- src/dehacked.c | 9 ++++----- src/doomstat.h | 2 +- src/g_game.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/m_menu.c | 2 +- src/p_tick.c | 13 +++++++++++++ 5 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 5449af593..416ce11ff 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -1800,7 +1800,7 @@ static void readsound(MYFILE *f, INT32 num, const char *savesfxnames[]) * \sa readmaincfg() * \author Graue */ -static boolean GoodDataFileName(const char *s) +/*static boolean GoodDataFileName(const char *s) { const char *p; const char *tail = ".dat"; @@ -1820,7 +1820,7 @@ static boolean GoodDataFileName(const char *s) if (fasticmp(s, "online.dat")) return false; // SRB2Kart online replay folder return true; -} +}*/ static void reademblemdata(MYFILE *f, INT32 num) { @@ -2598,8 +2598,7 @@ static void readmaincfg(MYFILE *f) { maxXtraLife = (UINT8)get_number(word2); } - - else if (fastcmp(word, "GAMEDATA")) + /*else if (fastcmp(word, "GAMEDATA")) { size_t filenamelen; @@ -2626,7 +2625,7 @@ static void readmaincfg(MYFILE *f) strcatbf(savegamename, srb2home, PATHSEP); refreshdirmenu |= REFRESHDIR_GAMEDATA; - } + }*/ else if (fastcmp(word, "RESETDATA")) { P_ResetData(value); diff --git a/src/doomstat.h b/src/doomstat.h index a97723b5a..2215c905b 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -351,7 +351,7 @@ enum GameType // SRB2Kart // String names for gametypes extern const char *Gametype_Names[NUMGAMETYPES]; -extern tic_t totalplaytime; +extern tic_t totalplaytime, raplaytime, onlineplaytime, raceplaytime, battleplaytime; extern UINT32 matchesplayed; extern UINT8 stagefailed; diff --git a/src/g_game.c b/src/g_game.c index 2f778b4e5..272f15a5e 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -175,7 +175,7 @@ INT32 tokenbits; // Used for setting token bits // Old Special Stage INT32 sstimer; // Time allotted in the special stage -tic_t totalplaytime; +tic_t totalplaytime, raplaytime, onlineplaytime, raceplaytime, battleplaytime; UINT32 matchesplayed; // SRB2Kart boolean gamedataloaded = false; @@ -609,6 +609,31 @@ tic_t G_GetBestTime(INT16 map) return mainrecords[map-1]->time; } +// hack t +static void G_SetSaveGameModified(void) +{ + size_t filenamelen; + + savemoddata = true; + majormods = false; // FIXME: this breaks the menu warning screen from popping up, id still want to use it to mention the diff savefile + + strlcpy(gamedatafilename, "modkartdata.dat", sizeof (gamedatafilename)); + strlwr(gamedatafilename); + + // Also save a time attack folder + filenamelen = strlen(gamedatafilename)-4; // Strip off the extension + filenamelen = min(filenamelen, sizeof (timeattackfolder)); + memcpy(timeattackfolder, gamedatafilename, filenamelen); + timeattackfolder[min(filenamelen, sizeof (timeattackfolder) - 1)] = '\0'; + + strcpy(savegamename, timeattackfolder); + strlcat(savegamename, "%u.ssg", sizeof(savegamename)); + // can't use sprintf since there is %u in savegamename + strcatbf(savegamename, srb2home, PATHSEP); + + G_LoadGameData(); +} + // for consistency among messages: this modifies the game and removes savemoddata. void G_SetGameModified(boolean silent, boolean major) { @@ -623,8 +648,10 @@ void G_SetGameModified(boolean silent, boolean major) //savemoddata = false; -- there is literally no reason to do this anymore. majormods = true; + G_SetSaveGameModified(); + if (!silent) - CONS_Alert(CONS_NOTICE, M_GetText("Game must be restarted to play Record Attack.\n")); + CONS_Alert(CONS_NOTICE, M_GetText("Record Attack data will be saved to seperate save.\n")); // If in record attack recording, cancel it. if (modeattacking) @@ -3567,6 +3594,10 @@ void G_LoadGameData(void) M_ClearSecrets(); // emblems, unlocks, maps visited, etc totalplaytime = 0; // total play time (separate from all) matchesplayed = 0; // SRB2Kart: matches played & finished + raplaytime = 0; // SRB2Kart: Record attack play time + onlineplaytime = 0; // SRB2Kart: online play time + raceplaytime = 0; // SRB2Kart: race mode play time + battleplaytime = 0; // SRB2Kart: battle mode play time if (M_CheckParm("-nodata")) return; // Don't load. @@ -3598,6 +3629,15 @@ void G_LoadGameData(void) totalplaytime = READUINT32(save.p); matchesplayed = READUINT32(save.p); + // well no clue but dont think it would like reading garbage from vanilla files + if (strcmp(gamedatafilename, "modkartdata.dat") == 0) + { + raplaytime = READUINT32(save.p); + onlineplaytime = READUINT32(save.p); + raceplaytime = READUINT32(save.p); + battleplaytime = READUINT32(save.p); + } + modded = READUINT8(save.p); // Aha! Someone's been screwing with the save file! @@ -3713,6 +3753,14 @@ void G_SaveGameData(boolean force) WRITEUINT32(save.p, totalplaytime); WRITEUINT32(save.p, matchesplayed); + if (strcmp(gamedatafilename, "modkartdata.dat") == 0) + { + WRITEUINT32(save.p, raplaytime); + WRITEUINT32(save.p, onlineplaytime); + WRITEUINT32(save.p, raceplaytime); + WRITEUINT32(save.p, battleplaytime); + } + btemp = (UINT8)(savemoddata); // what used to be here was profoundly dunderheaded WRITEUINT8(save.p, btemp); diff --git a/src/m_menu.c b/src/m_menu.c index f5008d649..35dc075a4 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6246,7 +6246,7 @@ static boolean M_AddonsRefresh(void) else if (majormods && !prevmajormods) { S_StartSound(NULL, sfx_s221); - message = va("%c%s\x80\nYou've loaded a gameplay-modifying addon.\n\nRecord Attack has been disabled, but you\ncan still play alone in local Multiplayer.\n\nIf you wish to play Record Attack mode, restart the game to disable loaded addons.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), refreshdirname); + message = va("%c%s\x80\nYou've loaded a gameplay-modifying addon.\n\nRecord Attack data will be saved to seperate save.\n\n(Press a key)\n", ('\x80' + (highlightflags>>V_CHARCOLORSHIFT)), refreshdirname); majormodtext = prevmajormods = majormods; } diff --git a/src/p_tick.c b/src/p_tick.c index c85cc862d..2b4b97123 100644 --- a/src/p_tick.c +++ b/src/p_tick.c @@ -618,8 +618,21 @@ void P_Ticker(boolean run) // Keep track of how long they've been playing! if (!demo.playback) // Don't increment if a demo is playing. + { totalplaytime++; + if (netgame) + onlineplaytime++; + else if (modeattacking) + raplaytime++; + + if (G_RaceGametype()) + raceplaytime++; + else if (G_BattleGametype()) + battleplaytime++; + } + + if (run) { // Dynamic slopeness