mirror of
https://github.com/kwsch/PKHeX
synced 2025-01-10 11:38:48 +00:00
3e8527f11a
Reduce allocation in a few places, delete unused stuff, more concise expressions.
44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
using System;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Gen3 <see cref="GameVersion.RSBOX"/> Block Info
|
|
/// </summary>
|
|
public sealed class BlockInfoRSBOX : BlockInfo
|
|
{
|
|
public readonly uint SaveCount;
|
|
private const int ChecksumRegionSize = 0x1FF8;
|
|
|
|
public BlockInfoRSBOX(ReadOnlySpan<byte> data, int offset)
|
|
{
|
|
Offset = offset;
|
|
Length = 4 + ChecksumRegionSize;
|
|
|
|
// Values stored in Big Endian format
|
|
ID = ReadUInt32BigEndian(data[(Offset + 4)..]);
|
|
SaveCount = ReadUInt32BigEndian(data[(Offset + 8)..]);
|
|
}
|
|
|
|
protected override bool ChecksumValid(Span<byte> data)
|
|
{
|
|
var chk = GetChecksum(data);
|
|
var old = ReadUInt32BigEndian(data[Offset..]);
|
|
return chk == old;
|
|
}
|
|
|
|
protected override void SetChecksum(Span<byte> data)
|
|
{
|
|
var chk = GetChecksum(data);
|
|
var span = data[Offset..];
|
|
WriteUInt32BigEndian(span, chk);
|
|
}
|
|
|
|
private uint GetChecksum(Span<byte> data)
|
|
{
|
|
var span = data.Slice(Offset + 4, ChecksumRegionSize);
|
|
return Checksums.CheckSum16BigInvert(span);
|
|
}
|
|
}
|
|
}
|