From 4f7b4e1ab7679f7276c2b7e75ebf9e9d33f9a93f Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 18 Sep 2025 18:20:10 +0200 Subject: [PATCH] dedupe map replacement checks the actual checks are in P_CheckMapReplacements --- src/d_main.c | 102 +++++++++++++++++--------------------------------- src/p_setup.c | 30 +++++++-------- src/p_setup.h | 2 + 3 files changed, 52 insertions(+), 82 deletions(-) diff --git a/src/d_main.c b/src/d_main.c index 4a430fd22..db19645c7 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -147,8 +147,6 @@ boolean dedicated = false; boolean loaded_config = false; // true once config.cfg loaded AND executed -static void D_CleanFile(char **filearray); - // // D_PostEvent // Called by the I/O functions when input is detected @@ -1123,6 +1121,16 @@ static void D_AddFile(const char *file, char **filearray) filearray[pnumwadfiles] = newfile; } +static void D_CleanFile(char **filearray) +{ + size_t pnumwadfiles; + for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) + { + free(filearray[pnumwadfiles]); + filearray[pnumwadfiles] = NULL; + } +} + // Taken from TSoURDt3rd // https://github.com/StarManiaKG/The-Story-of-Uncapped-Revengence-Discord-the-3rd/blob/main/src/STAR/star_functions.c static INT32 D_DetectFileType(const char* filename) @@ -1284,16 +1292,6 @@ void D_AddPostloadFiles(void) postautoloaded = true; } -static void D_CleanFile(char **filearray) -{ - size_t pnumwadfiles; - for (pnumwadfiles = 0; filearray[pnumwadfiles]; pnumwadfiles++) - { - free(filearray[pnumwadfiles]); - filearray[pnumwadfiles] = NULL; - } -} - // ========================================================================== // Identify the SRB2 version, and IWAD file to use. // ========================================================================== @@ -1422,6 +1420,27 @@ static void IdentifyVersion(void) #endif } +// +// search for maps +// +static void D_CheckMaps(boolean checkreplaced) +{ + INT32 i; + char *name; + UINT16 wadnum; + lumpinfo_t *lumpinfo; + + for (wadnum = 0; wadnum < mainwads; wadnum++) + { + lumpinfo = wadfiles[wadnum]->lumpinfo; + for (i = 0; i < wadfiles[wadnum]->numlumps; i++, lumpinfo++) + { + name = lumpinfo->name; + P_CheckMapReplacements(name, checkreplaced); + } + } +} + // // Center the title string, then add the date and time of compilation. // @@ -1673,12 +1692,9 @@ static void D_CheckSaturnExtraFiles(void) // void D_SRB2Main(void) { - INT32 p, i; + INT32 p; char srb2[82]; // srb2 title banner char title[82]; - lumpinfo_t *lumpinfo; - UINT16 wadnum; - char *name; INT32 pstartmap = 1; boolean autostart = false; @@ -1736,9 +1752,7 @@ void D_SRB2Main(void) #if defined (__OS2__) && !defined (HAVE_SDL) // set PM window title - snprintf(pmData->title, sizeof (pmData->title), - "SRB2Kart" VERSIONSTRING ": %s", - title); + snprintf(pmData->title, sizeof (pmData->title), "SRB2Kart" VERSIONSTRING ": %s", title); pmData->title[sizeof (pmData->title) - 1] = '\0'; #endif @@ -1912,60 +1926,14 @@ void D_SRB2Main(void) // conversion sometimes needs the palette V_ReloadPalette(); - // - // search for maps - // - for (wadnum = 0; wadnum < mainwads; wadnum++) - { - lumpinfo = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < wadfiles[wadnum]->numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - - if (memcmp(name, "MAP", 3) == 0 && name[5] == '\0') // Ignore the headers - { - INT16 num = (INT16)M_MapNumber(name[3], name[4]); - - // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant - if (num <= NUMMAPS && mapheaderinfo[num - 1]) - { - mapheaderinfo[num - 1]->menuflags |= LF2_EXISTSHACK; - } - } - } - } + D_CheckMaps(false); W_InitMultipleFiles(startuppwads, true); // Only search for pwad maps if we actually have a pwad added if (startuppwads[0] != NULL) { - // - // search for maps... again. - // - for (wadnum = mainwads+1; wadnum < numwadfiles; wadnum++) - { - lumpinfo = wadfiles[wadnum]->lumpinfo; - for (i = 0; i < wadfiles[wadnum]->numlumps; i++, lumpinfo++) - { - name = lumpinfo->name; - - if (memcmp(name, "MAP", 3) == 0 && name[5] == '\0') // Ignore the headers - { - INT16 num = (INT16)M_MapNumber(name[3], name[4]); - - // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant - if (num <= NUMMAPS && mapheaderinfo[num - 1]) - { - if (mapheaderinfo[num - 1]->menuflags & LF2_EXISTSHACK) - G_SetGameModified(multiplayer, true); // oops, double-defined - no record attack privileges for you - mapheaderinfo[num - 1]->menuflags |= LF2_EXISTSHACK; - } - - CONS_Printf("%s\n", name); - } - } - } + D_CheckMaps(true); } D_CleanFile(startuppwads); diff --git a/src/p_setup.c b/src/p_setup.c index 8233fb98d..04acf0e34 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -3057,33 +3057,33 @@ static boolean P_CheckSoundReplacements(UINT16 wadnum, char *name, size_t i) return false; } - // -// search for maps +// P_CheckReplacMapReplacements // -static boolean P_CheckMapReplacements(char *name) +// search for maps and check if they replace another map when checkreplaced is set +// +boolean P_CheckMapReplacements(char *name, boolean checkreplaced) { - if (memcmp(name, "MAP", 3) == 0) // Ignore the headers + if (memcmp(name, "MAP", 3) == 0 && name[5] == '\0') // Ignore the headers { - INT16 num; - - if (name[5] != '\0') - return false; - - num = (INT16)M_MapNumber(name[3], name[4]); + INT16 num = (INT16)M_MapNumber(name[3], name[4]); // we want to record whether this map exists. if it doesn't have a header, we can assume it's not relephant if (num <= NUMMAPS && mapheaderinfo[num-1]) { - if (mapheaderinfo[num-1]->menuflags & LF2_EXISTSHACK) + if (checkreplaced && mapheaderinfo[num-1]->menuflags & LF2_EXISTSHACK) G_SetGameModified(multiplayer, true); // oops, double-defined - no record attack privileges for you mapheaderinfo[num-1]->menuflags |= LF2_EXISTSHACK; } - if (num == gamemap) - partadd_replacescurrentmap = true; + if (checkreplaced) + { + if (num == gamemap) + partadd_replacescurrentmap = true; + + CONS_Printf("%s\n", name); + } - CONS_Printf("%s\n", name); return true; } @@ -3167,7 +3167,7 @@ UINT16 P_PartialAddWadFile(const char *wadfilename, boolean local) if (P_CheckSoundReplacements(wadnum, name, i)) continue; - if (P_CheckMapReplacements(name)) + if (P_CheckMapReplacements(name, true)) { mapsadded = true; continue; diff --git a/src/p_setup.h b/src/p_setup.h index 02f3238c6..7827ebbe6 100644 --- a/src/p_setup.h +++ b/src/p_setup.h @@ -76,6 +76,8 @@ void HWR_LoadLevel(void); boolean P_AddWadFile(const char *wadfilename, boolean local); +boolean P_CheckMapReplacements(char *name, boolean checkreplaced); + // WARNING: The following functions should be grouped as follows: // any amount of PartialAdds followed by MultiSetups until returned true, // as soon as possible.