mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-25 07:01:20 -09:00
commit
c8d6011205
@ -59,6 +59,9 @@ Each `ReflectClass` has the following methods:
|
||||
|
||||
- `instanceOf(object: Object)`
|
||||
- Checks if the `object` is an instance of the class.
|
||||
- `getConstructorByArgs(...argumentNames) : Function`
|
||||
- Finds a constructor that matches the specified argument names. Eg:
|
||||
- `ModAPI.reflect.getClassByName("ItemStack").getConstructorByArgs("blockIn", "amount")`
|
||||
|
||||
### ReflectMethod Definition
|
||||
|
||||
|
15
docs/config.md
Normal file
15
docs/config.md
Normal file
@ -0,0 +1,15 @@
|
||||
## eaglercraftXOpts and search parameters
|
||||
|
||||
### noInitialModGui
|
||||
- `processed.html?noInitialModGui=true`
|
||||
or inside eaglercraftXOpts
|
||||
|
||||
disables the mod gui display on startup
|
||||
|
||||
|
||||
### Adding mods
|
||||
Set eaglercraftXOpts.Mods to an array of mod urls.
|
||||
|
||||
You can also use search parameters, eg:
|
||||
- `processed.html?mod=https://example.com/mod.js`
|
||||
- `processed.html?mod=https://example.com/mod.js&mod=https://example.com/mod2.js`
|
@ -10,4 +10,6 @@ EaglerForge Injector is a tool that uses regular expressions to attach itself to
|
||||
|
||||
[Modding API documentation](apidoc/index.md)
|
||||
|
||||
[Compiling the client for EaglerForgeInjector](compiling_client.md)
|
||||
[Compiling the client for EaglerForgeInjector](compiling_client.md)
|
||||
|
||||
[eaglercraftXopts and search parameters](config.md)
|
@ -38,7 +38,7 @@
|
||||
recipeInternal.push(ingredient);
|
||||
});
|
||||
|
||||
var recipeContents = recipePattern.flatMap(row => ModAPI.util.str(row));
|
||||
var recipeContents = recipePattern.map(row => ModAPI.util.str(row));
|
||||
var recipe = ModAPI.util.makeArray(ObjectClass, recipeContents.concat(recipeInternal));
|
||||
|
||||
// Define the output item as diamond_block
|
||||
|
7
examplemods/flammable_string.js
Normal file
7
examplemods/flammable_string.js
Normal file
@ -0,0 +1,7 @@
|
||||
const originalGetBurnTime = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.tileentity.TileEntityFurnace", "getItemBurnTime")];
|
||||
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.minecraft.tileentity.TileEntityFurnace", "getItemBurnTime")] = function (...args) {
|
||||
if (args[0].$item === ModAPI.items.string.getRef()) {
|
||||
return 50;
|
||||
}
|
||||
return originalGetBurnTime.apply(this, args);
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
globalThis.ModAPIVersion = "v2.4";
|
||||
globalThis.ModAPIVersion = "v2.5";
|
||||
globalThis.doEaglerforge = true;
|
||||
document.querySelector("title").innerText = `EaglerForge Injector ${ModAPIVersion}`;
|
||||
document.querySelector("h1").innerText = `EaglerForge Injector ${ModAPIVersion}`;
|
||||
@ -296,11 +296,11 @@ var main;(function(){`
|
||||
` id="game_frame">
|
||||
\<script id="modapi_patchesreg_events"\>${PatchesRegistry.getEventInjectorCode()};\<\/script\>
|
||||
\<script id="modapi_postinit"\>${globalThis.modapi_postinit.replace("__modapi_version_code__", ModAPIVersion)}\<\/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\>`
|
||||
\<script id="libserverside"\>{"._|_libserverside_|_."}\<\/script\>
|
||||
\<script id="__eaglerforgeinjector_installation_flag__"\>console.log("Thank you for using EaglerForge!");\<\/script\>`
|
||||
);
|
||||
patchedFile = patchedFile.replace(`<title>EaglercraftX 1.8</title>`, `<title>EFI ${globalThis.ModAPIVersion}</title>`);
|
||||
patchedFile = patchedFile.replaceAll(/main\(\);\s*?}/gm, (match) => {
|
||||
|
@ -130,7 +130,7 @@ globalThis.modapi_modloader = "(" + (() => {
|
||||
"[EaglerML] Adding mod to loadlist from eaglercraftXOpts: " +
|
||||
modToAdd
|
||||
);
|
||||
modsArr.push(modToAdd);
|
||||
modsArr.push("web@" + modToAdd);
|
||||
});
|
||||
}
|
||||
|
||||
|
98
postinit.js
98
postinit.js
@ -2,6 +2,9 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
//EaglerForge post initialization code.
|
||||
//This script cannot contain backticks, escape characters, or backslashes in order to inject into the dedicated server code.
|
||||
var startedModLoader = false;
|
||||
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||
var ARGUMENT_NAMES = /([^\s,]+)/g;
|
||||
|
||||
|
||||
function startModLoader() {
|
||||
if (!startedModLoader) {
|
||||
@ -34,10 +37,40 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return x;
|
||||
}
|
||||
}
|
||||
function arraysAreSame(arr1, arr2) {
|
||||
if (!arr1 || !arr2)
|
||||
return false;
|
||||
if(arr1 === arr2)
|
||||
return true;
|
||||
if (arr1.length !== arr2.length)
|
||||
return false;
|
||||
|
||||
for (var i = 0, l=arr1.length; i < l; i++) {
|
||||
if (arr1[i] instanceof Array && arr2[i] instanceof Array) {
|
||||
if (!arr1[i].equals(arr2[i]))
|
||||
return false;
|
||||
}
|
||||
else if (arr1[i] !== arr2[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function getParamNames(func) {
|
||||
var fnStr = func.toString().replace(STRIP_COMMENTS, '');
|
||||
var result = fnStr.slice(fnStr.indexOf('(') + 1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
|
||||
if (result === null)
|
||||
result = [];
|
||||
return result;
|
||||
}
|
||||
function getEaglerConfigFlag(key) {
|
||||
var searchParams = new URLSearchParams(location.search);
|
||||
return (globalThis.eaglercraftXOpts?.[key] || searchParams.get(key)) ? true : false
|
||||
}
|
||||
function easyStaticMethod(classId, methodName, autoUnpack) {
|
||||
var method = ModAPI.reflect.getClassById(classId).staticMethods[methodName].method;
|
||||
return function easyImpl(...args) {
|
||||
return method(...(autoUnpack ? args.map(x=>{
|
||||
return method(...(autoUnpack ? args.map(x => {
|
||||
if ((typeof x === "object") && (x.isModProxy === true)) {
|
||||
return x.getRef();
|
||||
}
|
||||
@ -273,6 +306,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
var classId = item?.$meta?.name || null;
|
||||
|
||||
if (!ModAPI.hooks._classMap[compiledName]) {
|
||||
var argumentCache = null;
|
||||
ModAPI.hooks._classMap[compiledName] = {
|
||||
"name": compiledName.split("_")[1],
|
||||
"id": classId,
|
||||
@ -292,7 +326,21 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
"compiledName": compiledName
|
||||
"compiledName": compiledName,
|
||||
"getConstructorByArgs": function (...argNames) {
|
||||
if (!argumentCache) {
|
||||
argumentCache = [];
|
||||
this.internalConstructors.forEach(x=>{
|
||||
argumentCache.push(getParamNames(x).slice(1).map(y => y.substring(1)));
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < argumentCache.length; i++) {
|
||||
const args = argumentCache[i];
|
||||
if (arraysAreSame(args, argNames)) {
|
||||
return this.constructors[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof item?.$meta?.superclass === "function" && item?.$meta?.superclass?.$meta) {
|
||||
@ -342,8 +390,8 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
}
|
||||
}
|
||||
});
|
||||
ModAPI.hooks._classMap[compiledName].staticVariables = makeClinitProxy(ModAPI.hooks._rippedStaticProperties[compiledName] || {}, (()=>{
|
||||
(ModAPI.hooks._rippedStaticProperties[compiledName].$callClinit ?? (()=>{}))();
|
||||
ModAPI.hooks._classMap[compiledName].staticVariables = makeClinitProxy(ModAPI.hooks._rippedStaticProperties[compiledName] || {}, (() => {
|
||||
(ModAPI.hooks._rippedStaticProperties[compiledName].$callClinit ?? (() => { }))();
|
||||
}));
|
||||
ModAPI.hooks._classMap[compiledName].staticVariableNames = Object.keys(ModAPI.hooks._classMap[compiledName].staticVariables);
|
||||
});
|
||||
@ -370,18 +418,14 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
}
|
||||
}
|
||||
|
||||
//Iteratively load the superclasses' prototype methods.
|
||||
//Make it extend the parent. Used to iteratively load the superclasses' prototype methods.
|
||||
ModAPI.reflect.prototypeStack = function prototypeStack(reflectClass, classFn) {
|
||||
var stack = [reflectClass.class.prototype];
|
||||
var currentSuperclass = reflectClass.superclass;
|
||||
while (currentSuperclass) {
|
||||
stack.push(currentSuperclass.prototype);
|
||||
currentSuperclass = currentSuperclass?.$meta?.superclass;
|
||||
}
|
||||
stack.reverse();
|
||||
stack.forEach(proto => {
|
||||
Object.assign(classFn.prototype, proto);
|
||||
});
|
||||
classFn.prototype = Object.create(reflectClass.class.prototype);
|
||||
classFn.prototype.constructor = classFn;
|
||||
classFn.$meta = {
|
||||
item: null,
|
||||
supertypes: [reflectClass.class]
|
||||
};
|
||||
}
|
||||
|
||||
var reloadDeprecationWarnings = 0;
|
||||
@ -406,7 +450,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
}
|
||||
const TeaVM_to_Recursive_BaseData_ProxyConf = {
|
||||
ownKeys(target) {
|
||||
return Reflect.ownKeys(target).flatMap(x => x.substring(1));
|
||||
return Reflect.ownKeys(target).map(x => x.substring(1));
|
||||
},
|
||||
getOwnPropertyDescriptor(target, prop) {
|
||||
return Object.getOwnPropertyDescriptor(target, "$" + prop);
|
||||
@ -797,26 +841,6 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
return sendChatMessage.apply(this, [$this, $message]);
|
||||
}
|
||||
|
||||
// ModAPI.events.newEvent("render", "client");
|
||||
// const renderMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.renderer.EntityRenderer", "renderWorldPass");
|
||||
// const renderMethod = ModAPI.hooks.methods[renderMethodName];
|
||||
// ModAPI.hooks.methods[renderMethodName] = function ($this, $int_pass, $float_partialTicks, $long_finishTimeNano) {
|
||||
// var shouldRenderHand = $this.$renderHand;
|
||||
// $this.$renderHand = 0; //Rendering the hand clears the depth bit, which we don't want to do.
|
||||
// var out = renderMethod.apply(this, [$this, $int_pass, $float_partialTicks, $long_finishTimeNano]);
|
||||
// var data = {
|
||||
// partialTicks: $float_partialTicks
|
||||
// }
|
||||
// ModAPI.events.callEvent("render", data);
|
||||
// if (shouldRenderHand) {
|
||||
// ModAPI.hooks.methods.nlevo_GlStateManager_clear(256); //GL_DEPTH_BUFFER_BIT, found in class RealOpenGLEnums
|
||||
// ModAPI.hooks.methods.nmcr_EntityRenderer_renderHand($this, $float_partialTicks, $int_pass);
|
||||
// ModAPI.hooks.methods.nmcr_EntityRenderer_renderWorldDirections($this, $float_partialTicks);
|
||||
// }
|
||||
// $this.$renderHand = shouldRenderHand;
|
||||
// return out;
|
||||
// }
|
||||
|
||||
const ScaledResolutionConstructor = ModAPI.reflect.getClassByName("ScaledResolution").constructors[0];
|
||||
ModAPI.events.newEvent("frame", "client");
|
||||
const frameMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.client.Minecraft", "runTick");
|
||||
@ -973,7 +997,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
||||
var inited = false;
|
||||
const originalMainMethod = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")];
|
||||
ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.internal.teavm.ClientMain", "_main")] = function (...args) {
|
||||
if (!inited) {
|
||||
if ((!inited) && (!getEaglerConfigFlag("noInitialModGui"))) {
|
||||
inited = true;
|
||||
return modapi_displayModGui(globalThis.main);
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user