Skip to content

Commit

Permalink
fix(legacy): TickBase being movement-detected by anti-cheats. (CCBlue…
Browse files Browse the repository at this point in the history
  • Loading branch information
mems01 authored Oct 1, 2024
1 parent 924619b commit 743cc3b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.modules.player.Blink
import net.ccbluex.liquidbounce.utils.ClientUtils.runTimeTicks
import net.ccbluex.liquidbounce.utils.EntityUtils
import net.ccbluex.liquidbounce.utils.PacketUtils.sendPacket
import net.ccbluex.liquidbounce.utils.SimulatedPlayer
import net.ccbluex.liquidbounce.utils.misc.RandomUtils
import net.ccbluex.liquidbounce.utils.render.ColorUtils.rainbow
Expand All @@ -22,7 +20,6 @@ import net.ccbluex.liquidbounce.value.FloatValue
import net.ccbluex.liquidbounce.value.IntegerValue
import net.ccbluex.liquidbounce.value.ListValue
import net.minecraft.entity.EntityLivingBase
import net.minecraft.network.Packet
import net.minecraft.network.play.server.S08PacketPlayerPosLook
import net.minecraft.util.Vec3
import org.lwjgl.opengl.GL11.*
Expand All @@ -49,7 +46,6 @@ object TickBase : Module("TickBase", Category.COMBAT) {
private val forceGround by BoolValue("ForceGround", false)
private val pauseAfterTick by IntegerValue("PauseAfterTick", 0, 0..100)
private val pauseOnFlag by BoolValue("PauseOnFlag", true)
private val experimentalPacketCancel by BoolValue("ExperimentalPacketCancel", false)

private val line by BoolValue("Line", true, subjective = true)
private val rainbow by BoolValue("Rainbow", false, subjective = true) { line }
Expand All @@ -76,8 +72,7 @@ object TickBase : Module("TickBase", Category.COMBAT) {
private var tickBalance = 0f
private var reachedTheLimit = false
private val tickBuffer = mutableListOf<TickData>()
private var duringTickModification = false
private val packetMap: MutableMap<Int, MutableList<Packet<*>>> = mutableMapOf()
var duringTickModification = false

override val tag
get() = mode
Expand All @@ -87,7 +82,7 @@ object TickBase : Module("TickBase", Category.COMBAT) {
}

@EventTarget
fun onTickPre(event: PlayerTickEvent) {
fun onPreTick(event: PlayerTickEvent) {
val player = mc.thePlayer ?: return

if (player.ridingEntity != null || Blink.handleEvents()) {
Expand All @@ -99,15 +94,15 @@ object TickBase : Module("TickBase", Category.COMBAT) {
}
}

@EventTarget
fun onTickPost(event: PlayerTickEvent) {
@EventTarget(priority = 1)
fun onGameTick(event: GameTickEvent) {
val player = mc.thePlayer ?: return

if (player.ridingEntity != null || Blink.handleEvents()) {
return
}

if (event.state == EventState.POST && !duringTickModification && tickBuffer.isNotEmpty()) {
if (!duringTickModification && tickBuffer.isNotEmpty()) {
val nearbyEnemy = getNearestEntityInRange() ?: return
val currentDistance = player.positionVector.distanceTo(nearbyEnemy.positionVector)

Expand All @@ -116,7 +111,7 @@ object TickBase : Module("TickBase", Category.COMBAT) {
.filter { (_, tick) ->
val tickDistance = tick.position.distanceTo(nearbyEnemy.positionVector)

tickDistance < currentDistance && tickDistance in minRangeToAttack.get().. maxRangeToAttack.get()
tickDistance < currentDistance && tickDistance in minRangeToAttack.get()..maxRangeToAttack.get()
}
.filter { (_, tick) -> !tick.isCollidedHorizontally }
.filter { (_, tick) -> !forceGround || tick.onGround }
Expand All @@ -134,61 +129,31 @@ object TickBase : Module("TickBase", Category.COMBAT) {
return
}

packetMap.clear()
duringTickModification = true

if (mode == "Past") {
ticksToSkip = (bestTick + pauseAfterTick).coerceAtMost(maxTicksAtATime + pauseAfterTick)

WaitTickUtils.scheduleTicks(ticksToSkip) {
repeat(bestTick) {
if (experimentalPacketCancel) {
val zeroIndex = runTimeTicks - bestTick
val index = runTimeTicks - (bestTick - it)

if (it == 1) {
packetMap[zeroIndex]?.forEach { packet ->
sendPacket(packet, false)
}
}
packetMap[index]?.forEach { packet ->
sendPacket(packet, false)
}
}
player.onUpdate()
tickBalance -= 1
}

packetMap.clear()
duringTickModification = false
}
} else {
val skipTicks = (bestTick + pauseAfterTick).coerceAtMost(maxTicksAtATime + pauseAfterTick)
val skipTicks = (bestTick + pauseAfterTick).coerceAtMost(maxTicksAtATime + pauseAfterTick)

val skip = {
repeat(skipTicks) {
player.onUpdate()
tickBalance -= 1
}
}

if (mode == "Past") {
ticksToSkip = skipTicks

WaitTickUtils.scheduleTicks(ticksToSkip) {
if (experimentalPacketCancel) {
repeat(skipTicks) {
val zeroIndex = runTimeTicks - skipTicks
val index = runTimeTicks - (skipTicks - it)
if (it == 1) {
packetMap[zeroIndex]?.forEach { packet ->
sendPacket(packet, false)
}
}
packetMap[index]?.forEach { packet ->
sendPacket(packet, false)
}
}
}

packetMap.clear()
WaitTickUtils.scheduleTicks(skipTicks) {
skip()

duringTickModification = false
}
} else {
skip()

ticksToSkip = skipTicks

WaitTickUtils.scheduleTicks(skipTicks) {
duringTickModification = false
}
}
Expand Down Expand Up @@ -280,11 +245,6 @@ object TickBase : Module("TickBase", Category.COMBAT) {
tickBalance = 0f
}

if (event.eventType == EventState.SEND && ticksToSkip > 0 && experimentalPacketCancel) {
event.cancelEvent()
packetMap.getOrPut(runTimeTicks) { mutableListOf() }.add(event.packet)
}

}

private data class TickData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.ccbluex.liquidbounce.api.ClientUpdate;
import net.ccbluex.liquidbounce.event.*;
import net.ccbluex.liquidbounce.features.module.modules.combat.AutoClicker;
import net.ccbluex.liquidbounce.features.module.modules.combat.TickBase;
import net.ccbluex.liquidbounce.features.module.modules.exploit.AbortBreaking;
import net.ccbluex.liquidbounce.features.module.modules.exploit.MultiActions;
import net.ccbluex.liquidbounce.features.module.modules.world.FastPlace;
Expand Down Expand Up @@ -45,13 +46,11 @@
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.nio.ByteBuffer;
import java.util.Queue;

import static net.ccbluex.liquidbounce.utils.MinecraftInstance.mc;

Expand Down Expand Up @@ -288,6 +287,11 @@ public void sendClickBlockToController(boolean leftClick) {
}
}

@Redirect(method = "runGameLoop", at = @At(value = "INVOKE", target = "Ljava/util/Queue;isEmpty()Z"))
private boolean injectTickBase(Queue instance) {
return TickBase.INSTANCE.getDuringTickModification() || instance.isEmpty();
}

/**
* @author CCBlueX
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ object WaitTickUtils : MinecraftInstance(), Listenable {
private val scheduledActions = mutableListOf<ScheduledAction>()

fun scheduleTicks(ticks: Int, action: () -> Unit) {
if (ticks == 0) {
action()

return
}

scheduledActions.add(ScheduledAction(ClientUtils.runTimeTicks + ticks, action))
}

Expand Down

0 comments on commit 743cc3b

Please sign in to comment.