2023-01-22 04:02:33 +00:00
|
|
|
using System;
|
2019-01-03 02:15:29 +00:00
|
|
|
using System.Diagnostics;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
public sealed class HallFame3Entry
|
2019-01-03 02:15:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
private readonly byte[] Parent;
|
|
|
|
private readonly bool Japanese;
|
|
|
|
private readonly int Offset;
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int Count = 6;
|
|
|
|
public const int SIZE = Count * HallFame3PKM.SIZE;
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public HallFame3Entry(byte[] data, int offset, bool japanese)
|
|
|
|
{
|
|
|
|
Parent = data;
|
|
|
|
Japanese = japanese;
|
|
|
|
Offset = offset;
|
|
|
|
}
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private int GetMemberOffset(int index) => Offset + (index * HallFame3PKM.SIZE);
|
|
|
|
private HallFame3PKM GetMember(int index) => new(Parent, GetMemberOffset(index), Japanese);
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public HallFame3PKM[] Team
|
|
|
|
{
|
|
|
|
get
|
2019-01-03 02:15:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var team = new HallFame3PKM[6];
|
|
|
|
for (int i = 0; i < Count; i++)
|
|
|
|
team[i] = GetMember(i);
|
|
|
|
return team;
|
2019-01-03 02:15:29 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int MaxEntries = 50;
|
|
|
|
private const int MaxLength = MaxEntries * SIZE;
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static HallFame3Entry[] GetEntries(SAV3 sav)
|
|
|
|
{
|
|
|
|
byte[] data = sav.GetHallOfFameData();
|
|
|
|
Debug.Assert(data.Length > MaxLength);
|
|
|
|
bool Japanese = sav.Japanese;
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
var entries = new HallFame3Entry[MaxEntries];
|
|
|
|
for (int i = 0; i < entries.Length; i++)
|
|
|
|
entries[i] = new HallFame3Entry(data, SIZE, Japanese);
|
|
|
|
return entries;
|
2019-01-03 02:15:29 +00:00
|
|
|
}
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public static void SetEntries(SAV3 sav, HallFame3Entry[] entries)
|
2019-01-03 02:15:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
byte[] data = entries[0].Team[0].Data;
|
|
|
|
sav.SetHallOfFameData(data);
|
|
|
|
}
|
|
|
|
}
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public sealed class HallFame3PKM : ISpeciesForm
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
public const int SIZE = 20;
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public HallFame3PKM(byte[] data, int offset, bool jp)
|
|
|
|
{
|
|
|
|
Data = data;
|
|
|
|
Offset = offset;
|
|
|
|
Japanese = jp;
|
|
|
|
}
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public readonly byte[] Data;
|
|
|
|
private readonly int Offset;
|
|
|
|
private readonly bool Japanese;
|
2022-01-03 05:35:59 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public int TID16 { get => ReadUInt16LittleEndian(Data.AsSpan(0 + Offset)); set => WriteUInt16LittleEndian(Data.AsSpan(0 + Offset), (ushort)value); }
|
|
|
|
public int SID16 { get => ReadUInt16LittleEndian(Data.AsSpan(2 + Offset)); set => WriteUInt16LittleEndian(Data.AsSpan(2 + Offset), (ushort)value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
public uint PID { get => ReadUInt32LittleEndian(Data.AsSpan(4 + Offset)); set => WriteUInt32LittleEndian(Data.AsSpan(4 + Offset), value); }
|
|
|
|
private int SpecLevel { get => ReadUInt16LittleEndian(Data.AsSpan(8 + Offset)); set => WriteUInt16LittleEndian(Data.AsSpan(8 + Offset), (ushort)value); }
|
2019-01-03 02:15:29 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private Span<byte> Nickname_Trash => Data.AsSpan(10 + Offset, 10);
|
2023-01-22 04:02:33 +00:00
|
|
|
public string Nickname { get => StringConverter3.GetString(Nickname_Trash, Japanese); set => StringConverter3.SetString(Nickname_Trash, value, 10, Japanese, StringConverterOption.ClearZero); }
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public ushort Species { get => (ushort)(SpecLevel & 0x1FF); set => SpecLevel = (SpecLevel & 0xFE00) | value; }
|
|
|
|
public byte Form => 0; // no forms; derive Unown's from PID else use the Version for Deoxys.
|
2022-06-18 18:04:24 +00:00
|
|
|
public int Level { get => SpecLevel >> 9; set => SpecLevel = (SpecLevel & 0x1FF) | (value << 9); }
|
2019-01-03 02:15:29 +00:00
|
|
|
}
|