mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-23 06:01:38 -09:00
Dedicated server changes
-Fix static method detection -Add tick event (server) -Add serverstart event (server) -Add ModAPI.server (server)
This commit is contained in:
parent
fa9f50c399
commit
58b83230bd
@ -269,7 +269,7 @@ var main;(function(){`
|
||||
}
|
||||
);
|
||||
const extractInstanceMethodRegex =
|
||||
/^[\t ]*function \S+?_\S+?_\S+?\(/gm; // /^[\t ]*function \S+?_\S+?_\S+?\(\$this/gm
|
||||
/^[\t ]*function \S+?_\S+?_\S+?\((\$this)?/gm; // /^[\t ]*function \S+?_\S+?_\S+?\(\$this/gm
|
||||
const extractInstanceMethodFullNameRegex = /function (\S*?)\(/gm; // /function (\S*?)\(\$this/gm
|
||||
patchedFile = patchedFile.replaceAll(
|
||||
extractInstanceMethodRegex,
|
||||
@ -288,8 +288,8 @@ var main;(function(){`
|
||||
return ModAPI.hooks.methods[\`${fullName}\`].apply(this, args);
|
||||
}
|
||||
ModAPI.hooks._rippedMethodTypeMap[\`${fullName}\`] = \`${
|
||||
match.includes("($this")
|
||||
? "instance" //Todo: fix static/instance detection
|
||||
match.endsWith("($this")
|
||||
? "instance"
|
||||
: "static"
|
||||
}\`;
|
||||
ModAPI.hooks.methods[\`${fullName}\`]=` +
|
||||
@ -714,6 +714,28 @@ var main;(function(){`
|
||||
}
|
||||
return sendChatMessage.apply(this, [$this, ModAPI.util.str(data.message) || $message]);
|
||||
}
|
||||
|
||||
ModAPI.events.newEvent("tick");
|
||||
const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick");
|
||||
const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];
|
||||
ModAPI.hooks.methods[serverTickMethodName] = function ($this) {
|
||||
var data = { preventDefault: false }
|
||||
ModAPI.events.callEvent("tick", data);
|
||||
if (data.preventDefault) {
|
||||
return;
|
||||
}
|
||||
return serverTickMethod.apply(this, [$this]);
|
||||
}
|
||||
|
||||
ModAPI.events.newEvent("serverstart");
|
||||
const serverStartMethodName = ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.sp.server.EaglerMinecraftServer", "startServer");
|
||||
const serverStartMethod = ModAPI.hooks.methods[serverStartMethodName];
|
||||
ModAPI.hooks.methods[serverStartMethodName] = function ($this) {
|
||||
var x = serverStartMethod.apply(this, [$this]);
|
||||
ModAPI.server = ModAPI.serverInstance = new Proxy($this, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
ModAPI.events.callEvent("serverstart", {});
|
||||
return x;
|
||||
}
|
||||
})();`;
|
||||
</script>
|
||||
|
||||
|
22
postinit.js
22
postinit.js
@ -350,4 +350,26 @@
|
||||
}
|
||||
return sendChatMessage.apply(this, [$this, ModAPI.util.str(data.message) || $message]);
|
||||
}
|
||||
|
||||
ModAPI.events.newEvent("tick");
|
||||
const serverTickMethodName = ModAPI.util.getMethodFromPackage("net.minecraft.server.MinecraftServer", "tick");
|
||||
const serverTickMethod = ModAPI.hooks.methods[serverTickMethodName];
|
||||
ModAPI.hooks.methods[serverTickMethodName] = function ($this) {
|
||||
var data = { preventDefault: false }
|
||||
ModAPI.events.callEvent("tick", data);
|
||||
if (data.preventDefault) {
|
||||
return;
|
||||
}
|
||||
return serverTickMethod.apply(this, [$this]);
|
||||
}
|
||||
|
||||
ModAPI.events.newEvent("serverstart");
|
||||
const serverStartMethodName = ModAPI.util.getMethodFromPackage("net.lax1dude.eaglercraft.v1_8.sp.server.EaglerMinecraftServer", "startServer");
|
||||
const serverStartMethod = ModAPI.hooks.methods[serverStartMethodName];
|
||||
ModAPI.hooks.methods[serverStartMethodName] = function ($this) {
|
||||
var x = serverStartMethod.apply(this, [$this]);
|
||||
ModAPI.server = ModAPI.serverInstance = new Proxy($this, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||
ModAPI.events.callEvent("serverstart", {});
|
||||
return x;
|
||||
}
|
||||
})();
|
Loading…
x
Reference in New Issue
Block a user