- extended lump injection to allow injecting data into a PWAD's directory, not just the IWAD.

This commit is contained in:
Christoph Oelckers 2019-09-13 13:55:53 +02:00
parent 31aa855a51
commit 587fd75190
3 changed files with 27 additions and 22 deletions

View file

@ -74,7 +74,7 @@ struct FResourceLump
int ReleaseCache(); int ReleaseCache();
protected: protected:
virtual int FillCache() = 0; virtual int FillCache() {}
}; };
@ -114,6 +114,8 @@ public:
uint32_t LumpCount() const { return NumLumps; } uint32_t LumpCount() const { return NumLumps; }
uint32_t GetFirstLump() const { return FirstLump; } uint32_t GetFirstLump() const { return FirstLump; }
void SetFirstLump(uint32_t f) { FirstLump = f; } void SetFirstLump(uint32_t f) { FirstLump = f; }
const FString &GetHash() const { return Hash; }
virtual void FindStrifeTeaserVoices (); virtual void FindStrifeTeaserVoices ();
virtual bool Open(bool quiet) = 0; virtual bool Open(bool quiet) = 0;

View file

@ -146,9 +146,12 @@ void FWadCollection::InitMultipleFiles (TArray<FString> &filenames, const TArray
{ {
int baselump = NumLumps; int baselump = NumLumps;
AddFile (filenames[i]); AddFile (filenames[i]);
if (i == (unsigned)MaxIwadIndex) MoveLumpsInFolder("after_iwad/");
FStringf path("filter/%s", Files.Last()->GetHash().GetChars());
MoveLumpsInFolder(path);
} }
MoveIWadModifiers();
NumLumps = LumpInfo.Size(); NumLumps = LumpInfo.Size();
if (NumLumps == 0) if (NumLumps == 0)
{ {
@ -1056,39 +1059,38 @@ void FWadCollection::FixMacHexen()
//========================================================================== //==========================================================================
// //
// MoveIWadModifiers // MoveLumpsInFolder
// //
// Moves all content from the after_iwad subfolder of the internal // Moves all content from the given subfolder of the internal
// resources to the first positions in the lump directory after the IWAD. // resources to the current end of the directory.
// Used to allow modifying content in the base files, this is needed // Used to allow modifying content in the base files, this is needed
// so that Hacx and Harmony can override some content that clashes // 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() static FResourceLump placeholderLump;
{
TArray<LumpRecord> lumpsToMove;
void FWadCollection::MoveLumpsInFolder(const char *path)
{
auto len = strlen(path);
auto wadnum = LumpInfo.Last().wadnum;
unsigned i; unsigned i;
for (i = 0; i < LumpInfo.Size(); i++) for (i = 0; i < LumpInfo.Size(); i++)
{ {
auto& li = LumpInfo[i]; auto& li = LumpInfo[i];
if (li.wadnum >= GetIwadNum()) break; 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.Push(li);
LumpInfo.Delete(i--); 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);
}
} }
//========================================================================== //==========================================================================

View file

@ -222,7 +222,8 @@ private:
void RenameNerve(); void RenameNerve();
void FixMacHexen(); void FixMacHexen();
void DeleteAll(); void DeleteAll();
void MoveIWadModifiers(); void MoveLumpsInFolder(const char *);
FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD FileReader * GetFileReader(int wadnum); // Gets a FileReader object to the entire WAD
}; };