Skip to content

Commit

Permalink
fix incorrectly loading patch rpaks (by floxay)
Browse files Browse the repository at this point in the history
this does not have anything to do with rpak patching itself
  • Loading branch information
r-ex committed Mar 31, 2023
1 parent 7306f79 commit 5379f5f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
1 change: 1 addition & 0 deletions Legion/RpakLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ class RpakLib
uint32_t LoadedFileIndex;

List<string> LoadFileQueue;
List<string> LoadedFilePaths;

// The exporter formats for models and anims
std::unique_ptr<Assets::Exporters::Exporter> ModelExporter;
Expand Down
35 changes: 16 additions & 19 deletions Legion/src/RpakLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,18 @@ RpakLib::RpakLib()

void RpakLib::LoadRpaks(const List<string>& Paths)
{
List<string> LoadedFiles;

for (auto& Rpak : Paths)
{
// Ignore duplicate files triggered by loading multiple rpaks at once.
if (LoadedFiles.Contains(Rpak))
if (this->LoadedFilePaths.Contains(Rpak))
continue;

this->LoadRpak(Rpak, false);

// Copy over to loaded, clear for next file
for (auto& Loaded : this->LoadFileQueue)
{
LoadedFiles.EmplaceBack(Loaded);
this->LoadedFilePaths.EmplaceBack(Loaded);
}
this->LoadFileQueue.Clear();
}
Expand Down Expand Up @@ -830,26 +828,25 @@ bool RpakLib::ParseApexRpak(const string& RpakPath, std::unique_ptr<IO::MemorySt

ParseStream->Read(File->SegmentData.get(), 0, BufferRemaining);

if (this->LoadedFileIndex == 1)
{
string BasePath = IO::Path::GetDirectoryName(RpakPath);
string FileNameNoExt = IO::Path::GetFileNameWithoutExtension(RpakPath);

string BasePath = IO::Path::GetDirectoryName(RpakPath);
string FileNameNoExt = IO::Path::GetFileNameWithoutExtension(RpakPath);

// Trim off the () if exists
if (FileNameNoExt.Contains("("))
FileNameNoExt = FileNameNoExt.Substring(0, FileNameNoExt.IndexOf("("));
if (FileNameNoExt.Contains("("))
FileNameNoExt = FileNameNoExt.Substring(0, FileNameNoExt.IndexOf("("));

string FinalPath = IO::Path::Combine(BasePath, FileNameNoExt);
string FinalPath = IO::Path::Combine(BasePath, FileNameNoExt);

for (uint32_t i = 0; i < Header.PatchIndex; i++)
{
uint16_t PatchIndexToFile = PatchIndicesToFile[i];
for (uint32_t i = 0; i < Header.PatchIndex; i++)
{
uint16_t PatchIndexToFile = PatchIndicesToFile[i];
string AdditionalRpakToLoad = string::Format(PatchIndexToFile == 0 ? "%s.rpak" : "%s(%02d).rpak", FinalPath.ToCString(), PatchIndexToFile);

if (PatchIndexToFile == 0)
this->LoadFileQueue.EmplaceBack(string::Format("%s.rpak", FinalPath.ToCString()));
else
this->LoadFileQueue.EmplaceBack(string::Format("%s(%02d).rpak", FinalPath.ToCString(), PatchIndexToFile));
}
if (this->LoadedFilePaths.Contains(AdditionalRpakToLoad) || this->LoadFileQueue.Contains(AdditionalRpakToLoad))
continue;

this->LoadFileQueue.EmplaceBack(AdditionalRpakToLoad);
}

return true;
Expand Down

0 comments on commit 5379f5f

Please sign in to comment.