From 337bb1392ef0f9b1dfbe033e076823ed1aae7fbe Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Mon, 22 Oct 2018 19:35:44 +0100 Subject: [PATCH] Remove some fusion stuff we dont need --- .../net/fabricmc/loom/util/ModRemapper.java | 127 ------------------ 1 file changed, 127 deletions(-) diff --git a/src/main/java/net/fabricmc/loom/util/ModRemapper.java b/src/main/java/net/fabricmc/loom/util/ModRemapper.java index 80858bf..fd8b1a3 100644 --- a/src/main/java/net/fabricmc/loom/util/ModRemapper.java +++ b/src/main/java/net/fabricmc/loom/util/ModRemapper.java @@ -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("")){ - //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 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 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(); - } - - } - - }