mirror of
https://github.com/eaglerforge/EaglerForgeInjector
synced 2025-07-24 22:51:18 -09:00
patches beginnings, corrective basedatas
This commit is contained in:
parent
9fd38d89d1
commit
e6d0aae86e
@ -1,41 +1,44 @@
|
|||||||
PluginAPI.require("player"); //Require the player
|
(function grapplehook() {
|
||||||
var GrappleHookPlugin = {
|
PluginAPI.require("player"); //Require the player
|
||||||
oldXYZ: [0, 0, 0], //The previous hook position.
|
var GrappleHookPlugin = {
|
||||||
prev: "NONE", //The previous state
|
oldXYZ: [0, 0, 0], //The previous hook position.
|
||||||
scaleH: 0.25, //Used for X and Z velocity
|
prev: "NONE", //The previous state
|
||||||
scaleV: 0.15, //((Grapple Y) minus (Player Y)) times scaleV
|
scaleH: 0.25, //Used for X and Z velocity
|
||||||
lift: 0.4, //Base vertical motion
|
scaleV: 0.15, //((Grapple Y) minus (Player Y)) times scaleV
|
||||||
crouchToCancel: true //Whether or not crouching should disable the grappling hook.
|
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.
|
var player = ModAPI.player.getCorrective(); //Gets the corrective version of the player object. This removes broken proerty suffixes. You usually don't need this, but in my case, I do.
|
||||||
if (GrappleHookPlugin.prev === "GROUND" && (!GrappleHookPlugin.crouchToCancel || !PluginAPI.player.isSneaking())) { //If the old state was ground
|
PluginAPI.addEventListener("update", () => { //Every client tick
|
||||||
GrappleHookPlugin.prev = "NONE"; //Update the state
|
if (!player.fishEntity) { //If the fish hook does not exist.
|
||||||
var mx = GrappleHookPlugin.oldXYZ[0] - PluginAPI.player.posX; //Get delta X
|
if (GrappleHookPlugin.prev === "GROUND" && (!GrappleHookPlugin.crouchToCancel || !player.isSneaking())) { //If the old state was ground
|
||||||
var my = GrappleHookPlugin.oldXYZ[1] - PluginAPI.player.posY; //Get delta Y
|
GrappleHookPlugin.prev = "NONE"; //Update the state
|
||||||
var mz = GrappleHookPlugin.oldXYZ[2] - PluginAPI.player.posZ; //Get delta Z
|
var mx = GrappleHookPlugin.oldXYZ[0] - player.posX; //Get delta X
|
||||||
mx *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale
|
var my = GrappleHookPlugin.oldXYZ[1] - player.posY; //Get delta Y
|
||||||
my *= GrappleHookPlugin.scaleV; //Multiply by vertical scale
|
var mz = GrappleHookPlugin.oldXYZ[2] - player.posZ; //Get delta Z
|
||||||
mz *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale
|
mx *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale
|
||||||
PluginAPI.player.motionX += mx; //Add x motion
|
my *= GrappleHookPlugin.scaleV; //Multiply by vertical scale
|
||||||
PluginAPI.player.motionY += my + GrappleHookPlugin.lift; //Add y motion, plus base lift.
|
mz *= GrappleHookPlugin.scaleH; //Multiply by horizontal scale
|
||||||
PluginAPI.player.motionZ += mz; //Add z motion
|
player.motionX += mx; //Add x motion
|
||||||
} else {
|
player.motionY += my + GrappleHookPlugin.lift; //Add y motion, plus base lift.
|
||||||
GrappleHookPlugin.prev = "NONE";
|
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";
|
||||||
}
|
}
|
||||||
} else if (GrappleHookPlugin.prev === "NONE") { //If the hook exists, but the previous state was NONE, update the state.
|
if (
|
||||||
GrappleHookPlugin.prev = "AIR";
|
player.fishEntity !== undefined && //If the fish hook exists
|
||||||
}
|
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
|
||||||
if (
|
player.fishEntity.inGround //And the hook is in the ground
|
||||||
PluginAPI.player.fishEntity !== undefined && //If the fish hook exists
|
) {
|
||||||
GrappleHookPlugin.prev === "AIR" && //And the hook was previously in the air
|
GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position
|
||||||
PluginAPI.player.fishEntity[PluginAPI.util.getNearestProperty(ModAPI.player.fishEntity, "inGround")] //And the hook is in the ground (the inGround property is botched with random suffixes sometimes)
|
player.fishEntity.posX,
|
||||||
) {
|
player.fishEntity.posY,
|
||||||
GrappleHookPlugin.oldXYZ = [ //Set old grapple hook position
|
player.fishEntity.posZ,
|
||||||
PluginAPI.player.fishEntity.posX,
|
];
|
||||||
PluginAPI.player.fishEntity.posY,
|
GrappleHookPlugin.prev = "GROUND";//Update state
|
||||||
PluginAPI.player.fishEntity.posZ,
|
}
|
||||||
];
|
});
|
||||||
GrappleHookPlugin.prev = "GROUND";//Update state
|
|
||||||
}
|
|
||||||
});
|
});
|
13
patches.js
Normal file
13
patches.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
class PatchesRegistry {
|
||||||
|
static patchedEventNames = []
|
||||||
|
static patchedEventNames = []
|
||||||
|
static getEventInjectorCode() {
|
||||||
|
return globalThis.modapi_specialevents = "[" + PatchesRegistry.patchedEventNames.flatMap(x=>`\`${x}\``).join(",") + "]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function addPatch(params) {
|
||||||
|
|
||||||
|
}
|
||||||
|
function addSpecialEvent(eventName) {
|
||||||
|
|
||||||
|
}
|
86
postinit.js
86
postinit.js
@ -114,26 +114,40 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
});
|
});
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
ModAPI.util.wrap = function (outputValue, target) {
|
ModAPI.util.wrap = function (outputValue, target, corrective) {
|
||||||
|
const CorrectiveArray = patchProxyConfToCorrective(ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||||
|
const CorrectiveRecursive = patchProxyConfToCorrective(ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
||||||
|
if (corrective) {
|
||||||
|
return new Proxy(outputValue.data, CorrectiveArray);
|
||||||
|
}
|
||||||
return new Proxy(outputValue.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
return new Proxy(outputValue.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||||
}
|
}
|
||||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||||
|
if (corrective) {
|
||||||
|
return new Proxy(outputValue.data, CorrectiveRecursive);
|
||||||
|
}
|
||||||
return new Proxy(outputValue, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
return new Proxy(outputValue, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||||
}
|
}
|
||||||
if (outputValue && typeof outputValue === "function" && target) {
|
if (outputValue && typeof outputValue === "function" && target) {
|
||||||
return function (...args) {
|
return function (...args) {
|
||||||
var xOut = outputValue.apply(target, args);
|
var xOut = outputValue.apply(target, args);
|
||||||
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
if (xOut && typeof xOut === "object" && Array.isArray(xOut.data) && typeof outputValue.type === "function") {
|
||||||
|
if (corrective) {
|
||||||
|
return new Proxy(outputValue.data, CorrectiveArray);
|
||||||
|
}
|
||||||
return new Proxy(xOut.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
return new Proxy(xOut.data, ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf);
|
||||||
}
|
}
|
||||||
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
if (xOut && typeof xOut === "object" && !Array.isArray(xOut)) {
|
||||||
|
if (corrective) {
|
||||||
|
return new Proxy(outputValue.data, CorrectiveRecursive);
|
||||||
|
}
|
||||||
return new Proxy(xOut, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
return new Proxy(xOut, ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf);
|
||||||
}
|
}
|
||||||
return xOut;
|
return xOut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return outputValue;
|
||||||
}
|
}
|
||||||
ModAPI.array.object = function (jclass, size) {
|
ModAPI.array.object = function (jclass, size) {
|
||||||
if (Array.isArray(size)) {
|
if (Array.isArray(size)) {
|
||||||
@ -295,61 +309,18 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return key ? ModAPI.hooks._classMap[key] : null;
|
return key ? ModAPI.hooks._classMap[key] : null;
|
||||||
}
|
}
|
||||||
var reloadDeprecationWarnings = 0;
|
var reloadDeprecationWarnings = 0;
|
||||||
const TeaVM_to_BaseData_ProxyConf = {
|
|
||||||
ownKeys(target) {
|
|
||||||
return Reflect.ownKeys(target).flatMap(x => x.substring(1));
|
|
||||||
},
|
|
||||||
getOwnPropertyDescriptor(target, prop) {
|
|
||||||
return Object.getOwnPropertyDescriptor(target, "$" + prop);
|
|
||||||
},
|
|
||||||
has(target, prop) {
|
|
||||||
return ("$" + prop) in target;
|
|
||||||
},
|
|
||||||
get(target, prop, receiver) {
|
|
||||||
if (prop === "getRef") {
|
|
||||||
return function () {
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (prop === "reload") {
|
|
||||||
return function () {
|
|
||||||
if (reloadDeprecationWarnings < 10) {
|
|
||||||
console.warn("ModAPI/PluginAPI reload() is obsolete, please stop using it in code.")
|
|
||||||
reloadDeprecationWarnings++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var outProp = "$" + prop;
|
|
||||||
var outputValue = Reflect.get(target, outProp, receiver);
|
|
||||||
if (outputValue && typeof outputValue === "object" && Array.isArray(outputValue.data) && typeof outputValue.type === "function") {
|
|
||||||
return outputValue.data;
|
|
||||||
}
|
|
||||||
if (outputValue && typeof outputValue === "function") {
|
|
||||||
return function (...args) {
|
|
||||||
return outputValue.apply(target, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return outputValue;
|
|
||||||
},
|
|
||||||
set(object, prop, value) {
|
|
||||||
var outProp = "$" + prop;
|
|
||||||
object[outProp] = value;
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const TeaVMArray_To_Recursive_BaseData_ProxyConf = {
|
const TeaVMArray_To_Recursive_BaseData_ProxyConf = {
|
||||||
get(target, prop, receiver) {
|
get(target, prop, receiver) {
|
||||||
var outputValue = Reflect.get(target, prop, receiver);
|
var outputValue = Reflect.get(target, prop, receiver);
|
||||||
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
if (outputValue && typeof outputValue === "object" && !Array.isArray(outputValue)) {
|
||||||
return new Proxy(outputValue, TeaVM_to_Recursive_BaseData_ProxyConf);
|
return ModAPI.util.wrap(outputValue, target, this._corrective);
|
||||||
}
|
}
|
||||||
if (prop === "getRef") {
|
if (prop === "getRef") {
|
||||||
return function () {
|
return function () {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return outputValue;
|
return ModAPI.util.wrap(outputValue, target, this._corrective);
|
||||||
},
|
},
|
||||||
set(object, prop, value) {
|
set(object, prop, value) {
|
||||||
object[prop] = value;
|
object[prop] = value;
|
||||||
@ -367,6 +338,16 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return ("$" + prop) in target;
|
return ("$" + prop) in target;
|
||||||
},
|
},
|
||||||
get(target, prop, receiver) {
|
get(target, prop, receiver) {
|
||||||
|
if (prop === "getCorrective") {
|
||||||
|
return function () {
|
||||||
|
return new Proxy(target, patchProxyConfToCorrective(TeaVM_to_Recursive_BaseData_ProxyConf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (prop === "isCorrective") {
|
||||||
|
return function () {
|
||||||
|
return !!this._corrective;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (prop === "getRef") {
|
if (prop === "getRef") {
|
||||||
return function () {
|
return function () {
|
||||||
return target;
|
return target;
|
||||||
@ -382,8 +363,11 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var outProp = "$" + prop;
|
var outProp = "$" + prop;
|
||||||
|
if (this._corrective) {
|
||||||
|
outProp = ModAPI.util.getNearestProperty(target, outProp);
|
||||||
|
}
|
||||||
var outputValue = Reflect.get(target, outProp, receiver);
|
var outputValue = Reflect.get(target, outProp, receiver);
|
||||||
var wrapped = ModAPI.util.wrap(outputValue, target);
|
var wrapped = ModAPI.util.wrap(outputValue, target, this._corrective);
|
||||||
if (wrapped) {
|
if (wrapped) {
|
||||||
return wrapped;
|
return wrapped;
|
||||||
}
|
}
|
||||||
@ -395,6 +379,11 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
function patchProxyConfToCorrective(conf) {
|
||||||
|
var pconf = Object.assign({}, conf);
|
||||||
|
pconf._corrective = true;
|
||||||
|
return pconf;
|
||||||
|
}
|
||||||
const StaticProps_ProxyConf = {
|
const StaticProps_ProxyConf = {
|
||||||
get(target, prop, receiver) {
|
get(target, prop, receiver) {
|
||||||
var outProp = prop;
|
var outProp = prop;
|
||||||
@ -413,7 +402,6 @@ globalThis.modapi_postinit = "(" + (() => {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
ModAPI.util.TeaVM_to_BaseData_ProxyConf = TeaVM_to_BaseData_ProxyConf;
|
|
||||||
ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf = TeaVMArray_To_Recursive_BaseData_ProxyConf;
|
ModAPI.util.TeaVMArray_To_Recursive_BaseData_ProxyConf = TeaVMArray_To_Recursive_BaseData_ProxyConf;
|
||||||
ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf = TeaVM_to_Recursive_BaseData_ProxyConf;
|
ModAPI.util.TeaVM_to_Recursive_BaseData_ProxyConf = TeaVM_to_Recursive_BaseData_ProxyConf;
|
||||||
ModAPI.util.StaticProps_ProxyConf = StaticProps_ProxyConf;
|
ModAPI.util.StaticProps_ProxyConf = StaticProps_ProxyConf;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user