mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
1d94baeb7f
oops, another hotfix
41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Logic for recognizing .dsv save files from DeSmuME.
|
|
/// </summary>
|
|
public sealed class SaveHandlerDeSmuME : ISaveHandler
|
|
{
|
|
private const int sizeFooter = 0x7A;
|
|
private const int RealSize = SaveUtil.SIZE_G4RAW;
|
|
private const int ExpectedSize = RealSize + sizeFooter;
|
|
|
|
private const string SignatureDSV = "|-DESMUME SAVE-|";
|
|
|
|
private static bool GetHasFooter(ReadOnlySpan<byte> input)
|
|
{
|
|
var start = input.Length - SignatureDSV.Length;
|
|
var footer = input[start..];
|
|
for (int i = SignatureDSV.Length - 1; i >= 0; i--)
|
|
{
|
|
byte c = (byte)SignatureDSV[i];
|
|
if (footer[i] != c)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool IsRecognized(int size) => size is ExpectedSize;
|
|
|
|
public SaveHandlerSplitResult? TrySplit(ReadOnlySpan<byte> input)
|
|
{
|
|
if (!GetHasFooter(input))
|
|
return null;
|
|
|
|
var footer = input[RealSize..].ToArray();
|
|
var data = input[..RealSize].ToArray();
|
|
|
|
return new SaveHandlerSplitResult(data, Array.Empty<byte>(), footer);
|
|
}
|
|
}
|