Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added velocity hit feature #4878

Open
wants to merge 6 commits into
base: nextgen
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleC
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.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.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
Expand Down Expand Up @@ -119,6 +120,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) {

init {
tree(KillAuraAutoBlock)
tree(KillAuraVelocityHit)
}

// Target rendering
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -462,19 +464,26 @@ 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.isInventoryOpen || 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)
}

/**
Expand Down Expand Up @@ -531,6 +540,14 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) {
}
}

val extendedReach: Float
get() {
if (KillAuraVelocityHit.isVelocityHitPossible) {
return range + KillAuraVelocityHit.extendRange
}
return range
}

fun shouldBlockSprinting() = running && !player.isOnGround &&
criticalsMode != CriticalsMode.IGNORE &&
targetTracker.lockedOnTarget != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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.utils.client.Chronometer
import net.ccbluex.liquidbounce.utils.client.PacketQueueManager
import net.minecraft.network.packet.s2c.play.*

object KillAuraVelocityHit : ToggleableConfigurable(ModuleKillAura, "VelocityHit", false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation! What does this feature do?


val extendRange by float("ExtendRange", 1.0f, 0.1f..2.0f)
private val whenLag by boolean("OnlyWhileLagging", false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bad name


private var considerVelocityHit = false
private var damageReceived = false
private var onGroundTicks = 0
private var isPossible = false
Comment on lines +19 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation!

isPossible is not a very good name


private var timer = Chronometer()
private var lastPacketTime = Lists.newLinkedList<Long>()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are only a handful use cases for linked lists.

The ArrayDeque is the one that you are searching for. It is a ring buffer and has O(1) time complexity when inserting at/removing from the head and tail!

And documentation!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LongArrayFIFOQueue from fastutil will be good for this.


private const val SAMPLE_SIZE = 10

val isVelocityHitPossible
get() = super.running && isPossible

@Suppress("unused")
private val packetHandler = sequenceHandler<PacketEvent>(priority = 1) { event ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use one of the priority categories.

val packet = event.packet

if (event.origin == TransferOrigin.RECEIVE) {
addRecentPacketTime()
}

when {
packet is EntityDamageS2CPacket && packet.entityId == player.id -> {
damageReceived = true
}
packet is EntityVelocityUpdateS2CPacket && packet.entityId == player.id && damageReceived -> {
considerVelocityHit = true
}
Comment on lines +41 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have implemented a state machine, but you use two separate flags to keep track of what state the state machine is currently in.

I'd recommend using an enum for the states, for example:

enum PacketListenerState {
    IDLE,
    /**
     * The player received damage, but no velocity packet was received (yet)
     */
    DAMAGE_RECEIVED,
    /**
     * A hit with velocity was received.
     */
    VELOCITY_DAMAGE_RECEIVED
}

}
}

@Suppress("unused")
private val gameHandler = tickHandler {
if (player.isDead || player.isSpectator) {
return@tickHandler
}

val enemy = ModuleKillAura.targetTracker.lockedOnTarget
var lagging = isLagging() || PacketQueueManager.isLagging

if (!whenLag) {
lagging = true
}
Comment on lines +57 to +61
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that this code does what it should?

Suggested change
var lagging = isLagging() || PacketQueueManager.isLagging
if (!whenLag) {
lagging = true
}
var lagging = isLagging() || PacketQueueManager.isLagging || !whenLag


if (enemy == null) {
reset()
return@tickHandler
}

val isInExtendedRange = player.distanceTo(enemy) <= ModuleKillAura.extendedReach
isPossible = lagging && considerVelocityHit && isInExtendedRange

if ((player.isOnGround && isPossible) || (player.fallDistance > 0.3 && isPossible)) {
onGroundTicks++
}
Comment on lines +71 to +73
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ((player.isOnGround && isPossible) || (player.fallDistance > 0.3 && isPossible)) {
onGroundTicks++
}
if (isPossible && (player.isOnGround || player.fallDistance > 0.3)) {
onGroundTicks++
}


if (onGroundTicks > 5) {
reset()
}
}

fun reset() {
isPossible = false
considerVelocityHit = false
damageReceived = false
onGroundTicks = 0
}

private fun addRecentPacketTime() {
lastPacketTime.add(timer.elapsed)
timer.reset()

if (lastPacketTime.size > SAMPLE_SIZE) {
for (i in 0..<SAMPLE_SIZE) {
lastPacketTime.removeAt(0)
}
}
}

private fun isLagging(): Boolean {
if (lastPacketTime.size != SAMPLE_SIZE) {
return false
}

var sumTime = 0L
for (i in 0..<SAMPLE_SIZE) {
sumTime += lastPacketTime[i]
}

return sumTime / SAMPLE_SIZE.toDouble() > 0.5
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer<WorldRenderEnvi

private val outline = tree(Outline())


AlexanderDotH marked this conversation as resolved.
Show resolved Hide resolved
override fun render(env: WorldRenderEnvironment, entity: Entity, partialTicks: Float) {
val height = heightMode.activeChoice.getHeight(entity, partialTicks)
val pos = entity.interpolateCurrentPosition(partialTicks) + Vec3d(0.0, height, 0.0)
Expand Down Expand Up @@ -169,7 +168,6 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer<WorldRenderEnvi

private val outline = tree(Outline())


override fun render(env: WorldRenderEnvironment, entity: Entity, partialTicks: Float) {
val height = heightMode.activeChoice.getHeight(entity, partialTicks)
val pos = entity.interpolateCurrentPosition(partialTicks) + Vec3d(0.0, height, 0.0)
Expand Down Expand Up @@ -251,8 +249,6 @@ class WorldTargetRenderer(module: ClientModule) : TargetRenderer<WorldRenderEnvi
override val parent: ChoiceConfigurable<*>
get() = choiceConfigurable



AlexanderDotH marked this conversation as resolved.
Show resolved Hide resolved
override fun getHeight(entity: Entity, partialTicks: Float): Double {
if(entity !is LivingEntity) return 0.0
val box = entity.box
Expand Down
Loading