From 0549cfda4a80fa879d1ec35d8fa7057df0297349 Mon Sep 17 00:00:00 2001 From: Kurt Date: Thu, 16 Jan 2025 20:55:07 -0600 Subject: [PATCH] Rework SCBlock to Memory --- PKHeX.Core/Editing/Saves/Slots/Extensions.cs | 15 +++++---- .../Saves/Access/SaveBlockAccessor9SV.cs | 8 ++--- .../Saves/Encryption/SwishCrypto/SCBlock.cs | 17 +++++----- .../Encryption/SwishCrypto/SCBlockCompare.cs | 2 +- .../Encryption/SwishCrypto/SCBlockMetadata.cs | 2 +- PKHeX.Core/Saves/Substructures/Gen3/Swarm3.cs | 31 +++++++++---------- .../Substructures/Gen4/HoneyTreeValue.cs | 6 ++-- .../Substructures/Gen7/LGPE/PlayTime7b.cs | 2 +- .../Saves/Substructures/Gen8/BS/PlayTime8b.cs | 2 +- .../Substructures/Gen8/LA/BoxLayout8a.cs | 2 +- .../Substructures/Gen8/LA/Coordinates8a.cs | 2 +- .../Saves/Substructures/Gen8/LA/MyItem8a.cs | 6 ++-- .../Saves/Substructures/Gen8/LA/MyStatus8a.cs | 2 +- .../Saves/Substructures/Gen8/LA/Party8a.cs | 2 +- .../Substructures/Gen8/LA/PlayerFashion8a.cs | 2 +- .../Gen8/LA/Pokedex/PokedexSave8a.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/Box8.cs | 2 +- .../Substructures/Gen8/SWSH/BoxLayout8.cs | 2 +- .../Substructures/Gen8/SWSH/Coordinates8.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/Daycare8.cs | 2 +- .../Substructures/Gen8/SWSH/FashionUnlock8.cs | 2 +- .../Gen8/SWSH/FieldMoveModelSave8.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/Fused8.cs | 2 +- .../Gen8/SWSH/HallOfFameTime8.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/Misc8.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/MyItem8.cs | 2 +- .../Substructures/Gen8/SWSH/MyStatus8.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/Party8.cs | 2 +- .../Substructures/Gen8/SWSH/RaidSpawnList8.cs | 2 +- .../Saves/Substructures/Gen8/SWSH/Record8.cs | 2 +- .../Substructures/Gen8/SWSH/TeamIndexes8.cs | 4 +-- .../Substructures/Gen8/SWSH/TitleScreen8.cs | 4 +-- .../Substructures/Gen8/SWSH/TrainerCard8.cs | 4 +-- .../Substructures/Gen9/BlueberryClubRoom9.cs | 4 +-- .../Gen9/BlueberryQuestRecord9.cs | 2 +- .../Saves/Substructures/Gen9/BoxLayout9.cs | 2 +- .../Saves/Substructures/Gen9/ConfigCamera9.cs | 2 +- .../Saves/Substructures/Gen9/ConfigSave9.cs | 2 +- .../Substructures/Gen9/FixedSpawnList9.cs | 2 +- .../Saves/Substructures/Gen9/MyItem9.cs | 2 +- .../Saves/Substructures/Gen9/MyStatus9.cs | 2 +- PKHeX.Core/Saves/Substructures/Gen9/Party9.cs | 2 +- .../Saves/Substructures/Gen9/PlayTime9.cs | 2 +- .../Substructures/Gen9/PlayerAppearance9.cs | 2 +- .../Substructures/Gen9/PlayerFashion9.cs | 2 +- .../Substructures/Gen9/RaidSevenStar9.cs | 4 +-- .../Substructures/Gen9/RaidSpawnList9.cs | 2 +- .../PokeDex/Gen9/Zukan9Kitakami.cs | 7 ++--- .../PokeDex/Gen9/Zukan9Paldea.cs | 9 ++---- .../Saves/Substructures/PokeDex/Zukan8.cs | 30 +++++++++--------- .../Time/Epoch1900DateTimeValue.cs | 2 +- .../Substructures/Time/Epoch1900DateValue.cs | 2 +- .../Substructures/Time/Epoch1970Value.cs | 2 +- .../Save Editors/Gen8/SAV_BlockDump8.cs | 7 ++++- 54 files changed, 117 insertions(+), 117 deletions(-) diff --git a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs index 187cb1a6c..11cf4fd94 100644 --- a/PKHeX.Core/Editing/Saves/Slots/Extensions.cs +++ b/PKHeX.Core/Editing/Saves/Slots/Extensions.cs @@ -188,7 +188,7 @@ private static List GetExtraSlots8(ISaveBlock8Main sav) if (sav is SAV8SWSH {SaveRevision: >= 2} s8) { var block = s8.Blocks.GetBlockSafe(SaveBlockAccessor8SWSH.KFusedCalyrex); - var c = new SlotInfoMisc(block.Data, 3, true) {Type = StorageSlotType.FusedCalyrex}; + var c = new SlotInfoMisc(block.Raw, 3, true) {Type = StorageSlotType.FusedCalyrex}; list.Insert(3, c); } @@ -226,20 +226,19 @@ private static List GetExtraSlots9(SAV9SV sav) }; var block = sav.Blocks.GetBlock(SaveBlockAccessor9SV.KFusedCalyrex); - list.Add(new(block.Data, 0, true) { Type = StorageSlotType.FusedCalyrex }); + list.Add(new(block.Raw, 0, true) { Type = StorageSlotType.FusedCalyrex }); if (sav.Blocks.TryGetBlock(SaveBlockAccessor9SV.KFusedKyurem, out var kyurem)) - list.Add(new(kyurem.Data, 1, true) { Type = StorageSlotType.FusedKyurem }); + list.Add(new(kyurem.Raw, 1, true) { Type = StorageSlotType.FusedKyurem }); if (sav.Blocks.TryGetBlock(SaveBlockAccessor9SV.KFusedNecrozmaS, out var solgaleo)) - list.Add(new(solgaleo.Data, 2, true) { Type = StorageSlotType.FusedNecrozmaS }); + list.Add(new(solgaleo.Raw, 2, true) { Type = StorageSlotType.FusedNecrozmaS }); if (sav.Blocks.TryGetBlock(SaveBlockAccessor9SV.KFusedNecrozmaM, out var lunala)) - list.Add(new(lunala.Data, 3, true) { Type = StorageSlotType.FusedNecrozmaM }); + list.Add(new(lunala.Raw, 3, true) { Type = StorageSlotType.FusedNecrozmaM }); if (sav.Blocks.TryGetBlock(SaveBlockAccessor9SV.KSurpriseTrade, out var surprise)) { - var st = surprise.Data.AsMemory(); - list.Add(new(st[0x198..], 0) { Type = StorageSlotType.Misc }); // my upload - list.Add(new(st[0x2C..], 1) { Type = StorageSlotType.Misc }); // received from others + list.Add(new(surprise.Raw[0x198..], 0) { Type = StorageSlotType.Misc }); // my upload + list.Add(new(surprise.Raw[0x02C..], 1) { Type = StorageSlotType.Misc }); // received from others } return list; } diff --git a/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs b/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs index c177dea1c..f836de0fc 100644 --- a/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs +++ b/PKHeX.Core/Saves/Access/SaveBlockAccessor9SV.cs @@ -45,14 +45,14 @@ private class Raid9 public Raid9(SAV9SV sav) { var paldea = GetBlock(sav.AllBlocks, KTeraRaidPaldea); - Paldea = new RaidSpawnList9(sav, paldea, paldea.Data, RaidSpawnList9.RaidCountLegal_T0, true); + Paldea = new RaidSpawnList9(sav, paldea, paldea.Raw, RaidSpawnList9.RaidCountLegal_T0, true); if (TryGetBlock(sav.AllBlocks, KTeraRaidDLC, out var raidDLC)) { - var buffer = raidDLC.Data; + var buffer = raidDLC.Raw; const int size = 0xC80; - var memKita = buffer.AsMemory(0, size); - var memBlue = buffer.AsMemory(size, size); + var memKita = buffer[..size]; + var memBlue = buffer.Slice(size, size); Kitakami = new RaidSpawnList9(sav, raidDLC, memKita, RaidSpawnList9.RaidCountLegal_T1, false); Blueberry = new RaidSpawnList9(sav, raidDLC, memBlue, RaidSpawnList9.RaidCountLegal_T2, false); } diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlock.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlock.cs index 3fa79a56c..f4e9ba826 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlock.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlock.cs @@ -28,7 +28,10 @@ public sealed class SCBlock /// /// Decrypted data for this block. /// - public readonly byte[] Data; + public readonly Memory Raw; + + /// + public Span Data => Raw.Span; /// /// Changes the block's Boolean type. Will throw if the old / new is not boolean. @@ -59,7 +62,7 @@ public void ChangeData(ReadOnlySpan value) /// /// Hash key /// Value the block has - internal SCBlock(uint key, SCTypeCode type) : this(key, type, []) + internal SCBlock(uint key, SCTypeCode type) : this(key, type, Memory.Empty) { } @@ -69,11 +72,11 @@ internal SCBlock(uint key, SCTypeCode type) : this(key, type, []) /// Hash key /// Type of data that can be read /// Backing byte array to interpret as a typed value - internal SCBlock(uint key, SCTypeCode type, byte[] arr) + internal SCBlock(uint key, SCTypeCode type, Memory arr) { Key = key; Type = type; - Data = arr; + Raw = arr; } /// @@ -82,11 +85,11 @@ internal SCBlock(uint key, SCTypeCode type, byte[] arr) /// Hash key /// Backing byte array to read primitives from /// Primitive value type - internal SCBlock(uint key, byte[] arr, SCTypeCode subType) + internal SCBlock(uint key, Memory arr, SCTypeCode subType) { Key = key; Type = SCTypeCode.Array; - Data = arr; + Raw = arr; SubType = subType; } @@ -109,7 +112,7 @@ public SCBlock Clone() { if (Data.Length == 0) return new SCBlock(Key, Type); - var clone = Data.AsSpan().ToArray(); + var clone = Data.ToArray(); if (SubType == 0) return new SCBlock(Key, Type, clone); return new SCBlock(Key, clone, SubType); diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockCompare.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockCompare.cs index 0c9ded5e5..668763faf 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockCompare.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockCompare.cs @@ -105,7 +105,7 @@ void ReplaceLabels(Dictionary list, IEnumerable { foreach (var b in blocks) { - var match = list.FirstOrDefault(z => z.Value.Equals(b.Data)); + var match = list.FirstOrDefault(z => z.Value.Equals(b.Raw)); if (match.Key is not { } x) continue; ref var exist = ref CollectionsMarshal.GetValueRefOrNullRef(names, b.Key); diff --git a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs index 5df833e82..294694ba8 100644 --- a/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs +++ b/PKHeX.Core/Saves/Encryption/SwishCrypto/SCBlockMetadata.cs @@ -96,7 +96,7 @@ private string GetBlockHint(SCBlock z, int index) if (block.Data.Length != 0) { static bool SameBackingBuffer(IDataIndirect d, ReadOnlyMemory data) => d.Equals(data); - var obj = BlockList.FirstOrDefault(z => SameBackingBuffer(z.Value, block.Data)); + var obj = BlockList.FirstOrDefault(z => SameBackingBuffer(z.Value, block.Raw)); if (obj is not (null, null)) { saveBlock = obj.Value; diff --git a/PKHeX.Core/Saves/Substructures/Gen3/Swarm3.cs b/PKHeX.Core/Saves/Substructures/Gen3/Swarm3.cs index c0d710acd..7b17dbfcd 100644 --- a/PKHeX.Core/Saves/Substructures/Gen3/Swarm3.cs +++ b/PKHeX.Core/Saves/Substructures/Gen3/Swarm3.cs @@ -5,26 +5,25 @@ namespace PKHeX.Core; -public sealed class Swarm3(byte[] Data) +public sealed class Swarm3(Memory Raw) { public const int SIZE = 0x14; - public readonly byte[] Data = Data; - private Span Raw => Data.AsSpan(); + public Span Data => Raw.Span; - public ushort Gen3Species { get => ReadUInt16LittleEndian(Raw); set => WriteUInt16LittleEndian(Raw, value); } - public byte MapNum { get => Raw[2]; set => Raw[2] = value; } - public byte MapGroup { get => Raw[3]; set => Raw[3] = value; } - public byte Level { get => Raw[4]; set => Raw[4] = value; } - public byte Unused1 { get => Raw[5]; set => Raw[5] = value; } - public ushort Unused2 { get => ReadUInt16LittleEndian(Raw[0x6..]); set => WriteUInt16LittleEndian(Raw[0x6..], value); } - public ushort Move1 { get => ReadUInt16LittleEndian(Raw[0x8..]); set => WriteUInt16LittleEndian(Raw[0x8..], value); } - public ushort Move2 { get => ReadUInt16LittleEndian(Raw[0xA..]); set => WriteUInt16LittleEndian(Raw[0xA..], value); } - public ushort Move3 { get => ReadUInt16LittleEndian(Raw[0xC..]); set => WriteUInt16LittleEndian(Raw[0xC..], value); } - public ushort Move4 { get => ReadUInt16LittleEndian(Raw[0xE..]); set => WriteUInt16LittleEndian(Raw[0xE..], value); } - public byte Unused3 { get => Raw[0x10]; set => Raw[0x10] = value; } - public byte EncounterProbability { get => Raw[0x11]; set => Raw[0x11] = value; } - public ushort DaysLeft { get => ReadUInt16LittleEndian(Raw[0x12..]); set => WriteUInt16LittleEndian(Raw[0x12..], value); } + public ushort Gen3Species { get => ReadUInt16LittleEndian(Data); set => WriteUInt16LittleEndian(Data, value); } + public byte MapNum { get => Data[2]; set => Data[2] = value; } + public byte MapGroup { get => Data[3]; set => Data[3] = value; } + public byte Level { get => Data[4]; set => Data[4] = value; } + public byte Unused1 { get => Data[5]; set => Data[5] = value; } + public ushort Unused2 { get => ReadUInt16LittleEndian(Data[0x6..]); set => WriteUInt16LittleEndian(Data[0x6..], value); } + public ushort Move1 { get => ReadUInt16LittleEndian(Data[0x8..]); set => WriteUInt16LittleEndian(Data[0x8..], value); } + public ushort Move2 { get => ReadUInt16LittleEndian(Data[0xA..]); set => WriteUInt16LittleEndian(Data[0xA..], value); } + public ushort Move3 { get => ReadUInt16LittleEndian(Data[0xC..]); set => WriteUInt16LittleEndian(Data[0xC..], value); } + public ushort Move4 { get => ReadUInt16LittleEndian(Data[0xE..]); set => WriteUInt16LittleEndian(Data[0xE..], value); } + public byte Unused3 { get => Data[0x10]; set => Data[0x10] = value; } + public byte EncounterProbability { get => Data[0x11]; set => Data[0x11] = value; } + public ushort DaysLeft { get => ReadUInt16LittleEndian(Data[0x12..]); set => WriteUInt16LittleEndian(Data[0x12..], value); } public Swarm3(Species species, byte level, byte map, Move m1, Move m2 = 0, Move m3 = 0, Move m4 = 0) : this(new byte[SIZE]) { diff --git a/PKHeX.Core/Saves/Substructures/Gen4/HoneyTreeValue.cs b/PKHeX.Core/Saves/Substructures/Gen4/HoneyTreeValue.cs index 544a61163..6c43c7a1d 100644 --- a/PKHeX.Core/Saves/Substructures/Gen4/HoneyTreeValue.cs +++ b/PKHeX.Core/Saves/Substructures/Gen4/HoneyTreeValue.cs @@ -6,13 +6,13 @@ namespace PKHeX.Core; /// /// Honey Tree in Sinnoh (Gen4) /// -public sealed class HoneyTreeValue(byte[] Data) +public sealed class HoneyTreeValue(Memory Raw) { public const int Size = 8; - public readonly byte[] Data = Data; + public Span Data => Raw.Span; - public uint Time { get => ReadUInt32LittleEndian(Data.AsSpan(0)); set => WriteUInt32LittleEndian(Data.AsSpan(0), value); } + public uint Time { get => ReadUInt32LittleEndian(Data); set => WriteUInt32LittleEndian(Data, value); } public int Slot { get => Data[4]; set => Data[4] = (byte)value; } public int SubTable { get => Data[5]; set => Data[5] = (byte)value; } // offset by 1 with respect to Group public int Group { get => Data[6]; set { Data[6] = (byte)value; SubTable = Math.Max(0, Group - 1); } } diff --git a/PKHeX.Core/Saves/Substructures/Gen7/LGPE/PlayTime7b.cs b/PKHeX.Core/Saves/Substructures/Gen7/LGPE/PlayTime7b.cs index 72802dc3c..a46ba530a 100644 --- a/PKHeX.Core/Saves/Substructures/Gen7/LGPE/PlayTime7b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen7/LGPE/PlayTime7b.cs @@ -8,7 +8,7 @@ namespace PKHeX.Core; public sealed class PlayTime7b : PlayTimeLastSaved { public PlayTime7b(SAV7b sav, Memory raw) : base(sav, raw) { } - public PlayTime7b(SAV8SWSH sav, SCBlock block) : base(sav, block.Data) { } + public PlayTime7b(SAV8SWSH sav, SCBlock block) : base(sav, block.Raw) { } protected override Epoch1900DateTimeValue LastSaved => new(Raw.Slice(0x4, 4)); } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/PlayTime8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/PlayTime8b.cs index a91cd2cb1..9e798982d 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/PlayTime8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/PlayTime8b.cs @@ -10,5 +10,5 @@ namespace PKHeX.Core; public sealed class PlayTime8b : PlayTime { public PlayTime8b(SAV8BS sav, Memory raw) : base(sav, raw) { } - public PlayTime8b(SAV8LA sav, SCBlock block) : base(sav, block.Data) { } + public PlayTime8b(SAV8LA sav, SCBlock block) : base(sav, block.Raw) { } } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/BoxLayout8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/BoxLayout8a.cs index 8e5e7c5d0..20aeaa100 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/BoxLayout8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/BoxLayout8a.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; /// Exposes information about Box Names and which box is the first box to show when the UI is opened. /// [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class BoxLayout8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Data), IBoxDetailName +public sealed class BoxLayout8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Raw), IBoxDetailName { public const int BoxCount = 32; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/Coordinates8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/Coordinates8a.cs index acdb0ce4b..04b381f56 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/Coordinates8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/Coordinates8a.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// Stores the position of the player. /// [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class Coordinates8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Coordinates8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Raw) { // Map private Span MapName() => Data.Slice(0x08, 0x48); diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/MyItem8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/MyItem8a.cs index 20a0213bc..243da580a 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/MyItem8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/MyItem8a.cs @@ -9,7 +9,7 @@ namespace PKHeX.Core; /// /// Reads four separate pouch blobs: Items, Key Items, Storage, and Recipes. /// -public sealed class MyItem8a(SAV8LA sav, SCBlock block) : MyItem(sav, block.Data) +public sealed class MyItem8a(SAV8LA sav, SCBlock block) : MyItem(sav, block.Raw) { public override IReadOnlyList Inventory { @@ -49,14 +49,14 @@ public override IReadOnlyList Inventory private static void LoadFavorites(ReadOnlySpan pouches, SCBlockAccessor access) { - var favorites = access.GetBlock(SaveBlockAccessor8LA.KItemFavorite).Data.AsSpan(); + var favorites = access.GetBlock(SaveBlockAccessor8LA.KItemFavorite).Data; foreach (var arr in pouches) LoadFavorites(arr.Items, favorites); } private static void SaveFavorites(ReadOnlySpan pouches, SCBlockAccessor access) { - var favorites = access.GetBlock(SaveBlockAccessor8LA.KItemFavorite).Data.AsSpan(); + var favorites = access.GetBlock(SaveBlockAccessor8LA.KItemFavorite).Data; favorites.Clear(); foreach (var arr in pouches) SaveFavorites(arr.Items, favorites); diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/MyStatus8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/MyStatus8a.cs index 2ca934b52..3e9261b9a 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/MyStatus8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/MyStatus8a.cs @@ -8,7 +8,7 @@ namespace PKHeX.Core; /// Stores data about the player. /// [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class MyStatus8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class MyStatus8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Raw) { public uint ID32 { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/Party8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/Party8a.cs index 76ad00a20..d26dd25c9 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/Party8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/Party8a.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core; -public sealed class Party8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Party8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Raw) { public int PartyCount { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/PlayerFashion8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/PlayerFashion8a.cs index 0dd5923b7..55370afe1 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/PlayerFashion8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/PlayerFashion8a.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; /// Stores the selected appearance choices of the player. /// [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class PlayerFashion8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class PlayerFashion8a(SAV8LA sav, SCBlock block) : SaveBlock(sav, block.Raw) { public ulong Hair { get => ReadUInt64LittleEndian(Data); set => WriteUInt64LittleEndian(Data, value); } public ulong Contacts { get => ReadUInt64LittleEndian(Data[0x08..]); set => WriteUInt64LittleEndian(Data[0x08..], value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs b/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs index 41f7d976d..afcb3a8c5 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/LA/Pokedex/PokedexSave8a.cs @@ -11,7 +11,7 @@ namespace PKHeX.Core; /// > public sealed class PokedexSave8a(SAV8LA SaveFile, SCBlock block) { - private readonly PokedexSaveData SaveData = new(block.Data); + private readonly PokedexSaveData SaveData = new(block.Raw); public const int MAX_SPECIES = 981; public const int MAX_FORM = 120; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Box8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Box8.cs index 44083542e..171ee56a5 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Box8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Box8.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core; -public sealed class Box8(SaveFile sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Box8(SaveFile sav, SCBlock block) : SaveBlock(sav, block.Raw) { [Browsable(false)] public new Memory Raw => base.Raw; } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/BoxLayout8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/BoxLayout8.cs index ffe13b9e0..50cb92286 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/BoxLayout8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/BoxLayout8.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class BoxLayout8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data), IBoxDetailName +public sealed class BoxLayout8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw), IBoxDetailName { public const int BoxCount = 32; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Coordinates8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Coordinates8.cs index df6ed88e4..eb45809a6 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Coordinates8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Coordinates8.cs @@ -5,7 +5,7 @@ namespace PKHeX.Core; /// /// Stores the position of the player. /// -public sealed class Coordinates8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Coordinates8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { // Position public float X { get => ReadSingleLittleEndian(Data[0x10..]); set => WriteSingleLittleEndian(Data[0x10..], value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Daycare8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Daycare8.cs index d6ee62307..77a43f740 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Daycare8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Daycare8.cs @@ -6,7 +6,7 @@ namespace PKHeX.Core; /// /// Storage for the two in-game daycare structures. /// -public sealed class Daycare8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Daycare8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { // BLOCK STRUCTURE: // bool8 present diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs index 9b4888aa9..e03cd1047 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FashionUnlock8.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core; -public sealed class FashionUnlock8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class FashionUnlock8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { private const int SIZE_ENTRY = 0x80; private const int REGIONS = 15; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FieldMoveModelSave8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FieldMoveModelSave8.cs index 1d4ee5216..7034660ce 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FieldMoveModelSave8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/FieldMoveModelSave8.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class FieldMoveModelSave8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class FieldMoveModelSave8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { public int M { get => ReadUInt16LittleEndian(Data); set => WriteUInt16LittleEndian(Data, (ushort)value); } public float X { get => ReadSingleLittleEndian(Data[0x08..]); set => WriteSingleLittleEndian(Data[0x08..], value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Fused8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Fused8.cs index 9cb71ec43..f083a4d6c 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Fused8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Fused8.cs @@ -5,7 +5,7 @@ namespace PKHeX.Core; /// /// Storage for the species that was fused into and . /// -public sealed class Fused8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Fused8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { private const int SizeStored = PokeCrypto.SIZE_8PARTY; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/HallOfFameTime8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/HallOfFameTime8.cs index d035b50f2..98a95c0af 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/HallOfFameTime8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/HallOfFameTime8.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; public sealed class HallOfFameTime8 : SaveBlock { - public HallOfFameTime8(SAV8SWSH sav, SCBlock block) : base(sav, block.Data) + public HallOfFameTime8(SAV8SWSH sav, SCBlock block) : base(sav, block.Raw) { Debug.Assert(Data.Length == 8); } diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Misc8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Misc8.cs index 2abf847fb..f429040e7 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Misc8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Misc8.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class Misc8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Misc8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { public int Badges { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyItem8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyItem8.cs index 53493b8a8..8c33c31e6 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyItem8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyItem8.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class MyItem8(SAV8SWSH SAV, SCBlock block) : MyItem(SAV, block.Data) +public sealed class MyItem8(SAV8SWSH SAV, SCBlock block) : MyItem(SAV, block.Raw) { public const int Medicine = 0; public const int Balls = Medicine + (4 * PouchSize8.Medicine); diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyStatus8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyStatus8.cs index 97c4b5f5c..559b70f16 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyStatus8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/MyStatus8.cs @@ -4,7 +4,7 @@ namespace PKHeX.Core; -public sealed class MyStatus8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class MyStatus8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { public const uint MaxWatt = 9999999; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Party8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Party8.cs index e3ff9e044..00f68b944 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Party8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Party8.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core; -public sealed class Party8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Party8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { public int PartyCount { diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/RaidSpawnList8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/RaidSpawnList8.cs index 8f14e2ca3..96fd0fb36 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/RaidSpawnList8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/RaidSpawnList8.cs @@ -4,7 +4,7 @@ namespace PKHeX.Core; -public sealed class RaidSpawnList8(SAV8SWSH sav, SCBlock block, int legal) : SaveBlock(sav, block.Data) +public sealed class RaidSpawnList8(SAV8SWSH sav, SCBlock block, int legal) : SaveBlock(sav, block.Raw) { public readonly int CountAll = block.Data.Length / RaidSpawnDetail.SIZE; public readonly int CountUsed = legal; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Record8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Record8.cs index ff37a3509..69bb2d252 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Record8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/Record8.cs @@ -4,7 +4,7 @@ namespace PKHeX.Core; -public sealed class Record8(SAV8SWSH sav, SCBlock block) : RecordBlock(sav, block.Data) +public sealed class Record8(SAV8SWSH sav, SCBlock block) : RecordBlock(sav, block.Raw) { public const int RecordCount = 50; public const int WattTotal = 22; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs index 1af18503e..a7d93f9bb 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TeamIndexes8.cs @@ -32,7 +32,7 @@ public void LoadBattleTeams() for (int i = 0; i < TeamCount * 6; i++) { - short val = ReadInt16LittleEndian(Indexes.Data.AsSpan(i * 2)); + short val = ReadInt16LittleEndian(Indexes.Data[(i*2)..]); if (val < 0) { TeamSlots[i] = NONE_SELECTED; @@ -60,7 +60,7 @@ public void UnlockAllTeams() public void SaveBattleTeams() { - var span = Indexes.Data.AsSpan(); + var span = Indexes.Data; for (int i = 0; i < TeamCount * 6; i++) { int index = TeamSlots[i]; diff --git a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TitleScreen8.cs b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TitleScreen8.cs index 448a44eef..42f30ed40 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TitleScreen8.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/SWSH/TitleScreen8.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; /// /// Pokémon Team that shows up at the title screen. /// -public sealed class TitleScreen8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class TitleScreen8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { /// /// Gets an object that exposes the data of the corresponding party . @@ -15,7 +15,7 @@ public sealed class TitleScreen8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class TrainerCard8(SAV8SWSH sav, SCBlock block) : SaveBlock(sav, block.Raw) { private Span OriginalTrainerTrash => Data[..0x1A]; @@ -230,7 +230,7 @@ public ulong Shoe public TrainerCard8Poke ViewPoke(int index) { var ofs = GetPokeOffset(index); - var raw = block.Data.AsMemory(ofs, TrainerCard8Poke.SIZE); + var raw = block.Raw.Slice(ofs, TrainerCard8Poke.SIZE); return new TrainerCard8Poke(raw); } diff --git a/PKHeX.Core/Saves/Substructures/Gen9/BlueberryClubRoom9.cs b/PKHeX.Core/Saves/Substructures/Gen9/BlueberryClubRoom9.cs index 0f3e52fdb..183050edf 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/BlueberryClubRoom9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/BlueberryClubRoom9.cs @@ -2,9 +2,9 @@ namespace PKHeX.Core; -public sealed class BlueberryClubRoom9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class BlueberryClubRoom9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { - public BlueberrySupportBoard9 SupportBoard => new(block.Data.AsMemory(0, 0x38)); + public BlueberrySupportBoard9 SupportBoard => new(block.Raw[..0x38]); public BlueberryClubRoomStyle9 CurrentStyle { get => (BlueberryClubRoomStyle9)Data[0xE6C]; set => Data[0xE6C] = (byte)value; } } diff --git a/PKHeX.Core/Saves/Substructures/Gen9/BlueberryQuestRecord9.cs b/PKHeX.Core/Saves/Substructures/Gen9/BlueberryQuestRecord9.cs index 0fc4336f8..669e80d22 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/BlueberryQuestRecord9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/BlueberryQuestRecord9.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class BlueberryQuestRecord9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class BlueberryQuestRecord9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public uint QuestsDoneSolo { get => ReadUInt32LittleEndian(Data[0x188..]); set => WriteUInt32LittleEndian(Data[0x188..], value); } public uint QuestsDoneGroup { get => ReadUInt32LittleEndian(Data[0x18C..]); set => WriteUInt32LittleEndian(Data[0x18C..], value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen9/BoxLayout9.cs b/PKHeX.Core/Saves/Substructures/Gen9/BoxLayout9.cs index fb4e421ab..fbd7ba522 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/BoxLayout9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/BoxLayout9.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class BoxLayout9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data), IBoxDetailName +public sealed class BoxLayout9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw), IBoxDetailName { public const int BoxCount = 32; diff --git a/PKHeX.Core/Saves/Substructures/Gen9/ConfigCamera9.cs b/PKHeX.Core/Saves/Substructures/Gen9/ConfigCamera9.cs index cf1ac522c..54c40a5d6 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/ConfigCamera9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/ConfigCamera9.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class ConfigCamera9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class ConfigCamera9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { // Structure: u32 /* CameraSupport:1 | On = 0, Off = 1 diff --git a/PKHeX.Core/Saves/Substructures/Gen9/ConfigSave9.cs b/PKHeX.Core/Saves/Substructures/Gen9/ConfigSave9.cs index 0d7011a09..7f6142ef8 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/ConfigSave9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/ConfigSave9.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class ConfigSave9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class ConfigSave9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { // Structure: u32 /* TalkingSpeed:2 diff --git a/PKHeX.Core/Saves/Substructures/Gen9/FixedSpawnList9.cs b/PKHeX.Core/Saves/Substructures/Gen9/FixedSpawnList9.cs index f38aadc96..633de537b 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/FixedSpawnList9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/FixedSpawnList9.cs @@ -6,7 +6,7 @@ namespace PKHeX.Core; [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class FixedSpawnList9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class FixedSpawnList9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public readonly int CountAll = block.Data.Length / FixedSpawnDetail.SIZE; diff --git a/PKHeX.Core/Saves/Substructures/Gen9/MyItem9.cs b/PKHeX.Core/Saves/Substructures/Gen9/MyItem9.cs index eaf4c534f..239ac9c10 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/MyItem9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/MyItem9.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; /// Player item pouches storage /// /// size=0xBB80 ( items) -public sealed class MyItem9(SAV9SV sav, SCBlock block) : MyItem(sav, block.Data) +public sealed class MyItem9(SAV9SV sav, SCBlock block) : MyItem(sav, block.Raw) { public const int ItemSaveSize = 3000; diff --git a/PKHeX.Core/Saves/Substructures/Gen9/MyStatus9.cs b/PKHeX.Core/Saves/Substructures/Gen9/MyStatus9.cs index ec2d9a497..354c03d44 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/MyStatus9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/MyStatus9.cs @@ -3,7 +3,7 @@ namespace PKHeX.Core; -public sealed class MyStatus9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class MyStatus9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public uint ID32 { diff --git a/PKHeX.Core/Saves/Substructures/Gen9/Party9.cs b/PKHeX.Core/Saves/Substructures/Gen9/Party9.cs index a54f58a2b..c24c22f6b 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/Party9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/Party9.cs @@ -1,6 +1,6 @@ namespace PKHeX.Core; -public sealed class Party9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class Party9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public int PartyCount { diff --git a/PKHeX.Core/Saves/Substructures/Gen9/PlayTime9.cs b/PKHeX.Core/Saves/Substructures/Gen9/PlayTime9.cs index fc8509700..3387741ae 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/PlayTime9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/PlayTime9.cs @@ -2,7 +2,7 @@ namespace PKHeX.Core; -public sealed class PlayTime9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class PlayTime9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public int PlayedHours { diff --git a/PKHeX.Core/Saves/Substructures/Gen9/PlayerAppearance9.cs b/PKHeX.Core/Saves/Substructures/Gen9/PlayerAppearance9.cs index 59626bc94..72ec66a82 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/PlayerAppearance9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/PlayerAppearance9.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; /// Stores the selected facial appearances of the player. /// [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class PlayerAppearance9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class PlayerAppearance9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public ulong SkinColor { get => ReadUInt64LittleEndian(Data); set => WriteUInt64LittleEndian(Data, value); } public ulong LipColor { get => ReadUInt64LittleEndian(Data[0x08..]); set => WriteUInt64LittleEndian(Data[0x08..], value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen9/PlayerFashion9.cs b/PKHeX.Core/Saves/Substructures/Gen9/PlayerFashion9.cs index 4b2a3aac5..090942999 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/PlayerFashion9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/PlayerFashion9.cs @@ -7,7 +7,7 @@ namespace PKHeX.Core; /// Stores the selected clothing choices of the player. /// [TypeConverter(typeof(ExpandableObjectConverter))] -public sealed class PlayerFashion9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class PlayerFashion9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public ulong Base { get => ReadUInt64LittleEndian(Data); set => WriteUInt64LittleEndian(Data, value); } public ulong Accessory { get => ReadUInt64LittleEndian(Data[0x08..]); set => WriteUInt64LittleEndian(Data[0x08..], value); } diff --git a/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs b/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs index 63429f1c1..3a501f05e 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/RaidSevenStar9.cs @@ -60,7 +60,7 @@ public bool Defeated } } -public sealed class RaidSevenStarCaptured9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class RaidSevenStarCaptured9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { public readonly int CountAll = block.Data.Length / DetailSize; private const int DetailSize = SevenStarRaidCapturedDetail.SIZE; @@ -104,7 +104,7 @@ public bool Defeated // 0x06 - 0x07 padding } -public sealed class RaidSevenStarDefeated9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Data) +public sealed class RaidSevenStarDefeated9(SAV9SV sav, SCBlock block) : SaveBlock(sav, block.Raw) { // Structure matches the RaidSevenStarCapture9 but there are 4 bytes at the front to indicate if the copy of previous defeated flags happened when updating save public readonly int CountAll = (block.Data.Length - 0x04) / SevenStarRaidDefeatedDetail.SIZE; diff --git a/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs b/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs index 167da1e82..55a02b9d9 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/RaidSpawnList9.cs @@ -17,7 +17,7 @@ public sealed class RaidSpawnList9 : SaveBlock private readonly Memory Memory; private Span Span => Memory.Span; - public RaidSpawnList9(SAV9SV sav, SCBlock block, Memory memory, int countUsed, bool hasSeeds) : base(sav, block.Data) + public RaidSpawnList9(SAV9SV sav, SCBlock block, Memory memory, int countUsed, bool hasSeeds) : base(sav, block.Raw) { Memory = memory; var length = memory.Length; diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Kitakami.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Kitakami.cs index 0f434f02e..441be3310 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Kitakami.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Kitakami.cs @@ -14,7 +14,7 @@ public PokeDexEntry9Kitakami Get(ushort species) const int size = PokeDexEntry9Kitakami.SIZE; var internalSpecies = SpeciesConverter.GetInternal9(species); - var span = Block.Data.AsSpan(internalSpecies * size, size); + var span = Block.Data.Slice(internalSpecies * size, size); return new PokeDexEntry9Kitakami(span); } @@ -94,10 +94,7 @@ private ushort GetSpecies(byte group, int index) return (0, 0); } - public override void SeenNone() - { - Array.Clear(Block.Data, 0, Block.Data.Length); - } + public override void SeenNone() => Block.Data.Clear(); public override void CaughtNone() { diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Paldea.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Paldea.cs index 9703c0278..2bd3ace73 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Paldea.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Gen9/Zukan9Paldea.cs @@ -5,7 +5,7 @@ namespace PKHeX.Core; /// /// Pokédex structure used for . /// > -public sealed class Zukan9Paldea(SAV9SV sav, SCBlock block) : ZukanBase(sav, block.Data) +public sealed class Zukan9Paldea(SAV9SV sav, SCBlock block) : ZukanBase(sav, block.Raw) { public PokeDexEntry9Paldea Get(ushort species) { @@ -14,7 +14,7 @@ public PokeDexEntry9Paldea Get(ushort species) const int size = PokeDexEntry9Paldea.SIZE; var internalSpecies = SpeciesConverter.GetInternal9(species); - var span = block.Data.AsSpan(internalSpecies * size, size); + var span = block.Data.Slice(internalSpecies * size, size); return new PokeDexEntry9Paldea(span); } @@ -119,10 +119,7 @@ private ushort GetSpecies(byte group, int index) return default; } - public override void SeenNone() - { - Array.Clear(block.Data, 0, block.Data.Length); - } + public override void SeenNone() => block.Data.Clear(); public override void CaughtNone() { diff --git a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs index a585071ba..6396d761f 100644 --- a/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs +++ b/PKHeX.Core/Saves/Substructures/PokeDex/Zukan8.cs @@ -41,7 +41,7 @@ public int GetRevision() return 2; } - private byte[] GetDexBlock(Zukan8Type infoDexType) => infoDexType switch + private Span GetDexBlock(Zukan8Type infoDexType) => infoDexType switch { Zukan8Type.Galar => Galar.Data, Zukan8Type.Armor => Rigel1.Data, @@ -49,8 +49,8 @@ public int GetRevision() _ => throw new ArgumentOutOfRangeException(nameof(infoDexType), infoDexType, null), }; - private static bool GetFlag(byte[] data, int baseOffset, int bitIndex) => FlagUtil.GetFlag(data, baseOffset + (bitIndex >> 3), bitIndex); - private static void SetFlag(byte[] data, int baseOffset, int bitIndex, bool value = true) => FlagUtil.SetFlag(data, baseOffset + (bitIndex >> 3), bitIndex, value); + private static bool GetFlag(ReadOnlySpan data, int baseOffset, int bitIndex) => FlagUtil.GetFlag(data, baseOffset + (bitIndex >> 3), bitIndex); + private static void SetFlag(Span data, int baseOffset, int bitIndex, bool value = true) => FlagUtil.SetFlag(data, baseOffset + (bitIndex >> 3), bitIndex, value); private static Dictionary GetDexLookup(PersonalTable8SWSH pt, int dexRevision, int count) { @@ -177,12 +177,12 @@ public override bool GetSeen(ushort species) public bool GetSeen(Zukan8Index entry) { - byte[] data = GetDexBlock(entry.DexType); + var data = GetDexBlock(entry.DexType); int offset = entry.Offset; for (int i = 0; i < SeenRegionCount; i++) { var ofs = offset + (SeenRegionSize * i); - if (ReadUInt64LittleEndian(data.AsSpan(ofs)) != 0) + if (ReadUInt64LittleEndian(data[ofs..]) != 0) return true; } @@ -304,7 +304,7 @@ public uint GetFormDisplayed(Zukan8Index entry) { var data = GetDexBlock(entry.DexType); var index = entry.Offset; - var value = ReadUInt32LittleEndian(data.AsSpan(index + OFS_CAUGHT)); + var value = ReadUInt32LittleEndian(data[(index + OFS_CAUGHT)..]); return (value >> 15) & 0x1FFF; // (0x1FFF is really overkill, GameFreak) } @@ -320,7 +320,7 @@ public void SetFormDisplayed(Zukan8Index entry, uint value = 0) { var data = GetDexBlock(entry.DexType); var index = entry.Offset; - var span = data.AsSpan(index + OFS_CAUGHT); + var span = data[(index + OFS_CAUGHT)..]; var current = ReadUInt32LittleEndian(span); uint update = (current & ~(0x1FFFu << 15)) | ((value & 0x1FFF) << 15); WriteUInt32LittleEndian(span, update); @@ -338,7 +338,7 @@ public uint GetGenderDisplayed(Zukan8Index entry) { var data = GetDexBlock(entry.DexType); var index = entry.Offset; - var value = ReadUInt32LittleEndian(data.AsSpan(index + OFS_CAUGHT)); + var value = ReadUInt32LittleEndian(data[(index + OFS_CAUGHT)..]); return (value >> 29) & 3; } @@ -354,7 +354,7 @@ public void SetGenderDisplayed(Zukan8Index entry, uint value = 0) { var data = GetDexBlock(entry.DexType); var index = entry.Offset; - var span = data.AsSpan(index + OFS_CAUGHT); + var span = data[(index + OFS_CAUGHT)..]; var current = ReadUInt32LittleEndian(span); uint update = (current & ~(3u << 29)) | ((value & 3) << 29); WriteUInt32LittleEndian(span, update); @@ -432,7 +432,7 @@ private uint GetU32(Zukan8Index entry, int ofs) var dex = entry.DexType; var index = entry.Offset; var data = GetDexBlock(dex); - return ReadUInt32LittleEndian(data.AsSpan(index + ofs)); + return ReadUInt32LittleEndian(data[(index + ofs)..]); } private void SetU32(ushort species, uint value, int ofs) @@ -448,7 +448,7 @@ private void SetU32(Zukan8Index entry, uint value, int ofs) var dex = entry.DexType; var index = entry.Offset; var data = GetDexBlock(dex); - WriteUInt32LittleEndian(data.AsSpan(index + ofs), value); + WriteUInt32LittleEndian(data[(index + ofs)..], value); } #endregion @@ -500,9 +500,9 @@ public override void SetDex(PKM pk) public override void SeenNone() { - Galar .Data.AsSpan().Clear(); - Rigel1.Data.AsSpan().Clear(); - Rigel2.Data.AsSpan().Clear(); + Galar .Data.Clear(); + Rigel1.Data.Clear(); + Rigel2.Data.Clear(); } public override void CaughtNone() @@ -661,7 +661,7 @@ public override void ClearDexEntryAll(ushort species) private void ClearDexEntryAll(Zukan8Index entry) { var data = GetDexBlock(entry.DexType); - Array.Clear(data, entry.Offset, EntrySize); + data.Slice(entry.Offset, EntrySize).Clear(); } public void SetAllBattledCount(uint count = 500) diff --git a/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs b/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs index c8077062f..9de52c10f 100644 --- a/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs +++ b/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateTimeValue.cs @@ -12,7 +12,7 @@ public sealed class Epoch1900DateTimeValue(Memory Data) : EpochDateTime(Da // Data should be 4 or 8 bytes where we only care about the first 4 or 4.5 bytes i.e. 32 or 36 bits // First 12 bits are year from 1900, next 4 bits are 0 indexed month, next 5 are days, next 5 are hours, next 6 bits are minutes, (optional) last 4 bits are seconds - public Epoch1900DateTimeValue(SCBlock block) : this(block.Data) { } + public Epoch1900DateTimeValue(SCBlock block) : this(block.Raw) { } private static DateTime Epoch => new(1900, 1, 1); diff --git a/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateValue.cs b/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateValue.cs index 1bc55451a..b117659d4 100644 --- a/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateValue.cs +++ b/PKHeX.Core/Saves/Substructures/Time/Epoch1900DateValue.cs @@ -14,7 +14,7 @@ public sealed class Epoch1900DateValue(Memory Data) // First 12 bits are year from 1900, next 6 bits are 0 indexed month, next 6 are days private Span Span => Data.Span; - public Epoch1900DateValue(SCBlock block) : this(block.Data) { } + public Epoch1900DateValue(SCBlock block) : this(block.Raw) { } private static DateTime Epoch => new(1900, 1, 1); diff --git a/PKHeX.Core/Saves/Substructures/Time/Epoch1970Value.cs b/PKHeX.Core/Saves/Substructures/Time/Epoch1970Value.cs index bf2830e67..1359cc264 100644 --- a/PKHeX.Core/Saves/Substructures/Time/Epoch1970Value.cs +++ b/PKHeX.Core/Saves/Substructures/Time/Epoch1970Value.cs @@ -12,7 +12,7 @@ public sealed class Epoch1970Value(Memory Data) { private Span Span => Data.Span; - public Epoch1970Value(SCBlock block) : this(block.Data) { } + public Epoch1970Value(SCBlock block) : this(block.Raw) { } /// /// time_t (seconds since 1970 Epoch) diff --git a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs index 322aaa84f..e9e73046e 100644 --- a/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs +++ b/PKHeX.WinForms/Subforms/Save Editors/Gen8/SAV_BlockDump8.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Text; using System.Windows.Forms; using PKHeX.Core; using static PKHeX.Core.SCBlockUtil; @@ -80,7 +81,11 @@ private void UpdateBlockSummaryControls() { var block = CurrentBlock; L_Detail_R.Text = GetBlockSummary(block); - RTB_Hex.Text = string.Join(' ', block.Data.Select(z => $"{z:X2}")); + + var sb = new StringBuilder(); + foreach (var b in block.Data) + sb.Append($"{b:X2} "); + RTB_Hex.Text = sb.ToString(); var blockName = Metadata.GetBlockName(block, out var obj); if (blockName != null)