From a6a9392047173c90c32f88e167fdc165b0d9b76e Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Tue, 24 Jul 2018 15:06:12 -0500 Subject: [PATCH] Account for empty files --- libhac/Savefile/FileEntry.cs | 5 +++-- libhac/Savefile/Savefile.cs | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libhac/Savefile/FileEntry.cs b/libhac/Savefile/FileEntry.cs index b34e250b..c0ecf411 100644 --- a/libhac/Savefile/FileEntry.cs +++ b/libhac/Savefile/FileEntry.cs @@ -9,11 +9,12 @@ namespace libhac.Savefile public int ParentDirIndex { get; } public string Name { get; } public int Field44 { get; } - public int Offset { get; } + public int BlockIndex { get; } public long Size { get; } public long Field54 { get; } public int NextIndex { get; } + public long Offset { get; internal set; } public string FullPath { get; private set; } public FileEntry ParentDir { get; internal set; } public FileEntry Next { get; internal set; } @@ -26,7 +27,7 @@ namespace libhac.Savefile reader.BaseStream.Position = start + 0x44; Field44 = reader.ReadInt32(); - Offset = reader.ReadInt32(); + BlockIndex = reader.ReadInt32(); Size = reader.ReadInt64(); Field54 = reader.ReadInt64(); NextIndex = reader.ReadInt32(); diff --git a/libhac/Savefile/Savefile.cs b/libhac/Savefile/Savefile.cs index 2e5fa9ca..c6261865 100644 --- a/libhac/Savefile/Savefile.cs +++ b/libhac/Savefile/Savefile.cs @@ -108,7 +108,7 @@ namespace libhac.Savefile public Stream OpenFile(FileEntry file) { - return new SubStream(JournalStream, file.Offset * Header.Save.BlockSize, file.Size); + return new SubStream(JournalStream, file.Offset, file.Size); } public bool FileExists(string filename) => FileDict.ContainsKey(filename); @@ -142,6 +142,7 @@ namespace libhac.Savefile if (file.NextIndex != 0) file.Next = fileEntries[file.NextIndex]; if (file.ParentDirIndex != 0 && file.ParentDirIndex < dirEntries.Length) file.ParentDir = dirEntries[file.ParentDirIndex]; + file.Offset = file.BlockIndex < 0 ? 0 : file.BlockIndex * blockSize; } Files = new FileEntry[fileEntries.Length - 2];