From 0f97cce0d8139b0ca0cb111603eb8c7678500142 Mon Sep 17 00:00:00 2001 From: Izuna <1zuna@ccbluex.net> Date: Wed, 8 Jan 2025 19:43:34 +0100 Subject: [PATCH] feat: player input overwrite on 1.21.3+ (#5233) Fixes 1.21.3+ Grim Simulation flags. Grim uses the from the client sent Player Input since 1.21.3+ which was not modified before. --- .../minecraft/client/MixinKeyboardInput.java | 79 +++++++++---------- .../mixins/minecraft/entity/MixinEntity.java | 29 +++---- .../liquidbounce/event/EventManager.kt | 1 - .../liquidbounce/event/events/PlayerEvents.kt | 3 - .../world/autofarm/AutoFarmAutoWalk.kt | 14 ++-- .../utils/aiming/RotationManager.kt | 29 ++----- .../utils/movement/DirectionalInput.kt | 20 ++++- 7 files changed, 83 insertions(+), 92 deletions(-) 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 335c1e7e981..4e96560970e 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 @@ -18,22 +18,19 @@ */ package net.ccbluex.liquidbounce.injection.mixins.minecraft.client; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import net.ccbluex.liquidbounce.event.EventManager; import net.ccbluex.liquidbounce.event.events.MovementInputEvent; -import net.ccbluex.liquidbounce.event.events.RotatedMovementInputEvent; import net.ccbluex.liquidbounce.features.module.modules.combat.ModuleSuperKnockback; import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleInventoryMove; import net.ccbluex.liquidbounce.features.module.modules.movement.ModuleSprint; -import net.ccbluex.liquidbounce.utils.aiming.AimPlan; -import net.ccbluex.liquidbounce.utils.aiming.Rotation; import net.ccbluex.liquidbounce.utils.aiming.RotationManager; import net.ccbluex.liquidbounce.utils.input.InputTracker; import net.ccbluex.liquidbounce.utils.movement.DirectionalInput; import net.minecraft.client.MinecraftClient; import net.minecraft.client.input.KeyboardInput; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.option.GameOptions; import net.minecraft.client.option.KeyBinding; import net.minecraft.util.PlayerInput; @@ -47,7 +44,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(KeyboardInput.class) -public class MixinKeyboardInput extends MixinInput { +public abstract class MixinKeyboardInput extends MixinInput { @Shadow @Final @@ -73,60 +70,58 @@ private void hookInventoryMoveSprint(CallbackInfo ci) { } } - @Inject(method = "tick", at = @At("RETURN")) - private void injectMovementInputEvent(CallbackInfo ci) { - var event = new MovementInputEvent(new DirectionalInput(this.playerInput.forward(), this.playerInput.backward(), this.playerInput.left(), this.playerInput.right()), this.playerInput.jump(), this.playerInput.sneak()); - + @ModifyExpressionValue(method = "tick", at = @At(value = "NEW", target = "(ZZZZZZZ)Lnet/minecraft/util/PlayerInput;")) + private PlayerInput modifyInput(PlayerInput original) { + var event = new MovementInputEvent(new DirectionalInput(original), original.jump(), original.sneak()); EventManager.INSTANCE.callEvent(event); + var directionalInput = changeDirection(event.getDirectionalInput()); + + return new PlayerInput( + directionalInput.getForwards(), + directionalInput.getBackwards(), + directionalInput.getLeft(), + directionalInput.getRight(), + event.getJump(), + event.getSneak(), + playerInput.sprint() + ); + } - var directionalInput = event.getDirectionalInput(); - - playerInput = new PlayerInput(directionalInput.getForwards(), directionalInput.getBackwards(), directionalInput.getLeft(), directionalInput.getRight(), playerInput.jump(), playerInput.sneak(), playerInput.sprint()); - this.movementForward = KeyboardInput.getMovementMultiplier(directionalInput.getForwards(), directionalInput.getBackwards()); - this.movementSideways = KeyboardInput.getMovementMultiplier(directionalInput.getLeft(), directionalInput.getRight()); - - this.liquid_bounce$fixStrafeMovement(); - + @Inject(method = "tick", at = @At("RETURN")) + private void injectStopMove(CallbackInfo ci) { if (ModuleSuperKnockback.INSTANCE.shouldStopMoving()) { this.movementForward = 0f; - ModuleSprint sprint = ModuleSprint.INSTANCE; - - if (sprint.shouldSprintOmnidirectionally()) { + if (ModuleSprint.INSTANCE.shouldSprintOmnidirectionally()) { this.movementSideways = 0f; } } - - playerInput = new PlayerInput(playerInput.forward(), playerInput.backward(), playerInput.left(), playerInput.right(), event.getJump(), event.getSneak(), playerInput.sprint()); } @Unique - private void liquid_bounce$fixStrafeMovement() { - ClientPlayerEntity player = MinecraftClient.getInstance().player; - RotationManager rotationManager = RotationManager.INSTANCE; - Rotation rotation = rotationManager.getCurrentRotation(); - AimPlan configurable = rotationManager.getWorkingAimPlan(); - - float z = this.movementForward; - float x = this.movementSideways; + private DirectionalInput changeDirection(DirectionalInput input) { + var player = MinecraftClient.getInstance().player; + var rotation = RotationManager.INSTANCE.getCurrentRotation(); + var configurable = RotationManager.INSTANCE.getWorkingAimPlan(); - final RotatedMovementInputEvent MoveInputEvent; + float z = KeyboardInput.getMovementMultiplier(input.getForwards(), input.getBackwards()); + float x = KeyboardInput.getMovementMultiplier(input.getLeft(), input.getRight()); if (configurable == null || !configurable.getApplyVelocityFix() || rotation == null || player == null) { - MoveInputEvent = new RotatedMovementInputEvent(z, x); - EventManager.INSTANCE.callEvent(MoveInputEvent); - } else { - float deltaYaw = player.getYaw() - rotation.getYaw(); + return input; + } - float newX = x * MathHelper.cos(deltaYaw * 0.017453292f) - z * MathHelper.sin(deltaYaw * 0.017453292f); - float newZ = z * MathHelper.cos(deltaYaw * 0.017453292f) + x * MathHelper.sin(deltaYaw * 0.017453292f); + float deltaYaw = player.getYaw() - rotation.getYaw(); - MoveInputEvent = new RotatedMovementInputEvent(Math.round(newZ), Math.round(newX)); - EventManager.INSTANCE.callEvent(MoveInputEvent); - } + float newX = x * MathHelper.cos(deltaYaw * 0.017453292f) - z * + MathHelper.sin(deltaYaw * 0.017453292f); + float newZ = z * MathHelper.cos(deltaYaw * 0.017453292f) + x * + MathHelper.sin(deltaYaw * 0.017453292f); + + var movementSideways = Math.round(newX); + var movementForward = Math.round(newZ); - this.movementSideways = MoveInputEvent.getSideways(); - this.movementForward = MoveInputEvent.getForward(); + return new DirectionalInput(movementForward, movementSideways); } } diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinEntity.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinEntity.java index a184162b0aa..70adc7acd92 100644 --- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinEntity.java +++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/entity/MixinEntity.java @@ -20,6 +20,7 @@ package net.ccbluex.liquidbounce.injection.mixins.minecraft.entity; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; import net.ccbluex.liquidbounce.event.EventManager; import net.ccbluex.liquidbounce.event.events.*; import net.ccbluex.liquidbounce.features.module.modules.exploit.ModuleNoPitchLimit; @@ -109,26 +110,26 @@ public float hookNoPitchLimit(float value, float min, float max) { return MathHelper.clamp(value, min, max); } - @Redirect(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;movementInputToVelocity(Lnet/minecraft/util/math/Vec3d;FF)Lnet/minecraft/util/math/Vec3d;")) - public Vec3d hookVelocity(Vec3d movementInput, float speed, float yaw) { - if ((Object) this == MinecraftClient.getInstance().player) { - PlayerVelocityStrafe event = new PlayerVelocityStrafe(movementInput, speed, yaw, MixinEntity.movementInputToVelocity(movementInput, speed, yaw)); - EventManager.INSTANCE.callEvent(event); - return event.getVelocity(); + @ModifyExpressionValue(method = "updateVelocity", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;movementInputToVelocity(Lnet/minecraft/util/math/Vec3d;FF)Lnet/minecraft/util/math/Vec3d;")) + public Vec3d hookVelocity(Vec3d original, @Local(argsOnly = true) Vec3d movementInput, @Local(argsOnly = true) float speed, @Local(argsOnly = true) float yaw) { + if ((Object) this != MinecraftClient.getInstance().player) { + return original; } - return MixinEntity.movementInputToVelocity(movementInput, speed, yaw); + var event = new PlayerVelocityStrafe(movementInput, speed, yaw, original); + EventManager.INSTANCE.callEvent(event); + return event.getVelocity(); } - @Redirect(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getStepHeight()F")) - private float hookStepHeight(Entity instance) { - if ((Object) this == MinecraftClient.getInstance().player) { - PlayerStepEvent stepEvent = new PlayerStepEvent(instance.getStepHeight()); - EventManager.INSTANCE.callEvent(stepEvent); - return stepEvent.getHeight(); + @ModifyExpressionValue(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Entity;getStepHeight()F")) + private float hookStepHeight(float original) { + if ((Object) this != MinecraftClient.getInstance().player) { + return original; } - return instance.getStepHeight(); + var stepEvent = new PlayerStepEvent(original); + EventManager.INSTANCE.callEvent(stepEvent); + return stepEvent.getHeight(); } @Inject(method = "adjustMovementForCollisions(Lnet/minecraft/util/math/Vec3d;)Lnet/minecraft/util/math/Vec3d;", diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt index 9daa5177b68..2fe0edd6b45 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt @@ -72,7 +72,6 @@ val ALL_EVENT_CLASSES: Array> = arrayOf( PlayerNetworkMovementTickEvent::class, PlayerPushOutEvent::class, PlayerMoveEvent::class, - RotatedMovementInputEvent::class, PlayerJumpEvent::class, PlayerAfterJumpEvent::class, PlayerUseMultiplier::class, diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/events/PlayerEvents.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/events/PlayerEvents.kt index b80ee47981c..d12d9355b53 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/events/PlayerEvents.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/events/PlayerEvents.kt @@ -64,9 +64,6 @@ class PlayerPushOutEvent : CancellableEvent() @Nameable("playerMove") class PlayerMoveEvent(val type: MovementType, val movement: Vec3d) : Event() -@Nameable("rotatedMovementInput") -class RotatedMovementInputEvent(var forward: Float, var sideways: Float) : Event() - @Nameable("playerJump") class PlayerJumpEvent(var motion: Float) : CancellableEvent() diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/autofarm/AutoFarmAutoWalk.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/autofarm/AutoFarmAutoWalk.kt index a9581fddfbd..d91c5989f5f 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/autofarm/AutoFarmAutoWalk.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/autofarm/AutoFarmAutoWalk.kt @@ -21,7 +21,6 @@ package net.ccbluex.liquidbounce.features.module.modules.world.autofarm import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable import net.ccbluex.liquidbounce.event.events.MovementInputEvent import net.ccbluex.liquidbounce.event.events.NotificationEvent -import net.ccbluex.liquidbounce.event.events.RotatedMovementInputEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.utils.aiming.Rotation import net.ccbluex.liquidbounce.utils.aiming.RotationManager @@ -121,15 +120,18 @@ object AutoFarmAutoWalk : ToggleableConfigurable(ModuleAutoFarm, "AutoWalk", fal private fun shouldWalk() = (walkTarget != null && mc.currentScreen !is HandledScreen<*>) - val horizontalMovementHandling = handler { event -> - if (!shouldWalk()) return@handler - - event.forward = 1f + @Suppress("unused") + private val horizontalMovementHandling = handler { event -> + if (!shouldWalk()) { + return@handler + } + event.directionalInput = event.directionalInput.copy(forwards = true) player.isSprinting = true } - val verticalMovementHandling = handler { event -> + @Suppress("unused") + private val verticalMovementHandling = handler { event -> if (!shouldWalk()) return@handler // We want to swim up in water, so we don't drown and can move onwards diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/aiming/RotationManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/aiming/RotationManager.kt index 2c1c2b75183..ddb3f32f107 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/aiming/RotationManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/aiming/RotationManager.kt @@ -40,7 +40,6 @@ import net.minecraft.entity.Entity import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket import net.minecraft.network.packet.c2s.play.PlayerMoveC2SPacket import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket -import net.minecraft.util.math.Vec3d /** @@ -213,7 +212,13 @@ object RotationManager : EventListener { @Suppress("unused") private val velocityHandler = handler { event -> if (workingAimPlan?.applyVelocityFix == true) { - event.velocity = fixVelocity(event.velocity, event.movementInput, event.speed) + val rotation = currentRotation ?: return@handler + + event.velocity = Entity.movementInputToVelocity( + event.movementInput, + event.speed, + rotation.yaw + ) } } @@ -265,26 +270,6 @@ object RotationManager : EventListener { theoreticalServerRotation = rotation } - /** - * Fix velocity - */ - private fun fixVelocity(currVelocity: Vec3d, movementInput: Vec3d, speed: Float): Vec3d { - currentRotation?.let { rotation -> - val yaw = rotation.yaw - val d = movementInput.lengthSquared() - - return if (d < 1.0E-7) { - Vec3d.ZERO - } else { - val vec3d = (if (d > 1.0) movementInput.normalize() else movementInput).multiply(speed.toDouble()) - - vec3d.rotateY(-yaw.toRadians()) - } - } - - return currVelocity - } - override val running: Boolean get() = inGame diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/movement/DirectionalInput.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/movement/DirectionalInput.kt index 4098572bce7..7ec67959ff4 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/movement/DirectionalInput.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/movement/DirectionalInput.kt @@ -1,6 +1,7 @@ package net.ccbluex.liquidbounce.utils.movement import net.minecraft.client.input.Input +import net.minecraft.util.PlayerInput data class DirectionalInput( val forwards: Boolean, @@ -9,10 +10,21 @@ data class DirectionalInput( val right: Boolean, ) { constructor(input: Input) : this( - input.playerInput.forward, - input.playerInput.backward, - input.playerInput.left, - input.playerInput.right + input.playerInput + ) + + constructor(input: PlayerInput) : this( + input.forward, + input.backward, + input.left, + input.right + ) + + constructor(movementForward: Float, movementSideways: Float) : this( + forwards = movementForward > 0.0, + backwards = movementForward < 0.0, + left = movementSideways > 0.0, + right = movementSideways < 0.0 ) override fun equals(other: Any?): Boolean {