2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
2019-02-02 07:08:03 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 5 <see cref="SaveFile"/> object.
|
|
|
|
|
/// </summary>
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public abstract class SAV5 : SaveFile
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected override PKM GetPKM(byte[] data) => new PK5(data);
|
|
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PKX.DecryptArray45(data);
|
|
|
|
|
|
2018-07-30 04:51:45 +00:00
|
|
|
|
protected override string BAKText => $"{OT} ({(GameVersion)Game}) - {PlayTimeString}";
|
2019-02-08 05:40:20 +00:00
|
|
|
|
public override string Filter => (Footer.Length != 0 ? "DeSmuME DSV|*.dsv|" : string.Empty) + "SAV File|*.sav|All Files|*.*";
|
2016-06-20 05:11:53 +00:00
|
|
|
|
public override string Extension => ".sav";
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int SIZE_STORED => PKX.SIZE_5STORED;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected override int SIZE_PARTY => PKX.SIZE_5PARTY;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override PKM BlankPKM => new PK5();
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public override Type PKMType => typeof(PK5);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public override int BoxCount => 24;
|
|
|
|
|
public override int MaxEV => 255;
|
|
|
|
|
public override int Generation => 5;
|
2017-04-10 04:53:53 +00:00
|
|
|
|
public override int OTLength => 7;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int NickLength => 10;
|
|
|
|
|
protected override int GiftCountMax => 12;
|
|
|
|
|
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxMoveID => Legal.MaxMoveID_5;
|
2016-10-24 04:59:27 +00:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_5;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxAbilityID => Legal.MaxAbilityID_5;
|
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_5;
|
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_5; // B2
|
2016-06-21 01:58:06 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected SAV5(int size) : base(size)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Initialize();
|
|
|
|
|
ClearBoxes();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected SAV5(byte[] data) : base(data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Initialize();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public override GameVersion Version
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
get => (GameVersion)Game;
|
|
|
|
|
protected set => Game = (int)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
private void Initialize()
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
// First blocks are always the same position/size
|
|
|
|
|
PCLayout = 0x0;
|
|
|
|
|
Box = 0x400;
|
|
|
|
|
Party = 0x18E00;
|
|
|
|
|
Trainer1 = 0x19400;
|
|
|
|
|
WondercardData = 0x1C800;
|
|
|
|
|
AdventureInfo = 0x1D900;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
HeldItems = Legal.HeldItems_BW;
|
|
|
|
|
BoxLayout = new BoxLayout5(this, PCLayout);
|
|
|
|
|
MysteryBlock = new MysteryBlock5(this, WondercardData);
|
|
|
|
|
PlayerData = new PlayerData5(this, Trainer1);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
// Blocks & Offsets
|
|
|
|
|
protected IReadOnlyList<BlockInfoNDS> Blocks;
|
|
|
|
|
protected override void SetChecksums() => Blocks.SetChecksums(Data);
|
|
|
|
|
public override bool ChecksumsValid => Blocks.GetChecksumsValid(Data);
|
|
|
|
|
public override string ChecksumInfo => Blocks.GetChecksumInfo(Data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected MyItem Items { get; set; }
|
|
|
|
|
public Zukan Zukan { get; protected set; }
|
|
|
|
|
public Misc5 MiscBlock { get; protected set; }
|
|
|
|
|
private MysteryBlock5 MysteryBlock { get; set; }
|
|
|
|
|
protected Daycare5 DaycareBlock { get; set; }
|
|
|
|
|
public BoxLayout5 BoxLayout { get; private set; }
|
|
|
|
|
public PlayerData5 PlayerData { get; private set; }
|
|
|
|
|
public BattleSubway5 BattleSubwayBlock { get; protected set; }
|
|
|
|
|
|
|
|
|
|
protected int CGearInfoOffset;
|
|
|
|
|
protected int CGearDataOffset;
|
|
|
|
|
protected int EntreeForestOffset;
|
|
|
|
|
protected int Trainer2;
|
|
|
|
|
private int AdventureInfo;
|
|
|
|
|
protected int BattleSubway;
|
2019-07-05 23:21:53 +00:00
|
|
|
|
protected int PokeDexLanguageFlags;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private int PCLayout;
|
|
|
|
|
public int GTS { get; protected set; } = int.MinValue;
|
|
|
|
|
public int Fused { get; protected set; } = int.MinValue;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
// Daycare
|
|
|
|
|
public override int DaycareSeedSize => Daycare5.DaycareSeedSize;
|
|
|
|
|
public override bool? IsDaycareOccupied(int loc, int slot) => DaycareBlock.IsOccupied(slot);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public override int GetDaycareSlotOffset(int loc, int slot) => DaycareBlock.GetPKMOffset(slot);
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public override uint? GetDaycareEXP(int loc, int slot) => DaycareBlock.GetEXP(slot);
|
|
|
|
|
public override string GetDaycareRNGSeed(int loc) => DaycareBlock.GetSeed()?.ToString("X16");
|
|
|
|
|
public override void SetDaycareEXP(int loc, int slot, uint EXP) => DaycareBlock.SetEXP(slot, EXP);
|
|
|
|
|
public override void SetDaycareOccupied(int loc, int slot, bool occupied) => DaycareBlock.SetOccupied(slot, occupied);
|
|
|
|
|
public override void SetDaycareRNGSeed(int loc, string seed) => DaycareBlock.SetSeed(seed);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => Data[Party + 4];
|
|
|
|
|
protected set => Data[Party + 4] = (byte)value;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public override int GetBoxOffset(int box) => Box + (SIZE_STORED * box * 30) + (box * 0x10);
|
|
|
|
|
public override int GetPartyOffset(int slot) => Party + 8 + (SIZE_PARTY * slot);
|
2019-04-30 00:21:19 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected override int GetBoxWallpaperOffset(int box) => BoxLayout.GetBoxWallpaperOffset(box);
|
|
|
|
|
public override int GetBoxWallpaper(int box) => BoxLayout.GetBoxWallpaper(box);
|
|
|
|
|
public override void SetBoxWallpaper(int box, int value) => BoxLayout.SetBoxWallpaper(box, value);
|
|
|
|
|
public override string GetBoxName(int box) => BoxLayout[box];
|
|
|
|
|
public override void SetBoxName(int box, string value) => BoxLayout[box] = value;
|
|
|
|
|
public override int CurrentBox { get => BoxLayout.CurrentBox; set => BoxLayout.CurrentBox = value; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public override bool BattleBoxLocked
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
get => Data[BattleBox + 0x358] != 0; // wifi/live
|
|
|
|
|
set => Data[BattleBox + 0x358] = (byte)(value ? 1 : 0);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-03-22 04:10:23 +00:00
|
|
|
|
protected override void SetPKM(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
var pk5 = (PK5)pkm;
|
|
|
|
|
// Apply to this Save File
|
|
|
|
|
DateTime Date = DateTime.Now;
|
|
|
|
|
if (pk5.Trade(OT, TID, SID, Gender, Date.Day, Date.Month, Date.Year))
|
|
|
|
|
pkm.RefreshChecksum();
|
|
|
|
|
}
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
// Player Data
|
|
|
|
|
public override string OT { get => PlayerData.OT; set => PlayerData.OT = value; }
|
|
|
|
|
public override int TID { get => PlayerData.TID; set => PlayerData.TID = value; }
|
|
|
|
|
public override int SID { get => PlayerData.SID; set => PlayerData.SID = value; }
|
|
|
|
|
public override int Language { get => PlayerData.Language; set => PlayerData.Language = value; }
|
|
|
|
|
public override int Game { get => PlayerData.Game; set => PlayerData.Game = value; }
|
|
|
|
|
public override int Gender { get => PlayerData.Gender; set => PlayerData.Gender = value; }
|
|
|
|
|
public override int PlayedHours { get => PlayerData.PlayedHours; set => PlayerData.PlayedHours = value; }
|
|
|
|
|
public override int PlayedMinutes { get => PlayerData.PlayedMinutes; set => PlayerData.PlayedMinutes = value; }
|
|
|
|
|
public override int PlayedSeconds { get => PlayerData.PlayedSeconds; set => PlayerData.PlayedSeconds = value; }
|
|
|
|
|
public override uint Money { get => MiscBlock.Money; set => MiscBlock.Money = value; }
|
2019-03-05 23:55:26 +00:00
|
|
|
|
public override uint SecondsToStart { get => BitConverter.ToUInt32(Data, AdventureInfo + 0x34); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x34); }
|
|
|
|
|
public override uint SecondsToFame { get => BitConverter.ToUInt32(Data, AdventureInfo + 0x3C); set => BitConverter.GetBytes(value).CopyTo(Data, AdventureInfo + 0x3C); }
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public override MysteryGiftAlbum GiftAlbum { get => MysteryBlock.GiftAlbum; set => MysteryBlock.GiftAlbum = value; }
|
|
|
|
|
public override InventoryPouch[] Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
2016-07-04 18:56:30 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
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);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2018-12-05 06:00:57 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString5(data, offset, length);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
2017-04-09 21:06:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (PadToSize == 0)
|
|
|
|
|
PadToSize = maxLength + 1;
|
2017-08-01 06:03:51 +00:00
|
|
|
|
return StringConverter.SetString5(value, maxLength, PadToSize, PadWith);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
}
|
2018-01-14 00:32:57 +00:00
|
|
|
|
|
|
|
|
|
// DLC
|
2019-07-14 22:06:45 +00:00
|
|
|
|
private int CGearSkinInfoOffset => CGearInfoOffset + (this is SAV5B2W2 ? 0x10 : 0) + 0x24;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-01-14 00:32:57 +00:00
|
|
|
|
private bool CGearSkinPresent
|
|
|
|
|
{
|
|
|
|
|
get => Data[CGearSkinInfoOffset + 2] == 1;
|
2019-07-14 22:06:45 +00:00
|
|
|
|
set => Data[CGearSkinInfoOffset + 2] = Data[Trainer1 + (this is SAV5B2W2 ? 0x6C : 0x54)] = (byte) (value ? 1 : 0);
|
2018-01-14 00:32:57 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-01-14 00:32:57 +00:00
|
|
|
|
public byte[] CGearSkinData
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
byte[] data = new byte[CGearBackground.SIZE_CGB];
|
2018-01-14 00:32:57 +00:00
|
|
|
|
if (CGearSkinPresent)
|
|
|
|
|
Array.Copy(Data, CGearDataOffset, data, 0, data.Length);
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == null)
|
|
|
|
|
return; // no clearing
|
|
|
|
|
byte[] dlcfooter = { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x14, 0x27, 0x00, 0x00, 0x27, 0x35, 0x05, 0x31, 0x00, 0x00 };
|
|
|
|
|
|
|
|
|
|
byte[] bgdata = value;
|
|
|
|
|
SetData(bgdata, CGearDataOffset);
|
|
|
|
|
|
2019-03-16 19:01:21 +00:00
|
|
|
|
ushort chk = Checksums.CRC16_CCITT(bgdata);
|
2018-01-14 00:32:57 +00:00
|
|
|
|
var chkbytes = BitConverter.GetBytes(chk);
|
|
|
|
|
int footer = CGearDataOffset + bgdata.Length;
|
|
|
|
|
|
|
|
|
|
BitConverter.GetBytes((ushort)1).CopyTo(Data, footer); // block updated once
|
|
|
|
|
chkbytes.CopyTo(Data, footer + 2); // checksum
|
|
|
|
|
chkbytes.CopyTo(Data, footer + 0x100); // second checksum
|
|
|
|
|
dlcfooter.CopyTo(Data, footer + 0x102);
|
2019-03-16 19:01:21 +00:00
|
|
|
|
ushort skinchkval = Checksums.CRC16_CCITT(Data, footer + 0x100, 4);
|
2018-01-14 00:32:57 +00:00
|
|
|
|
BitConverter.GetBytes(skinchkval).CopyTo(Data, footer + 0x112);
|
|
|
|
|
|
|
|
|
|
// Indicate in the save file that data is present
|
|
|
|
|
BitConverter.GetBytes((ushort)0xC21E).CopyTo(Data, 0x19438);
|
|
|
|
|
|
|
|
|
|
chkbytes.CopyTo(Data, CGearSkinInfoOffset);
|
|
|
|
|
CGearSkinPresent = true;
|
|
|
|
|
|
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-28 15:26:52 +00:00
|
|
|
|
|
|
|
|
|
public EntreeForest EntreeData
|
|
|
|
|
{
|
|
|
|
|
get => new EntreeForest(GetData(EntreeForestOffset, 0x850));
|
|
|
|
|
set => SetData(value.Write(), EntreeForestOffset);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|