diff --git a/PKHeX.Core/Saves/Substructures/Gen9/ZA/MyItem9a.cs b/PKHeX.Core/Saves/Substructures/Gen9/ZA/MyItem9a.cs index 45ae67f69..a65abf677 100644 --- a/PKHeX.Core/Saves/Substructures/Gen9/ZA/MyItem9a.cs +++ b/PKHeX.Core/Saves/Substructures/Gen9/ZA/MyItem9a.cs @@ -117,7 +117,7 @@ private static InventoryPouch9a MakePouch(InventoryType type) return new InventoryPouch9a(type, info, max, GetPouchIndex(type)); } - private static uint GetPouchIndex(InventoryType type) => type switch + public static uint GetPouchIndex(InventoryType type) => type switch { InventoryType.Items => InventoryItem9a.PouchOther, InventoryType.KeyItems => InventoryItem9a.PouchKey, diff --git a/PKHeX.Core/Saves/Substructures/Inventory/Item/InventoryItem9a.cs b/PKHeX.Core/Saves/Substructures/Inventory/Item/InventoryItem9a.cs index 127e32a83..029dfa200 100644 --- a/PKHeX.Core/Saves/Substructures/Inventory/Item/InventoryItem9a.cs +++ b/PKHeX.Core/Saves/Substructures/Inventory/Item/InventoryItem9a.cs @@ -64,10 +64,6 @@ public static InventoryItem9a Read(ushort index, ReadOnlySpan data) => new public void Write(Span data) { - // Ensure the updated flag state is as expected. - if (Pouch == PouchNone) - Flags = DefaultFlagValue; - // Index is not saved. WriteUInt32LittleEndian(data, Pouch); WriteUInt32LittleEndian(data[4..], (uint)Count); diff --git a/PKHeX.Core/Saves/Substructures/Inventory/Pouch/InventoryPouch9a.cs b/PKHeX.Core/Saves/Substructures/Inventory/Pouch/InventoryPouch9a.cs index 65ac7a693..fba94e2c1 100644 --- a/PKHeX.Core/Saves/Substructures/Inventory/Pouch/InventoryPouch9a.cs +++ b/PKHeX.Core/Saves/Substructures/Inventory/Pouch/InventoryPouch9a.cs @@ -10,7 +10,16 @@ public sealed class InventoryPouch9a(InventoryType type, IItemStorage info, int public bool SetNew { get; set; } public uint PouchIndex { get; set; } = pouch; - public override InventoryItem9a GetEmpty(int itemID = 0, int count = 0) => new() { Index = itemID, Count = count, IsNew = count != 0 }; + public override InventoryItem9a GetEmpty(int itemID = 0, int count = 0) => new() + { + Index = itemID, + Pouch = MyItem9a.GetPouchIndex(ItemStorage9ZA.GetInventoryPouch((ushort)itemID)), + Count = count, + IsNewShop = true, + IsNewNotify = true, + IsNew = true, + }; + public static int GetItemOffset(ushort index) => InventoryItem9a.SIZE * index; public static Span GetItemSpan(Span block, ushort index) => block.Slice(GetItemOffset(index), InventoryItem9a.SIZE); @@ -74,6 +83,11 @@ public override void SetPouch(Span block) private void EnsureFlagsConsistent(InventoryItem9a item, InventoryItem9a original) { + if (item.Index == 0x14) + { + + } + item.Pouch = PouchIndex; // ensure the pouch is set if (item.Count != 0) { // Ensure the flag is set; 0->X and Y->Z @@ -81,6 +95,11 @@ private void EnsureFlagsConsistent(InventoryItem9a item, InventoryItem9a origina item.IsNew = true; item.IsNewNotify = false; } + else if (original.Count == 0) + { + item.Flags = original.Flags; + item.Pouch = original.Pouch; + } } public static void SetQuantityZero(Span block, ushort index)