From 51412011b4485d567a04b24221a04e3f5594d9c3 Mon Sep 17 00:00:00 2001 From: 1zuna <1zuna@ccbluex.net> Date: Sat, 28 Dec 2024 08:59:13 +0100 Subject: [PATCH] refactor: once handler and no stateless handling (#5072) Handling that ignores the running parameter is a very insecure way to handle events, especially when dealing with parents. This forces you to override the running parameter or create/use a different EventListener instead. --- .../liquidbounce/event/EventListener.kt | 22 ++-- .../liquidbounce/event/EventManager.kt | 18 +-- .../features/cosmetic/CosmeticService.kt | 2 +- .../features/misc/HideAppearance.kt | 4 +- .../features/module/ClientModule.kt | 28 +---- .../features/module/ModuleManager.kt | 40 ++++++- .../modules/combat/velocity/ModuleVelocity.kt | 9 +- .../combat/velocity/mode/VelocityAAC442.kt | 5 +- .../combat/velocity/mode/VelocityBlocksMC.kt | 5 +- .../combat/velocity/mode/VelocityDexland.kt | 8 +- .../velocity/mode/VelocityExemptGrim117.kt | 5 +- .../combat/velocity/mode/VelocityHylex.kt | 4 +- .../combat/velocity/mode/VelocityIntave.kt | 4 +- .../combat/velocity/mode/VelocityJumpReset.kt | 5 +- .../combat/velocity/mode/VelocityMode.kt | 16 +++ .../combat/velocity/mode/VelocityModify.kt | 5 +- .../combat/velocity/mode/VelocityStrafe.kt | 5 +- .../combat/velocity/mode/VelocityWatchdog.kt | 8 +- .../module/modules/exploit/ModuleSpoofer.kt | 2 +- .../exploit/disabler/ModuleDisabler.kt | 1 - .../disablers/DisablerVerusExperimental.kt | 13 +- .../movement/autododge/ModuleAutoDodge.kt | 7 +- .../module/modules/player/ModuleAntiAFK.kt | 11 +- .../modules/render/ModuleBreadcrumbs.kt | 2 +- .../module/modules/render/ModuleClickGui.kt | 9 +- .../module/modules/render/ModuleHud.kt | 8 +- .../protocol/event/SocketEventListener.kt | 3 +- .../script/bindings/features/ScriptChoice.kt | 3 +- .../script/bindings/features/ScriptModule.kt | 3 +- .../utils/client/EventScheduler.kt | 112 ------------------ 30 files changed, 123 insertions(+), 244 deletions(-) create mode 100644 src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityMode.kt delete mode 100644 src/main/kotlin/net/ccbluex/liquidbounce/utils/client/EventScheduler.kt diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventListener.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventListener.kt index d4e11baf643..9e4aefb511e 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventListener.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventListener.kt @@ -26,7 +26,6 @@ typealias Handler = (T) -> Unit class EventHook( val handlerClass: EventListener, val handler: Handler, - val ignoreNotRunning: Boolean, val priority: Short = 0 ) @@ -69,24 +68,34 @@ interface EventListener { } inline fun EventListener.handler( - ignoreNotRunning: Boolean = false, priority: Short = 0, noinline handler: Handler ): EventHook { return EventManager.registerEventHook(T::class.java, - EventHook(this, handler, ignoreNotRunning, priority) + EventHook(this, handler, priority) ) } +inline fun EventListener.once( + priority: Short = 0, + noinline handler: Handler +): EventHook { + lateinit var eventHook: EventHook + eventHook = EventHook(this, { + handler(it) + EventManager.unregisterEventHook(T::class.java, eventHook) + }, priority) + return EventManager.registerEventHook(T::class.java, eventHook) +} + /** * Registers an event hook for events of type [T] and launches a sequence */ inline fun EventListener.sequenceHandler( - ignoreNotRunning: Boolean = false, priority: Short = 0, noinline eventHandler: SuspendableHandler ) { - handler(ignoreNotRunning, priority) { event -> Sequence(this, eventHandler, event) } + handler(priority) { event -> Sequence(this, eventHandler, event) } } /** @@ -98,8 +107,7 @@ fun EventListener.tickHandler(eventHandler: SuspendableHandler) { // and can be used in the event handler function. This is a very useful pattern to use in Kotlin. var sequence: TickSequence? = TickSequence(this, eventHandler) - // Ignore condition makes sense because we do not want our sequence to run after we do not handle events anymore - handler(ignoreNotRunning = true) { + SequenceManager.handler { // Check if we should start or stop the sequence if (this.running) { // Check if the sequence is already running diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt index 6f0ee0edc64..383e2fc3975 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/event/EventManager.kt @@ -19,10 +19,9 @@ package net.ccbluex.liquidbounce.event import net.ccbluex.liquidbounce.event.events.* -import net.ccbluex.liquidbounce.utils.client.EventScheduler +import net.ccbluex.liquidbounce.features.misc.HideAppearance.isDestructed import net.ccbluex.liquidbounce.utils.client.logger import net.ccbluex.liquidbounce.utils.kotlin.sortedInsert -import net.minecraft.client.MinecraftClient import java.util.concurrent.CopyOnWriteArrayList import kotlin.reflect.KClass @@ -176,13 +175,6 @@ object EventManager { registry[eventClass]?.remove(eventHook as EventHook) } - /** - * Unregisters event handlers. - */ - fun unregisterEventHooks(eventClass: Class, hooks: Collection>) { - registry[eventClass]?.removeAll(hooks.toHashSet()) - } - fun unregisterEventHandler(eventListener: EventListener) { registry.values.forEach { it.removeIf { it.handlerClass == eventListener } @@ -201,12 +193,14 @@ object EventManager { * @param event to call */ fun callEvent(event: T): T { + if (isDestructed) { + return event + } + val target = registry[event.javaClass] ?: return event for (eventHook in target) { - EventScheduler.process(event) - - if (!eventHook.ignoreNotRunning && !eventHook.handlerClass.running) { + if (!eventHook.handlerClass.running) { continue } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/cosmetic/CosmeticService.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/cosmetic/CosmeticService.kt index 9af7928f6b3..59fd80cfa95 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/cosmetic/CosmeticService.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/cosmetic/CosmeticService.kt @@ -193,7 +193,7 @@ object CosmeticService : EventListener, Configurable("Cosmetics") { } @Suppress("unused") - private val sessionHandler = handler(ignoreNotRunning = true) { event -> + private val sessionHandler = handler { event -> val session = event.session // Check if the account is valid diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/misc/HideAppearance.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/misc/HideAppearance.kt index fe3fbcf6a8c..3a9b5b731bb 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/misc/HideAppearance.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/misc/HideAppearance.kt @@ -45,7 +45,7 @@ import kotlin.concurrent.thread */ object HideAppearance : EventListener { - val shiftChronometer = Chronometer() + private val shiftChronometer = Chronometer() var isHidingNow = false set(value) { @@ -68,7 +68,7 @@ object HideAppearance : EventListener { } @Suppress("unused") - val keyHandler = handler(ignoreNotRunning = true) { + private val keyHandler = handler { val keyCode = it.keyCode val modifier = it.mods diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ClientModule.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ClientModule.kt index 37321a75b7a..6b1d8a4c008 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ClientModule.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ClientModule.kt @@ -26,15 +26,11 @@ import net.ccbluex.liquidbounce.event.EventListener import net.ccbluex.liquidbounce.event.EventManager import net.ccbluex.liquidbounce.event.SequenceManager.cancelAllSequences import net.ccbluex.liquidbounce.event.events.* -import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.features.module.modules.misc.antibot.ModuleAntiBot import net.ccbluex.liquidbounce.lang.LanguageManager import net.ccbluex.liquidbounce.lang.translation import net.ccbluex.liquidbounce.script.ScriptApiRequired -import net.ccbluex.liquidbounce.utils.client.inGame -import net.ccbluex.liquidbounce.utils.client.logger -import net.ccbluex.liquidbounce.utils.client.notification -import net.ccbluex.liquidbounce.utils.client.toLowerCamelCase +import net.ccbluex.liquidbounce.utils.client.* import net.ccbluex.liquidbounce.utils.input.InputBind import net.minecraft.client.util.InputUtil @@ -135,7 +131,7 @@ open class ClientModule( * If the module is running and in game. Can be overridden to add additional checks. */ override val running: Boolean - get() = (super.running && inGame && enabled) || disableActivation + get() = super.running && inGame && (enabled || disableActivation) val bind by bind("Bind", InputBind(InputUtil.Type.KEYSYM, bind, bindAction)) .doNotIncludeWhen { !AutoConfig.includeConfiguration.includeBinds } @@ -176,7 +172,7 @@ open class ClientModule( @ScriptApiRequired open val settings by lazy { inner.associateBy { it.name } } - private var calledSinceStartup = false + internal var calledSinceStartup = false /** * Called when module is turned on @@ -193,24 +189,6 @@ open class ClientModule( */ open fun init() {} - /** - * Handles disconnect and if [disableOnQuit] is true disables module - */ - @Suppress("unused") - val onDisconnect = handler(ignoreNotRunning = true) { - if (enabled && disableOnQuit) { - enabled = false - } - } - - @Suppress("unused") - val onWorldChange = handler(ignoreNotRunning = true) { - if (enabled && !calledSinceStartup && it.world != null) { - calledSinceStartup = true - enable() - } - } - /** * If we want a module to have the requires bypass option, we specifically call it * on init. This will add the option and enable the feature. diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt index e708ab0570c..5241d544a63 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/ModuleManager.kt @@ -21,6 +21,7 @@ package net.ccbluex.liquidbounce.features.module import net.ccbluex.liquidbounce.LiquidBounce import net.ccbluex.liquidbounce.config.ConfigSystem import net.ccbluex.liquidbounce.event.EventListener +import net.ccbluex.liquidbounce.event.events.DisconnectEvent import net.ccbluex.liquidbounce.event.events.KeyboardKeyEvent import net.ccbluex.liquidbounce.event.events.MouseButtonEvent import net.ccbluex.liquidbounce.event.events.WorldChangeEvent @@ -31,8 +32,6 @@ import net.ccbluex.liquidbounce.features.module.modules.client.ModuleRichPresenc import net.ccbluex.liquidbounce.features.module.modules.client.ModuleTargets import net.ccbluex.liquidbounce.features.module.modules.combat.* import net.ccbluex.liquidbounce.features.module.modules.combat.aimbot.ModuleAutoBow -import net.ccbluex.liquidbounce.features.module.modules.combat.aimbot.ModuleDroneControl -import net.ccbluex.liquidbounce.features.module.modules.combat.aimbot.ModuleProjectileAimbot import net.ccbluex.liquidbounce.features.module.modules.combat.autoarmor.ModuleAutoArmor import net.ccbluex.liquidbounce.features.module.modules.combat.criticals.ModuleCriticals import net.ccbluex.liquidbounce.features.module.modules.combat.crystalaura.ModuleCrystalAura @@ -84,6 +83,7 @@ import net.ccbluex.liquidbounce.features.module.modules.world.packetmine.ModuleP import net.ccbluex.liquidbounce.features.module.modules.world.scaffold.ModuleScaffold import net.ccbluex.liquidbounce.features.module.modules.world.traps.ModuleAutoTrap import net.ccbluex.liquidbounce.script.ScriptApiRequired +import net.ccbluex.liquidbounce.utils.client.logger import net.ccbluex.liquidbounce.utils.client.mc import net.ccbluex.liquidbounce.utils.input.InputBind import net.ccbluex.liquidbounce.utils.kotlin.mapArray @@ -142,11 +142,45 @@ object ModuleManager : EventListener, Iterable by modules { } } + /** + * Handles world change and enables modules that are not enabled yet + */ @Suppress("unused") - val worldHandler = handler { + private val handleWorldChange = handler { event -> + // Delayed start handling + if (event.world != null) { + for (module in modules) { + if (!module.enabled || module.calledSinceStartup) continue + + try { + module.calledSinceStartup = true + module.enable() + } catch (e: Exception) { + logger.error("Failed to enable module ${module.name}", e) + } + } + } + + // Store modules configuration after world change, happens on disconnect as well ConfigSystem.storeConfigurable(modulesConfigurable) } + /** + * Handles disconnect and if [Module.disableOnQuit] is true disables module + */ + @Suppress("unused") + private val handleDisconnect = handler { + for (module in modules) { + if (module.disableOnQuit) { + try { + module.enabled = false + } catch (e: Exception) { + logger.error("Failed to disable module ${module.name}", e) + } + } + } + } + /** * Register inbuilt client modules */ 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 a5a2090bb80..e9e42ccb469 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 @@ -63,10 +63,10 @@ object ModuleVelocity : ClientModule("Velocity", Category.COMBAT) { private val delay by intRange("Delay", 0..0, 0..40, "ticks") private val pauseOnFlag by int("PauseOnFlag", 0, 0..20, "ticks") - private var pause = 0 + internal var pause = 0 @Suppress("unused") - private val countHandler = handler(ignoreNotRunning = true) { + private val pauseHandler = handler { if (pause > 0) { pause-- } @@ -76,7 +76,7 @@ object ModuleVelocity : ClientModule("Velocity", Category.COMBAT) { private val packetHandler = sequenceHandler(priority = 1) { event -> val packet = event.packet - if (!event.original) { + if (!event.original || pause > 0) { return@sequenceHandler } @@ -105,7 +105,4 @@ object ModuleVelocity : ClientModule("Velocity", Category.COMBAT) { } } - override val running: Boolean - get() = super.running && pause == 0 - } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityAAC442.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityAAC442.kt index 8a5f94049ff..0041c08f47a 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityAAC442.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityAAC442.kt @@ -28,10 +28,7 @@ import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVe * Velocity for AAC4.4.2, pretty sure, it works on other versions */ -internal object VelocityAAC442 : Choice("AAC4.4.2") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityAAC442 : VelocityMode("AAC4.4.2") { private val reduce by float("Reduce", 0.62f, 0f..1f) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityBlocksMC.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityBlocksMC.kt index 79ff37f614c..adcd80ffe52 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityBlocksMC.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityBlocksMC.kt @@ -30,10 +30,7 @@ import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket * BlocksMC velocity * @author liquidsquid1 */ -internal object VelocityBlocksMC : Choice("BlocksMC") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityBlocksMC : VelocityMode("BlocksMC") { @Suppress("unused") private val packetHandler = handler { event -> diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityDexland.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityDexland.kt index 15b91d182e7..628eaf64f6a 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityDexland.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityDexland.kt @@ -18,16 +18,10 @@ */ package net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode -import net.ccbluex.liquidbounce.config.types.Choice -import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable import net.ccbluex.liquidbounce.event.events.AttackEntityEvent import net.ccbluex.liquidbounce.event.handler -import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVelocity.modes -internal object VelocityDexland : Choice("Dexland") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityDexland : VelocityMode("Dexland") { private val hReduce by float("HReduce", 0.3f, 0f..1f) private val times by int("AttacksToWork", 4, 1..10) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityExemptGrim117.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityExemptGrim117.kt index 11d38f04f59..eef0e07831d 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityExemptGrim117.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityExemptGrim117.kt @@ -41,10 +41,7 @@ import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket * * https://github.com/GrimAnticheat/Grim/issues/1133 */ -internal object VelocityExemptGrim117 : Choice("ExemptGrim117") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityExemptGrim117 : VelocityMode("ExemptGrim117") { private var alternativeBypass by boolean("AlternativeBypass", true) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityHylex.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityHylex.kt index 9d79d3ad880..b995a51e079 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityHylex.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityHylex.kt @@ -32,9 +32,7 @@ import net.ccbluex.liquidbounce.utils.entity.moving * Works because of a silly exemption from Hylex * @author @liquidsquid1 */ -object VelocityHylex : Choice("Hylex") { - override val parent: ChoiceConfigurable - get() = modes +object VelocityHylex : VelocityMode("Hylex") { @Suppress("unused") private val attackHandler = handler { diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityIntave.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityIntave.kt index 0a93faa8893..9604e51b4bf 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityIntave.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityIntave.kt @@ -28,9 +28,7 @@ import net.ccbluex.liquidbounce.event.tickHandler import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVelocity.modes import net.minecraft.client.gui.screen.ingame.InventoryScreen -object VelocityIntave : Choice("Intave") { - override val parent: ChoiceConfigurable - get() = modes +object VelocityIntave : VelocityMode("Intave") { private class ReduceOnAttack(parent: EventListener?) : ToggleableConfigurable( parent, "ReduceOnAttack", diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityJumpReset.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityJumpReset.kt index 64f94f2e15d..e286124d7c8 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityJumpReset.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityJumpReset.kt @@ -29,10 +29,7 @@ import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVe /** * Jump Reset mode. A technique most players use to minimize the amount of knockback they get. */ -internal object VelocityJumpReset : Choice("JumpReset") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityJumpReset : VelocityMode("JumpReset") { object JumpByReceivedHits : ToggleableConfigurable(ModuleVelocity, "JumpByReceivedHits", false) { val hitsUntilJump by int("HitsUntilJump", 2, 0..10) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityMode.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityMode.kt new file mode 100644 index 00000000000..6c14b7c2a88 --- /dev/null +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityMode.kt @@ -0,0 +1,16 @@ +package net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode + +import net.ccbluex.liquidbounce.config.types.Choice +import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable +import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVelocity.modes +import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVelocity.pause + +abstract class VelocityMode(name: String) : Choice(name) { + + override val parent: ChoiceConfigurable + get() = modes + + override val running: Boolean + get() = super.running && pause == 0 + +} diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityModify.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityModify.kt index 7d43bbe20b0..8337b5bee22 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityModify.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityModify.kt @@ -33,10 +33,7 @@ import kotlin.random.Random /** * Basic velocity which should bypass the most server with regular anti-cheats like NCP. */ -internal object VelocityModify : Choice("Modify") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityModify : VelocityMode("Modify") { private val horizontal by float("Horizontal", 0f, -1f..1f) private val vertical by float("Vertical", 0f, -1f..1f) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt index b94b9a6e125..76269677eba 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityStrafe.kt @@ -34,10 +34,7 @@ import net.minecraft.network.packet.s2c.play.ExplosionS2CPacket /** * Strafe velocity */ -internal object VelocityStrafe : Choice("Strafe") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityStrafe : VelocityMode("Strafe") { private val delay by int("Delay", 2, 0..10, "ticks") private val strength by float("Strength", 1f, 0.1f..2f) diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityWatchdog.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityWatchdog.kt index 542ef0c050a..7f70a3dd00b 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityWatchdog.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/combat/velocity/mode/VelocityWatchdog.kt @@ -18,18 +18,12 @@ */ package net.ccbluex.liquidbounce.features.module.modules.combat.velocity.mode -import net.ccbluex.liquidbounce.config.types.Choice -import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable import net.ccbluex.liquidbounce.event.events.PacketEvent import net.ccbluex.liquidbounce.event.handler import net.ccbluex.liquidbounce.event.tickHandler -import net.ccbluex.liquidbounce.features.module.modules.combat.velocity.ModuleVelocity.modes import net.minecraft.network.packet.s2c.play.EntityVelocityUpdateS2CPacket -internal object VelocityWatchdog : Choice("Watchdog") { - - override val parent: ChoiceConfigurable - get() = modes +internal object VelocityWatchdog : VelocityMode("Watchdog") { private var absorbedVelocity = false diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleSpoofer.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleSpoofer.kt index bfd97dc2ba0..854c417acc1 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleSpoofer.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/ModuleSpoofer.kt @@ -35,7 +35,7 @@ object ModuleSpoofer : ClientModule("ClientSpoofer", Category.EXPLOIT) { ) override val running: Boolean - get() = enabled && !isDestructed + get() = this.enabled fun clientBrand(brand: String) = if (running) mode.activeChoice.getBrand() else brand diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/ModuleDisabler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/ModuleDisabler.kt index c19243044f3..9e4bafe4493 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/ModuleDisabler.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/exploit/disabler/ModuleDisabler.kt @@ -32,7 +32,6 @@ import net.ccbluex.liquidbounce.utils.client.regular */ object ModuleDisabler : ClientModule("Disabler", Category.EXPLOIT) { - init { tree(DisablerGrimSpectate) tree(DisablerVulcanScaffold) 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 5ec267f0908..04e36f49c44 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 @@ -19,6 +19,7 @@ package net.ccbluex.liquidbounce.features.module.modules.exploit.disabler.disablers import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable +import net.ccbluex.liquidbounce.event.EventListener import net.ccbluex.liquidbounce.event.events.PacketEvent import net.ccbluex.liquidbounce.event.events.QueuePacketEvent import net.ccbluex.liquidbounce.event.events.TransferOrigin @@ -55,6 +56,10 @@ internal object DisablerVerusExperimental : ToggleableConfigurable(ModuleDisable private val check14E by boolean("Scaffold14E", true) + // Disables in-game check + override val running: Boolean + get() = ModuleDisabler.enabled && this.enabled + object NoAction : ToggleableConfigurable(DisablerVerusExperimental, "NoAction", false) { private val sprinting by boolean("Sprinting", true) @@ -199,11 +204,9 @@ internal object DisablerVerusExperimental : ToggleableConfigurable(ModuleDisable @Suppress("unused") private val fakeLagHandler = handler( - // We want to have this running when not in-game yet - ignoreNotRunning = true, priority = EventPriorityConvention.SAFETY_FEATURE ) { event -> - if (!this.enabled || event.origin != TransferOrigin.SEND || waitTime > System.currentTimeMillis()) { + if (event.origin != TransferOrigin.SEND || waitTime > System.currentTimeMillis()) { return@handler } @@ -240,13 +243,11 @@ internal object DisablerVerusExperimental : ToggleableConfigurable(ModuleDisable @Suppress("unused") private val flushHandler = handler( - // We want to have this running when not in-game yet - ignoreNotRunning = true, priority = EventPriorityConvention.OBJECTION_AGAINST_EVERYTHING ) { event -> val packet = event.packet - if (!this.enabled || waitTime > System.currentTimeMillis() || event.origin != TransferOrigin.SEND + if (waitTime > System.currentTimeMillis() || event.origin != TransferOrigin.SEND || packet !is PlayerMoveC2SPacket) { return@handler } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/autododge/ModuleAutoDodge.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/autododge/ModuleAutoDodge.kt index 172cfb416ec..b5607f0ccb0 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/autododge/ModuleAutoDodge.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/movement/autododge/ModuleAutoDodge.kt @@ -21,12 +21,11 @@ package net.ccbluex.liquidbounce.features.module.modules.movement.autododge import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable import net.ccbluex.liquidbounce.event.events.MovementInputEvent import net.ccbluex.liquidbounce.event.handler +import net.ccbluex.liquidbounce.event.once import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.player.ModuleBlink import net.ccbluex.liquidbounce.features.module.modules.render.murdermystery.ModuleMurderMystery -import net.ccbluex.liquidbounce.features.module.modules.world.scaffold.ModuleScaffold -import net.ccbluex.liquidbounce.utils.client.EventScheduler import net.ccbluex.liquidbounce.utils.client.PacketQueueManager import net.ccbluex.liquidbounce.utils.client.Timer import net.ccbluex.liquidbounce.utils.entity.* @@ -81,8 +80,8 @@ object ModuleAutoDodge : ClientModule("AutoDodge", Category.COMBAT) { } if (dodgePlan.shouldJump && AllowRotationChange.allowJump && player.isOnGround) { - EventScheduler.schedule(ModuleScaffold) { - it.jump = true + once { event -> + event.jump = true } } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.kt index f95a48b71ed..d1006949efd 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/player/ModuleAntiAFK.kt @@ -23,17 +23,16 @@ import net.ccbluex.liquidbounce.config.types.ChoiceConfigurable import net.ccbluex.liquidbounce.config.types.ToggleableConfigurable import net.ccbluex.liquidbounce.event.events.MovementInputEvent import net.ccbluex.liquidbounce.event.handler +import net.ccbluex.liquidbounce.event.once import net.ccbluex.liquidbounce.event.tickHandler import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiAFK.CustomMode.Rotate.angle import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiAFK.CustomMode.Rotate.ignoreOpenInventory import net.ccbluex.liquidbounce.features.module.modules.player.ModuleAntiAFK.CustomMode.Rotate.rotationsConfigurable -import net.ccbluex.liquidbounce.features.module.modules.world.scaffold.ModuleScaffold import net.ccbluex.liquidbounce.utils.aiming.Rotation import net.ccbluex.liquidbounce.utils.aiming.RotationManager import net.ccbluex.liquidbounce.utils.aiming.RotationsConfigurable -import net.ccbluex.liquidbounce.utils.client.EventScheduler import net.ccbluex.liquidbounce.utils.kotlin.Priority import net.ccbluex.liquidbounce.utils.kotlin.random import net.ccbluex.liquidbounce.utils.movement.DirectionalInput @@ -85,8 +84,8 @@ object ModuleAntiAFK : ClientModule("AntiAFK", Category.PLAYER) { val repeatable = tickHandler { when (Random.nextInt(0, 6)) { 0 -> { - EventScheduler.schedule(ModuleScaffold) { - it.jump = true + once { event -> + event.jump = true } } @@ -169,8 +168,8 @@ object ModuleAntiAFK : ClientModule("AntiAFK", Category.PLAYER) { } if (jump && player.isOnGround) { - EventScheduler.schedule(ModuleScaffold) { - it.jump = true + once { event -> + event.jump = true } } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleBreadcrumbs.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleBreadcrumbs.kt index 2e1872c1dfb..528d42a1e3b 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleBreadcrumbs.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleBreadcrumbs.kt @@ -148,7 +148,7 @@ object ModuleBreadcrumbs : ClientModule("Breadcrumbs", Category.RENDER, aliases } @Suppress("unused") - val worldChangeHandler = handler(ignoreNotRunning = true) { + private val worldChangeHandler = handler { clear() } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleClickGui.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleClickGui.kt index 3d65280e2dc..e3befb07357 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleClickGui.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleClickGui.kt @@ -33,7 +33,6 @@ import net.ccbluex.liquidbounce.integration.theme.ThemeManager import net.ccbluex.liquidbounce.utils.client.asText import net.ccbluex.liquidbounce.utils.client.inGame import net.ccbluex.liquidbounce.utils.kotlin.EventPriorityConvention -import net.minecraft.client.gui.DrawContext import net.minecraft.client.gui.screen.Screen import org.lwjgl.glfw.GLFW @@ -46,6 +45,8 @@ import org.lwjgl.glfw.GLFW object ModuleClickGui : ClientModule("ClickGUI", Category.RENDER, bind = GLFW.GLFW_KEY_RIGHT_SHIFT, disableActivation = true) { + override val running = true + @Suppress("UnusedPrivateProperty") private val scale by float("Scale", 1f, 0.5f..2f).onChanged { EventManager.callEvent(ClickGuiScaleChangeEvent(it)) @@ -149,7 +150,6 @@ object ModuleClickGui : @Suppress("unused") private val gameRenderHandler = handler( priority = EventPriorityConvention.OBJECTION_AGAINST_EVERYTHING, - ignoreNotRunning = true ) { // A hack to prevent the clickgui from being drawn if (mc.currentScreen !is ClickScreen) { @@ -158,16 +158,13 @@ object ModuleClickGui : } @Suppress("unused") - private val browserReadyHandler = handler( - ignoreNotRunning = true - ) { + private val browserReadyHandler = handler { createView() } @Suppress("unused") private val worldChangeHandler = sequenceHandler( priority = EventPriorityConvention.OBJECTION_AGAINST_EVERYTHING, - ignoreNotRunning = true ) { event -> if (event.world == null) { return@sequenceHandler diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleHud.kt b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleHud.kt index 291f81e8bc4..e07da2a40e3 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleHud.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/features/module/modules/render/ModuleHud.kt @@ -20,10 +20,12 @@ package net.ccbluex.liquidbounce.features.module.modules.render import net.ccbluex.liquidbounce.config.types.Configurable import net.ccbluex.liquidbounce.config.types.Value +import net.ccbluex.liquidbounce.event.EventListener import net.ccbluex.liquidbounce.event.EventManager import net.ccbluex.liquidbounce.event.events.ScreenEvent import net.ccbluex.liquidbounce.event.events.SpaceSeperatedNamesChangeEvent import net.ccbluex.liquidbounce.event.handler +import net.ccbluex.liquidbounce.features.misc.HideAppearance.isDestructed import net.ccbluex.liquidbounce.features.misc.HideAppearance.isHidingNow import net.ccbluex.liquidbounce.features.module.Category import net.ccbluex.liquidbounce.features.module.ClientModule @@ -47,6 +49,9 @@ import net.minecraft.client.gui.screen.DisconnectedScreen object ModuleHud : ClientModule("HUD", Category.RENDER, state = true, hide = true) { + override val running + get() = this.enabled && !isDestructed + private var browserTab: ITab? = null override val baseKey: String @@ -68,7 +73,8 @@ object ModuleHud : ClientModule("HUD", Category.RENDER, state = true, hide = tru tree(Configurable("Custom", customComponents as MutableList>)) } - val screenHandler = handler(ignoreNotRunning = true) { + @Suppress("unused") + private val screenHandler = handler { if (!running || !inGame || it.screen is DisconnectedScreen || isHidingNow) { browserTab?.closeTab() browserTab = null diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/event/SocketEventListener.kt b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/event/SocketEventListener.kt index cba731afb8a..7019f3643de 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/event/SocketEventListener.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/integration/interop/protocol/event/SocketEventListener.kt @@ -51,8 +51,7 @@ class SocketEventListener : EventListener { val eventHook = EventHook( this, - { writeToSockets(it) }, - false + { writeToSockets(it) } ) registeredEvents[eventClass] = eventHook diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptChoice.kt b/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptChoice.kt index c224d22d117..d83dcd1b413 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptChoice.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptChoice.kt @@ -85,8 +85,7 @@ class ScriptChoice(choiceObject: Map, override val parent: ChoiceCo this, { callEvent(eventName, it) - }, - false + } ) ) } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptModule.kt b/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptModule.kt index f784fa050c8..12ea71a592d 100644 --- a/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptModule.kt +++ b/src/main/kotlin/net/ccbluex/liquidbounce/script/bindings/features/ScriptModule.kt @@ -124,8 +124,7 @@ class ScriptModule(val script: PolyglotScript, moduleObject: Map) : this, { callEvent(eventName, it) - }, - false + } ) ) } diff --git a/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/EventScheduler.kt b/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/EventScheduler.kt deleted file mode 100644 index 68218aa76c8..00000000000 --- a/src/main/kotlin/net/ccbluex/liquidbounce/utils/client/EventScheduler.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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 . - */ -package net.ccbluex.liquidbounce.utils.client - -import net.ccbluex.liquidbounce.event.ALL_EVENT_CLASSES -import net.ccbluex.liquidbounce.event.Event -import net.ccbluex.liquidbounce.event.EventListener -import net.ccbluex.liquidbounce.features.module.ClientModule -import java.util.concurrent.CopyOnWriteArrayList - -/** - * Useful for sending actions to other events. - */ -object EventScheduler : EventListener { - - /** - * Maps the event class to the scheduled tasks that currently wait for it. - */ - private val eventActionsMap: Map, CopyOnWriteArrayList> - - init { - eventActionsMap = ALL_EVENT_CLASSES.associate { Pair(it.java, CopyOnWriteArrayList()) } - } - - /** - * Schedules a task on the next moment an event is called. - * - * @param uniqueId Allows the caller to specify a unique id for the event. If an event is already scheduled for - * that event with the same module and id, the task will not be scheduled again. - * @return Whether the task was scheduled. A reason why a schedule failed is the `uniqueId` param - * or the event does not exist. - */ - inline fun schedule( - module: ClientModule, - uniqueId: Int? = null, - noinline action: (T) -> Unit - ): Boolean { - return schedule(module, T::class.java, uniqueId) { action(it as T) } - } - - /** - * @see schedule - */ - fun schedule( - module: ClientModule, - eventClass: Class, - uniqueId: Int?, - action: (Event) -> Unit - ): Boolean { - val scheduledEvents = eventActionsMap[eventClass] ?: return false - - if (uniqueId != null) { - val alreadyScheduled = scheduledEvents.any { it.module == module && it.id == uniqueId } - - if (alreadyScheduled) { - return false - } - } - - scheduledEvents.add(ScheduleInfo(module, uniqueId, action)) - - return true - } - - - fun clear(module: ClientModule) { - for (value in eventActionsMap.values) { - value.removeIf { it.module == module } - } - } - - fun process(event: Event) { - val scheduledTasks = eventActionsMap[event.javaClass] ?: return - - // DON'T CHANGE THIS! This prevents a race condition. I know it looks silly, but it prevents problems. - scheduledTasks.removeIf { scheduledTask -> - // The removeIf function gives us no guarantee that the predicate is executed only once... - if (!scheduledTask.discarded) { - scheduledTask.action(event) - - scheduledTask.discarded = true - } - - true - } - } - - // An event here that detects world change then clears the list - - data class ScheduleInfo( - val module: ClientModule, - val id: Int?, - val action: (Event) -> Unit, - var discarded: Boolean = false - ) -}