From 786fa14d8993a1e6d79960c6ec4e3a301f04852b Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sat, 3 Jun 2023 09:07:50 -0700 Subject: [PATCH 1/3] Search: old signs + prevent possible concurrent modification --- .../client/module/modules/render/Search.kt | 76 +++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt b/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt index 31e1a09f9..c0bdc1e54 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt @@ -10,9 +10,11 @@ import com.lambda.client.module.Category import com.lambda.client.module.Module import com.lambda.client.module.modules.client.Hud import com.lambda.client.setting.settings.impl.collection.CollectionSetting +import com.lambda.client.util.EntityUtils import com.lambda.client.util.color.ColorHolder import com.lambda.client.util.graphics.ESPRenderer import com.lambda.client.util.graphics.GeometryMasks +import com.lambda.client.util.graphics.LambdaTessellator import com.lambda.client.util.graphics.ShaderHelper import com.lambda.client.util.math.VectorUtils.distanceTo import com.lambda.client.util.text.MessageSendHelper @@ -26,14 +28,19 @@ import kotlinx.coroutines.isActive import kotlinx.coroutines.launch import net.minecraft.block.BlockEnderChest import net.minecraft.block.BlockShulkerBox +import net.minecraft.block.BlockStandingSign +import net.minecraft.block.BlockWallSign +import net.minecraft.block.state.BlockStateContainer.StateImplementation import net.minecraft.block.state.IBlockState import net.minecraft.entity.EntityList import net.minecraft.entity.item.EntityItemFrame import net.minecraft.init.Blocks import net.minecraft.network.play.server.SPacketBlockChange import net.minecraft.network.play.server.SPacketMultiBlockChange +import net.minecraft.tileentity.TileEntitySign import net.minecraft.util.math.BlockPos import net.minecraft.util.math.ChunkPos +import net.minecraft.util.text.TextComponentString import net.minecraft.world.chunk.Chunk import net.minecraftforge.fml.common.gameevent.TickEvent import java.util.concurrent.ConcurrentHashMap @@ -52,6 +59,8 @@ object Search : Module( private val blockSearch by setting("Block Search", true) private val illegalBedrock = setting("Illegal Bedrock", false) private val illegalNetherWater = setting("Illegal Nether Water", false) + private val oldSigns = setting("Old Signs", true) + private val oldSignsColor by setting("Old Signs Color", ColorHolder(220, 0, 0, 110), visibility = { oldSigns.value }) private val range by setting("Search Range", 512, 0..4096, 8) private val yRangeBottom by setting("Top Y", 256, 0..256, 1) private val yRangeTop by setting("Bottom Y", 0, 0..256, 1) @@ -78,6 +87,8 @@ object Search : Module( private val blockRenderer = ESPRenderer() private val entityRenderer = ESPRenderer() private val foundBlockMap: ConcurrentMap = ConcurrentHashMap() + private val foundEntityUpdateLock = Any() + private val foundBlocksUpdateLock = Any() private var blockRenderUpdateJob: Job? = null private var entityRenderUpdateJob: Job? = null private var blockSearchJob: Job? = null @@ -91,6 +102,7 @@ object Search : Module( blockSearchList.editListeners.add { blockSearchListUpdateListener(isEnabled) } illegalBedrock.listeners.add { blockSearchListUpdateListener(illegalBedrock.value) } illegalNetherWater.listeners.add { blockSearchListUpdateListener(illegalNetherWater.value) } + oldSigns.listeners.add { blockSearchListUpdateListener(oldSigns.value) } onEnable { if (!overrideWarning && ShaderHelper.isIntegratedGraphics) { @@ -118,12 +130,16 @@ object Search : Module( } if (blockSearch) { if (!(hideF1 && mc.gameSettings.hideGUI)) { - blockRenderer.render(false) + synchronized(foundBlocksUpdateLock) { + blockRenderer.render(false) + } } } if (entitySearch) { if (!(hideF1 && mc.gameSettings.hideGUI)) { - entityRenderer.render(false) + synchronized(foundEntityUpdateLock) { + entityRenderer.render(false) + } } } } @@ -191,16 +207,14 @@ object Search : Module( entitySearchDimensionFilter.value.find { dimFilter -> dimFilter.searchKey == entityName }?.dim }?.contains(player.dimension) ?: true } - .sortedBy { - it.distanceTo(player.getPositionEyes(1f)) - } + .sortedBy { it.distanceTo(player.getPositionEyes(1f)) } .take(maximumEntities) - .filter { - it.distanceTo(player.getPositionEyes(1f)) < range - } + .filter { it.distanceTo(player.getPositionEyes(1f)) < range } + .map { Triple(it.renderBoundingBox.offset(EntityUtils.getInterpolatedAmount(it, LambdaTessellator.pTicks())), entitySearchColor, GeometryMasks.Quad.ALL) } .toMutableList() - entityRenderer.clear() - renderList.forEach { entityRenderer.add(it, entitySearchColor) } + synchronized(foundEntityUpdateLock) { + entityRenderer.replaceAll(renderList) + } } private fun SafeClientEvent.searchAllLoadedChunks() { @@ -270,8 +284,9 @@ object Search : Module( } } .toMutableList() - - blockRenderer.replaceAll(renderList) + synchronized(foundBlocksUpdateLock) { + blockRenderer.replaceAll(renderList) + } } private fun updateAlpha() { @@ -294,6 +309,11 @@ object Search : Module( for (y in yRange) for (x in xRange) for (z in zRange) { val pos = BlockPos(x, y, z) val blockState = chunk.getBlockState(pos) + if (isOldSign(blockState, pos)) { + val signState = if (blockState.block == Blocks.STANDING_SIGN) OldStandingSign(blockState) else OldWallSign(blockState) + blocks.add((pos to signState)) + continue // skip searching for regular sign at this pos + } if (searchQuery(blockState, pos)) blocks.add(pos to blockState) } return blocks @@ -304,8 +324,8 @@ object Search : Module( if (block == Blocks.AIR) return false return (blockSearchList.contains(block.registryName.toString()) && blockSearchDimensionFilter.value.find { dimFilter -> - dimFilter.searchKey == block.registryName.toString() - }?.dim?.contains(player.dimension) ?: true) + dimFilter.searchKey == block.registryName.toString() + }?.dim?.contains(player.dimension) ?: true) || isIllegalBedrock(state, pos) || isIllegalWater(state) } @@ -331,6 +351,24 @@ object Search : Module( return player.dimension == -1 && state.isWater } + private fun SafeClientEvent.isOldSign(state: IBlockState, pos: BlockPos): Boolean { + if (!oldSigns.value) return false + return (state.block == Blocks.STANDING_SIGN || state.block == Blocks.WALL_SIGN) && isOldSignText(pos) + } + + private fun SafeClientEvent.isOldSignText(pos: BlockPos): Boolean { + // Explanation: Old signs on 2b2t (pre-2015 <1.9 ?) have older style NBT text tags. + // we can tell them apart by checking if there are siblings in the tag. Old signs won't have siblings. + val signTextComponents = listOf(world.getTileEntity(pos)) + .filterIsInstance() + .flatMap { it.signText.toList() } + .filterIsInstance() + .toList() + return signTextComponents.isNotEmpty() + && signTextComponents.all { it.siblings.size == 0 } + && !signTextComponents.all { it.text.isEmpty() } + } + private fun SafeClientEvent.getBlockColor(pos: BlockPos, blockState: IBlockState): ColorHolder { val block = blockState.block return if (autoBlockColor) { @@ -345,6 +383,12 @@ object Search : Module( is BlockEnderChest -> { ColorHolder(64, 49, 114) } + is BlockOldStandingSign -> { + oldSignsColor + } + is BlockOldWallSign -> { + oldSignsColor + } else -> { val colorInt = blockState.getMapColor(world, pos).colorValue ColorHolder((colorInt shr 16), (colorInt shr 8 and 255), (colorInt and 255)) @@ -361,4 +405,8 @@ object Search : Module( } } + class OldWallSign(blockStateIn: IBlockState): StateImplementation(BlockOldWallSign, blockStateIn.properties) + class OldStandingSign(blockStateIn: IBlockState): StateImplementation(BlockOldStandingSign, blockStateIn.properties) + object BlockOldWallSign: BlockWallSign() + object BlockOldStandingSign: BlockStandingSign() } \ No newline at end of file From 053dc454523895b2e848c1bd29b77c81891c7d13 Mon Sep 17 00:00:00 2001 From: rfresh2 <89827146+rfresh2@users.noreply.github.com> Date: Sat, 3 Jun 2023 10:00:28 -0700 Subject: [PATCH 2/3] remove unnecessary synchronization --- .../client/module/modules/render/Search.kt | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt b/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt index c0bdc1e54..95168d1e2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt @@ -87,8 +87,6 @@ object Search : Module( private val blockRenderer = ESPRenderer() private val entityRenderer = ESPRenderer() private val foundBlockMap: ConcurrentMap = ConcurrentHashMap() - private val foundEntityUpdateLock = Any() - private val foundBlocksUpdateLock = Any() private var blockRenderUpdateJob: Job? = null private var entityRenderUpdateJob: Job? = null private var blockSearchJob: Job? = null @@ -130,16 +128,12 @@ object Search : Module( } if (blockSearch) { if (!(hideF1 && mc.gameSettings.hideGUI)) { - synchronized(foundBlocksUpdateLock) { - blockRenderer.render(false) - } + blockRenderer.render(false) } } if (entitySearch) { if (!(hideF1 && mc.gameSettings.hideGUI)) { - synchronized(foundEntityUpdateLock) { - entityRenderer.render(false) - } + entityRenderer.render(false) } } } @@ -212,9 +206,7 @@ object Search : Module( .filter { it.distanceTo(player.getPositionEyes(1f)) < range } .map { Triple(it.renderBoundingBox.offset(EntityUtils.getInterpolatedAmount(it, LambdaTessellator.pTicks())), entitySearchColor, GeometryMasks.Quad.ALL) } .toMutableList() - synchronized(foundEntityUpdateLock) { - entityRenderer.replaceAll(renderList) - } + entityRenderer.replaceAll(renderList) } private fun SafeClientEvent.searchAllLoadedChunks() { @@ -284,9 +276,7 @@ object Search : Module( } } .toMutableList() - synchronized(foundBlocksUpdateLock) { - blockRenderer.replaceAll(renderList) - } + blockRenderer.replaceAll(renderList) } private fun updateAlpha() { From 45134ebf843cecdb8dddfd3088483a30573e432c Mon Sep 17 00:00:00 2001 From: Constructor Date: Mon, 5 Jun 2023 02:36:22 +0200 Subject: [PATCH 3/3] Fix format --- .../client/module/modules/render/Search.kt | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt b/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt index 95168d1e2..35ec8a7a2 100644 --- a/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt +++ b/src/main/kotlin/com/lambda/client/module/modules/render/Search.kt @@ -152,7 +152,7 @@ object Search : Module( } safeListener { - // We avoid listening to SPacketChunkData directly here as even on PostReceive the chunk is not always + // We avoid listening to SPacketChunkData directly here, as even on PostReceive the chunk is not always // fully loaded into the world. Chunk load is handled on a separate thread in mc code. // i.e. world.getChunk(x, z) can and will return an empty chunk in the packet event defaultScope.launch { @@ -204,7 +204,13 @@ object Search : Module( .sortedBy { it.distanceTo(player.getPositionEyes(1f)) } .take(maximumEntities) .filter { it.distanceTo(player.getPositionEyes(1f)) < range } - .map { Triple(it.renderBoundingBox.offset(EntityUtils.getInterpolatedAmount(it, LambdaTessellator.pTicks())), entitySearchColor, GeometryMasks.Quad.ALL) } + .map { + Triple( + it.renderBoundingBox.offset(EntityUtils.getInterpolatedAmount(it, LambdaTessellator.pTicks())), + entitySearchColor, + GeometryMasks.Quad.ALL + ) + } .toMutableList() entityRenderer.replaceAll(renderList) } @@ -300,8 +306,12 @@ object Search : Module( val pos = BlockPos(x, y, z) val blockState = chunk.getBlockState(pos) if (isOldSign(blockState, pos)) { - val signState = if (blockState.block == Blocks.STANDING_SIGN) OldStandingSign(blockState) else OldWallSign(blockState) - blocks.add((pos to signState)) + val signState = if (blockState.block == Blocks.STANDING_SIGN) { + OldStandingSign(blockState) + } else { + OldWallSign(blockState) + } + blocks.add(pos to signState) continue // skip searching for regular sign at this pos } if (searchQuery(blockState, pos)) blocks.add(pos to blockState) @@ -324,15 +334,9 @@ object Search : Module( if (!illegalBedrock.value) return false if (state.block != Blocks.BEDROCK) return false return when (player.dimension) { - 0 -> { - pos.y >= 5 - } - -1 -> { - pos.y in 5..122 - } - else -> { - false - } + 0 -> pos.y >= 5 + -1 -> pos.y in 5..122 + else -> false } } @@ -348,7 +352,8 @@ object Search : Module( private fun SafeClientEvent.isOldSignText(pos: BlockPos): Boolean { // Explanation: Old signs on 2b2t (pre-2015 <1.9 ?) have older style NBT text tags. - // we can tell them apart by checking if there are siblings in the tag. Old signs won't have siblings. + // We can tell them apart by checking if there are siblings in the tag. + // Old signs won't have siblings. val signTextComponents = listOf(world.getTileEntity(pos)) .filterIsInstance() .flatMap { it.signText.toList() }