mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-25 07:01:20 -09:00
Progress on postinit
This commit is contained in:
parent
feed7e6420
commit
a031e6d5b3
@ -46,6 +46,9 @@ patchedFile = patchedFile.replace("\r", "").replace("var main;\n(function() {",
|
|||||||
ModAPI.hooks._rippedData.push(data);
|
ModAPI.hooks._rippedData.push(data);
|
||||||
/*/EaglerForge Client Patch/*/`
|
/*/EaglerForge Client Patch/*/`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
patchedFile = patchedFile.replace(` id="game_frame">`, ` id="game_frame">\<script id="modapi_postinit"\>\<\/script\>`);
|
||||||
|
|
||||||
const extractConstructorRegex = /^\s*function (\S*?)__init_\d+?\((?!\$)/gm;
|
const extractConstructorRegex = /^\s*function (\S*?)__init_\d+?\((?!\$)/gm;
|
||||||
const extractConstructorFullNameRegex = /function (\S*?)__init_[0-9]+/gm;
|
const extractConstructorFullNameRegex = /function (\S*?)__init_[0-9]+/gm;
|
||||||
patchedFile = patchedFile.replaceAll(extractConstructorRegex, (match) => {
|
patchedFile = patchedFile.replaceAll(extractConstructorRegex, (match) => {
|
||||||
@ -74,53 +77,5 @@ patchedFile = patchedFile.replace("\r", "").replace("var main;\n(function() {",
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>
|
|
||||||
(()=>{
|
|
||||||
|
|
||||||
|
|
||||||
ModAPI.hooks._classMap = {};
|
|
||||||
ModAPI.hooks._rippedConstructorKeys = Object.keys(ModAPI.hooks._rippedConstructors);
|
|
||||||
ModAPI.hooks._rippedMethodKeys = Object.keys(ModAPI.hooks._rippedMethodTypeMap);
|
|
||||||
ModAPI.hooks._rippedData.forEach(block => {block.forEach(item=>{
|
|
||||||
if (typeof item === "function") {
|
|
||||||
var compiledName = item.name;
|
|
||||||
if (!item.$meta || typeof item.$meta.name !== "string") {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var classId = item.$meta.name;
|
|
||||||
if (!ModAPI.hooks._classMap[classId]) {
|
|
||||||
ModAPI.hooks._classMap[classId] = {
|
|
||||||
"name": classId.split(".")[classId.split(".").length - 1],
|
|
||||||
"id": classId,
|
|
||||||
"binaryName": item.$meta.binaryName,
|
|
||||||
"constructors": [],
|
|
||||||
"methods": [],
|
|
||||||
"staticMethods": [],
|
|
||||||
"class": item,
|
|
||||||
"compiledName": compiledName
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (typeof item.$meta.superclass === "function" && item.$meta.superclass.$meta) {
|
|
||||||
ModAPI.hooks._classMap[classId].superclass = item.$meta.superclass.$meta.name;
|
|
||||||
}
|
|
||||||
if (item["$$constructor$$"]) {
|
|
||||||
//Class does not have any hand written constructors
|
|
||||||
//Eg: class MyClass {}
|
|
||||||
ModAPI.hooks._classMap[classId].constructors.push(item["$$constructor$$"]);
|
|
||||||
} else {
|
|
||||||
//Class has hand written constructors, we need to search in the stash
|
|
||||||
ModAPI.hooks._rippedConstructorKeys.forEach(constructor => {
|
|
||||||
if (constructor.startsWith(compiledName) && !constructor.includes("$lambda$")) {
|
|
||||||
ModAPI.hooks._classMap[classId].constructors.push(ModAPI.hooks._rippedConstructors[constructor]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
})});
|
|
||||||
|
|
||||||
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
43
postinit.js
Normal file
43
postinit.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
//EaglerForge post initialisation code.
|
||||||
|
ModAPI.hooks._classMap = {};
|
||||||
|
ModAPI.hooks._rippedConstructorKeys = Object.keys(ModAPI.hooks._rippedConstructors);
|
||||||
|
ModAPI.hooks._rippedMethodKeys = Object.keys(ModAPI.hooks._rippedMethodTypeMap);
|
||||||
|
ModAPI.hooks._rippedData.forEach(block => {
|
||||||
|
block.forEach(item => {
|
||||||
|
if (typeof item === "function") {
|
||||||
|
var compiledName = item.name;
|
||||||
|
if (!item.$meta || typeof item.$meta.name !== "string") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var classId = item.$meta.name;
|
||||||
|
if (!ModAPI.hooks._classMap[classId]) {
|
||||||
|
ModAPI.hooks._classMap[classId] = {
|
||||||
|
"name": classId.split(".")[classId.split(".").length - 1],
|
||||||
|
"id": classId,
|
||||||
|
"binaryName": item.$meta.binaryName,
|
||||||
|
"constructors": [],
|
||||||
|
"methods": [],
|
||||||
|
"staticMethods": [],
|
||||||
|
"class": item,
|
||||||
|
"compiledName": compiledName
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof item.$meta.superclass === "function" && item.$meta.superclass.$meta) {
|
||||||
|
ModAPI.hooks._classMap[classId].superclass = item.$meta.superclass.$meta.name;
|
||||||
|
}
|
||||||
|
if (item["$$constructor$$"]) {
|
||||||
|
//Class does not have any hand written constructors
|
||||||
|
//Eg: class MyClass {}
|
||||||
|
ModAPI.hooks._classMap[classId].constructors.push(item["$$constructor$$"]);
|
||||||
|
} else {
|
||||||
|
//Class has hand written constructors, we need to search in the stash
|
||||||
|
ModAPI.hooks._rippedConstructorKeys.forEach(constructor => {
|
||||||
|
if (constructor.startsWith(compiledName + "__init_") && !constructor.includes("$lambda$")) {
|
||||||
|
ModAPI.hooks._classMap[classId].constructors.push(ModAPI.hooks._rippedConstructors[constructor]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user