2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
2023-03-31 20:00:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Generation 6 savedata object that stores the player's trainer data.
|
|
|
|
/// </summary>
|
2024-03-04 05:13:16 +00:00
|
|
|
public class MyStatus6(SAV6 sav, Memory<byte> raw) : SaveBlock<SAV6>(sav, raw), IRegionOrigin
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2023-01-22 04:02:33 +00:00
|
|
|
public uint ID32
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => ReadUInt32LittleEndian(Data);
|
|
|
|
set => WriteUInt32LittleEndian(Data, value);
|
2023-01-22 04:02:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public ushort TID16
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => ReadUInt16LittleEndian(Data);
|
|
|
|
set => WriteUInt16LittleEndian(Data, value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public ushort SID16
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => ReadUInt16LittleEndian(Data[2..]);
|
|
|
|
set => WriteUInt16LittleEndian(Data[2..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public byte Game
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[4];
|
|
|
|
set => Data[4] = value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public byte Gender
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[5];
|
|
|
|
set => Data[5] = value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int MultiplayerSpriteID_1
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[6];
|
|
|
|
set => Data[6] = (byte)value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-06 04:39:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int MultiplayerSpriteID_2
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[7];
|
|
|
|
set => Data[7] = (byte)value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public const int GameSyncIDSize = 16; // 64 bits
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public string GameSyncID
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Util.GetHexStringFromBytes(Data.Slice(0x08, GameSyncIDSize / 2));
|
2022-06-18 18:04:24 +00:00
|
|
|
set
|
2019-06-09 02:56:11 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
if (value.Length != GameSyncIDSize)
|
2023-03-31 20:00:34 +00:00
|
|
|
throw new ArgumentOutOfRangeException(nameof(value));
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var data = Util.GetBytesFromHexString(value);
|
2024-03-04 05:13:16 +00:00
|
|
|
SAV.SetData(Data[0x8..], data);
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public byte Region
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[0x26];
|
|
|
|
set => Data[0x26] = value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public byte Country
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[0x27];
|
|
|
|
set => Data[0x27] = value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-06 04:39:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public decimal Latitude // don't use the setters
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => (ReadInt16LittleEndian(Data[0x28..]) * 180m) / 0x8000;
|
|
|
|
set => WriteInt16LittleEndian(Data[0x28..], (short)((value * 0x8000) / 180m));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-07-06 04:39:47 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public decimal Longitude // don't use the setters
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => (ReadInt16LittleEndian(Data[0x2A..]) * 180m) / 0x8000;
|
|
|
|
set => WriteInt16LittleEndian(Data[0x2A..], (short)((value * 0x8000) / 180m));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public byte ConsoleRegion
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[0x2C];
|
|
|
|
set => Data[0x2C] = value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Language
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => Data[0x2D];
|
|
|
|
set => Data[0x2D] = (byte)value;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
private Span<byte> OriginalTrainerTrash => Data.Slice(0x48, 0x1A);
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public string OT
|
|
|
|
{
|
2024-02-23 03:20:54 +00:00
|
|
|
get => SAV.GetString(OriginalTrainerTrash);
|
|
|
|
set => SAV.SetString(OriginalTrainerTrash, value, SAV.MaxStringLengthOT, StringConverterOption.ClearZero);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
private Span<byte> GetSayingSpan(int say) => Data.Slice(GetSayingOffset(say), SAV6.LongStringLength);
|
|
|
|
private static int GetSayingOffset(int say) => 0x7C + (SAV6.LongStringLength * say);
|
2022-06-18 18:04:24 +00:00
|
|
|
private string GetSaying(int say) => SAV.GetString(GetSayingSpan(say));
|
2023-01-22 04:02:33 +00:00
|
|
|
private void SetSaying(int say, ReadOnlySpan<char> value) => SAV.SetString(GetSayingSpan(say), value, SAV6.LongStringLength / 2, StringConverterOption.ClearZero);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public string Saying1 { get => GetSaying(0); set => SetSaying(0, value); }
|
|
|
|
public string Saying2 { get => GetSaying(1); set => SetSaying(1, value); }
|
|
|
|
public string Saying3 { get => GetSaying(2); set => SetSaying(2, value); }
|
|
|
|
public string Saying4 { get => GetSaying(3); set => SetSaying(3, value); }
|
|
|
|
public string Saying5 { get => GetSaying(4); set => SetSaying(4, value); }
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool IsMegaEvolutionUnlocked
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => (Data[0x14A] & 0x01) != 0;
|
|
|
|
set => Data[0x14A] = (byte)((Data[0x14A] & 0xFE) | (value ? 1 : 0)); // in battle
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool IsMegaRayquazaUnlocked
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => (Data[0x14A] & 0x02) != 0;
|
|
|
|
set => Data[0x14A] = (byte)((Data[0x14A] & ~2) | (value ? 2 : 0)); // in battle
|
2019-06-09 02:56:11 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|