Gui update

This commit is contained in:
ZXMushroom63 2024-09-22 19:26:12 +08:00
parent b017107907
commit 76e3d64e31
5 changed files with 114 additions and 18 deletions

View File

@ -89,6 +89,8 @@
<label class="custom-file-label" for="htmlFile"
>Choose .html file...</label
>
<br />
<span><code id="status">Awaiting input...</code></span>
<br /><br />
<button class="btn btn-primary" id="giveme">Make modded client</button>
<button class="btn btn-primary" id="givemeserver" disabled>
@ -123,7 +125,9 @@
</details>
<details>
<summary>Roadmap?</summary>
<a href="https://eaglerforge.github.io/EaglerForgeInjector/roadmap/">roadmap.</a>
<a href="https://eaglerforge.github.io/EaglerForgeInjector/roadmap/"
>roadmap.</a
>
</details>
<details>
<summary>How does this tool work?</summary>
@ -143,7 +147,9 @@
</div>
</div>
<script src="filesaver.min.js"></script>
<!-- Libraries -->
<script src="libs/babel.min.js"></script>
<script src="libs/filesaver.min.js"></script>
<script>
document.querySelector("#htmlFile").addEventListener("input", (e) => {
@ -166,6 +172,7 @@
`;
var freezeCallstack = `if(ModAPI.hooks.freezeCallstack){return false};`;
</script>
<script src="injector.stepAsync.js"></script>
<script src="injector.js"></script>
<!-- Code assets -->

View File

@ -1,3 +1,11 @@
function wait(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => { resolve(); }, ms);
});
}
function _status(x) {
document.querySelector("#status").innerText = x;
}
function entriesToStaticVariableProxy(entries, prefix) {
var getComponents = "";
entries.forEach((entry) => {
@ -45,7 +53,9 @@ function entriesToStaticVariableProxy(entries, prefix) {
});`;
return proxy;
}
function processClasses(string) {
async function processClasses(string) {
_status("Beginning patch process...");
await wait(50);
var patchedFile = string;
patchedFile = patchedFile.replaceAll(
`(function(root, module) {`,
@ -57,6 +67,10 @@ function processClasses(string) {
`${modapi_preinit}
var main;(function(){`
);
_status("Patching threads and reflect metadata...");
await wait(50);
patchedFile = patchedFile
.replace("\r", "")
.replace(
@ -97,16 +111,8 @@ var main;(function(){`
patchedFile = patchedFile.replaceAll("function TeaVMThread(", "globalThis.ModAPI.hooks.TeaVMThread = TeaVMThread;\nfunction TeaVMThread(");
patchedFile = patchedFile.replace(
` id="game_frame">`,
` id="game_frame">
\<script id="modapi_postinit"\>${globalThis.modapi_postinit}\<\/script\>
\<script id="modapi_postinitasync"\>${globalThis.modapi_postinitasync}\<\/script\>
\<script id="modapi_modloader"\>${globalThis.modapi_modloader}\<\/script\>
\<script id="modapi_guikit"\>${globalThis.modapi_guikit}\<\/script\>
\<script id="modapi_postinit_data"\>globalThis.modapi_postinit = \`${globalThis.modapi_postinit}\`;\<\/script\>
\<script id="libserverside"\>{"._|_libserverside_|_."}\<\/script\>`
);
_status("Extracting constructors and methods...");
await wait(50);
const extractConstructorRegex =
/^\s*function (\S*?)__init_\d*?\((?!\$)/gm;
@ -211,7 +217,8 @@ var main;(function(){`
return proxy + "\n" + match;
}
);
_status("Extracting teavm internals...");
await wait(50);
patchedFile = patchedFile.replaceAll(
/function \$rt_\S+?\(/gm,
(match) => {
@ -223,9 +230,28 @@ var main;(function(){`
);
}
);
_status("Applying async override...");
await wait(50);
//patchedFile = await asyncify(patchedFile);
_status("Injecting scripts...");
await wait(50);
patchedFile = patchedFile.replace(
` id="game_frame">`,
` id="game_frame">
\<script id="modapi_postinit"\>${globalThis.modapi_postinit}\<\/script\>
\<script id="modapi_postinitasync"\>${globalThis.modapi_postinitasync}\<\/script\>
\<script id="modapi_modloader"\>${globalThis.modapi_modloader}\<\/script\>
\<script id="modapi_guikit"\>${globalThis.modapi_guikit}\<\/script\>
\<script id="modapi_postinit_data"\>globalThis.modapi_postinit = \`${globalThis.modapi_postinit}\`;\<\/script\>
\<script id="libserverside"\>{"._|_libserverside_|_."}\<\/script\>`
);
patchedFile = patchedFile.replaceAll(/main\(\);\s*?}/gm, (match) => {
return match.replace("main();", "main();ModAPI.hooks._postInit();");
});
_status("Done, awaiting input...");
await wait(50);
return patchedFile;
}
@ -241,8 +267,8 @@ document.querySelector("#giveme").addEventListener("click", () => {
var fileType = file.name.split(".");
fileType = fileType[fileType.length - 1];
file.text().then((string) => {
var patchedFile = processClasses(string);
file.text().then(async (string) => {
var patchedFile = await processClasses(string);
patchedFile.replace(`{"._|_libserverside_|_."}`)
var blob = new Blob([patchedFile], { type: file.type });
saveAs(blob, "processed." + fileType);
@ -261,8 +287,8 @@ document.querySelector("#givemeserver").addEventListener("click", () => {
var fileType = file.name.split(".");
fileType = fileType[fileType.length - 1];
file.text().then((string) => {
var patchedFile = processClasses(string);
file.text().then(async (string) => {
var patchedFile = await processClasses(string);
patchedFile.replace(`{"._|_libserverside_|_."}`, `(${EFServer.toString()})()`);
var blob = new Blob([patchedFile], { type: file.type });
saveAs(blob, "efserver." + fileType);

61
injector.stepAsync.js Normal file
View File

@ -0,0 +1,61 @@
// Babel plugin to transform functions and calls
const ASYNC_PLUGIN_1 = function ({ types: t }) {
return {
visitor: {
FunctionDeclaration(path) {
console.log(path);
path.node.async = true;
},
ArrowFunctionExpression(path) {
console.log(path);
path.node.async = true;
},
CallExpression(path) {
console.log(path);
if (path.parent.type !== 'AwaitExpression') {
path.replaceWith(
t.awaitExpression(path.node)
);
}
}
}
};
};
async function asyncify(input) {
let isHtml = true;
let inputHtml = input;
// Check if the input is raw JavaScript
if (!input.trim().startsWith('<')) {
isHtml = false;
inputHtml = `<script>${input}</script>`;
}
_status("[ASYNC_PLUGIN_1] Parsing html...");
await wait(50);
const parser = new DOMParser();
const doc = parser.parseFromString(inputHtml, 'text/html');
const scriptTags = doc.querySelectorAll('script');
for (let i = 0; i < scriptTags.length; i++) {
const scriptTag = scriptTags[i];
const code = scriptTag.textContent;
_status("[ASYNC_PLUGIN_1] Transpiling script #" + (i + 1) + " of length " + Math.round(code.length / 1000) + "k...");
await wait(50);
const output = Babel.transform(code, {
plugins: [ASYNC_PLUGIN_1]
});
scriptTag.textContent = output.code;
}
_status("[ASYNC_PLUGIN_1] Job complete!");
await wait(50);
if (isHtml) {
return doc.documentElement.outerHTML;
} else {
return doc.querySelector('script').textContent;
}
}

2
libs/babel.min.js vendored Normal file

File diff suppressed because one or more lines are too long