mirror of
https://github.com/kwsch/PKHeX
synced 2024-11-27 06:20:25 +00:00
88830e0d00
Updates from net46->net7, dropping support for mono in favor of using the latest runtime (along with the performance/API improvements). Releases will be posted as 64bit only for now. Refactors a good amount of internal API methods to be more performant and more customizable for future updates & fixes. Adds functionality for Batch Editor commands to `>`, `<` and <=/>= TID/SID properties renamed to TID16/SID16 for clarity; other properties exposed for Gen7 / display variants. Main window has a new layout to account for DPI scaling (8 point grid) Fixed: Tatsugiri and Paldean Tauros now output Showdown form names as Showdown expects Changed: Gen9 species now interact based on the confirmed National Dex IDs (closes #3724) Fixed: Pokedex set all no longer clears species with unavailable non-base forms (closes #3720) Changed: Hyper Training suggestions now apply for level 50 in SV. (closes #3714) Fixed: B2/W2 hatched egg met locations exclusive to specific versions are now explicitly checked (closes #3691) Added: Properties for ribbon/mark count (closes #3659) Fixed: Traded SV eggs are now checked correctly (closes #3692)
77 lines
2.7 KiB
C#
77 lines
2.7 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core;
|
|
|
|
/// <summary>
|
|
/// Logic for recognizing .gci save files.
|
|
/// </summary>
|
|
public sealed class SaveHandlerGCI : ISaveHandler
|
|
{
|
|
private const int headerSize = 0x40;
|
|
private const int SIZE_G3BOXGCI = headerSize + SaveUtil.SIZE_G3BOX; // GCI data
|
|
private const int SIZE_G3COLOGCI = headerSize + SaveUtil.SIZE_G3COLO; // GCI data
|
|
private const int SIZE_G3XDGCI = headerSize + SaveUtil.SIZE_G3XD; // GCI data
|
|
|
|
private static readonly string[] HEADER_COLO = { "GC6J", "GC6E", "GC6P" }; // NTSC-J, NTSC-U, PAL
|
|
private static readonly string[] HEADER_XD = { "GXXJ", "GXXE", "GXXP" }; // NTSC-J, NTSC-U, PAL
|
|
private static readonly string[] HEADER_RSBOX = { "GPXJ", "GPXE", "GPXP" }; // NTSC-J, NTSC-U, PAL
|
|
|
|
private static bool IsGameMatchHeader(ReadOnlySpan<string> headers, ReadOnlySpan<byte> data)
|
|
{
|
|
foreach (var header in headers)
|
|
{
|
|
if (IsGameMatchHeader(data, header))
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private static bool IsGameMatchHeader(ReadOnlySpan<byte> data, ReadOnlySpan<char> header)
|
|
{
|
|
for (int i = 0; i < header.Length; i++)
|
|
{
|
|
var c = (byte)header[i];
|
|
if (data[i] != c)
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool IsRecognized(int size) => size is SIZE_G3BOXGCI or SIZE_G3COLOGCI or SIZE_G3XDGCI;
|
|
|
|
public SaveHandlerSplitResult? TrySplit(ReadOnlySpan<byte> input)
|
|
{
|
|
switch (input.Length)
|
|
{
|
|
case SIZE_G3COLOGCI when IsGameMatchHeader(HEADER_COLO , input):
|
|
case SIZE_G3XDGCI when IsGameMatchHeader(HEADER_XD , input):
|
|
case SIZE_G3BOXGCI when IsGameMatchHeader(HEADER_RSBOX, input):
|
|
break;
|
|
default:
|
|
return null;
|
|
}
|
|
|
|
var header = input[..headerSize].ToArray();
|
|
var data = input[headerSize..].ToArray();
|
|
|
|
return new SaveHandlerSplitResult(data, header, Array.Empty<byte>());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if the game code is one of the recognizable versions.
|
|
/// </summary>
|
|
/// <param name="gameCode">4 character game code string</param>
|
|
/// <returns>Magic version ID enumeration; <see cref="GameVersion.Unknown"/> if no match.</returns>
|
|
public static GameVersion GetGameCode(ReadOnlySpan<byte> gameCode)
|
|
{
|
|
if (IsGameMatchHeader(HEADER_COLO, gameCode))
|
|
return GameVersion.COLO;
|
|
if (IsGameMatchHeader(HEADER_XD, gameCode))
|
|
return GameVersion.XD;
|
|
if (IsGameMatchHeader(HEADER_RSBOX, gameCode))
|
|
return GameVersion.RSBOX;
|
|
|
|
return GameVersion.Unknown;
|
|
}
|
|
}
|