2022-06-18 18:04:24 +00:00
|
|
|
using System;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2018-07-08 07:26:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public sealed class SecretBase3(Memory<byte> raw)
|
2018-07-08 07:26:31 +00:00
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
private Span<byte> Data => raw.Span;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private bool Japanese => Language == (int) LanguageID.Japanese;
|
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public int SecretBaseLocation { get => Data[0]; set => Data[0] = (byte) value; }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public byte OriginalTrainerGender
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => (byte)((Data[1] >> 4) & 1);
|
|
|
|
set => Data[1] = (byte) ((Data[1] & 0xEF) | ((value & 1) << 4));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool BattledToday
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => ((Data[1] >> 5) & 1) == 1;
|
|
|
|
set => Data[1] = (byte)((Data[1] & 0xDF) | ((value ? 1 : 0) << 5));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int RegistryStatus
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => (Data[1] >> 6) & 3;
|
|
|
|
set => Data[1] = (byte)((Data[1] & 0x3F) | ((value & 3) << 6));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public string OriginalTrainerName
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2024-03-18 04:34:13 +00:00
|
|
|
get => StringConverter3.GetString(Data.Slice(2, 7), Language);
|
|
|
|
set => StringConverter3.SetString(Data.Slice(2, 7), value, 7, Language, StringConverterOption.ClearFF);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public uint OT_ID
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => ReadUInt32LittleEndian(Data[9..]);
|
|
|
|
set => WriteUInt32LittleEndian(Data[9..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public int OT_Class => Data[9] % 5;
|
|
|
|
public int Language { get => Data[0x0D]; set => Data[0x0D] = (byte)value; }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public ushort SecretBasesReceived
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
get => ReadUInt16LittleEndian(Data[0x0E..]);
|
|
|
|
set => WriteUInt16LittleEndian(Data[0x0E..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public byte TimesEntered { get => Data[0x10]; set => Data[0x10] = value; }
|
|
|
|
public int Unused11 { get => Data[0x11]; set => Data[0x11] = (byte)value; } // alignment padding
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public Span<byte> GetDecorations() => Data.Slice(0x12, 0x10);
|
2023-12-04 04:13:20 +00:00
|
|
|
public void SetDecorations(Span<byte> value) => value.CopyTo(GetDecorations());
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public Span<byte> GetDecorationCoordinates() => Data.Slice(0x22, 0x10);
|
2023-12-04 04:13:20 +00:00
|
|
|
public void SetDecorationCoordinates(Span<byte> value) => value.CopyTo(GetDecorationCoordinates());
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
private Span<byte> TeamData => Data.Slice(50, 72);
|
2022-06-18 18:04:24 +00:00
|
|
|
public SecretBase3Team Team
|
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => new(TeamData.ToArray());
|
|
|
|
set => value.Write().CopyTo(TeamData);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public int TID16
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
get => (ushort)OT_ID;
|
2023-01-22 04:02:33 +00:00
|
|
|
set => OT_ID = (ushort)(SID16 | (ushort)value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public int SID16
|
2018-07-08 07:26:31 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
get => (ushort)OT_ID >> 8;
|
2023-01-22 04:02:33 +00:00
|
|
|
set => OT_ID = (ushort)(((ushort)value << 16) | TID16);
|
2018-07-08 07:26:31 +00:00
|
|
|
}
|
|
|
|
}
|