mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-24 19:33:10 +00:00
47071b41f3
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.
30 lines
No EOL
1.1 KiB
C#
30 lines
No EOL
1.1 KiB
C#
using System;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
public sealed class BoxLayout8 : SaveBlock, IBoxDetailName
|
|
{
|
|
public const int BoxCount = 32;
|
|
|
|
private const int StringMaxLength = SAV6.LongStringLength / 2;
|
|
|
|
public BoxLayout8(SAV8SWSH sav, SCBlock block) : base(sav, block.Data) { }
|
|
|
|
private static int GetBoxNameOffset(int box) => SAV6.LongStringLength * box;
|
|
private Span<byte> GetBoxNameSpan(int box) => Data.AsSpan(GetBoxNameOffset(box), SAV6.LongStringLength);
|
|
public string GetBoxName(int box) => SAV.GetString(GetBoxNameSpan(box));
|
|
public void SetBoxName(int box, string value) => SAV.SetString(GetBoxNameSpan(box), value.AsSpan(), StringMaxLength, StringConverterOption.ClearZero);
|
|
|
|
public string this[int i]
|
|
{
|
|
get => GetBoxName(i);
|
|
set => SetBoxName(i, value);
|
|
}
|
|
|
|
public int CurrentBox
|
|
{
|
|
get => ((SAV8SWSH)SAV).GetValue<byte>(SaveBlockAccessor8SWSH.KCurrentBox);
|
|
set => ((SAV8SWSH)SAV).SetValue(SaveBlockAccessor8SWSH.KCurrentBox, (byte)value);
|
|
}
|
|
}
|
|
} |