From 0aa063d28582eede7793965faf6322fb0d17192c Mon Sep 17 00:00:00 2001 From: kuroppoi <68156848+kuroppoi@users.noreply.github.com> Date: Mon, 7 Jun 2021 19:49:04 +0200 Subject: [PATCH] Fixed crash caused by out-of-bounds linked block positions --- .../main/java/brainwine/gameserver/zone/Zone.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java b/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java index 2f89ef4..93c1168 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java @@ -395,11 +395,17 @@ public class Zone { for(List position : positions) { int pX = position.get(0); int pY = position.get(1); + int pIndex = pY * width + pX; + int pOffset = 0; + + // Make sure that the linked block is in bounds + if(pIndex >= 0 && pIndex < blocks.length) { + // Create an offset in case the block is bigger than 1x1 + Item linkedItem = blocks[pIndex].getFrontItem(); + linkedItem = replacedItems.getOrDefault(linkedItem, linkedItem); + pOffset = -(linkedItem.getBlockWidth() - 1); + } - // Create an offset in case the block is bigger than 1x1 - Item linkedItem = blocks[pY * width + pX].getFrontItem(); - linkedItem = replacedItems.getOrDefault(linkedItem, linkedItem); - int pOffset = -(linkedItem.getBlockWidth() - 1); position.set(0, (mirrored ? width - 1 - pX + pOffset : pX) + x); position.set(1, position.get(1) + y); }