From 74b8bc34f6a8a62333a6ca34c4b6c4fa96c2fde9 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 11 Dec 2024 16:55:03 +0100 Subject: [PATCH 1/5] feat: Added velocity hit feature --- .../modules/combat/killaura/ModuleKillAura.kt | 30 ++++- .../killaura/features/KillAuraAutoBlock.kt | 3 +- .../killaura/features/KillAuraFailSwing.kt | 2 +- .../killaura/features/KillAuraFightBot.kt | 2 +- .../killaura/features/KillAuraVelocityHit.kt | 123 ++++++++++++++++++ .../modules/combat/velocity/ModuleVelocity.kt | 2 + .../utils/render/TargetRenderer.kt | 4 - 7 files changed, 152 insertions(+), 14 deletions(-) create mode 100644 src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt index a96da506a27..2a3977f6efc 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt @@ -31,10 +31,9 @@ import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.KillAuraClickScheduler.considerMissCooldown import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.RaycastMode.* -import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraAutoBlock +import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.* import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraFailSwing import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraFailSwing.dealWithFakeSwing -import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraFightBot import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraNotifyWhenFail import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraNotifyWhenFail.failedHits import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraNotifyWhenFail.hasFailedHit @@ -45,6 +44,7 @@ import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug import net.ccbluex.liquidbounce.render.engine.Color4b import net.ccbluex.liquidbounce.render.renderEnvironmentForWorld import net.ccbluex.liquidbounce.utils.aiming.* +import net.ccbluex.liquidbounce.utils.client.chat import net.ccbluex.liquidbounce.utils.combat.* import net.ccbluex.liquidbounce.utils.entity.boxedDistanceTo import net.ccbluex.liquidbounce.utils.entity.isBlockAction @@ -62,6 +62,7 @@ import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.AxeItem import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.Full +import org.oryxel.cube.util.MathUtil /** * KillAura module @@ -119,6 +120,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { init { tree(KillAuraAutoBlock) + tree(KillAuraVelocityHit) } // Target rendering @@ -250,7 +252,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { // Are we actually facing the [chosenEntity] val isFacingEnemy = facingEnemy(toEntity = chosenEntity, rotation = rotation, - range = range.toDouble(), + range = extendedReach.toDouble(), wallsRange = wallRange.toDouble()) ModuleDebug.debugParameter(ModuleKillAura, "isFacingEnemy", isFacingEnemy) @@ -325,7 +327,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { * Update enemy on target tracker */ private fun updateEnemySelection() { - targetTracker.validateLock { it.shouldBeAttacked() && it.boxedDistanceTo(player) <= range } + targetTracker.validateLock { it.shouldBeAttacked() && it.boxedDistanceTo(player) <= extendedReach } // Update target tracker, since we want to access // the maximumDistance in the next step @@ -334,7 +336,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { // Maximum range can be higher than the normal range, since we want to scan for enemies // which are in our [scanExtraRange] as well val maximumRange = if (targetTracker.maximumDistance > range) { - range + scanExtraRange + range + scanExtraRange.coerceAtLeast(extendedReach) } else { range } @@ -462,19 +464,25 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { } private fun checkIfReadyToAttack(choosenEntity: Entity): Boolean { + val critical = when (criticalsMode) { CriticalsMode.IGNORE -> true CriticalsMode.SMART -> !ModuleCriticals.shouldWaitForCrit(choosenEntity, ignoreState = true) CriticalsMode.ALWAYS -> ModuleCriticals.wouldDoCriticalHit() } + val shielding = attackShielding || choosenEntity !is PlayerEntity || player.mainHandStack.item is AxeItem || !choosenEntity.wouldBlockHit(player) val isInInventoryScreen = InventoryManager.isInventoryOpenServerSide || mc.currentScreen is GenericContainerScreen val missCooldown = considerMissCooldown && mc.attackCooldown > 0 - return critical && shielding && - !(isInInventoryScreen && !ignoreOpenInventory && !simulateInventoryClosing) && !missCooldown + var isReady = critical && shielding && + !(isInInventoryScreen && !ignoreOpenInventory && !simulateInventoryClosing) && !missCooldown; + + var canUseVelocityHit = KillAuraVelocityHit.enabled && KillAuraVelocityHit.running && KillAuraVelocityHit.isVelocityHitPossible + + return isReady || (isReady && canUseVelocityHit) } /** @@ -531,6 +539,14 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { } } + var extendedReach: Float = range + get() { + if (KillAuraVelocityHit.enabled && KillAuraVelocityHit.running && KillAuraVelocityHit.isVelocityHitPossible) { + return range + KillAuraVelocityHit.extensionRange + } + return range + } + fun shouldBlockSprinting() = running && !player.isOnGround && criticalsMode != CriticalsMode.IGNORE && targetTracker.lockedOnTarget != null && diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraAutoBlock.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraAutoBlock.kt index 933636c8906..ef6d1826e00 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraAutoBlock.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraAutoBlock.kt @@ -24,6 +24,7 @@ import net.ccbluex.liquidbounce.event.events.PacketEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.RaycastMode.* +import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.extendedReach import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.range import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.raycast import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.targetTracker @@ -207,7 +208,7 @@ object KillAuraAutoBlock : ToggleableConfigurable(ModuleKillAura, "AutoBlocking" // Raycast using the current rotation and find a block or entity that should be interacted with val rotationToTheServer = RotationManager.serverRotation - val entityHitResult = raytraceEntity(range.toDouble(), rotationToTheServer, filter = { + val entityHitResult = raytraceEntity(extendedReach.toDouble(), rotationToTheServer, filter = { when (raycast) { TRACE_NONE -> false TRACE_ONLYENEMY -> it.shouldBeAttacked() diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFailSwing.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFailSwing.kt index e7bbc6d8b1c..7a0defaae8d 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFailSwing.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFailSwing.kt @@ -68,7 +68,7 @@ internal object KillAuraFailSwing : ToggleableConfigurable(ModuleKillAura, "Fail val raycastType = mc.crosshairTarget?.type - val range = ModuleKillAura.range + additionalRange + val range = ModuleKillAura.extendedReach + additionalRange val entity = target ?: world.findEnemy(0f..range) ?: return if (entity.isRemoved || entity.boxedDistanceTo(player) > range || raycastType != HitResult.Type.MISS) { diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFightBot.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFightBot.kt index 1b9303ca1ea..1facd20618e 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFightBot.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraFightBot.kt @@ -64,7 +64,7 @@ object KillAuraFightBot : ToggleableConfigurable(ModuleKillAura, "FightBot", fal val distance = enemy.boxedDistanceTo(player) if (clickScheduler.isClickOnNextTick()) { - if (distance < ModuleKillAura.range) { + if (distance < ModuleKillAura.extendedReach) { ev.directionalInput = DirectionalInput.NONE sideToGo = !sideToGo } else { diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt new file mode 100644 index 00000000000..3e0864e680b --- /dev/null +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt @@ -0,0 +1,123 @@ +package net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features + +import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable +import net.ccbluex.liquidbounce.event.events.PacketEvent +import net.ccbluex.liquidbounce.event.events.TransferOrigin +import net.ccbluex.liquidbounce.event.sequenceHandler +import net.ccbluex.liquidbounce.event.tickHandler +import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura +import net.ccbluex.liquidbounce.features.module.modules.misc.ModulePacketLogger +import net.ccbluex.liquidbounce.utils.client.Chronometer +import net.ccbluex.liquidbounce.utils.client.PacketQueueManager +import net.ccbluex.liquidbounce.utils.client.chat +import net.minecraft.entity.LivingEntity +import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket +import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket +import net.minecraft.network.packet.s2c.play.* + +object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit", false) { + + private var considerVelocityHit = false; + private var damageReceived = false; + private var onGroundTicks = 0; + private var isPossible = false; + + val extensionRange by float("Extension", 1.0f, 0.1f..2.0f) + val onLag by boolean("OnlyWhileLagging", false) + + private var timer: Chronometer = Chronometer() + private var lastPacketTime: ArrayList = ArrayList() + + private val sampleSize: Int = 10 + + @Suppress("unused") + private val packetHandler = sequenceHandler(priority = 1) { event -> + + val packet = event.packet + + if (event.origin == TransferOrigin.RECEIVE) { + addRecentPacketTime() + } + + if (packet is EntityDamageS2CPacket && packet.entityId == player.id) { + damageReceived = true; + } + + if (packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id && damageReceived) { + considerVelocityHit = true; + } + } + + @Suppress("unused") + private val gameHandler = tickHandler { + + if (player.isDead || player.isSpectator) { + return@tickHandler + } + + var enemy: LivingEntity? = ModuleKillAura.targetTracker.lockedOnTarget; + var lagging: Boolean = isLagging() || PacketQueueManager.isLagging + + if (!onLag) + lagging = true; + + var isTracking: Boolean = enemy != null; + + if (enemy == null) { + reset() + return@tickHandler + } + + var distanceToEnemy: Float = player.distanceTo(enemy) + var isInExtensionRange: Boolean = distanceToEnemy <= ModuleKillAura.extendedReach + + isPossible = lagging && isTracking && considerVelocityHit && isInExtensionRange + + if ((player.isOnGround && isPossible) || (player.fallDistance > 0.3 && isPossible)) { + onGroundTicks++ + } + + if (onGroundTicks > 5) { + reset() + } + } + + fun reset() { + isPossible = false; + considerVelocityHit = false + damageReceived = false + onGroundTicks = 0 + } + + fun addRecentPacketTime() { + + lastPacketTime.add(timer.elapsed) + timer.reset() + + if (lastPacketTime.size > sampleSize) { + for (i in 0.. 0.5 + } + + var isVelocityHitPossible: Boolean = false + get() = isPossible && super.running +} diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt index a5a2090bb80..a390767dc52 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt @@ -27,6 +27,7 @@ import net.ccbluex.liquidbounce.event.sequenceHandler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.* +import net.ccbluex.liquidbounce.utils.client.chat import net.minecraft.network.listener.ClientPlayPacketListener import net.minecraft.network.packet.Packet import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket @@ -81,6 +82,7 @@ object ModuleVelocity : ClientModule("Velocity", Category.COMBAT) { } if (packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id || packet is ExplosionS2CPacket) { + // When delay is above 0, we will delay the velocity update if (delay.last > 0) { event.cancelEvent() diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt index 442241cbeb9..9236da96c18 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/TargetRenderer.kt @@ -130,7 +130,6 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer get() = choiceConfigurable - - override fun getHeight(entity: Entity, partialTicks: Float): Double { if(entity !is LivingEntity) return 0.0 val box = entity.box From 6b2bc8c4a1b69b16d46d68c75b94c01a0dd133b8 Mon Sep 17 00:00:00 2001 From: 1zuna <1zuna@ccbluex.net> Date: Mon, 16 Dec 2024 01:13:36 +0100 Subject: [PATCH 2/5] Apply suggestions from code review Co-authored-by: DataModel <183248792+DataM0del@users.noreply.github.com> --- .../modules/combat/killaura/ModuleKillAura.kt | 4 ++- .../killaura/features/KillAuraVelocityHit.kt | 25 ++++++++++--------- .../modules/combat/velocity/ModuleVelocity.kt | 2 -- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt index 2a3977f6efc..846f59719d5 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt @@ -31,7 +31,9 @@ import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.KillAuraClickScheduler.considerMissCooldown import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura.RaycastMode.* -import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.* +import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraAutoBlock +import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraFightBot +import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraVelocityHit import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraFailSwing import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraFailSwing.dealWithFakeSwing import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features.KillAuraNotifyWhenFail diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt index 3e0864e680b..d2b03aba9c9 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt @@ -17,10 +17,10 @@ import net.minecraft.network.packet.s2c.play.* object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit", false) { - private var considerVelocityHit = false; - private var damageReceived = false; - private var onGroundTicks = 0; - private var isPossible = false; + private var considerVelocityHit = false + private var damageReceived = false + private var onGroundTicks = 0 + private var isPossible = false val extensionRange by float("Extension", 1.0f, 0.1f..2.0f) val onLag by boolean("OnlyWhileLagging", false) @@ -28,7 +28,7 @@ object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit private var timer: Chronometer = Chronometer() private var lastPacketTime: ArrayList = ArrayList() - private val sampleSize: Int = 10 + const val sampleSize = 10 @Suppress("unused") private val packetHandler = sequenceHandler(priority = 1) { event -> @@ -40,11 +40,11 @@ object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit } if (packet is EntityDamageS2CPacket && packet.entityId == player.id) { - damageReceived = true; + damageReceived = true } if (packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id && damageReceived) { - considerVelocityHit = true; + considerVelocityHit = true } } @@ -55,13 +55,14 @@ object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit return@tickHandler } - var enemy: LivingEntity? = ModuleKillAura.targetTracker.lockedOnTarget; + var enemy: LivingEntity? = ModuleKillAura.targetTracker.lockedOnTarget var lagging: Boolean = isLagging() || PacketQueueManager.isLagging - if (!onLag) - lagging = true; + if (!onLag) { + lagging = true +} - var isTracking: Boolean = enemy != null; + var isTracking: Boolean = enemy != null if (enemy == null) { reset() @@ -83,7 +84,7 @@ object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit } fun reset() { - isPossible = false; + isPossible = false considerVelocityHit = false damageReceived = false onGroundTicks = 0 diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt index a390767dc52..a5a2090bb80 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt @@ -27,7 +27,6 @@ import net.ccbluex.liquidbounce.event.sequenceHandler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode.* -import net.ccbluex.liquidbounce.utils.client.chat import net.minecraft.network.listener.ClientPlayPacketListener import net.minecraft.network.packet.Packet import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket @@ -82,7 +81,6 @@ object ModuleVelocity : ClientModule("Velocity", Category.COMBAT) { } if (packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id || packet is ExplosionS2CPacket) { - // When delay is above 0, we will delay the velocity update if (delay.last > 0) { event.cancelEvent() From 449033cc1e610fb14298185aacef08089a2f812d Mon Sep 17 00:00:00 2001 From: izuna Date: Mon, 16 Dec 2024 01:21:36 +0100 Subject: [PATCH 3/5] refactor: code clean-up --- .../modules/combat/killaura/ModuleKillAura.kt | 8 +-- .../killaura/features/KillAuraVelocityHit.kt | 70 ++++++++----------- 2 files changed, 32 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt index 846f59719d5..dc6a837667b 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt @@ -46,7 +46,6 @@ import net.ccbluex.liquidbounce.features.module.modules.render.ModuleDebug import net.ccbluex.liquidbounce.render.engine.Color4b import net.ccbluex.liquidbounce.render.renderEnvironmentForWorld import net.ccbluex.liquidbounce.utils.aiming.* -import net.ccbluex.liquidbounce.utils.client.chat import net.ccbluex.liquidbounce.utils.combat.* import net.ccbluex.liquidbounce.utils.entity.boxedDistanceTo import net.ccbluex.liquidbounce.utils.entity.isBlockAction @@ -64,7 +63,6 @@ import net.minecraft.entity.player.PlayerEntity import net.minecraft.item.AxeItem import net.minecraft.network.packet.c2s.play.CloseHandledScreenC2SPacket import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket.Full -import org.oryxel.cube.util.MathUtil /** * KillAura module @@ -541,10 +539,10 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { } } - var extendedReach: Float = range + val extendedReach: Float get() { - if (KillAuraVelocityHit.enabled && KillAuraVelocityHit.running && KillAuraVelocityHit.isVelocityHitPossible) { - return range + KillAuraVelocityHit.extensionRange + if (KillAuraVelocityHit.isVelocityHitPossible) { + return range + KillAuraVelocityHit.extendRange } return range } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt index d2b03aba9c9..6b26e511999 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt @@ -1,78 +1,72 @@ package net.ccbluex.liquidbounce.features.module.modules.combat.killaura.features +import com.google.common.collect.Lists import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable import net.ccbluex.liquidbounce.event.events.PacketEvent import net.ccbluex.liquidbounce.event.events.TransferOrigin import net.ccbluex.liquidbounce.event.sequenceHandler import net.ccbluex.liquidbounce.event.tickHandler import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura -import net.ccbluex.liquidbounce.features.module.modules.misc.ModulePacketLogger import net.ccbluex.liquidbounce.utils.client.Chronometer import net.ccbluex.liquidbounce.utils.client.PacketQueueManager -import net.ccbluex.liquidbounce.utils.client.chat -import net.minecraft.entity.LivingEntity -import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket -import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket import net.minecraft.network.packet.s2c.play.* object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit", false) { + val extendRange by float("ExtendRange", 1.0f, 0.1f..2.0f) + private val whenLag by boolean("OnlyWhileLagging", false) + private var considerVelocityHit = false private var damageReceived = false private var onGroundTicks = 0 private var isPossible = false - val extensionRange by float("Extension", 1.0f, 0.1f..2.0f) - val onLag by boolean("OnlyWhileLagging", false) + private var timer = Chronometer() + private var lastPacketTime = Lists.newLinkedList() - private var timer: Chronometer = Chronometer() - private var lastPacketTime: ArrayList = ArrayList() + private const val SAMPLE_SIZE = 10 - const val sampleSize = 10 + val isVelocityHitPossible + get() = super.running && isPossible @Suppress("unused") private val packetHandler = sequenceHandler(priority = 1) { event -> - val packet = event.packet if (event.origin == TransferOrigin.RECEIVE) { addRecentPacketTime() } - if (packet is EntityDamageS2CPacket && packet.entityId == player.id) { - damageReceived = true - } - - if (packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id && damageReceived) { - considerVelocityHit = true + when { + packet is EntityDamageS2CPacket && packet.entityId == player.id -> { + damageReceived = true + } + packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id && damageReceived -> { + considerVelocityHit = true + } } } @Suppress("unused") private val gameHandler = tickHandler { - if (player.isDead || player.isSpectator) { return@tickHandler } - var enemy: LivingEntity? = ModuleKillAura.targetTracker.lockedOnTarget - var lagging: Boolean = isLagging() || PacketQueueManager.isLagging + val enemy = ModuleKillAura.targetTracker.lockedOnTarget + var lagging = isLagging() || PacketQueueManager.isLagging - if (!onLag) { + if (!whenLag) { lagging = true -} - - var isTracking: Boolean = enemy != null + } if (enemy == null) { reset() return@tickHandler } - var distanceToEnemy: Float = player.distanceTo(enemy) - var isInExtensionRange: Boolean = distanceToEnemy <= ModuleKillAura.extendedReach - - isPossible = lagging && isTracking && considerVelocityHit && isInExtensionRange + val isInExtendedRange = player.distanceTo(enemy) <= ModuleKillAura.extendedReach + isPossible = lagging && considerVelocityHit && isInExtendedRange if ((player.isOnGround && isPossible) || (player.fallDistance > 0.3 && isPossible)) { onGroundTicks++ @@ -90,35 +84,29 @@ object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit onGroundTicks = 0 } - fun addRecentPacketTime() { - + private fun addRecentPacketTime() { lastPacketTime.add(timer.elapsed) timer.reset() - if (lastPacketTime.size > sampleSize) { - for (i in 0.. SAMPLE_SIZE) { + for (i in 0.. 0.5 } - var isVelocityHitPossible: Boolean = false - get() = isPossible && super.running } From a49cc07b99b82c1dcf149df7d9c14b26180de4f5 Mon Sep 17 00:00:00 2001 From: izuna Date: Mon, 16 Dec 2024 01:22:09 +0100 Subject: [PATCH 4/5] refactor: code clean-up --- .../modules/combat/killaura/features/KillAuraVelocityHit.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt index 6b26e511999..e9526bac472 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/KillAuraVelocityHit.kt @@ -100,13 +100,12 @@ object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit return false } - var sumTime: Long = 0 + var sumTime = 0L for (i in 0.. 0.5 + return sumTime / SAMPLE_SIZE.toDouble() > 0.5 } } From 3faf9f7259b7795afba661ca0c4b105d789823fc Mon Sep 17 00:00:00 2001 From: 1zuna <1zuna@ccbluex.net> Date: Mon, 16 Dec 2024 03:12:51 +0100 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: DataModel <183248792+DataM0del@users.noreply.github.com> --- .../features/module/modules/combat/killaura/ModuleKillAura.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt index 3dabce8f1de..36843af7b06 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/ModuleKillAura.kt @@ -480,7 +480,8 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { var isReady = critical && shielding && !(isInInventoryScreen && !ignoreOpenInventory && !simulateInventoryClosing) && !missCooldown; - var canUseVelocityHit = KillAuraVelocityHit.enabled && KillAuraVelocityHit.running && KillAuraVelocityHit.isVelocityHitPossible + var canUseVelocityHit = KillAuraVelocityHit.enabled + && KillAuraVelocityHit.running && KillAuraVelocityHit.isVelocityHitPossible return isReady || (isReady && canUseVelocityHit) }