mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-24 11:23:11 +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`
40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using System;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Gen5 Block Info
|
|
/// </summary>
|
|
public sealed class BlockInfoNDS : BlockInfo
|
|
{
|
|
private readonly int ChecksumOffset;
|
|
private readonly int ChecksumMirror;
|
|
|
|
public BlockInfoNDS(int offset, int length, int chkOffset, int chkMirror)
|
|
{
|
|
Offset = offset;
|
|
Length = length;
|
|
ChecksumOffset = chkOffset;
|
|
ChecksumMirror = chkMirror;
|
|
}
|
|
|
|
private ushort GetChecksum(ReadOnlySpan<byte> data) => Checksums.CRC16_CCITT(data.Slice(Offset, Length));
|
|
|
|
protected override bool ChecksumValid(ReadOnlySpan<byte> data)
|
|
{
|
|
ushort chk = GetChecksum(data);
|
|
if (chk != ReadUInt16LittleEndian(data[ChecksumOffset..]))
|
|
return false;
|
|
if (chk != ReadUInt16LittleEndian(data[ChecksumMirror..]))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
protected override void SetChecksum(Span<byte> data)
|
|
{
|
|
ushort chk = GetChecksum(data);
|
|
WriteUInt16LittleEndian(data[ChecksumOffset..], chk);
|
|
WriteUInt16LittleEndian(data[ChecksumMirror..], chk);
|
|
}
|
|
}
|