Skip to content

Commit

Permalink
Merge pull request #13 from eaglerforge/main
Browse files Browse the repository at this point in the history
Update stable to latest
  • Loading branch information
ZXMushroom63 authored Sep 23, 2024
2 parents d0853bc + d872980 commit 35e31c2
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 17 deletions.
2 changes: 2 additions & 0 deletions docs/apidoc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Events broadcast data for use in mods.
- `frame`:
- Called just when a frame is rendered on the client.
- Event object is blank.


### Server Side Events
Can only be used in the context of the dedicated server. More: [DedicatedServerDocumentation](dedicatedserver.md)
- `serverstart`:
Expand Down
4 changes: 3 additions & 1 deletion docs/apidoc/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion docs/quirks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examplemods/grapplehook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions examplemods/lib.customitems.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
Expand Down
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ <h6>
>Choose .html file...</label
>
<br />
<span><code id="status">Awaiting input...</code></span>
<span><label>Minify:&nbsp;</label><input type="checkbox" oninput="globalThis.doShronk = this.checked">&nbsp;&nbsp;&nbsp;
<label>EaglerForge:&nbsp;</label><input checked type="checkbox" oninput="globalThis.doEaglerforge = this.checked">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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>
Expand Down Expand Up @@ -172,7 +174,7 @@ <h6>
`;
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 -->
Expand Down
31 changes: 25 additions & 6 deletions injector.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
globalThis.doEaglerforge = true;
function wait(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => { resolve(); }, ms);
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
});
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions injector.stepAsync.js → injector.minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,7 +45,7 @@ async function asyncify(input) {


const output = Babel.transform(code, {
plugins: [ASYNC_PLUGIN_1]
plugins: []
});
scriptTag.textContent = output.code;
}
Expand Down
19 changes: 17 additions & 2 deletions postinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -750,15 +763,17 @@ 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;
}

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 {
Expand Down

0 comments on commit 35e31c2

Please sign in to comment.