Skip to content

Commit

Permalink
feats(legacy): FreeLook module, fixed rotation pitch not being smooth…
Browse files Browse the repository at this point in the history
… and added FreezeYCamera option to Scaffold. (CCBlueX#4062)
  • Loading branch information
mems01 authored Oct 4, 2024
1 parent 8975db4 commit 98bb8b8
Show file tree
Hide file tree
Showing 14 changed files with 216 additions and 56 deletions.
18 changes: 14 additions & 4 deletions src/main/java/net/ccbluex/liquidbounce/event/Events.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
*/
package net.ccbluex.liquidbounce.event

import net.ccbluex.liquidbounce.features.module.modules.render.FreeCam
import net.ccbluex.liquidbounce.utils.extensions.withY
import net.minecraft.block.Block
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.multiplayer.WorldClient
import net.minecraft.entity.Entity
import net.minecraft.network.Packet
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.util.MovementInput
import net.minecraft.util.*

/**
* Called when player attacks other entity
Expand Down Expand Up @@ -183,6 +182,17 @@ class PlayerTickEvent(val state: EventState) : CancellableEvent()

class RotationUpdateEvent : Event()

class RotationSetEvent(var yawDiff: Float, var pitchDiff: Float) : CancellableEvent()

class CameraPositionEvent(
private val currPos: Vec3, private val prevPos: Vec3, private val lastTickPos: Vec3,
var result: FreeCam.PositionPair? = null,
) : Event() {
fun withY(value: Double) {
result = FreeCam.PositionPair(currPos.withY(value), prevPos.withY(value), lastTickPos.withY(value))
}
}

/**
* Called when minecraft player will be updated
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ object ModuleManager : Listenable {
OverrideRaycast,
TickBase,
RotationRecorder,
ForwardTrack
ForwardTrack,
FreeLook
)

InventoryManager.startCoroutine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
*/
package net.ccbluex.liquidbounce.features.module.modules.`fun`

import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.Rotation
import net.ccbluex.liquidbounce.utils.RotationUtils.currentRotation
import net.ccbluex.liquidbounce.utils.RotationUtils.serverRotation
import net.ccbluex.liquidbounce.utils.RotationUtils.syncSpecialModuleRotations
import net.ccbluex.liquidbounce.utils.misc.RandomUtils.nextFloat
import net.ccbluex.liquidbounce.value.BoolValue
import net.ccbluex.liquidbounce.value.FloatValue
Expand All @@ -16,25 +19,24 @@ object Derp : Module("Derp", Category.FUN, subjective = true, hideModule = false

private val headless by BoolValue("Headless", false)
private val spinny by BoolValue("Spinny", false)
private val increment by FloatValue("Increment", 1F, 0F..50F) { spinny }
private val increment by FloatValue("Increment", 1F, 0F..50F) { spinny }

private var currentSpin = 0F
override fun onDisable() {
syncSpecialModuleRotations()
}

val rotation: Rotation
get() {
val rot = Rotation(mc.thePlayer.rotationYaw + nextFloat(-180f, 180f), nextFloat(-90f, 90f))
val rotationToUse = currentRotation ?: serverRotation

val rot = Rotation(rotationToUse.yaw, nextFloat(-90f, 90f))

if (headless)
rot.pitch = 180F

if (spinny) {
currentSpin += increment
rot.yaw = currentSpin
}

rot.fixedSensitivity()
rot.yaw += if (spinny) increment else nextFloat(-180f, 180f)

return rot
return rot.fixedSensitivity()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
*/
package net.ccbluex.liquidbounce.features.module.modules.render

import net.ccbluex.liquidbounce.event.EventTarget
import net.ccbluex.liquidbounce.event.MovementInputEvent
import net.ccbluex.liquidbounce.event.WorldEvent
import net.ccbluex.liquidbounce.event.*
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.MovementUtils.isMoving
Expand All @@ -26,7 +24,7 @@ object FreeCam : Module("FreeCam", Category.RENDER, gameDetecting = false, hideM
private val allowCameraInteract by BoolValue("AllowCameraInteract", true)
private val allowRotationChange by BoolValue("AllowRotationChange", true)

private data class PositionPair(var pos: Vec3, var lastPos: Vec3, var extraPos: Vec3 = lastPos) {
data class PositionPair(var pos: Vec3, var lastPos: Vec3, var extraPos: Vec3 = lastPos) {
operator fun plusAssign(velocity: Vec3) {
lastPos = pos
pos += velocity
Expand All @@ -46,6 +44,7 @@ object FreeCam : Module("FreeCam", Category.RENDER, gameDetecting = false, hideM

override fun onDisable() {
pos = null
originalPos = null
}

@EventTarget
Expand Down Expand Up @@ -79,22 +78,24 @@ object FreeCam : Module("FreeCam", Category.RENDER, gameDetecting = false, hideM
}

fun useModifiedPosition() {
if (!state)
return

val player = mc.thePlayer ?: return

val data = pos ?: return

originalPos = PositionPair(player.currPos, player.prevPos, player.lastTickPos)

val event = CameraPositionEvent(player.currPos, player.prevPos, player.lastTickPos)
EventManager.callEvent(event)

event.result?.run {
player.setPosAndPrevPos(pos, lastPos, extraPos)
return
}

val data = pos ?: return

player.setPosAndPrevPos(data.pos, data.lastPos, data.lastPos)
}

fun restoreOriginalPosition() {
if (!state)
return

val player = mc.thePlayer ?: return

originalPos?.run { player.setPosAndPrevPos(pos, lastPos, extraPos) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* LiquidBounce Hacked Client
* A free open source mixin-based injection hacked client for Minecraft using Minecraft Forge.
* https://github.com/CCBlueX/LiquidBounce/
*/
package net.ccbluex.liquidbounce.features.module.modules.render

import net.ccbluex.liquidbounce.event.EventTarget
import net.ccbluex.liquidbounce.event.RotationSetEvent
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.utils.Rotation
import net.ccbluex.liquidbounce.utils.extensions.prevRotation
import net.ccbluex.liquidbounce.utils.extensions.rotation

object FreeLook : Module("FreeLook", Category.RENDER) {

// The module's rotations
private var currRotation = Rotation.ZERO
private var prevRotation = currRotation

// The player's rotations
private var savedCurrRotation = Rotation.ZERO
private var savedPrevRotation = Rotation.ZERO

override fun onEnable() {
mc.thePlayer?.run {
currRotation = rotation
prevRotation = prevRotation
}
}

@EventTarget
fun onRotationSet(event: RotationSetEvent) {
if (mc.gameSettings.thirdPersonView != 0) {
event.cancelEvent()
}

prevRotation = currRotation
currRotation += Rotation(event.yawDiff, -event.pitchDiff)

currRotation.withLimitedPitch()
}

fun useModifiedRotation() {
val player = mc.thePlayer ?: return

savedCurrRotation = player.rotation
savedPrevRotation = player.prevRotation

if (!handleEvents())
return

player.rotation = currRotation
player.prevRotation = prevRotation
}

fun restoreOriginalRotation() {
val player = mc.thePlayer ?: return

if (mc.gameSettings.thirdPersonView == 0) {
savedCurrRotation = player.rotation
savedPrevRotation = player.prevRotation
return
}

if (!handleEvents())
return

player.rotation = savedCurrRotation
player.prevRotation = savedPrevRotation
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package net.ccbluex.liquidbounce.features.module.modules.render

import net.ccbluex.liquidbounce.event.EventState
import net.ccbluex.liquidbounce.event.EventTarget
import net.ccbluex.liquidbounce.event.MotionEvent
import net.ccbluex.liquidbounce.features.module.Category
Expand Down Expand Up @@ -36,13 +37,17 @@ object Rotations : Module("Rotations", Category.RENDER, gameDetecting = false, h

@EventTarget
fun onMotion(event: MotionEvent) {
if (event.eventState != EventState.POST)
return

val thePlayer = mc.thePlayer ?: return
val targetRotation = getRotation() ?: return
val targetRotation = getRotation() ?: serverRotation

prevHeadPitch = headPitch
headPitch = targetRotation.pitch

thePlayer.rotationYawHead = targetRotation.yaw

if (shouldRotate() && body && !realistic) {
thePlayer.renderYawOffset = thePlayer.rotationYawHead
}
Expand Down Expand Up @@ -81,12 +86,12 @@ object Rotations : Module("Rotations", Category.RENDER, gameDetecting = false, h
* Which rotation should the module use?
*/
fun getRotation(): Rotation? {
val targetRotation = if (specialCases) serverRotation else currentRotation
val currRotation = if (specialCases) serverRotation else currentRotation

return if (smoothRotations && lastRotation != null && targetRotation != null) {
smoothRotation(lastRotation!!, targetRotation)
return if (smoothRotations && currRotation != null) {
smoothRotation(lastRotation ?: return currRotation, currRotation)
} else {
targetRotation
currRotation
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ object Scaffold : Module("Scaffold", Category.WORLD, Keyboard.KEY_I, hideModule

// Safety
private val sameY by BoolValue("SameY", false) { scaffoldMode != "GodBridge" }
private val freezeCameraY by BoolValue("FreezeCameraY", false)
private val jumpOnUserInput by BoolValue("JumpOnUserInput", true) { sameY && scaffoldMode != "GodBridge" }

private val safeWalkValue = BoolValue("SafeWalk", true) { scaffoldMode != "GodBridge" }
Expand All @@ -343,7 +344,7 @@ object Scaffold : Module("Scaffold", Category.WORLD, Keyboard.KEY_I, hideModule
var placeRotation: PlaceRotation? = null

// Launch position
private var launchY = 0
private var launchY = -999

val shouldJumpOnInput
get() = !jumpOnUserInput || !mc.gameSettings.keyBindJump.isKeyDown && mc.thePlayer.posY >= launchY && !mc.thePlayer.onGround
Expand Down Expand Up @@ -536,6 +537,9 @@ object Scaffold : Module("Scaffold", Category.WORLD, Keyboard.KEY_I, hideModule

@EventTarget
fun onRotationUpdate(event: RotationUpdateEvent) {
if (mc.thePlayer.ticksExisted == 1)
launchY = mc.thePlayer.posY.roundToInt()

val rotation = RotationUtils.currentRotation

update()
Expand Down Expand Up @@ -607,6 +611,14 @@ object Scaffold : Module("Scaffold", Category.WORLD, Keyboard.KEY_I, hideModule
event.strafe *= eagleSpeed / 0.3f
}

@EventTarget
fun onCameraUpdate(event: CameraPositionEvent) {
if (!freezeCameraY || mc.thePlayer.posY < launchY || mc.thePlayer.posY - launchY > 1.5 || launchY == -999)
return

event.withY(launchY.toDouble())
}

@EventTarget
fun onMovementInput(event: MovementInputEvent) {
val player = mc.thePlayer ?: return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package net.ccbluex.liquidbounce.injection.forge.mixins.entity;

import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.RotationSetEvent;
import net.ccbluex.liquidbounce.event.StrafeEvent;
import net.ccbluex.liquidbounce.features.module.modules.combat.HitBox;
import net.ccbluex.liquidbounce.features.module.modules.exploit.NoPitchLimit;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.MathHelper;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
Expand All @@ -26,6 +28,7 @@
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.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand Down Expand Up @@ -234,17 +237,9 @@ private void getCollisionBorderSize(final CallbackInfoReturnable<Float> callback
callbackInfoReturnable.setReturnValue(0.1F + hitBox.determineSize((Entity) (Object) this));
}

@Inject(method = "setAngles", at = @At("HEAD"), cancellable = true)
private void setAngles(final float yaw, final float pitch, final CallbackInfo callbackInfo) {
if (NoPitchLimit.INSTANCE.handleEvents()) {
callbackInfo.cancel();

prevRotationYaw = rotationYaw;
prevRotationPitch = rotationPitch;

rotationYaw += yaw * 0.15f;
rotationPitch -= pitch * 0.15f;
}
@Redirect(method = "setAngles", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;clamp_float(FFF)F"))
private float setAngles(float a, float min, float max) {
return NoPitchLimit.INSTANCE.handleEvents() ? a : MathHelper.clamp_float(a, min, max);
}

@Inject(method = "moveFlying", at = @At("HEAD"), cancellable = true)
Expand Down Expand Up @@ -276,4 +271,17 @@ private void isInLava(final CallbackInfoReturnable<Boolean> cir) {
private void hookFreeCamModifiedRaycast(float tickDelta, CallbackInfoReturnable<Vec3> cir) {
cir.setReturnValue(FreeCam.INSTANCE.modifyRaycast(cir.getReturnValue(), (Entity) (Object) this, tickDelta));
}

@Inject(method = "setAngles", at = @At("HEAD"), cancellable = true)
private void injectRotationSetEvent(float yaw, float pitch, CallbackInfo ci) {
if ((Object) this != mc.thePlayer)
return;

RotationSetEvent event = new RotationSetEvent((float) (yaw * 0.15), (float) (pitch * 0.15));

EventManager.INSTANCE.callEvent(event);

if (event.isCancelled())
ci.cancel();
}
}
Loading

0 comments on commit 98bb8b8

Please sign in to comment.