From 8177583e2ff3f870c6e8ac186b87b434e0d44293 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 15 Jul 2019 20:48:00 +0200 Subject: [PATCH] - treat configurations which load a secondary WAD on top of a primary IWAD like SVE to consider the secondary WAD an actual IWAD as well. This fixes localization of the SVE menu. --- src/d_iwad.cpp | 8 ++++++-- src/g_level.cpp | 2 +- src/gamedata/d_dehacked.cpp | 4 ++-- src/gamedata/fonts/font.cpp | 2 +- src/gamedata/textures/texturemanager.cpp | 14 +++++++------- src/gamedata/w_wad.h | 6 +++++- src/intermission/intermission_parse.cpp | 2 +- src/playsim/p_user.cpp | 2 +- src/r_data/gldefs.cpp | 4 ++-- src/win32/st_start.cpp | 2 +- 10 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/d_iwad.cpp b/src/d_iwad.cpp index f4431583e..f7656e9d4 100644 --- a/src/d_iwad.cpp +++ b/src/d_iwad.cpp @@ -738,16 +738,20 @@ int FIWadManager::IdentifyVersion (TArray &wadfiles, const char *iwad, D_AddFile (wadfiles, zdoom_wad); // [SP] Load non-free assets if available. This must be done before the IWAD. + int iwadnum; if (D_AddFile(wadfiles, optional_wad)) - Wads.SetIwadNum(2); + iwadnum = 2; else - Wads.SetIwadNum(1); + iwadnum = 1; + Wads.SetIwadNum(iwadnum); if (picks[pick].mRequiredPath.IsNotEmpty()) { D_AddFile (wadfiles, picks[pick].mRequiredPath); + iwadnum++; } D_AddFile (wadfiles, picks[pick].mFullPath); + Wads.SetMaxIwadNum(iwadnum); auto info = mIWadInfos[picks[pick].mInfoIndex]; // Load additional resources from the same directory as the IWAD itself. diff --git a/src/g_level.cpp b/src/g_level.cpp index c989af3d8..741018d2d 100644 --- a/src/g_level.cpp +++ b/src/g_level.cpp @@ -881,7 +881,7 @@ bool FLevelLocals::DoCompleted (FString nextlevel, wbstartstruct_t &wminfo) if (tex != nullptr) { int filenum = Wads.GetLumpFile(tex->GetSourceLump()); - if (filenum >= 0 && filenum <= Wads.GetIwadNum()) + if (filenum >= 0 && filenum <= Wads.GetMaxIwadNum()) { texids[i]->SetInvalid(); } diff --git a/src/gamedata/d_dehacked.cpp b/src/gamedata/d_dehacked.cpp index 7156796db..1f14f8e6a 100644 --- a/src/gamedata/d_dehacked.cpp +++ b/src/gamedata/d_dehacked.cpp @@ -2451,12 +2451,12 @@ int D_LoadDehLumps(DehLumpSource source) { const int filenum = Wads.GetLumpFile(lumpnum); - if (FromIWAD == source && filenum > Wads.GetIwadNum()) + if (FromIWAD == source && filenum > Wads.GetMaxIwadNum()) { // No more DEHACKED lumps in IWAD break; } - else if (FromPWADs == source && filenum <= Wads.GetIwadNum()) + else if (FromPWADs == source && filenum <= Wads.GetMaxIwadNum()) { // Skip DEHACKED lumps from IWAD continue; diff --git a/src/gamedata/fonts/font.cpp b/src/gamedata/fonts/font.cpp index aa0a7af80..480b9a4c4 100644 --- a/src/gamedata/fonts/font.cpp +++ b/src/gamedata/fonts/font.cpp @@ -233,7 +233,7 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla for (auto entry : array) { FTexture *tex = TexMan.GetTexture(entry, false); - if (tex && tex->SourceLump >= 0 && Wads.GetLumpFile(tex->SourceLump) <= Wads.GetIwadNum() && tex->UseType == ETextureType::MiscPatch) + if (tex && tex->SourceLump >= 0 && Wads.GetLumpFile(tex->SourceLump) <= Wads.GetMaxIwadNum() && tex->UseType == ETextureType::MiscPatch) { texs[i] = tex; } diff --git a/src/gamedata/textures/texturemanager.cpp b/src/gamedata/textures/texturemanager.cpp index a8bdba67e..1bdbf9624 100644 --- a/src/gamedata/textures/texturemanager.cpp +++ b/src/gamedata/textures/texturemanager.cpp @@ -443,7 +443,7 @@ bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitut // Mode 3 must also reject substitutions for non-IWAD content. int file = Wads.GetLumpFile(Textures[texnum.GetIndex()].Texture->SourceLump); - if (file > Wads.GetIwadNum()) return true; + if (file > Wads.GetMaxIwadNum()) return true; return false; } @@ -927,7 +927,7 @@ void FTextureManager::AddTexturesForWad(int wadnum, FMultipatchTextureBuilder &b { int firsttexture = Textures.Size(); int lumpcount = Wads.GetNumLumps(); - bool iwad = wadnum == Wads.GetIwadNum(); + bool iwad = wadnum >= Wads.GetIwadNum() && wadnum <= Wads.GetMaxIwadNum(); FirstTextureForFile.Push(firsttexture); @@ -1449,14 +1449,14 @@ void FTextureManager::AdjustSpriteOffsets() for (int i = 0; i < numtex; i++) { - if (Wads.GetLumpFile(i) > Wads.GetIwadNum()) break; // we are past the IWAD - if (Wads.GetLumpNamespace(i) == ns_sprites && Wads.GetLumpFile(i) == Wads.GetIwadNum()) + if (Wads.GetLumpFile(i) > Wads.GetMaxIwadNum()) break; // we are past the IWAD + if (Wads.GetLumpNamespace(i) == ns_sprites && Wads.GetLumpFile(i) >= Wads.GetIwadNum() && Wads.GetLumpFile(i) <= Wads.GetMaxIwadNum()) { char str[9]; Wads.GetLumpName(str, i); str[8] = 0; FTextureID texid = TexMan.CheckForTexture(str, ETextureType::Sprite, 0); - if (texid.isValid() && Wads.GetLumpFile(GetTexture(texid)->SourceLump) > Wads.GetIwadNum()) + if (texid.isValid() && Wads.GetLumpFile(GetTexture(texid)->SourceLump) > Wads.GetMaxIwadNum()) { // This texture has been replaced by some PWAD. memcpy(&sprid, str, 4); @@ -1498,9 +1498,9 @@ void FTextureManager::AdjustSpriteOffsets() if (lumpnum >= 0 && lumpnum < Wads.GetNumLumps()) { int wadno = Wads.GetLumpFile(lumpnum); - if ((iwadonly && wadno == Wads.GetIwadNum()) || (!iwadonly && wadno == ofslumpno)) + if ((iwadonly && wadno >= Wads.GetIwadNum() && wadno <= Wads.GetMaxIwadNum()) || (!iwadonly && wadno == ofslumpno)) { - if (wadno == Wads.GetIwadNum() && !forced && iwadonly) + if (wadno >= Wads.GetIwadNum() && wadno <= Wads.GetMaxIwadNum() && !forced && iwadonly) { memcpy(&sprid, &tex->Name[0], 4); if (donotprocess.CheckKey(sprid)) continue; // do not alter sprites that only get partially replaced. diff --git a/src/gamedata/w_wad.h b/src/gamedata/w_wad.h index 7fc19d5fa..414174bd0 100644 --- a/src/gamedata/w_wad.h +++ b/src/gamedata/w_wad.h @@ -117,6 +117,9 @@ public: int GetIwadNum() { return IwadIndex; } void SetIwadNum(int x) { IwadIndex = x; } + int GetMaxIwadNum() { return MaxIwadIndex; } + void SetMaxIwadNum(int x) { MaxIwadIndex = x; } + void InitMultipleFiles (TArray &filenames, const TArray &deletelumps); void AddFile (const char *filename, FileReader *wadinfo = NULL); int CheckIfWadLoaded (const char *name); @@ -208,7 +211,8 @@ protected: uint32_t NumLumps = 0; // Not necessarily the same as LumpInfo.Size() uint32_t NumWads; - int IwadIndex; + int IwadIndex = -1; + int MaxIwadIndex = -1; void InitHashChains (); // [RH] Set up the lumpinfo hashing diff --git a/src/intermission/intermission_parse.cpp b/src/intermission/intermission_parse.cpp index c7277c847..dc07b3a4b 100644 --- a/src/intermission/intermission_parse.cpp +++ b/src/intermission/intermission_parse.cpp @@ -323,7 +323,7 @@ bool FIntermissionActionTextscreen::ParseKey(FScanner &sc) else { // only print an error if coming from a PWAD - if (Wads.GetLumpFile(sc.LumpNum) > Wads.GetIwadNum()) + if (Wads.GetLumpFile(sc.LumpNum) > Wads.GetMaxIwadNum()) sc.ScriptMessage("Unknown text lump '%s'", sc.String); mText.Format("Unknown text lump '%s'", sc.String); } diff --git a/src/playsim/p_user.cpp b/src/playsim/p_user.cpp index da1e46494..3c7965918 100644 --- a/src/playsim/p_user.cpp +++ b/src/playsim/p_user.cpp @@ -836,7 +836,7 @@ static int SetupCrouchSprite(AActor *self, int crouchsprite) int wadnorm = Wads.GetLumpFile(spritenorm); int wadcrouch = Wads.GetLumpFile(spritenorm); - if (wadnorm > Wads.GetIwadNum() && wadcrouch <= Wads.GetIwadNum()) + if (wadnorm > Wads.GetMaxIwadNum() && wadcrouch <= Wads.GetMaxIwadNum()) { // Question: Add an option / disable crouching or do what? return false; diff --git a/src/r_data/gldefs.cpp b/src/r_data/gldefs.cpp index 2c6dbf8fb..8f860f9e7 100644 --- a/src/r_data/gldefs.cpp +++ b/src/r_data/gldefs.cpp @@ -1152,7 +1152,7 @@ class GLDefsParser if (lumpnum != -1) { - if (iwad && Wads.GetLumpFile(lumpnum) <= Wads.GetIwadNum()) useme = true; + if (iwad && Wads.GetLumpFile(lumpnum) <= Wads.GetMaxIwadNum()) useme = true; if (thiswad && Wads.GetLumpFile(lumpnum) == workingLump) useme = true; } if (!useme) return; @@ -1336,7 +1336,7 @@ class GLDefsParser if (lumpnum != -1) { - if (iwad && Wads.GetLumpFile(lumpnum) <= Wads.GetIwadNum()) useme = true; + if (iwad && Wads.GetLumpFile(lumpnum) <= Wads.GetMaxIwadNum()) useme = true; if (thiswad && Wads.GetLumpFile(lumpnum) == workingLump) useme = true; } if (!useme) return; diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index 8acb6ddbb..036a7e142 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -1106,7 +1106,7 @@ void ST_Endoom() exit(0); } - if (Wads.GetLumpFile(endoom_lump) == Wads.GetIwadNum() && showendoom == 2) + if (Wads.GetLumpFile(endoom_lump) == Wads.GetMaxIwadNum() && showendoom == 2) { // showendoom==2 means to show only lumps from PWADs. exit(0);