From 2ab317c4b7c304bc624f803e7b5763ab27f39f7b Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 18 Oct 2014 14:11:51 -0400 Subject: doom: Refactor IWAD dehacked patch loading. As per suggestions from Fabian Greffrath: * Change -noiwaddeh to -nodeh for consistency with other source ports (Boom-derived source ports use this to disable loading of DEHACKED lumps). * Extend the parameter so that it also disables loading of the Chex Quest dehacked patch. * Refactor the code for loading IWAD dehacked patches to all be in a single function. --- src/doom/d_main.c | 115 ++++++++++++++++++++++++++---------------------------- 1 file changed, 56 insertions(+), 59 deletions(-) diff --git a/src/doom/d_main.c b/src/doom/d_main.c index 15134d7a..ef8e8aea 100644 --- a/src/doom/d_main.c +++ b/src/doom/d_main.c @@ -986,17 +986,57 @@ void PrintGameVersion(void) } } -// Load the Chex Quest dehacked file, if we are in Chex mode. +// Function called at exit to display the ENDOOM screen -static void LoadChexDeh(void) +static void D_Endoom(void) { - char *chex_deh = NULL; - char *sep; + byte *endoom; + + // Don't show ENDOOM if we have it disabled, or we're running + // in screensaver or control test mode. Only show it once the + // game has actually started. + + if (!show_endoom || !main_loop_started + || screensaver_mode || M_CheckParm("-testcontrols") > 0) + { + return; + } + + endoom = W_CacheLumpName(DEH_String("ENDOOM"), PU_STATIC); + + I_Endoom(endoom); +} + +// Load dehacked patches needed for certain IWADs. +static void LoadIwadDeh(void) +{ + // The Freedoom IWADs have DEHACKED lumps that must be loaded. + if (W_CheckNumForName("FREEDOOM") >= 0) + { + // Old versions of Freedoom (before 2014-09) did not have technically + // valid DEHACKED lumps, so ignore errors and just continue if this + // is an old IWAD. + DEH_LoadLumpByName("DEHACKED", false, true); + } + // If this is the HACX IWAD, we need to load the DEHACKED lump. + if (gameversion == exe_hacx) + { + if (!DEH_LoadLumpByName("DEHACKED", true, false)) + { + I_Error("DEHACKED lump not found. Please check that this is the " + "Hacx v1.2 IWAD."); + } + } + + // Chex Quest needs a separate Dehacked patch which must be downloaded + // and installed next to the IWAD. if (gameversion == exe_chex) { - // Look for chex.deh in the same directory as the IWAD file. + char *chex_deh = NULL; + char *sep; + // Look for chex.deh in the same directory as the IWAD file. sep = strrchr(iwadfile, DIR_SEPARATOR); if (sep != NULL) @@ -1014,7 +1054,6 @@ static void LoadChexDeh(void) // If the dehacked patch isn't found, try searching the WAD // search path instead. We might find it... - if (!M_FileExists(chex_deh)) { free(chex_deh); @@ -1022,7 +1061,6 @@ static void LoadChexDeh(void) } // Still not found? - if (chex_deh == NULL) { I_Error("Unable to find Chex Quest dehacked file (chex.deh).\n" @@ -1039,42 +1077,6 @@ static void LoadChexDeh(void) } } -// Function called at exit to display the ENDOOM screen - -static void D_Endoom(void) -{ - byte *endoom; - - // Don't show ENDOOM if we have it disabled, or we're running - // in screensaver or control test mode. Only show it once the - // game has actually started. - - if (!show_endoom || !main_loop_started - || screensaver_mode || M_CheckParm("-testcontrols") > 0) - { - return; - } - - endoom = W_CacheLumpName(DEH_String("ENDOOM"), PU_STATIC); - - I_Endoom(endoom); -} - -static void LoadHacxDeh(void) -{ - // If this is the HACX IWAD, we need to load the DEHACKED lump. - - if (gameversion == exe_hacx) - { - if (!M_ParmExists("-noiwaddeh") - && !DEH_LoadLumpByName("DEHACKED", true, false)) - { - I_Error("DEHACKED lump not found. Please check that this is the " - "Hacx v1.2 IWAD."); - } - } -} - // // D_DoomMain // @@ -1300,23 +1302,22 @@ void D_DoomMain (void) W_CheckCorrectIWAD(doom); - // The Freedoom IWADs have DEHACKED lumps with cosmetic changes to the - // in-game messages. Load this, but allow it to be disabled on the - // command line if desired. + // Now that we've loaded the IWAD, we can figure out what gamemission + // we're playing and which version of Vanilla Doom we need to emulate. + D_IdentifyVersion(); + InitGameVersion(); //! // @category mod // - // Disable automatic loading of Dehacked patches contained in some + // Disable automatic loading of Dehacked patches for certain // IWAD files. - - if (!M_ParmExists("-noiwaddeh") - && W_CheckNumForName("FREEDOOM") >= 0) + // + if (!M_ParmExists("-nodeh")) { - // Old versions of Freedoom (before 2014-09) did not have technically - // valid DEHACKED lumps, so ignore errors and just continue if this - // is an old IWAD. - DEH_LoadLumpByName("DEHACKED", false, true); + // Some IWADs have dehacked patches that need to be loaded for + // them to be played properly. + LoadIwadDeh(); } // Doom 3: BFG Edition includes modified versions of the classic @@ -1407,11 +1408,7 @@ void D_DoomMain (void) // Generate the WAD hash table. Speed things up a bit. W_GenerateHashTable(); - - D_IdentifyVersion(); - InitGameVersion(); - LoadChexDeh(); - LoadHacxDeh(); + D_SetGameDescription(); savegamedir = M_GetSaveGameDir(D_SaveGameIWADName(gamemission)); -- cgit v1.2.3