From dd30d2a0451a79a76b29759535bb243f0364680f Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 4 Apr 2017 12:20:12 +0300 Subject: [PATCH] DEHACKED lumps from IWAD now have precedence over embedded lumps and separate files See https://forum.drdteam.org/viewtopic.php?t=7588 Processing order is now the same as in Chocolate Doom prBoom+ loads separate files after all WAD lumps though This makes sense but would change loading sequence existed in ZDoom for years --- src/d_dehacked.cpp | 17 +++++++++++++++-- src/d_dehacked.h | 8 +++++++- src/d_main.cpp | 5 ++++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/d_dehacked.cpp b/src/d_dehacked.cpp index 85a8e8c58..69b7c814a 100644 --- a/src/d_dehacked.cpp +++ b/src/d_dehacked.cpp @@ -2422,16 +2422,29 @@ static bool isDehFile(int lumpnum) && (0 == stricmp(extension, ".deh") || 0 == stricmp(extension, ".bex")); } -int D_LoadDehLumps() +int D_LoadDehLumps(DehLumpSource source) { int lastlump = 0, lumpnum, count = 0; while ((lumpnum = Wads.FindLump("DEHACKED", &lastlump)) >= 0) { + const int filenum = Wads.GetLumpFile(lumpnum); + + if (FromIWAD == source && filenum > FWadCollection::IWAD_FILENUM) + { + // No more DEHACKED lumps in IWAD + break; + } + else if (FromPWADs == source && filenum <= FWadCollection::IWAD_FILENUM) + { + // Skip DEHACKED lumps from IWAD + continue; + } + count += D_LoadDehLump(lumpnum); } - if (0 == PatchSize && dehload > 0) + if (FromPWADs == source && 0 == PatchSize && dehload > 0) { // No DEH/BEX patch is loaded yet, try to find lump(s) with specific extensions diff --git a/src/d_dehacked.h b/src/d_dehacked.h index f7fce9868..bb87993e9 100644 --- a/src/d_dehacked.h +++ b/src/d_dehacked.h @@ -34,7 +34,13 @@ #ifndef __D_DEHACK_H__ #define __D_DEHACK_H__ -int D_LoadDehLumps(); +enum DehLumpSource +{ + FromIWAD, + FromPWADs +}; + +int D_LoadDehLumps(DehLumpSource source); bool D_LoadDehLump(int lumpnum); bool D_LoadDehFile(const char *filename); void FinishDehPatch (); diff --git a/src/d_main.cpp b/src/d_main.cpp index 21433acdb..d6edd7230 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -2507,6 +2507,9 @@ void D_DoomMain (void) if (!batchrun) Printf ("DecalLibrary: Load decals.\n"); DecalLibrary.ReadAllDecals (); + // Load embedded Dehacked patches + D_LoadDehLumps(FromIWAD); + // [RH] Add any .deh and .bex files on the command line. // If there are none, try adding any in the config file. // Note that the command line overrides defaults from the config. @@ -2528,7 +2531,7 @@ void D_DoomMain (void) } // Load embedded Dehacked patches - D_LoadDehLumps(); + D_LoadDehLumps(FromPWADs); // Create replacements for dehacked pickups FinishDehPatch();