2019-09-23 23:56:47 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
protected override string BAKText => $"{OT} ({Version}) - {Played.LastSavedTime}";
|
2019-11-16 01:34:18 +00:00
|
|
|
|
public override string Filter => "Main SAV|*.*";
|
|
|
|
|
public override string Extension => string.Empty;
|
2019-09-23 23:56:47 +00:00
|
|
|
|
|
|
|
|
|
public override string[] PKMExtensions => PKM.Extensions.Where(f =>
|
|
|
|
|
{
|
|
|
|
|
int gen = f.Last() - 0x30;
|
|
|
|
|
return gen == 8; // future: change to <= when HOME released
|
|
|
|
|
}).ToArray();
|
|
|
|
|
|
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-01-04 22:48:39 +00:00
|
|
|
|
public override int SIZE_STORED => PokeCrypto.SIZE_8STORED;
|
|
|
|
|
protected override int SIZE_PARTY => 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; }
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
public override GameVersion Version
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var game = (GameVersion)Game;
|
|
|
|
|
if (game == GameVersion.SW || game == GameVersion.SH)
|
|
|
|
|
return game;
|
|
|
|
|
return GameVersion.Invalid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetString(byte[] data, int offset, int length) => StringConverter.GetString7(data, offset, length);
|
|
|
|
|
|
|
|
|
|
public override byte[] SetString(string value, int maxLength, int PadToSize = 0, ushort PadWith = 0)
|
|
|
|
|
{
|
|
|
|
|
if (PadToSize == 0)
|
|
|
|
|
PadToSize = maxLength + 1;
|
|
|
|
|
return StringConverter.SetString7(value, maxLength, Language, PadToSize, PadWith);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
public override InventoryPouch[] Inventory { get => Items.Inventory; set => Items.Inventory = value; }
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
|
protected override void SetPKM(PKM pkm)
|
|
|
|
|
{
|
|
|
|
|
PK8 pk = (PK8)pkm;
|
|
|
|
|
// Apply to this Save File
|
|
|
|
|
DateTime Date = DateTime.Now;
|
|
|
|
|
pk.Trade(this, Date.Day, Date.Month, Date.Year);
|
|
|
|
|
pkm.RefreshChecksum();
|
|
|
|
|
AddCountAcquired(pkm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
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 int GetBoxSlotOffset(int box, int slot) => GetBoxOffset(box) + (slot * SIZE_PARTY); // party format in boxes!
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
}
|