2019-09-03 02:30:58 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Abstract <see cref="SaveFile"/> format for <see cref="GameVersion.DP"/> and <see cref="GameVersion.Pt"/>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class SAV4Sinnoh : SAV4
|
|
|
|
|
{
|
|
|
|
|
protected override int StorageStart => GeneralSize;
|
2019-09-04 01:16:10 +00:00
|
|
|
|
protected override int FooterSize => 0x14;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected SAV4Sinnoh() { }
|
|
|
|
|
protected SAV4Sinnoh(byte[] data) : base(data) { }
|
|
|
|
|
|
|
|
|
|
#region Storage
|
|
|
|
|
// u32 currentBox
|
|
|
|
|
// box{pk4[30}[18]
|
|
|
|
|
// g4str[18] boxNames
|
|
|
|
|
// byte[18] boxWallpapers
|
|
|
|
|
private const int BOX_COUNT = 18;
|
|
|
|
|
private const int BOX_SLOTS = 30;
|
|
|
|
|
private const int BOX_NAME_LEN = 40; // 20 characters
|
|
|
|
|
|
2020-01-04 22:48:39 +00:00
|
|
|
|
private const int BOX_DATA_LEN = (BOX_SLOTS * PokeCrypto.SIZE_4STORED); // 0xFF0, no padding between boxes (to nearest 0x100)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
private const int BOX_END = BOX_COUNT * BOX_DATA_LEN; // 18 * 0xFF0
|
|
|
|
|
private const int BOX_NAME = 4 + BOX_END; // after box data
|
|
|
|
|
private const int BOX_WP = BOX_NAME + (BOX_COUNT * BOX_NAME_LEN); // 0x121B4;
|
2019-11-20 19:39:31 +00:00
|
|
|
|
private const int BOX_FLAGS = 18 + BOX_WP; // 0x121C6
|
2019-09-03 02:30:58 +00:00
|
|
|
|
|
|
|
|
|
public override int GetBoxOffset(int box) => 4 + (box * BOX_DATA_LEN);
|
|
|
|
|
private static int GetBoxNameOffset(int box) => BOX_NAME + (box * BOX_NAME_LEN);
|
|
|
|
|
protected override int GetBoxWallpaperOffset(int box) => BOX_WP + box;
|
|
|
|
|
|
2019-10-05 21:32:40 +00:00
|
|
|
|
public override int CurrentBox // (align 32)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
{
|
2019-10-05 21:32:40 +00:00
|
|
|
|
get => Storage[0];
|
|
|
|
|
set => Storage[0] = (byte)value;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-20 19:39:31 +00:00
|
|
|
|
public override byte[] BoxFlags
|
2019-09-03 02:30:58 +00:00
|
|
|
|
{
|
2019-11-20 19:39:31 +00:00
|
|
|
|
get => new[] { Storage[BOX_FLAGS] };
|
|
|
|
|
set => Storage[BOX_FLAGS] = value[0];
|
2019-09-03 02:30:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string GetBoxName(int box) => GetString(Storage, GetBoxNameOffset(box), BOX_NAME_LEN);
|
|
|
|
|
|
|
|
|
|
public override void SetBoxName(int box, string value)
|
|
|
|
|
{
|
2019-11-19 00:01:36 +00:00
|
|
|
|
const int maxlen = 8;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
if (value.Length > maxlen)
|
|
|
|
|
value = value.Substring(0, maxlen); // Hard cap
|
|
|
|
|
int offset = GetBoxNameOffset(box);
|
|
|
|
|
var str = SetString(value, maxlen);
|
|
|
|
|
SetData(Storage, str, offset);
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2019-10-07 03:27:34 +00:00
|
|
|
|
#region Poketch
|
2021-02-21 23:01:28 +00:00
|
|
|
|
protected int PoketchStart { private get; set; }
|
2019-10-07 03:27:34 +00:00
|
|
|
|
private byte PoketchPacked { get => General[PoketchStart]; set => General[PoketchStart] = value; }
|
2019-09-03 02:30:58 +00:00
|
|
|
|
|
2019-10-07 03:27:34 +00:00
|
|
|
|
public bool PoketchEnabled { get => (PoketchPacked & 1) != 0; set => PoketchPacked = (byte)(value ? (PoketchPacked | 1) : (PoketchPacked & ~1)); }
|
|
|
|
|
public bool PoketchFlag1 { get => (PoketchPacked & 2) != 0; set => PoketchPacked = (byte)(value ? (PoketchPacked | 2) : (PoketchPacked & ~2)); }
|
|
|
|
|
public bool PoketchFlag2 { get => (PoketchPacked & 4) != 0; set => PoketchPacked = (byte)(value ? (PoketchPacked | 4) : (PoketchPacked & ~4)); }
|
|
|
|
|
|
|
|
|
|
public PoketchColor PoketchColor
|
|
|
|
|
{
|
|
|
|
|
get => (PoketchColor) ((PoketchPacked >> 3) & 7);
|
|
|
|
|
set => PoketchPacked = (byte) ((PoketchPacked & 0xC7) | ((int) value << 3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool PoketchFlag6 { get => (PoketchPacked & 0x40) != 0; set => PoketchPacked = (byte)(value ? (PoketchPacked | 0x40) : (PoketchPacked & ~0x40)); }
|
|
|
|
|
public bool PoketchFlag7 { get => (PoketchPacked & 0x80) != 0; set => PoketchPacked = (byte)(value ? (PoketchPacked | 0x80) : (PoketchPacked & ~0x80)); }
|
2020-04-12 23:07:59 +00:00
|
|
|
|
public byte Poketch1 { get => General[PoketchStart + 1]; set => General[PoketchStart + 1] = value; }
|
2019-10-07 03:27:34 +00:00
|
|
|
|
public sbyte CurrentPoketchApp { get => (sbyte)General[PoketchStart + 2]; set => General[PoketchStart + 2] = (byte)Math.Min((sbyte)PoketchApp.Alarm_Clock, value); }
|
|
|
|
|
|
|
|
|
|
public bool GetPoketchAppUnlocked(PoketchApp index)
|
|
|
|
|
{
|
|
|
|
|
if (index > PoketchApp.Alarm_Clock)
|
|
|
|
|
throw new ArgumentException(nameof(index));
|
|
|
|
|
return General[PoketchStart + 3 + (int) index] != 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetPoketchAppUnlocked(PoketchApp index, bool value = true)
|
|
|
|
|
{
|
|
|
|
|
if (index > PoketchApp.Alarm_Clock)
|
|
|
|
|
throw new ArgumentException(nameof(index));
|
|
|
|
|
var b = value ? 1 : 0;
|
|
|
|
|
General[PoketchStart + 3 + (int)index] = (byte)b;
|
|
|
|
|
}
|
2019-10-08 01:40:09 +00:00
|
|
|
|
|
2019-10-07 03:27:34 +00:00
|
|
|
|
// 8 bytes unk
|
|
|
|
|
|
|
|
|
|
public uint PoketchStepCounter
|
|
|
|
|
{
|
|
|
|
|
get => BitConverter.ToUInt32(General, PoketchStart + 0x24);
|
|
|
|
|
set => SetData(General, BitConverter.GetBytes(value), PoketchStart + 0x24);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2 bytes for alarm clock time setting
|
|
|
|
|
|
2020-09-06 17:53:13 +00:00
|
|
|
|
public byte[] GetPoketchDotArtistData() => General.Slice(PoketchStart + 0x2A, 120);
|
|
|
|
|
|
|
|
|
|
public void SetPoketchDotArtistData(byte[] value)
|
2019-10-07 03:27:34 +00:00
|
|
|
|
{
|
2020-09-06 17:53:13 +00:00
|
|
|
|
if (value.Length != 120)
|
|
|
|
|
throw new ArgumentException($"Expected {120} bytes.", nameof(value.Length));
|
|
|
|
|
SetData(General, value, PoketchStart + 0x2A);
|
2019-10-07 03:27:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// map marking stuff is at the end, unimportant
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region Honey Trees
|
2019-09-03 02:30:58 +00:00
|
|
|
|
protected int OFS_HONEY;
|
|
|
|
|
protected const int HONEY_SIZE = 8;
|
|
|
|
|
|
|
|
|
|
public HoneyTree GetHoneyTree(int index)
|
|
|
|
|
{
|
|
|
|
|
if ((uint)index > 21)
|
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
|
|
|
|
throw new ArgumentException(nameof(index));
|
2019-09-03 02:30:58 +00:00
|
|
|
|
return new HoneyTree(General.Slice(OFS_HONEY + (HONEY_SIZE * index), HONEY_SIZE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetHoneyTree(HoneyTree tree, int index)
|
|
|
|
|
{
|
|
|
|
|
if (index <= 21)
|
|
|
|
|
SetData(General, tree.Data, OFS_HONEY + (HONEY_SIZE * index));
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-06 17:53:13 +00:00
|
|
|
|
public int[] GetMunchlaxTrees() => CalculateMunchlaxTrees(TID, SID);
|
|
|
|
|
|
|
|
|
|
private static int[] CalculateMunchlaxTrees(int tid, int sid)
|
2019-09-03 02:30:58 +00:00
|
|
|
|
{
|
2020-09-06 17:53:13 +00:00
|
|
|
|
int A = (tid >> 8) % 21;
|
|
|
|
|
int B = (tid & 0x00FF) % 21;
|
|
|
|
|
int C = (sid >> 8) % 21;
|
|
|
|
|
int D = (sid & 0x00FF) % 21;
|
|
|
|
|
|
|
|
|
|
if (A == B) B = (B + 1) % 21;
|
|
|
|
|
if (A == C) C = (C + 1) % 21;
|
|
|
|
|
if (B == C) C = (C + 1) % 21;
|
|
|
|
|
if (A == D) D = (D + 1) % 21;
|
|
|
|
|
if (B == D) D = (D + 1) % 21;
|
|
|
|
|
if (C == D) D = (D + 1) % 21;
|
|
|
|
|
|
|
|
|
|
return new[] {A, B, C, D};
|
2019-09-03 02:30:58 +00:00
|
|
|
|
}
|
2020-09-06 17:53:13 +00:00
|
|
|
|
|
2019-10-07 03:27:34 +00:00
|
|
|
|
#endregion
|
2019-09-03 02:30:58 +00:00
|
|
|
|
|
|
|
|
|
public int OFS_PoffinCase { get; protected set; }
|
|
|
|
|
|
2020-09-13 21:55:50 +00:00
|
|
|
|
#region Underground
|
2019-09-03 02:30:58 +00:00
|
|
|
|
//Underground Scores
|
|
|
|
|
protected int OFS_UG_Stats;
|
2020-01-24 00:37:39 +00:00
|
|
|
|
public uint UG_PlayersMet { get => BitConverter.ToUInt32(General, OFS_UG_Stats); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats); }
|
|
|
|
|
public uint UG_Gifts { get => BitConverter.ToUInt32(General, OFS_UG_Stats + 0x4); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats + 0x4); }
|
|
|
|
|
public uint UG_Spheres { get => BitConverter.ToUInt32(General, OFS_UG_Stats + 0xC); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats + 0xC); }
|
|
|
|
|
public uint UG_Fossils { get => BitConverter.ToUInt32(General, OFS_UG_Stats + 0x10); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats + 0x10); }
|
|
|
|
|
public uint UG_TrapsAvoided { get => BitConverter.ToUInt32(General, OFS_UG_Stats + 0x18); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats + 0x18); }
|
|
|
|
|
public uint UG_TrapsTriggered { get => BitConverter.ToUInt32(General, OFS_UG_Stats + 0x1C); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats + 0x1C); }
|
|
|
|
|
public uint UG_Flags { get => BitConverter.ToUInt32(General, OFS_UG_Stats + 0x34); set => SetData(General, BitConverter.GetBytes(value), OFS_UG_Stats + 0x34); }
|
2020-09-13 21:55:50 +00:00
|
|
|
|
|
|
|
|
|
//Underground Items
|
|
|
|
|
protected int OFS_UG_Items;
|
|
|
|
|
|
|
|
|
|
public const int UG_POUCH_SIZE = 0x28; // 40 for each of the inventory pouches
|
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public byte[] GetUGI_Traps() => General.Slice(OFS_UG_Items, UG_POUCH_SIZE);
|
|
|
|
|
public void SetUGI_Traps(byte[] value) => SetData(General, value, OFS_UG_Items);
|
2020-09-13 21:55:50 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public byte[] GetUGI_Goods() => General.Slice(OFS_UG_Items + 0x28, UG_POUCH_SIZE);
|
|
|
|
|
public void SetUGI_Goods(byte[] value) => SetData(General, value, OFS_UG_Items + 0x28);
|
2020-09-13 21:55:50 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
public byte[] GetUGI_Treasures() => General.Slice(OFS_UG_Items + 0x50, UG_POUCH_SIZE);
|
|
|
|
|
public void SetUGI_Treasures(byte[] value) => SetData(General, value, OFS_UG_Items + 0x50);
|
2020-09-13 21:55:50 +00:00
|
|
|
|
|
2020-12-05 14:09:33 +00:00
|
|
|
|
// first 40 are the sphere type, last 40 are the sphere sizes
|
|
|
|
|
public byte[] GetUGI_Spheres() => General.Slice(OFS_UG_Items + 0x78, UG_POUCH_SIZE * 2);
|
|
|
|
|
public void SetUGI_Spheres(byte[] value) => SetData(General, value, OFS_UG_Items + 0x78);
|
|
|
|
|
|
|
|
|
|
#endregion
|
2019-09-03 02:30:58 +00:00
|
|
|
|
}
|
2019-10-07 03:27:34 +00:00
|
|
|
|
|
|
|
|
|
public enum PoketchColor
|
|
|
|
|
{
|
|
|
|
|
Green = 0,
|
|
|
|
|
Yellow = 1,
|
|
|
|
|
Orange = 2,
|
|
|
|
|
Red = 3,
|
|
|
|
|
Purple = 4,
|
|
|
|
|
Blue = 5,
|
|
|
|
|
Turquoise = 6,
|
|
|
|
|
White = 7,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum PoketchApp
|
|
|
|
|
{
|
|
|
|
|
Digital_Watch,
|
|
|
|
|
Calculator,
|
|
|
|
|
Memo_Pad,
|
|
|
|
|
Pedometer,
|
|
|
|
|
Party,
|
|
|
|
|
Friendship_Checker,
|
|
|
|
|
Dowsing_Machine,
|
|
|
|
|
Berry_Searcher,
|
|
|
|
|
Daycare,
|
|
|
|
|
History,
|
|
|
|
|
Counter,
|
|
|
|
|
Analog_Watch,
|
|
|
|
|
Marking_Map,
|
|
|
|
|
Link_Searcher,
|
|
|
|
|
Coin_Toss,
|
|
|
|
|
Move_Tester,
|
|
|
|
|
Calendar,
|
|
|
|
|
Dot_Artist,
|
|
|
|
|
Roulette,
|
|
|
|
|
Trainer_Counter,
|
|
|
|
|
Kitchen_Timer,
|
|
|
|
|
Color_Changer,
|
|
|
|
|
Matchup_Checker,
|
|
|
|
|
Stopwatch,
|
|
|
|
|
Alarm_Clock,
|
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
}
|