Skip to content

Commit

Permalink
Pak file fixes
Browse files Browse the repository at this point in the history
- FPakVFS::LoadPakIndex now handling "unused" pak values
- FPakVFS::DecryptDataBlock crashes with "FString[0/0] error when AES was not provided, now displaying more informative error
  • Loading branch information
gildor2 committed Oct 31, 2021
1 parent e8ae1c0 commit a41ccc2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Unreal/FileSystem/UnArchivePak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ void FPakVFS::DecryptDataBlock(byte* Data, int DataSize)
guard(FPakVFS::DecryptDataBlock);

const FString& Key = GetPakEncryptionKey();
if (Key.Len() == 0) appError("Empty AES key");
appDecryptAES(Data, DataSize, &Key[0], Key.Len());

unguard;
Expand Down Expand Up @@ -967,19 +968,25 @@ bool FPakVFS::LoadPakIndex(FArchive* reader, const FPakInfo& info, FString& erro
FolderIndex = RegisterGameFolder(*DirectoryPath);
}

for (int DirectoryFileIndex = 0; DirectoryFileIndex < NumFilesInDirectory; DirectoryFileIndex++)
for (int DirectoryFileIndex = 0; DirectoryFileIndex < NumFilesInDirectory; DirectoryFileIndex++, FileIndex++)
{
guard(File);
// Read FPakDirectory entry Key
FStaticString<MAX_PACKAGE_PATH> DirectoryFileName;
InfoReader << DirectoryFileName;

// Read FPakDirectory entry Value
// PakEntryLocation is positive (offset in 'EncodedPakEntries') or negative (index in 'Files').
int32 PakEntryLocation;
InfoReader << PakEntryLocation;
if (PakEntryLocation == 0x7fffffff || PakEntryLocation == 0x80000000)
{
// 0x7fffffff and 0x80000000 are special values, "Invalid" or "Unused"
continue;
}

FPakEntry& E = FileInfos[FileIndex];

// PakEntryLocation is positive (offset in 'EncodedPakEntries') or negative (index in 'Files')
// References in UE4:
// FPakFile::DecodePakEntry <- FPakFile::GetPakEntry (decode or pick from 'Files') <- FPakFile::Find (name to index/location)
if (PakEntryLocation < 0)
Expand Down Expand Up @@ -1012,7 +1019,6 @@ bool FPakVFS::LoadPakIndex(FArchive* reader, const FPakInfo& info, FString& erro
reg.IndexInArchive = FileIndex;
E.FileInfo = RegisterFile(reg);

FileIndex++;
unguard;
}
unguard;
Expand Down

0 comments on commit a41ccc2

Please sign in to comment.