mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-11 07:57:45 +00:00
working on the reflection stuff some more...
This commit is contained in:
11 files changed
+439
-131
No files matched your search
@@ -1,15 +1,19 @@
|
||||
package com.falsepattern.lib.reflection;
|
||||
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import com.falsepattern.lib.internal.FalsePatternLib;
|
||||
import com.falsepattern.lib.reflection.storage.Lookup;
|
||||
import com.falsepattern.lib.reflection.types.MappingType;
|
||||
import com.falsepattern.lib.reflection.types.NameType;
|
||||
import com.falsepattern.lib.reflection.types.UniversalClass;
|
||||
import com.falsepattern.lib.reflection.types.UniversalField;
|
||||
import com.falsepattern.lib.reflection.types.UniversalMethod;
|
||||
import com.falsepattern.lib.util.ResourceUtil;
|
||||
import lombok.NonNull;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.val;
|
||||
import org.objectweb.asm.tree.FieldInsnNode;
|
||||
import org.objectweb.asm.tree.MethodInsnNode;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MappingManager {
|
||||
@@ -37,31 +41,75 @@ public class MappingManager {
|
||||
val fieldMappings = ResourceUtil.getResourceStringFromJar("/fields.csv", FalsePatternLib.class).split("\n");
|
||||
for (int i = 1; i < fieldMappings.length; i++) {
|
||||
val line = fieldMappings[i].split(",");
|
||||
val field = new UniversalField(line, stringPool);
|
||||
val clazz = internalLookup.get(MappingType.Notch, line[0].substring(0, line[0].lastIndexOf('/')));
|
||||
clazz.addField(field);
|
||||
new UniversalField(clazz, line, stringPool);
|
||||
}
|
||||
}
|
||||
{
|
||||
val methodMappings = ResourceUtil.getResourceStringFromJar("/methods.csv", FalsePatternLib.class).split("\n");
|
||||
for (int i = 1; i < methodMappings.length; i++) {
|
||||
val line = methodMappings[i].split(",");
|
||||
val field = new UniversalMethod(line, stringPool);
|
||||
val clazz = internalLookup.get(MappingType.Notch, line[0].substring(0, line[0].lastIndexOf('/')));
|
||||
clazz.addMethod(field);
|
||||
new UniversalMethod(clazz, line, stringPool);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static UniversalClass classForName(@NonNull NameType nameType, @NonNull MappingType mappingType, String className) {
|
||||
public static UniversalClass classForName(NameType nameType, MappingType mappingType, String className) throws ClassNotFoundException {
|
||||
initialize();
|
||||
switch (nameType) {
|
||||
case Internal:
|
||||
return internalLookup.get(mappingType, className);
|
||||
case Regular:
|
||||
return regularLookup.get(mappingType, className);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid enum value " + nameType);
|
||||
try {
|
||||
switch (nameType) {
|
||||
case Internal:
|
||||
return internalLookup.get(mappingType, className);
|
||||
case Regular:
|
||||
return regularLookup.get(mappingType, className);
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid enum value " + nameType);
|
||||
}
|
||||
} catch (Lookup.LookupException e) {
|
||||
throw new ClassNotFoundException("Could not find class \"" + className + "\" with " + nameType.name().toLowerCase() + " name in the " + mappingType.name() + " mapping.");
|
||||
}
|
||||
}
|
||||
|
||||
public static UniversalField getField(FieldInsnNode instruction) throws ClassNotFoundException,
|
||||
NoSuchFieldException {
|
||||
if (!CoreLoadingPlugin.isObfuscated()) {
|
||||
try {
|
||||
return classForName(NameType.Internal, MappingType.MCP, instruction.owner).getField(MappingType.MCP, instruction.name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ClassNotFoundException("Could not find the class " + instruction.owner + " in the MCP mappings. Are you sure it's a Minecraft class? (we're in dev, cannot use SRG or Notch here).");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return classForName(NameType.Internal, MappingType.SRG, instruction.owner).getField(MappingType.SRG, instruction.name);
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
return classForName(NameType.Internal, MappingType.Notch, instruction.owner).getField(MappingType.Notch, instruction.name);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new ClassNotFoundException("Could not find the class " + instruction.owner + " neither in the SRG nor in the Notch mappings. Are you sure it's a Minecraft class? (we're in obf, cannot use MCP here)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static UniversalMethod getMethod(MethodInsnNode instruction)
|
||||
throws ClassNotFoundException, NoSuchMethodException {
|
||||
if (!CoreLoadingPlugin.isObfuscated()) {
|
||||
try {
|
||||
return classForName(NameType.Internal, MappingType.MCP, instruction.owner).getMethod(MappingType.MCP, instruction.name, instruction.desc);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ClassNotFoundException("Could not find the class " + instruction.owner + " in the MCP mappings. Are you sure it's a Minecraft class? (we're in dev, cannot use SRG or Notch here).");
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return classForName(NameType.Internal, MappingType.SRG, instruction.owner).getMethod(MappingType.SRG, instruction.name, instruction.desc);
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
return classForName(NameType.Internal, MappingType.Notch, instruction.owner).getMethod(MappingType.Notch, instruction.name, instruction.desc);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new ClassNotFoundException("Could not find the class " + instruction.owner + " neither in the SRG nor in the Notch mappings. Are you sure it's a Minecraft class? (we're in obf, cannot use MCP here)");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user