Skip to content
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: module zoom #3938

Merged
merged 5 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

package net.ccbluex.liquidbounce.injection.mixins.minecraft.client;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import com.llamalad7.mixinextras.sugar.Local;
import net.ccbluex.liquidbounce.event.EventManager;
import net.ccbluex.liquidbounce.event.events.MouseButtonEvent;
import net.ccbluex.liquidbounce.event.events.MouseCursorEvent;
import net.ccbluex.liquidbounce.event.events.MouseRotationEvent;
import net.ccbluex.liquidbounce.event.events.MouseScrollEvent;
import net.ccbluex.liquidbounce.event.events.*;
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleZoom;
import net.minecraft.client.Mouse;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -51,6 +51,13 @@ private void hookMouseScroll(long window, double horizontal, double vertical, Ca
EventManager.INSTANCE.callEvent(new MouseScrollEvent(horizontal, vertical));
}

@Inject(method = "onMouseScroll", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isSpectator()Z", shift = At.Shift.BEFORE), cancellable = true)
private void hookMouseScroll(long window, double horizontal, double vertical, CallbackInfo ci, @Local(ordinal = 2) int k) {
if (EventManager.INSTANCE.callEvent(new MouseScrollInHotbarEvent(k)).isCancelled()) {
ci.cancel();
}
}

/**
* Hook mouse cursor event
*/
Expand All @@ -59,6 +66,16 @@ private void hookCursorPos(long window, double x, double y, CallbackInfo callbac
EventManager.INSTANCE.callEvent(new MouseCursorEvent(x, y));
}

@ModifyExpressionValue(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/option/Perspective;isFirstPerson()Z"))
private boolean injectZoomCondition1(boolean original) {
return original || ModuleZoom.INSTANCE.getEnabled();
}

@ModifyExpressionValue(method = "updateMouse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingSpyglass()Z"))
private boolean injectZoomCondition2(boolean original) {
return original || ModuleZoom.INSTANCE.getEnabled();
}

/**
* Hook mouse cursor event
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/

package net.ccbluex.liquidbounce.injection.mixins.minecraft.render;

import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
Expand Down Expand Up @@ -259,11 +258,19 @@ private void hookRestoreLightMap(RenderTickCounter tickCounter, CallbackInfo ci)

@ModifyExpressionValue(method = "getFov", at = @At(value = "INVOKE", target = "Ljava/lang/Integer;intValue()I", remap = false))
private int hookGetFov(int original) {
if (ModuleNoFov.INSTANCE.getEnabled()) {
return ModuleNoFov.INSTANCE.getFov(original);
int result;

if (ModuleZoom.INSTANCE.getEnabled()) {
return ModuleZoom.INSTANCE.getFov(true, 0);
} else {
result = ModuleZoom.INSTANCE.getFov(false, original);
}

if (ModuleNoFov.INSTANCE.getEnabled() && result == original) {
return ModuleNoFov.INSTANCE.getFov(result);
}

return original;
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public interface ChatHudLineAddition {

/**
* Sets the count of the message.
* This indicates how many times this massage has already been sent in
* {@link ModuleBetterChat}.
* This indicates how many times this massage has already been sent in {@link ModuleBetterChat}.
*/
void liquid_bounce$setCount(int count);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ val ALL_EVENT_CLASSES: Array<KClass<out Event>> = arrayOf(
SpaceSeperatedNamesChangeEvent::class,
ClickGuiScaleChangeEvent::class,
BrowserUrlChangeEvent::class,
TagEntityEvent::class
TagEntityEvent::class,
MouseScrollInHotbarEvent::class
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package net.ccbluex.liquidbounce.event.events

import net.ccbluex.liquidbounce.event.CancellableEvent
import net.ccbluex.liquidbounce.event.Event
import net.ccbluex.liquidbounce.utils.client.Nameable
import net.ccbluex.liquidbounce.web.socket.protocol.event.WebSocketEvent
Expand All @@ -40,6 +41,9 @@ class MouseButtonEvent(val button: Int, val action: Int, val mods: Int) : Event(
@WebSocketEvent
class MouseScrollEvent(val horizontal: Double, val vertical: Double) : Event()

@Nameable("mouseScrollInHotbar")
class MouseScrollInHotbarEvent(val speed: Int) : CancellableEvent()

@Nameable("mouseCursor")
@WebSocketEvent
class MouseCursorEvent(val x: Double, val y: Double) : Event()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ object ModuleManager : Listenable, Iterable<Module> by modules {
ModuleTrueSight,
ModuleXRay,
ModuleDebug,
ModuleZoom,

// World
ModuleAutoDisable,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* This file is part of LiquidBounce (https://github.com/CCBlueX/LiquidBounce)
*
* Copyright (c) 2015 - 2024 CCBlueX
*
* LiquidBounce is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LiquidBounce is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LiquidBounce. If not, see <https://www.gnu.org/licenses/>.
*/
package net.ccbluex.liquidbounce.features.module.modules.render

import net.ccbluex.liquidbounce.config.ToggleableConfigurable
import net.ccbluex.liquidbounce.event.events.MouseScrollInHotbarEvent
import net.ccbluex.liquidbounce.event.handler
import net.ccbluex.liquidbounce.features.module.Category
import net.ccbluex.liquidbounce.features.module.Module
import net.ccbluex.liquidbounce.injection.mixins.minecraft.client.MixinMouse
import net.ccbluex.liquidbounce.utils.client.Chronometer
import net.minecraft.util.math.MathHelper
import kotlin.math.abs
import kotlin.math.round

/**
* Module Zoom
*
* Allows you to zoom.
*
* The mose is slowed down with the help of mixins in [MixinMouse].
*/
object ModuleZoom : Module("Zoom", Category.RENDER, bindAction = BindAction.HOLD) {

val zoom by int("Zoom", 30, 10..150)

object Scroll : ToggleableConfigurable(this, "Scroll", true) {

val speed by float("Speed", 2f, 0.5f..8f)

@Suppress("unused")
val onScroll = handler<MouseScrollInHotbarEvent> {
previousFov = getFov(true)
targetFov = (targetFov + round(it.speed * this.speed).toInt()).coerceIn(1..179)
reset()
it.cancelEvent()
}

}

init {
tree(Scroll)
}

private val chronometer = Chronometer()
private var targetFov = 0
private var previousFov = 0
private var scaledDifference = 0.0
private var disableAnimationFinished = true

override fun enable() {
targetFov = zoom
previousFov = getDefaultFov()
reset()
}

override fun disable() {
previousFov = getFov(true)
chronometer.reset()
targetFov = getDefaultFov()
reset()
disableAnimationFinished = false
}

fun getFov(enabled: Boolean, original: Int = 0): Int {
if (!enabled && disableAnimationFinished) {
return original
}

val factor = (chronometer.elapsed / scaledDifference).toFloat().coerceIn(0F..1F)
if (!enabled && factor == 1f) {
disableAnimationFinished = true
}

return MathHelper.lerp(factor, previousFov, targetFov)
}

private fun getDefaultFov(): Int {
val fov = mc.options.fov.value
return if (ModuleNoFov.enabled) ModuleNoFov.getFov(fov) else fov
}

private fun reset() {
chronometer.reset()
scaledDifference = 2.5 * abs(targetFov - previousFov)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ import net.ccbluex.liquidbounce.render.engine.Vec3
import net.ccbluex.liquidbounce.utils.client.mc
import net.minecraft.client.gl.ShaderProgram
import net.minecraft.client.render.*
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormat.DrawMode
import net.minecraft.client.render.VertexFormats
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.math.Box
import net.minecraft.util.math.Direction
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/liquidbounce/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@
"liquidbounce.module.vehicleOneHit.description": "Allows you to break any vehicle with a single hit.",
"liquidbounce.module.velocity.description": "Modifies the amount of velocity you take.",
"liquidbounce.module.xRay.description": "Only renders selected blocks.",
"liquidbounce.module.zoom.description": "Allows you to make everything in your world appear smaller or bigger.",
"liquidbounce.module.antiHunger.description": "Prevents you from getting hungry.",
"liquidbounce.module.antiHunger.messages.warnSprint": "Another module caused sprint packets, which could lead to hunger.",
"liquidbounce.module.antiHunger.messages.warnBreak": "You are breaking a block, which could lead to hunger.",
Expand Down
Loading