2018-11-14 03:18:29 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
2019-02-10 04:24:38 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 7 <see cref="SaveFile"/> object for <see cref="GameVersion.GG"/> games.
|
|
|
|
|
/// </summary>
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public sealed class SAV7b : SAV_BEEF
|
2018-11-14 03:18:29 +00:00
|
|
|
|
{
|
|
|
|
|
protected override string BAKText => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
2018-11-17 06:17:18 +00:00
|
|
|
|
public override string Filter => "savedata|*.bin";
|
2018-11-14 03:18:29 +00:00
|
|
|
|
public override string Extension => string.Empty;
|
2019-02-10 04:33:37 +00:00
|
|
|
|
public override string[] PKMExtensions => PKM.Extensions.Where(f => f[1] == 'b' && f[f.Length - 1] == '7').ToArray();
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
|
|
|
|
public override Type PKMType => typeof(PB7);
|
|
|
|
|
public override PKM BlankPKM => new PB7();
|
|
|
|
|
public override int SIZE_STORED => SIZE_PARTY;
|
|
|
|
|
protected override int SIZE_PARTY => 260;
|
|
|
|
|
|
2019-05-12 22:06:50 +00:00
|
|
|
|
public override SaveFile Clone() => new SAV7b((byte[])Data.Clone());
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public SAV7b() : base(SaveUtil.SIZE_G7GG, BlockInfoGG, 0xB8800)
|
|
|
|
|
{
|
|
|
|
|
Initialize();
|
|
|
|
|
ClearBoxes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SAV7b(byte[] data) : base(data, BlockInfoGG, 0xB8800)
|
|
|
|
|
{
|
|
|
|
|
Initialize();
|
|
|
|
|
}
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
private void Initialize()
|
2018-11-14 03:18:29 +00:00
|
|
|
|
{
|
|
|
|
|
Personal = PersonalTable.GG;
|
|
|
|
|
|
|
|
|
|
Box = GetBlockOffset(BelugaBlockIndex.PokeListPokemon);
|
|
|
|
|
Party = GetBlockOffset(BelugaBlockIndex.PokeListPokemon);
|
|
|
|
|
EventFlag = GetBlockOffset(BelugaBlockIndex.EventWork);
|
|
|
|
|
PokeDex = GetBlockOffset(BelugaBlockIndex.Zukan);
|
|
|
|
|
Zukan = new Zukan7b(this, PokeDex, 0x550);
|
|
|
|
|
Config = new ConfigSave7b(this);
|
|
|
|
|
Items = new MyItem7b(this);
|
|
|
|
|
Storage = new PokeListHeader(this);
|
|
|
|
|
Status = new MyStatus7b(this);
|
|
|
|
|
Played = new PlayTime7b(this);
|
|
|
|
|
Misc = new Misc7b(this);
|
|
|
|
|
EventWork = new EventWork7b(this);
|
2018-12-30 05:24:38 +00:00
|
|
|
|
GiftRecords = new WB7Records(this);
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
2018-12-30 06:09:59 +00:00
|
|
|
|
WondercardData = GiftRecords.Offset;
|
|
|
|
|
|
2018-11-14 03:18:29 +00:00
|
|
|
|
HeldItems = Legal.HeldItems_GG;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Save Block accessors
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public MyItem Items { get; private set; }
|
|
|
|
|
public Misc7b Misc { get; private set; }
|
|
|
|
|
public Zukan7b Zukan { get; private set; }
|
|
|
|
|
public MyStatus7b Status { get; private set; }
|
|
|
|
|
public PlayTime7b Played { get; private set; }
|
|
|
|
|
public ConfigSave7b Config { get; private set; }
|
|
|
|
|
public EventWork7b EventWork { get; private set; }
|
|
|
|
|
public PokeListHeader Storage { get; private set; }
|
|
|
|
|
public WB7Records GiftRecords { get; private set; }
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
|
|
|
|
public override InventoryPouch[] Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
|
|
|
|
|
|
|
|
|
// Feature Overrides
|
|
|
|
|
public override int Generation => 7;
|
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_7b;
|
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_7b;
|
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_7b;
|
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_7b;
|
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_7b;
|
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_7b;
|
|
|
|
|
|
|
|
|
|
public override int MaxIV => 31;
|
|
|
|
|
public override int MaxEV => 252;
|
|
|
|
|
public override int OTLength => 12;
|
|
|
|
|
public override int NickLength => 12;
|
|
|
|
|
protected override int GiftCountMax => 48;
|
|
|
|
|
protected override int GiftFlagMax => 0x100 * 8;
|
|
|
|
|
protected override int EventFlagMax => 4160; // 0xDC0 (true max may be up to 0x7F less. 23A8 starts u64 hashvals)
|
|
|
|
|
protected override int EventConstMax => 1000;
|
|
|
|
|
|
|
|
|
|
public override bool HasParty => false; // handled via team slots
|
|
|
|
|
public override bool HasEvents => true; // advanced!
|
|
|
|
|
|
|
|
|
|
// BoxSlotCount => 1000 -- why couldn't this be a multiple of 30...
|
|
|
|
|
public override int BoxSlotCount => 25;
|
|
|
|
|
public override int BoxCount => 40; // 1000/25
|
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public BlockInfo GetBlock(BelugaBlockIndex index) => Blocks[(int)index];
|
2018-11-21 21:51:26 +00:00
|
|
|
|
public int GetBlockOffset(BelugaBlockIndex index) => GetBlock(index).Offset;
|
|
|
|
|
|
2019-07-05 18:57:40 +00:00
|
|
|
|
private const int boGG = 0xB8800 - 0x200; // nowhere near 1MB (savedata.bin size)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
|
2018-11-21 21:51:26 +00:00
|
|
|
|
private static readonly BlockInfo[] BlockInfoGG =
|
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
new BlockInfo7b(boGG, 00, 0x00000, 0x00D90),
|
|
|
|
|
new BlockInfo7b(boGG, 01, 0x00E00, 0x00200),
|
|
|
|
|
new BlockInfo7b(boGG, 02, 0x01000, 0x00168),
|
|
|
|
|
new BlockInfo7b(boGG, 03, 0x01200, 0x01800),
|
|
|
|
|
new BlockInfo7b(boGG, 04, 0x02A00, 0x020E8),
|
|
|
|
|
new BlockInfo7b(boGG, 05, 0x04C00, 0x00930),
|
|
|
|
|
new BlockInfo7b(boGG, 06, 0x05600, 0x00004),
|
|
|
|
|
new BlockInfo7b(boGG, 07, 0x05800, 0x00130),
|
|
|
|
|
new BlockInfo7b(boGG, 08, 0x05A00, 0x00012),
|
|
|
|
|
new BlockInfo7b(boGG, 09, 0x05C00, 0x3F7A0),
|
|
|
|
|
new BlockInfo7b(boGG, 10, 0x45400, 0x00008),
|
|
|
|
|
new BlockInfo7b(boGG, 11, 0x45600, 0x00E90),
|
|
|
|
|
new BlockInfo7b(boGG, 12, 0x46600, 0x010A4),
|
|
|
|
|
new BlockInfo7b(boGG, 13, 0x47800, 0x000F0),
|
|
|
|
|
new BlockInfo7b(boGG, 14, 0x47A00, 0x06010),
|
|
|
|
|
new BlockInfo7b(boGG, 15, 0x4DC00, 0x00200),
|
|
|
|
|
new BlockInfo7b(boGG, 16, 0x4DE00, 0x00098),
|
|
|
|
|
new BlockInfo7b(boGG, 17, 0x4E000, 0x00068),
|
|
|
|
|
new BlockInfo7b(boGG, 18, 0x4E200, 0x69780),
|
|
|
|
|
new BlockInfo7b(boGG, 19, 0xB7A00, 0x000B0),
|
|
|
|
|
new BlockInfo7b(boGG, 20, 0xB7C00, 0x00940),
|
2018-11-21 21:51:26 +00:00
|
|
|
|
};
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
|
|
|
|
public bool FixPreWrite() => Storage.CompressStorage();
|
|
|
|
|
|
|
|
|
|
protected override void SetPKM(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var pk = (PB7)pkm;
|
|
|
|
|
// Apply to this Save File
|
|
|
|
|
int CT = pk.CurrentHandler;
|
|
|
|
|
var Date = DateTime.Now;
|
2019-03-31 05:05:28 +00:00
|
|
|
|
pk.Trade(this, Date.Day, Date.Month, Date.Year);
|
2018-11-14 03:18:29 +00:00
|
|
|
|
if (CT != pk.CurrentHandler) // Logic updated Friendship
|
|
|
|
|
{
|
|
|
|
|
// Copy over the Friendship Value only under certain circumstances
|
|
|
|
|
if (pk.Moves.Contains(216)) // Return
|
|
|
|
|
pk.CurrentFriendship = pk.OppositeFriendship;
|
|
|
|
|
else if (pk.Moves.Contains(218)) // Frustration
|
|
|
|
|
pk.CurrentFriendship = pk.OppositeFriendship;
|
|
|
|
|
}
|
|
|
|
|
pk.RefreshChecksum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void SetDex(PKM pkm) => Zukan.SetDex(pkm);
|
|
|
|
|
public override bool GetCaught(int species) => Zukan.GetCaught(species);
|
|
|
|
|
public override bool GetSeen(int species) => Zukan.GetSeen(species);
|
|
|
|
|
|
2019-03-30 02:43:33 +00:00
|
|
|
|
protected override PKM GetPKM(byte[] data) => new PB7(data);
|
|
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray(data);
|
2018-11-14 03:18:29 +00:00
|
|
|
|
public override int GetBoxOffset(int box) => Box + (box * BoxSlotCount * SIZE_STORED);
|
|
|
|
|
protected override IList<int>[] SlotPointers => new[] { Storage.PokeListInfo };
|
|
|
|
|
|
|
|
|
|
public override int GetPartyOffset(int slot) => Storage.GetPartyOffset(slot);
|
|
|
|
|
public override int PartyCount { get => Storage.PartyCount; protected set => Storage.PartyCount = value; }
|
2018-11-18 03:42:48 +00:00
|
|
|
|
protected override void SetPartyValues(PKM pkm, bool isParty) => base.SetPartyValues(pkm, true);
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
2018-12-05 06:59:28 +00:00
|
|
|
|
public override StorageSlotFlag GetSlotFlags(int index)
|
|
|
|
|
{
|
|
|
|
|
var val = StorageSlotFlag.None;
|
|
|
|
|
if (Storage.PokeListInfo[6] == index)
|
|
|
|
|
val |= StorageSlotFlag.Starter;
|
|
|
|
|
int position = Array.IndexOf(Storage.PokeListInfo, index);
|
|
|
|
|
if ((uint) position < 6)
|
|
|
|
|
val |= (StorageSlotFlag)((int)StorageSlotFlag.Party1 << position);
|
|
|
|
|
return val;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-14 03:18:29 +00:00
|
|
|
|
public override string GetBoxName(int box) => $"Box {box + 1}";
|
|
|
|
|
public override void SetBoxName(int box, string value) { }
|
|
|
|
|
|
2018-12-05 06:00:57 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString7(data, offset, length);
|
2018-11-14 03:18:29 +00:00
|
|
|
|
|
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
|
|
|
|
{
|
|
|
|
|
if (PadToSize == 0)
|
|
|
|
|
PadToSize = maxLength + 1;
|
2018-11-15 06:51:53 +00:00
|
|
|
|
return StringConverter.SetString7b(value, maxLength, Language, PadToSize, PadWith);
|
2018-11-14 03:18:29 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override GameVersion Version
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
switch (Game)
|
|
|
|
|
{
|
|
|
|
|
case (int)GameVersion.GP: return GameVersion.GP;
|
|
|
|
|
case (int)GameVersion.GE: return GameVersion.GE;
|
|
|
|
|
default: return GameVersion.Invalid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Player Information
|
|
|
|
|
public override int TID { get => Status.TID; set => Status.TID = value; }
|
|
|
|
|
public override int SID { get => Status.SID; set => Status.SID = value; }
|
|
|
|
|
public override int Game { get => Status.Game; set => Status.Game = value; }
|
|
|
|
|
public override int Gender { get => Status.Gender; set => Status.Gender = value; }
|
2019-04-10 04:19:08 +00:00
|
|
|
|
public override int Language { get => Status.Language; set => Config.Language = Status.Language = value; } // stored in multiple places
|
2018-11-14 03:18:29 +00:00
|
|
|
|
public override string OT { get => Status.OT; set => Status.OT = value; }
|
|
|
|
|
public override uint Money { get => Misc.Money; set => Misc.Money = value; }
|
|
|
|
|
|
|
|
|
|
public override int PlayedHours { get => Played.PlayedHours; set => Played.PlayedHours = value; }
|
|
|
|
|
public override int PlayedMinutes { get => Played.PlayedMinutes; set => Played.PlayedMinutes = value; }
|
|
|
|
|
public override int PlayedSeconds { get => Played.PlayedSeconds; set => Played.PlayedSeconds = value; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the <see cref="bool"/> status of a desired Event Flag
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flagNumber">Event Flag to check</param>
|
|
|
|
|
/// <returns>Flag is Set (true) or not Set (false)</returns>
|
|
|
|
|
public override bool GetEventFlag(int flagNumber) => EventWork.GetFlag(flagNumber);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the <see cref="bool"/> status of a desired Event Flag
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="flagNumber">Event Flag to check</param>
|
|
|
|
|
/// <param name="value">Event Flag status to set</param>
|
|
|
|
|
/// <remarks>Flag is Set (true) or not Set (false)</remarks>
|
|
|
|
|
public override void SetEventFlag(int flagNumber, bool value) => EventWork.SetFlag(flagNumber, value);
|
2018-12-30 06:09:59 +00:00
|
|
|
|
|
|
|
|
|
protected override bool[] MysteryGiftReceivedFlags { get => GiftRecords.Flags; set => GiftRecords.Flags = value; }
|
|
|
|
|
protected override MysteryGift[] MysteryGiftCards { get => GiftRecords.Records; set => GiftRecords.Records = (WR7[])value; }
|
2019-05-17 05:26:51 +00:00
|
|
|
|
|
|
|
|
|
public override int GameSyncIDSize => MyStatus7b.GameSyncIDSize; // 64 bits
|
|
|
|
|
public override string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; }
|
2018-11-14 03:18:29 +00:00
|
|
|
|
}
|
|
|
|
|
}
|