Skip to content

Commit

Permalink
Finish of ModGUI on init
Browse files Browse the repository at this point in the history
  • Loading branch information
ZXMushroom63 committed Sep 18, 2024
1 parent 6aa2451 commit a355bb4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 7 deletions.
2 changes: 0 additions & 2 deletions injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ document.querySelector("#giveme").addEventListener("click", () => {
) {
return;
}

// @type File
var file = document.querySelector("input").files[0];
var fileType = file.name.split(".");
Expand All @@ -259,7 +258,6 @@ document.querySelector("#givemeserver").addEventListener("click", () => {
) {
return;
}

// @type File
var file = document.querySelector("input").files[0];
var fileType = file.name.split(".");
Expand Down
19 changes: 16 additions & 3 deletions 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(); main();">Done</button>
<button class="button _doneButton" onclick="this.parentElement.parentElement.remove();">Done</button>
</div>
<span>(reload to apply changes)</span>
Expand Down Expand Up @@ -168,7 +168,7 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays
fr.readAsDataURL(file);
});
}
window.modapi_displayModGui = async function () {
window.modapi_displayModGui = async function (cb) {
if (!getMods) {
return;
}
Expand Down Expand Up @@ -248,7 +248,19 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays
tr.appendChild(button);
tbody.appendChild(tr);
});
var once = false;
if (cb) {
document.querySelector("#modapi_gui_container ._doneButton").addEventListener("mousedown", ()=>{
if (once) {
return;
}
once = true;
cb();
document.querySelector("#modapi_gui_container").remove();
})
}
}
window.modapi_clearmods = async () => {
await resetMods();
window.modapi_displayModGui();
Expand Down Expand Up @@ -277,4 +289,5 @@ globalThis.modapi_guikit = `// ModAPI GUI made by TheIdiotPlays
});
f.click();
}
})();`;
})();
`;
16 changes: 14 additions & 2 deletions 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(); main();">Done</button>
<button class="button _doneButton" onclick="this.parentElement.parentElement.remove();">Done</button>
</div>
<span>(reload to apply changes)</span>
Expand Down Expand Up @@ -168,7 +168,7 @@
fr.readAsDataURL(file);
});
}
window.modapi_displayModGui = async function () {
window.modapi_displayModGui = async function (cb) {
if (!getMods) {
return;
}
Expand Down Expand Up @@ -248,7 +248,19 @@
tr.appendChild(button);
tbody.appendChild(tr);
});
var once = false;
if (cb) {
document.querySelector("#modapi_gui_container ._doneButton").addEventListener("mousedown", ()=>{
if (once) {
return;
}
once = true;
cb();
document.querySelector("#modapi_gui_container").remove();
})
}
}

window.modapi_clearmods = async () => {
await resetMods();
window.modapi_displayModGui();
Expand Down
9 changes: 9 additions & 0 deletions postinit.injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,4 +749,13 @@ globalThis.modapi_postinit = `(() => {
var x = originalCrashMethod.apply(this, args);
return x;
}
var inited = false;
const originalMainMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")];
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")] = function (...args) {
if (!inited) {
return modapi_displayModGui(originalMainMethod);
} else {
return originalMainMethod.apply(this, args);
}
}
})();`;
10 changes: 10 additions & 0 deletions postinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -749,4 +749,14 @@
var x = originalCrashMethod.apply(this, args);
return x;
}
var inited = false;
const originalMainMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")];
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")] = function (...args) {
if (!inited) {
inited = true;
return modapi_displayModGui(globalThis.main);
} else {
return originalMainMethod.apply(this, args);
}
}
})();

0 comments on commit a355bb4

Please sign in to comment.