From 7744d67e0416e1237c16bf0ddc0605eb5e7c1bb6 Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Sun, 2 Aug 2015 17:05:01 -0400 Subject: fix up converter some more --- src/cuchaz/enigma/ConvertMain.java | 15 ++++---- src/cuchaz/enigma/convert/MappingsConverter.java | 44 +++++++++++++++++++----- 2 files changed, 43 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java index 068fe5b..1948c84 100644 --- a/src/cuchaz/enigma/ConvertMain.java +++ b/src/cuchaz/enigma/ConvertMain.java @@ -44,19 +44,20 @@ public class ConvertMain { // init files String inVer = "1.8.3"; String outVer = "1.8.8"; + String side = "client"; File home = new File(System.getProperty("user.home")); 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"); + File inMappingsFile = new File("../Enigma Mappings/" + inVer + "-" + side + ".mappings"); + File outMappingsFile = new File("../Enigma Mappings/" + outVer + "-" + side + ".mappings"); Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); - 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"); + File classMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".class.matches"); + File fieldMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".field.matches"); + File methodMatchesFile = new File(inVer + "to" + outVer + "-" + side + ".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 @@ -67,7 +68,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/MappingsConverter.java b/src/cuchaz/enigma/convert/MappingsConverter.java index b404e8f..958a17c 100644 --- a/src/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/cuchaz/enigma/convert/MappingsConverter.java @@ -27,6 +27,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Sets; +import cuchaz.enigma.Constants; import cuchaz.enigma.Deobfuscator; import cuchaz.enigma.analysis.JarIndex; import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; @@ -208,33 +209,58 @@ public class MappingsConverter { } // migrate fields - for (FieldMapping fieldMapping : oldClassMapping.fields()) { - if (canMigrate(fieldMapping.getObfType(), replacer)) { - newClassMapping.addFieldMapping(new FieldMapping(fieldMapping, replacer)); + for (FieldMapping oldFieldMapping : oldClassMapping.fields()) { + if (canMigrate(oldFieldMapping.getObfType(), matches)) { + newClassMapping.addFieldMapping(new FieldMapping(oldFieldMapping, replacer)); + } else { + System.out.println(String.format("Can't map field, dropping: %s.%s %s", + oldClassMapping.getDeobfName(), + oldFieldMapping.getDeobfName(), + oldFieldMapping.getObfType() + )); } } // migrate methods for (MethodMapping oldMethodMapping : oldClassMapping.methods()) { - if (canMigrate(oldMethodMapping.getObfSignature(), replacer)) { + if (canMigrate(oldMethodMapping.getObfSignature(), matches)) { newClassMapping.addMethodMapping(new MethodMapping(oldMethodMapping, replacer)); + } else { + System.out.println(String.format("Can't map method, dropping: %s.%s %s", + oldClassMapping.getDeobfName(), + oldMethodMapping.getDeobfName(), + oldMethodMapping.getObfSignature() + )); } } return newClassMapping; } - private static boolean canMigrate(Signature obfSignature, ClassNameReplacer replacer) { - for (Type type : obfSignature.types()) { - if (!canMigrate(type, replacer)) { + private static boolean canMigrate(Signature oldObfSignature, ClassMatches classMatches) { + for (Type oldObfType : oldObfSignature.types()) { + if (!canMigrate(oldObfType, classMatches)) { return false; } } return true; } - private static boolean canMigrate(Type type, ClassNameReplacer replacer) { - return !type.hasClass() || replacer.replace(type.getClassEntry().getClassName()) != null; + private static boolean canMigrate(Type oldObfType, ClassMatches classMatches) { + + // non classes can be migrated + if (!oldObfType.hasClass()) { + return true; + } + + // non obfuscated classes can be migrated + ClassEntry classEntry = oldObfType.getClassEntry(); + if (!classEntry.getPackageName().equals(Constants.NonePackage)) { + return true; + } + + // obfuscated classes with mappings can be migrated + return classMatches.getUniqueMatches().containsKey(classEntry); } public static void convertMappings(Mappings mappings, BiMap changes) { -- cgit v1.2.3