2022-06-18 21:11:22 +00:00
|
|
|
using System;
|
2021-05-18 20:04:23 +00:00
|
|
|
using System.Collections.Generic;
|
2022-01-03 05:35:59 +00:00
|
|
|
using static System.Buffers.Binary.BinaryPrimitives;
|
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
|
|
|
namespace PKHeX.Core;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <see cref="SaveFile"/> format for <see cref="GameVersion.Pt"/>
|
|
|
|
/// </summary>
|
|
|
|
public sealed class SAV4Pt : SAV4Sinnoh
|
2019-09-03 02:30:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV4Pt() : 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-02-21 17:59:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV4Pt(byte[] data) : base(data, GeneralSize, StorageSize, GeneralSize)
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
Dex = new Zukan4(this, PokeDex);
|
|
|
|
}
|
2021-02-21 17:59:10 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override Zukan4 Dex { get; }
|
|
|
|
protected override SAV4 CloneInternal4() => State.Exportable ? new SAV4Pt((byte[])Data.Clone()) : new SAV4Pt();
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalTable4 Personal => PersonalTable.Pt;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override IReadOnlyList<ushort> HeldItems => Legal.HeldItems_Pt;
|
|
|
|
public override int MaxItemID => Legal.MaxItemID_4_Pt;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int GeneralSize = 0xCF2C;
|
|
|
|
private const int StorageSize = 0x121E4; // Start 0xCF2C, +4 starts box data
|
|
|
|
protected override int StorageStart => GeneralSize;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void Initialize()
|
|
|
|
{
|
|
|
|
Version = GameVersion.Pt;
|
|
|
|
GetSAVOffsets();
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int EventWork => 0xDAC;
|
|
|
|
protected override int EventFlag => 0xFEC;
|
2022-04-10 01:12:57 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private void GetSAVOffsets()
|
|
|
|
{
|
|
|
|
AdventureInfo = 0;
|
|
|
|
Trainer1 = 0x68;
|
|
|
|
Party = 0xA0;
|
|
|
|
PokeDex = 0x1328;
|
2023-02-27 00:33:53 +00:00
|
|
|
Geonet = 0xA4C5;
|
2022-06-18 18:04:24 +00:00
|
|
|
WondercardFlags = 0xB4C0;
|
|
|
|
WondercardData = 0xB5C0;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DaycareOffset = 0x1654;
|
|
|
|
OFS_HONEY = 0x7F38;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
OFS_UG_Stats = 0x3CB4;
|
|
|
|
OFS_UG_Items = 0x4538;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
PoketchStart = 0x1160;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
OFS_PoffinCase = 0x52E8;
|
|
|
|
Seal = 0x6494;
|
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
|
|
|
|
private static int AdjustWallpaper(int value, int shift)
|
|
|
|
{
|
|
|
|
// Pt's Special Wallpapers 1-8 are shifted by +0x8
|
|
|
|
// HG/SS Special Wallpapers 1-8 (Primo Phrases) are shifted by +0x10
|
|
|
|
if (value >= 0x10) // special
|
|
|
|
return value + shift;
|
|
|
|
return value;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int GetBoxWallpaper(int box)
|
|
|
|
{
|
|
|
|
if ((uint)box > 18)
|
|
|
|
return 0;
|
|
|
|
int value = Storage[GetBoxWallpaperOffset(box)];
|
|
|
|
return AdjustWallpaper(value, -0x08);
|
|
|
|
}
|
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;
|
|
|
|
value = AdjustWallpaper(value, 0x08);
|
|
|
|
Storage[GetBoxWallpaperOffset(box)] = (byte)value;
|
|
|
|
}
|
|
|
|
#endregion
|
2019-10-26 19:33: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
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
InventoryPouch[] pouch =
|
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
|
|
|
new InventoryPouch4(InventoryType.Items, Legal.Pouch_Items_Pt, 999, 0x630),
|
|
|
|
new InventoryPouch4(InventoryType.KeyItems, Legal.Pouch_Key_Pt, 1, 0x8C4),
|
|
|
|
new InventoryPouch4(InventoryType.TMHMs, Legal.Pouch_TMHM_Pt, 99, 0x98C),
|
|
|
|
new InventoryPouch4(InventoryType.MailItems, Legal.Pouch_Mail_Pt, 999, 0xB1C),
|
|
|
|
new InventoryPouch4(InventoryType.Medicine, Legal.Pouch_Medicine_Pt, 999, 0xB4C),
|
|
|
|
new InventoryPouch4(InventoryType.Berries, Legal.Pouch_Berries_Pt, 999, 0xBEC),
|
|
|
|
new InventoryPouch4(InventoryType.Balls, Legal.Pouch_Ball_Pt, 999, 0xCEC),
|
|
|
|
new InventoryPouch4(InventoryType.BattleItems, Legal.Pouch_Battle_Pt, 999, 0xD28),
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
}
|
2021-05-18 20:04:23 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int M { get => ReadUInt16LittleEndian(General.AsSpan(0x1280)); set => WriteUInt16LittleEndian(General.AsSpan(0x1280), (ushort)value); }
|
|
|
|
public override int X { get => ReadUInt16LittleEndian(General.AsSpan(0x1288)); set => WriteUInt16LittleEndian(General.AsSpan(0x1288), (ushort)(X2 = value)); }
|
|
|
|
public override int Y { get => ReadUInt16LittleEndian(General.AsSpan(0x128C)); set => WriteUInt16LittleEndian(General.AsSpan(0x128C), (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
|
|
|
|
{
|
2022-11-25 01:42:17 +00:00
|
|
|
get => General.AsSpan(0x27E8, MaxStringLengthOT * 2);
|
|
|
|
set { if (value.Length == MaxStringLengthOT * 2) value.CopyTo(General.AsSpan(0x27E8)); }
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-10-10 23:11:46 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int X2 { get => ReadUInt16LittleEndian(General.AsSpan(0x287E)); set => WriteUInt16LittleEndian(General.AsSpan(0x287E), (ushort)value); }
|
|
|
|
public override int Y2 { get => ReadUInt16LittleEndian(General.AsSpan(0x2882)); set => WriteUInt16LittleEndian(General.AsSpan(0x2882), (ushort)value); }
|
|
|
|
public override int Z { get => ReadUInt16LittleEndian(General.AsSpan(0x2886)); set => WriteUInt16LittleEndian(General.AsSpan(0x2886), (ushort)value); }
|
2021-08-21 02:52:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override uint SafariSeed { get => ReadUInt32LittleEndian(General.AsSpan(0x5660)); set => WriteUInt32LittleEndian(General.AsSpan(0x5660), value); }
|
|
|
|
public override uint SwarmSeed { get => ReadUInt32LittleEndian(General.AsSpan(0x5664)); set => WriteUInt32LittleEndian(General.AsSpan(0x5664), value); }
|
|
|
|
public override uint SwarmMaxCountModulo => 22;
|
2022-06-18 21:11:22 +00:00
|
|
|
|
2022-06-19 02:46:53 +00:00
|
|
|
public Roamer4 RoamerMesprit => new(General, 0x7FF4);
|
|
|
|
public Roamer4 RoamerCresselia => new(General, 0x8008);
|
|
|
|
public Roamer4 RoamerUnused => new(General, 0x801C); // Darkrai
|
|
|
|
public Roamer4 RoamerArticuno => new(General, 0x8030);
|
|
|
|
public Roamer4 RoamerZapdos => new(General, 0x8044);
|
|
|
|
public Roamer4 RoamerMoltres => new(General, 0x8058);
|
2021-02-21 17:59:10 +00:00
|
|
|
}
|