From 587fd75190871c2d19e32ecd9fe132a635d90954 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 13 Sep 2019 13:55:53 +0200 Subject: [PATCH] - extended lump injection to allow injecting data into a PWAD's directory, not just the IWAD. --- src/gamedata/resourcefiles/resourcefile.h | 4 ++- src/gamedata/w_wad.cpp | 42 ++++++++++++----------- src/gamedata/w_wad.h | 3 +- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/src/gamedata/resourcefiles/resourcefile.h b/src/gamedata/resourcefiles/resourcefile.h index 65e0ef3f1f..a07029e842 100644 --- a/src/gamedata/resourcefiles/resourcefile.h +++ b/src/gamedata/resourcefiles/resourcefile.h @@ -74,7 +74,7 @@ struct FResourceLump int ReleaseCache(); protected: - virtual int FillCache() = 0; + virtual int FillCache() {} }; @@ -114,6 +114,8 @@ public: uint32_t LumpCount() const { return NumLumps; } uint32_t GetFirstLump() const { return FirstLump; } void SetFirstLump(uint32_t f) { FirstLump = f; } + const FString &GetHash() const { return Hash; } + virtual void FindStrifeTeaserVoices (); virtual bool Open(bool quiet) = 0; diff --git a/src/gamedata/w_wad.cpp b/src/gamedata/w_wad.cpp index 16deadc900..d7d9911d86 100644 --- a/src/gamedata/w_wad.cpp +++ b/src/gamedata/w_wad.cpp @@ -146,9 +146,12 @@ void FWadCollection::InitMultipleFiles (TArray &filenames, const TArray { int baselump = NumLumps; AddFile (filenames[i]); + + if (i == (unsigned)MaxIwadIndex) MoveLumpsInFolder("after_iwad/"); + FStringf path("filter/%s", Files.Last()->GetHash().GetChars()); + MoveLumpsInFolder(path); } - MoveIWadModifiers(); - + NumLumps = LumpInfo.Size(); if (NumLumps == 0) { @@ -1056,39 +1059,38 @@ void FWadCollection::FixMacHexen() //========================================================================== // -// MoveIWadModifiers +// MoveLumpsInFolder // -// Moves all content from the after_iwad subfolder of the internal -// resources to the first positions in the lump directory after the IWAD. +// Moves all content from the given subfolder of the internal +// resources to the current end of the directory. // Used to allow modifying content in the base files, this is needed // so that Hacx and Harmony can override some content that clashes -// with localization. +// with localization, and to inject modifying data into mods, in case +// this is needed for some compatibility requirement. // //========================================================================== -void FWadCollection::MoveIWadModifiers() -{ - TArray lumpsToMove; +static FResourceLump placeholderLump; +void FWadCollection::MoveLumpsInFolder(const char *path) +{ + auto len = strlen(path); + auto wadnum = LumpInfo.Last().wadnum; + unsigned i; for (i = 0; i < LumpInfo.Size(); i++) { auto& li = LumpInfo[i]; if (li.wadnum >= GetIwadNum()) break; - if (li.lump->FullName.Left(11).CompareNoCase("after_iwad/") == 0) + if (li.lump->FullName.Left(len).CompareNoCase(path) == 0) { - lumpsToMove.Push(li); - LumpInfo.Delete(i--); + LumpInfo.Push(li); + li.lump = &placeholderLump; // Make the old entry point to something empty. We cannot delete the lump record here because it'd require adjustment of all indices in the list. + auto &ln = LumpInfo.Last(); + ln.wadnum = wadnum; // pretend this is from the WAD this is injected into. + ln.lump->LumpNameSetup(ln.lump->FullName.Mid(len)); } } - if (lumpsToMove.Size() == 0) return; - for (; i < LumpInfo.Size() && LumpInfo[i].wadnum <= Wads.GetMaxIwadNum(); i++); - for (auto& li : lumpsToMove) - { - li.lump->LumpNameSetup(li.lump->FullName.Mid(11)); - li.wadnum = Wads.GetMaxIwadNum(); // pretend this comes from the IWAD itself. - LumpInfo.Insert(i++, li); - } } //========================================================================== diff --git a/src/gamedata/w_wad.h b/src/gamedata/w_wad.h index be45a8f1d7..610e67e9a5 100644 --- a/src/gamedata/w_wad.h +++ b/src/gamedata/w_wad.h @@ -222,7 +222,8 @@ private: void RenameNerve(); void FixMacHexen(); void DeleteAll(); - void MoveIWadModifiers(); + void MoveLumpsInFolder(const char *); + FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD };