mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-02 16:59:15 +00:00
d47bb1d297
With the new version of Visual Studio bringing C# 12, we can revise our logic for better readability as well as use new methods/APIs introduced in the .NET 8.0 BCL.
28 lines
810 B
C#
28 lines
810 B
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 static bool GetHasFooter(ReadOnlySpan<byte> input) => input.EndsWith("|-DESMUME SAVE-|"u8);
|
|
|
|
public bool IsRecognized(long 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, [], footer);
|
|
}
|
|
}
|