Finish patches registry

This commit is contained in:
ZXMushroom63 2024-10-02 14:58:37 +08:00
parent 0321c07978
commit 134967456c
4 changed files with 20 additions and 0 deletions

View File

@ -175,6 +175,7 @@
`;
var freezeCallstack = `if(ModAPI.hooks.freezeCallstack){return false};`;
</script>
<script src="patches.js"></script>
<script src="injector.minify.js"></script>
<script src="injector.js"></script>

View File

@ -276,6 +276,7 @@ var main;(function(){`
patchedFile = patchedFile.replace(
` id="game_frame">`,
` id="game_frame">
\<script id="modapi_patchesreg_events"\>${PatchesRegistry.getEventInjectorCode()}\`;\<\/script\>
\<script id="modapi_postinit"\>${globalThis.modapi_postinit}\<\/script\>
\<script id="modapi_postinitasync"\>${globalThis.modapi_postinitasync}\<\/script\>
\<script id="modapi_modloader"\>${globalThis.modapi_modloader}\<\/script\>
@ -286,6 +287,11 @@ var main;(function(){`
patchedFile = patchedFile.replaceAll(/main\(\);\s*?}/gm, (match) => {
return match.replace("main();", "main();ModAPI.hooks._postInit();");
});
_status("Applying bonus patches from patch registry...");
await wait(50);
patchedFile = PatchesRegistry.patchFile(patchedFile);
_status("Done, awaiting input...");
await wait(50);
return patchedFile;

View File

@ -4,6 +4,13 @@ class PatchesRegistry {
static getEventInjectorCode() {
return "globalThis.modapi_specialevents = [" + PatchesRegistry.patchedEventNames.flatMap(x=>`\`${x}\``).join(",") + "]"
}
static patchFile(x) {
var current = x;
PatchesRegistry.patchFns.forEach(fn => {
current = fn(current);
});
return current;
}
static addPatch(fn) {
PatchesRegistry.patchFns.push(fn);
}

View File

@ -859,4 +859,10 @@ globalThis.modapi_postinit = "(" + (() => {
return originalMainMethod.apply(this, args);
}
}
if (globalThis.modapi_specialevents && Array.isArray(globalThis.modapi_specialevents)) {
globalThis.modapi_specialevents.forEach(eventName => {
ModAPI.events.newEvent(eventName, "patcher");
});
}
}).toString() + ")();";