From 8bdbc4744a132aea5608981f1bf04ce789981d59 Mon Sep 17 00:00:00 2001 From: Xiaro <62033805+Xiaro@users.noreply.github.com> Date: Fri, 8 Jan 2021 17:34:34 -0500 Subject: [PATCH] [fix] Proper fix for StorageESP NPE crash closes #1820 --- .../kami/module/modules/render/Search.kt | 4 +- .../kami/module/modules/render/StorageESP.kt | 13 ++-- .../kami/util/graphics/ESPRenderer.kt | 61 ++++++------------- 3 files changed, 30 insertions(+), 48 deletions(-) diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/render/Search.kt b/src/main/java/me/zeroeightsix/kami/module/modules/render/Search.kt index 42605e66e..1ab16b748 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/render/Search.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/render/Search.kt @@ -153,7 +153,9 @@ object Search : Module( val dist = eyePos.distanceTo(pos) if (dist > range) continue - map[dist] = (pos to blockState) + synchronized(map) { + map[dist] = (pos to blockState) + } } } diff --git a/src/main/java/me/zeroeightsix/kami/module/modules/render/StorageESP.kt b/src/main/java/me/zeroeightsix/kami/module/modules/render/StorageESP.kt index 45d6eef92..480042142 100644 --- a/src/main/java/me/zeroeightsix/kami/module/modules/render/StorageESP.kt +++ b/src/main/java/me/zeroeightsix/kami/module/modules/render/StorageESP.kt @@ -78,7 +78,6 @@ object StorageESP : Module( if (it.phase != TickEvent.Phase.START) return@safeAsyncListener cycler++ - renderer.clear() val cached = ArrayList>() coroutineScope { @@ -120,7 +119,9 @@ object StorageESP : Module( if (tileEntity.adjacentChestXNeg != null) side = (side and GeometryMasks.Quad.WEST).inv() } - list.add(Triple(box, color, side)) + synchronized(list) { + list.add(Triple(box, color, side)) + } } } @@ -154,12 +155,14 @@ object StorageESP : Module( val box = entity.renderBoundingBox ?: continue val color = getEntityColor(entity) ?: continue - list.add(Triple(box, color, GeometryMasks.Quad.ALL)) + synchronized(list) { + list.add(Triple(box, color, GeometryMasks.Quad.ALL)) + } } } private fun checkEntityType(entity: Entity) = - entity is EntityItemFrame && frameShulkerOrAny(entity) + entity is EntityItemFrame && frame && (!withShulkerOnly || entity.displayedItem.item is ItemShulkerBox) || (entity is EntityMinecartChest || entity is EntityMinecartHopper || entity is EntityMinecartFurnace) && cart private fun getEntityColor(entity: Entity): ColorHolder? { @@ -173,6 +176,4 @@ object StorageESP : Module( } else color } - private fun frameShulkerOrAny(entity: EntityItemFrame) = - frame && (!withShulkerOnly || entity.displayedItem.item is ItemShulkerBox) } diff --git a/src/main/java/me/zeroeightsix/kami/util/graphics/ESPRenderer.kt b/src/main/java/me/zeroeightsix/kami/util/graphics/ESPRenderer.kt index a36aaf2e0..b13631dd9 100644 --- a/src/main/java/me/zeroeightsix/kami/util/graphics/ESPRenderer.kt +++ b/src/main/java/me/zeroeightsix/kami/util/graphics/ESPRenderer.kt @@ -19,9 +19,8 @@ import org.lwjgl.opengl.GL11.GL_QUADS * Created by Xiaro on 30/07/20 */ class ESPRenderer { - private var toRender: MutableList>? = ArrayList() - private val lockObject = Any() private val frustumCamera: ICamera = Frustum() + private var toRender: MutableList> = ArrayList() var aFilled = 0 var aOutline = 0 @@ -32,7 +31,7 @@ class ESPRenderer { var fullOutline = false val size: Int - get() = toRender?.size ?: 0 + get() = toRender?.size fun add(entity: Entity, color: ColorHolder) { add(entity, color, GeometryMasks.Quad.ALL) @@ -60,61 +59,41 @@ class ESPRenderer { } fun add(triple: Triple) { - synchronized(lockObject) { - getListNotNull().add(triple) - } + toRender.add(triple) } fun replaceAll(list: MutableList>) { - synchronized(lockObject) { - toRender = list - } + toRender = list } fun clear() { - synchronized(lockObject) { - getListNotNull().clear() - } - } - - private fun getListNotNull(): MutableList> { - synchronized(lockObject) { - return toRender ?: ArrayList>().also { replaceAll(it) } - } + toRender.clear() } fun render(clear: Boolean, cull: Boolean = true) { - synchronized(lockObject) { - if (aFilled == 0 && aOutline == 0 && aTracer == 0) return + if (toRender.isEmpty() && (aFilled == 0 && aOutline == 0 && aTracer == 0)) return - val list = toRender ?: return + val entity = Wrapper.minecraft.renderViewEntity ?: Wrapper.player ?: return + val interpolatedPos = EntityUtils.getInterpolatedPos(entity, KamiTessellator.pTicks()) + frustumCamera.setPosition(interpolatedPos.x, interpolatedPos.y, interpolatedPos.z) - if (list.isEmpty()) return + if (through) GlStateManager.disableDepth() - val entity = Wrapper.minecraft.renderViewEntity ?: Wrapper.player ?: return - val interpolatedPos = EntityUtils.getInterpolatedPos(entity, KamiTessellator.pTicks()) - frustumCamera.setPosition(interpolatedPos.x, interpolatedPos.y, interpolatedPos.z) + if (aFilled != 0) drawList(Type.FILLED, cull) + if (aOutline != 0) drawList(Type.OUTLINE, cull) + if (aTracer != 0) drawList(Type.TRACER, cull) - if (through) GlStateManager.disableDepth() - - if (aFilled != 0) drawList(list, Type.FILLED, cull) - if (aOutline != 0) drawList(list, Type.OUTLINE, cull) - if (aTracer != 0) drawList(list, Type.TRACER, cull) - if (clear) clear() - - GlStateManager.enableDepth() - } + if (clear) clear() + GlStateManager.enableDepth() } - private fun drawList(list: List>, type: Type, cull: Boolean = false) { + private fun drawList(type: Type, cull: Boolean = false) { KamiTessellator.begin(if (type == Type.FILLED) GL_QUADS else GL_LINES) - for ((box, color, sides) in list) { - when (type) { - Type.FILLED -> drawFilled(cull, box, color, sides) - Type.OUTLINE -> drawOutline(cull, box, color, sides) - Type.TRACER -> drawTracer(box, color) - } + for ((box, color, sides) in toRender) when (type) { + Type.FILLED -> drawFilled(cull, box, color, sides) + Type.OUTLINE -> drawOutline(cull, box, color, sides) + Type.TRACER -> drawTracer(box, color) } KamiTessellator.render()