mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-25 07:01:20 -09:00
add get constructor by args
This commit is contained in:
parent
f2c6adaab8
commit
f46d2650d1
48
postinit.js
48
postinit.js
@ -2,6 +2,9 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
//EaglerForge post initialization code.
|
//EaglerForge post initialization code.
|
||||||
//This script cannot contain backticks, escape characters, or backslashes in order to inject into the dedicated server code.
|
//This script cannot contain backticks, escape characters, or backslashes in order to inject into the dedicated server code.
|
||||||
var startedModLoader = false;
|
var startedModLoader = false;
|
||||||
|
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
||||||
|
var ARGUMENT_NAMES = /([^\s,]+)/g;
|
||||||
|
|
||||||
|
|
||||||
function startModLoader() {
|
function startModLoader() {
|
||||||
if (!startedModLoader) {
|
if (!startedModLoader) {
|
||||||
@ -34,6 +37,32 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return x;
|
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) {
|
function getEaglerConfigFlag(key) {
|
||||||
var searchParams = new URLSearchParams(location.search);
|
var searchParams = new URLSearchParams(location.search);
|
||||||
return (globalThis.eaglercraftXOpts?.[key] || searchParams.get(key)) ? true : false
|
return (globalThis.eaglercraftXOpts?.[key] || searchParams.get(key)) ? true : false
|
||||||
@ -277,6 +306,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
var classId = item?.$meta?.name || null;
|
var classId = item?.$meta?.name || null;
|
||||||
|
|
||||||
if (!ModAPI.hooks._classMap[compiledName]) {
|
if (!ModAPI.hooks._classMap[compiledName]) {
|
||||||
|
var argumentCache = null;
|
||||||
ModAPI.hooks._classMap[compiledName] = {
|
ModAPI.hooks._classMap[compiledName] = {
|
||||||
"name": compiledName.split("_")[1],
|
"name": compiledName.split("_")[1],
|
||||||
"id": classId,
|
"id": classId,
|
||||||
@ -296,7 +326,21 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return false;
|
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) {
|
if (typeof item?.$meta?.superclass === "function" && item?.$meta?.superclass?.$meta) {
|
||||||
@ -406,7 +450,7 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
}
|
}
|
||||||
const TeaVM_to_Recursive_BaseData_ProxyConf = {
|
const TeaVM_to_Recursive_BaseData_ProxyConf = {
|
||||||
ownKeys(target) {
|
ownKeys(target) {
|
||||||
return Reflect.ownKeys(target).flatMap(x => x.substring(1));
|
return Reflect.ownKeys(target).map(x => x.substring(1));
|
||||||
},
|
},
|
||||||
getOwnPropertyDescriptor(target, prop) {
|
getOwnPropertyDescriptor(target, prop) {
|
||||||
return Object.getOwnPropertyDescriptor(target, "$" + prop);
|
return Object.getOwnPropertyDescriptor(target, "$" + prop);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user