mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 06:01:38 -09:00
u37 fixes
This commit is contained in:
parent
814104e758
commit
d872980fc4
@ -41,4 +41,6 @@ Methods:
|
||||
- Makes a java array from a class and a javascript array.
|
||||
- The class parameter can be retrieved via reflect: `ModAPI.reflect.getClassById("net.minecraft.util.BlockPos").class`
|
||||
- `ModAPI.util.wrap(obj: Object) : object`
|
||||
- Returns a wrapper around native java objects, removing prefixes and fixing method outputs.
|
||||
- Returns a wrapper around native java objects, removing prefixes and fixing method outputs.
|
||||
- `ModAPI.util.getNearestProperty(object: Object, property: string) : string`
|
||||
- Finds the nearest property name to the one you specify (suffix based). This is used to mitigate teavm adding random suffixes to properties.
|
@ -2,7 +2,7 @@
|
||||
When TeaVM compiles code, it sometimes does strange things.
|
||||
|
||||
#### Property Suffixes
|
||||
TeaVM will add suffixes to some variables, seemingly randomly. An example is the property `inGround` of any entity. When accessing this on the `ModAPI.player.fishEntity` object, TeaVM has renamed it to `inGround2`.
|
||||
TeaVM will add suffixes to some variables, seemingly randomly. An example is the property `inGround` of any entity. When accessing this on the `ModAPI.player.fishEntity` object, TeaVM has renamed it to `inGround2`. Can be mitigated with `ModAPI.util.getNearestProperty`.
|
||||
|
||||
#### Collapsing Methods
|
||||
When I was trying to hook into the server-side processing of chat messages, I found that chat packets were handled by the method `processChatMessage` in `NetHandlerPlayServer`. However, in the compiled JavaScript, this method no longer exists. This is because it is only used once, in the `processPacket` method of `C01PacketChatMessage`. TeaVM automatically saw this, and collapsed one method into the other.
|
||||
|
@ -29,7 +29,7 @@ PluginAPI.addEventListener("update", () => { //Every client tick
|
||||
if (
|
||||
PluginAPI.player.fishEntity !== undefined && //If the fish hook exists
|
||||
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
|
||||
PluginAPI.player.fishEntity.inGround2 //And the hook is in the ground
|
||||
PluginAPI.player.fishEntity[PluginAPI.util.getNearestProperty(ModAPI.player.fishEntity, "inGround")] //And the hook is in the ground (the inGround property is botched with random suffixes sometimes)
|
||||
) {
|
||||
GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position
|
||||
PluginAPI.player.fishEntity.posX,
|
||||
|
@ -59,9 +59,10 @@
|
||||
if (!globalThis.LCI_LMBEVENTS[cid]) {
|
||||
return oldDig.apply(this, [$this, packet]);
|
||||
}
|
||||
var statusTag = Object.keys(packet.$status).find(x => { return x.startsWith("$name") });
|
||||
var $status = ModAPI.util.getNearestProperty(packet, "$status");
|
||||
var statusTag = Object.keys(packet[$status]).find(x => { return x.startsWith("$name") });
|
||||
var positionTag = Object.keys(packet).filter(x => { return x.startsWith("$position") })[0];
|
||||
var stat = ModAPI.util.unstr(packet.$status[statusTag]);
|
||||
var stat = ModAPI.util.unstr(packet[$status][statusTag]);
|
||||
if (stat === "START_DESTROY_BLOCK") {
|
||||
sendPacket($this, packetblockchange($this.$serverController.$worldServerForDimension($this.$playerEntity.$dimension), packet[positionTag]));
|
||||
}
|
||||
|
@ -90,7 +90,9 @@
|
||||
>Choose .html file...</label
|
||||
>
|
||||
<br />
|
||||
<span><code id="status">Awaiting input...</code></span>
|
||||
<span><label>Minify: </label><input type="checkbox" oninput="globalThis.doShronk = this.checked">
|
||||
<label>EaglerForge: </label><input checked type="checkbox" oninput="globalThis.doEaglerforge = this.checked">
|
||||
<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>
|
||||
@ -172,7 +174,7 @@
|
||||
`;
|
||||
var freezeCallstack = `if(ModAPI.hooks.freezeCallstack){return false};`;
|
||||
</script>
|
||||
<script src="injector.stepAsync.js"></script>
|
||||
<script src="injector.minify.js"></script>
|
||||
<script src="injector.js"></script>
|
||||
|
||||
<!-- Code assets -->
|
||||
|
31
injector.js
31
injector.js
@ -1,3 +1,4 @@
|
||||
globalThis.doEaglerforge = true;
|
||||
function wait(ms) {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => { resolve(); }, ms);
|
||||
@ -231,10 +232,14 @@ var main;(function(){`
|
||||
}
|
||||
);
|
||||
|
||||
_status("Applying async override...");
|
||||
await wait(50);
|
||||
if (globalThis.doShronk) {
|
||||
_status("Shrinking file...");
|
||||
await wait(50);
|
||||
|
||||
patchedFile = await shronk(patchedFile);
|
||||
}
|
||||
|
||||
|
||||
//patchedFile = await asyncify(patchedFile);
|
||||
_status("Injecting scripts...");
|
||||
await wait(50);
|
||||
patchedFile = patchedFile.replace(
|
||||
@ -268,8 +273,15 @@ document.querySelector("#giveme").addEventListener("click", () => {
|
||||
fileType = fileType[fileType.length - 1];
|
||||
|
||||
file.text().then(async (string) => {
|
||||
var patchedFile = await processClasses(string);
|
||||
patchedFile.replace(`{"._|_libserverside_|_."}`)
|
||||
var patchedFile = string;
|
||||
|
||||
if (globalThis.doEaglerforge) {
|
||||
patchedFile = await processClasses(patchedFile);
|
||||
} else if (globalThis.doShronk) {
|
||||
patchedFile = await shronk(patchedFile);
|
||||
}
|
||||
|
||||
patchedFile.replace(`{"._|_libserverside_|_."}`, "");
|
||||
var blob = new Blob([patchedFile], { type: file.type });
|
||||
saveAs(blob, "processed." + fileType);
|
||||
});
|
||||
@ -288,7 +300,14 @@ document.querySelector("#givemeserver").addEventListener("click", () => {
|
||||
fileType = fileType[fileType.length - 1];
|
||||
|
||||
file.text().then(async (string) => {
|
||||
var patchedFile = await processClasses(string);
|
||||
var patchedFile = string;
|
||||
|
||||
if (globalThis.doEaglerforge) {
|
||||
patchedFile = await processClasses(patchedFile);
|
||||
} else if (globalThis.doShronk) {
|
||||
patchedFile = await shronk(patchedFile);
|
||||
}
|
||||
|
||||
patchedFile.replace(`{"._|_libserverside_|_."}`, `(${EFServer.toString()})()`);
|
||||
var blob = new Blob([patchedFile], { type: file.type });
|
||||
saveAs(blob, "efserver." + fileType);
|
||||
|
@ -21,7 +21,7 @@ const ASYNC_PLUGIN_1 = function ({ types: t }) {
|
||||
}
|
||||
};
|
||||
};
|
||||
async function asyncify(input) {
|
||||
async function shronk(input) {
|
||||
let isHtml = true;
|
||||
let inputHtml = input;
|
||||
|
||||
@ -45,7 +45,7 @@ async function asyncify(input) {
|
||||
|
||||
|
||||
const output = Babel.transform(code, {
|
||||
plugins: [ASYNC_PLUGIN_1]
|
||||
plugins: []
|
||||
});
|
||||
scriptTag.textContent = output.code;
|
||||
}
|
19
postinit.js
19
postinit.js
@ -571,6 +571,19 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return ModAPI.hooks._teavm.$rt_suspending() || ModAPI.hooks._teavm.$rt_resuming();
|
||||
}
|
||||
|
||||
ModAPI.util.getNearestProperty = function getNearestProperty(object, prop) {
|
||||
if (!object) {
|
||||
return null;
|
||||
}
|
||||
var possibleKeys = Object.keys(object).filter(x => { return x.startsWith(prop) });
|
||||
possibleKeys = possibleKeys.filter(x => {
|
||||
return Number.isFinite(parseInt(x.substring(prop.length))) || (x.substring(prop.length).length === 0);
|
||||
})
|
||||
return possibleKeys.sort((a, b) => {
|
||||
return a.length - b.length;
|
||||
})[0] || null;
|
||||
}
|
||||
|
||||
ModAPI.clickMouse = function () {
|
||||
ModAPI.hooks.methods["nmc_Minecraft_clickMouse"](ModAPI.javaClient);
|
||||
}
|
||||
@ -750,7 +763,8 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
|
||||
// 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));
|
||||
var heightProp = ModAPI.util.getNearestProperty(args[0], "$height");
|
||||
var btn = btnConstructor(9635329, 0, args[0][heightProp] - 21, 100, 20, ModAPI.util.str(msg));
|
||||
args[0].$buttonList.$add(btn);
|
||||
|
||||
return x;
|
||||
@ -758,7 +772,8 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
|
||||
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) {
|
||||
var idProp = ModAPI.util.getNearestProperty(args[1], "$id");
|
||||
if (args[1] && args[1][idProp] === 9635329) {
|
||||
if (typeof window.modapi_displayModGui === "function") {
|
||||
window.modapi_displayModGui();
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user