[fix] Proper fix for StorageESP NPE crash

closes #1820
This commit is contained in:
Xiaro 2021-01-08 17:34:34 -05:00
parent b23e73968d
commit 8bdbc4744a
No known key found for this signature in database
GPG Key ID: 996D265D6E155377
3 changed files with 30 additions and 48 deletions

View File

@ -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)
}
}
}

View File

@ -78,7 +78,6 @@ object StorageESP : Module(
if (it.phase != TickEvent.Phase.START) return@safeAsyncListener
cycler++
renderer.clear()
val cached = ArrayList<Triple<AxisAlignedBB, ColorHolder, Int>>()
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)
}

View File

@ -19,9 +19,8 @@ import org.lwjgl.opengl.GL11.GL_QUADS
* Created by Xiaro on 30/07/20
*/
class ESPRenderer {
private var toRender: MutableList<Triple<AxisAlignedBB, ColorHolder, Int>>? = ArrayList()
private val lockObject = Any()
private val frustumCamera: ICamera = Frustum()
private var toRender: MutableList<Triple<AxisAlignedBB, ColorHolder, Int>> = 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<AxisAlignedBB, ColorHolder, Int>) {
synchronized(lockObject) {
getListNotNull().add(triple)
}
toRender.add(triple)
}
fun replaceAll(list: MutableList<Triple<AxisAlignedBB, ColorHolder, Int>>) {
synchronized(lockObject) {
toRender = list
}
toRender = list
}
fun clear() {
synchronized(lockObject) {
getListNotNull().clear()
}
}
private fun getListNotNull(): MutableList<Triple<AxisAlignedBB, ColorHolder, Int>> {
synchronized(lockObject) {
return toRender ?: ArrayList<Triple<AxisAlignedBB, ColorHolder, Int>>().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<Triple<AxisAlignedBB, ColorHolder, Int>>, 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()