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")
|
||||
};
|
||||
|
||||
//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'
|
||||
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) {
|
||||
return classes.GlStateManager.methods.filter((method) => {
|
||||
return method.methodName === name
|
||||
})[0].exec(args);
|
||||
return methodMaps["GlStateManager"][name].exec(args);
|
||||
}
|
||||
|
||||
function gpuFunction(name, args) {
|
||||
return classes.EaglercraftGPU.methods.filter((method) => {
|
||||
return method.methodName === name
|
||||
})[0].exec(args);
|
||||
return methodMaps["EaglercraftGPU"][name].exec(args);
|
||||
}
|
||||
|
||||
function entityRendererFunction(name, args) {
|
||||
return classes.EntityRenderer.methods.filter((method) => {
|
||||
return method.methodName === name
|
||||
})[0].exec(args);
|
||||
return methodMaps["EntityRenderer"][name].exec(args);
|
||||
}
|
||||
|
||||
function mathHelperFunction(name, args) {
|
||||
return classes.MathHelper.methods.filter((method) => {
|
||||
return method.methodName === name
|
||||
})[0].exec(args);
|
||||
return methodMaps["MathHelper"][name].exec(args);
|
||||
}
|
||||
|
||||
function tessellatorFunction(name, args) {
|
||||
return classes.Tessellator.methods.filter((method) => {
|
||||
return method.methodName === name
|
||||
})[0].exec(args);
|
||||
return methodMaps["Tessellator"][name].exec(args);
|
||||
}
|
||||
|
||||
function worldRendererFunction(name, args) {
|
||||
return classes.WorldRenderer.methods.filter((method) => {
|
||||
return method.methodName === name
|
||||
})[0].exec(args);
|
||||
return methodMaps["WorldRenderer"][name].exec(args);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -74,10 +74,14 @@ import org.teavm.jso.JSFunctor;
|
|||
//Made by ZXMushroom63
|
||||
|
||||
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%
|
||||
|
||||
public static PLReflect makeModData() {
|
||||
PLReflect plReflectGlobal = new PLReflect();
|
||||
setMethodMapFn(plReflectGlobal);
|
||||
ArrayList<BaseData> reflectProfiles = new ArrayList<BaseData>();
|
||||
|
||||
%classdefcalls%
|
||||
|
|
Loading…
Reference in New Issue