From 40d2ba21afc1adb53ed9c99ed55d0a3b0d9400ed Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Thu, 21 Nov 2024 21:54:09 -0600
Subject: [PATCH 01/15] wip(ProxyManager): import proxy modal (no file icon
yet)
---
.../menu/proxymanager/ImportProxyModal.svelte | 21 +++++++++++++++++++
.../menu/proxymanager/ProxyManager.svelte | 8 +++++++
2 files changed, 29 insertions(+)
create mode 100644 src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
diff --git a/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte b/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
new file mode 100644
index 00000000000..9f2a37c5151
--- /dev/null
+++ b/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
@@ -0,0 +1,21 @@
+
+
+
+
+
+ alert("Not implemented yet")}/>
+ alert("Not implemented yet")}/>
+
diff --git a/src-theme/src/routes/menu/proxymanager/ProxyManager.svelte b/src-theme/src/routes/menu/proxymanager/ProxyManager.svelte
index dda3bbf7116..2b32757d7b2 100644
--- a/src-theme/src/routes/menu/proxymanager/ProxyManager.svelte
+++ b/src-theme/src/routes/menu/proxymanager/ProxyManager.svelte
@@ -34,6 +34,7 @@
ProxyCheckResultEvent,
ProxyEditResultEvent
} from "../../../integration/events.js";
+ import ImportProxyModal from "./ImportProxyModal.svelte";
$: {
let filteredProxies = proxies;
@@ -51,6 +52,7 @@
let addProxyModalVisible = false;
let editProxyModalVisible = false;
+ let importProxyModalVisible = false;
let allCountries: string[] = [];
let searchQuery = "";
@@ -202,6 +204,7 @@
+
{#if currentEditProxy}
addProxyModalVisible = true}/>
addProxyFromClipboard()}/>
+ importProxyModalVisible = true}
+ />
Date: Thu, 21 Nov 2024 22:14:19 -0600
Subject: [PATCH 02/15] chore(integration/host.ts): enable `IN_DEV`
---
src-theme/src/integration/host.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src-theme/src/integration/host.ts b/src-theme/src/integration/host.ts
index 9124eed4f8a..9729cf99eb1 100644
--- a/src-theme/src/integration/host.ts
+++ b/src-theme/src/integration/host.ts
@@ -1,4 +1,4 @@
-const IN_DEV = false;
+const IN_DEV = true;
const DEV_PORT = 15000;
export const REST_BASE = IN_DEV ? `http://localhost:${DEV_PORT}` : window.location.origin;
From 40e82b13701d1fe8041ff4410b6559fe5ecb4d34 Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Thu, 21 Nov 2024 23:09:32 -0600
Subject: [PATCH 03/15] wip(api/v1/proxies): add import routes
---
.../rest/v1/InteropFunctionRegistry.kt | 3 +
.../protocol/rest/v1/client/ProxyFunctions.kt | 71 +++++++++++++++++++
2 files changed, 74 insertions(+)
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/InteropFunctionRegistry.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/InteropFunctionRegistry.kt
index 94d2ca84dbd..8b750062e1e 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/InteropFunctionRegistry.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/InteropFunctionRegistry.kt
@@ -92,6 +92,9 @@ internal fun registerInteropFunctions(node: Node) = node.withPath("/api/v1/clien
get("/proxies", ::getProxies).apply {
post("/add", ::postAddProxy)
post("/clipboard", ::postClipboardProxy)
+ // Imports
+ post("/import/clipboard", ::postImportClipboardProxy)
+ post("/import/file", ::postImportFileProxy)
post("/edit", ::postEditProxy)
post("/check", ::postCheckProxy)
delete("/remove", ::deleteRemoveProxy)
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
index c9413e8b6cd..5ebd44a5209 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
@@ -30,6 +30,10 @@ import net.ccbluex.netty.http.model.RequestObject
import net.ccbluex.netty.http.util.httpForbidden
import net.ccbluex.netty.http.util.httpOk
import org.lwjgl.glfw.GLFW
+// needed for showing a file dialog, a dummy Frame is created that is invisible
+// so that we can use it to open the dialog, instead of adding JAWT so we can convert it to a java.awt.Frame.
+import java.awt.FileDialog
+import java.awt.Frame
/**
* Proxy endpoints
@@ -125,6 +129,73 @@ fun postClipboardProxy(requestObject: RequestObject): FullHttpResponse {
return httpOk(JsonObject())
}
+private fun importProxies(content: String) {
+ // TabNine moment
+ content.split("\n").map { line ->
+ val split = line.split(":")
+ val host = split[0]
+ val port = split[1].toInt()
+
+ if (split.size > 2) {
+ val username = split[2]
+ val password = split[3]
+ ProxyManager.addProxy(host, port, username, password, false)
+ } else {
+ ProxyManager.addProxy(host, port, "", "", false)
+ }
+ }
+}
+
+// why are we overcomplicating things
+// just have a get clipboard route or something... but ok fine, I'll do this anyway.
+// POST /api/v1/client/proxies/import/clipboard
+@Suppress("UNUSED_PARAMETER")
+fun postImportClipboardProxy(_requestObject: RequestObject): FullHttpResponse {
+ RenderSystem.recordRenderCall {
+ runCatching {
+ // Get clipboard content via GLFW
+ val clipboard = GLFW.glfwGetClipboardString(mc.window.handle)?: ""
+ if (!clipboard.isNotBlank())
+ return@recordRenderCall
+
+ importProxies(clipboard)
+ }
+ }
+
+ return httpOk(JsonObject())
+}
+
+// POST /api/v1/client/proxies/import/clipboard
+@Suppress("UNUSED_PARAMETER")
+fun postImportFileProxy(_requestObject: RequestObject): FullHttpResponse {
+ RenderSystem.recordRenderCall {
+ runCatching {
+ // https://github.com/JetBrains/compose-multiplatform/issues/176 (the initial file dialog idea)
+ // (initially to convert a GLFW window handle into a Frame,
+ // but I ended up creating a dummy frame because I didn't want an extra dependency)
+ // https://chatgpt.com/share/67400ff3-dcd8-8005-ae2f-41c8efe04b16
+
+ // Create a dummy AWT Frame
+ var dummyFrame = Frame()
+ // Remove borders and title bar
+ dummyFrame.isUndecorated = true
+ // Make it invisible
+ dummyFrame.setSize(0, 0)
+ // Center the dummy frame (optional)
+ dummyFrame.setLocationRelativeTo(null)
+ // Required for the dialog to work
+ dummyFrame.isVisible = true
+
+ // Open a File Dialog
+ // TODO: could `null as Frame?` work? will test later
+ var fileDialog = FileDialog(dummyFrame, "Choose a file", FileDialog.LOAD)
+ fileDialog.isVisible = true
+ }
+ }
+
+ return httpOk(JsonObject())
+}
+
// POST /api/v1/client/proxies/edit
@Suppress("UNUSED_PARAMETER")
fun postEditProxy(requestObject: RequestObject): FullHttpResponse {
From 5e4ff95eec910ac2a1b770aec36dae5d3865111e Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Fri, 22 Nov 2024 07:46:29 -0600
Subject: [PATCH 04/15] fix(ProxyFunctions/postImportClipboardProxy): add
braces in guard clause (to fix detekt)
---
.../interop/protocol/rest/v1/client/ProxyFunctions.kt | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
index 5ebd44a5209..924f87d255c 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
@@ -155,8 +155,9 @@ fun postImportClipboardProxy(_requestObject: RequestObject): FullHttpResponse {
runCatching {
// Get clipboard content via GLFW
val clipboard = GLFW.glfwGetClipboardString(mc.window.handle)?: ""
- if (!clipboard.isNotBlank())
+ if (!clipboard.isNotBlank()) {
return@recordRenderCall
+ }
importProxies(clipboard)
}
From 30d0616289cb032fa1da7f00a15d957ca7cf62a5 Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Fri, 22 Nov 2024 07:51:43 -0600
Subject: [PATCH 05/15] fix(ProxyFunctions): rename `_requestObject` param to
`requestObject` to fix detekt
---
.../interop/protocol/rest/v1/client/ProxyFunctions.kt | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
index 924f87d255c..192fe064702 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
@@ -150,7 +150,7 @@ private fun importProxies(content: String) {
// just have a get clipboard route or something... but ok fine, I'll do this anyway.
// POST /api/v1/client/proxies/import/clipboard
@Suppress("UNUSED_PARAMETER")
-fun postImportClipboardProxy(_requestObject: RequestObject): FullHttpResponse {
+fun postImportClipboardProxy(requestObject: RequestObject): FullHttpResponse {
RenderSystem.recordRenderCall {
runCatching {
// Get clipboard content via GLFW
@@ -168,7 +168,7 @@ fun postImportClipboardProxy(_requestObject: RequestObject): FullHttpResponse {
// POST /api/v1/client/proxies/import/clipboard
@Suppress("UNUSED_PARAMETER")
-fun postImportFileProxy(_requestObject: RequestObject): FullHttpResponse {
+fun postImportFileProxy(requestObject: RequestObject): FullHttpResponse {
RenderSystem.recordRenderCall {
runCatching {
// https://github.com/JetBrains/compose-multiplatform/issues/176 (the initial file dialog idea)
From 38947ea3399c4ef4a4cef19e2a7fc30d5e22adbe Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Sat, 23 Nov 2024 21:22:18 -0600
Subject: [PATCH 06/15] add(theme/integration/rest): importProxyFromClipboard,
importProxyFromFile
---
src-theme/src/integration/rest.ts | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/src-theme/src/integration/rest.ts b/src-theme/src/integration/rest.ts
index cf4ef9e84a7..6d5ac5e563c 100644
--- a/src-theme/src/integration/rest.ts
+++ b/src-theme/src/integration/rest.ts
@@ -489,6 +489,19 @@ export async function addProxyFromClipboard() {
});
}
+export async function importProxyFromClipboard() {
+ await fetch(`${API_BASE}/client/proxies/import/clipboard`, {
+ method: "POST"
+ });
+}
+
+export async function importProxyFromFile() {
+ await fetch(`${API_BASE}/client/proxies/import/file`, {
+ method: "POST"
+ });
+}
+
+
export async function removeProxy(id: number) {
await fetch(`${API_BASE}/client/proxies/remove`, {
method: "DELETE",
From 07a1c901db51d81bb8d0f9fe783b62f4d522dff7 Mon Sep 17 00:00:00 2001
From: 1zuna <1zuna@ccbluex.net>
Date: Mon, 25 Nov 2024 19:05:26 +0100
Subject: [PATCH 07/15] refactor(Listenable): is running (#4685)
---
.../minecraft/client/MixinMinecraftClient.java | 6 +++---
.../network/MixinPlayerInteractBlockC2SPacket.java | 4 ++--
.../render/MixinBlockEntityRenderDispatcher.java | 2 +-
.../minecraft/render/MixinWorldRenderer.java | 4 ++--
.../config/types/ChoiceConfigurable.kt | 10 +++++-----
.../config/types/ToggleableConfigurable.kt | 2 +-
.../net/ccbluex/liquidbounce/event/EventManager.kt | 2 +-
.../net/ccbluex/liquidbounce/event/Listenable.kt | 14 ++++++++++----
.../net/ccbluex/liquidbounce/event/Sequence.kt | 6 +++---
.../command/commands/client/CommandCenter.kt | 2 +-
.../ccbluex/liquidbounce/features/module/Module.kt | 2 +-
.../module/modules/client/ModuleAutoConfig.kt | 2 +-
.../module/modules/client/ModuleLiquidChat.kt | 2 +-
.../module/modules/client/ModuleRichPresence.kt | 2 +-
.../module/modules/combat/ModuleSuperKnockback.kt | 4 ++--
.../module/modules/combat/ModuleSwordBlock.kt | 4 ++--
.../combat/crystalaura/CrystalAuraSpeedDebugger.kt | 2 +-
.../combat/crystalaura/CrystalPostAttackTracker.kt | 2 +-
.../modules/combat/crystalaura/SubmoduleSetDead.kt | 2 +-
.../modules/combat/killaura/ModuleKillAura.kt | 2 +-
.../modules/combat/killaura/features/AutoBlock.kt | 2 +-
.../modules/combat/velocity/ModuleVelocity.kt | 2 +-
.../disablers/DisablerVerusExperimental.kt | 4 ++--
.../module/modules/misc/ModuleAntiStaff.kt | 2 +-
.../module/modules/misc/ModuleAutoAccount.kt | 2 +-
.../module/modules/movement/ModuleFreeze.kt | 2 +-
.../movement/fly/modes/specific/FlyNcpClip.kt | 2 +-
.../movement/fly/modes/verus/FlyVerusB3869Flat.kt | 2 +-
.../movement/noslow/modes/blocking/NoSlowBlock.kt | 4 ++--
.../noslow/modes/blocking/NoSlowBlockingBlink.kt | 2 +-
.../modules/movement/noslow/modes/bow/NoSlowBow.kt | 4 ++--
.../movement/noslow/modes/consume/NoSlowConsume.kt | 4 ++--
.../noslow/modes/sneaking/NoSlowSneaking.kt | 2 +-
.../module/modules/movement/speed/ModuleSpeed.kt | 12 ++++++------
.../player/antivoid/mode/AntiVoidBlinkMode.kt | 2 +-
.../module/modules/player/nofall/ModuleNoFall.kt | 4 ++--
.../modules/player/nofall/modes/NoFallBlink.kt | 2 +-
.../module/modules/render/ModuleStorageESP.kt | 4 ++--
.../modules/world/scaffold/ModuleScaffold.kt | 2 +-
.../scaffold/features/ScaffoldBlinkFeature.kt | 2 +-
.../protocol/rest/v1/game/ServerListFunctions.kt | 2 +-
.../theme/component/ComponentOverlay.kt | 6 +++---
.../utils/client/InteractionTracker.kt | 3 +--
.../utils/render/placement/PlacementRenderer.kt | 4 ++--
44 files changed, 79 insertions(+), 74 deletions(-)
diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMinecraftClient.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMinecraftClient.java
index 3a7a4eea033..fa92d84e187 100644
--- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMinecraftClient.java
+++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/client/MixinMinecraftClient.java
@@ -328,12 +328,12 @@ private void onFinishedLoading(CallbackInfo ci) {
@ModifyExpressionValue(method = "handleBlockBreaking", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z"))
private boolean injectMultiActionsBreakingWhileUsing(boolean original) {
- return original && !(ModuleMultiActions.INSTANCE.handleEvents() && ModuleMultiActions.INSTANCE.getBreakingWhileUsing());
+ return original && !(ModuleMultiActions.INSTANCE.isRunning() && ModuleMultiActions.INSTANCE.getBreakingWhileUsing());
}
@ModifyExpressionValue(method = "doItemUse", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerInteractionManager;isBreakingBlock()Z"))
private boolean injectMultiActionsPlacingWhileBreaking(boolean original) {
- return original && !(ModuleMultiActions.INSTANCE.handleEvents() && ModuleMultiActions.INSTANCE.getPlacingWhileBreaking());
+ return original && !(ModuleMultiActions.INSTANCE.isRunning() && ModuleMultiActions.INSTANCE.getPlacingWhileBreaking());
}
@ModifyExpressionValue(method = "handleInputEvents", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayerEntity;isUsingItem()Z", ordinal = 0))
@@ -344,7 +344,7 @@ private boolean injectMultiActionsAttackingWhileUsingAndEnforcedBlockingState(bo
this.interactionManager.stopUsingItem(this.player);
}
- if (!ModuleMultiActions.INSTANCE.handleEvents() || !ModuleMultiActions.INSTANCE.getAttackingWhileUsing()) {
+ if (!ModuleMultiActions.INSTANCE.isRunning() || !ModuleMultiActions.INSTANCE.getAttackingWhileUsing()) {
this.options.attackKey.timesPressed = 0;
}
diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/network/MixinPlayerInteractBlockC2SPacket.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/network/MixinPlayerInteractBlockC2SPacket.java
index b3df4b1c5b9..8c23167c791 100644
--- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/network/MixinPlayerInteractBlockC2SPacket.java
+++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/network/MixinPlayerInteractBlockC2SPacket.java
@@ -2,9 +2,9 @@
import net.ccbluex.liquidbounce.features.module.modules.exploit.disabler.disablers.DisablerVerusScaffoldG;
import net.minecraft.network.PacketByteBuf;
+import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import net.minecraft.util.hit.BlockHitResult;
import org.spongepowered.asm.mixin.Mixin;
-import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@@ -12,7 +12,7 @@
public class MixinPlayerInteractBlockC2SPacket {
@Redirect(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketByteBuf;writeBlockHitResult(Lnet/minecraft/util/hit/BlockHitResult;)V"))
private void writeBlockHitResult(PacketByteBuf buf, BlockHitResult hitResult) {
- if (DisablerVerusScaffoldG.INSTANCE.getEnabled() && DisablerVerusScaffoldG.INSTANCE.handleEvents()) {
+ if (DisablerVerusScaffoldG.INSTANCE.getEnabled() && DisablerVerusScaffoldG.INSTANCE.isRunning()) {
buf.writeBlockPos(hitResult.getBlockPos());
buf.writeVarInt(6 + hitResult.getSide().ordinal() * 7);
buf.writeFloat((float) hitResult.getPos().x - hitResult.getBlockPos().getX());
diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinBlockEntityRenderDispatcher.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinBlockEntityRenderDispatcher.java
index 14aa435651d..207ffb166b6 100644
--- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinBlockEntityRenderDispatcher.java
+++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinBlockEntityRenderDispatcher.java
@@ -44,7 +44,7 @@ public class MixinBlockEntityRenderDispatcher {
at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/entity/BlockEntityRenderer;render(Lnet/minecraft/block/entity/BlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V")
)
private static void render(BlockEntityRenderer blockEntityRenderer, BlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
- if (ModuleStorageESP.INSTANCE.getEnabled() && ModuleStorageESP.INSTANCE.handleEvents()
+ if (ModuleStorageESP.INSTANCE.getEnabled() && ModuleStorageESP.INSTANCE.isRunning()
&& ModuleStorageESP.Glow.INSTANCE.isActive()) {
var outlineVertexConsumerProvider = MinecraftClient.getInstance().getBufferBuilders()
.getOutlineVertexConsumers();
diff --git a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinWorldRenderer.java b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinWorldRenderer.java
index 55ebd1804f3..f73c136c33f 100644
--- a/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinWorldRenderer.java
+++ b/src/main/java/net/ccbluex/liquidbounce/injection/mixins/minecraft/render/MixinWorldRenderer.java
@@ -206,7 +206,7 @@ private boolean injectHasOutline(MinecraftClient instance, Entity entity) {
return true;
}
- if (ModuleStorageESP.INSTANCE.getEnabled() && ModuleStorageESP.INSTANCE.handleEvents() &&
+ if (ModuleStorageESP.INSTANCE.getEnabled() && ModuleStorageESP.INSTANCE.isRunning() &&
ModuleStorageESP.Glow.INSTANCE.isActive() && ModuleStorageESP.categorize(entity) != null) {
return true;
}
@@ -229,7 +229,7 @@ private int injectTeamColor(Entity instance) {
return ModuleTNTTimer.INSTANCE.getTntColor(((TntEntity) instance).getFuse()).toARGB();
}
- if (ModuleStorageESP.INSTANCE.getEnabled() && ModuleStorageESP.INSTANCE.handleEvents()
+ if (ModuleStorageESP.INSTANCE.getEnabled() && ModuleStorageESP.INSTANCE.isRunning()
&& ModuleStorageESP.Glow.INSTANCE.isActive()) {
var categorizedEntity = ModuleStorageESP.categorize(instance);
if (categorizedEntity != null) {
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ChoiceConfigurable.kt b/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ChoiceConfigurable.kt
index 8e6e87cf5f1..c36a258da4a 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ChoiceConfigurable.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ChoiceConfigurable.kt
@@ -70,7 +70,7 @@ class ChoiceConfigurable(
return
}
- if (this.activeChoice.handleEvents()) {
+ if (this.activeChoice.isRunning()) {
this.activeChoice.disable()
}
@@ -81,7 +81,7 @@ class ChoiceConfigurable(
this.activeChoice = it[0] as T
})
- if (this.activeChoice.handleEvents()) {
+ if (this.activeChoice.isRunning()) {
this.activeChoice.enable()
}
}
@@ -91,7 +91,7 @@ class ChoiceConfigurable(
return
}
- if (this.activeChoice.handleEvents()) {
+ if (this.activeChoice.isRunning()) {
this.activeChoice.disable()
}
@@ -99,7 +99,7 @@ class ChoiceConfigurable(
this.activeChoice = it[0] as T
})
- if (this.activeChoice.handleEvents()) {
+ if (this.activeChoice.isRunning()) {
this.activeChoice.enable()
}
}
@@ -130,7 +130,7 @@ abstract class Choice(name: String) : Configurable(name), Listenable, NamedChoic
* We check if the parent is active and if the mode is active, if so
* we handle the events.
*/
- override fun handleEvents() = super.handleEvents() && isActive
+ override fun isRunning() = super.isRunning() && isActive
override fun parent() = this.parent.listenable
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ToggleableConfigurable.kt b/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ToggleableConfigurable.kt
index 4a2f0673533..3ff621fe2d9 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ToggleableConfigurable.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/config/types/ToggleableConfigurable.kt
@@ -62,7 +62,7 @@ abstract class ToggleableConfigurable(
* Because we pass the parent to the Listenable, we can simply
* call the super.handleEvents() and it will return false if the upper-listenable is disabled.
*/
- override fun handleEvents() = super.handleEvents() && enabled
+ override fun isRunning() = super.isRunning() && enabled
override fun parent() = parent
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt
index 1db9c990d32..c7626ad5c63 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt
@@ -199,7 +199,7 @@ object EventManager {
for (eventHook in target) {
EventScheduler.process(event)
- if (!eventHook.ignoresCondition && !eventHook.handlerClass.handleEvents()) {
+ if (!eventHook.ignoreRunning && !eventHook.handlerClass.isRunning()) {
continue
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/Listenable.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/Listenable.kt
index 288273fe105..599907aafc6 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/event/Listenable.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/Listenable.kt
@@ -26,16 +26,22 @@ typealias Handler = (T) -> Unit
class EventHook(
val handlerClass: Listenable,
val handler: Handler,
- val ignoresCondition: Boolean,
+ val ignoreRunning: Boolean,
val priority: Int = 0
)
interface Listenable {
/**
- * Allows disabling event handling when condition is false.
+ * Returns whether the listenable is running or not, this is based on the parent listenable
+ * and if no parent is present, it will return the opposite of [isDestructed].
+ *
+ * When destructed, the listenable will not handle any events. This is likely to be overridden by
+ * the implementing class to provide a toggleable feature.
+ *
+ * This can be ignored by handlers when [ignoreRunning] is set to true on the [EventHook].
*/
- fun handleEvents(): Boolean = parent()?.handleEvents() ?: !isDestructed
+ fun isRunning(): Boolean = parent()?.isRunning() ?: !isDestructed
/**
* Parent listenable
@@ -92,7 +98,7 @@ fun Listenable.repeatable(eventHandler: SuspendableHandler) {
// Ignore condition makes sense because we do not want our sequence to run after we do not handle events anymore
handler(ignoreCondition = true) {
// Check if we should start or stop the sequence
- if (this.handleEvents()) {
+ if (this.isRunning()) {
// Check if the sequence is already running
if (sequence == null) {
// If not, start it
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt
index 9c0db81d18a..1b9ca082d65 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/Sequence.kt
@@ -45,7 +45,7 @@ object SequenceManager : Listenable {
val tickSequences = handler(priority = 1000) {
for (sequence in sequences) {
// Prevent modules handling events when not supposed to
- if (!sequence.owner.handleEvents()) {
+ if (!sequence.owner.isRunning()) {
sequence.cancel()
continue
}
@@ -82,7 +82,7 @@ open class Sequence(val owner: Listenable, val handler: SuspendableHa
}
internal open suspend fun coroutineRun() {
- if (owner.handleEvents()) {
+ if (owner.isRunning()) {
runCatching {
handler(event)
}.onFailure {
@@ -185,7 +185,7 @@ class RepeatingSequence(owner: Listenable, handler: SuspendableHandler Unit) =
sendRichPresence(RichPresence.Builder().apply(builderAction).build())
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 65d7a764a37..30e27d5fe27 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
@@ -63,8 +63,8 @@ object ModuleSuperKnockback : Module("SuperKnockback", Category.COMBAT, aliases
}
}
- override fun handleEvents(): Boolean {
- val handleEvents = super.handleEvents()
+ override fun isRunning(): Boolean {
+ val handleEvents = super.isRunning()
// Reset if the module is not handling events anymore
if (!handleEvents) {
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSwordBlock.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSwordBlock.kt
index 2d8e5d405e0..f3110d798d7 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSwordBlock.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/ModuleSwordBlock.kt
@@ -45,8 +45,8 @@ object ModuleSwordBlock : Module("SwordBlock", Category.COMBAT, aliases = arrayO
player: PlayerEntity = this.player,
offHandItem: Item = player.offHandStack.item,
mainHandItem: Item = player.mainHandStack.item,
- ) = (handleEvents() || AutoBlock.blockVisual) && offHandItem is ShieldItem
- && (mainHandItem is SwordItem || player === this.player && handleEvents() && alwaysHideShield)
+ ) = (isRunning() || AutoBlock.blockVisual) && offHandItem is ShieldItem
+ && (mainHandItem is SwordItem || player === this.player && isRunning() && alwaysHideShield)
@Suppress("UNUSED")
private val packetHandler = sequenceHandler {
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalAuraSpeedDebugger.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalAuraSpeedDebugger.kt
index 08941340f76..c707cdafe33 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalAuraSpeedDebugger.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalAuraSpeedDebugger.kt
@@ -53,6 +53,6 @@ object CrystalAuraSpeedDebugger : CrystalPostAttackTracker() {
attackedIds.clear()
}
- override fun handleEvents() = ModuleCrystalAura.handleEvents() && ModuleDebug.enabled
+ override fun isRunning() = ModuleCrystalAura.isRunning() && ModuleDebug.enabled
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalPostAttackTracker.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalPostAttackTracker.kt
index 27de103b9a3..d565d9b072c 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalPostAttackTracker.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/CrystalPostAttackTracker.kt
@@ -110,7 +110,7 @@ abstract class CrystalPostAttackTracker : Listenable {
* @param id The id of the attacked entity.
*/
open fun attacked(id: Int) {
- if (!handleEvents()) {
+ if (!isRunning()) {
return
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/SubmoduleSetDead.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/SubmoduleSetDead.kt
index a47acb44535..19c385f545b 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/SubmoduleSetDead.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/crystalaura/SubmoduleSetDead.kt
@@ -41,7 +41,7 @@ object SubmoduleSetDead : ToggleableConfigurable(ModuleCrystalAura, "SetDead", t
val entities: MutableMap = Int2ObjectMaps.synchronize(Int2ObjectOpenHashMap())
override fun attacked(id: Int) {
- if (!handleEvents()) {
+ if (!isRunning()) {
return
}
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 4b37b38e7b7..6aab5470b5c 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
@@ -507,7 +507,7 @@ object ModuleKillAura : Module("KillAura", Category.COMBAT) {
}
}
} else if (player.isUsingItem &&
- !(ModuleMultiActions.handleEvents() && ModuleMultiActions.attackingWhileUsing)) {
+ !(ModuleMultiActions.isRunning() && ModuleMultiActions.attackingWhileUsing)) {
return // return if it's not allowed to attack while the player is using another item that's not a shield
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/AutoBlock.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/AutoBlock.kt
index b78eb2052fb..0ae338e8d8b 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/AutoBlock.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/killaura/features/AutoBlock.kt
@@ -70,7 +70,7 @@ object AutoBlock : ToggleableConfigurable(ModuleKillAura, "AutoBlocking", false)
* @see net.minecraft.client.render.item.HeldItemRenderer renderFirstPersonItem
*/
var blockVisual = false
- get() = field && super.handleEvents()
+ get() = field && super.isRunning()
val shouldUnblockToHit
get() = unblockMode != UnblockMode.NONE
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt
index f1bd9f2ccb5..f7dfded35eb 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/ModuleVelocity.kt
@@ -105,6 +105,6 @@ object ModuleVelocity : Module("Velocity", Category.COMBAT) {
}
}
- override fun handleEvents() = super.handleEvents() && pause == 0
+ override fun isRunning() = super.isRunning() && pause == 0
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/disablers/DisablerVerusExperimental.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/disablers/DisablerVerusExperimental.kt
index d9aeb9032b6..3ea3c9c1872 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/disablers/DisablerVerusExperimental.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/disablers/DisablerVerusExperimental.kt
@@ -194,7 +194,7 @@ internal object DisablerVerusExperimental : ToggleableConfigurable(ModuleDisable
// ping spoof, multiple checks
fun shouldBlink(packet: Packet<*>?): Boolean {
- if (!this.handleEvents()) return false
+ if (!this.isRunning()) return false
if (waitTime > System.currentTimeMillis()) return false
if (packet == null && lastFlush + delayTime < System.currentTimeMillis()) {
@@ -220,7 +220,7 @@ internal object DisablerVerusExperimental : ToggleableConfigurable(ModuleDisable
// meant to trigger playerData.hasLag
fun shouldPrepareToFlush(packet: Packet<*>?): Boolean {
- if (!this.handleEvents()) return false
+ if (!this.isRunning()) return false
if (waitTime > System.currentTimeMillis()) return false
if (packet !is PlayerMoveC2SPacket) return false
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAntiStaff.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAntiStaff.kt
index e20726d2edb..ce5bb5cf6f3 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAntiStaff.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAntiStaff.kt
@@ -153,7 +153,7 @@ object ModuleAntiStaff : Module("AntiStaff", Category.MISC) {
}
- override fun handleEvents() = ModuleAntiStaff.enabled && enabled
+ override fun isRunning() = ModuleAntiStaff.enabled && enabled
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAutoAccount.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAutoAccount.kt
index 8ae1f86f2dd..ed25607f360 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAutoAccount.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/misc/ModuleAutoAccount.kt
@@ -49,7 +49,7 @@ object ModuleAutoAccount : Module("AutoAccount", Category.MISC, aliases = arrayO
// We can receive chat messages before the world is initialized,
// so we have to handel events even before the that
- override fun handleEvents() = enabled
+ override fun isRunning() = enabled
fun login() {
chat("login")
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleFreeze.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleFreeze.kt
index 3a654d5e028..a1c98c004a1 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleFreeze.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/ModuleFreeze.kt
@@ -147,7 +147,7 @@ object ModuleFreeze : Module("Freeze", Category.MOVEMENT) {
get() = modes
fun shouldLag(origin: TransferOrigin): LagResult? {
- if (!enabled || !handleEvents()) {
+ if (!enabled || !isRunning()) {
return null
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/specific/FlyNcpClip.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/specific/FlyNcpClip.kt
index a1adf0b9a3e..9a23943ac81 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/specific/FlyNcpClip.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/specific/FlyNcpClip.kt
@@ -71,7 +71,7 @@ object FlyNcpClip : Choice("NcpClip") {
var shouldLag = false
private set
- get() = this.handleEvents() && blink && field
+ get() = this.isRunning() && blink && field
val repeatable = repeatable {
val startPos = startPosition
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/verus/FlyVerusB3869Flat.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/verus/FlyVerusB3869Flat.kt
index 9ca95b1175c..25a7a11add1 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/verus/FlyVerusB3869Flat.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/fly/modes/verus/FlyVerusB3869Flat.kt
@@ -49,7 +49,7 @@ internal object FlyVerusB3869Flat : Choice("VerusB3896Flat") {
get() = ModuleFly.modes
val requiresLag
- get() = this.handleEvents()
+ get() = this.isRunning()
val packetHandler = handler { event ->
val packet = event.packet
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlock.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlock.kt
index 7b5c502b183..9acca8aae62 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlock.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlock.kt
@@ -49,8 +49,8 @@ internal object NoSlowBlock : ToggleableConfigurable(ModuleNoSlow, "Blocking", t
)
}
- override fun handleEvents(): Boolean {
- if (!super.handleEvents() || !inGame) {
+ override fun isRunning(): Boolean {
+ if (!super.isRunning() || !inGame) {
return false
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlockingBlink.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlockingBlink.kt
index a425fc54a7f..fb96283b16d 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlockingBlink.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/blocking/NoSlowBlockingBlink.kt
@@ -13,7 +13,7 @@ internal object NoSlowBlockingBlink : Choice("Blink") {
get() = modes
fun shouldLag(packet: Packet<*>?): FakeLag.LagResult? {
- if (!isActive || !handleEvents() || !player.isBlocking) {
+ if (!isActive || !isRunning() || !player.isBlocking) {
return null
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/bow/NoSlowBow.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/bow/NoSlowBow.kt
index e2d156c20b7..386dd7c0431 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/bow/NoSlowBow.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/bow/NoSlowBow.kt
@@ -43,8 +43,8 @@ internal object NoSlowBow : ToggleableConfigurable(ModuleNoSlow, "Bow", true) {
)
}
- override fun handleEvents(): Boolean {
- if (!super.handleEvents() || !inGame) {
+ override fun isRunning(): Boolean {
+ if (!super.isRunning() || !inGame) {
return false
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/consume/NoSlowConsume.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/consume/NoSlowConsume.kt
index ae2c4efd3c4..4bf55e10f2d 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/consume/NoSlowConsume.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/consume/NoSlowConsume.kt
@@ -52,8 +52,8 @@ object NoSlowConsume : ToggleableConfigurable(ModuleNoSlow, "Consume", true) {
)
}
- override fun handleEvents(): Boolean {
- if (!super.handleEvents() || !inGame) {
+ override fun isRunning(): Boolean {
+ if (!super.isRunning() || !inGame) {
return false
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/sneaking/NoSlowSneaking.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/sneaking/NoSlowSneaking.kt
index b0b9eae11df..d6f3affe830 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/sneaking/NoSlowSneaking.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/noslow/modes/sneaking/NoSlowSneaking.kt
@@ -45,5 +45,5 @@ internal object NoSlowSneaking : ToggleableConfigurable(ModuleNoSlow, "Sneaking"
event.multiplier = max(event.multiplier, minMultiplier)
}
- override fun handleEvents() = super.handleEvents() && inGame && player.isSneaking
+ override fun isRunning() = super.isRunning() && inGame && player.isSneaking
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/speed/ModuleSpeed.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/speed/ModuleSpeed.kt
index 81cf991154e..aae5d627d05 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/speed/ModuleSpeed.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/speed/ModuleSpeed.kt
@@ -105,7 +105,7 @@ object ModuleSpeed : Module("Speed", Category.MOVEMENT) {
val modes = choices(this, "Mode", { it.choices[0] },
ModuleSpeed::initializeSpeeds)
- override fun handleEvents(): Boolean {
+ override fun isRunning(): Boolean {
// We cannot use our parent super.handleEvents() here, because it has been turned false
// when [OnlyInCombat] is enabled
if (!ModuleSpeed.enabled || !enabled || !inGame || !passesRequirements()) {
@@ -113,7 +113,7 @@ object ModuleSpeed : Module("Speed", Category.MOVEMENT) {
}
// Only On Potion Effect has a higher priority
- if (OnlyOnPotionEffect.handleEvents()) {
+ if (OnlyOnPotionEffect.isRunning()) {
return false
}
@@ -135,7 +135,7 @@ object ModuleSpeed : Module("Speed", Category.MOVEMENT) {
val modes = choices(this, "Mode", { it.choices[0] },
ModuleSpeed::initializeSpeeds)
- override fun handleEvents(): Boolean {
+ override fun isRunning(): Boolean {
// We cannot use our parent super.handleEvents() here, because it has been turned false
// when [OnlyOnPotionEffect] is enabled
if (!ModuleSpeed.enabled || !enabled || !inGame || !passesRequirements()) {
@@ -152,10 +152,10 @@ object ModuleSpeed : Module("Speed", Category.MOVEMENT) {
tree(OnlyOnPotionEffect)
}
- override fun handleEvents(): Boolean {
+ override fun isRunning(): Boolean {
// Early return if the module is not ready to be used - prevents accessing player when it's null below
// in case it was forgotten to be checked
- if (!super.handleEvents()) {
+ if (!super.isRunning()) {
return false
}
@@ -164,7 +164,7 @@ object ModuleSpeed : Module("Speed", Category.MOVEMENT) {
}
// We do not want to handle events if the OnlyInCombat is enabled
- if (OnlyInCombat.enabled && OnlyInCombat.handleEvents()) {
+ if (OnlyInCombat.enabled && OnlyInCombat.isRunning()) {
return false
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/antivoid/mode/AntiVoidBlinkMode.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/antivoid/mode/AntiVoidBlinkMode.kt
index b8a666be32d..eef431e1382 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/antivoid/mode/AntiVoidBlinkMode.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/antivoid/mode/AntiVoidBlinkMode.kt
@@ -43,7 +43,7 @@ object AntiVoidBlinkMode : AntiVoidMode("Blink") {
// Whether artificial lag is needed to prevent falling into the void.
val requiresLag
- get() = AntiVoidBlinkMode.handleEvents() && ModuleAntiVoid.isLikelyFalling
+ get() = AntiVoidBlinkMode.isRunning() && ModuleAntiVoid.isLikelyFalling
&& !isExempt && isWorth()
@Suppress("unused")
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/ModuleNoFall.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/ModuleNoFall.kt
index 5e6616dbdb8..05f0a8f116f 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/ModuleNoFall.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/ModuleNoFall.kt
@@ -52,8 +52,8 @@ object ModuleNoFall : Module("NoFall", Category.PLAYER) {
private var duringFallFlying by boolean("DuringFallFlying", false)
- override fun handleEvents(): Boolean {
- if (!super.handleEvents()) {
+ override fun isRunning(): Boolean {
+ if (!super.isRunning()) {
return false
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/modes/NoFallBlink.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/modes/NoFallBlink.kt
index 755deb9a5ba..84e9be6cf66 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/modes/NoFallBlink.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/nofall/modes/NoFallBlink.kt
@@ -142,6 +142,6 @@ internal object NoFallBlink : Choice("Blink") {
super.disable()
}
- fun shouldLag() = handleEvents() && blinkFall
+ fun shouldLag() = isRunning() && blinkFall
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleStorageESP.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleStorageESP.kt
index 976e6e6b514..f761614a064 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleStorageESP.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleStorageESP.kt
@@ -261,12 +261,12 @@ object ModuleStorageESP : Module("StorageESP", Category.RENDER, aliases = arrayO
}
}
- override fun handleEvents(): Boolean {
+ override fun isRunning(): Boolean {
if (requiresChestStealer && !ModuleChestStealer.enabled) {
return false
}
- return super.handleEvents()
+ return super.isRunning()
}
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/ModuleScaffold.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/ModuleScaffold.kt
index 8118d80c085..01e791f9527 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/ModuleScaffold.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/ModuleScaffold.kt
@@ -568,7 +568,7 @@ object ModuleScaffold : Module("Scaffold", Category.WORLD) {
}
internal fun getTargetedPosition(blockPos: BlockPos): BlockPos {
- if (ScaffoldDownFeature.handleEvents() && ScaffoldDownFeature.shouldGoDown) {
+ if (ScaffoldDownFeature.isRunning() && ScaffoldDownFeature.shouldGoDown) {
return blockPos.add(0, -2, 0)
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/features/ScaffoldBlinkFeature.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/features/ScaffoldBlinkFeature.kt
index 26e9b2f4058..3649ccf91e0 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/features/ScaffoldBlinkFeature.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/world/scaffold/features/ScaffoldBlinkFeature.kt
@@ -33,7 +33,7 @@ object ScaffoldBlinkFeature : ToggleableConfigurable(ModuleScaffold, "Blink", fa
private val pulseTimer = Chronometer()
val shouldBlink
- get() = handleEvents() && (!player.isOnGround || !pulseTimer.hasElapsed(pulseTime))
+ get() = isRunning() && (!player.isOnGround || !pulseTimer.hasElapsed(pulseTime))
fun onBlockPlacement() {
pulseTime = time.random().toLong()
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/game/ServerListFunctions.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/game/ServerListFunctions.kt
index b2b86c6604a..77f8e9674bf 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/game/ServerListFunctions.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/game/ServerListFunctions.kt
@@ -231,7 +231,7 @@ object ActiveServerList : Listenable {
serverListPinger.tick()
}
- override fun handleEvents() = true
+ override fun isRunning() = true
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/theme/component/ComponentOverlay.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/theme/component/ComponentOverlay.kt
index cf0bb7f268e..b2e0541ac8f 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/theme/component/ComponentOverlay.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/theme/component/ComponentOverlay.kt
@@ -26,10 +26,10 @@ import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.event.events.ComponentsUpdate
import net.ccbluex.liquidbounce.features.misc.HideAppearance
import net.ccbluex.liquidbounce.features.module.modules.render.ModuleHud
-import net.ccbluex.liquidbounce.utils.client.logger
import net.ccbluex.liquidbounce.integration.theme.ThemeManager
import net.ccbluex.liquidbounce.integration.theme.component.types.IntegratedComponent
import net.ccbluex.liquidbounce.integration.theme.component.types.TextComponent
+import net.ccbluex.liquidbounce.utils.client.logger
val components: MutableList = mutableListOf()
val customComponents: MutableList = mutableListOf(
@@ -39,12 +39,12 @@ val customComponents: MutableList = mutableListOf(
object ComponentOverlay : Listenable {
@JvmStatic
- fun isTweakEnabled(tweak: FeatureTweak) = handleEvents() && !HideAppearance.isHidingNow &&
+ fun isTweakEnabled(tweak: FeatureTweak) = isRunning() && !HideAppearance.isHidingNow &&
components.filterIsInstance().any { it.enabled && it.tweaks.contains(tweak) }
@JvmStatic
fun getComponentWithTweak(tweak: FeatureTweak): IntegratedComponent? {
- if (!handleEvents() || HideAppearance.isHidingNow) {
+ if (!isRunning() || HideAppearance.isHidingNow) {
return null
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/InteractionTracker.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/InteractionTracker.kt
index 975d734445a..7bbd20ae08a 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/InteractionTracker.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/InteractionTracker.kt
@@ -3,7 +3,6 @@ package net.ccbluex.liquidbounce.utils.client
import net.ccbluex.liquidbounce.event.Listenable
import net.ccbluex.liquidbounce.event.events.PacketEvent
import net.ccbluex.liquidbounce.event.handler
-import net.ccbluex.liquidbounce.features.module.modules.movement.noslow.modes.blocking.NoSlowBlock
import net.ccbluex.liquidbounce.features.module.modules.movement.noslow.modes.blocking.NoSlowBlock.player
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket
import net.minecraft.network.packet.c2s.play.PlayerInteractItemC2SPacket
@@ -65,6 +64,6 @@ object InteractionTracker : Listenable {
data class Interaction(val hand: Hand, val action: UseAction)
- override fun handleEvents() = inGame
+ override fun isRunning() = inGame
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/placement/PlacementRenderer.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/placement/PlacementRenderer.kt
index 1b61f0bad9e..b075629550a 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/placement/PlacementRenderer.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/utils/render/placement/PlacementRenderer.kt
@@ -180,8 +180,8 @@ open class PlacementRenderer(
/**
* Only run when the module and this is enabled or out-animations are running.
*/
- override fun handleEvents(): Boolean {
- return module.handleEvents() && enabled || !outAnimationsFinished
+ override fun isRunning(): Boolean {
+ return module.isRunning() && enabled || !outAnimationsFinished
}
/**
From ca00f95f2dfb950aad5c60430f69d60c7a6fba80 Mon Sep 17 00:00:00 2001
From: superblaubeere27
Date: Mon, 25 Nov 2024 21:46:54 +0100
Subject: [PATCH 08/15] feat(FontRenderer): multi-atlas support (#4688)
* Added multi atlas support
* Fix detekt
* Stop using the test atlas size
---
.../render/nametags/NametagTextFormatter.kt | 15 ++-
.../engine/font/FontGlyphPageManager.kt | 23 ++--
.../render/engine/font/FontRenderer.kt | 3 +
.../render/engine/font/StaticGlyphPage.kt | 110 ++++++++++++++----
4 files changed, 112 insertions(+), 39 deletions(-)
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/nametags/NametagTextFormatter.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/nametags/NametagTextFormatter.kt
index d8a70b87bb4..2283e860fb3 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/nametags/NametagTextFormatter.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/nametags/NametagTextFormatter.kt
@@ -47,9 +47,16 @@ class NametagTextFormatter(private val entity: Entity) {
outputText.append(this.pingText).append(" ")
}
- val nameString = entity.displayName!!.sanitizeWithNameProtect().string
+ val name = entity.displayName!!.sanitizeWithNameProtect()
+ val nameColor = this.nameColor
- outputText.append(nameString.asText().styled { it.withColor(this.nameColor) })
+ val nameText: Text = if (nameColor != null) {
+ name.string.asText().styled { it.withColor(nameColor) }
+ } else {
+ name
+ }
+
+ outputText.append(nameText)
if (ModuleNametags.ShowOptions.health) {
outputText.append(" ").append(this.healthText)
@@ -64,7 +71,7 @@ class NametagTextFormatter(private val entity: Entity) {
private val isBot = ModuleAntiBot.isBot(entity)
- private val nameColor: TextColor
+ private val nameColor: TextColor?
get() {
val tagColor = EntityTaggingManager.getTag(this.entity).color
@@ -73,7 +80,7 @@ class NametagTextFormatter(private val entity: Entity) {
entity.isInvisible -> Formatting.GOLD.toTextColor()
entity.isSneaking -> Formatting.DARK_RED.toTextColor()
tagColor != null -> TextColor.fromRgb(tagColor.toARGB())
- else -> Formatting.GRAY.toTextColor()
+ else -> null
}
}
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontGlyphPageManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontGlyphPageManager.kt
index 179e943eb10..df6e39c5333 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontGlyphPageManager.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontGlyphPageManager.kt
@@ -17,7 +17,7 @@ class FontGlyphPageManager(
additionalFonts: Set = emptySet()
): Listenable {
- private var staticPage: StaticGlyphPage = StaticGlyphPage.create(baseFonts.flatMap { loadedFont ->
+ private var staticPage: List = StaticGlyphPage.createGlyphPages(baseFonts.flatMap { loadedFont ->
loadedFont.styles.filterNotNull().flatMap { font -> BASIC_CHARS.map { ch -> FontGlyph(ch, font) } }
})
private val dynamicPage: DynamicGlyphPage = DynamicGlyphPage(
@@ -35,7 +35,7 @@ class FontGlyphPageManager(
init {
this.dynamicFontManager.startThread()
- this.availableFonts = createGlyphRegistries(baseFonts, this.staticPage.glyphs)
+ this.availableFonts = createGlyphRegistries(baseFonts, this.staticPage)
}
@Suppress("unused")
@@ -51,9 +51,10 @@ class FontGlyphPageManager(
}
}
+ @Suppress("NestedBlockDepth")
private fun createGlyphRegistries(
baseFonts: Set,
- glyphs: Set>
+ glyphPages: List
): Map {
val fontMap = baseFonts.associateWith {
Array(4) {
@@ -63,12 +64,14 @@ class FontGlyphPageManager(
baseFonts.forEach { loadedFont ->
loadedFont.styles.filterNotNull().forEach { fontId ->
- glyphs
- .filter { it.first == fontId }
- .forEach { (font, glyphRenderInfo) ->
- fontMap[loadedFont]!![font.style][glyphRenderInfo.char] =
- GlyphDescriptor(staticPage, glyphRenderInfo)
- }
+ glyphPages.forEach { glyphPage ->
+ glyphPage.glyphs
+ .filter { it.first == fontId }
+ .forEach { (font, glyphRenderInfo) ->
+ fontMap[loadedFont]!![font.style][glyphRenderInfo.char] =
+ GlyphDescriptor(glyphPage, glyphRenderInfo)
+ }
+ }
}
}
@@ -103,7 +106,7 @@ class FontGlyphPageManager(
fun unload() {
this.dynamicPage.texture.close()
- this.staticPage.texture.close()
+ this.staticPage.forEach { it.texture.close() }
}
private class FontGlyphRegistry(
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontRenderer.kt b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontRenderer.kt
index 96ec8ab40b8..91b4ba27dac 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontRenderer.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/FontRenderer.kt
@@ -28,10 +28,12 @@ import net.ccbluex.liquidbounce.render.engine.Vec3
import net.ccbluex.liquidbounce.render.engine.font.processor.LegacyTextProcessor
import net.ccbluex.liquidbounce.render.engine.font.processor.MinecraftTextProcessor
import net.ccbluex.liquidbounce.render.engine.font.processor.TextProcessor
+import net.ccbluex.liquidbounce.utils.client.logger
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.text.Text
import net.minecraft.util.math.Vec3d
+import org.apache.logging.log4j.MarkerManager
import org.joml.Vector3f
import java.awt.Font
import java.util.*
@@ -77,6 +79,7 @@ class FontRenderer(
override val height: Float = font.styles.firstNotNullOf { it?.height }
val ascent: Float = font.styles.firstNotNullOf { it?.ascent }
+
override fun begin() {
if (this.cache.renderedGlyphs.isNotEmpty() || this.cache.lines.isNotEmpty()) {
// this.commit()
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/StaticGlyphPage.kt b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/StaticGlyphPage.kt
index 3469b3ecb1e..9c64c8a7f0c 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/StaticGlyphPage.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/render/engine/font/StaticGlyphPage.kt
@@ -2,6 +2,7 @@ package net.ccbluex.liquidbounce.render.engine.font
import net.ccbluex.liquidbounce.render.FontManager
import net.ccbluex.liquidbounce.render.engine.font.GlyphPage.Companion.CharacterGenerationInfo
+import net.ccbluex.liquidbounce.utils.client.logger
import net.minecraft.client.texture.NativeImageBackedTexture
import java.awt.Dimension
import java.awt.Point
@@ -17,41 +18,67 @@ class StaticGlyphPage(
val glyphs: Set>
): GlyphPage() {
companion object {
+ fun createGlyphPages(chars: List): List {
+ val glyphPages = mutableListOf()
+
+ var remainingChars = chars
+
+ do {
+ val result = createGlyphPageWithFittingCharacters(remainingChars)
+
+ glyphPages.add(result.first)
+
+ remainingChars = result.second
+ } while (remainingChars.isNotEmpty())
+
+ return glyphPages
+ }
+
/**
- * Creates a bitmap based
+ * Creates a bitmap which contains all [chars].
*/
- fun create(chars: List): StaticGlyphPage {
- // Get information about the glyphs and sort them by their height
- val glyphsToRender = chars
- .mapNotNull { createCharacterCreationInfo(it) }
- .sortedBy { it.glyphMetrics.bounds2D.height }
+ fun createGlyphPageWithFittingCharacters(chars: List): Pair> {
+ val result: Pair>? = tryCharacterPlacementWithShrinking(chars)
- val maxTextureSize = maxTextureSize.value
+ val (res, remainingGlyphs) = result ?: error("Unable to create static atlas.")
- // The suggested width of the atlas, determined by a simple heuristic, capped by the maximal texture size
- val totalArea =
- glyphsToRender.sumOf { it.glyphMetrics.bounds2D.width * it.glyphMetrics.bounds2D.height }
+ if (res.glyphsToRender.size < chars.size) {
+ logger.warn("Failed to place all characters (${chars.size}) on the atlas, " +
+ "using a reduced charset (${res.glyphsToRender.size}) instead!")
+ }
- val suggestedAtlasWidth = min(
- (sqrt(totalArea) * 1.232).toInt(),
- maxTextureSize
- )
+ return renderGlyphPage(res) to remainingGlyphs
+ }
- // Do the placement
- val atlasDimensions = doCharacterPlacement(glyphsToRender, suggestedAtlasWidth)
+ /**
+ * Tries to fit all characters on a page.
+ * If it does not fit, it reduces the list of characters to place by 20% and retries.
+ */
+ private fun tryCharacterPlacementWithShrinking(
+ chars: List
+ ): Pair>? {
+ var currentLen = chars.size
+
+ while (currentLen > 1) {
+ val result = tryCharacterPlacement(chars.subList(0, currentLen))
+
+ if (result != null) {
+ return result to chars.subList(currentLen, chars.size)
+ }
- check(atlasDimensions.width <= maxTextureSize && atlasDimensions.height <= maxTextureSize) {
- "Multiple atlases are not implemented yet."
+ currentLen = currentLen * 4 / 5
}
- // TODO: Multi atlas support
+ return null
+ }
- val atlas = createBufferedImageWithDimensions(atlasDimensions)
+ private fun renderGlyphPage(placementPlan: GlyphPlacementResult): StaticGlyphPage {
+ val atlas = createBufferedImageWithDimensions(placementPlan.atlasDimension)
- renderGlyphs(atlas, glyphsToRender)
+ renderGlyphs(atlas, placementPlan.glyphsToRender)
- val glyphs = glyphsToRender
- .map { it.fontGlyph.font to createGlyphFromGenerationInfo(it, atlasDimensions) }
+ val glyphs = placementPlan.glyphsToRender
+ .map { it.fontGlyph.font to createGlyphFromGenerationInfo(it, placementPlan.atlasDimension) }
.toSet()
val nativeImage = atlas.toNativeImage()
@@ -67,13 +94,45 @@ class StaticGlyphPage(
}
/**
- * Used for [create]. Assigns a position to every glyph.
+ * Tries to come up with a placement which includes all [chars].
+ *
+ * @return null if the resulting atlas is bigger than the maximum texture size.
+ */
+ private fun tryCharacterPlacement(chars: List): GlyphPlacementResult? {
+ // Get information about the glyphs and sort them by their height
+ val glyphsToRender = chars
+ .mapNotNull { createCharacterCreationInfo(it) }
+ .sortedBy { it.glyphMetrics.bounds2D.height }
+
+ val maxTextureSize = maxTextureSize.value
+
+ // The suggested width of the atlas, determined by a simple heuristic, capped by the maximal texture size
+ val totalArea = glyphsToRender.sumOf { it.glyphMetrics.bounds2D.width * it.glyphMetrics.bounds2D.height }
+
+ val suggestedAtlasWidth = min(
+ (sqrt(totalArea) * 1.232).toInt(),
+ maxTextureSize
+ )
+
+ // Do the placement
+ val atlasDimensions = placeCharacters(glyphsToRender, suggestedAtlasWidth)
+
+ // The placement won't fit on the current atlas size.
+ if (atlasDimensions.width > maxTextureSize || atlasDimensions.height > maxTextureSize) {
+ return null
+ }
+
+ return GlyphPlacementResult(glyphsToRender, atlasDimensions)
+ }
+
+ /**
+ * Used for [createGlyphPageWithFittingCharacters]. Assigns a position to every glyph.
*
* @param atlasWidth The width of the atlas. No character will be longer that this width
*
* @return The height of the resulting texture. Is at least (1, 1)
*/
- private fun doCharacterPlacement(glyphs: List, atlasWidth: Int): Dimension {
+ private fun placeCharacters(glyphs: List, atlasWidth: Int): Dimension {
var currentX = 0
var currentY = 0
@@ -112,4 +171,5 @@ class StaticGlyphPage(
}
}
+ private class GlyphPlacementResult(val glyphsToRender: List, val atlasDimension: Dimension)
}
From 278e042372fcc392f05c78c9b9068ac2d6b26e22 Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Mon, 25 Nov 2024 15:50:44 -0600
Subject: [PATCH 09/15] fix(importProxies): remove protocol from line
---
.../protocol/rest/v1/client/ProxyFunctions.kt | 28 ++++++++++++-------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
index 76dc7a7ab28..0530c10652e 100644
--- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
+++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/rest/v1/client/ProxyFunctions.kt
@@ -25,8 +25,10 @@ import com.mojang.blaze3d.systems.RenderSystem
import io.netty.handler.codec.http.FullHttpResponse
import net.ccbluex.liquidbounce.config.gson.interopGson
import net.ccbluex.liquidbounce.features.misc.proxy.ProxyManager
+import net.ccbluex.liquidbounce.utils.client.logger
import net.ccbluex.liquidbounce.utils.client.mc
import net.ccbluex.netty.http.model.RequestObject
+import net.ccbluex.netty.http.util.httpBadRequest
import net.ccbluex.netty.http.util.httpForbidden
import net.ccbluex.netty.http.util.httpOk
import org.lwjgl.glfw.GLFW
@@ -132,7 +134,11 @@ fun postClipboardProxy(requestObject: RequestObject): FullHttpResponse {
private fun importProxies(content: String) {
// TabNine moment
content.split("\n").map { line ->
- val split = line.split(":")
+ var lineWithoutProtocol = line
+ if (lineWithoutProtocol.contains("://")) {
+ lineWithoutProtocol = line.split("://")[1]
+ }
+ val split = lineWithoutProtocol.split(":")
val host = split[0]
val port = split[1].toInt()
@@ -151,16 +157,18 @@ private fun importProxies(content: String) {
// POST /api/v1/client/proxies/import/clipboard
@Suppress("UNUSED_PARAMETER")
fun postImportClipboardProxy(requestObject: RequestObject): FullHttpResponse {
- RenderSystem.recordRenderCall {
- runCatching {
- // Get clipboard content via GLFW
- val clipboard = GLFW.glfwGetClipboardString(mc.window.handle)?: ""
- if (!clipboard.isNotBlank()) {
- return@recordRenderCall
- }
-
- importProxies(clipboard)
+ runCatching {
+ // Get clipboard content via GLFW
+ val clipboard = GLFW.glfwGetClipboardString(mc.window.handle)?: ""
+ logger.debug ("Get clipboard content via GLFW: $clipboard")
+
+ if (!clipboard.isNotBlank()) {
+ logger.debug("Clipboard is empty, skip.")
+ return httpBadRequest("Clipboard is empty")
}
+ logger.debug("Clipboard content is not empty, import.")
+
+ importProxies(clipboard)
}
return httpOk(JsonObject())
From 55e96c1b35a918c42d1f2ece62f44d29bf9f5400 Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Mon, 25 Nov 2024 15:54:26 -0600
Subject: [PATCH 10/15]
feat(src-theme/routes/menu/proxymanager/ImportProxyModal): implement from
clipboard and from file
mfw it's just a 4 line change, why didn't I do this before when I added the endpoints?...
---
.../src/routes/menu/proxymanager/ImportProxyModal.svelte | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte b/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
index 9f2a37c5151..1c2e16043a8 100644
--- a/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
+++ b/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
@@ -7,6 +7,7 @@ import Modal from "../common/modal/Modal.svelte";
// import SwitchSetting from "../common/setting/SwitchSetting.svelte";
// import ButtonSetting from "../common/setting/ButtonSetting.svelte";
// import {editProxy as editProxyRest} from "../../../integration/rest";
+ import { importProxyFromFile, importProxyFromClipboard } from "../../../integration/rest";
export let visible: boolean;
@@ -14,8 +15,8 @@ import Modal from "../common/modal/Modal.svelte";
alert("Not implemented yet")}/>
+ on:click={() => importProxyFromClipboard() }/>
alert("Not implemented yet")}/>
+ on:click={() => importProxyFromFile() }/>
From 6cd901e0776e48a24b641a74de89232ae9e86b11 Mon Sep 17 00:00:00 2001
From: DataM0del <183248792+DataM0del@users.noreply.github.com>
Date: Mon, 25 Nov 2024 17:03:54 -0600
Subject: [PATCH 11/15]
fix(src-theme/routes/menu/proxymanager/ImportProxyModal): remove commented
imports & fix indentation
---
.../src/routes/menu/proxymanager/ImportProxyModal.svelte | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte b/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
index 1c2e16043a8..808c27fe6e8 100644
--- a/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
+++ b/src-theme/src/routes/menu/proxymanager/ImportProxyModal.svelte
@@ -2,11 +2,7 @@