From 18fc90ac3512273a9d17a134092c67d80ccd27e7 Mon Sep 17 00:00:00 2001 From: Francis Dionne <96087943+FrancisDionne@users.noreply.github.com> Date: Thu, 5 Dec 2024 16:15:50 -0800 Subject: [PATCH] [#1797] Fixed out of bound exceptions when navigating with the mouse/controller in the item overflow screen (#1795) * Fixed two out of bound exceptions when using the mouse/controller and hovering an empty slot when the max item amount is lower than 7 * Fixed overflow menu out of bounds when going up on controller and having less than 7 item limit * Fixed out of bounds on cursor click on empty row in overflow menu * Fixed more out of bounds exception in the overflow menu --- .../inventory/screens/TooManyItemsScreen.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/legend/game/inventory/screens/TooManyItemsScreen.java b/src/main/java/legend/game/inventory/screens/TooManyItemsScreen.java index 92e7e242b..7d307942f 100644 --- a/src/main/java/legend/game/inventory/screens/TooManyItemsScreen.java +++ b/src/main/java/legend/game/inventory/screens/TooManyItemsScreen.java @@ -127,8 +127,8 @@ protected void render() { this.invScroll--; this.renderable_8011e204.y_44 = this.FUN_8010f178(this.invIndex); } else if(this.invScroll == 0) { - this.invScroll = slotCount - 7; - this.invIndex = 6; + this.invScroll = Math.max(0, slotCount - 7); + this.invIndex = this.invScroll > 0 ? 6 : 0; this.renderable_8011e204.y_44 = this.FUN_8010f178(this.invIndex); } } @@ -209,7 +209,9 @@ private void FUN_8010fd80(final boolean allocate, final InventoryEntry inv, fina } if((a4 & 0x2) != 0) { - renderString(194, 164, I18n.translate(this.items.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate); + if(slotScroll + slotIndex < this.items.size()) { + renderString(194, 164, I18n.translate(this.items.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate); + } final Renderable58 renderable = allocateOneFrameGlyph(137, 84, 140); renderable.clut_30 = 0x7ceb; @@ -223,7 +225,9 @@ private void FUN_8010fd80(final boolean allocate, final InventoryEntry inv, fina } if((a4 & 0x2) != 0) { - renderString(194, 164, I18n.translate(this.equipment.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate); + if(slotScroll + slotIndex < this.equipment.size()) { + renderString(194, 164, I18n.translate(this.equipment.get(slotScroll + slotIndex).getDescriptionTranslationKey()), allocate); + } final Renderable58 renderable = allocateOneFrameGlyph(137, 84, 140); renderable.clut_30 = 0x7ceb; @@ -255,7 +259,7 @@ protected InputPropagation mouseMove(final int x, final int y) { } } } else if(this.menuState == MenuState._9) { - for(int i = 0; i < 7; i++) { + for(int i = 0; i < this.items.size(); i++) { if(this.invIndex != i && MathHelper.inBox(x, y, 188, this.FUN_8010f178(i), 171, 17)) { playMenuSound(1); this.invIndex = i; @@ -339,8 +343,8 @@ private void handleInventoryScrollUp() { } if(this.invIndex == 0 && this.invScroll == 0) { - this.invScroll = slotCount - 7; - this.invIndex = 7; + this.invScroll = Math.max(0, slotCount - 7); + this.invIndex = Math.min(slotCount, 7); } } @@ -351,7 +355,7 @@ private void handleInventoryScrollDown() { this.invScroll++; } - if(this.invIndex == 6 && this.invScroll == slotCount - 7) { + if((this.invIndex == 6 && this.invScroll == slotCount - 7) || (this.invScroll < 1 && this.invIndex >= slotCount - 1)) { this.invScroll = 0; this.invIndex = -1; } @@ -442,6 +446,10 @@ private void selectMenuState9() { final MenuEntryStruct04 newItem = this.droppedItems.get(this.dropIndex); final boolean isItem = this.droppedItems.get(this.dropIndex).item_00 instanceof Item; + if(this.invIndex + this.invScroll > this.items.size() - 1) { + return; + } + if(((isItem ? this.items : this.equipment).get(this.invIndex + this.invScroll).flags_02 & 0x6000) != 0) { playMenuSound(40); } else {