PKHeX/PKHeX.Core/Saves/SAV4DP.cs

151 lines
5.5 KiB
C#
Raw Normal View History

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;
namespace PKHeX.Core
{
/// <summary>
/// <see cref="SaveFile"/> format for <see cref="GameVersion.DP"/>
/// </summary>
public sealed class SAV4DP : SAV4Sinnoh
{
2021-02-21 17:59:10 +00:00
public SAV4DP()
{
Initialize();
Dex = new Zukan4(this, PokeDex);
}
public SAV4DP(byte[] data) : base(data)
{
Initialize();
Dex = new Zukan4(this, PokeDex);
}
public override Zukan4 Dex { get; }
protected override SAV4 CloneInternal4() => State.Exportable ? new SAV4DP(Data) : new SAV4DP();
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 override PersonalTable Personal => PersonalTable.DP;
public override IReadOnlyList<ushort> HeldItems => Legal.HeldItems_DP;
public override int MaxItemID => Legal.MaxItemID_4_DP;
protected override int GeneralSize => 0xC100;
protected override int StorageSize => 0x121E0; // Start 0xC100, +4 starts box data
private void Initialize()
{
Version = GameVersion.DP;
GetSAVOffsets();
}
private void GetSAVOffsets()
{
AdventureInfo = 0;
Trainer1 = 0x64;
Party = 0x98;
PokeDex = 0x12DC;
WondercardFlags = 0xA6D0;
WondercardData = 0xA7fC;
EventConst = 0xD9C;
EventFlag = 0xFDC;
DaycareOffset = 0x141C;
OFS_HONEY = 0x72E4;
OFS_UG_Stats = 0x3A2C;
OFS_UG_Items = 0x42B0;
PoketchStart = 0x114C;
Seal = 0x6178;
OFS_PoffinCase = 0x5050;
Box = 4;
}
#region Storage
public override int GetBoxWallpaper(int box)
{
if ((uint)box >= 18)
return 0;
return Storage[GetBoxWallpaperOffset(box)];
}
public override void SetBoxWallpaper(int box, int value)
{
if ((uint)box >= 18)
return;
Storage[GetBoxWallpaperOffset(box)] = (byte)value;
}
#endregion
public override IReadOnlyList<InventoryPouch> Inventory
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
{
get
{
InventoryPouch[] pouch =
{
new InventoryPouch4(InventoryType.Items, Legal.Pouch_Items_DP, 999, 0x624),
new InventoryPouch4(InventoryType.KeyItems, Legal.Pouch_Key_DP, 1, 0x8B8),
new InventoryPouch4(InventoryType.TMHMs, Legal.Pouch_TMHM_DP, 99, 0x980),
new InventoryPouch4(InventoryType.MailItems, Legal.Pouch_Mail_DP, 999, 0xB10),
new InventoryPouch4(InventoryType.Medicine, Legal.Pouch_Medicine_DP, 999, 0xB40),
new InventoryPouch4(InventoryType.Berries, Legal.Pouch_Berries_DP, 999, 0xBE0),
new InventoryPouch4(InventoryType.Balls, Legal.Pouch_Ball_DP, 999, 0xCE0),
new InventoryPouch4(InventoryType.BattleItems, Legal.Pouch_Battle_DP, 999, 0xD1C),
};
return pouch.LoadAll(General);
}
set => value.SaveAll(General);
}
private const uint MysteryGiftDPSlotActive = 0xEDB88320;
public bool[] GetMysteryGiftDPSlotActiveFlags()
{
int ofs = WondercardFlags + 0x100; // skip over flags
bool[] active = new bool[GiftCountMax]; // 8 PGT, 3 PCD
for (int i = 0; i < active.Length; i++)
active[i] = BitConverter.ToUInt32(General, ofs + (4 * i)) == MysteryGiftDPSlotActive;
return active;
}
public void SetMysteryGiftDPSlotActiveFlags(bool[] value)
{
if (value.Length != GiftCountMax)
return;
int ofs = WondercardFlags + 0x100; // skip over flags
for (int i = 0; i < value.Length; i++)
{
byte[] magic = BitConverter.GetBytes(value[i] ? MysteryGiftDPSlotActive : 0); // 4 bytes
SetData(General, magic, ofs + (4 * i));
}
}
public override MysteryGiftAlbum GiftAlbum
{
get => base.GiftAlbum;
set
{
base.GiftAlbum = value;
SetActiveGiftFlags(value.Gifts);
}
}
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
public override int M { get => BitConverter.ToUInt16(General, 0x1238); set => BitConverter.GetBytes((ushort)value).CopyTo(General, 0x1238); }
public override int X { get => BitConverter.ToUInt16(General, 0x1240); set => BitConverter.GetBytes((ushort)(X2 = value)).CopyTo(General, 0x1240); }
public override int Y { get => BitConverter.ToUInt16(General, 0x1244); set => BitConverter.GetBytes((ushort)(Y2 = value)).CopyTo(General, 0x1244); }
public override int X2 { get => BitConverter.ToUInt16(General, 0x25FA); set => BitConverter.GetBytes((ushort)value).CopyTo(General, 0x25FA); }
public override int Y2 { get => BitConverter.ToUInt16(General, 0x25FE); set => BitConverter.GetBytes((ushort)value).CopyTo(General, 0x25FE); }
public override int Z { get => BitConverter.ToUInt16(General, 0x2602); set => BitConverter.GetBytes((ushort)value).CopyTo(General, 0x2602); }
}
2021-05-18 20:04:23 +00:00
}