diff --git a/src/main/java/com/chattriggers/ctjs/internal/mixins/MinecraftClientMixin.java b/src/main/java/com/chattriggers/ctjs/internal/mixins/MinecraftClientMixin.java index e2fd550f..7ed706f6 100644 --- a/src/main/java/com/chattriggers/ctjs/internal/mixins/MinecraftClientMixin.java +++ b/src/main/java/com/chattriggers/ctjs/internal/mixins/MinecraftClientMixin.java @@ -2,6 +2,7 @@ import com.chattriggers.ctjs.internal.engine.CTEvents; import com.chattriggers.ctjs.api.triggers.TriggerType; +import com.chattriggers.ctjs.internal.engine.module.ModuleManager; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.network.ServerInfo; @@ -56,7 +57,10 @@ private void injectScreenOpened(Screen screen, CallbackInfo ci) { @Inject(method = "run", at = @At("HEAD")) private void injectRun(CallbackInfo ci) { - TriggerType.GAME_LOAD.triggerAll(); + new Thread(() -> { + ModuleManager.INSTANCE.entryPass(); + TriggerType.GAME_LOAD.triggerAll(); + }).start(); } @Inject(method = "render", at = @At("HEAD")) diff --git a/src/main/kotlin/com/chattriggers/ctjs/CTJS.kt b/src/main/kotlin/com/chattriggers/ctjs/CTJS.kt index 2fc8df0e..47a3d14d 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/CTJS.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/CTJS.kt @@ -10,20 +10,14 @@ import com.chattriggers.ctjs.api.message.ChatLib import com.chattriggers.ctjs.api.render.Image import com.chattriggers.ctjs.api.triggers.TriggerType import com.chattriggers.ctjs.api.world.World +import com.chattriggers.ctjs.engine.Console import com.chattriggers.ctjs.engine.Register import com.chattriggers.ctjs.internal.commands.StaticCommand -import com.chattriggers.ctjs.engine.Console -import com.chattriggers.ctjs.internal.console.ConsoleHostProcess -import com.chattriggers.ctjs.internal.engine.CTEvents import com.chattriggers.ctjs.internal.engine.module.ModuleManager import com.chattriggers.ctjs.internal.utils.Initializer import kotlinx.serialization.json.Json import net.fabricmc.api.ClientModInitializer -import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper import net.fabricmc.loader.api.FabricLoader -import net.minecraft.client.option.KeyBinding -import net.minecraft.client.util.InputUtil -import org.lwjgl.glfw.GLFW import java.io.File import java.net.URL import java.net.URLConnection @@ -33,39 +27,19 @@ import kotlin.concurrent.thread class CTJS : ClientModInitializer { override fun onInitializeClient() { - // Need to initialize the keybind here, as putting it inside the MinecraftClient::send - // runs it too late - val keybind = KeyBindingHelper.registerKeyBinding( - KeyBinding( - "chattriggers.key.binding.console", - InputUtil.Type.KEYSYM, - GLFW.GLFW_KEY_GRAVE_ACCENT, - "chattriggers.key.category", - ) - ) - - CTEvents.RENDER_GAME.register { - if (keybind.wasPressed()) - ConsoleHostProcess.show() - } + Client.referenceSystemTime = System.nanoTime() + Initializer.initializers.forEach(Initializer::init) - Client.getMinecraft().send { - Client.referenceSystemTime = System.nanoTime() - - Initializer.initializers.forEach(Initializer::init) - - thread { - ModuleManager.entryPass() - reportHashedUUID() - } + thread { + reportHashedUUID() + } - Config.loadData() + Config.loadData() - Runtime.getRuntime().addShutdownHook(Thread { - TriggerType.GAME_UNLOAD.triggerAll() - Console.close() - }) - } + Runtime.getRuntime().addShutdownHook(Thread { + TriggerType.GAME_UNLOAD.triggerAll() + Console.close() + }) } private fun reportHashedUUID() { diff --git a/src/main/kotlin/com/chattriggers/ctjs/internal/console/ConsoleHostProcess.kt b/src/main/kotlin/com/chattriggers/ctjs/internal/console/ConsoleHostProcess.kt index ebf39a5d..aa01eb2e 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/internal/console/ConsoleHostProcess.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/internal/console/ConsoleHostProcess.kt @@ -5,10 +5,16 @@ import com.chattriggers.ctjs.api.Config import com.chattriggers.ctjs.api.client.Client import com.chattriggers.ctjs.engine.LogType import com.chattriggers.ctjs.engine.printTraceToConsole +import com.chattriggers.ctjs.internal.engine.CTEvents import com.chattriggers.ctjs.internal.engine.JSLoader +import com.chattriggers.ctjs.internal.utils.Initializer import gg.essential.universal.UDesktop import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper +import net.minecraft.client.option.KeyBinding +import net.minecraft.client.util.InputUtil +import org.lwjgl.glfw.GLFW import java.awt.Color import java.io.BufferedReader import java.io.File @@ -37,7 +43,7 @@ import kotlin.io.path.Path * Each console gets its own Host/Client pair running on their own port, so there will be * ` + 1` sockets (the extra 1 is for the generic console). */ -object ConsoleHostProcess { +object ConsoleHostProcess : Initializer { private var PORT = 9002 private var running = true private lateinit var socketOut: PrintWriter @@ -53,6 +59,22 @@ object ConsoleHostProcess { thread { hostMain() } } + override fun init() { + val keybind = KeyBindingHelper.registerKeyBinding( + KeyBinding( + "chattriggers.key.binding.console", + InputUtil.Type.KEYSYM, + GLFW.GLFW_KEY_GRAVE_ACCENT, + "chattriggers.key.category", + ) + ) + + CTEvents.RENDER_GAME.register { + if (keybind.wasPressed()) + show() + } + } + private fun hostMain() { // Spawn the Client process. This remote process can be easily debugged in IntelliJ by // adding the Remote JVM Debug command line arguments after the class path argument, and diff --git a/src/main/kotlin/com/chattriggers/ctjs/internal/engine/module/ModuleManager.kt b/src/main/kotlin/com/chattriggers/ctjs/internal/engine/module/ModuleManager.kt index df470fca..029414a4 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/internal/engine/module/ModuleManager.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/internal/engine/module/ModuleManager.kt @@ -63,6 +63,7 @@ object ModuleManager { JSLoader.setup(jars) } + @JvmOverloads fun entryPass(modules: List = cachedModules, completionListener: (percentComplete: Float) -> Unit = {}) { JSLoader.entrySetup() diff --git a/src/main/kotlin/com/chattriggers/ctjs/internal/utils/Initializer.kt b/src/main/kotlin/com/chattriggers/ctjs/internal/utils/Initializer.kt index 25c9e0ce..38ba65c1 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/internal/utils/Initializer.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/internal/utils/Initializer.kt @@ -5,6 +5,7 @@ import com.chattriggers.ctjs.api.client.KeyBind import com.chattriggers.ctjs.api.commands.DynamicCommands import com.chattriggers.ctjs.internal.commands.CTCommand import com.chattriggers.ctjs.internal.commands.StaticCommand +import com.chattriggers.ctjs.internal.console.ConsoleHostProcess import com.chattriggers.ctjs.internal.engine.module.ModuleUpdater import com.chattriggers.ctjs.internal.listeners.ClientListener import com.chattriggers.ctjs.internal.listeners.MouseListener @@ -16,6 +17,7 @@ internal interface Initializer { companion object { internal val initializers = listOf( ClientListener, + ConsoleHostProcess, CPS, CTCommand, DynamicCommands,