2021-05-14 19:30:40 +00:00
|
|
|
using System;
|
|
|
|
|
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;
|
2021-05-14 19:30:40 +00:00
|
|
|
public readonly uint OriginalChecksum;
|
|
|
|
private const int ChecksumRegionSize = 0x1FF8;
|
2018-02-19 19:33:37 +00:00
|
|
|
|
|
|
|
public BlockInfoRSBOX(byte[] data, int offset)
|
|
|
|
{
|
|
|
|
Offset = offset;
|
2021-05-14 19:30:40 +00:00
|
|
|
Length = 4 + ChecksumRegionSize;
|
2018-02-19 19:33:37 +00:00
|
|
|
|
|
|
|
// Values stored in Big Endian format
|
2021-05-14 19:30:40 +00:00
|
|
|
OriginalChecksum = BigEndian.ToUInt32(data, Offset);
|
2018-02-19 19:33:37 +00:00
|
|
|
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;
|
2021-05-14 19:30:40 +00:00
|
|
|
var span = new ReadOnlySpan<byte>(data, start, ChecksumRegionSize);
|
|
|
|
return Checksums.CheckSum16BigInvert(span);
|
2018-02-19 19:33:37 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-08 19:39:15 +00:00
|
|
|
}
|