2022-06-19 02:46:53 +00:00
|
|
|
using System;
|
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
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <see cref="SaveFile"/> format for <see cref="GameVersion.DP"/>
|
|
|
|
/// </summary>
|
|
|
|
public sealed class SAV4DP : SAV4Sinnoh
|
2019-09-03 02:30:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV4DP() : base(GeneralSize, StorageSize)
|
2019-09-03 02:30:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
Initialize();
|
|
|
|
Dex = new Zukan4(this, PokeDex);
|
|
|
|
}
|
2021-05-18 20:33:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV4DP(byte[] data) : base(data, GeneralSize, StorageSize, GeneralSize)
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
Dex = new Zukan4(this, PokeDex);
|
|
|
|
}
|
2021-05-18 20:33:13 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override Zukan4 Dex { get; }
|
2021-02-21 17:59:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override SAV4 CloneInternal4() => State.Exportable ? new SAV4DP((byte[])Data.Clone()) : new SAV4DP();
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalTable4 Personal => PersonalTable.DP;
|
2023-03-26 00:55:55 +00:00
|
|
|
public override ReadOnlySpan<ushort> HeldItems => Legal.HeldItems_DP;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxItemID => Legal.MaxItemID_4_DP;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-11-10 06:02:23 +00:00
|
|
|
public const int GeneralSize = 0xC100;
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int StorageSize = 0x121E0; // Start 0xC100, +4 starts box data
|
2023-12-04 04:13:20 +00:00
|
|
|
|
|
|
|
protected override BlockInfo4[] ExtraBlocks =>
|
|
|
|
[
|
2023-11-09 07:33:40 +00:00
|
|
|
new BlockInfo4(0, 0x20000, 0x2AC0), // Hall of Fame
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Initialize()
|
|
|
|
{
|
|
|
|
Version = GameVersion.DP;
|
|
|
|
GetSAVOffsets();
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int EventWork => 0xD9C;
|
|
|
|
protected override int EventFlag => 0xFDC;
|
2022-04-10 01:12:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void GetSAVOffsets()
|
|
|
|
{
|
|
|
|
AdventureInfo = 0;
|
|
|
|
Trainer1 = 0x64;
|
|
|
|
Party = 0x98;
|
|
|
|
PokeDex = 0x12DC;
|
2023-12-19 04:24:24 +00:00
|
|
|
ChatterOffset = 0x61CC;
|
2023-06-11 16:38:24 +00:00
|
|
|
Geonet = 0x96D8;
|
2022-06-18 18:04:24 +00:00
|
|
|
WondercardFlags = 0xA6D0;
|
|
|
|
WondercardData = 0xA7fC;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DaycareOffset = 0x141C;
|
|
|
|
OFS_HONEY = 0x72E4;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
OFS_UG_Stats = 0x3A2C;
|
|
|
|
OFS_UG_Items = 0x42B0;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PoketchStart = 0x114C;
|
|
|
|
Seal = 0x6178;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
OFS_PoffinCase = 0x5050;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Box = 4;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region Storage
|
|
|
|
public override int GetBoxWallpaper(int box)
|
|
|
|
{
|
|
|
|
if ((uint)box >= 18)
|
|
|
|
return 0;
|
|
|
|
return Storage[GetBoxWallpaperOffset(box)];
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void SetBoxWallpaper(int box, int value)
|
|
|
|
{
|
|
|
|
if ((uint)box >= 18)
|
|
|
|
return;
|
|
|
|
Storage[GetBoxWallpaperOffset(box)] = (byte)value;
|
|
|
|
}
|
|
|
|
#endregion
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override IReadOnlyList<InventoryPouch> Inventory
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2023-04-16 19:58:07 +00:00
|
|
|
var info = ItemStorage4DP.Instance;
|
2022-06-18 18:04:24 +00:00
|
|
|
InventoryPouch[] pouch =
|
2023-12-04 04:13:20 +00:00
|
|
|
[
|
2023-04-16 19:58:07 +00:00
|
|
|
new InventoryPouch4(InventoryType.Items, info, 999, 0x624),
|
|
|
|
new InventoryPouch4(InventoryType.KeyItems, info, 1, 0x8B8),
|
|
|
|
new InventoryPouch4(InventoryType.TMHMs, info, 99, 0x980),
|
|
|
|
new InventoryPouch4(InventoryType.MailItems, info, 999, 0xB10),
|
|
|
|
new InventoryPouch4(InventoryType.Medicine, info, 999, 0xB40),
|
|
|
|
new InventoryPouch4(InventoryType.Berries, info, 999, 0xBE0),
|
|
|
|
new InventoryPouch4(InventoryType.Balls, info, 999, 0xCE0),
|
|
|
|
new InventoryPouch4(InventoryType.BattleItems, info, 999, 0xD1C),
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2022-06-18 18:04:24 +00:00
|
|
|
return pouch.LoadAll(General);
|
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
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
set => value.SaveAll(General);
|
|
|
|
}
|
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
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// reverse crc32 polynomial, nice!
|
|
|
|
private const uint MysteryGiftDPSlotActive = 0xEDB88320;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public bool[] GetMysteryGiftDPSlotActiveFlags()
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
var span = General[(WondercardFlags + 0x100)..]; // skip over flags
|
2022-06-18 18:04:24 +00:00
|
|
|
bool[] active = new bool[GiftCountMax]; // 8 PGT, 3 PCD
|
|
|
|
for (int i = 0; i < active.Length; i++)
|
|
|
|
active[i] = ReadUInt32LittleEndian(span[(4*i)..]) == MysteryGiftDPSlotActive;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
return active;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
Refactoring: Move Source (Legality) (#3560)
Rewrites a good amount of legality APIs pertaining to:
* Legal moves that can be learned
* Evolution chains & cross-generation paths
* Memory validation with forgotten moves
In generation 8, there are 3 separate contexts an entity can exist in: SW/SH, BD/SP, and LA. Not every entity can cross between them, and not every entity from generation 7 can exist in generation 8 (Gogoat, etc). By creating class models representing the restrictions to cross each boundary, we are able to better track and validate data.
The old implementation of validating moves was greedy: it would iterate for all generations and evolutions, and build a full list of every move that can be learned, storing it on the heap. Now, we check one game group at a time to see if the entity can learn a move that hasn't yet been validated. End result is an algorithm that requires 0 allocation, and a smaller/quicker search space.
The old implementation of storing move parses was inefficient; for each move that was parsed, a new object is created and adjusted depending on the parse. Now, move parse results are `struct` and store the move parse contiguously in memory. End result is faster parsing and 0 memory allocation.
* `PersonalTable` objects have been improved with new API methods to check if a species+form can exist in the game.
* `IEncounterTemplate` objects have been improved to indicate the `EntityContext` they originate in (similar to `Generation`).
* Some APIs have been extended to accept `Span<T>` instead of Array/IEnumerable
2022-08-03 23:15:27 +00:00
|
|
|
public void SetMysteryGiftDPSlotActiveFlags(ReadOnlySpan<bool> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
if (value.Length != GiftCountMax)
|
|
|
|
return;
|
2020-05-26 23:59:47 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
var span = General[(WondercardFlags + 0x100)..]; // skip over flags
|
2022-06-18 18:04:24 +00:00
|
|
|
for (int i = 0; i < value.Length; i++)
|
|
|
|
WriteUInt32LittleEndian(span[(4 * i)..], value[i] ? MysteryGiftDPSlotActive : 0);
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override MysteryGiftAlbum GiftAlbum
|
|
|
|
{
|
|
|
|
get => base.GiftAlbum;
|
|
|
|
set
|
2019-09-03 02:30:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
base.GiftAlbum = value;
|
|
|
|
SetActiveGiftFlags(value.Gifts);
|
2019-09-03 02:30:58 +00:00
|
|
|
}
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void SetActiveGiftFlags(IReadOnlyList<MysteryGift> gifts)
|
|
|
|
{
|
|
|
|
var arr = new bool[gifts.Count];
|
|
|
|
for (int i = 0; i < arr.Length; i++)
|
|
|
|
arr[i] = !gifts[i].Empty;
|
|
|
|
SetMysteryGiftDPSlotActiveFlags(arr);
|
|
|
|
}
|
2021-05-18 20:04:23 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public override int M { get => ReadUInt16LittleEndian(General[0x1238..]); set => WriteUInt16LittleEndian(General[0x1238..], (ushort)value); }
|
|
|
|
public override int X { get => ReadUInt16LittleEndian(General[0x1240..]); set => WriteUInt16LittleEndian(General[0x1240..], (ushort)(X2 = value)); }
|
|
|
|
public override int Y { get => ReadUInt16LittleEndian(General[0x1244..]); set => WriteUInt16LittleEndian(General[0x1244..], (ushort)(Y2 = value)); }
|
2021-10-10 23:11:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override Span<byte> Rival_Trash
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => General.Slice(0x25A8, MaxStringLengthOT * 2);
|
|
|
|
set { if (value.Length == MaxStringLengthOT * 2) value.CopyTo(General[0x25A8..]); }
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-10-10 23:11:46 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public override int X2 { get => ReadUInt16LittleEndian(General[0x25FA..]); set => WriteUInt16LittleEndian(General[0x25FA..], (ushort)value); }
|
|
|
|
public override int Y2 { get => ReadUInt16LittleEndian(General[0x25FE..]); set => WriteUInt16LittleEndian(General[0x25FE..], (ushort)value); }
|
|
|
|
public override int Z { get => ReadUInt16LittleEndian(General[0x2602..]); set => WriteUInt16LittleEndian(General[0x2602..], (ushort)value); }
|
2021-08-21 02:52:31 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public override uint SafariSeed { get => ReadUInt32LittleEndian(General[0x53C4..]); set => WriteUInt32LittleEndian(General[0x53C4..], value); }
|
|
|
|
public override uint SwarmSeed { get => ReadUInt32LittleEndian(General[0x53C8..]); set => WriteUInt32LittleEndian(General[0x53C8..], value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
public override uint SwarmMaxCountModulo => 28;
|
2022-06-19 02:46:53 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
protected override ReadOnlySpan<ushort> TreeSpecies =>
|
|
|
|
[
|
2023-03-26 00:55:55 +00:00
|
|
|
000, 000, 000, 000, 000, 000,
|
|
|
|
265, 266, 415, 412, 420, 190,
|
|
|
|
415, 412, 420, 190, 214, 265,
|
|
|
|
446, 446, 446, 446, 446, 446,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2023-03-26 00:55:55 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public Roamer4 RoamerMesprit => GetRoamer(0);
|
|
|
|
public Roamer4 RoamerCresselia => GetRoamer(1);
|
|
|
|
public Roamer4 RoamerUnused => GetRoamer(2); // Darkrai
|
|
|
|
|
|
|
|
private Roamer4 GetRoamer(int index)
|
|
|
|
{
|
|
|
|
const int size = Roamer4.SIZE;
|
|
|
|
var ofs = 0x73A0 + (index * size);
|
|
|
|
var mem = GeneralBuffer.Slice(ofs, size);
|
|
|
|
return new Roamer4(mem);
|
|
|
|
}
|
2021-05-18 20:04:23 +00:00
|
|
|
}
|