2021-03-28 01:58:51 +00:00
|
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2021-03-28 01:58:51 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public abstract class Gen3MysteryData
|
|
|
|
|
{
|
|
|
|
|
public readonly byte[] Data;
|
|
|
|
|
|
|
|
|
|
protected Gen3MysteryData(byte[] data) => Data = data;
|
|
|
|
|
|
|
|
|
|
public uint Checksum
|
|
|
|
|
{
|
2022-01-03 05:35:59 +00:00
|
|
|
|
get => ReadUInt32LittleEndian(Data.AsSpan(0));
|
|
|
|
|
set => WriteUInt32LittleEndian(Data.AsSpan(0), value);
|
2021-03-28 01:58:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsChecksumValid() => Checksum == GetChecksum(Data);
|
|
|
|
|
public void FixChecksum() => Checksum = GetChecksum(Data);
|
|
|
|
|
|
2022-01-03 05:35:59 +00:00
|
|
|
|
private static uint GetChecksum(ReadOnlySpan<byte> data)
|
2021-03-28 01:58:51 +00:00
|
|
|
|
{
|
|
|
|
|
uint sum = 0;
|
|
|
|
|
for (var i = 4; i < data.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
var b = data[i];
|
|
|
|
|
sum += b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sum;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|