Updated NoReflect

This commit is contained in:
ZXMushroom63 2024-05-27 16:02:40 +08:00
parent 66706815cf
commit 05bb6bede8
2 changed files with 34 additions and 9 deletions

View File

@ -19,6 +19,7 @@ for (int i = 0; i < reflect_%classname%_methods_arr.length; i++) {
reflect_%classname%.set("constructors", reflect_%classname%_constructors_arr);
reflect_%classname%.set("methods", reflect_%classname%_methods_arr);
reflect_%classname%.set("className", "%classname%");
reflect_%classname%.set("classId", "%classid%");
reflect_%classname%.set("class", %classname%.class);
reflectProfiles.add(reflect_%classname%);
@ -50,13 +51,16 @@ const templateManager = `
import net.eaglerforge.api.*;
import java.util.ArrayList;
import java.lang.Exception;
import org.teavm.jso.JSBody;
import org.teavm.jso.JSObject;
import org.teavm.jso.JSFunctor;
//AUTOGENERATED BY NOREFLECT
//Made by ZXMushroom63
public class PLReflect {
public static ModData makeModData() {
ModData plReflectGlobal = new ModData();
public class PLReflect extends ModData {
public static PLReflect makeModData() {
PLReflect plReflectGlobal = new PLReflect();
ArrayList<BaseData> reflectProfiles = new ArrayList<BaseData>();
%classdefs%
BaseData[] reflectProfilesArr = new BaseData[reflectProfiles.size()];
@ -64,6 +68,25 @@ public class PLReflect {
reflectProfilesArr[i] = reflectProfiles.get(i);
}
plReflectGlobal.set("classes", reflectProfilesArr);
plReflectGlobal.setCallbackClassFinder("getClassByName", (String className)->{
for (int i = 0; i < reflectProfilesArr.length; i++) {
if (reflectProfilesArr[i].getString("className").equals(className)) {
return reflectProfilesArr[i];
}
}
return null;
});
plReflectGlobal.setCallbackClassFinder("getClassById", (String classId)->{
for (int i = 0; i < reflectProfilesArr.length; i++) {
if (reflectProfilesArr[i].getString("classId").equals(classId)) {
return reflectProfilesArr[i];
}
}
return null;
});
return plReflectGlobal;
}
}`;
@ -83,11 +106,12 @@ function logTxt(txt) {
}
document.querySelector("#logs").scrollTop = document.querySelector("#logs").scrollHeight;
}
function process(file, reader, classDataDump, className) {
function process(file, reader, classDataDump, className, classId) {
return new Promise((res, rej)=>{
reader.addEventListener("load", ()=>{
var output = reader.result;
classDataDump[className] = (reconJ(output, className));
classDataDump[className].classId = classId;
res(output);
});
reader.readAsText(file);
@ -110,6 +134,7 @@ function createManagerFile(managerTemplate, config, zip, dataDump, classIdMap) {
var tmpClassText = templateClassdef;
tmpClassText = tmpClassText.replaceAll("%classname%", className);
tmpClassText = tmpClassText.replaceAll("%classid%", dataDump[className].classId);
var constructorText = "";
for (let i = 0; i < dataDump[className].constructors.length; i++) {
@ -238,7 +263,7 @@ async function generate(fileList) {
classToLocationMap.set(className, classId);
if (cfg.targetFiles.includes(classId)) {
logTxt("Found "+classId+" ["+file.name+"], processing...");
var javaFileContent = await process(file, new FileReader(), classDataDump, className);
var javaFileContent = await process(file, new FileReader(), classDataDump, className, classId);
if (cfg.includeReadFiles) {
output.file(file.webkitRelativePath.replaceAll("java/", ""), javaFileContent);
}

View File

@ -65,7 +65,7 @@ function reconJ(java, className) {
}
let impl = `setCallbackReflectiveWithDataArg("${constructorName}", (BaseData params) -> {
let impl = `setCallbackReflectiveWithDataArg("exec", (BaseData params) -> {
return new ${className}(${argStr});
});
`;
@ -116,7 +116,7 @@ function reconJ(java, className) {
let prefix = isStatic ? className : `((${className}) params.getReflective("_self"))`;
let impl;
if (returnType === "void") {
impl = `setCallbackVoidWithDataArg("${methodName}", (BaseData params) -> {
impl = `setCallbackVoidWithDataArg("exec", (BaseData params) -> {
try {
${prefix}.${methodName}(${argStr});
} catch (Exception _exception_reflect_) {
@ -125,7 +125,7 @@ function reconJ(java, className) {
});
`;
} else if (callbackStatementsTypes.includes(returnType)) {
impl = `${callbackStatements[returnType]}("${methodName}", (BaseData params) -> {
impl = `${callbackStatements[returnType]}("exec", (BaseData params) -> {
try {
return (${returnType}) ${prefix}.${methodName}(${argStr});
} catch (Exception _exception_reflect_) {
@ -135,7 +135,7 @@ function reconJ(java, className) {
`;
} else {
usedClasses.push(returnType);
impl = `setCallbackReflectiveWithDataArg("${methodName}", (BaseData params) -> {
impl = `setCallbackReflectiveWithDataArg("exec", (BaseData params) -> {
try {
return (${returnType}) ${prefix}.${methodName}(${argStr});
} catch (Exception _exception_reflect_) {