2020-09-30 19:45:41 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Pocket Monsters Stadium
|
|
|
|
|
/// </summary>
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public sealed class SAV1StadiumJ : SAV_STADIUM
|
2020-09-30 19:45:41 +00:00
|
|
|
|
{
|
2020-10-01 01:00:25 +00:00
|
|
|
|
// Required since PK1 logic comparing a save file assumes the save file can be U/J
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public override int SaveRevision => 0;
|
|
|
|
|
public override string SaveRevisionString => "0"; // so we're different from Japanese SAV1Stadium naming...
|
2020-10-01 01:00:25 +00:00
|
|
|
|
|
2020-09-30 19:45:41 +00:00
|
|
|
|
public override PersonalTable Personal => PersonalTable.Y;
|
|
|
|
|
public override int MaxEV => ushort.MaxValue;
|
|
|
|
|
public override IReadOnlyList<ushort> HeldItems => Array.Empty<ushort>();
|
|
|
|
|
public override GameVersion Version { get; protected set; } = GameVersion.StadiumJ;
|
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
protected override SaveFile CloneInternal() => new SAV1StadiumJ((byte[])Data.Clone());
|
2020-09-30 19:45:41 +00:00
|
|
|
|
|
|
|
|
|
public override int Generation => 1;
|
2020-10-01 01:00:25 +00:00
|
|
|
|
private const int StringLength = 6; // Japanese Only
|
2020-09-30 19:45:41 +00:00
|
|
|
|
public override int OTLength => StringLength;
|
|
|
|
|
public override int NickLength => StringLength;
|
2020-10-04 14:51:55 +00:00
|
|
|
|
public override int BoxCount => 4; // 8 boxes stored sequentially; latter 4 are backups
|
2020-09-30 19:45:41 +00:00
|
|
|
|
public override int BoxSlotCount => 30;
|
|
|
|
|
|
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_1;
|
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_1;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_1;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_1;
|
2020-10-04 16:23:16 +00:00
|
|
|
|
private const int SIZE_PK1J = PokeCrypto.SIZE_1STORED + (2 * StringLength); // 0x2D
|
|
|
|
|
protected override int SIZE_STORED => SIZE_PK1J;
|
|
|
|
|
protected override int SIZE_PARTY => SIZE_PK1J;
|
2020-09-30 19:45:41 +00:00
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public override Type PKMType => typeof(PK1);
|
|
|
|
|
public override PKM BlankPKM => new PK1(true);
|
2020-10-01 01:00:25 +00:00
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
private const int ListHeaderSize = 0x14;
|
|
|
|
|
private const int ListFooterSize = 6; // POKE + 2byte checksum
|
|
|
|
|
private const uint FOOTER_MAGIC = 0x454B4F50; // POKE
|
2020-10-01 05:46:07 +00:00
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
protected override int TeamCount => 16; // 32 teams stored sequentially; latter 16 are backups
|
|
|
|
|
private const int TeamSizeJ = 0x14 + (SIZE_PK1J * 6) + ListFooterSize; // 0x128
|
|
|
|
|
private const int BoxSizeJ = 0x560;
|
|
|
|
|
|
|
|
|
|
public SAV1StadiumJ(byte[] data) : base(data, true, StadiumUtil.IsMagicPresentSwap(data, TeamSizeJ, FOOTER_MAGIC))
|
2020-10-01 05:46:07 +00:00
|
|
|
|
{
|
2020-10-04 16:23:16 +00:00
|
|
|
|
Box = 0x2500;
|
2020-10-01 05:46:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public SAV1StadiumJ() : base(true, SaveUtil.SIZE_G1STAD)
|
|
|
|
|
{
|
|
|
|
|
Box = 0x2500;
|
|
|
|
|
ClearBoxes();
|
|
|
|
|
}
|
2020-10-01 01:00:25 +00:00
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
protected override bool GetIsBoxChecksumValid(int i)
|
2020-10-01 01:00:25 +00:00
|
|
|
|
{
|
2020-10-04 16:23:16 +00:00
|
|
|
|
var boxOfs = GetBoxOffset(i) - ListHeaderSize;
|
|
|
|
|
const int size = BoxSizeJ - 2;
|
|
|
|
|
var chk = Checksums.CheckSum16(Data, boxOfs, size);
|
|
|
|
|
var actual = BigEndian.ToUInt16(Data, boxOfs + size);
|
|
|
|
|
return chk == actual;
|
2020-10-01 01:00:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
protected override void SetBoxChecksum(int i)
|
2020-10-01 01:00:25 +00:00
|
|
|
|
{
|
2020-10-04 16:23:16 +00:00
|
|
|
|
var boxOfs = GetBoxOffset(i) - ListHeaderSize;
|
|
|
|
|
const int size = BoxSizeJ - 2;
|
|
|
|
|
var chk = Checksums.CheckSum16(Data, boxOfs, size);
|
|
|
|
|
BigEndian.GetBytes(chk).CopyTo(Data, boxOfs + size);
|
2020-10-01 01:00:25 +00:00
|
|
|
|
}
|
2020-09-30 19:45:41 +00:00
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
protected override void SetBoxMetadata(int i)
|
|
|
|
|
{
|
|
|
|
|
// Not implemented
|
|
|
|
|
}
|
2020-09-30 19:45:41 +00:00
|
|
|
|
|
|
|
|
|
protected override PKM GetPKM(byte[] data)
|
|
|
|
|
{
|
2020-10-01 01:00:25 +00:00
|
|
|
|
const int len = StringLength;
|
2020-09-30 19:45:41 +00:00
|
|
|
|
var nick = data.Slice(0x21, len);
|
|
|
|
|
var ot = data.Slice(0x21 + len, len);
|
2020-10-01 01:00:25 +00:00
|
|
|
|
data = data.Slice(0, 0x21);
|
2020-09-30 19:45:41 +00:00
|
|
|
|
return new PK1(data, true) { OT_Trash = ot, Nickname_Trash = nick };
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-10 21:59:51 +00:00
|
|
|
|
public override byte[] GetDataForFormatStored(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
byte[] result = new byte[SIZE_STORED];
|
|
|
|
|
var gb = (PK1)pkm;
|
|
|
|
|
|
|
|
|
|
var data = pkm.Data;
|
|
|
|
|
const int len = StringLength;
|
|
|
|
|
data.CopyTo(result, 0);
|
|
|
|
|
gb.nick.CopyTo(result, PokeCrypto.SIZE_1STORED);
|
|
|
|
|
gb.otname.CopyTo(result, PokeCrypto.SIZE_1STORED + len);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override byte[] GetDataForFormatParty(PKM pkm) => GetDataForFormatStored(pkm);
|
|
|
|
|
public override byte[] GetDataForParty(PKM pkm) => GetDataForFormatStored(pkm);
|
|
|
|
|
public override byte[] GetDataForBox(PKM pkm) => GetDataForFormatStored(pkm);
|
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public override int GetBoxOffset(int box) => Box + ListHeaderSize + (box * BoxSizeJ);
|
2020-10-10 22:28:34 +00:00
|
|
|
|
public static int GetTeamOffset(int team) => 0 + (team * 2 * TeamSizeJ); // backups are after each team
|
2020-10-10 03:31:13 +00:00
|
|
|
|
|
|
|
|
|
public string GetTeamName(int team)
|
|
|
|
|
{
|
|
|
|
|
var name = $"Team {team + 1}";
|
|
|
|
|
|
|
|
|
|
var ofs = GetTeamOffset(team);
|
|
|
|
|
var str = GetString(ofs + 2, 5);
|
|
|
|
|
if (string.IsNullOrWhiteSpace(str))
|
|
|
|
|
return name;
|
|
|
|
|
var id = BigEndian.ToUInt16(Data, ofs + 8);
|
|
|
|
|
return $"{name} [{id:D5}:{str}]";
|
|
|
|
|
}
|
2020-10-01 01:00:25 +00:00
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public override SlotGroup GetTeam(int team)
|
2020-10-01 01:00:25 +00:00
|
|
|
|
{
|
|
|
|
|
if ((uint)team >= TeamCount)
|
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(team));
|
|
|
|
|
|
|
|
|
|
var name = GetTeamName(team);
|
|
|
|
|
var members = new PK1[6];
|
|
|
|
|
var ofs = GetTeamOffset(team);
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
{
|
2020-10-04 01:22:29 +00:00
|
|
|
|
var rel = ofs + ListHeaderSize + (i * SIZE_STORED);
|
2020-10-01 01:00:25 +00:00
|
|
|
|
members[i] = (PK1)GetStoredSlot(Data, rel);
|
|
|
|
|
}
|
2020-10-04 01:22:29 +00:00
|
|
|
|
return new SlotGroup(name, members);
|
2020-10-01 01:00:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-30 19:45:41 +00:00
|
|
|
|
public override void WriteSlotFormatStored(PKM pkm, byte[] data, int offset)
|
|
|
|
|
{
|
|
|
|
|
// pkm that have never been boxed have yet to save the 'current level' for box indication
|
|
|
|
|
// set this value at this time
|
|
|
|
|
((PK1)pkm).Stat_LevelBox = pkm.CurrentLevel;
|
|
|
|
|
base.WriteSlotFormatStored(pkm, Data, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WriteBoxSlot(PKM pkm, byte[] data, int offset)
|
|
|
|
|
{
|
|
|
|
|
// pkm that have never been boxed have yet to save the 'current level' for box indication
|
|
|
|
|
// set this value at this time
|
|
|
|
|
((PK1)pkm).Stat_LevelBox = pkm.CurrentLevel;
|
|
|
|
|
base.WriteBoxSlot(pkm, Data, offset);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 16:23:16 +00:00
|
|
|
|
public static bool IsStadium(byte[] data)
|
2020-09-30 19:45:41 +00:00
|
|
|
|
{
|
2020-10-01 01:00:25 +00:00
|
|
|
|
if (data.Length != SaveUtil.SIZE_G1STADJ)
|
2020-09-30 19:45:41 +00:00
|
|
|
|
return false;
|
2020-10-04 16:23:16 +00:00
|
|
|
|
return StadiumUtil.IsMagicPresentEither(data, TeamSizeJ, FOOTER_MAGIC);
|
2020-09-30 19:45:41 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|