From 8ab6a9d694c9d2a023d697f688d005c1171edf09 Mon Sep 17 00:00:00 2001 From: Deterous <138427222+Deterous@users.noreply.github.com> Date: Wed, 7 Feb 2024 09:32:56 +0900 Subject: [PATCH] Fix file hash for split files with irregular filesize --- IRDKit/IRDKit.csproj | 2 +- IRDKit/Program.cs | 4 +++- LibIRD/IRD.cs | 11 +++++------ LibIRD/LibIRD.csproj | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/IRDKit/IRDKit.csproj b/IRDKit/IRDKit.csproj index a11a292..e88e509 100644 --- a/IRDKit/IRDKit.csproj +++ b/IRDKit/IRDKit.csproj @@ -9,7 +9,7 @@ win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 latest true - 0.4.0 + 0.4.1 Deterous diff --git a/IRDKit/Program.cs b/IRDKit/Program.cs index 9ce8e9e..ce26c1d 100644 --- a/IRDKit/Program.cs +++ b/IRDKit/Program.cs @@ -610,7 +610,9 @@ namespace IRDKit missingOffsets1.Add(IRD2.FileKeys[i]); } // Print the file offsets that differ - printText.AppendLine($"File Offsets not Present in {irdPath1}: {string.Join(", ", missingOffsets1)}"); + if (missingOffsets1.Count > 0) + printText.AppendLine($"File Offsets not Present in {irdPath1}: {string.Join(", ", missingOffsets1)}"); + if (missingOffsets2.Count > 0) printText.AppendLine($"File Offsets not Present in {irdPath2}: {string.Join(", ", missingOffsets2)}"); // Print any extra config data difference diff --git a/LibIRD/IRD.cs b/LibIRD/IRD.cs index 4071aa7..58f9094 100644 --- a/LibIRD/IRD.cs +++ b/LibIRD/IRD.cs @@ -946,23 +946,22 @@ namespace LibIRD if (fileClusters[i].Offset < smallestOffset) smallestOffset = fileClusters[i].Offset; } - int firstSector = (int)(smallestOffset); // If already encountered file offset, skip this file - if (Array.Exists(FileKeys, element => element == firstSector)) + if (Array.Exists(FileKeys, element => element == smallestOffset)) continue; if (fileClusters.Length > 1) Console.WriteLine($"Split file detected: {filePath}"); // Add file offset to keys - FileKeys[FileCount] = firstSector; + FileKeys[FileCount] = smallestOffset; // Determine whether file is in encrypted or decrypted region bool encrypted = false; for (int i = RegionCount - 1; i > 0; i--) { - if (RegionStart[i] <= firstSector) + if (RegionStart[i] <= smallestOffset) { encrypted = i % 2 == 1; break; @@ -986,7 +985,7 @@ namespace LibIRD throw new InvalidFileSystemException("Disc region ended unexpectedly"); // Decrypt sector if necessary if (encrypted) - buf = DecryptSector(buf, firstSector + j); + buf = DecryptSector(buf, (int)fileClusters[i].Offset + j); // Hash sector md5.TransformBlock(buf, 0, numBytes, null, 0); } @@ -999,7 +998,7 @@ namespace LibIRD throw new InvalidFileSystemException("Disc region ended unexpectedly"); // Decrypt partial sector if necessary if (encrypted) - buf = DecryptSector(buf, firstSector + (int)(fileClusters[i].Count / SectorSize)); + buf = DecryptSector(buf, (int)fileClusters[i].Offset + (int)(fileClusters[i].Count / SectorSize)); // Hash partial sector md5.TransformBlock(buf, 0, (int)(fileClusters[i].Count % SectorSize), null, 0); } diff --git a/LibIRD/LibIRD.csproj b/LibIRD/LibIRD.csproj index f690d96..8221be2 100644 --- a/LibIRD/LibIRD.csproj +++ b/LibIRD/LibIRD.csproj @@ -6,7 +6,7 @@ win-x86;win-x64;win-arm64;linux-x64;linux-arm64;osx-x64;osx-arm64 latest true - 0.4.0 + 0.4.1 ../nupkg