From 98713f4d7b5675d3dd672e9ebb0cddbc2142f3bd Mon Sep 17 00:00:00 2001 From: Kurt Date: Mon, 13 Dec 2021 18:31:00 -0800 Subject: [PATCH] Move inventory item clearing to class Fixes ClearItem offset being wrong --- PKHeX.Core/Saves/Substructures/Gen8/BS/MyItem8b.cs | 2 +- PKHeX.Core/Saves/Substructures/Inventory/InventoryItem8b.cs | 4 ++++ .../Saves/Substructures/Inventory/InventoryPouch8b.cs | 6 ++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PKHeX.Core/Saves/Substructures/Gen8/BS/MyItem8b.cs b/PKHeX.Core/Saves/Substructures/Gen8/BS/MyItem8b.cs index 71bb036c1..6992281eb 100644 --- a/PKHeX.Core/Saves/Substructures/Gen8/BS/MyItem8b.cs +++ b/PKHeX.Core/Saves/Substructures/Gen8/BS/MyItem8b.cs @@ -99,7 +99,7 @@ private void CleanIllegalSlots() for (ushort i = 0; i < (ushort)SAV.MaxItemID; i++) // even though there are 3000, just overwrite the ones that people will mess up. { if (!hashSet.Contains(i)) - InventoryPouch8b.ClearItem(Data, InventoryPouch8b.GetItemOffset(i, Offset)); + InventoryItem8b.Clear(Data, InventoryPouch8b.GetItemOffset(i, Offset)); } } diff --git a/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem8b.cs b/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem8b.cs index 4f9c6cdfd..ee045a075 100644 --- a/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem8b.cs +++ b/PKHeX.Core/Saves/Substructures/Inventory/InventoryItem8b.cs @@ -4,6 +4,8 @@ namespace PKHeX.Core { public sealed class InventoryItem8b : InventoryItem, IItemFavorite, IItemNew { + public const int SIZE = 0x10; + public bool IsFavorite { get; set; } public bool IsNew { get; set; } public ushort SortOrder { get; set; } @@ -38,6 +40,8 @@ public void Write(byte[] data, int offset) BitConverter.GetBytes((ushort)0).CopyTo(data, offset + 0xE); } + public static void Clear(byte[] data, int offset) => Array.Clear(data, offset, SIZE); + public override void SetNewDetails(int count) { base.SetNewDetails(count); diff --git a/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch8b.cs b/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch8b.cs index 547b581d9..c52316033 100644 --- a/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch8b.cs +++ b/PKHeX.Core/Saves/Substructures/Inventory/InventoryPouch8b.cs @@ -6,8 +6,6 @@ namespace PKHeX.Core { public sealed class InventoryPouch8b : InventoryPouch { - private const int SIZE_ITEM = 0x10; - public bool SetNew { get; set; } public InventoryPouch8b(InventoryType type, ushort[] legal, int maxCount, int offset, @@ -84,8 +82,8 @@ public override void SetPouch(byte[] data) } } - public static int GetItemOffset(ushort index, int baseOffset) => baseOffset + (SIZE_ITEM * index); + public static int GetItemOffset(ushort index, int baseOffset) => baseOffset + (InventoryItem8b.SIZE * index); - public static void ClearItem(byte[] data, int ofs) => Array.Clear(data, ofs, 0x10); + public void ClearItem(byte[] data, ushort index) => InventoryItem8b.Clear(data, GetItemOffset(index, Offset)); } }