2018-02-19 19:33:37 +00:00
|
|
|
namespace PKHeX.Core
|
|
|
|
{
|
2018-07-29 20:27:48 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gen3 <see cref="GameVersion.RSBOX"/> Block Info
|
|
|
|
/// </summary>
|
2018-02-19 19:33:37 +00:00
|
|
|
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)
|
|
|
|
{
|
2018-06-11 16:12:41 +00:00
|
|
|
var chk = GetChecksum(data);
|
2018-03-30 22:56:59 +00:00
|
|
|
data[Offset + 0] = (byte)(chk >> 24);
|
|
|
|
data[Offset + 1] = (byte)(chk >> 16);
|
|
|
|
data[Offset + 2] = (byte)(chk >> 8);
|
|
|
|
data[Offset + 3] = (byte)(chk >> 0);
|
2018-02-19 19:33:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private uint GetChecksum(byte[] data)
|
|
|
|
{
|
|
|
|
int start = Offset + 4;
|
2018-06-11 16:12:41 +00:00
|
|
|
int end = start + Length - 4;
|
2018-02-19 19:33:37 +00:00
|
|
|
|
2021-03-08 19:39:15 +00:00
|
|
|
return Checksums.CheckSum16BigInvert(data, start, end);
|
2018-02-19 19:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-08 19:39:15 +00:00
|
|
|
}
|