mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-23 12:33:06 +00:00
fc754b346b
[Language Reference](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/file-scoped-namespaces) Updates all the files, one less level of indentation. Some small changes were made to API surfaces, renaming `PKM pkm` -> `PKM pk`, and `LegalityAnalysis.pkm` -> `LegalityAnalysis.Entity`
43 lines
1.2 KiB
C#
43 lines
1.2 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(ReadOnlySpan<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(ReadOnlySpan<byte> data)
|
|
{
|
|
var span = data.Slice(Offset + 4, ChecksumRegionSize);
|
|
return Checksums.CheckSum16BigInvert(span);
|
|
}
|
|
}
|