-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
base: nextgen
Are you sure you want to change the base?
Changes from all commits
74b8bc3
6b2bc8c
449033c
a49cc07
321ca9e
3faf9f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) { | ||||||||||||||
|
||||||||||||||
val extendRange by float("ExtendRange", 1.0f, 0.1f..2.0f) | ||||||||||||||
private val whenLag by boolean("OnlyWhileLagging", false) | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation!
|
||||||||||||||
|
||||||||||||||
private var timer = Chronometer() | ||||||||||||||
private var lastPacketTime = Lists.newLinkedList<Long>() | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are only a handful use cases for linked lists. The And documentation! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||
|
||||||||||||||
private const val SAMPLE_SIZE = 10 | ||||||||||||||
|
||||||||||||||
val isVelocityHitPossible | ||||||||||||||
get() = super.running && isPossible | ||||||||||||||
|
||||||||||||||
@Suppress("unused") | ||||||||||||||
private val packetHandler = sequenceHandler<PacketEvent>(priority = 1) { event -> | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that this code does what it should?
Suggested change
|
||||||||||||||
|
||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
|
||||||||||||||
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 | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
} |
There was a problem hiding this comment.
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?