From 43c036641d981453a6bdc00d362c8beabbb9db8e Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Sun, 9 Oct 2016 18:38:04 -0700 Subject: [PATCH] Use MaxCount when storing items Rewritten, HaX can now bypass this limit (still constrained for overflow) Closes #314 , thanks @Ninjistix ! --- PKHeX/Subforms/Save Editors/SAV_Inventory.cs | 30 +++++++++++--------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/PKHeX/Subforms/Save Editors/SAV_Inventory.cs b/PKHeX/Subforms/Save Editors/SAV_Inventory.cs index 9685261b1..b56321dd3 100644 --- a/PKHeX/Subforms/Save Editors/SAV_Inventory.cs +++ b/PKHeX/Subforms/Save Editors/SAV_Inventory.cs @@ -178,21 +178,25 @@ private void packBags() { string item = dgv.Rows[i].Cells[0].Value.ToString(); int itemindex = Array.IndexOf(itemlist, item); - int itemcnt; - try - { itemcnt = Convert.ToUInt16(dgv.Rows[i].Cells[1].Value.ToString()); } - catch { itemcnt = 0; } - - if (itemcnt == 0) - itemcnt++; // No 0 count of items - else if (itemcnt > 995) - itemcnt = 995; // cap out - else if (itemcnt > 99 && SAV.Generation <= 3) - itemcnt = 99; - - if (itemindex == 0) // Compression of Empty Slots + if (itemindex <= 0) // Compression of Empty Slots continue; + int itemcnt; + int.TryParse(dgv.Rows[i].Cells[1].Value.ToString(), out itemcnt); + + if (Main.HaX) + { + // Cap at absolute maximum + if (SAV.Generation <= 2 && itemcnt > byte.MaxValue) + itemcnt = byte.MaxValue; + else if (SAV.Generation >= 3 && itemcnt > ushort.MaxValue) + itemcnt = ushort.MaxValue; + } + else if (itemcnt > t.MaxCount) + itemcnt = t.MaxCount; // Cap at pouch maximum + else if (itemcnt <= 0) + itemcnt = 1; + t.Items[ctr++] = new InventoryItem {Index = itemindex, Count = itemcnt}; } for (int i = ctr; i < t.Items.Length; i++)