2019-09-23 23:56:47 +00:00
|
|
|
|
using System;
|
2020-08-18 22:39:45 +00:00
|
|
|
|
using System.Collections.Generic;
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Generation 8 <see cref="SaveFile"/> object.
|
|
|
|
|
/// </summary>
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public abstract class SAV8 : SaveFile, ISaveBlock8Main
|
2019-09-23 23:56:47 +00:00
|
|
|
|
{
|
|
|
|
|
// Save Data Attributes
|
2020-12-05 13:36:23 +00:00
|
|
|
|
protected internal override string ShortSummary => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public override string Extension => string.Empty;
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2021-08-06 05:39:38 +00:00
|
|
|
|
public override IReadOnlyList<string> PKMExtensions => Array.FindAll(PKM.Extensions, f =>
|
2019-09-23 23:56:47 +00:00
|
|
|
|
{
|
2021-07-27 06:33:56 +00:00
|
|
|
|
int gen = f[^1] - 0x30;
|
2021-06-04 20:16:00 +00:00
|
|
|
|
return gen <= 8;
|
2021-08-06 05:39:38 +00:00
|
|
|
|
});
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2019-11-16 01:34:18 +00:00
|
|
|
|
protected SAV8(byte[] data) : base(data) { }
|
|
|
|
|
protected SAV8() { }
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
|
|
|
|
// Configuration
|
2020-08-07 23:16:10 +00:00
|
|
|
|
protected override int SIZE_STORED => PokeCrypto.SIZE_8STORED;
|
2020-01-04 22:48:39 +00:00
|
|
|
|
protected override int SIZE_PARTY => PokeCrypto.SIZE_8PARTY;
|
2020-08-07 23:16:10 +00:00
|
|
|
|
public override int SIZE_BOXSLOT => PokeCrypto.SIZE_8PARTY;
|
2019-09-23 23:56:47 +00:00
|
|
|
|
public override PKM BlankPKM => new PK8();
|
|
|
|
|
public override Type PKMType => typeof(PK8);
|
|
|
|
|
|
|
|
|
|
public override int BoxCount => BoxLayout8.BoxCount;
|
|
|
|
|
public override int MaxEV => 252;
|
|
|
|
|
public override int Generation => 8;
|
|
|
|
|
// protected override int GiftCountMax => 48;
|
|
|
|
|
// protected override int GiftFlagMax => 0x100 * 8;
|
|
|
|
|
protected override int EventConstMax => 1000;
|
|
|
|
|
public override int OTLength => 12;
|
|
|
|
|
public override int NickLength => 12;
|
|
|
|
|
protected override PKM GetPKM(byte[] data) => new PK8(data);
|
2020-01-04 22:48:39 +00:00
|
|
|
|
protected override byte[] DecryptPKM(byte[] data) => PokeCrypto.DecryptArray8(data);
|
2019-09-23 23:56: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
|
|
|
|
#region Blocks
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public abstract Box8 BoxInfo { get; }
|
|
|
|
|
public abstract Party8 PartyInfo { get; }
|
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 PlayTime8 Played { get; }
|
|
|
|
|
public abstract MyStatus8 MyStatus { get; }
|
2019-10-19 03:42:03 +00:00
|
|
|
|
public abstract Misc8 Misc { get; }
|
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 Zukan8 Zukan { get; }
|
|
|
|
|
public abstract BoxLayout8 BoxLayout { get; }
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public abstract Fused8 Fused { get; }
|
|
|
|
|
public abstract Daycare8 Daycare { get; }
|
|
|
|
|
public abstract Record8 Records { get; }
|
2019-11-19 01:57:33 +00:00
|
|
|
|
public abstract TrainerCard8 TrainerCard { get; }
|
2020-01-22 07:23:27 +00:00
|
|
|
|
public abstract RaidSpawnList8 Raid { get; }
|
2020-06-19 23:51:15 +00:00
|
|
|
|
public abstract RaidSpawnList8 RaidArmor { get; }
|
2020-10-24 18:09:29 +00:00
|
|
|
|
public abstract RaidSpawnList8 RaidCrown { get; }
|
2020-01-22 07:23:27 +00:00
|
|
|
|
public abstract TitleScreen8 TitleScreen { get; }
|
2020-02-02 02:56:23 +00:00
|
|
|
|
public abstract TeamIndexes8 TeamIndexes { get; }
|
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
|
|
|
|
#endregion
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2021-01-02 01:08:49 +00:00
|
|
|
|
public override GameVersion Version => Game switch
|
2019-09-23 23:56:47 +00:00
|
|
|
|
{
|
2021-01-02 01:08:49 +00:00
|
|
|
|
(int)GameVersion.SW => GameVersion.SW,
|
|
|
|
|
(int)GameVersion.SH => GameVersion.SH,
|
|
|
|
|
_ => GameVersion.Invalid
|
|
|
|
|
};
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2021-04-19 01:29:02 +00:00
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString7b(data, offset, length);
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
|
|
|
|
{
|
|
|
|
|
if (PadToSize == 0)
|
|
|
|
|
PadToSize = maxLength + 1;
|
2021-04-19 01:29:02 +00:00
|
|
|
|
return StringConverter.SetString7b(value, maxLength, PadToSize, PadWith);
|
2019-09-23 23:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Player Information
|
|
|
|
|
public override int TID { get => MyStatus.TID; set => MyStatus.TID = value; }
|
|
|
|
|
public override int SID { get => MyStatus.SID; set => MyStatus.SID = value; }
|
|
|
|
|
public override int Game { get => MyStatus.Game; set => MyStatus.Game = value; }
|
|
|
|
|
public override int Gender { get => MyStatus.Gender; set => MyStatus.Gender = value; }
|
|
|
|
|
public override int Language { get => MyStatus.Language; set => MyStatus.Language = value; }
|
|
|
|
|
public override string OT { get => MyStatus.OT; set => MyStatus.OT = value; }
|
2019-10-19 03:42:03 +00:00
|
|
|
|
public override uint Money { get => Misc.Money; set => Misc.Money = value; }
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public int Badges { get => Misc.Badges; set => Misc.Badges = value; }
|
2019-09-23 23:56:47 +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; }
|
|
|
|
|
|
|
|
|
|
// Inventory
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
|
|
|
|
// Storage
|
|
|
|
|
public override int GetPartyOffset(int slot) => Party + (SIZE_PARTY * slot);
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public override int GetBoxOffset(int box) => Box + (SIZE_PARTY * box * 30);
|
2019-09-23 23:56:47 +00:00
|
|
|
|
public override string GetBoxName(int box) => BoxLayout[box];
|
|
|
|
|
public override void SetBoxName(int box, string value) => BoxLayout[box] = value;
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public override byte[] GetDataForBox(PKM pkm) => pkm.EncryptedPartyData;
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
2021-02-09 04:26:53 +00:00
|
|
|
|
protected override void SetPKM(PKM pkm, bool isParty = false)
|
2019-09-23 23:56:47 +00:00
|
|
|
|
{
|
|
|
|
|
PK8 pk = (PK8)pkm;
|
|
|
|
|
// Apply to this Save File
|
|
|
|
|
DateTime Date = DateTime.Now;
|
|
|
|
|
pk.Trade(this, Date.Day, Date.Month, Date.Year);
|
2021-02-09 04:26:53 +00:00
|
|
|
|
|
2021-02-09 04:42:19 +00:00
|
|
|
|
if (FormArgumentUtil.IsFormArgumentTypeDatePair(pk.Species, pk.Form))
|
2021-02-09 04:26:53 +00:00
|
|
|
|
{
|
|
|
|
|
pk.FormArgumentElapsed = pk.FormArgumentMaximum = 0;
|
|
|
|
|
pk.FormArgumentRemain = (byte)GetFormArgument(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 23:56:47 +00:00
|
|
|
|
pkm.RefreshChecksum();
|
|
|
|
|
AddCountAcquired(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-09 04:26:53 +00:00
|
|
|
|
private static uint GetFormArgument(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
if (pkm.Form == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
return pkm.Species switch
|
|
|
|
|
{
|
|
|
|
|
(int)Species.Furfrou => 5u, // Furfrou
|
|
|
|
|
(int)Species.Hoopa => 3u, // Hoopa
|
|
|
|
|
_ => 0u
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-23 23:56:47 +00:00
|
|
|
|
private void AddCountAcquired(PKM pkm)
|
|
|
|
|
{
|
2020-02-06 03:42:46 +00:00
|
|
|
|
if (pkm.WasEgg)
|
|
|
|
|
{
|
|
|
|
|
Records.AddRecord(00);
|
|
|
|
|
}
|
|
|
|
|
else // capture, assume wild
|
|
|
|
|
{
|
|
|
|
|
Records.AddRecord(01); // wild capture
|
|
|
|
|
Records.AddRecord(06); // total captured
|
|
|
|
|
Records.AddRecord(16); // wild encountered
|
2021-02-24 16:12:59 +00:00
|
|
|
|
Records.AddRecord(23); // total battled
|
2020-02-06 03:42:46 +00:00
|
|
|
|
}
|
|
|
|
|
if (pkm.CurrentHandler == 1)
|
|
|
|
|
Records.AddRecord(17, 2); // trade * 2 -- these games count 1 trade as 2 for some reason.
|
2019-09-23 23:56:47 +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);
|
|
|
|
|
|
|
|
|
|
public override int PartyCount
|
|
|
|
|
{
|
2019-11-16 01:34:18 +00:00
|
|
|
|
get => PartyInfo.PartyCount;
|
|
|
|
|
protected set => PartyInfo.PartyCount = value;
|
2019-09-23 23:56:47 +00:00
|
|
|
|
}
|
2019-11-16 01:34:18 +00:00
|
|
|
|
|
|
|
|
|
protected override byte[] BoxBuffer => BoxInfo.Data;
|
|
|
|
|
protected override byte[] PartyBuffer => PartyInfo.Data;
|
|
|
|
|
public override PKM GetDecryptedPKM(byte[] data) => GetPKM(DecryptPKM(data));
|
|
|
|
|
public override PKM GetBoxSlot(int offset) => GetDecryptedPKM(GetData(BoxInfo.Data, offset, SIZE_PARTY)); // party format in boxes!
|
2019-09-23 23:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|