Remove some fusion stuff we dont need

This commit is contained in:
modmuss50 2018-10-22 19:35:44 +01:00
parent 8e65e6e8b6
commit 337bb1392e

View file

@ -81,7 +81,6 @@ public class ModRemapper {
TinyRemapper remapper = TinyRemapper.newRemapper()
.withMappings(TinyUtils.createTinyMappingProvider(mappings, fromM, toM))
.withRemapperExtension(new MixinRemapper())
.build();
try {
@ -106,130 +105,4 @@ public class ModRemapper {
project.getArtifacts().add("archives", deobfJar);
}
public static class MixinRemapper implements IRemapperExtension{
@Override
public byte[] handleUnmappedClass(byte[] inBytes, TinyRemapper remapper) {
//I know this isnt the fastest, but its the easiest
ClassNode classNode = readClassFromBytes(inBytes);
if(isMixin(classNode)){
String target = getMixinTarget(classNode);
System.out.println("Remapping mixin (" + classNode.name + ") targeting: " + target);
for(MethodNode methodNode : classNode.methods){
if(needsTargetMap(methodNode.visibleAnnotations)){
methodNode.visibleAnnotations.add(createTargetMap(methodNode, target, remapper));
}
}
for(FieldNode fieldNode : classNode.fields){
if(needsTargetMap(fieldNode.visibleAnnotations)){
//fieldNode.visibleAnnotations.add(createTargetMap(fieldNode));
}
}
return writeClassToBytes(classNode);
}
return inBytes;
}
private AnnotationNode createTargetMap(MethodNode methodNode, String targetClass, TinyRemapper remapper){
AnnotationNode targetMapNode = new AnnotationNode("Lme/modmuss50/fusion/api/TargetMap;");
String deobfTarget = methodNode.name + methodNode.desc;
if(getRewriteTarget(methodNode).isPresent()){
deobfTarget = getRewriteTarget(methodNode).get();
}
if(deobfTarget.equals("<init>")){
//No need to handle constructors, may need to do something about the desc but we will see
return targetMapNode;
}
String oldName = deobfTarget.substring(0, deobfTarget.indexOf("("));
String oldDesc = deobfTarget.substring(deobfTarget.lastIndexOf("("));
String newName = remapper.remapper.mapMethodName(targetClass.replaceAll("\\.", "/"), oldName, oldDesc);
String newDesc = remapper.remapper.mapDesc(oldDesc);
System.out.println(oldName + oldDesc + " -> " + newName + newDesc);
targetMapNode.visit("value", newName + newDesc);
return targetMapNode;
}
private boolean isMixin(ClassNode classNode){
if(classNode.visibleAnnotations == null){
return false;
}
for(AnnotationNode annotation : classNode.visibleAnnotations){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Mixin;")){
return true;
}
}
return false;
}
private String getMixinTarget(ClassNode classNode){
if(classNode.visibleAnnotations == null){
throw new RuntimeException(classNode.name + " is not a mixin!");
}
for(AnnotationNode annotation : classNode.visibleAnnotations){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Mixin;")){
for (int i = 0; i < annotation.values.size(); i++) {
Object value = annotation.values.get(i);
if(value instanceof String && value.toString().equals("value")){
Type target = (Type) annotation.values.get(i + 1);
return target.getClassName();
}
}
}
}
throw new RuntimeException(classNode.name + " is not a valid mixin!");
}
private Optional<String> getRewriteTarget(MethodNode methodNode){
if(methodNode.visibleAnnotations == null){
return Optional.empty();
}
for(AnnotationNode annotation : methodNode.visibleAnnotations){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Rewrite;")){
for (int i = 0; i < annotation.values.size(); i++) {
Object value = annotation.values.get(i);
if(value instanceof String && value.toString().equals("target")){
return Optional.of((String) annotation.values.get(i + 1));
}
}
}
}
return Optional.empty();
}
private boolean needsTargetMap(List<AnnotationNode> annotationNodes){
if(annotationNodes == null){
return false;
}
for(AnnotationNode annotation : annotationNodes){
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Rewrite;")){
return true;
}
if(annotation.desc.equals("Lme/modmuss50/fusion/api/Inject;")){
return true;
}
}
return false;
}
private static ClassNode readClassFromBytes(byte[] bytes) {
ClassNode classNode = new org.objectweb.asm.tree.ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
return classNode;
}
private static byte[] writeClassToBytes(ClassNode classNode) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
}
}