From 3cb01c5a5e4d8c5af677ce083091c70f9478c5a7 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Fri, 20 Sep 2024 19:00:35 +0800 Subject: [PATCH] Cool fixes --- modgui.injector.js | 3 +++ modgui.js | 4 ++++ postinit.injector.js | 28 ++++++++++++++++++++++++++++ postinit.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/modgui.injector.js b/modgui.injector.js index 2c5a49a..dd2af4f 100644 --- a/modgui.injector.js +++ b/modgui.injector.js @@ -173,8 +173,11 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays return; } if (document.querySelector("#modapi_gui_container")) { + cb ||= document.querySelector("#modapi_gui_container")._cb; document.querySelector("#modapi_gui_container").remove(); } + + document.querySelector("#modapi_gui_container")._cb = cb; var element = document.createElement("div"); element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]); diff --git a/modgui.js b/modgui.js index 2b4ef23..0d4c5c0 100644 --- a/modgui.js +++ b/modgui.js @@ -173,8 +173,12 @@ return; } if (document.querySelector("#modapi_gui_container")) { + cb ||= document.querySelector("#modapi_gui_container")._cb; document.querySelector("#modapi_gui_container").remove(); } + + document.querySelector("#modapi_gui_container")._cb = cb; + var element = document.createElement("div"); element.innerHTML = gui.replace("{splash_msg}", splashes[Math.floor(Math.random() * splashes.length)]); diff --git a/postinit.injector.js b/postinit.injector.js index b4e8278..3813b68 100644 --- a/postinit.injector.js +++ b/postinit.injector.js @@ -741,6 +741,34 @@ globalThis.modapi_postinit = `(() => { ModAPI.materials = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.block.material.Material")].staticVariables, StaticProps_ProxyConf); ModAPI.enchantments = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.enchantment.Enchantment")].staticVariables, StaticProps_ProxyConf); + const originalOptionsInit = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")] = function (...args) { + var x = originalOptionsInit.apply(this, args); + + //NOT A BUG DO NOT FIX + var msg = Math.random() < 0.025 ? "Plugins" : "Mods"; + + // Find the right constructor. (int id, int x, int y, int width, int height, String buttonText); + var btnConstructor = ModAPI.hooks._classMap['nmcg_GuiButton'].constructors.filter(c => { return c.length === 6 })[0]; + var btn = btnConstructor(9635329, 0, args[0].$height8 - 21, 100, 20, ModAPI.util.str(msg)); + args[0].$buttonList.$add(btn); + + return x; + } + + const originalOptionsAction = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")] = function (...args) { + if (args[1] && args[1].$id12 === 9635329) { + if (typeof window.modapi_displayModGui === "function") { + window.modapi_displayModGui(); + } else { + alert("[ModAPI] Mod Manager GUI does not exist!") + } + } + var x = originalOptionsAction.apply(this, args); + return x; + } + const originalCrashMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")]; ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")] = function (...args) { if (window.confirm("Your game has crashed, do you want to open the mod manager gui?")) { diff --git a/postinit.js b/postinit.js index c4f04d1..ab6190a 100644 --- a/postinit.js +++ b/postinit.js @@ -741,6 +741,34 @@ ModAPI.materials = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.block.material.Material")].staticVariables, StaticProps_ProxyConf); ModAPI.enchantments = new Proxy(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.enchantment.Enchantment")].staticVariables, StaticProps_ProxyConf); + const originalOptionsInit = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "initGui")] = function (...args) { + var x = originalOptionsInit.apply(this, args); + + //NOT A BUG DO NOT FIX + var msg = Math.random() < 0.025 ? "Plugins" : "Mods"; + + // Find the right constructor. (int id, int x, int y, int width, int height, String buttonText); + var btnConstructor = ModAPI.hooks._classMap['nmcg_GuiButton'].constructors.filter(c => { return c.length === 6 })[0]; + var btn = btnConstructor(9635329, 0, args[0].$height8 - 21, 100, 20, ModAPI.util.str(msg)); + args[0].$buttonList.$add(btn); + + return x; + } + + const originalOptionsAction = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")]; + ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.client.gui.GuiOptions", "actionPerformed")] = function (...args) { + if (args[1] && args[1].$id12 === 9635329) { + if (typeof window.modapi_displayModGui === "function") { + window.modapi_displayModGui(); + } else { + alert("[ModAPI] Mod Manager GUI does not exist!") + } + } + var x = originalOptionsAction.apply(this, args); + return x; + } + const originalCrashMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")]; ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "showCrashScreen")] = function (...args) { if (window.confirm("Your game has crashed, do you want to open the mod manager gui?")) {