From 4923fdfe8a01f361b76bd4c7d045184272d41ad5 Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Sun, 2 Aug 2015 15:47:27 -0400 Subject: fix up class matcher a bit --- src/cuchaz/enigma/ConvertMain.java | 20 ++++++++++-------- src/cuchaz/enigma/convert/ClassIdentity.java | 11 +++++++--- src/cuchaz/enigma/convert/MappingsConverter.java | 27 +++++++++++++++++++----- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index 17bd2f80..068fe5bf 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java @@ -42,19 +42,21 @@ public class ConvertMain { throws IOException, MappingParseException { // init files + String inVer = "1.8.3"; + String outVer = "1.8.8"; File home = new File(System.getProperty("user.home")); - JarFile sourceJar = new JarFile(new File(home, ".minecraft/versions/1.8/1.8.jar")); - JarFile destJar = new JarFile(new File(home, ".minecraft/versions/1.8.3/1.8.3.jar")); - File inMappingsFile = new File("../Enigma Mappings/1.8.mappings"); - File outMappingsFile = new File("../Enigma Mappings/1.8.3.mappings"); + JarFile sourceJar = new JarFile(new File(home, ".minecraft/versions/" + inVer + "/" + inVer + ".jar")); + JarFile destJar = new JarFile(new File(home, ".minecraft/versions/" + outVer + "/" + outVer + ".jar")); + File inMappingsFile = new File("../minecraft-mappings/" + inVer + ".mappings"); + File outMappingsFile = new File("../minecraft-mappings/" + outVer + ".mappings"); Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); - File classMatchesFile = new File(inMappingsFile.getName() + ".class.matches"); - File fieldMatchesFile = new File(inMappingsFile.getName() + ".field.matches"); - File methodMatchesFile = new File(inMappingsFile.getName() + ".method.matches"); + File classMatchesFile = new File(inVer + "to" + outVer + ".class.matches"); + File fieldMatchesFile = new File(inVer + "to" + outVer + ".field.matches"); + File methodMatchesFile = new File(inVer + "to" + outVer + ".method.matches"); // match classes //computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); - //editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); + editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); // match fields @@ -65,7 +67,7 @@ public class ConvertMain { // match methods/constructors //computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); //editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); - convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); + //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); } private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) diff --git a/src/cuchaz/enigma/convert/ClassIdentity.java b/src/cuchaz/enigma/convert/ClassIdentity.java index 2e164ae7..d9ed08ea 100644 --- a/src/cuchaz/enigma/convert/ClassIdentity.java +++ b/src/cuchaz/enigma/convert/ClassIdentity.java @@ -117,7 +117,7 @@ public class ClassIdentity { // stuff from the bytecode - m_classEntry = new ClassEntry(Descriptor.toJvmName(c.getName())); + m_classEntry = EntryFactory.getClassEntry(c); m_fields = HashMultiset.create(); for (CtField field : c.getDeclaredFields()) { m_fields.add(scrubType(field.getSignature())); @@ -180,7 +180,10 @@ public class ClassIdentity { } } - m_outer = EntryFactory.getClassEntry(c).getOuterClassName(); + m_outer = null; + if (m_classEntry.isInnerClass()) { + m_outer = m_classEntry.getOuterClassName(); + } } private void addReference(EntryReference reference) { @@ -460,7 +463,9 @@ public class ClassIdentity { } private int getNumMatches(String a, String b) { - if (a.equals(b)) { + if (a == null && b == null) { + return 1; + } else if (a != null && b != null && a.equals(b)) { return 1; } return 0; diff --git a/src/cuchaz/enigma/convert/MappingsConverter.java b/src/cuchaz/enigma/convert/MappingsConverter.java index b457d6c4..b404e8f1 100644 --- a/src/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/cuchaz/enigma/convert/MappingsConverter.java @@ -207,18 +207,35 @@ public class MappingsConverter { newClassMapping = new ClassMapping(newObfClass.getName()); } - // copy fields + // migrate fields for (FieldMapping fieldMapping : oldClassMapping.fields()) { - newClassMapping.addFieldMapping(new FieldMapping(fieldMapping, replacer)); + if (canMigrate(fieldMapping.getObfType(), replacer)) { + newClassMapping.addFieldMapping(new FieldMapping(fieldMapping, replacer)); + } } - // copy methods - for (MethodMapping methodMapping : oldClassMapping.methods()) { - newClassMapping.addMethodMapping(new MethodMapping(methodMapping, replacer)); + // migrate methods + for (MethodMapping oldMethodMapping : oldClassMapping.methods()) { + if (canMigrate(oldMethodMapping.getObfSignature(), replacer)) { + newClassMapping.addMethodMapping(new MethodMapping(oldMethodMapping, replacer)); + } } return newClassMapping; } + + private static boolean canMigrate(Signature obfSignature, ClassNameReplacer replacer) { + for (Type type : obfSignature.types()) { + if (!canMigrate(type, replacer)) { + return false; + } + } + return true; + } + + private static boolean canMigrate(Type type, ClassNameReplacer replacer) { + return !type.hasClass() || replacer.replace(type.getClassEntry().getClassName()) != null; + } public static void convertMappings(Mappings mappings, BiMap changes) { -- cgit v1.2.3