diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Backtrack.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Backtrack.kt index 266a922bdbc..61bcb192b79 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Backtrack.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Backtrack.kt @@ -117,7 +117,7 @@ object Backtrack : Module("Backtrack", Category.COMBAT, hideModule = false) { get() = synchronized(packetQueue) { packetQueue.isEmpty() } val areQueuedPacketsEmpty - get() = PacketUtils.isEmpty() + get() = PacketUtils.isQueueEmpty() val onPacket = handler { event -> val packet = event.packet @@ -472,7 +472,7 @@ object Backtrack : Module("Backtrack", Category.COMBAT, hideModule = false) { synchronized(packetQueue) { packetQueue.removeAll { (packet, timestamp) -> if (timestamp <= System.currentTimeMillis() - supposedDelay) { - schedulePacketProcess(packet) + PacketUtils.schedulePacketProcess(packet) true } else false } @@ -494,7 +494,7 @@ object Backtrack : Module("Backtrack", Category.COMBAT, hideModule = false) { synchronized(packetQueue) { packetQueue.removeAll { (packet, timestamp) -> if (timestamp <= time) { - schedulePacketProcess(packet) + PacketUtils.schedulePacketProcess(packet) true } else false } @@ -533,7 +533,7 @@ object Backtrack : Module("Backtrack", Category.COMBAT, hideModule = false) { synchronized(packetQueue) { packetQueue.removeAll { if (handlePackets) { - schedulePacketProcess(it.packet) + PacketUtils.schedulePacketProcess(it.packet) } true diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/TimerRange.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/TimerRange.kt index 17a55768120..17b3bc154f6 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/TimerRange.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/TimerRange.kt @@ -15,8 +15,8 @@ import net.ccbluex.liquidbounce.ui.client.hud.element.elements.Notification import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isLookingOnEntities import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isSelected import net.ccbluex.liquidbounce.utils.client.BlinkUtils +import net.ccbluex.liquidbounce.utils.client.PacketUtils import net.ccbluex.liquidbounce.utils.client.chat -import net.ccbluex.liquidbounce.utils.client.schedulePacketProcess import net.ccbluex.liquidbounce.utils.extensions.* import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.nextFloat import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.nextInt @@ -279,7 +279,8 @@ object TimerRange : Module("TimerRange", Category.COMBAT, hideModule = false) { val onMotion = handler { event -> if (blink && event.eventState == EventState.POST) { synchronized(packetsReceived) { - schedulePacketProcess(packetsReceived) + PacketUtils.schedulePacketProcess(packetsReceived) + Unit } packetsReceived.clear() } diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Velocity.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Velocity.kt index f248009a2b3..d1ada7cd96b 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Velocity.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/combat/Velocity.kt @@ -13,12 +13,9 @@ import net.ccbluex.liquidbounce.features.module.modules.exploit.Disabler import net.ccbluex.liquidbounce.features.module.modules.movement.Speed import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isLookingOnEntities import net.ccbluex.liquidbounce.utils.attack.EntityUtils.isSelected +import net.ccbluex.liquidbounce.utils.client.* import net.ccbluex.liquidbounce.utils.client.PacketUtils.sendPacket import net.ccbluex.liquidbounce.utils.client.PacketUtils.sendPackets -import net.ccbluex.liquidbounce.utils.client.realMotionX -import net.ccbluex.liquidbounce.utils.client.realMotionY -import net.ccbluex.liquidbounce.utils.client.realMotionZ -import net.ccbluex.liquidbounce.utils.client.schedulePacketProcess import net.ccbluex.liquidbounce.utils.extensions.* import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.nextInt import net.ccbluex.liquidbounce.utils.movement.MovementUtils.isOnGround @@ -690,7 +687,7 @@ object Velocity : Module("Velocity", Category.COMBAT, hideModule = false) { synchronized(packets) { packets.entries.removeAll { (packet, timestamp) -> if (velocity || timestamp <= System.currentTimeMillis() - spoofDelay) { - schedulePacketProcess(packet) + PacketUtils.schedulePacketProcess(packet) true } else false } diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/exploit/PingSpoof.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/exploit/PingSpoof.kt index af80cc598db..471b1d2b9a0 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/exploit/PingSpoof.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/exploit/PingSpoof.kt @@ -14,7 +14,7 @@ import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.Module import net.ccbluex.liquidbounce.features.module.modules.combat.Velocity -import net.ccbluex.liquidbounce.utils.client.schedulePacketProcess +import net.ccbluex.liquidbounce.utils.client.PacketUtils import net.minecraft.network.Packet import net.minecraft.network.play.client.C0CPacketInput import net.minecraft.network.play.server.* @@ -76,7 +76,7 @@ object PingSpoof : Module("PingSpoof", Category.EXPLOIT, hideModule = false) { synchronized(packetQueue) { packetQueue.entries.removeAll { (packet, timestamp) -> if (all || timestamp <= (System.currentTimeMillis() - spoofDelay)) { - schedulePacketProcess(packet) + PacketUtils.schedulePacketProcess(packet) true } else false } diff --git a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/movement/flymodes/blocksmc/BlocksMC2.kt b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/movement/flymodes/blocksmc/BlocksMC2.kt index 3d34928bfc6..02bb147daa2 100644 --- a/src/main/java/net/ccbluex/liquidbounce/features/module/modules/movement/flymodes/blocksmc/BlocksMC2.kt +++ b/src/main/java/net/ccbluex/liquidbounce/features/module/modules/movement/flymodes/blocksmc/BlocksMC2.kt @@ -15,9 +15,9 @@ import net.ccbluex.liquidbounce.features.module.modules.movement.Fly.stopOnLandi import net.ccbluex.liquidbounce.features.module.modules.movement.Fly.stopOnNoMove import net.ccbluex.liquidbounce.features.module.modules.movement.Fly.timerSlowed import net.ccbluex.liquidbounce.features.module.modules.movement.flymodes.FlyMode +import net.ccbluex.liquidbounce.utils.client.PacketUtils import net.ccbluex.liquidbounce.utils.client.PacketUtils.sendPackets import net.ccbluex.liquidbounce.utils.client.chat -import net.ccbluex.liquidbounce.utils.client.schedulePacketProcess import net.ccbluex.liquidbounce.utils.extensions.isMoving import net.ccbluex.liquidbounce.utils.extensions.tryJump import net.ccbluex.liquidbounce.utils.movement.MovementUtils.strafe @@ -204,7 +204,8 @@ object BlocksMC2 : FlyMode("BlocksMC2"), Listenable { private fun blink() { synchronized(packetsReceived) { - schedulePacketProcess(packetsReceived) + PacketUtils.schedulePacketProcess(packetsReceived) + Unit } synchronized(packets) { sendPackets(*packets.toTypedArray(), triggerEvents = false) diff --git a/src/main/java/net/ccbluex/liquidbounce/utils/client/BlinkUtils.kt b/src/main/java/net/ccbluex/liquidbounce/utils/client/BlinkUtils.kt index 604ad93df2a..d4c9ab1faf8 100644 --- a/src/main/java/net/ccbluex/liquidbounce/utils/client/BlinkUtils.kt +++ b/src/main/java/net/ccbluex/liquidbounce/utils/client/BlinkUtils.kt @@ -46,7 +46,8 @@ object BlinkUtils : MinecraftInstance, Listenable { if (sent == true && receive == false) { if (event.eventType == EventState.RECEIVE) { synchronized(packetsReceived) { - schedulePacketProcess(packetsReceived) + PacketUtils.schedulePacketProcess(packetsReceived) + Unit } packetsReceived.clear() } @@ -119,7 +120,7 @@ object BlinkUtils : MinecraftInstance, Listenable { fun syncSent() { synchronized(packetsReceived) { - schedulePacketProcess(packetsReceived) + PacketUtils.schedulePacketProcess(packetsReceived) packetsReceived.clear() } } @@ -163,7 +164,8 @@ object BlinkUtils : MinecraftInstance, Listenable { fun unblink() { synchronized(packetsReceived) { - schedulePacketProcess(packetsReceived) + PacketUtils.schedulePacketProcess(packetsReceived) + Unit } synchronized(packets) { sendPackets(*packets.toTypedArray(), triggerEvents = false) diff --git a/src/main/java/net/ccbluex/liquidbounce/utils/client/PacketUtils.kt b/src/main/java/net/ccbluex/liquidbounce/utils/client/PacketUtils.kt index d39fbb70341..55d57464f7f 100644 --- a/src/main/java/net/ccbluex/liquidbounce/utils/client/PacketUtils.kt +++ b/src/main/java/net/ccbluex/liquidbounce/utils/client/PacketUtils.kt @@ -22,24 +22,28 @@ import net.minecraft.network.play.client.C03PacketPlayer import net.minecraft.network.play.server.* import net.minecraft.util.BlockPos import net.minecraft.util.Vec3 -import java.util.concurrent.locks.ReentrantReadWriteLock +import java.util.concurrent.locks.ReentrantLock import kotlin.collections.ArrayDeque -import kotlin.concurrent.read +import kotlin.concurrent.withLock import kotlin.concurrent.write import kotlin.math.roundToInt object PacketUtils : MinecraftInstance, Listenable { private val queuedPackets = ArrayDeque>() - private val queueLock = ReentrantReadWriteLock() + private val queueLock = ReentrantLock() - fun addAll(elements: Collection>): Boolean = queueLock.write { queuedPackets.addAll(elements) } - - fun add(element: Packet<*>): Boolean = queueLock.write { queuedPackets.add(element) } + fun schedulePacketProcess(elements: Collection>): Boolean = queueLock.withLock { + queuedPackets.addAll(elements) + } - fun isEmpty(): Boolean = queueLock.read { queuedPackets.isEmpty() } + fun schedulePacketProcess(element: Packet<*>): Boolean = queueLock.withLock { + queuedPackets.add(element) + } - val size: Int get() = queueLock.read { queuedPackets.size } + fun isQueueEmpty(): Boolean = queueLock.withLock { + queuedPackets.isEmpty() + } val onTick = handler(priority = 2) { for (entity in mc.theWorld.loadedEntityList) { @@ -91,7 +95,7 @@ object PacketUtils : MinecraftInstance, Listenable { return@handler } - queueLock.write { + queueLock.withLock { queuedPackets.removeEach { packet -> handlePacket(packet) val packetEvent = PacketEvent(packet, EventState.RECEIVE) @@ -105,7 +109,7 @@ object PacketUtils : MinecraftInstance, Listenable { val onWorld = handler(priority = -1) { event -> if (event.worldClient == null) { - queueLock.write { + queueLock.withLock { queuedPackets.clear() } } @@ -244,12 +248,3 @@ var C03PacketPlayer.pos y = value.yCoord z = value.zCoord } - - -fun schedulePacketProcess(packet: Packet<*>) { - PacketUtils.add(packet) -} - -fun schedulePacketProcess(packets: Collection>) { - PacketUtils.addAll(packets) -} \ No newline at end of file