Skip to content

Commit

Permalink
- treat configurations which load a secondary WAD on top of a primary…
Browse files Browse the repository at this point in the history
… IWAD like SVE to consider the secondary WAD an actual IWAD as well.

This fixes localization of the SVE menu.
  • Loading branch information
coelckers committed Jul 15, 2019
1 parent 7d87df2 commit 8177583
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 19 deletions.
8 changes: 6 additions & 2 deletions src/d_iwad.cpp
Expand Up @@ -738,16 +738,20 @@ int FIWadManager::IdentifyVersion (TArray<FString> &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.
Expand Down
2 changes: 1 addition & 1 deletion src/g_level.cpp
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/gamedata/d_dehacked.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/gamedata/fonts/font.cpp
Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/gamedata/textures/texturemanager.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion src/gamedata/w_wad.h
Expand Up @@ -117,6 +117,9 @@ class FWadCollection
int GetIwadNum() { return IwadIndex; }
void SetIwadNum(int x) { IwadIndex = x; }

int GetMaxIwadNum() { return MaxIwadIndex; }
void SetMaxIwadNum(int x) { MaxIwadIndex = x; }

void InitMultipleFiles (TArray<FString> &filenames, const TArray<FString> &deletelumps);
void AddFile (const char *filename, FileReader *wadinfo = NULL);
int CheckIfWadLoaded (const char *name);
Expand Down Expand Up @@ -208,7 +211,8 @@ class FWadCollection
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

Expand Down
2 changes: 1 addition & 1 deletion src/intermission/intermission_parse.cpp
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/playsim/p_user.cpp
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/r_data/gldefs.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/win32/st_start.cpp
Expand Up @@ -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);
Expand Down

0 comments on commit 8177583

Please sign in to comment.