ref: 2ab317c4b7c304bc624f803e7b5763ab27f39f7b
parent: 621552f637fff1fcdf3f3a5e9b450d733c01c746
author: Simon Howard <fraggle@gmail.com>
date: Sat Oct 18 10:11:51 EDT 2014
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.
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -986,17 +986,57 @@
}
}
-// 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 @@
// 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 @@
}
// Still not found?
-
if (chex_deh == NULL)
{
I_Error("Unable to find Chex Quest dehacked file (chex.deh).\n"
@@ -1039,42 +1077,6 @@
}
}
-// 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 @@
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 @@
// 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));