Merge pull request #87 from eaglerforge/main

v2.7.6
This commit is contained in:
ZXMushroom63 2025-04-21 16:34:00 +08:00 committed by GitHub
commit 3b439ad097
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 255 additions and 5 deletions

View File

@ -14,7 +14,7 @@ var modapi_preinit = `globalThis.ModAPI ||= {};
`;
var freezeCallstack = `if(ModAPI.hooks.freezeCallstack){return false};`;
const EFIConfig = {
ModAPIVersion: "v2.7.4", //also change in package.json
ModAPIVersion: "v2.7.6", //also change in package.json
doEaglerforge: true,
verbose: false,
doServerExtras: false,
@ -375,9 +375,11 @@ var main;(function(){`
_status("Injecting scripts...");
await wait(50);
// 1.12 check is using nleit_MainClass, because peyton felt like renaming stuff. annoying, but useful too ig
patchedFile = patchedFile.replace(
` id="game_frame">`,
` id="game_frame">
\<script id="1_12_corelib_flag"\>ModAPI.is_1_12 = ${patchedFile.includes("nleit_MainClass_main")}\<\/script\>
\<script id="modapi_patchesreg_events"\>${assets.PatchesRegistry.getEventInjectorCode()};\<\/script\>
\<script id="modapi_postinit"\>${assets.modapi_postinit.replace("__modapi_version_code__", EFIConfig.ModAPIVersion)}\<\/script\>
\<script id="modapi_modloader"\>${assets.modapi_modloader}\<\/script\>
@ -388,6 +390,8 @@ var main;(function(){`
);
backgroundLog("[HTML] Injecting script files");
patchedFile = patchedFile.replace(`<title>EaglercraftX`, `<title>EFI ${EFIConfig.ModAPIVersion} on`);
patchedFile = patchedFile.replace(`<title>Eaglercraft`, `<title>EFI ${EFIConfig.ModAPIVersion} on`);
backgroundLog("[HTML] Injecting title");
patchedFile = patchedFile.replaceAll(/main\(\);\s*?}/gm, (match) => {
return match.replace("main();", "main();ModAPI.hooks._postInit();");

View File

@ -129,6 +129,16 @@ const modapi_postinit = "(" + (() => {
}) : args))
}
}
function easyAlias(obj, realProperty, alias) {
Object.defineProperty(obj, alias, {
get: function () {
return obj[realProperty];
},
set: function (x) {
obj[realProperty] = x;
}
});
}
ModAPI.meta.title = function (title) {
if (!document.currentScript || document.currentScript.getAttribute("data-isMod") !== "true") {
return console.log("[ModAPIMeta] Cannot set meta for non-mod script.");
@ -203,6 +213,9 @@ const modapi_postinit = "(" + (() => {
}
ModAPI.util ||= {};
ModAPI.util.getMethodFromPackage = function (classId, methodName) {
if (ModAPI.is_1_12) {
classId = classId.replace(".eaglercraft.v1_8", ".eaglercraft"); //why peyton why must you do this. you couldve changed it to v1_12 too, that would've worked
}
var name = "";
var classStuff = classId.split(".");
classStuff.forEach((component, i) => {
@ -216,6 +229,9 @@ const modapi_postinit = "(" + (() => {
return name;
}
ModAPI.util.getCompiledNameFromPackage = ModAPI.util.getCompiledName = function (classId) {
if (ModAPI.is_1_12) {
classId = classId.replace(".eaglercraft.v1_8", ".eaglercraft"); //why peyton why must you do this. you couldve changed it to v1_12 too, that would've worked
}
var name = "";
var classStuff = classId.split(".");
classStuff.forEach((component, i) => {
@ -269,6 +285,9 @@ const modapi_postinit = "(" + (() => {
return null;
}
ModAPI.array.object = function (jclass, size) {
if (typeof jclass === "string") {
jclass = ModAPI.reflect.getClassById(jclass).class;
}
if (Array.isArray(size)) {
return ModAPI.hooks._teavm.$rt_createArrayFromData(jclass, size);
}
@ -908,8 +927,16 @@ const modapi_postinit = "(" + (() => {
globalThis.Minecraft = ModAPI.mcinstance = ModAPI.javaClient = args[0];
ModAPI.settings = new Proxy(ModAPI.mcinstance.$gameSettings, TeaVM_to_Recursive_BaseData_ProxyConf);
if (ModAPI.is_1_12) {
easyAlias(ModAPI.javaClient, "$player", "$thePlayer");
easyAlias(ModAPI.javaClient, "$world", "$theWorld");
}
startModLoader();
ModAPI.hooks.methods[initMethodName] = originalInit; //unhook
return x;
};
@ -1126,6 +1153,7 @@ const modapi_postinit = "(" + (() => {
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")] = function (...args) {
if ((!inited) && (!getEaglerConfigFlag("noInitialModGui"))) {
inited = true;
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")] = originalMainMethod; //unhook
return modapi_displayModGui(globalThis.main);
} else {
return originalMainMethod.apply(this, args);

View File

@ -2,8 +2,10 @@
ModAPI.array contains the API for creating java arrays easily.
Methods:
- `ModAPI.array.object(class: Class, jsarray: object[]) : Object[]`
- `ModAPI.array.object(class: Class|String, jsarray: object[]) : Object[]`
- Converts a javascript array of a class to a java array of a class.
- The class argument can be a raw java class (eg. `ModAPI.reflect.getClassByName(...).class`)
- It can also be a string `"java.util.String"`
- `ModAPI.array.object(class: Class, size: number) : Object[]`
- Creates a java array of a class with the specified size.
- `ModAPI.array.boolean(jsarray: boolean[]) : Boolean[]`

View File

@ -1,6 +1,6 @@
(function grapplehook() {
PluginAPI.require("player"); //Require the player
var GrappleHookPlugin = {
globalThis.GrappleHookPlugin = {
oldXYZ: [0, 0, 0], //The previous hook position.
prev: "NONE", //The previous state
scaleH: 0.25, //Used for X and Z velocity
@ -31,7 +31,7 @@
if (
player.fishEntity !== undefined && //If the fish hook exists
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
player.fishEntity.inGround //And the hook is in the ground
(player.fishEntity.inGround || player.fishEntity.onGround) //And the hook is in the ground
) {
GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position
player.fishEntity.posX,

216
examplemods/winemod.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "eaglerforgeinjector",
"version": "2.7.4",
"version": "2.7.6",
"description": "Advanced modding API injector for unminified, unobfuscated, unsigned eaglercraft builds.",
"main": "node.js",
"directories": {