From a7a1d5a496b6d3063c749090b8d1ee5bdc9b6f88 Mon Sep 17 00:00:00 2001 From: izuna Date: Wed, 8 Jan 2025 20:58:47 +0100 Subject: [PATCH] sprint event --- .../mixins/minecraft/client/MixinInput.java | 18 ++- .../minecraft/client/MixinKeyboardInput.java | 24 ++-- .../entity/MixinClientPlayerEntity.java | 46 +++----- .../liquidbounce/event/EventManager.kt | 1 + .../liquidbounce/event/events/GameEvents.kt | 15 ++- .../modules/combat/ModuleSuperKnockback.kt | 110 ++++++++---------- .../combat/criticals/ModuleCriticals.kt | 16 +++ .../modules/combat/killaura/ModuleKillAura.kt | 21 +++- .../modules/exploit/ModuleAntiHunger.kt | 11 +- .../module/modules/movement/ModuleSprint.kt | 40 ++++--- 10 files changed, 162 insertions(+), 140 deletions(-) diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinInput.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinInput.java index 38aebaa3342..8631d8dd531 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinInput.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinInput.java @@ -19,15 +19,13 @@ package net.ccbluex.liquidbounce.injection.mixins.minecraft.client; -import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals; +import com.llamalad7.mixinextras.injector.ModifyReturnValue; import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint; import net.minecraft.client.input.Input; import net.minecraft.util.PlayerInput; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Input.class) public abstract class MixinInput { @@ -41,16 +39,14 @@ public abstract class MixinInput { @Shadow public PlayerInput playerInput; - @Inject(method = "hasForwardMovement", cancellable = true, at = @At("RETURN")) - private void hookOmnidirectionalSprintA(final CallbackInfoReturnable callbackInfoReturnable) { - if (ModuleCriticals.WhenSprinting.INSTANCE.getRunning() && ModuleCriticals.WhenSprinting.INSTANCE.getStopSprinting() == ModuleCriticals.WhenSprinting.StopSprintingMode.LEGIT) { - callbackInfoReturnable.setReturnValue(false); - return; + @ModifyReturnValue(method = "hasForwardMovement", at = @At("RETURN")) + private boolean hookOmnidirectionalSprint(boolean original) { + // Allow omnidirectional sprinting + if (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally()) { + return Math.abs(movementForward) > 1.0E-5F || Math.abs(movementSideways) > 1.0E-5F; } - final boolean hasMovement = Math.abs(movementForward) > 1.0E-5F || Math.abs(movementSideways) > 1.0E-5F; - - callbackInfoReturnable.setReturnValue(!ModuleSprint.INSTANCE.shouldPreventSprint() && (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally() ? hasMovement : callbackInfoReturnable.getReturnValue())); + return original; } } diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinKeyboardInput.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinKeyboardInput.java index 4e96560970e..651987ceb27 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinKeyboardInput.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinKeyboardInput.java @@ -23,9 +23,8 @@ import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.ccbluex.liquidbounce.event.EventManager; import net.ccbluex.liquidbounce.event.events.MovementInputEvent; -import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback; +import net.ccbluex.liquidbounce.event.events.SprintEvent; import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleInventoryMove; -import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint; import net.ccbluex.liquidbounce.utils.aiming.RotationManager; import net.ccbluex.liquidbounce.utils.input.InputTracker; import net.ccbluex.liquidbounce.utils.movement.DirectionalInput; @@ -61,9 +60,10 @@ private boolean hookInventoryMove(KeyBinding instance, Operation origin } /** - * At settings.backKey.isPressed() + * Later in the code, the sprint key is checked for being pressed. We need to update the state of the key + * as well. */ - @Inject(method = "tick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z", ordinal = 1)) + @Inject(method = "tick", at = @At("HEAD")) private void hookInventoryMoveSprint(CallbackInfo ci) { if (ModuleInventoryMove.INSTANCE.shouldHandleInputs(this.settings.sprintKey)) { this.settings.sprintKey.setPressed(InputTracker.INSTANCE.isPressedOnAny(this.settings.sprintKey)); @@ -76,6 +76,9 @@ private PlayerInput modifyInput(PlayerInput original) { EventManager.INSTANCE.callEvent(event); var directionalInput = changeDirection(event.getDirectionalInput()); + var sprintEvent = new SprintEvent(original.sprint(), SprintEvent.Source.INPUT); + EventManager.INSTANCE.callEvent(sprintEvent); + return new PlayerInput( directionalInput.getForwards(), directionalInput.getBackwards(), @@ -83,21 +86,10 @@ private PlayerInput modifyInput(PlayerInput original) { directionalInput.getRight(), event.getJump(), event.getSneak(), - playerInput.sprint() + sprintEvent.getSprint() ); } - @Inject(method = "tick", at = @At("RETURN")) - private void injectStopMove(CallbackInfo ci) { - if (ModuleSuperKnockback.INSTANCE.shouldStopMoving()) { - this.movementForward = 0f; - - if (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally()) { - this.movementSideways = 0f; - } - } - } - @Unique private DirectionalInput changeDirection(DirectionalInput input) { var player = MinecraftClient.getInstance().player; diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinClientPlayerEntity.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinClientPlayerEntity.java index 2713ab4f624..c5cb2f2cdaa 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinClientPlayerEntity.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinClientPlayerEntity.java @@ -24,10 +24,6 @@ import net.ccbluex.liquidbounce.event.EventManager; import net.ccbluex.liquidbounce.event.EventState; import net.ccbluex.liquidbounce.event.events.*; -import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback; -import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals; -import net.ccbluex.liquidbounce.features.module.modules.combat.killaura.ModuleKillAura; -import net.ccbluex.liquidbounce.features.module.modules.exploit.ModuleAntiHunger; import net.ccbluex.liquidbounce.features.module.modules.exploit.ModulePortalMenu; import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleEntityControl; import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleNoPush; @@ -308,13 +304,9 @@ private float hookSprintIgnoreHunger(float constant) { @ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/KeyBinding;isPressed()Z")) private boolean hookAutoSprint(boolean original) { - return !ModuleSuperKnockback.INSTANCE.shouldBlockSprinting() && !ModuleKillAura.INSTANCE.shouldBlockSprinting() - && (ModuleSprint.INSTANCE.getRunning() || original); - } - - @ModifyExpressionValue(method = "tickMovement", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isWalking()Z")) - private boolean hookOmnidirectionalSprintB(boolean original) { - return liquid_bounce$isOmniWalking(); + var event = new SprintEvent(original, SprintEvent.Source.MOVEMENT_TICK); + EventManager.INSTANCE.callEvent(event); + return event.getSprint(); } @ModifyExpressionValue(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isBlind()Z")) @@ -322,34 +314,32 @@ private boolean hookSprintIgnoreBlindness(boolean original) { return !ModuleSprint.INSTANCE.shouldIgnoreBlindness() && original; } - @ModifyExpressionValue(method = "canStartSprinting", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isWalking()Z")) - private boolean hookOmnidirectionalSprintC(boolean original) { - return liquid_bounce$isOmniWalking(); - } - @ModifyExpressionValue(method = "tickMovement", at = @At(value = "FIELD", target = "Lnet/minecraft/client/network/ClientPlayerEntity;horizontalCollision:Z")) private boolean hookSprintIgnoreCollision(boolean original) { return !ModuleSprint.INSTANCE.shouldIgnoreCollision() && original; } - @Unique - private boolean liquid_bounce$isOmniWalking() { - boolean hasMovement = Math.abs(input.movementForward) > 1.0E-5F || Math.abs(input.movementSideways) > 1.0E-5F; - boolean isWalking = (double) Math.abs(input.movementForward) >= 0.8 || (double) Math.abs(input.movementSideways) >= 0.8; - boolean modifiedIsWalking = this.isSubmergedInWater() ? hasMovement : isWalking; - return ModuleSprint.INSTANCE.shouldSprintOmnidirectionally() ? modifiedIsWalking : this.isWalking(); + @ModifyReturnValue(method = "isWalking", at = @At("RETURN")) + private boolean hookIsWalking(boolean original) { + if (!ModuleSprint.INSTANCE.shouldSprintOmnidirectionally()) { + return original; + } + + var hasMovement = Math.abs(input.movementForward) > 1.0E-5F || + Math.abs(input.movementSideways) > 1.0E-5F; + var isWalking = (double) Math.abs(input.movementForward) >= 0.8 || + (double) Math.abs(input.movementSideways) >= 0.8; + return this.isSubmergedInWater() ? hasMovement : isWalking; } @ModifyExpressionValue(method = "sendSprintingPacket", at = @At( value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSprinting()Z") ) - private boolean hookNoHungerSprint(boolean original) { - if (ModuleCriticals.WhenSprinting.INSTANCE.getRunning() && ModuleCriticals.WhenSprinting.INSTANCE.getStopSprinting() == ModuleCriticals.WhenSprinting.StopSprintingMode.ON_NETWORK) { - return false; - } - - return !(ModuleAntiHunger.INSTANCE.getRunning() && ModuleAntiHunger.INSTANCE.getNoSprint()) && original; + private boolean hookNetworkSprint(boolean original) { + var event = new SprintEvent(original, SprintEvent.Source.NETWORK); + EventManager.INSTANCE.callEvent(event); + return event.getSprint(); } @WrapWithCondition(method = "closeScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V")) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt index 2fe0edd6b45..91d92013b12 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt @@ -49,6 +49,7 @@ val ALL_EVENT_CLASSES: Array> = arrayOf( KeyboardCharEvent::class, InputHandleEvent::class, MovementInputEvent::class, + SprintEvent::class, KeyEvent::class, MouseRotationEvent::class, KeybindChangeEvent::class, diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/events/GameEvents.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/events/GameEvents.kt index 6c6a0684e09..a3086c646a0 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/events/GameEvents.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/events/GameEvents.kt @@ -54,7 +54,20 @@ class KeyEvent(val key: InputUtil.Key, val action: Int) : Event() object InputHandleEvent : Event() @Nameable("movementInput") -class MovementInputEvent(var directionalInput: DirectionalInput, var jump: Boolean, var sneak: Boolean) : Event() +class MovementInputEvent( + var directionalInput: DirectionalInput, + var jump: Boolean, + var sneak: Boolean +) : Event() + +@Nameable("sprint") +class SprintEvent(var sprint: Boolean, val source: Source) : Event() { + enum class Source { + INPUT, + MOVEMENT_TICK, + NETWORK + } +} @Nameable("mouseRotation") class MouseRotationEvent(var cursorDeltaX: Double, var cursorDeltaY: Double) : CancellableEvent() diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSuperKnockback.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSuperKnockback.kt index 0ad441e2de3..a665ccd1015 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSuperKnockback.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSuperKnockback.kt @@ -21,14 +21,17 @@ package net.ccbluex.liquidbounce.features.module.modules.combat import net.ccbluex.liquidbounce.config.types.Choice import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable -import net.ccbluex.liquidbounce.event.DummyEvent -import net.ccbluex.liquidbounce.event.Sequence import net.ccbluex.liquidbounce.event.events.AttackEntityEvent +import net.ccbluex.liquidbounce.event.events.MovementInputEvent +import net.ccbluex.liquidbounce.event.events.SprintEvent import net.ccbluex.liquidbounce.event.handler +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.criticals.ModuleCriticals +import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention import net.ccbluex.liquidbounce.utils.math.minus +import net.ccbluex.liquidbounce.utils.movement.DirectionalInput import net.minecraft.entity.Entity import net.minecraft.entity.LivingEntity import net.minecraft.network.packet.c2s.play.ClientCommandC2SPacket @@ -55,33 +58,12 @@ object ModuleSuperKnockback : ClientModule("SuperKnockback", Category.COMBAT, al tree(OnlyOnMove) } - var sequence: Sequence? = null - - init { - modes.onChange { - reset() - it - } - } - - override val running: Boolean - get() { - val running = super.running - - // Reset if the module is not handling events anymore - if (!running) { - reset() - } - - return running - } - object Packet : Choice("Packet") { override val parent: ChoiceConfigurable get() = modes @Suppress("unused") - val attackHandler = handler { event -> + private val attackHandler = handler { event -> if (event.isCancelled) { return@handler } @@ -114,23 +96,34 @@ object ModuleSuperKnockback : ClientModule("SuperKnockback", Category.COMBAT, al private val reSprintTicks by intRange("ReSprint", 0..1, 0..10, "ticks") - var antiSprint = false + private var cancelSprint = false @Suppress("unused") - val attackHandler = handler { event -> - if (event.isCancelled || !shouldOperate(event.entity) || !shouldStopSprinting(event) || sequence != null) { - return@handler + private val attackHandler = sequenceHandler { event -> + if (event.isCancelled || !shouldOperate(event.entity) || !shouldStopSprinting(event)) { + return@sequenceHandler } - runWithDummyEvent { - antiSprint = true - - it.waitUntil { !player.isSprinting && !player.lastSprinting } - it.waitTicks(reSprintTicks.random()) + cancelSprint = true + waitUntil { !player.isSprinting && !player.lastSprinting } + waitTicks(reSprintTicks.random()) + cancelSprint = false + } - antiSprint = false + @Suppress("unused") + private val movementHandler = handler( + priority = EventPriorityConvention.FIRST_PRIORITY + ) { event -> + if (cancelSprint) { + event.sprint = false } } + + override fun disable() { + cancelSprint = false + super.disable() + } + } object WTap : Choice("WTap") { @@ -142,27 +135,34 @@ object ModuleSuperKnockback : ClientModule("SuperKnockback", Category.COMBAT, al private val ticksUntilAllowedMovement by intRange("UntilAllowedMovement", 0..1, 0..10, "ticks") - var stopMoving = false + private var cancelMovement = false @Suppress("unused") - val attackHandler = handler { event -> - if (event.isCancelled || !shouldOperate(event.entity) || !shouldStopSprinting(event) || sequence != null) { - return@handler + private val attackHandler = sequenceHandler { event -> + if (event.isCancelled || !shouldOperate(event.entity) || !shouldStopSprinting(event)) { + return@sequenceHandler } - runWithDummyEvent { - it.waitTicks(ticksUntilMovementBlock.random()) - stopMoving = true - it.waitUntil { !player.input.hasForwardMovement() } - it.waitTicks(ticksUntilAllowedMovement.random()) - stopMoving = false + waitTicks(ticksUntilMovementBlock.random()) + cancelMovement = true + waitUntil { !player.input.hasForwardMovement() } + waitTicks(ticksUntilAllowedMovement.random()) + cancelMovement = false + } + + @Suppress("unused") + private val movementHandler = handler { event -> + if (cancelMovement) { + event.directionalInput = DirectionalInput.NONE } } - } - fun shouldBlockSprinting() = running && SprintTap.isSelected && SprintTap.antiSprint + override fun disable() { + cancelMovement = false + super.disable() + } - fun shouldStopMoving() = running && WTap.isSelected && WTap.stopMoving + } private fun shouldStopSprinting(event: AttackEntityEvent): Boolean { val enemy = event.entity @@ -201,20 +201,4 @@ object ModuleSuperKnockback : ClientModule("SuperKnockback", Category.COMBAT, al return true } - private fun reset() { - sequence?.cancel() - sequence = null - - WTap.stopMoving = false - SprintTap.antiSprint = false - } - - private fun runWithDummyEvent(action: suspend (Sequence) -> Unit) { - sequence = Sequence(this, { - action(this) - }, DummyEvent) - - sequence = null - } - } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/criticals/ModuleCriticals.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/criticals/ModuleCriticals.kt index 385e59512a8..5ce374465a0 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/criticals/ModuleCriticals.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/criticals/ModuleCriticals.kt @@ -22,6 +22,7 @@ import net.ccbluex.liquidbounce.config.types.NamedChoice import net.ccbluex.liquidbounce.config.types.NoneChoice import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable import net.ccbluex.liquidbounce.event.events.AttackEntityEvent +import net.ccbluex.liquidbounce.event.events.SprintEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule @@ -92,6 +93,21 @@ object ModuleCriticals : ClientModule("Criticals", Category.COMBAT) { } } + @Suppress("unused") + private val sprintHandler = handler { event -> + when (stopSprinting) { + StopSprintingMode.LEGIT -> + if (event.source == SprintEvent.Source.MOVEMENT_TICK || event.source == SprintEvent.Source.INPUT) { + event.sprint = false + } + StopSprintingMode.ON_NETWORK -> + if (event.source == SprintEvent.Source.NETWORK || event.source == SprintEvent.Source.INPUT) { + event.sprint = false + } + else -> {} + } + } + fun shouldAttemptCritWhileSprinting(): Boolean { return this.running && this.stopSprinting == StopSprintingMode.NONE } 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 540ab61f190..4afb64a1c6b 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 @@ -23,6 +23,7 @@ import net.ccbluex.liquidbounce.config.types.NamedChoice import net.ccbluex.liquidbounce.event.Sequence import net.ccbluex.liquidbounce.event.events.InputHandleEvent import net.ccbluex.liquidbounce.event.events.RotationUpdateEvent +import net.ccbluex.liquidbounce.event.events.SprintEvent import net.ccbluex.liquidbounce.event.events.WorldRenderEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.event.tickHandler @@ -209,7 +210,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { return@tickHandler } - if (player.isSprinting && shouldBlockSprinting()) { + if (player.isSprinting && shouldBlockSprinting) { player.isSprinting = false return@tickHandler } @@ -294,7 +295,7 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { } // Attack enemy - chosenEntity.attack(true, keepSprint && !shouldBlockSprinting()) + chosenEntity.attack(true, keepSprint && !shouldBlockSprinting) KillAuraNotifyWhenFail.failedHitsIncrement = 0 GenericDebugRecorder.recordDebugInfo(ModuleKillAura, "attackEntity", JsonObject().apply { @@ -540,10 +541,18 @@ object ModuleKillAura : ClientModule("KillAura", Category.COMBAT) { } } - fun shouldBlockSprinting() = running && !player.isOnGround && - criticalsMode != CriticalsMode.IGNORE && - targetTracker.lockedOnTarget != null && - clickScheduler.isClickOnNextTick(1) + val shouldBlockSprinting + get() = !player.isOnGround && + criticalsMode != CriticalsMode.IGNORE && + targetTracker.lockedOnTarget != null && + clickScheduler.isClickOnNextTick(1) + + @Suppress("unused") + private val sprintHandler = handler { event -> + if (shouldBlockSprinting) { + event.sprint = false + } + } private enum class RotationTimingMode(override val choiceName: String) : NamedChoice { NORMAL("Normal"), diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleAntiHunger.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleAntiHunger.kt index 50e721566ca..b61042754e8 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleAntiHunger.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleAntiHunger.kt @@ -20,6 +20,7 @@ package net.ccbluex.liquidbounce.features.module.modules.exploit import net.ccbluex.liquidbounce.event.events.NotificationEvent import net.ccbluex.liquidbounce.event.events.PacketEvent +import net.ccbluex.liquidbounce.event.events.SprintEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule @@ -54,7 +55,15 @@ object ModuleAntiHunger : ClientModule("AntiHunger", Category.EXPLOIT) { private var notificationCooldown = Chronometer() - val packetHandler = handler { event -> + @Suppress("unused") + private val sprintHandler = handler { event -> + if (noSprint && (event.source == SprintEvent.Source.NETWORK || event.source == SprintEvent.Source.INPUT)) { + event.sprint = false + } + } + + @Suppress("unused") + private val packetHandler = handler { event -> when (val packet = event.packet) { is ClientCommandC2SPacket -> { diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleSprint.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleSprint.kt index 17dbf9770ef..379f1fb928f 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleSprint.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleSprint.kt @@ -20,14 +20,15 @@ package net.ccbluex.liquidbounce.features.module.modules.movement import net.ccbluex.liquidbounce.config.types.NamedChoice import net.ccbluex.liquidbounce.event.events.GameTickEvent +import net.ccbluex.liquidbounce.event.events.SprintEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.utils.aiming.Rotation import net.ccbluex.liquidbounce.utils.aiming.RotationManager import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable +import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention import net.ccbluex.liquidbounce.utils.kotlin.Priority -import net.minecraft.util.math.MathHelper /** * Sprint module @@ -48,31 +49,42 @@ object ModuleSprint : ClientModule("Sprint", Category.MOVEMENT) { private val ignoreBlindness by boolean("IgnoreBlindness", false) private val ignoreHunger by boolean("IgnoreHunger", false) private val ignoreCollision by boolean("IgnoreCollision", false) - private val stopOnGround by boolean("StopOnGround", true) - private val stopOnAir by boolean("StopOnAir", true) + +// private val stopOnGround by boolean("StopOnGround", true) +// private val stopOnAir by boolean("StopOnAir", true) // DO NOT USE TREE TO MAKE SURE THAT THE ROTATIONS ARE NOT CHANGED private val rotationsConfigurable = RotationsConfigurable(this) - fun shouldSprintOmnidirectionally() = running && sprintMode == SprintMode.OMNIDIRECTIONAL - - fun shouldIgnoreBlindness() = running && ignoreBlindness - - fun shouldIgnoreHunger() = running && ignoreHunger - - fun shouldIgnoreCollision() = running && ignoreCollision - - fun shouldPreventSprint(): Boolean { - val deltaYaw = player.yaw - (RotationManager.currentRotation ?: return false).yaw + fun shouldSprintOmnidirectionally(): Boolean { +/* val deltaYaw = player.yaw - (RotationManager.currentRotation ?: return false).yaw val (forward, sideways) = Pair(player.input.movementForward, player.input.movementSideways) val hasForwardMovement = forward * MathHelper.cos(deltaYaw * 0.017453292f) + sideways * - MathHelper.sin(deltaYaw * 0.017453292f) > 1.0E-5 + MathHelper.sin(deltaYaw * 0.017453292f) > 1.0E-5 val preventSprint = (if (player.isOnGround) stopOnGround else stopOnAir) && !shouldSprintOmnidirectionally() && RotationManager.workingAimPlan?.applyVelocityFix == false && !hasForwardMovement return running && preventSprint + + */ + return running && sprintMode == SprintMode.OMNIDIRECTIONAL + } + + fun shouldIgnoreBlindness() = running && ignoreBlindness + + fun shouldIgnoreHunger() = running && ignoreHunger + + fun shouldIgnoreCollision() = running && ignoreCollision + + @Suppress("unused") + private val sprintHandler = handler( + priority = EventPriorityConvention.FIRST_PRIORITY + ) { event -> + if (event.source == SprintEvent.Source.MOVEMENT_TICK || event.source == SprintEvent.Source.INPUT) { + event.sprint = true + } } @Suppress("unused")