From 46cfb2f948a135a032d414d41024d4d2babdfe2e Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Tue, 24 Jul 2018 18:50:41 -0500 Subject: [PATCH] Read correct duplex data --- hactoolnet/Program.cs | 2 +- libhac/Savefile/Header.cs | 4 ++-- libhac/Savefile/Savefile.cs | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/hactoolnet/Program.cs b/hactoolnet/Program.cs index 1cfb41db..d83ee2be 100644 --- a/hactoolnet/Program.cs +++ b/hactoolnet/Program.cs @@ -245,7 +245,7 @@ namespace hactoolnet File.WriteAllBytes(Path.Combine(dir, "L1_4_Layer1Hash"), save.JournalLayer1Hash); File.WriteAllBytes(Path.Combine(dir, "L1_5_Layer2Hash"), save.JournalLayer2Hash); File.WriteAllBytes(Path.Combine(dir, "L1_6_Layer3Hash"), save.JournalLayer3Hash); - File.WriteAllBytes(Path.Combine(dir, "L1_7_FAT"), save.JournalStuff); + File.WriteAllBytes(Path.Combine(dir, "L1_7_FAT"), save.JournalFat); save.JournalStream.Position = 0; using (var outFile = new FileStream(Path.Combine(dir, "L2_0_SaveData"), FileMode.Create, FileAccess.Write)) diff --git a/libhac/Savefile/Header.cs b/libhac/Savefile/Header.cs index fc1a1ee8..98761ab6 100644 --- a/libhac/Savefile/Header.cs +++ b/libhac/Savefile/Header.cs @@ -111,7 +111,7 @@ namespace libhac.Savefile public long Layer3HashSize { get; set; } public long Field148 { get; set; } public long Field150 { get; set; } - public long Field158 { get; set; } + public long DuplexIndex { get; set; } public FsLayout(BinaryReader reader) { @@ -156,7 +156,7 @@ namespace libhac.Savefile Layer3HashSize = reader.ReadInt64(); Field148 = reader.ReadInt64(); Field150 = reader.ReadInt64(); - Field158 = reader.ReadInt64(); + DuplexIndex = reader.ReadInt64(); } } diff --git a/libhac/Savefile/Savefile.cs b/libhac/Savefile/Savefile.cs index c6261865..27e61249 100644 --- a/libhac/Savefile/Savefile.cs +++ b/libhac/Savefile/Savefile.cs @@ -26,7 +26,7 @@ namespace libhac.Savefile public byte[] JournalLayer1Hash { get; } public byte[] JournalLayer2Hash { get; } public byte[] JournalLayer3Hash { get; } - public byte[] JournalStuff { get; } + public byte[] JournalFat { get; } public FileEntry[] Files { get; private set; } private Dictionary FileDict { get; } @@ -56,7 +56,8 @@ namespace libhac.Savefile FileRemap.Position = layout.DuplexDataOffsetB; FileRemap.Read(DuplexDataB, 0, DuplexDataB.Length); - var duplexData = new SubStream(FileRemap, layout.DuplexDataOffsetB, layout.DuplexDataSize); + var duplexDataOffset = layout.DuplexIndex == 0 ? layout.DuplexDataOffsetA : layout.DuplexDataOffsetB; + var duplexData = new SubStream(FileRemap, duplexDataOffset, layout.DuplexDataSize); MetaRemap = new RemapStream(duplexData, Header.MetaMapEntries, Header.MetaRemap.MapSegmentCount); JournalTable = new byte[layout.JournalTableSize]; @@ -66,7 +67,7 @@ namespace libhac.Savefile JournalLayer1Hash = new byte[layout.Layer1HashSize]; JournalLayer2Hash = new byte[layout.Layer2HashSize]; JournalLayer3Hash = new byte[layout.Layer3HashSize]; - JournalStuff = new byte[layout.Field150]; + JournalFat = new byte[layout.Field150]; MetaRemap.Position = layout.JournalTableOffset; MetaRemap.Read(JournalTable, 0, JournalTable.Length); @@ -83,7 +84,7 @@ namespace libhac.Savefile MetaRemap.Position = layout.Layer3HashOffset; MetaRemap.Read(JournalLayer3Hash, 0, JournalLayer3Hash.Length); MetaRemap.Position = layout.Field148; - MetaRemap.Read(JournalStuff, 0, JournalStuff.Length); + MetaRemap.Read(JournalFat, 0, JournalFat.Length); var journalMap = JournalStream.ReadMappingEntries(JournalTable, JournalBitmapUpdatedPhysical, JournalBitmapUpdatedVirtual, JournalBitmapUnassigned, Header.Journal.MappingEntryCount);