diff --git a/docs/architecture.md b/docs/architecture.md index e69de29..1867749 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -0,0 +1,26 @@ +# EaglerForge Injector Architecture +The Injector has several layers (or steps) in it's patching process. These layers can be put into two seperate categories: pre-processing and post-processing. The injector patches the EaglercraftX build with the pre-processor ahead of time, and then the post-processor is appended to the EaglercraftX build. + +## Preprocessing +The preprocessor's job is to find and hook into as many internal TeaVM / Minecraft methods as possible. + +The first thing it does is it adds a piece of pre-initialisation code at the start of the TeaVM module, to define global varaibles such as `ModAPI` and `ModAPI.hooks`. + +Then it: + +Hooks into the `$rt_metadata` function, intercepting its arguments and storing them in the array `ModAPI.hooks._rippedData`. + +Hooks into the the teavm threading shim and adds controls to freeze the callstack. + +Looks for the `#game_frame` element, and then adds the post-processing codes after it (`modapi_postinit`, `modapi_modloader` and `modapi_guikit`). It also stores a copy of the `modapi_postinit` script into a fourth post init script, for the post-processing scripts to inject into the dedicated server. + +Searches for constructors and appends them to the `ModAPI.hooks._rippedConstructors` dictionary. + +Extracts and hooks into all class methods, storing their type (`instance` or `static`) into `ModAPI.hooks._rippedMethodTypeMap`, and storing the method itself in `ModAPI.hooks.methods` + +Finds static class variables, and build a proxy object for them, to allow for readwrite access even though there is no way to expose their context. The keys for the static properties of a specific class are stored under `ModAPI.hooks._rippedStaticIndexer` and the proxy objects are stored in `ModAPI.hooks._rippedStaticProperties`. + +Finally, it adds references (not hooks, as they would tank performance) to all TeaVM internal methods, most importantly `$rt_str` and `$rt_ustr`, used for interaction with jcl strings. + +## Postprocessing +The post processor is much simpler than the preprocessor, but it effectively uses the data in `ModAPI.hooks` to create a (mostly) backwards compatible `ModAPI` global. \ No newline at end of file diff --git a/index.html b/index.html index 7c73a4f..0ec4644 100644 --- a/index.html +++ b/index.html @@ -164,7 +164,7 @@ var main;(function(){` `return $rt_currentNativeThread;`, (match) => { return ( - `if(ModAPI.hooks.freezeCallstack){return {push: (a)=>{console.log("Data pushed to stack: ") + a}, pop: ()=>{console.warn("Frozen stack was popped, context is now unstable.")}}};` + + `if(ModAPI.hooks.freezeCallstack){return {push: (a)=>{}, pop: ()=>{console.warn("Frozen stack was popped, context is now unstable.")}}};` + match ); } diff --git a/postinit.injector.js b/postinit.injector.js index 1e47220..fc4f2de 100644 --- a/postinit.injector.js +++ b/postinit.injector.js @@ -405,6 +405,8 @@ globalThis.modapi_postinit = `(() => { return x; }; + ModAPI.events.newEvent("load", "client"); + var integratedServerStartup = ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.sp.internal.ClientPlatformSingleplayer", "loadIntegratedServerSourceInline"); //Integrated server setup has a randomised suffix on the end integratedServerStartup = ModAPI.hooks._rippedMethodKeys.filter(key => { return key.startsWith(integratedServerStartup); })[0]; diff --git a/postinit.js b/postinit.js index e30b3a3..337b970 100644 --- a/postinit.js +++ b/postinit.js @@ -416,6 +416,8 @@ return x; }; + ModAPI.events.newEvent("load", "client"); + ModAPI.events.newEvent("sendchatmessage", "client"); const sendChatMessageMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.entity.EntityPlayerSP", "sendChatMessage"); const sendChatMessage = ModAPI.hooks.methods[sendChatMessageMethodName];