ref: dec3348a9a2584fa375407341ea265535dc0f8e3
parent: 5914e16076339ef487094dba8be67eed21b0a811
author: Simon Howard <fraggle@gmail.com>
date: Sat Oct 18 16:48:40 EDT 2014
Fix dehacked patch loading order. The order in which we load dehacked patches is important. Change the order so that IWAD dehacked patches are loaded before any others, and so if, for example, we're playing with Freedoom, the Freedoom string replacements can be overridden by those from extra mods we're playing with. As part of this, ditch DEH_Init() and use DEH_ParseCommandLine() instead to handle the -deh option. Remove the DEH_Init() message from startup and show messages about dehacked patches that we load with the WAD files that we load.
--- a/src/deh_main.c
+++ b/src/deh_main.c
@@ -83,6 +83,25 @@
}
}
+static void DEH_Init(void)
+{
+ //!
+ // @category mod
+ //
+ // Ignore cheats in dehacked files.
+ //
+
+ if (M_CheckParm("-nocheats") > 0)
+ {
+ deh_apply_cheats = false;
+ }
+
+ // Call init functions for all the section definitions.
+ InitializeSections();
+
+ deh_initialized = true;
+}
+
// Given a section name, get the section structure which corresponds
static deh_section_t *GetSectionByName(char *name)
@@ -355,8 +374,7 @@
if (!deh_initialized)
{
- InitializeSections();
- deh_initialized = true;
+ DEH_Init();
}
// Before parsing a new file, reset special override flags to false.
@@ -397,8 +415,7 @@
if (!deh_initialized)
{
- InitializeSections();
- deh_initialized = true;
+ DEH_Init();
}
// Reset all special flags to defaults.
@@ -443,23 +460,11 @@
return DEH_LoadLump(lumpnum, allow_long, allow_error);
}
-// Checks the command line for -deh argument
-
-void DEH_Init(void)
+// Check the command line for -deh argument, and others.
+void DEH_ParseCommandLine(void)
{
char *filename;
int p;
-
- //!
- // @category mod
- //
- // Ignore cheats in dehacked files.
- //
-
- if (M_CheckParm("-nocheats") > 0)
- {
- deh_apply_cheats = false;
- }
//!
// @arg <files>
--- a/src/deh_main.h
+++ b/src/deh_main.h
@@ -30,7 +30,7 @@
#define DEH_VANILLA_NUMSTATES 966
#define DEH_VANILLA_NUMSFX 107
-void DEH_Init(void);
+void DEH_ParseCommandLine(void);
int DEH_LoadFile(char *filename);
int DEH_LoadLump(int lumpnum, boolean allow_long, boolean allow_error);
int DEH_LoadLumpByName(char *name, boolean allow_long, boolean allow_error);
--- a/src/doom/d_main.c
+++ b/src/doom/d_main.c
@@ -1082,9 +1082,10 @@
//
void D_DoomMain (void)
{
- int p;
- char file[256];
- char demolumpname[9];
+ int p;
+ char file[256];
+ char demolumpname[9];
+ int numiwadlumps;
I_AtExit(D_Endoom, false);
@@ -1153,11 +1154,6 @@
}
#endif
-
-#ifdef FEATURE_DEHACKED
- printf("DEH_Init: Init Dehacked support.\n");
- DEH_Init();
-#endif
//!
// @vanilla
@@ -1299,6 +1295,7 @@
DEH_printf("W_Init: Init WADfiles.\n");
D_AddFile(iwadfile);
+ numiwadlumps = numlumps;
W_CheckCorrectIWAD(doom);
@@ -1344,6 +1341,17 @@
DEH_AddStringReplacement(PHUSTR_1, "level 33: betray");
}
+#ifdef FEATURE_DEHACKED
+ // Load Dehacked patches specified on the command line with -deh.
+ // Note that there's a very careful and deliberate ordering to how
+ // Dehacked patches are loaded. The order we use is:
+ // 1. IWAD dehacked patches.
+ // 2. Command line dehacked patches specified with -deh.
+ // 3. PWAD dehacked patches in DEHACKED lumps.
+ DEH_ParseCommandLine();
+#endif
+
+ // Load PWAD files.
modifiedgame = W_ParseCommandLine();
// Debug:
@@ -1406,9 +1414,35 @@
I_AtExit((atexit_func_t) G_CheckDemoStatus, true);
// Generate the WAD hash table. Speed things up a bit.
-
W_GenerateHashTable();
+ // Load DEHACKED lumps from WAD files - but only if we give the right
+ // command line parameter.
+
+ //!
+ // @category mod
+ //
+ // Load Dehacked patches from DEHACKED lumps contained in one of the
+ // loaded PWAD files.
+ //
+ if (M_ParmExists("-dehlump"))
+ {
+ int i, loaded = 0;
+
+ for (i = numiwadlumps; i < numlumps; ++i)
+ {
+ if (!strncmp(lumpinfo[i].name, "DEHACKED", 8))
+ {
+ DEH_LoadLump(i, false, false);
+ loaded++;
+ }
+ }
+
+ printf(" loaded %i DEHACKED lumps from PWAD files.\n", loaded);
+ }
+
+ // Set the gamedescription string. This is only possible now that
+ // we've finished loading Dehacked patches.
D_SetGameDescription();
savegamedir = M_GetSaveGameDir(D_SaveGameIWADName(gamemission));
@@ -1459,31 +1493,6 @@
" for more information on how to play using Freedoom:\n"
" http://www.chocolate-doom.org/wiki/index.php/Freedoom\n");
I_PrintDivider();
- }
-
- // Load DEHACKED lumps from WAD files - but only if we give the right
- // command line parameter.
-
- //!
- // @category mod
- //
- // Load Dehacked patches from DEHACKED lumps contained in one of the
- // loaded PWAD files.
- //
- if (M_ParmExists("-dehlump"))
- {
- int i, loaded = 0;
-
- for (i = 0; i < numlumps; ++i)
- {
- if (!strncmp(lumpinfo[i].name, "DEHACKED", 8))
- {
- DEH_LoadLump(i, false, false);
- loaded++;
- }
- }
-
- printf("Loaded %i DEHACKED lumps from WAD files.\n", loaded);
}
DEH_printf("I_Init: Setting up machine state.\n");
--- a/src/heretic/d_main.c
+++ b/src/heretic/d_main.c
@@ -955,11 +955,6 @@
DEH_printf("Z_Init: Init zone memory allocation daemon.\n");
Z_Init();
-#ifdef FEATURE_DEHACKED
- printf("DEH_Init: Init Dehacked support.\n");
- DEH_Init();
-#endif
-
DEH_printf("W_Init: Init WADfiles.\n");
iwadfile = D_FindIWAD(IWAD_MASK_HERETIC, &gamemission);
@@ -972,6 +967,13 @@
D_AddFile(iwadfile);
W_CheckCorrectIWAD(heretic);
+
+#ifdef FEATURE_DEHACKED
+ // Load dehacked patches specified on the command line.
+ DEH_ParseCommandLine();
+#endif
+
+ // Load PWAD files.
W_ParseCommandLine();
//!
--- a/src/strife/d_main.c
+++ b/src/strife/d_main.c
@@ -1390,12 +1390,6 @@
}
#endif
-
-#ifdef FEATURE_DEHACKED
- if(devparm)
- printf("DEH_Init: Init Dehacked support.\n");
- DEH_Init();
-#endif
//!
// @vanilla
@@ -1558,6 +1552,13 @@
DEH_printf("W_Init: Init WADfiles.\n");
D_AddFile(iwadfile);
W_CheckCorrectIWAD(strife);
+
+#ifdef FEATURE_DEHACKED
+ // Load dehacked patches specified on the command line.
+ DEH_ParseCommandLine();
+#endif
+
+ // Load PWAD files.
modifiedgame = W_ParseCommandLine();
// [STRIFE] serial number output