Merge pull request #33 from ZXMushroom63/main
NoReflect method map function + other new features
This commit is contained in:
commit
42f3bf4695
|
@ -0,0 +1,41 @@
|
||||||
|
//Blink hack mod that prototype pollutes WebSocket to implement itself.
|
||||||
|
|
||||||
|
//Blinking state
|
||||||
|
var blinking = false;
|
||||||
|
|
||||||
|
//The backlog of packets that need to be sent on disable
|
||||||
|
var backlog = [];
|
||||||
|
|
||||||
|
//Store the original, actual WebSocket send method
|
||||||
|
const originalSend = WebSocket.prototype.send;
|
||||||
|
|
||||||
|
//Override WebSocket.send, so when eagler tries to send messages, it runs our code instead
|
||||||
|
Object.defineProperty(WebSocket.prototype, 'send', {
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false,
|
||||||
|
writable: false,
|
||||||
|
value: function(data) {
|
||||||
|
//If blinking, push data to backlog along with it's websocket instance.
|
||||||
|
if (blinking) {
|
||||||
|
backlog.push({data: data, thisArg: this});
|
||||||
|
} else { //Else send the data as normal
|
||||||
|
originalSend.call(this, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ModAPI.addEventListener("key", (ev)=>{
|
||||||
|
if (ev.key === 48) { //KEY_B
|
||||||
|
ev.preventDefault = true;
|
||||||
|
blinking = !blinking; //Toggle blinking boolean
|
||||||
|
|
||||||
|
if (blinking === false) { //If blink just turned off, send data.
|
||||||
|
for (let i = 0; i < backlog.length; i++) {
|
||||||
|
const backlogItem = backlog[i];
|
||||||
|
originalSend.call(backlogItem.thisArg, backlogItem.data);
|
||||||
|
}
|
||||||
|
backlog = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
|
@ -18,6 +18,15 @@ function initTracers() {
|
||||||
WorldRenderer: ModAPI.reflect.getClassByName("WorldRenderer")
|
WorldRenderer: ModAPI.reflect.getClassByName("WorldRenderer")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Build a method map object, to avoid searching for methods multiple times over.
|
||||||
|
const methodMaps = {};
|
||||||
|
var usedClasses = Object.keys(classes);
|
||||||
|
usedClasses.forEach((className)=>{
|
||||||
|
methodMaps[className] = ModAPI.reflect.getMethodMapFromClass(classes[className]);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(methodMaps);
|
||||||
|
|
||||||
//Get the vertex format for 'POSITION'
|
//Get the vertex format for 'POSITION'
|
||||||
const positionVertexFormat = ModAPI.reflect.getClassByName("VertexFormat").class.$platformClass.$$enumConstants$$().data[5];
|
const positionVertexFormat = ModAPI.reflect.getClassByName("VertexFormat").class.$platformClass.$$enumConstants$$().data[5];
|
||||||
|
|
||||||
|
@ -43,41 +52,29 @@ function initTracers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Utility functions for running methods on classes/instances of classes
|
//Utility functions for running methods on classes/instances of classes by referencing the created methodMaps object.
|
||||||
function glFunction(name, args) {
|
function glFunction(name, args) {
|
||||||
return classes.GlStateManager.methods.filter((method) => {
|
return methodMaps["GlStateManager"][name].exec(args);
|
||||||
return method.methodName === name
|
|
||||||
})[0].exec(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gpuFunction(name, args) {
|
function gpuFunction(name, args) {
|
||||||
return classes.EaglercraftGPU.methods.filter((method) => {
|
return methodMaps["EaglercraftGPU"][name].exec(args);
|
||||||
return method.methodName === name
|
|
||||||
})[0].exec(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function entityRendererFunction(name, args) {
|
function entityRendererFunction(name, args) {
|
||||||
return classes.EntityRenderer.methods.filter((method) => {
|
return methodMaps["EntityRenderer"][name].exec(args);
|
||||||
return method.methodName === name
|
|
||||||
})[0].exec(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function mathHelperFunction(name, args) {
|
function mathHelperFunction(name, args) {
|
||||||
return classes.MathHelper.methods.filter((method) => {
|
return methodMaps["MathHelper"][name].exec(args);
|
||||||
return method.methodName === name
|
|
||||||
})[0].exec(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tessellatorFunction(name, args) {
|
function tessellatorFunction(name, args) {
|
||||||
return classes.Tessellator.methods.filter((method) => {
|
return methodMaps["Tessellator"][name].exec(args);
|
||||||
return method.methodName === name
|
|
||||||
})[0].exec(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function worldRendererFunction(name, args) {
|
function worldRendererFunction(name, args) {
|
||||||
return classes.WorldRenderer.methods.filter((method) => {
|
return methodMaps["WorldRenderer"][name].exec(args);
|
||||||
return method.methodName === name
|
|
||||||
})[0].exec(args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,14 @@ import org.teavm.jso.JSFunctor;
|
||||||
//Made by ZXMushroom63
|
//Made by ZXMushroom63
|
||||||
|
|
||||||
public class PLReflect extends ModData {
|
public class PLReflect extends ModData {
|
||||||
|
@JSBody(params = { "reflectInst" }, script = "reflectInst.getMethodMapFromClass = function(classObj) {var outMethodMap = {}; classObj.methods.forEach(method=>{outMethodMap[method.methodName]=method;}); return outMethodMap;}")
|
||||||
|
public static native BaseData setMethodMapFn(BaseData reflectInst);
|
||||||
|
|
||||||
%classdefs%
|
%classdefs%
|
||||||
|
|
||||||
public static PLReflect makeModData() {
|
public static PLReflect makeModData() {
|
||||||
PLReflect plReflectGlobal = new PLReflect();
|
PLReflect plReflectGlobal = new PLReflect();
|
||||||
|
setMethodMapFn(plReflectGlobal);
|
||||||
ArrayList<BaseData> reflectProfiles = new ArrayList<BaseData>();
|
ArrayList<BaseData> reflectProfiles = new ArrayList<BaseData>();
|
||||||
|
|
||||||
%classdefcalls%
|
%classdefcalls%
|
||||||
|
|
Loading…
Reference in New Issue