NOREFLECT WORKING!!!!!!!!!!!!!

This commit is contained in:
ZXMushroom63 2024-05-24 16:39:34 +08:00
parent 02b7958928
commit 66706815cf
2 changed files with 44 additions and 16 deletions

View File

@ -4,14 +4,14 @@ BaseData reflect_%classname% = new ModData();
ArrayList<BaseData> reflect_%classname%_constructors = new ArrayList<BaseData>(); ArrayList<BaseData> reflect_%classname%_constructors = new ArrayList<BaseData>();
%constructordefs% %constructordefs%
BaseData[] reflect_%classname%_constructors_arr = new BaseData[reflectProfiles.size()]; BaseData[] reflect_%classname%_constructors_arr = new BaseData[reflect_%classname%_constructors.size()];
for (int i = 0; i < reflect_%classname%_constructors_arr.length; i++) { for (int i = 0; i < reflect_%classname%_constructors_arr.length; i++) {
reflect_%classname%_constructors_arr[i] = reflect_%classname%_constructors.get(i); reflect_%classname%_constructors_arr[i] = reflect_%classname%_constructors.get(i);
} }
ArrayList<BaseData> reflect_%classname%_methods = new ArrayList<BaseData>(); ArrayList<BaseData> reflect_%classname%_methods = new ArrayList<BaseData>();
%methoddefs% %methoddefs%
BaseData[] reflect_%classname%_methods_arr = new BaseData[reflectProfiles.size()]; BaseData[] reflect_%classname%_methods_arr = new BaseData[reflect_%classname%_methods.size()];
for (int i = 0; i < reflect_%classname%_methods_arr.length; i++) { for (int i = 0; i < reflect_%classname%_methods_arr.length; i++) {
reflect_%classname%_methods_arr[i] = reflect_%classname%_methods.get(i); reflect_%classname%_methods_arr[i] = reflect_%classname%_methods.get(i);
} }
@ -31,7 +31,7 @@ BaseData reflect_%classname%_constructor_%constructorname%_%idx% = new ModData()
reflect_%classname%_constructor_%constructorname%_%idx%.set("returnType", %returntype%); reflect_%classname%_constructor_%constructorname%_%idx%.set("returnType", %returntype%);
reflect_%classname%_constructor_%constructorname%_%idx%.set("argnames", %argkeys%); reflect_%classname%_constructor_%constructorname%_%idx%.set("argnames", %argkeys%);
reflect_%classname%_constructor_%constructorname%_%idx%.set("argtypes", %argvalues%); reflect_%classname%_constructor_%constructorname%_%idx%.set("argtypes", %argvalues%);
reflect_%classname%_constructors_%idx%.%constructorimpl% reflect_%classname%_constructor_%constructorname%_%idx%.%constructorimpl%
reflect_%classname%_constructors.add(reflect_%classname%_constructor_%constructorname%_%idx%); reflect_%classname%_constructors.add(reflect_%classname%_constructor_%constructorname%_%idx%);
`; `;
@ -49,6 +49,11 @@ reflect_%classname%_methods.add(reflect_%classname%_method_%methodname%_%idx%);
const templateManager = ` const templateManager = `
import net.eaglerforge.api.*; import net.eaglerforge.api.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.lang.Exception;
//AUTOGENERATED BY NOREFLECT
//Made by ZXMushroom63
public class PLReflect { public class PLReflect {
public static ModData makeModData() { public static ModData makeModData() {
ModData plReflectGlobal = new ModData(); ModData plReflectGlobal = new ModData();
@ -209,7 +214,6 @@ async function generate(fileList) {
var classToLocationMap = new Map(); var classToLocationMap = new Map();
var cfg; var cfg;
var output = new JSZip(); var output = new JSZip();
const reader = new FileReader();
var classDataDump = {}; var classDataDump = {};
logClear(); logClear();
logTxt("[INIT] Build @ "+(new Date())); logTxt("[INIT] Build @ "+(new Date()));
@ -234,13 +238,14 @@ async function generate(fileList) {
classToLocationMap.set(className, classId); classToLocationMap.set(className, classId);
if (cfg.targetFiles.includes(classId)) { if (cfg.targetFiles.includes(classId)) {
logTxt("Found "+classId+" ["+file.name+"], processing..."); logTxt("Found "+classId+" ["+file.name+"], processing...");
var javaFileContent = await process(file, reader, classDataDump, className); var javaFileContent = await process(file, new FileReader(), classDataDump, className);
if (cfg.includeReadFiles) { if (cfg.includeReadFiles) {
output.file(file.webkitRelativePath.replaceAll("java/", ""), javaFileContent); output.file(file.webkitRelativePath.replaceAll("java/", ""), javaFileContent);
} }
} }
} }
} }
console.log(classDataDump);
logTxt(`Creating manager file...`); logTxt(`Creating manager file...`);
createManagerFile(templateManager, cfg, output, classDataDump, classToLocationMap); createManagerFile(templateManager, cfg, output, classDataDump, classToLocationMap);

View File

@ -7,6 +7,15 @@ const getStatements = {
"char": "params.getChar(%s)", "char": "params.getChar(%s)",
"double": "params.getDouble(%s)", "double": "params.getDouble(%s)",
} }
const primitiveDefaultValues = {
"int": "0",
"String": "\"\"",
"boolean": "false",
"float": "0.0f",
"byte": "(byte) 0",
"char": "\'a\'",
"double": "0.0d",
}
const callbackStatements = { const callbackStatements = {
"boolean": "setCallbackBooleanWithDataArg", "boolean": "setCallbackBooleanWithDataArg",
"int": "setCallbackIntWithDataArg", "int": "setCallbackIntWithDataArg",
@ -26,7 +35,7 @@ function reconJ(java, className) {
let constructorRegex = /(public|protected|private|static|\s) +(\w+) *\(([^)]*)\)/g; let constructorRegex = /(public|protected|private|static|\s) +(\w+) *\(([^)]*)\)/g;
let constructors = [...javaText.matchAll(constructorRegex).filter((line)=>{ let constructors = [...javaText.matchAll(constructorRegex).filter((line)=>{
return !line[0].includes(" private ") && !line[0].includes(" protected "); return !line[0].includes(" private ") && !line[0].includes(" protected ") && !line[0].includes("\n\t\t") && line[1] !== "private" && line[1] !== "protected";
})]; })];
let constructorDetails = constructors.map((constructor) => { let constructorDetails = constructors.map((constructor) => {
@ -56,7 +65,7 @@ function reconJ(java, className) {
} }
let impl = `setCallbackReflectiveWithArgs("${constructorName}", (BaseData params) -> { let impl = `setCallbackReflectiveWithDataArg("${constructorName}", (BaseData params) -> {
return new ${className}(${argStr}); return new ${className}(${argStr});
}); });
`; `;
@ -65,14 +74,15 @@ function reconJ(java, className) {
name: constructorName, name: constructorName,
idx: constructors.indexOf(constructor), idx: constructors.indexOf(constructor),
arguments: arguments, arguments: arguments,
impl: impl impl: impl,
data: constructor
}; };
}); });
let methodRegex = /(public|static|\s)* +([\w\<\>\[\]]+)\s+(\w+) *\(([^)]*)\)/g; let methodRegex = /(public|static|private|protected|\s)* +([\w\<\>\[\]]+)\s+(\w+) *\(([^)]*)\)/g;
let methods = [...javaText.matchAll(methodRegex).filter((line)=>{ let methods = [...javaText.matchAll(methodRegex).filter((line)=>{
return !line[0].includes("> ") && !line[0].startsWith(" else ") && !line[0].startsWith(" new ") && !line[0].includes(" private ") && !line[0].includes(" protected "); return !line[0].includes("> ") && !line[0].startsWith(" else ") && !line[0].startsWith(" new ") && !line[0].includes(" private ") && !line[0].includes("\tprotected ") && !line[0].includes("\tprivate ") && !line[0].includes(" protected ") && !line[0].includes("\n\t\t");
//Doesn't support Type<Subtype> yet //Doesn't support Type<Subtype> yet
})]; })];
@ -106,19 +116,31 @@ function reconJ(java, className) {
let prefix = isStatic ? className : `((${className}) params.getReflective("_self"))`; let prefix = isStatic ? className : `((${className}) params.getReflective("_self"))`;
let impl; let impl;
if (returnType === "void") { if (returnType === "void") {
impl = `setCallbackVoidWithArgs("${methodName}", (BaseData params) -> { impl = `setCallbackVoidWithDataArg("${methodName}", (BaseData params) -> {
${prefix}.${methodName}(${argStr}); try {
${prefix}.${methodName}(${argStr});
} catch (Exception _exception_reflect_) {
return;
}
}); });
`; `;
} else if (callbackStatementsTypes.includes(returnType)) { } else if (callbackStatementsTypes.includes(returnType)) {
impl = `${callbackStatements[returnType]}("${methodName}", (BaseData params) -> { impl = `${callbackStatements[returnType]}("${methodName}", (BaseData params) -> {
return (${returnType}) ${prefix}.${methodName}(${argStr}); try {
return (${returnType}) ${prefix}.${methodName}(${argStr});
} catch (Exception _exception_reflect_) {
return ${primitiveDefaultValues[returnType]};
}
}); });
`; `;
} else { } else {
usedClasses.push(returnType); usedClasses.push(returnType);
impl = `setCallbackReflectiveWithArgs("${methodName}", (BaseData params) -> { impl = `setCallbackReflectiveWithDataArg("${methodName}", (BaseData params) -> {
return (${returnType}) ${prefix}.${methodName}(${argStr}); try {
return (${returnType}) ${prefix}.${methodName}(${argStr});
} catch (Exception _exception_reflect_) {
return null;
}
}); });
`; `;
} }
@ -130,7 +152,8 @@ function reconJ(java, className) {
isStatic: isStatic, isStatic: isStatic,
arguments: arguments, arguments: arguments,
impl: impl, impl: impl,
idx: methods.indexOf(method) idx: methods.indexOf(method),
data: method
}; };
}); });
return { return {