2022-08-27 06:43:36 +00:00
|
|
|
using System;
|
2018-11-14 03:18:29 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Generation 7 <see cref="SaveFile"/> object for <see cref="GameVersion.GG"/> games.
|
|
|
|
/// </summary>
|
2024-03-04 05:13:16 +00:00
|
|
|
public sealed class SAV7b : SAV_BEEF, ISaveBlock7b, IGameSync, IMysteryGiftStorageProvider
|
2018-11-14 03:18:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {Blocks.Played.LastSavedTime}";
|
|
|
|
public override string Extension => ".bin";
|
|
|
|
public override IReadOnlyList<string> PKMExtensions => EntityFileExtension.Extensions7b;
|
|
|
|
|
|
|
|
public override Type PKMType => typeof(PB7);
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PB7 BlankPKM => new();
|
2024-03-05 05:46:11 +00:00
|
|
|
protected override int SIZE_STORED => PokeCrypto.SIZE_6STORED;
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int SIZE_PARTY => PokeCrypto.SIZE_6PARTY;
|
|
|
|
public override int SIZE_BOXSLOT => PokeCrypto.SIZE_6PARTY;
|
|
|
|
public override byte[] GetDataForBox(PKM pk) => pk.EncryptedPartyData;
|
2024-03-05 15:42:20 +00:00
|
|
|
public override PB7 GetBoxSlot(int offset) => GetDecryptedPKM(Data.AsSpan(offset, SIZE_PARTY).ToArray()); // party format in boxes!
|
|
|
|
public override PB7 GetDecryptedPKM(byte[] data) => GetPKM(DecryptPKM(data));
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalTable7GG Personal => PersonalTable.GG;
|
2023-03-26 00:55:55 +00:00
|
|
|
public override ReadOnlySpan<ushort> HeldItems => Legal.HeldItems_GG;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override SAV7b CloneInternal() => new((byte[])Data.Clone());
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public SaveBlockAccessor7b Blocks { get; }
|
|
|
|
public override IReadOnlyList<BlockInfo> AllBlocks => Blocks.BlockInfo;
|
|
|
|
|
|
|
|
public SAV7b() : base(SaveUtil.SIZE_G7GG, 0xB8800)
|
|
|
|
{
|
|
|
|
Blocks = new SaveBlockAccessor7b(this);
|
|
|
|
Initialize();
|
|
|
|
ClearBoxes();
|
|
|
|
}
|
|
|
|
|
|
|
|
public SAV7b(byte[] data) : base(data, 0xB8800)
|
|
|
|
{
|
|
|
|
Blocks = new SaveBlockAccessor7b(this);
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2024-03-04 05:13:16 +00:00
|
|
|
public override bool HasPokeDex => true;
|
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Initialize()
|
|
|
|
{
|
2024-03-04 05:13:16 +00:00
|
|
|
Box = Blocks.BlockInfo[(int)BelugaBlockIndex.PokeListPokemon].Offset;
|
|
|
|
Party = Blocks.BlockInfo[(int)BelugaBlockIndex.PokeListPokemon].Offset;
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save Block accessors
|
2024-03-04 05:13:16 +00:00
|
|
|
public MyItem7b Items => Blocks.Items;
|
2023-11-05 20:24:08 +00:00
|
|
|
public Coordinates7b Coordinates => Blocks.Coordinates;
|
2022-06-18 18:04:24 +00:00
|
|
|
public Misc7b Misc => Blocks.Misc;
|
|
|
|
public Zukan7b Zukan => Blocks.Zukan;
|
|
|
|
public MyStatus7b Status => Blocks.Status;
|
|
|
|
public PlayTime7b Played => Blocks.Played;
|
|
|
|
public ConfigSave7b Config => Blocks.Config;
|
|
|
|
public EventWork7b EventWork => Blocks.EventWork;
|
|
|
|
public PokeListHeader Storage => Blocks.Storage;
|
|
|
|
public WB7Records GiftRecords => Blocks.GiftRecords;
|
2024-03-04 05:13:16 +00:00
|
|
|
public Daycare7b Daycare => Blocks.Daycare;
|
2022-06-18 18:04:24 +00:00
|
|
|
public CaptureRecords Captured => Blocks.Captured;
|
2024-02-23 19:20:24 +00:00
|
|
|
public GoParkStorage Park => Blocks.Park;
|
2024-02-23 19:19:01 +00:00
|
|
|
public PlayerGeoLocation7b PlayerGeoLocation => Blocks.PlayerGeoLocation;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory { get => Blocks.Items.Inventory; set => Blocks.Items.Inventory = value; }
|
|
|
|
|
|
|
|
// Feature Overrides
|
2024-02-23 03:20:54 +00:00
|
|
|
public override byte Generation => 7;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override EntityContext Context => EntityContext.Gen7b;
|
2022-08-27 06:43:36 +00:00
|
|
|
public override ushort MaxMoveID => Legal.MaxMoveID_7b;
|
|
|
|
public override ushort MaxSpeciesID => Legal.MaxSpeciesID_7b;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxItemID => Legal.MaxItemID_7b;
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_7b;
|
2024-02-23 03:20:54 +00:00
|
|
|
public override GameVersion MaxGameID => Legal.MaxGameID_7b;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_7b;
|
|
|
|
|
|
|
|
public override int MaxIV => 31;
|
2023-09-28 05:15:59 +00:00
|
|
|
public override int MaxEV => EffortValues.Max252;
|
2024-05-12 19:46:58 +00:00
|
|
|
public override int MaxStringLengthTrainer => 12;
|
2022-11-25 01:42:17 +00:00
|
|
|
public override int MaxStringLengthNickname => 12;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public override bool HasParty => false; // handled via team slots
|
|
|
|
|
|
|
|
// BoxSlotCount => 1000 -- why couldn't this be a multiple of 30...
|
|
|
|
public override int BoxSlotCount => 25;
|
|
|
|
public override int BoxCount => 40; // 1000/25
|
|
|
|
|
|
|
|
public bool FixPreWrite() => Blocks.Storage.CompressStorage();
|
|
|
|
|
|
|
|
protected override void SetPKM(PKM pk, bool isParty = false)
|
2018-11-14 03:18:29 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
var pb7 = (PB7)pk;
|
|
|
|
// Apply to this Save File
|
2024-02-23 23:01:36 +00:00
|
|
|
pb7.UpdateHandler(this);
|
2022-06-18 18:04:24 +00:00
|
|
|
pb7.RefreshChecksum();
|
2018-11-14 03:18:29 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
protected override void SetDex(PKM pk) => Blocks.Zukan.SetDex(pk);
|
2022-08-27 06:43:36 +00:00
|
|
|
public override bool GetCaught(ushort species) => Blocks.Zukan.GetCaught(species);
|
|
|
|
public override bool GetSeen(ushort species) => Blocks.Zukan.GetSeen(species);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
protected override PB7 GetPKM(byte[] data) => new(data);
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray6(data);
|
|
|
|
public override int GetBoxOffset(int box) => Box + (box * BoxSlotCount * SIZE_BOXSLOT);
|
2023-12-04 04:13:20 +00:00
|
|
|
protected override IList<int>[] SlotPointers => [ Blocks.Storage.PokeListInfo ];
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
public override int GetPartyOffset(int slot) => Blocks.Storage.GetPartyOffset(slot);
|
|
|
|
public override int PartyCount { get => Blocks.Storage.PartyCount; protected set => Blocks.Storage.PartyCount = value; }
|
|
|
|
protected override void SetPartyValues(PKM pk, bool isParty) => base.SetPartyValues(pk, true);
|
|
|
|
|
2024-06-29 15:39:59 +00:00
|
|
|
public override StorageSlotSource GetBoxSlotFlags(int index)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
var result = StorageSlotSource.None;
|
|
|
|
var header = Blocks.Storage.PokeListInfo;
|
|
|
|
int position = Array.IndexOf(header, index, 0, 6);
|
|
|
|
if (position >= 0)
|
|
|
|
result = (StorageSlotSource)((int)StorageSlotSource.Party1 << position);
|
|
|
|
if (header[PokeListHeader.STARTER] == index)
|
|
|
|
result |= StorageSlotSource.Starter;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-04-23 05:57:17 +00:00
|
|
|
public override string GetString(ReadOnlySpan<byte> data)
|
|
|
|
=> StringConverter8.GetString(data);
|
|
|
|
public override int LoadString(ReadOnlySpan<byte> data, Span<char> destBuffer)
|
|
|
|
=> StringConverter8.LoadString(data, destBuffer);
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int SetString(Span<byte> destBuffer, ReadOnlySpan<char> value, int maxLength, StringConverterOption option)
|
2024-04-23 05:57:17 +00:00
|
|
|
=> StringConverter8.SetString(destBuffer, value, maxLength);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
2024-02-23 03:20:54 +00:00
|
|
|
public override bool IsVersionValid() => Version is GameVersion.GP or GameVersion.GE;
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// Player Information
|
2023-01-22 04:02:33 +00:00
|
|
|
public override uint ID32 { get => Blocks.Status.ID32; set => Blocks.Status.ID32 = value; }
|
|
|
|
public override ushort TID16 { get => Blocks.Status.TID16; set => Blocks.Status.TID16 = value; }
|
|
|
|
public override ushort SID16 { get => Blocks.Status.SID16; set => Blocks.Status.SID16 = value; }
|
2024-02-23 03:20:54 +00:00
|
|
|
public override GameVersion Version { get => (GameVersion)Blocks.Status.Game; set => Blocks.Status.Game = (byte)value; }
|
|
|
|
public override byte Gender { get => Blocks.Status.Gender; set => Blocks.Status.Gender = value; }
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int Language { get => Blocks.Status.Language; set => Blocks.Config.Language = Blocks.Status.Language = value; } // stored in multiple places
|
|
|
|
public override string OT { get => Blocks.Status.OT; set => Blocks.Status.OT = value; }
|
|
|
|
public override uint Money { get => Blocks.Misc.Money; set => Blocks.Misc.Money = value; }
|
|
|
|
|
|
|
|
public override int PlayedHours { get => Blocks.Played.PlayedHours; set => Blocks.Played.PlayedHours = value; }
|
|
|
|
public override int PlayedMinutes { get => Blocks.Played.PlayedMinutes; set => Blocks.Played.PlayedMinutes = value; }
|
|
|
|
public override int PlayedSeconds { get => Blocks.Played.PlayedSeconds; set => Blocks.Played.PlayedSeconds = value; }
|
|
|
|
|
|
|
|
public int GameSyncIDSize => MyStatus7b.GameSyncIDSize; // 64 bits
|
|
|
|
public string GameSyncID { get => Blocks.Status.GameSyncID; set => Blocks.Status.GameSyncID = value; }
|
2024-03-04 05:13:16 +00:00
|
|
|
IMysteryGiftStorage IMysteryGiftStorageProvider.MysteryGiftStorage => Blocks.GiftRecords;
|
2018-11-14 03:18:29 +00:00
|
|
|
}
|