Crystal (International) Checksum 2 Fix (#3939)

* Correct invalid OverallChecksumPosition2 offset for International Crystal

* Update SAV2 Checksum validation to check against both Checksum values
This commit is contained in:
Zazsona 2023-07-09 04:21:43 +01:00 committed by GitHub
parent 2ea6ee4e10
commit b340e2327a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View file

@ -308,18 +308,23 @@ public sealed class SAV2 : SaveFile, ILangDeviantSave, IEventFlagArray, IEventWo
WriteUInt16LittleEndian(Data.AsSpan(Offsets.OverallChecksumPosition2), accum);
}
public override bool ChecksumsValid
public override bool ChecksumsValid => !ChecksumInfo.Contains("Invalid");
public override string ChecksumInfo
{
get
{
ushort accum = GetChecksum();
ushort actual = ReadUInt16LittleEndian(Data.AsSpan(Offsets.OverallChecksumPosition));
return accum == actual;
ushort actual2 = ReadUInt16LittleEndian(Data.AsSpan(Offsets.OverallChecksumPosition2));
bool checksum1Valid = (accum == actual);
bool checksum2Valid = (accum == actual2);
static string valid(bool s) => s ? "Valid" : "Invalid";
return $"Checksum 1 {valid(checksum1Valid)}, Checksum 2 {valid(checksum2Valid)}.";
}
}
public override string ChecksumInfo => ChecksumsValid ? "Checksum valid." : "Checksum invalid";
// Trainer Info
public override GameVersion Version { get; protected set; }

View file

@ -1,4 +1,4 @@
using System;
using System;
namespace PKHeX.Core;
@ -100,7 +100,7 @@ internal sealed class SAV2Offsets
Gender = 0x3E3D;
AccumulatedChecksumEnd = 0x2B82;
OverallChecksumPosition = 0x2D0D;
OverallChecksumPosition2 = 0x7F0D;
OverallChecksumPosition2 = 0x1F0D;
PouchTMHM = 0x23E7;
PouchItem = 0x2420;