Skip to content

Commit

Permalink
feat: player input overwrite on 1.21.3+ (#5233)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
1zun4 authored Jan 8, 2025
1 parent a6b6159 commit 0f97cce
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ val ALL_EVENT_CLASSES: Array<KClass<out Event>> = arrayOf(
PlayerNetworkMovementTickEvent::class,
PlayerPushOutEvent::class,
PlayerMoveEvent::class,
RotatedMovementInputEvent::class,
PlayerJumpEvent::class,
PlayerAfterJumpEvent::class,
PlayerUseMultiplier::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -121,15 +120,18 @@ object AutoFarmAutoWalk : ToggleableConfigurable(ModuleAutoFarm, "AutoWalk", fal

private fun shouldWalk() = (walkTarget != null && mc.currentScreen !is HandledScreen<*>)

val horizontalMovementHandling = handler<RotatedMovementInputEvent> { event ->
if (!shouldWalk()) return@handler

event.forward = 1f
@Suppress("unused")
private val horizontalMovementHandling = handler<MovementInputEvent> { event ->
if (!shouldWalk()) {
return@handler
}

event.directionalInput = event.directionalInput.copy(forwards = true)
player.isSprinting = true
}

val verticalMovementHandling = handler<MovementInputEvent> { event ->
@Suppress("unused")
private val verticalMovementHandling = handler<MovementInputEvent> { event ->
if (!shouldWalk()) return@handler

// We want to swim up in water, so we don't drown and can move onwards
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


/**
Expand Down Expand Up @@ -213,7 +212,13 @@ object RotationManager : EventListener {
@Suppress("unused")
private val velocityHandler = handler<PlayerVelocityStrafe> { 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
)
}
}

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 {
Expand Down

0 comments on commit 0f97cce

Please sign in to comment.