- 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();
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;

View file

@ -146,8 +146,11 @@ void FWadCollection::InitMultipleFiles (TArray<FString> &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()
static FResourceLump placeholderLump;
void FWadCollection::MoveLumpsInFolder(const char *path)
{
TArray<LumpRecord> lumpsToMove;
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);
}
}
//==========================================================================

View file

@ -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
};