mirror of
https://github.com/kwsch/PKHeX
synced 2024-12-18 08:23:12 +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.
64 lines
No EOL
2.5 KiB
C#
64 lines
No EOL
2.5 KiB
C#
using System;
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
|
|
|
namespace PKHeX.Core
|
|
{
|
|
public sealed class Situation7 : SaveBlock
|
|
{
|
|
public Situation7(SAV7SM sav, int offset) : base(sav) => Offset = offset;
|
|
public Situation7(SAV7USUM sav, int offset) : base(sav) => Offset = offset;
|
|
|
|
// "StartLocation"
|
|
public int M { get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x00)); set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x00), (ushort)value); }
|
|
public float X { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x08)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x08), value); }
|
|
public float Z { get => ReadSingleLittleEndian(Data.AsSpan(Offset + 0x10)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x10), value); }
|
|
public float Y { get => (int)ReadSingleLittleEndian(Data.AsSpan(Offset + 0x18)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x18), value); }
|
|
public float R { get => (int)ReadSingleLittleEndian(Data.AsSpan(Offset + 0x20)); set => WriteSingleLittleEndian(Data.AsSpan(Offset + 0x20), value); }
|
|
|
|
public void UpdateOverworldCoordinates()
|
|
{
|
|
var o = ((SAV7)SAV).Overworld;
|
|
o.M = M;
|
|
o.X = X;
|
|
o.Z = Z;
|
|
o.Y = Y;
|
|
o.R = R;
|
|
}
|
|
|
|
public int SpecialLocation
|
|
{
|
|
get => Data[Offset + 0x24];
|
|
set => Data[Offset + 0x24] = (byte)value;
|
|
}
|
|
|
|
public int WarpContinueRequest
|
|
{
|
|
get => Data[Offset + 0x6E];
|
|
set => Data[Offset + 0x6E] = (byte)value;
|
|
}
|
|
|
|
public int StepCountEgg
|
|
{
|
|
get => ReadInt32LittleEndian(Data.AsSpan(Offset + 0x70));
|
|
set => WriteInt32LittleEndian(Data.AsSpan(Offset + 0x70), value);
|
|
}
|
|
|
|
public int LastZoneID
|
|
{
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x74));
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x74), (ushort)value);
|
|
}
|
|
|
|
public int StepCountFriendship
|
|
{
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x76));
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x76), (ushort)value);
|
|
}
|
|
|
|
public int StepCountAffection // Kawaigari
|
|
{
|
|
get => ReadUInt16LittleEndian(Data.AsSpan(Offset + 0x78));
|
|
set => WriteUInt16LittleEndian(Data.AsSpan(Offset + 0x78), (ushort)value);
|
|
}
|
|
}
|
|
} |