Skip to content

Commit da2be77

Browse files
authored
Repair incomplete SS files (#950)
* Cleanup SS handling * Fix SS validity check * Clean SS for DIC dumps too * Fix build * Account for net20 * Account for old dotnet * Fix tests * decrypt response table * Update ProcessingTool.cs * Repair CCRT * fix * fix build * fix * cid value is int * code review * fix * fix * Fix FixSS * Copy don't move DIC SS * Abracadabra
1 parent 716470e commit da2be77

5 files changed

Lines changed: 381 additions & 177 deletions

File tree

MPF.Processors.Test/DiscImageCreatorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public void GetOutputFiles_DVD_Populated()
117117
var processor = new DiscImageCreator(RedumpSystem.IBMPCcompatible);
118118

119119
var actual = processor.GetOutputFiles(MediaType.DVD, outputDirectory, outputFilename);
120-
Assert.Equal(16, actual.Count);
120+
Assert.Equal(17, actual.Count);
121121
}
122122

123123
[Fact]
@@ -128,7 +128,7 @@ public void GetOutputFiles_NintendoGameCubeGameDisc_Populated()
128128
var processor = new DiscImageCreator(RedumpSystem.IBMPCcompatible);
129129

130130
var actual = processor.GetOutputFiles(MediaType.NintendoGameCubeGameDisc, outputDirectory, outputFilename);
131-
Assert.Equal(16, actual.Count);
131+
Assert.Equal(17, actual.Count);
132132
}
133133

134134
[Fact]
@@ -139,7 +139,7 @@ public void GetOutputFiles_NintendoWiiOpticalDisc_Populated()
139139
var processor = new DiscImageCreator(RedumpSystem.IBMPCcompatible);
140140

141141
var actual = processor.GetOutputFiles(MediaType.NintendoWiiOpticalDisc, outputDirectory, outputFilename);
142-
Assert.Equal(16, actual.Count);
142+
Assert.Equal(17, actual.Count);
143143
}
144144

145145
[Fact]

MPF.Processors/DiscImageCreator.cs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text.RegularExpressions;
88
using MPF.Processors.OutputFiles;
99
using SabreTools.Data.Models.Logiqx;
10+
using SabreTools.Hashing;
1011
using SabreTools.RedumpLib.Data;
1112
#if NET462_OR_GREATER || NETCOREAPP
1213
using SharpCompress.Archives;
@@ -345,7 +346,8 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, MediaType? medi
345346
{
346347
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty;
347348
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd1PFIHash ?? string.Empty;
348-
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty;
349+
// Don't put raw SS hash from _suppl.dat / _disc.txt in submission info
350+
//info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty;
349351
}
350352

351353
if (GetXGDAuxInfo($"{basePath}_disc.txt", out _, out _, out _, out var xgd1SS))
@@ -359,11 +361,33 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, MediaType? medi
359361
{
360362
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd1DMIHash ?? string.Empty;
361363
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd1PFIHash ?? string.Empty;
362-
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty;
364+
// Don't put raw SS hash from _suppl.dat / _disc.txt in submission info
365+
//info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSHash ?? string.Empty;
363366
info.Extras.SecuritySectorRanges = xgd1SS ?? string.Empty;
364367
}
365368
}
366369

370+
string xgd1SSPath = $"{basePath}_SS.bin";
371+
string xgd1RawSSPath = $"{basePath}_RawSS.bin";
372+
if (File.Exists(xgd1SSPath) && ProcessingTool.IsValidSS(xgd1SSPath))
373+
{
374+
// Save untouched SS
375+
try
376+
{
377+
if (!File.Exists(xgd1RawSSPath))
378+
File.Copy(xgd1SSPath, xgd1RawSSPath);
379+
}
380+
catch { }
381+
382+
// Repair, clean, and validate SS before adding hash to submission info
383+
if (ProcessingTool.FixSS(xgd1SSPath, xgd1SSPath))
384+
{
385+
string? xgd1SSCrc = HashTool.GetFileHash(xgd1SSPath, HashType.CRC32);
386+
if (xgd1SSCrc is not null)
387+
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd1SSCrc.ToUpperInvariant();
388+
}
389+
}
390+
367391
break;
368392

369393
case RedumpSystem.MicrosoftXbox360:
@@ -387,7 +411,8 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, MediaType? medi
387411
{
388412
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty;
389413
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd23PFIHash ?? string.Empty;
390-
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty;
414+
// Don't put raw SS hash from _suppl.dat / _disc.txt in submission info
415+
//info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty;
391416
}
392417

393418
if (GetXGDAuxInfo($"{basePath}_disc.txt", out _, out _, out _, out var xgd23SS))
@@ -401,11 +426,33 @@ public override void GenerateSubmissionInfo(SubmissionInfo info, MediaType? medi
401426
{
402427
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.DMIHash] = xgd23DMIHash ?? string.Empty;
403428
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.PFIHash] = xgd23PFIHash ?? string.Empty;
404-
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty;
429+
// Don't put raw SS hash from _suppl.dat / _disc.txt in submission info
430+
//info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd23SSHash ?? string.Empty;
405431
info.Extras.SecuritySectorRanges = xgd23SS ?? string.Empty;
406432
}
407433
}
408434

435+
string xgd2SSPath = $"{basePath}_SS.bin";
436+
string xgd2RawSSPath = $"{basePath}_RawSS.bin";
437+
if (File.Exists(xgd2SSPath) && ProcessingTool.IsValidSS(xgd2SSPath))
438+
{
439+
// Save untouched SS
440+
try
441+
{
442+
if (!File.Exists(xgd2RawSSPath))
443+
File.Copy(xgd2SSPath, xgd2RawSSPath);
444+
}
445+
catch { }
446+
447+
// Repair, clean, and validate SS before adding hash to submission info
448+
if (ProcessingTool.FixSS(xgd2SSPath, xgd2SSPath))
449+
{
450+
string? xgd2SSCrc = HashTool.GetFileHash(xgd2SSPath, HashType.CRC32);
451+
if (xgd2SSCrc is not null)
452+
info.CommonDiscInfo.CommentsSpecialFields[SiteCode.SSHash] = xgd2SSCrc.ToUpperInvariant();
453+
}
454+
}
455+
409456
break;
410457

411458
case RedumpSystem.NamcoSegaNintendoTriforce:
@@ -787,6 +834,9 @@ internal override List<OutputFile> GetOutputFiles(MediaType? mediaType, string?
787834
? OutputFileFlags.Required | OutputFileFlags.Binary | OutputFileFlags.Zippable
788835
: OutputFileFlags.Binary | OutputFileFlags.Zippable,
789836
"ss"),
837+
new($"{outputFilename}_RawSS.bin",
838+
OutputFileFlags.Binary | OutputFileFlags.Zippable,
839+
"raw_ss"),
790840
];
791841

792842
case MediaType.HDDVD:

0 commit comments

Comments
 (0)