2016-06-20 04:22:43 +00:00
|
|
|
|
using System;
|
2017-09-29 05:20:27 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-07-02 02:43:51 +00:00
|
|
|
|
using System.Diagnostics;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
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>
|
|
|
|
|
/// Base Class for Save Files
|
|
|
|
|
/// </summary>
|
2018-03-28 22:55:19 +00:00
|
|
|
|
public abstract class SaveFile : ITrainerInfo
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-19 05:27:40 +00:00
|
|
|
|
public static bool SetUpdateDex { protected get; set; } = true;
|
|
|
|
|
public static bool SetUpdatePKM { protected get; set; } = true;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// General Object Properties
|
|
|
|
|
public byte[] Data;
|
|
|
|
|
public bool Edited;
|
|
|
|
|
public string FileName, FilePath;
|
|
|
|
|
public abstract string BAKName { get; }
|
2016-06-28 06:03:57 +00:00
|
|
|
|
public byte[] BAK { get; protected set; }
|
|
|
|
|
public bool Exportable { get; protected set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract SaveFile Clone();
|
2016-06-20 05:11:53 +00:00
|
|
|
|
public abstract string Filter { get; }
|
2016-06-28 06:03:57 +00:00
|
|
|
|
public byte[] Footer { protected get; set; } = new byte[0]; // .dsv
|
2016-09-19 05:47:31 +00:00
|
|
|
|
public byte[] Header { protected get; set; } = new byte[0]; // .gci
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool Japanese { get; protected set; }
|
2018-02-21 23:22:43 +00:00
|
|
|
|
protected virtual string PlayTimeString => $"{PlayedHours}ː{PlayedMinutes:00}ː{PlayedSeconds:00}"; // not :
|
2018-03-12 01:07:48 +00:00
|
|
|
|
public bool IndeterminateGame => Version == GameVersion.Unknown;
|
2016-10-12 02:11:24 +00:00
|
|
|
|
public virtual bool IndeterminateSubVersion => false;
|
2017-01-05 06:22:50 +00:00
|
|
|
|
public abstract string Extension { get; }
|
|
|
|
|
public virtual string[] PKMExtensions => PKM.Extensions.Where(f =>
|
|
|
|
|
{
|
|
|
|
|
int gen = f.Last() - 0x30;
|
2017-01-27 17:13:42 +00:00
|
|
|
|
return 3 <= gen && gen <= Generation;
|
2017-01-05 06:22:50 +00:00
|
|
|
|
}).ToArray();
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// General PKM Properties
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public abstract Type PKMType { get; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public abstract PKM GetPKM(byte[] data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract PKM BlankPKM { get; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public abstract byte[] DecryptPKM(byte[] data);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int SIZE_STORED { get; }
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected abstract int SIZE_PARTY { get; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int MaxEV { get; }
|
2016-08-28 10:18:22 +00:00
|
|
|
|
public virtual int MaxIV => 31;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public ushort[] HeldItems { get; protected set; }
|
|
|
|
|
|
|
|
|
|
// General SAV Properties
|
2017-04-21 02:38:48 +00:00
|
|
|
|
public virtual byte[] Write(bool DSV, bool GCI)
|
2017-04-02 14:53:46 +00:00
|
|
|
|
{
|
|
|
|
|
return Write(DSV);
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected virtual byte[] Write(bool DSV)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetChecksums();
|
2016-06-20 05:11:53 +00:00
|
|
|
|
if (Footer.Length > 0 && DSV)
|
|
|
|
|
return Data.Concat(Footer).ToArray();
|
2016-09-19 05:47:31 +00:00
|
|
|
|
if (Header.Length > 0)
|
|
|
|
|
return Header.Concat(Data).ToArray();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return Data;
|
|
|
|
|
}
|
2017-09-29 05:20:27 +00:00
|
|
|
|
public virtual string MiscSaveChecks() => string.Empty;
|
|
|
|
|
public virtual string MiscSaveInfo() => string.Empty;
|
2016-06-28 06:03:57 +00:00
|
|
|
|
public virtual GameVersion Version { get; protected set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract bool ChecksumsValid { get; }
|
|
|
|
|
public abstract string ChecksumInfo { get; }
|
|
|
|
|
public abstract int Generation { get; }
|
2016-07-28 01:59:10 +00:00
|
|
|
|
public PersonalTable Personal { get; set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-09-19 05:36:06 +00:00
|
|
|
|
public bool USUM => Data.Length == SaveUtil.SIZE_G7USUM;
|
2016-11-08 16:43:57 +00:00
|
|
|
|
public bool SM => Data.Length == SaveUtil.SIZE_G7SM;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public bool ORASDEMO => Data.Length == SaveUtil.SIZE_G6ORASDEMO;
|
2016-08-16 03:57:42 +00:00
|
|
|
|
public bool ORAS => Data.Length == SaveUtil.SIZE_G6ORAS;
|
|
|
|
|
public bool XY => Data.Length == SaveUtil.SIZE_G6XY;
|
2016-07-26 06:11:17 +00:00
|
|
|
|
public bool B2W2 => Version == GameVersion.B2W2;
|
|
|
|
|
public bool BW => Version == GameVersion.BW;
|
|
|
|
|
public bool HGSS => Version == GameVersion.HGSS;
|
|
|
|
|
public bool Pt => Version == GameVersion.Pt;
|
|
|
|
|
public bool DP => Version == GameVersion.DP;
|
|
|
|
|
public bool E => Version == GameVersion.E;
|
|
|
|
|
public bool FRLG => Version == GameVersion.FRLG;
|
|
|
|
|
public bool RS => Version == GameVersion.RS;
|
2016-09-02 21:20:39 +00:00
|
|
|
|
public bool GSC => Version == GameVersion.GS || Version == GameVersion.C;
|
2017-01-07 05:22:42 +00:00
|
|
|
|
public bool RBY => Version == GameVersion.RBY;
|
|
|
|
|
public bool GameCube => new[] { GameVersion.COLO, GameVersion.XD, GameVersion.RSBOX }.Contains(Version);
|
2016-09-02 21:20:39 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public abstract int MaxMoveID { get; }
|
|
|
|
|
public abstract int MaxSpeciesID { get; }
|
|
|
|
|
public abstract int MaxAbilityID { get; }
|
|
|
|
|
public abstract int MaxItemID { get; }
|
|
|
|
|
public abstract int MaxBallID { get; }
|
|
|
|
|
public abstract int MaxGameID { get; }
|
2016-06-21 01:58:06 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Flags
|
|
|
|
|
public bool HasWondercards => WondercardData > -1;
|
|
|
|
|
public bool HasSuperTrain => SuperTrain > -1;
|
|
|
|
|
public bool HasBerryField => BerryField > -1;
|
|
|
|
|
public bool HasHoF => HoF > -1;
|
|
|
|
|
public bool HasSecretBase => SecretBase > -1;
|
|
|
|
|
public bool HasPuff => Puff > -1;
|
|
|
|
|
public bool HasPSS => PSS > -1;
|
|
|
|
|
public bool HasOPower => OPower > -1;
|
|
|
|
|
public bool HasJPEG => JPEGData != null;
|
|
|
|
|
public bool HasBox => Box > -1;
|
2016-07-05 06:52:37 +00:00
|
|
|
|
public virtual bool HasParty => Party > -1;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public bool HasBattleBox => BattleBox > -1;
|
|
|
|
|
public bool HasFused => Fused > -1;
|
|
|
|
|
public bool HasGTS => GTS > -1;
|
|
|
|
|
public bool HasDaycare => Daycare > -1;
|
2016-07-04 18:56:30 +00:00
|
|
|
|
public virtual bool HasPokeDex => PokeDex > -1;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual bool HasBoxWallpapers => GetBoxWallpaperOffset(0) > -1;
|
2017-12-27 23:52:29 +00:00
|
|
|
|
public virtual bool HasNamableBoxes => HasBoxWallpapers;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public virtual bool HasSUBE => SUBE > -1 && !ORAS;
|
|
|
|
|
public virtual bool HasGeolocation => false;
|
|
|
|
|
public bool HasPokeBlock => ORAS && !ORASDEMO;
|
|
|
|
|
public bool HasEvents => EventFlags != null;
|
2016-07-27 03:18:48 +00:00
|
|
|
|
public bool HasLink => ORAS && !ORASDEMO || XY;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Counts
|
|
|
|
|
protected virtual int GiftCountMax { get; } = int.MinValue;
|
|
|
|
|
protected virtual int GiftFlagMax { get; } = 0x800;
|
|
|
|
|
protected virtual int EventFlagMax { get; } = int.MinValue;
|
|
|
|
|
protected virtual int EventConstMax { get; } = int.MinValue;
|
2016-06-26 21:23:41 +00:00
|
|
|
|
public virtual int DaycareSeedSize { get; } = 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int OTLength { get; }
|
|
|
|
|
public abstract int NickLength { get; }
|
2017-02-04 20:13:54 +00:00
|
|
|
|
public virtual int MaxMoney => 9999999;
|
|
|
|
|
public virtual int MaxCoins => 9999;
|
|
|
|
|
public virtual int MaxShadowID => 0;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Offsets
|
2018-02-16 01:05:45 +00:00
|
|
|
|
protected int Box { get; set; } = int.MinValue;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected int Party { get; set; } = int.MinValue;
|
|
|
|
|
protected int Trainer1 { get; set; } = int.MinValue;
|
|
|
|
|
protected int Daycare { get; set; } = int.MinValue;
|
|
|
|
|
protected int WondercardData { get; set; } = int.MinValue;
|
|
|
|
|
protected int PCLayout { get; set; } = int.MinValue;
|
|
|
|
|
protected int EventFlag { get; set; } = int.MinValue;
|
|
|
|
|
protected int EventConst { get; set; } = int.MinValue;
|
|
|
|
|
|
|
|
|
|
public int GTS { get; protected set; } = int.MinValue;
|
|
|
|
|
public int BattleBox { get; protected set; } = int.MinValue;
|
|
|
|
|
public int Fused { get; protected set; } = int.MinValue;
|
|
|
|
|
public int SUBE { get; protected set; } = int.MinValue;
|
|
|
|
|
public int PokeDex { get; protected set; } = int.MinValue;
|
|
|
|
|
public int SuperTrain { get; protected set; } = int.MinValue;
|
|
|
|
|
public int SecretBase { get; protected set; } = int.MinValue;
|
|
|
|
|
public int Puff { get; protected set; } = int.MinValue;
|
|
|
|
|
public int PSS { get; protected set; } = int.MinValue;
|
|
|
|
|
public int BerryField { get; protected set; } = int.MinValue;
|
|
|
|
|
public int OPower { get; protected set; } = int.MinValue;
|
|
|
|
|
public int HoF { get; protected set; } = int.MinValue;
|
|
|
|
|
|
|
|
|
|
// SAV Properties
|
2017-09-29 05:20:27 +00:00
|
|
|
|
public IList<PKM> BoxData
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-08-28 10:18:22 +00:00
|
|
|
|
PKM[] data = new PKM[BoxCount*BoxSlotCount];
|
2016-06-20 04:22:43 +00:00
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
data[i] = GetStoredSlot(GetBoxOffset(i/BoxSlotCount) + SIZE_STORED*(i%BoxSlotCount));
|
|
|
|
|
data[i].Identifier = $"{GetBoxName(i/BoxSlotCount)}:{i%BoxSlotCount + 1:00}";
|
2016-08-28 10:18:22 +00:00
|
|
|
|
data[i].Box = i/BoxSlotCount + 1;
|
|
|
|
|
data[i].Slot = i%BoxSlotCount + 1;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
data[i].Locked = IsSlotLocked(data[i].Box, data[i].Slot);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-09-29 05:20:27 +00:00
|
|
|
|
if (value.Count != BoxCount*BoxSlotCount)
|
|
|
|
|
throw new ArgumentException($"Expected {BoxCount*BoxSlotCount}, got {value.Count}");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (value.Any(pk => PKMType != pk.GetType()))
|
|
|
|
|
throw new ArgumentException($"Not {PKMType} array.");
|
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
for (int i = 0; i < value.Count; i++)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetStoredSlot(value[i], GetBoxOffset(i/BoxSlotCount) + SIZE_STORED*(i%BoxSlotCount));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 05:20:27 +00:00
|
|
|
|
public IList<PKM> PartyData
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
PKM[] data = new PKM[PartyCount];
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
data[i] = GetPartySlot(GetPartyOffset(i));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-09-29 05:20:27 +00:00
|
|
|
|
if (value.Count == 0 || value.Count > 6)
|
2017-09-30 05:58:25 +00:00
|
|
|
|
throw new ArgumentException($"Expected 1-6, got {value.Count}");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (value.Any(pk => PKMType != pk.GetType()))
|
|
|
|
|
throw new ArgumentException($"Not {PKMType} array.");
|
|
|
|
|
if (value[0].Species == 0)
|
2017-09-29 05:20:27 +00:00
|
|
|
|
Debug.WriteLine($"Empty first slot, received {value.Count}.");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-10-24 06:12:58 +00:00
|
|
|
|
PKM[] newParty = new PKM[6];
|
|
|
|
|
value.Where(pk => pk.Species != 0).CopyTo(newParty);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
for (int i = PartyCount; i < newParty.Length; i++)
|
|
|
|
|
newParty[i] = BlankPKM;
|
|
|
|
|
for (int i = 0; i < newParty.Length; i++)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPartySlot(newParty[i], GetPartyOffset(i));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-29 05:20:27 +00:00
|
|
|
|
public IList<PKM> BattleBoxData
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-10-20 01:19:01 +00:00
|
|
|
|
if (!HasBattleBox)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return new PKM[0];
|
|
|
|
|
|
|
|
|
|
PKM[] data = new PKM[6];
|
|
|
|
|
for (int i = 0; i < data.Length; i++)
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
data[i] = GetStoredSlot(BattleBox + SIZE_STORED * i);
|
2016-12-16 07:17:17 +00:00
|
|
|
|
data[i].Locked = BattleBoxLocked;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (data[i].Species == 0)
|
|
|
|
|
return data.Take(i).ToArray();
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 03:37:18 +00:00
|
|
|
|
/// <summary> All Event Flag values for the savegame </summary>
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public bool[] EventFlags
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (EventFlagMax < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
bool[] Flags = new bool[EventFlagMax];
|
|
|
|
|
for (int i = 0; i < Flags.Length; i++)
|
2017-09-24 23:36:51 +00:00
|
|
|
|
Flags[i] = GetEventFlag(i);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return Flags;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (EventFlagMax < 0)
|
|
|
|
|
return;
|
|
|
|
|
if (value.Length != EventFlagMax)
|
|
|
|
|
return;
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
2017-09-24 23:36:51 +00:00
|
|
|
|
SetEventFlag(i, value[i]);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-14 03:37:18 +00:00
|
|
|
|
/// <summary> All Event Constant values for the savegame </summary>
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public ushort[] EventConsts
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (EventConstMax < 0)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
ushort[] Constants = new ushort[EventConstMax];
|
|
|
|
|
for (int i = 0; i < Constants.Length; i++)
|
2016-08-04 00:56:15 +00:00
|
|
|
|
Constants[i] = BitConverter.ToUInt16(Data, EventConst + i * 2);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return Constants;
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (EventConstMax < 0)
|
|
|
|
|
return;
|
|
|
|
|
if (value.Length != EventConstMax)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
|
BitConverter.GetBytes(value[i]).CopyTo(Data, EventConst + i * 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-14 03:37:18 +00:00
|
|
|
|
/// <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 bool GetEventFlag(int flagNumber)
|
|
|
|
|
{
|
|
|
|
|
if (flagNumber > EventFlagMax)
|
|
|
|
|
throw new ArgumentException($"Event Flag to get ({flagNumber}) is greater than max ({EventFlagMax}).");
|
2017-09-24 23:36:51 +00:00
|
|
|
|
return GetFlag(EventFlag + (flagNumber >> 3), flagNumber & 7);
|
2017-09-14 03:37:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <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 void SetEventFlag(int flagNumber, bool value)
|
|
|
|
|
{
|
|
|
|
|
if (flagNumber > EventFlagMax)
|
|
|
|
|
throw new ArgumentException($"Event Flag to set ({flagNumber}) is greater than max ({EventFlagMax}).");
|
2017-09-24 23:36:51 +00:00
|
|
|
|
SetFlag(EventFlag + (flagNumber >> 3), flagNumber & 7, value);
|
|
|
|
|
}
|
2017-10-19 04:43:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the <see cref="bool"/> status of the Flag at the specified offset and index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset to read from</param>
|
|
|
|
|
/// <param name="bitIndex">Bit index to read</param>
|
|
|
|
|
/// <returns>Flag is Set (true) or not Set (false)</returns>
|
|
|
|
|
public bool GetFlag(int offset, int bitIndex)
|
2017-09-24 23:36:51 +00:00
|
|
|
|
{
|
2017-10-19 04:43:42 +00:00
|
|
|
|
bitIndex &= 7; // ensure bit access is 0-7
|
|
|
|
|
return (Data[offset] >> bitIndex & 1) != 0;
|
2017-09-24 23:36:51 +00:00
|
|
|
|
}
|
2017-10-19 04:43:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the <see cref="bool"/> status of the Flag at the specified offset and index.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="offset">Offset to read from</param>
|
|
|
|
|
/// <param name="bitIndex">Bit index to read</param>
|
|
|
|
|
/// <param name="value">Flag status to set</param>
|
|
|
|
|
/// <remarks>Flag is Set (true) or not Set (false)</remarks>
|
|
|
|
|
public void SetFlag(int offset, int bitIndex, bool value)
|
2017-09-24 23:36:51 +00:00
|
|
|
|
{
|
2017-10-19 04:43:42 +00:00
|
|
|
|
bitIndex &= 7; // ensure bit access is 0-7
|
|
|
|
|
Data[offset] &= (byte)~(1 << bitIndex);
|
|
|
|
|
Data[offset] |= (byte)((value ? 1 : 0) << bitIndex);
|
2017-09-14 03:37:18 +00:00
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Inventory
|
2016-09-19 05:47:31 +00:00
|
|
|
|
public virtual InventoryPouch[] Inventory { get; set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
protected int OFS_PouchHeldItem { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_PouchKeyItem { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_PouchMedicine { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_PouchTMHM { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_PouchBerry { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_PouchBalls { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_BattleItems { get; set; } = int.MinValue;
|
|
|
|
|
protected int OFS_MailItems { get; set; } = int.MinValue;
|
2016-08-27 11:33:21 +00:00
|
|
|
|
protected int OFS_PCItem { get; set; } = int.MinValue;
|
2016-10-20 01:19:01 +00:00
|
|
|
|
protected int OFS_PouchZCrystals { get; set; } = int.MinValue;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Mystery Gift
|
2017-05-13 03:32:36 +00:00
|
|
|
|
protected virtual bool[] MysteryGiftReceivedFlags { get => null; set { } }
|
|
|
|
|
protected virtual MysteryGift[] MysteryGiftCards { get => null; set { } }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public virtual MysteryGiftAlbum GiftAlbum
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => new MysteryGiftAlbum
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
Flags = MysteryGiftReceivedFlags,
|
|
|
|
|
Gifts = MysteryGiftCards
|
|
|
|
|
};
|
2016-06-20 04:22:43 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
MysteryGiftReceivedFlags = value.Flags;
|
|
|
|
|
MysteryGiftCards = value.Gifts;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual bool BattleBoxLocked { get => false; set { } }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public virtual string JPEGTitle => null;
|
|
|
|
|
public virtual byte[] JPEGData => null;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int Country { get => -1; set { } }
|
|
|
|
|
public virtual int ConsoleRegion { get => -1; set { } }
|
|
|
|
|
public virtual int SubRegion { get => -1; set { } }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Trainer Info
|
2016-09-19 05:47:31 +00:00
|
|
|
|
public virtual int Gender { get; set; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int Language { get => -1; set { } }
|
|
|
|
|
public virtual int Game { get => -1; set { } }
|
2018-04-28 18:06:58 +00:00
|
|
|
|
public virtual int TID { get; set; }
|
|
|
|
|
public virtual int SID { get; set; }
|
2016-11-19 01:19:16 +00:00
|
|
|
|
public int TrainerID7 => (int)((uint)(TID | (SID << 16)) % 1000000);
|
2017-05-19 00:51:08 +00:00
|
|
|
|
public virtual string OT { get; set; } = "PKHeX";
|
2016-09-19 05:47:31 +00:00
|
|
|
|
public virtual int PlayedHours { get; set; }
|
|
|
|
|
public virtual int PlayedMinutes { get; set; }
|
|
|
|
|
public virtual int PlayedSeconds { get; set; }
|
2016-06-26 21:23:41 +00:00
|
|
|
|
public virtual int SecondsToStart { get; set; }
|
|
|
|
|
public virtual int SecondsToFame { get; set; }
|
2016-09-19 05:47:31 +00:00
|
|
|
|
public virtual uint Money { get; set; }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public abstract int BoxCount { get; }
|
2017-05-23 04:55:05 +00:00
|
|
|
|
public int SlotCount => BoxCount * BoxSlotCount;
|
2016-09-19 05:47:31 +00:00
|
|
|
|
public virtual int PartyCount { get; protected set; }
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int MultiplayerSpriteID { get => 0; set { } }
|
2017-06-22 03:24:42 +00:00
|
|
|
|
public bool IsPartyAllEggs(params int[] except)
|
|
|
|
|
{
|
|
|
|
|
if (!HasParty)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var party = PartyData;
|
2017-09-29 05:20:27 +00:00
|
|
|
|
return party.Count == party.Where((t, i) => t.IsEgg || except.Contains(i)).Count();
|
2017-06-22 03:24:42 +00:00
|
|
|
|
}
|
2016-06-20 05:11:53 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Varied Methods
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected abstract void SetChecksums();
|
|
|
|
|
public abstract int GetBoxOffset(int box);
|
|
|
|
|
public abstract int GetPartyOffset(int slot);
|
|
|
|
|
public abstract string GetBoxName(int box);
|
|
|
|
|
public abstract void SetBoxName(int box, string val);
|
2016-12-10 20:27:37 +00:00
|
|
|
|
public virtual int GameSyncIDSize { get; } = 8;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual string GameSyncID { get => null; set { } }
|
|
|
|
|
public virtual ulong? Secure1 { get => null; set { } }
|
|
|
|
|
public virtual ulong? Secure2 { get => null; set { } }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Daycare
|
|
|
|
|
public int DaycareIndex = 0;
|
2016-10-23 19:45:27 +00:00
|
|
|
|
public virtual bool HasTwoDaycares => false;
|
2017-10-18 06:19:34 +00:00
|
|
|
|
public virtual int GetDaycareSlotOffset(int loc, int slot) => -1;
|
|
|
|
|
public virtual uint? GetDaycareEXP(int loc, int slot) => null;
|
|
|
|
|
public virtual string GetDaycareRNGSeed(int loc) => null;
|
|
|
|
|
public virtual bool? IsDaycareHasEgg(int loc) => null;
|
|
|
|
|
public virtual bool? IsDaycareOccupied(int loc, int slot) => null;
|
2016-09-19 05:47:31 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual void SetDaycareEXP(int loc, int slot, uint EXP) { }
|
|
|
|
|
public virtual void SetDaycareRNGSeed(int loc, string seed) { }
|
|
|
|
|
public virtual void SetDaycareHasEgg(int loc, bool hasEgg) { }
|
|
|
|
|
public virtual void SetDaycareOccupied(int loc, int slot, bool occupied) { }
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
// Storage
|
2016-08-28 10:18:22 +00:00
|
|
|
|
public virtual int BoxSlotCount => 30;
|
2017-05-13 03:32:36 +00:00
|
|
|
|
public virtual int BoxesUnlocked { get => -1; set { } }
|
|
|
|
|
public virtual byte[] BoxFlags { get => null; set { } }
|
|
|
|
|
public virtual int CurrentBox { get => 0; set { } }
|
2016-12-16 07:17:17 +00:00
|
|
|
|
protected int[] LockedSlots = new int[0];
|
2016-12-27 00:41:12 +00:00
|
|
|
|
protected int[] TeamSlots = new int[0];
|
2017-01-07 05:22:42 +00:00
|
|
|
|
public bool MoveBox(int box, int insertBeforeBox)
|
|
|
|
|
{
|
|
|
|
|
if (box == insertBeforeBox) // no movement required
|
|
|
|
|
return true;
|
|
|
|
|
if (box >= BoxCount || insertBeforeBox >= BoxCount) // invalid box positions
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int pos1 = BoxSlotCount*box;
|
|
|
|
|
int pos2 = BoxSlotCount*insertBeforeBox;
|
|
|
|
|
int min = Math.Min(pos1, pos2);
|
|
|
|
|
int max = Math.Max(pos1, pos2);
|
|
|
|
|
if (LockedSlots.Any(slot => min <= slot && slot < max)) // slots locked within operation range
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
int len = BoxSlotCount*SIZE_STORED;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
byte[] boxdata = GetData(GetBoxOffset(0), len*BoxCount); // get all boxes
|
|
|
|
|
string[] boxNames = new int[BoxCount].Select((x, i) => GetBoxName(i)).ToArray();
|
|
|
|
|
int[] boxWallpapers = new int[BoxCount].Select((x, i) => GetBoxWallpaper(i)).ToArray();
|
2017-01-07 05:22:42 +00:00
|
|
|
|
|
|
|
|
|
min /= BoxSlotCount;
|
|
|
|
|
max /= BoxSlotCount;
|
|
|
|
|
|
|
|
|
|
// move all boxes within range to final spot
|
|
|
|
|
for (int i = min, ctr = min; i < max; i++)
|
|
|
|
|
{
|
|
|
|
|
int b = insertBeforeBox; // if box is the moved box, move to insertion point, else move to unused box.
|
|
|
|
|
if (i != box)
|
|
|
|
|
{
|
|
|
|
|
if (insertBeforeBox == ctr)
|
|
|
|
|
++ctr;
|
|
|
|
|
b = ctr++;
|
|
|
|
|
}
|
2017-09-29 05:20:27 +00:00
|
|
|
|
Buffer.BlockCopy(boxdata, len*i, Data, GetBoxOffset(b), len);
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetBoxName(b, boxNames[i]);
|
|
|
|
|
SetBoxWallpaper(b, boxWallpapers[i]);
|
2017-01-07 05:22:42 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public bool SwapBox(int box1, int box2)
|
|
|
|
|
{
|
|
|
|
|
if (box1 == box2) // no movement required
|
|
|
|
|
return true;
|
|
|
|
|
if (box1 >= BoxCount || box2 >= BoxCount) // invalid box positions
|
|
|
|
|
return false;
|
|
|
|
|
|
2017-10-18 06:19:34 +00:00
|
|
|
|
if (!IsBoxAbleToMove(box1) || !IsBoxAbleToMove(box2))
|
2017-01-07 05:22:42 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Data
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int b1o = GetBoxOffset(box1);
|
|
|
|
|
int b2o = GetBoxOffset(box2);
|
2017-01-07 05:22:42 +00:00
|
|
|
|
int len = BoxSlotCount*SIZE_STORED;
|
|
|
|
|
byte[] b1 = new byte[len];
|
2017-09-29 05:20:27 +00:00
|
|
|
|
Buffer.BlockCopy(Data, b1o, b1, 0, len);
|
|
|
|
|
Buffer.BlockCopy(Data, b2o, Data, b1o, len);
|
|
|
|
|
Buffer.BlockCopy(b1, 0, Data, b2o, len);
|
2017-01-07 05:22:42 +00:00
|
|
|
|
|
|
|
|
|
// Name
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string b1n = GetBoxName(box1);
|
|
|
|
|
SetBoxName(box1, GetBoxName(box2));
|
|
|
|
|
SetBoxName(box2, b1n);
|
2017-01-07 05:22:42 +00:00
|
|
|
|
|
|
|
|
|
// Wallpaper
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int b1w = GetBoxWallpaper(box1);
|
|
|
|
|
SetBoxWallpaper(box1, GetBoxWallpaper(box2));
|
|
|
|
|
SetBoxWallpaper(box2, b1w);
|
2017-01-07 05:22:42 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-10-18 06:19:34 +00:00
|
|
|
|
private bool IsBoxAbleToMove(int box)
|
|
|
|
|
{
|
|
|
|
|
int min = BoxSlotCount * box;
|
|
|
|
|
int max = BoxSlotCount * box + BoxSlotCount;
|
|
|
|
|
if (LockedSlots.Any(slot => min <= slot && slot < max)) // locked slot within box
|
|
|
|
|
return false;
|
|
|
|
|
if (TeamSlots.Any(slot => min <= slot && slot < max)) // team slot within box
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-29 18:32:21 +00:00
|
|
|
|
|
2017-12-17 03:52:06 +00:00
|
|
|
|
protected virtual int GetBoxWallpaperOffset(int box) => -1;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual int GetBoxWallpaper(int box)
|
2016-10-29 18:32:21 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = GetBoxWallpaperOffset(box);
|
2016-10-29 18:32:21 +00:00
|
|
|
|
if (offset < 0 || box > BoxCount)
|
|
|
|
|
return box;
|
|
|
|
|
return Data[offset];
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual void SetBoxWallpaper(int box, int val)
|
2016-10-29 18:32:21 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = GetBoxWallpaperOffset(box);
|
2016-10-29 18:32:21 +00:00
|
|
|
|
if (offset < 0 || box > BoxCount)
|
|
|
|
|
return;
|
|
|
|
|
Data[offset] = (byte)val;
|
|
|
|
|
}
|
2016-09-19 05:47:31 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual PKM GetPartySlot(int offset)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetPKM(DecryptPKM(GetData(offset, SIZE_PARTY)));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual PKM GetStoredSlot(int offset)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
return GetPKM(DecryptPKM(GetData(offset, SIZE_STORED)));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetPartySlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm == null) return;
|
|
|
|
|
if (pkm.GetType() != PKMType)
|
2017-03-17 04:20:06 +00:00
|
|
|
|
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (trade ?? SetUpdatePKM)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKM(pkm);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (dex ?? SetUpdateDex)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetDex(pkm);
|
|
|
|
|
SetPartyValues(pkm, isParty: true);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-10-18 06:19:34 +00:00
|
|
|
|
int i = GetPartyIndex(offset);
|
|
|
|
|
if (i <= -1)
|
|
|
|
|
throw new ArgumentException("Invalid Party offset provided; unable to resolve party slot index.");
|
|
|
|
|
|
|
|
|
|
// update party count
|
|
|
|
|
if (pkm.Species != 0)
|
|
|
|
|
{
|
|
|
|
|
if (PartyCount <= i)
|
|
|
|
|
PartyCount = i + 1;
|
|
|
|
|
}
|
|
|
|
|
else if (PartyCount > i)
|
|
|
|
|
PartyCount = i;
|
2016-07-05 03:04:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetData(pkm.EncryptedPartyData, offset);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
2017-10-18 06:19:34 +00:00
|
|
|
|
private int GetPartyIndex(int offset)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 6; i++)
|
|
|
|
|
if (GetPartyOffset(i) == offset)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual void SetStoredSlot(PKM pkm, int offset, bool? trade = null, bool? dex = null)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (pkm == null) return;
|
|
|
|
|
if (pkm.GetType() != PKMType)
|
2017-03-17 04:20:06 +00:00
|
|
|
|
throw new ArgumentException($"PKM Format needs to be {PKMType} when setting to this Save File.");
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (trade ?? SetUpdatePKM)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetPKM(pkm);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (dex ?? SetUpdateDex)
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetDex(pkm);
|
|
|
|
|
SetPartyValues(pkm, isParty: false);
|
|
|
|
|
SetData(pkm.EncryptedBoxData, offset);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void DeletePartySlot(int slot)
|
2016-07-05 03:04:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (PartyCount <= slot) // beyond party range (or empty data already present)
|
|
|
|
|
return;
|
|
|
|
|
// Move all party slots down one
|
|
|
|
|
for (int i = slot + 1; i < 6; i++) // Slide slots down
|
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int slotTo = GetPartyOffset(i - 1);
|
|
|
|
|
int slotFrom = GetPartyOffset(i);
|
|
|
|
|
SetData(GetData(slotFrom, SIZE_PARTY), slotTo);
|
2016-07-05 03:04:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
SetStoredSlot(BlankPKM, GetPartyOffset(5), false, false);
|
2016-07-05 03:04:43 +00:00
|
|
|
|
PartyCount -= 1;
|
|
|
|
|
}
|
2017-10-18 06:19:34 +00:00
|
|
|
|
public virtual bool IsSlotLocked(int box, int slot) => false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool IsAnySlotLockedInBox(int BoxStart, int BoxEnd)
|
2016-12-16 07:17:17 +00:00
|
|
|
|
{
|
|
|
|
|
return LockedSlots.Any(slot => BoxStart*BoxSlotCount <= slot && slot < (BoxEnd + 1)*BoxSlotCount);
|
|
|
|
|
}
|
2017-10-18 06:19:34 +00:00
|
|
|
|
public virtual bool IsSlotInBattleTeam(int box, int slot) => false;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-05-01 04:39:12 +00:00
|
|
|
|
public void SortBoxes(int BoxStart = 0, int BoxEnd = -1, Func<IEnumerable<PKM>, IEnumerable<PKM>> sortMethod = null, bool reverse = false)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-09-29 05:20:27 +00:00
|
|
|
|
var BD = BoxData;
|
|
|
|
|
int start = BoxSlotCount * BoxStart;
|
|
|
|
|
var Section = BD.Skip(start);
|
2018-04-24 02:11:55 +00:00
|
|
|
|
if (BoxEnd >= BoxStart)
|
|
|
|
|
Section = Section.Take(BoxSlotCount * (BoxEnd - BoxStart + 1));
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2018-04-21 22:07:58 +00:00
|
|
|
|
var Sorted = (sortMethod ?? PKMSorting.OrderBySpecies)(Section);
|
2018-05-01 04:39:12 +00:00
|
|
|
|
if (reverse)
|
|
|
|
|
Sorted = Sorted.ReverseSort();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
Sorted.CopyTo(BD, start);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
BoxData = BD;
|
|
|
|
|
}
|
2018-05-01 00:29:13 +00:00
|
|
|
|
public void ClearBoxes(int BoxStart = 0, int BoxEnd = -1, Func<PKM, bool> deleteCriteria = null)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (BoxEnd < 0)
|
2018-04-24 02:11:55 +00:00
|
|
|
|
BoxEnd = BoxCount - 1;
|
2017-03-04 17:38:39 +00:00
|
|
|
|
|
|
|
|
|
var blank = BlankPKM.EncryptedBoxData;
|
|
|
|
|
if (this is SAV3RSBox)
|
|
|
|
|
Array.Resize(ref blank, blank.Length + 4); // 00000 TID/SID at end
|
|
|
|
|
|
2018-04-24 02:11:55 +00:00
|
|
|
|
for (int i = BoxStart; i <= BoxEnd; i++)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
int offset = GetBoxOffset(i);
|
2016-08-28 10:18:22 +00:00
|
|
|
|
for (int p = 0; p < BoxSlotCount; p++)
|
2018-05-01 00:29:13 +00:00
|
|
|
|
{
|
|
|
|
|
var ofs = offset + SIZE_STORED * p;
|
|
|
|
|
if (deleteCriteria != null)
|
|
|
|
|
{
|
|
|
|
|
var pk = GetStoredSlot(ofs);
|
|
|
|
|
if (!deleteCriteria(pk))
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetData(blank, ofs);
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-22 19:43:18 +00:00
|
|
|
|
public void ModifyBoxes(Action<PKM> action, int BoxStart = 0, int BoxEnd = -1)
|
|
|
|
|
{
|
|
|
|
|
if (BoxEnd < 0)
|
2018-04-24 02:11:55 +00:00
|
|
|
|
BoxEnd = BoxCount - 1;
|
2018-04-22 19:43:18 +00:00
|
|
|
|
var BD = BoxData;
|
2018-04-24 02:11:55 +00:00
|
|
|
|
for (int b = BoxStart; b <= BoxEnd; b++)
|
2018-04-22 19:43:18 +00:00
|
|
|
|
for (int s = 0; s < BoxSlotCount; s++)
|
|
|
|
|
{
|
|
|
|
|
if (IsSlotLocked(b, s))
|
|
|
|
|
continue;
|
|
|
|
|
var index = b * BoxSlotCount + s;
|
|
|
|
|
action(BD[index]);
|
|
|
|
|
}
|
|
|
|
|
BoxData = BD;
|
|
|
|
|
}
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public byte[] PCBinary => BoxData.SelectMany(pk => pk.EncryptedBoxData).ToArray();
|
|
|
|
|
public byte[] GetBoxBinary(int box) => BoxData.Skip(box*BoxSlotCount).Take(BoxSlotCount).SelectMany(pk => pk.EncryptedBoxData).ToArray();
|
|
|
|
|
public bool SetPCBinary(byte[] data)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-12-05 04:16:54 +00:00
|
|
|
|
if (LockedSlots.Length != 0)
|
2016-12-16 07:17:17 +00:00
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (data.Length != PCBinary.Length)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
var BD = BoxData;
|
|
|
|
|
var pkdata = PKX.GetPKMDataFromConcatenatedBinary(data, BlankPKM.EncryptedBoxData.Length);
|
|
|
|
|
pkdata.Select(z => GetPKM(DecryptPKM(z))).CopyTo(BD);
|
|
|
|
|
BoxData = BD;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public bool SetBoxBinary(byte[] data, int box)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2017-09-29 05:20:27 +00:00
|
|
|
|
int start = box * BoxSlotCount;
|
|
|
|
|
int end = start + BoxSlotCount;
|
|
|
|
|
if (LockedSlots.Any(slot => start <= slot && slot < end))
|
2016-12-16 07:17:17 +00:00
|
|
|
|
return false;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
if (data.Length != GetBoxBinary(box).Length)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2017-09-29 05:20:27 +00:00
|
|
|
|
var BD = BoxData;
|
|
|
|
|
var pkdata = PKX.GetPKMDataFromConcatenatedBinary(data, BlankPKM.EncryptedBoxData.Length);
|
|
|
|
|
pkdata.Select(z => GetPKM(DecryptPKM(z))).CopyTo(BD, start);
|
|
|
|
|
BoxData = BD;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-26 02:05:49 +00:00
|
|
|
|
protected virtual void SetPartyValues(PKM pkm, bool isParty)
|
|
|
|
|
{
|
|
|
|
|
if (!isParty)
|
|
|
|
|
return;
|
|
|
|
|
if (pkm.Stat_HPMax != 0) // Stats already present
|
|
|
|
|
return;
|
|
|
|
|
pkm.SetStats(pkm.GetStats(pkm.PersonalInfo));
|
|
|
|
|
pkm.Stat_Level = pkm.CurrentLevel;
|
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
protected virtual void SetPKM(PKM pkm) { }
|
|
|
|
|
protected virtual void SetDex(PKM pkm) { }
|
|
|
|
|
public virtual bool GetSeen(int species) => false;
|
|
|
|
|
public virtual void SetSeen(int species, bool seen) { }
|
|
|
|
|
public virtual bool GetCaught(int species) => false;
|
|
|
|
|
public virtual void SetCaught(int species, bool caught) { }
|
2017-10-31 16:24:54 +00:00
|
|
|
|
public int SeenCount => HasPokeDex ? Enumerable.Range(1, MaxSpeciesID).Count(GetSeen) : 0;
|
|
|
|
|
public int CaughtCount => HasPokeDex ? Enumerable.Range(1, MaxSpeciesID).Count(GetCaught) : 0;
|
|
|
|
|
public decimal PercentSeen => (decimal) SeenCount / MaxSpeciesID;
|
|
|
|
|
public decimal PercentCaught => (decimal)CaughtCount / MaxSpeciesID;
|
2017-06-18 01:37:19 +00:00
|
|
|
|
|
|
|
|
|
public byte[] GetData(int Offset, int Length)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
2016-08-20 06:36:13 +00:00
|
|
|
|
byte[] data = new byte[Length];
|
2017-09-29 05:20:27 +00:00
|
|
|
|
Buffer.BlockCopy(Data, Offset, data, 0, Length);
|
2016-08-20 06:36:13 +00:00
|
|
|
|
return data;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public void SetData(byte[] input, int Offset)
|
2016-06-20 04:22:43 +00:00
|
|
|
|
{
|
|
|
|
|
input.CopyTo(Data, Offset);
|
|
|
|
|
Edited = true;
|
|
|
|
|
}
|
2017-12-17 02:29:10 +00:00
|
|
|
|
public bool IsRangeEmpty(int Offset, int Length)
|
|
|
|
|
{
|
|
|
|
|
for (int i = Offset; i < Offset + Length; i++)
|
|
|
|
|
if (Data[i] != 0)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2018-03-18 23:22:21 +00:00
|
|
|
|
public virtual bool IsPKMPresent(int Offset) => PKX.IsPKMPresent(Data, Offset);
|
2016-11-12 15:30:51 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public abstract string GetString(int Offset, int Length);
|
|
|
|
|
public abstract byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public virtual string EBerryName => string.Empty;
|
|
|
|
|
public virtual bool IsEBerryIsEnigma => true;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|