2022-06-18 21:11:22 +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-03-26 02:47:23 +00:00
|
|
|
using System.Runtime.InteropServices;
|
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.HGSS"/>
|
|
|
|
/// </summary>
|
|
|
|
public sealed class SAV4HGSS : SAV4
|
2019-09-03 02:30:58 +00:00
|
|
|
{
|
2022-06-18 18:04:24 +00:00
|
|
|
public SAV4HGSS() : 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 SAV4HGSS(byte[] data) : base(data, GeneralSize, StorageSize, GeneralSize + GeneralGap)
|
|
|
|
{
|
|
|
|
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 SAV4HGSS((byte[])Data.Clone()) : new SAV4HGSS();
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override PersonalTable4 Personal => PersonalTable.HGSS;
|
2023-03-26 00:55:55 +00:00
|
|
|
public override ReadOnlySpan<ushort> HeldItems => Legal.HeldItems_HGSS;
|
2022-06-18 18:04:24 +00:00
|
|
|
public override int MaxItemID => Legal.MaxItemID_4_HGSS;
|
2023-11-10 06:02:23 +00:00
|
|
|
public const int GeneralSize = 0xF628;
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int StorageSize = 0x12310; // Start 0xF700, +0 starts box data
|
|
|
|
private const int GeneralGap = 0xD8;
|
|
|
|
protected override int FooterSize => 0x10;
|
2023-12-04 04:13:20 +00:00
|
|
|
|
|
|
|
protected override BlockInfo4[] ExtraBlocks =>
|
|
|
|
[
|
2023-11-09 07:33:40 +00:00
|
|
|
new BlockInfo4(0, 0x23000, 0x2AC0), // Hall of Fame
|
|
|
|
new BlockInfo4(1, 0x26000, 0x0BB0), // Battle Hall
|
|
|
|
new BlockInfo4(2, 0x27000, 0x1D60), // Battle Video (My Video)
|
|
|
|
new BlockInfo4(3, 0x29000, 0x1D60), // Battle Video (Other Videos 1)
|
|
|
|
new BlockInfo4(4, 0x2B000, 0x1D60), // Battle Video (Other Videos 2)
|
|
|
|
new BlockInfo4(5, 0x2D000, 0x1D60), // Battle Video (Other Videos 3)
|
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.HGSS;
|
|
|
|
GetSAVOffsets();
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
protected override int EventWork => 0xDE4;
|
|
|
|
protected override int EventFlag => 0x10C4;
|
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 = 0x12B8;
|
2023-11-09 07:33:40 +00:00
|
|
|
Extra = 0x230C;
|
2023-06-11 16:38:24 +00:00
|
|
|
Geonet = 0x8D44;
|
2022-06-18 18:04:24 +00:00
|
|
|
WondercardFlags = 0x9D3C;
|
|
|
|
WondercardData = 0x9E3C;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
DaycareOffset = 0x15FC;
|
|
|
|
Seal = 0x4E20;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
Box = 0;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
private Span<byte> LockCapsuleSpan => General.Slice(0xB064, PCD.Size);
|
2022-05-06 04:21:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PCD LockCapsuleSlot
|
|
|
|
{
|
|
|
|
get => new(LockCapsuleSpan.ToArray());
|
|
|
|
set => value.Data.CopyTo(LockCapsuleSpan);
|
|
|
|
}
|
2022-05-06 04:21:03 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
#region Storage
|
|
|
|
// box{pk4[30}[18]
|
|
|
|
// u32 currentBox
|
|
|
|
// u32 counter
|
|
|
|
// g4str[18] boxNames
|
|
|
|
// byte[18] boxWallpapers
|
|
|
|
// -- each box is chunked, padded to nearest 0x100 (resulting in 0x10 trailing zeroes)
|
|
|
|
// -- The final 0x16 bytes in the Storage block are unused (padding to nearest 0x100).
|
|
|
|
private const int BOX_COUNT = 18;
|
|
|
|
private const int BOX_SLOTS = 30;
|
|
|
|
private const int BOX_NAME_LEN = 40; // 20 characters
|
|
|
|
|
|
|
|
private const int BOX_DATA_LEN = (BOX_SLOTS * PokeCrypto.SIZE_4STORED) + 0x10; // 0xFF0, each box chunk is padded to nearest 0x100
|
|
|
|
private const int BOX_END = BOX_COUNT * BOX_DATA_LEN; // 18 * 0x1000
|
|
|
|
private const int BOX_NAME = 0x12008; // after current & counter
|
|
|
|
private const int BOX_WP = BOX_NAME + (BOX_COUNT * BOX_NAME_LEN); // 0x122D8;
|
|
|
|
private const int BOX_FLAGS = 18 + BOX_WP; // 0x122EA;
|
|
|
|
|
|
|
|
public override int GetBoxOffset(int box) => box * 0x1000;
|
|
|
|
private static int GetBoxNameOffset(int box) => BOX_NAME + (box * BOX_NAME_LEN);
|
|
|
|
protected override int GetBoxWallpaperOffset(int box) => BOX_WP + box;
|
|
|
|
|
|
|
|
// 8 bytes current box (align 32) & (stored count?)
|
|
|
|
public override int CurrentBox
|
|
|
|
{
|
|
|
|
get => Storage[BOX_END];
|
|
|
|
set => Storage[BOX_END] = (byte)value;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override byte[] BoxFlags
|
|
|
|
{
|
2023-12-04 04:13:20 +00:00
|
|
|
get => [ Storage[BOX_FLAGS] ];
|
2022-06-18 18:04:24 +00:00
|
|
|
set => Storage[BOX_FLAGS] = value[0];
|
|
|
|
}
|
2019-11-20 19:39:31 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int Counter
|
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
get => ReadInt32LittleEndian(Storage[(BOX_END + 4)..]);
|
|
|
|
set => WriteInt32LittleEndian(Storage[(BOX_END + 4)..], value);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
private Span<byte> GetBoxNameSpan(int box) => Storage.Slice(GetBoxNameOffset(box), BOX_NAME_LEN);
|
|
|
|
public override string GetBoxName(int box) => GetString(GetBoxNameSpan(box));
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-01-22 04:02:33 +00:00
|
|
|
public override void SetBoxName(int box, ReadOnlySpan<char> value)
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
|
|
|
const int maxlen = 8;
|
2023-03-26 22:16:12 +00:00
|
|
|
var span = GetBoxNameSpan(box);
|
2023-01-22 04:02:33 +00:00
|
|
|
SetString(span, value, maxlen, StringConverterOption.ClearZero);
|
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 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)
|
|
|
|
{
|
|
|
|
int offset = GetBoxWallpaperOffset(box);
|
|
|
|
int value = Storage[offset];
|
|
|
|
return AdjustWallpaper(value, -0x10);
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public override void SetBoxWallpaper(int box, int value)
|
|
|
|
{
|
|
|
|
value = AdjustWallpaper(value, 0x10);
|
|
|
|
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 = ItemStorage4HGSS.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, 0x644), // 0x644-0x8D7 (0x8CB)
|
|
|
|
new InventoryPouch4(InventoryType.KeyItems, info, 1, 0x8D8), // 0x8D8-0x99F (0x979)
|
|
|
|
new InventoryPouch4(InventoryType.TMHMs, info, 99, 0x9A0), // 0x9A0-0xB33 (0xB2F)
|
|
|
|
new InventoryPouch4(InventoryType.MailItems, info, 999, 0xB34), // 0xB34-0xB63 (0xB63)
|
|
|
|
new InventoryPouch4(InventoryType.Medicine, info, 999, 0xB64), // 0xB64-0xC03 (0xBFB)
|
|
|
|
new InventoryPouch4(InventoryType.Berries, info, 999, 0xC04), // 0xC04-0xD03
|
|
|
|
new InventoryPouch4(InventoryType.Balls, info, 999, 0xD04), // 0xD04-0xD63
|
|
|
|
new InventoryPouch4(InventoryType.BattleItems, info, 999, 0xD64), // 0xD64-0xD97
|
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
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public override int M { get => ReadUInt16LittleEndian(General[0x1234..]); set => WriteUInt16LittleEndian(General[0x1234..], (ushort)value); }
|
|
|
|
public override int X { get => ReadUInt16LittleEndian(General[0x123C..]); set => WriteUInt16LittleEndian(General[0x123C..], (ushort)(X2 = value)); }
|
|
|
|
public override int Y { get => ReadUInt16LittleEndian(General[0x1240..]); set => WriteUInt16LittleEndian(General[0x1240..], (ushort)(Y2 = value)); }
|
2022-02-25 07:17:16 +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 => RivalSpan;
|
|
|
|
set { if (value.Length == MaxStringLengthOT * 2) value.CopyTo(RivalSpan); }
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2021-05-18 20:04:23 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
private Span<byte> RivalSpan => General.Slice(0x22D4, MaxStringLengthOT * 2);
|
|
|
|
|
|
|
|
public override int X2 { get => ReadUInt16LittleEndian(General[0x236E..]); set => WriteUInt16LittleEndian(General[0x236E..], (ushort)value); }
|
|
|
|
public override int Y2 { get => ReadUInt16LittleEndian(General[0x2372..]); set => WriteUInt16LittleEndian(General[0x2372..], (ushort)value); }
|
|
|
|
public override int Z { get => ReadUInt16LittleEndian(General[0x2376..]); set => WriteUInt16LittleEndian(General[0x2376..], (ushort)value); }
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public int Badges16
|
|
|
|
{
|
|
|
|
get => General[Trainer1 + 0x1F];
|
|
|
|
set => General[Trainer1 + 0x1F] = (byte)value;
|
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
private const int OFS_GearRolodex = 0xC0EC;
|
|
|
|
private const byte GearMaxCallers = (byte)(PokegearNumber.Ernest + 1);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public PokegearNumber GetCallerAtIndex(int index) => (PokegearNumber)General[OFS_GearRolodex + index];
|
|
|
|
public void SetCallerAtIndex(int index, PokegearNumber caller) => General[OFS_GearRolodex + index] = (byte)caller;
|
2020-12-05 14:09:33 +00:00
|
|
|
|
2023-09-21 20:14:34 +00:00
|
|
|
public Span<PokegearNumber> GetPokeGearRoloDex()
|
2022-06-18 18:04:24 +00:00
|
|
|
{
|
2023-03-26 22:16:12 +00:00
|
|
|
var arr = General.Slice(OFS_GearRolodex, GearMaxCallers);
|
2023-09-21 20:14:34 +00:00
|
|
|
return MemoryMarshal.Cast<byte, PokegearNumber>(arr);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void SetPokeGearRoloDex(ReadOnlySpan<PokegearNumber> value)
|
|
|
|
{
|
|
|
|
if (value.Length > GearMaxCallers)
|
|
|
|
throw new ArgumentOutOfRangeException(nameof(value));
|
2023-09-21 20:14:34 +00:00
|
|
|
MemoryMarshal.AsBytes(value).CopyTo(General.Slice(OFS_GearRolodex, GearMaxCallers));
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void PokeGearUnlockAllCallers()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < GearMaxCallers; i++)
|
|
|
|
SetCallerAtIndex(i, (PokegearNumber)i);
|
|
|
|
}
|
2019-09-03 04:24:49 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void PokeGearClearAllCallers(int start = 0)
|
|
|
|
{
|
2023-09-21 20:14:34 +00:00
|
|
|
var dex = GetPokeGearRoloDex();
|
|
|
|
dex[start..].Fill(PokegearNumber.None);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-09-03 04:24:49 +00:00
|
|
|
|
2023-12-04 04:13:20 +00:00
|
|
|
private static ReadOnlySpan<PokegearNumber> NotTrainers =>
|
|
|
|
[
|
2023-09-21 20:14:34 +00:00
|
|
|
PokegearNumber.Mother,
|
|
|
|
PokegearNumber.Professor_Elm,
|
|
|
|
PokegearNumber.Professor_Oak,
|
|
|
|
PokegearNumber.Ethan,
|
|
|
|
PokegearNumber.Lyra,
|
|
|
|
PokegearNumber.Kurt,
|
|
|
|
PokegearNumber.Daycare_Man,
|
|
|
|
PokegearNumber.Daycare_Lady,
|
|
|
|
PokegearNumber.Bill,
|
|
|
|
PokegearNumber.Bike_Shop,
|
|
|
|
PokegearNumber.Baoba,
|
2023-12-04 04:13:20 +00:00
|
|
|
];
|
2023-09-21 20:14:34 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
public void PokeGearUnlockAllCallersNoTrainers()
|
|
|
|
{
|
2023-09-21 20:14:34 +00:00
|
|
|
var dex = GetPokeGearRoloDex();
|
|
|
|
NotTrainers.CopyTo(dex);
|
2022-06-18 18:04:24 +00:00
|
|
|
|
|
|
|
// clear remaining callers
|
2023-09-21 20:14:34 +00:00
|
|
|
PokeGearClearAllCallers(NotTrainers.Length);
|
2022-06-18 18:04:24 +00:00
|
|
|
}
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Apricorn Pouch
|
|
|
|
public int GetApricornCount(int index) => General[0xE558 + index];
|
|
|
|
public void SetApricornCount(int index, int count) => General[0xE558 + index] = (byte)count;
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2022-06-18 18:04:24 +00:00
|
|
|
// Pokewalker
|
|
|
|
public const int WalkerPair = 0xE5E0;
|
|
|
|
private const int OFS_WALKER = 0xE704;
|
2020-08-01 16:20:13 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public uint PokewalkerSteps { get => ReadUInt32LittleEndian(General[OFS_WALKER..]); set => WriteUInt32LittleEndian(General[OFS_WALKER..], value); }
|
|
|
|
public uint PokewalkerWatts { get => ReadUInt32LittleEndian(General[(OFS_WALKER + 0x4)..]); set => WriteUInt32LittleEndian(General[(OFS_WALKER + 4)..], value); }
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public bool[] GetPokewalkerCoursesUnlocked() => FlagUtil.GitBitFlagArray(General[(OFS_WALKER + 0x8)..], 32);
|
|
|
|
public void SetPokewalkerCoursesUnlocked(ReadOnlySpan<bool> value) => FlagUtil.SetBitFlagArray(General[(OFS_WALKER + 0x8)..], value);
|
2019-09-03 02:30:58 +00:00
|
|
|
|
2023-03-26 22:16:12 +00:00
|
|
|
public void PokewalkerCoursesSetAll(uint value = 0x07FF_FFFFu) => WriteUInt32LittleEndian(General[(OFS_WALKER + 0x8)..], value);
|
2021-08-21 02:52:31 +00:00
|
|
|
|
2023-10-07 15:57:38 +00:00
|
|
|
// Swarm
|
2023-03-26 22:16:12 +00:00
|
|
|
public override uint SwarmSeed { get => ReadUInt32LittleEndian(General[0x68A8..]); set => WriteUInt32LittleEndian(General[0x68A8..], value); }
|
2022-06-18 18:04:24 +00:00
|
|
|
public override uint SwarmMaxCountModulo => 20;
|
2022-06-18 21:11:22 +00:00
|
|
|
|
2023-10-07 15:57:38 +00:00
|
|
|
// Roamers
|
2023-03-26 22:16:12 +00:00
|
|
|
public Roamer4 RoamerRaikou => GetRoamer(0);
|
|
|
|
public Roamer4 RoamerEntei => GetRoamer(1);
|
|
|
|
public Roamer4 RoamerLatias => GetRoamer(2);
|
|
|
|
public Roamer4 RoamerLatios => GetRoamer(3);
|
|
|
|
|
|
|
|
private Roamer4 GetRoamer(int index)
|
|
|
|
{
|
|
|
|
const int size = Roamer4.SIZE;
|
|
|
|
var ofs = 0x68B4 + (index * size);
|
|
|
|
var mem = GeneralBuffer.Slice(ofs, size);
|
|
|
|
return new Roamer4(mem);
|
|
|
|
}
|
2023-10-07 15:57:38 +00:00
|
|
|
|
|
|
|
// Pokeathlon
|
|
|
|
public uint PokeathlonPoints { get => ReadUInt32LittleEndian(General[0xE548..]); set => WriteUInt32LittleEndian(General[0xE548..], value); }
|
2022-06-19 02:46:53 +00:00
|
|
|
}
|