Skip to content

Commit

Permalink
Dedicated server changes
Browse files Browse the repository at this point in the history
-Fix static method detection
-Add tick event (server)
-Add serverstart event (server)
-Add ModAPI.server (server)
  • Loading branch information
ZXMushroom63 committed Aug 25, 2024
1 parent fa9f50c commit 58b8323
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
28 changes: 25 additions & 3 deletions injector.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ <h4>
}
);
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,
Expand All @@ -288,8 +288,8 @@ <h4>
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}\`]=` +
Expand Down Expand Up @@ -714,6 +714,28 @@ <h4>
}
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>

Expand Down
22 changes: 22 additions & 0 deletions postinit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
})();

0 comments on commit 58b8323

Please sign in to comment.