Skip to content

Commit

Permalink
not quite done, but launch GUI before client (#5)
Browse files Browse the repository at this point in the history
* Update modgui.js

* Update modgui.injector.js

* idk if u want this

* idk if u want this pt 2

* I cont beleive i forgor this

* forgor
  • Loading branch information
STPv22 authored Sep 18, 2024
1 parent df75615 commit 6aa2451
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 62 deletions.
5 changes: 5 additions & 0 deletions injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ var main;(function(){`
\<script id="libserverside"\>{"._|_libserverside_|_."}\<\/script\>`
);

patchedFile = patchedFile.replace(
`document.getElementById("launch_countdown_screen").remove(); main();`,
`document.getElementById("launch_countdown_screen").remove(); window.modapi_displayModGui();`
)

const extractConstructorRegex =
/^\s*function (\S*?)__init_\d*?\((?!\$)/gm;
const extractConstructorFullNameRegex =
Expand Down
3 changes: 2 additions & 1 deletion modgui.injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays
<button class="button" onclick="window.modapi_uploadmod()">Upload Mod (.js)</button>
<button class="button" onclick="window.modapi_addmod()">Add Mod From URL</button>
<button class="button" style="text-shadow: 0px 0px 10px rgba(255, 0, 0, 0.5)" onclick="window.modapi_clearmods()">Clear All Mods</button>
<button class="button" onclick="this.parentElement.parentElement.remove();">Done</button>
<button class="button" onclick="this.parentElement.parentElement.remove(); main();">Done</button>
</div>
<span>(reload to apply changes)</span>
Expand Down Expand Up @@ -159,6 +159,7 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays
}
</style>
</div>\`;
async function fileToDataURI(file) {
return new Promise((res, rej) => {
var fr = new FileReader();
Expand Down
3 changes: 2 additions & 1 deletion modgui.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<button class="button" onclick="window.modapi_uploadmod()">Upload Mod (.js)</button>
<button class="button" onclick="window.modapi_addmod()">Add Mod From URL</button>
<button class="button" style="text-shadow: 0px 0px 10px rgba(255, 0, 0, 0.5)" onclick="window.modapi_clearmods()">Clear All Mods</button>
<button class="button" onclick="this.parentElement.parentElement.remove();">Done</button>
<button class="button" onclick="this.parentElement.parentElement.remove(); main();">Done</button>
</div>
<span>(reload to apply changes)</span>
Expand Down Expand Up @@ -159,6 +159,7 @@
}
</style>
</div>`;

async function fileToDataURI(file) {
return new Promise((res, rej) => {
var fr = new FileReader();
Expand Down
31 changes: 1 addition & 30 deletions postinit.injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,35 +741,6 @@ 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?")) {
Expand All @@ -778,4 +749,4 @@ globalThis.modapi_postinit = `(() => {
var x = originalCrashMethod.apply(this, args);
return x;
}
})();`;
})();`;
31 changes: 1 addition & 30 deletions postinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,35 +741,6 @@
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?")) {
Expand All @@ -778,4 +749,4 @@
var x = originalCrashMethod.apply(this, args);
return x;
}
})();
})();

0 comments on commit 6aa2451

Please sign in to comment.