mirror of
https://github.com/kwsch/PKHeX.git
synced 2026-05-21 05:09:35 -05:00
Existing `get`/`set` logic is flawed in that it doesn't work on Big Endian operating systems, and it allocates heap objects when it doesn't need to. `System.Buffers.Binary.BinaryPrimitives` in the `System.Memory` NuGet package provides both Little Endian and Big Endian methods to read and write data; all the `get`/`set` operations have been reworked to use this new API. This removes the need for PKHeX's manual `BigEndian` class, as all functions are already covered by the BinaryPrimitives API. The `StringConverter` has now been rewritten to accept a Span to read from & write to, no longer requiring a temporary StringBuilder. Other Fixes included: - The Super Training UI for Gen6 has been reworked according to the latest block structure additions. - Cloning a Stadium2 Save File now works correctly (opening from the Folder browser list). - Checksum & Sanity properties removed from parent PKM class, and is now implemented via interface.
52 lines
1.7 KiB
C#
52 lines
1.7 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
/// <summary>
|
|
/// Tracks the main menu items. Size: 0x44
|
|
/// </summary>
|
|
[TypeConverter(typeof(ExpandableObjectConverter))]
|
|
public sealed class MenuSelect8b : SaveBlock
|
|
{
|
|
// (TopMenuItemTypeInt32, bool IsNew)[8], TopMenuItemTypeInt32 LastSelected
|
|
private const int COUNT_ITEMS = 8;
|
|
private const int SIZE_TUPLE = 4 + 4; // int,bool32
|
|
public MenuSelect8b(SAV8BS sav, int offset) : base(sav) => Offset = offset;
|
|
|
|
public int GetMenuItem(int index)
|
|
{
|
|
int ofs = GetOffset(index);
|
|
return ReadInt32LittleEndian(Data.AsSpan(Offset + ofs));
|
|
}
|
|
|
|
public void SetMenuItem(int index, int value)
|
|
{
|
|
int ofs = GetOffset(index);
|
|
WriteInt32LittleEndian(Data.AsSpan(Offset + ofs), value);
|
|
}
|
|
|
|
public bool GetMenuItemIsNew(int index)
|
|
{
|
|
int ofs = GetOffset(index);
|
|
return ReadInt32LittleEndian(Data.AsSpan(Offset + ofs + 4)) == 1;
|
|
}
|
|
|
|
public void SetMenuItemIsNew(int index, bool value)
|
|
{
|
|
int ofs = GetOffset(index);
|
|
WriteInt32LittleEndian(Data.AsSpan(Offset + ofs + 4), value ? 1 : 0);
|
|
}
|
|
|
|
private static int GetOffset(int index)
|
|
{
|
|
if ((uint)index >= COUNT_ITEMS)
|
|
throw new ArgumentOutOfRangeException(nameof(index));
|
|
return index * SIZE_TUPLE;
|
|
}
|
|
|
|
public int LastSelectedMenu { get => ReadInt32LittleEndian(Data.AsSpan(Offset + 0x40)); set => WriteInt32LittleEndian(Data.AsSpan(Offset + 0x40), value); }
|
|
}
|
|
}
|