From 96fc674a0d81cc8f6df78f29b99bfbe86190f2d3 Mon Sep 17 00:00:00 2001 From: ZXMushroom63 Date: Thu, 22 Aug 2024 20:04:33 +0800 Subject: [PATCH] Add example mod --- grapplehook.js | 41 +++++++++++++++++++++++++++++++++ injector.html | 62 ++++++++++++++++++++++++++++++++------------------ postinit.js | 29 +++++++++++------------ 3 files changed, 94 insertions(+), 38 deletions(-) create mode 100644 grapplehook.js diff --git a/grapplehook.js b/grapplehook.js new file mode 100644 index 0000000..d3aa9ee --- /dev/null +++ b/grapplehook.js @@ -0,0 +1,41 @@ +PluginAPI.require("player"); //Require the player +var GrappleHookPlugin = { + oldXYZ: [0, 0, 0], //The previous hook position. + prev: "NONE", //The previous state + scaleH: 0.25, //Used for X and Z velocity + scaleV: 0.15, //((Grapple Y) minus (Player Y)) times scaleV + lift: 0.4, //Base vertical motion + crouchToCancel: true //Whether or not crouching should disable the grappling hook. +}; +PluginAPI.addEventListener("update", () => { //Every client tick + if (!PluginAPI.player.fishEntity) { //If the fish hook does not exist. + if (GrappleHookPlugin.prev === "GROUND" && (!GrappleHookPlugin.crouchToCancel || !PluginAPI.player.isSneaking.apply(PluginAPI.javaClient.$thePlayer, []))) { //If the old state was ground + GrappleHookPlugin.prev = "NONE"; //Update the state + var mx = GrappleHookPlugin.oldXYZ[0] - PluginAPI.player.posX; //Get delta X + var my = GrappleHookPlugin.oldXYZ[1] - PluginAPI.player.posY; //Get delta Y + var mz = GrappleHookPlugin.oldXYZ[2] - PluginAPI.player.posZ; //Get delta Z + mx *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale + my *= GrappleHookPlugin.scaleV; //Multiply by vertical scale + mz *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale + PluginAPI.player.motionX += mx; //Add x motion + PluginAPI.player.motionY += my + GrappleHookPlugin.lift; //Add y motion, plus base lift. + PluginAPI.player.motionZ += mz; //Add z motion + } else { + GrappleHookPlugin.prev = "NONE"; + } + } else if (GrappleHookPlugin.prev === "NONE") { //If the hook exists, but the previous state was NONE, update the state. + GrappleHookPlugin.prev = "AIR"; + } + if ( + PluginAPI.player.fishEntity !== undefined && //If the fish hook exists + GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air + PluginAPI.player.fishEntity.onGround //And the hook is in the ground + ) { + GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position + PluginAPI.player.fishEntity.posX, + PluginAPI.player.fishEntity.posY, + PluginAPI.player.fishEntity.posZ, + ]; + GrappleHookPlugin.prev = "GROUND";//Update state + } +}); \ No newline at end of file diff --git a/injector.html b/injector.html index 1f5b13e..1c65933 100644 --- a/injector.html +++ b/injector.html @@ -3,13 +3,31 @@ - EaglerForge Client Postprocessor + EaglerForge Injector + -

EaglerForge Client Postprocessor

-

Adds hooking into any TeaVM function to any uploaded Eaglercraft client. For use with NoReflect (allows for interaction of methods and classes)

-
- +

EaglerForge Injector

+

Adds ModAPI with more functionality (adds hooking into functions, exposes all classes, etc) to unminified unobfuscated EaglercraftX and Eaglercraft builds.

+
+

+ @@ -57,7 +75,7 @@ patchedFile = patchedFile.replace("\r", "").replace("var main;\n(function() {", const extractInstanceMethodRegex = /^[\t ]*function \S+?_\S+?_\S+?\(/gm; // /^[\t ]*function \S+?_\S+?_\S+?\(\$this/gm const extractInstanceMethodFullNameRegex = /function (\S*?)\(/gm; // /function (\S*?)\(\$this/gm patchedFile = patchedFile.replaceAll(extractInstanceMethodRegex, (match) => { - if (match.includes("__init_") || match.includes("__clinit_") || match.includes("_$callClinit")) { + if (match.includes("__init_") || match.includes("__clinit_") || match.includes("_$callClinit") || match.match(/_\S+?\$\S+?_/gm)) { return match; } var fullName = match.match(extractInstanceMethodFullNameRegex); @@ -77,6 +95,9 @@ patchedFile = patchedFile.replace("\r", "").replace("var main;\n(function() {", }); }); + + +