2015-10-22 07:16:44 +00:00
|
|
|
|
using System;
|
2020-12-05 14:09:33 +00:00
|
|
|
|
using System.Collections.Generic;
|
2015-10-22 07:16:44 +00:00
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2015-10-22 07:16:44 +00:00
|
|
|
|
{
|
2017-10-24 06:12:58 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 6 <see cref="SaveFile"/> object.
|
|
|
|
|
/// </summary>
|
2020-10-31 18:43:57 +00:00
|
|
|
|
public abstract class SAV6 : SAV_BEEF, ITrainerStatRecord, ISaveBlock6Core, IRegionOrigin, IGameSync
|
2015-10-22 07:16:44 +00:00
|
|
|
|
{
|
|
|
|
|
// Save Data Attributes
|
2020-12-05 13:36:23 +00:00
|
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
2019-02-08 05:40:20 +00:00
|
|
|
|
public override string Extension => string.Empty;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
protected SAV6(byte[] data, int biOffset) : base(data, biOffset) { }
|
|
|
|
|
protected SAV6(int size, int biOffset) : base(size, biOffset) { }
|
2015-10-22 07:16:44 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Configuration
|
2020-08-07 23:16:10 +00:00
|
|
|
|
protected override int SIZE_STORED => PokeCrypto.SIZE_6STORED;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
protected override int SIZE_PARTY => PokeCrypto.SIZE_6PARTY;
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override PKM BlankPKM => new PK6();
|
2016-09-26 23:14:11 +00:00
|
|
|
|
public override Type PKMType => typeof(PK6);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
|
|
|
|
public override int BoxCount => 31;
|
|
|
|
|
public override int MaxEV => 252;
|
|
|
|
|
public override int Generation => 6;
|
|
|
|
|
protected override int GiftCountMax => 24;
|
|
|
|
|
protected override int GiftFlagMax => 0x100 * 8;
|
2021-02-13 04:08:54 +00:00
|
|
|
|
protected override int EventFlagMax => 8 * 0x1A0;
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected override int EventConstMax => (EventFlag - EventConst) / sizeof(ushort);
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int OTLength => 12;
|
|
|
|
|
public override int NickLength => 12;
|
|
|
|
|
|
2016-10-24 04:59:27 +00:00
|
|
|
|
public override int MaxSpeciesID => Legal.MaxSpeciesID_6;
|
2017-01-27 03:18:20 +00:00
|
|
|
|
public override int MaxBallID => Legal.MaxBallID_6;
|
|
|
|
|
public override int MaxGameID => Legal.MaxGameID_6; // OR
|
2016-06-21 01:58:06 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected override PKM GetPKM(byte[] data) => new PK6(data);
|
2020-01-04 22:48:39 +00:00
|
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray6(data);
|
2019-01-01 08:57:51 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected int WondercardFlags { get; set; } = int.MinValue;
|
|
|
|
|
protected int JPEG { get; set; } = int.MinValue;
|
2019-07-06 05:02:29 +00:00
|
|
|
|
public int PSS { get; protected set; } = int.MinValue;
|
|
|
|
|
public int BerryField { get; protected set; } = int.MinValue;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
public int HoF { get; protected set; } = int.MinValue;
|
|
|
|
|
protected int PCLayout { private get; set; } = int.MinValue;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
protected int BattleBoxOffset { get; set; } = int.MinValue;
|
|
|
|
|
public int GetBattleBoxSlot(int slot) => BattleBoxOffset + (slot * SIZE_STORED);
|
2019-07-06 05:02:29 +00:00
|
|
|
|
|
|
|
|
|
public virtual string JPEGTitle => string.Empty;
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public virtual byte[] GetJPEGData() => Array.Empty<byte>();
|
2016-06-20 04:22:43 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
protected internal const int LongStringLength = 0x22; // bytes, not characters
|
|
|
|
|
protected internal const int ShortStringLength = 0x1A; // bytes, not characters
|
2018-05-12 15:13:39 +00:00
|
|
|
|
|
2015-10-22 07:16:44 +00:00
|
|
|
|
// Player Information
|
2019-06-09 02:56:11 +00:00
|
|
|
|
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; }
|
|
|
|
|
public override int Language { get => Status.Language; set => Status.Language = value; }
|
|
|
|
|
public override string OT { get => Status.OT; set => Status.OT = value; }
|
2020-07-31 20:53:42 +00:00
|
|
|
|
public int Region { get => Status.SubRegion; set => Status.SubRegion = value; }
|
|
|
|
|
public int Country { get => Status.Country; set => Status.Country = value; }
|
|
|
|
|
public int ConsoleRegion { get => Status.ConsoleRegion; set => Status.ConsoleRegion = value; }
|
2020-10-31 18:43:57 +00:00
|
|
|
|
public int GameSyncIDSize => MyStatus6.GameSyncIDSize; // 64 bits
|
|
|
|
|
public string GameSyncID { get => Status.GameSyncID; set => Status.GameSyncID = value; }
|
2019-06-09 02:56:11 +00:00
|
|
|
|
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; }
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
public abstract int Badges { get; set; }
|
|
|
|
|
public abstract int Vivillon { get; set; }
|
|
|
|
|
public abstract int BP { get; set; }
|
|
|
|
|
// Money
|
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public override uint SecondsToStart { get => GameTime.SecondsToStart; set => GameTime.SecondsToStart = value; }
|
|
|
|
|
public override uint SecondsToFame { get => GameTime.SecondsToFame; set => GameTime.SecondsToFame = value; }
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
2015-10-22 07:16:44 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Daycare
|
|
|
|
|
public override int DaycareSeedSize => 16;
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
// Storage
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
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);
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-01-02 04:05:36 +00:00
|
|
|
|
private int GetBoxNameOffset(int box) => PCLayout + (LongStringLength * box);
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public override string GetBoxName(int box)
|
2015-10-22 07:16:44 +00:00
|
|
|
|
{
|
2016-06-20 04:22:43 +00:00
|
|
|
|
if (PCLayout < 0)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
return $"B{box + 1}";
|
2019-11-18 04:41:40 +00:00
|
|
|
|
return GetString(Data, GetBoxNameOffset(box), LongStringLength);
|
2015-10-22 07:16:44 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-05-12 15:13:39 +00:00
|
|
|
|
public override void SetBoxName(int box, string value)
|
2015-10-22 07:16:44 +00:00
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
var data = SetString(value, LongStringLength / 2, LongStringLength / 2);
|
|
|
|
|
SetData(data, PCLayout + (LongStringLength * box));
|
2016-01-24 18:19:30 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2021-02-09 04:26:53 +00:00
|
|
|
|
protected override void SetPKM(PKM pkm, bool isParty = false)
|
2015-10-24 18:29:03 +00:00
|
|
|
|
{
|
2017-12-12 00:01:24 +00:00
|
|
|
|
PK6 pk6 = (PK6)pkm;
|
2015-10-24 18:29:03 +00:00
|
|
|
|
// Apply to this Save File
|
2015-10-24 18:57:07 +00:00
|
|
|
|
int CT = pk6.CurrentHandler;
|
2015-10-24 18:29:03 +00:00
|
|
|
|
DateTime Date = DateTime.Now;
|
2019-03-31 05:05:28 +00:00
|
|
|
|
pk6.Trade(this, Date.Day, Date.Month, Date.Year);
|
2015-10-24 18:57:07 +00:00
|
|
|
|
if (CT != pk6.CurrentHandler) // Logic updated Friendship
|
|
|
|
|
{
|
2015-10-26 01:46:17 +00:00
|
|
|
|
// Copy over the Friendship Value only under certain circumstances
|
2020-08-18 22:39:45 +00:00
|
|
|
|
if (pk6.HasMove(216)) // Return
|
2015-10-26 01:46:17 +00:00
|
|
|
|
pk6.CurrentFriendship = pk6.OppositeFriendship;
|
2020-08-18 22:39:45 +00:00
|
|
|
|
else if (pk6.HasMove(218)) // Frustration
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pkm.CurrentFriendship = pk6.OppositeFriendship;
|
2015-10-24 18:57:07 +00:00
|
|
|
|
}
|
2021-02-09 04:26:53 +00:00
|
|
|
|
|
|
|
|
|
pk6.FormArgumentElapsed = pk6.FormArgumentMaximum = 0;
|
|
|
|
|
pk6.FormArgumentRemain = (byte)GetFormArgument(pkm, isParty);
|
|
|
|
|
if (!isParty && pkm.Form != 0)
|
|
|
|
|
{
|
|
|
|
|
switch (pkm.Species)
|
|
|
|
|
{
|
|
|
|
|
case (int) Species.Furfrou:
|
|
|
|
|
pkm.Form = 0;
|
|
|
|
|
break;
|
|
|
|
|
case (int) Species.Hoopa:
|
|
|
|
|
{
|
|
|
|
|
pkm.Form = 0;
|
|
|
|
|
var hsf = Array.IndexOf(pkm.Moves, (int) Move.HyperspaceFury);
|
|
|
|
|
if (hsf != -1)
|
|
|
|
|
pkm.SetMove(hsf, (int) Move.HyperspaceHole);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
pkm.RefreshChecksum();
|
2019-06-09 02:56:11 +00:00
|
|
|
|
AddCountAcquired(pkm);
|
2018-09-28 04:30:20 +00:00
|
|
|
|
}
|
2018-09-27 02:06:05 +00:00
|
|
|
|
|
2018-09-28 04:30:20 +00:00
|
|
|
|
private void AddCountAcquired(PKM pkm)
|
|
|
|
|
{
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Records.AddRecord(pkm.WasEgg ? 009 : 007); // egg, capture
|
2018-09-27 02:06:05 +00:00
|
|
|
|
if (pkm.CurrentHandler == 1)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Records.AddRecord(012); // trade
|
2018-11-27 16:53:56 +00:00
|
|
|
|
if (!pkm.WasEgg)
|
2019-06-09 02:56:11 +00:00
|
|
|
|
Records.AddRecord(005); // wild encounters
|
2015-10-22 07:16:44 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2019-11-29 18:44:52 +00:00
|
|
|
|
private static uint GetFormArgument(PKM pkm, bool isParty)
|
2018-07-21 03:25:28 +00:00
|
|
|
|
{
|
2020-12-11 04:42:30 +00:00
|
|
|
|
if (!isParty || pkm.Form == 0)
|
2018-07-21 03:25:28 +00:00
|
|
|
|
return 0;
|
2019-10-08 01:40:09 +00:00
|
|
|
|
return pkm.Species switch
|
2018-07-21 03:25:28 +00:00
|
|
|
|
{
|
2019-10-08 01:40:09 +00:00
|
|
|
|
(int)Species.Furfrou => 5u, // Furfrou
|
|
|
|
|
(int)Species.Hoopa => 3u, // Hoopa
|
|
|
|
|
_ => 0u
|
|
|
|
|
};
|
2017-06-07 05:13:12 +00:00
|
|
|
|
}
|
2017-03-15 05:41:15 +00:00
|
|
|
|
|
2016-06-20 04:22:43 +00:00
|
|
|
|
public override int PartyCount
|
2015-11-16 05:58:34 +00:00
|
|
|
|
{
|
2018-09-15 05:37:47 +00:00
|
|
|
|
get => Data[Party + (6 * SIZE_PARTY)];
|
|
|
|
|
protected set => Data[Party + (6 * SIZE_PARTY)] = (byte)value;
|
2015-11-16 05:58:34 +00:00
|
|
|
|
}
|
2018-09-15 05:37:47 +00:00
|
|
|
|
|
2018-12-05 06:00:57 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString6(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.SetString6(value, maxLength, PadToSize, PadWith);
|
2017-04-09 21:06:50 +00:00
|
|
|
|
}
|
2018-06-09 19:32:55 +00:00
|
|
|
|
|
2019-06-09 02:56:11 +00:00
|
|
|
|
public int GetRecord(int recordID) => Records.GetRecord(recordID);
|
|
|
|
|
public int GetRecordOffset(int recordID) => Records.GetRecordOffset(recordID);
|
|
|
|
|
public int GetRecordMax(int recordID) => Records.GetRecordMax(recordID);
|
|
|
|
|
public void SetRecord(int recordID, int value) => Records.SetRecord(recordID, value);
|
2019-10-19 03:42:03 +00:00
|
|
|
|
public int RecordCount => RecordBlock6.RecordCount;
|
PKHeX.Core Nullable cleanup (#2401)
* Handle some nullable cases
Refactor MysteryGift into a second abstract class (backed by a byte array, or fake data)
Make some classes have explicit constructors instead of { } initialization
* Handle bits more obviously without null
* Make SaveFile.BAK explicitly readonly again
* merge constructor methods to have readonly fields
* Inline some properties
* More nullable handling
* Rearrange box actions
define straightforward classes to not have any null properties
* Make extrabyte reference array immutable
* Move tooltip creation to designer
* Rearrange some logic to reduce nesting
* Cache generated fonts
* Split mystery gift album purpose
* Handle more tooltips
* Disallow null setters
* Don't capture RNG object, only type enum
* Unify learnset objects
Now have readonly properties which are never null
don't new() empty learnsets (>800 Learnset objects no longer created,
total of 2400 objects since we also new() a move & level array)
optimize g1/2 reader for early abort case
* Access rewrite
Initialize blocks in a separate object, and get via that object
removes a couple hundred "might be null" warnings since blocks are now readonly getters
some block references have been relocated, but interfaces should expose all that's needed
put HoF6 controls in a groupbox, and disable
* Readonly personal data
* IVs non nullable for mystery gift
* Explicitly initialize forced encounter moves
* Make shadow objects readonly & non-null
Put murkrow fix in binary data resource, instead of on startup
* Assign dex form fetch on constructor
Fixes legality parsing edge cases
also handle cxd parse for valid; exit before exception is thrown in FrameGenerator
* Remove unnecessary null checks
* Keep empty value until init
SetPouch sets the value to an actual one during load, but whatever
* Readonly team lock data
* Readonly locks
Put locked encounters at bottom (favor unlocked)
* Mail readonly data / offset
Rearrange some call flow and pass defaults
Add fake classes for SaveDataEditor mocking
Always party size, no need to check twice in stat editor
use a fake save file as initial data for savedata editor, and for
gamedata (wow i found a usage)
constrain eventwork editor to struct variable types (uint, int, etc),
thus preventing null assignment errors
2019-10-17 01:47:31 +00:00
|
|
|
|
public abstract MyItem Items { get; }
|
|
|
|
|
public abstract ItemInfo6 ItemInfo { get; }
|
|
|
|
|
public abstract GameTime6 GameTime { get; }
|
|
|
|
|
public abstract Situation6 Situation { get; }
|
|
|
|
|
public abstract PlayTime6 Played { get; }
|
|
|
|
|
public abstract MyStatus6 Status { get; }
|
2019-10-19 03:42:03 +00:00
|
|
|
|
public abstract RecordBlock6 Records { get; }
|
2015-10-22 07:16:44 +00:00
|
|
|
|
}
|
2019-06-09 02:56:11 +00:00
|
|
|
|
}
|