mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-24 11:23:11 +00:00
e32bfcde2e
Extract RSBOX checksum logic to checksum class Allocate half as much for gen3 save detect Simplify some expressions for GC save loading (x - size + offset, when x==size)
46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Gen3 <see cref="GameVersion.RSBOX"/> Block Info
|
|
/// </summary>
|
|
public sealed class BlockInfoRSBOX : BlockInfo
|
|
{
|
|
public readonly uint SaveCount;
|
|
public readonly uint Checksum;
|
|
|
|
public BlockInfoRSBOX(byte[] data, int offset)
|
|
{
|
|
Offset = offset;
|
|
Length = 0x1FFC;
|
|
|
|
// Values stored in Big Endian format
|
|
Checksum = BigEndian.ToUInt32(data, Offset + 0);
|
|
ID = BigEndian.ToUInt32(data, Offset + 4);
|
|
SaveCount = BigEndian.ToUInt32(data, Offset + 8);
|
|
}
|
|
|
|
protected override bool ChecksumValid(byte[] data)
|
|
{
|
|
var chk = GetChecksum(data);
|
|
var old = BigEndian.ToUInt32(data, Offset);
|
|
return chk == old;
|
|
}
|
|
|
|
protected override void SetChecksum(byte[] data)
|
|
{
|
|
var chk = GetChecksum(data);
|
|
data[Offset + 0] = (byte)(chk >> 24);
|
|
data[Offset + 1] = (byte)(chk >> 16);
|
|
data[Offset + 2] = (byte)(chk >> 8);
|
|
data[Offset + 3] = (byte)(chk >> 0);
|
|
}
|
|
|
|
private uint GetChecksum(byte[] data)
|
|
{
|
|
int start = Offset + 4;
|
|
int end = start + Length - 4;
|
|
|
|
return Checksums.CheckSum16BigInvert(data, start, end);
|
|
}
|
|
}
|
|
}
|