summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Cuchaz2015-08-02 15:47:27 -0400
committerGravatar Cuchaz2015-08-02 15:47:27 -0400
commit4923fdfe8a01f361b76bd4c7d045184272d41ad5 (patch)
tree6692a634a597276f872d891799d60dfe4f074c53
parentMerged in mikesmiffy128/enigma/fix-unit-tests (pull request #2) (diff)
downloadenigma-fork-4923fdfe8a01f361b76bd4c7d045184272d41ad5.tar.gz
enigma-fork-4923fdfe8a01f361b76bd4c7d045184272d41ad5.tar.xz
enigma-fork-4923fdfe8a01f361b76bd4c7d045184272d41ad5.zip
fix up class matcher a bit
-rw-r--r--src/cuchaz/enigma/ConvertMain.java20
-rw-r--r--src/cuchaz/enigma/convert/ClassIdentity.java11
-rw-r--r--src/cuchaz/enigma/convert/MappingsConverter.java27
3 files changed, 41 insertions, 17 deletions
diff --git a/src/cuchaz/enigma/ConvertMain.java b/src/cuchaz/enigma/ConvertMain.java
index 17bd2f8..068fe5b 100644
--- a/src/cuchaz/enigma/ConvertMain.java
+++ b/src/cuchaz/enigma/ConvertMain.java
@@ -42,19 +42,21 @@ public class ConvertMain {
42 throws IOException, MappingParseException { 42 throws IOException, MappingParseException {
43 43
44 // init files 44 // init files
45 String inVer = "1.8.3";
46 String outVer = "1.8.8";
45 File home = new File(System.getProperty("user.home")); 47 File home = new File(System.getProperty("user.home"));
46 JarFile sourceJar = new JarFile(new File(home, ".minecraft/versions/1.8/1.8.jar")); 48 JarFile sourceJar = new JarFile(new File(home, ".minecraft/versions/" + inVer + "/" + inVer + ".jar"));
47 JarFile destJar = new JarFile(new File(home, ".minecraft/versions/1.8.3/1.8.3.jar")); 49 JarFile destJar = new JarFile(new File(home, ".minecraft/versions/" + outVer + "/" + outVer + ".jar"));
48 File inMappingsFile = new File("../Enigma Mappings/1.8.mappings"); 50 File inMappingsFile = new File("../minecraft-mappings/" + inVer + ".mappings");
49 File outMappingsFile = new File("../Enigma Mappings/1.8.3.mappings"); 51 File outMappingsFile = new File("../minecraft-mappings/" + outVer + ".mappings");
50 Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile)); 52 Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile));
51 File classMatchesFile = new File(inMappingsFile.getName() + ".class.matches"); 53 File classMatchesFile = new File(inVer + "to" + outVer + ".class.matches");
52 File fieldMatchesFile = new File(inMappingsFile.getName() + ".field.matches"); 54 File fieldMatchesFile = new File(inVer + "to" + outVer + ".field.matches");
53 File methodMatchesFile = new File(inMappingsFile.getName() + ".method.matches"); 55 File methodMatchesFile = new File(inVer + "to" + outVer + ".method.matches");
54 56
55 // match classes 57 // match classes
56 //computeClassMatches(classMatchesFile, sourceJar, destJar, mappings); 58 //computeClassMatches(classMatchesFile, sourceJar, destJar, mappings);
57 //editClasssMatches(classMatchesFile, sourceJar, destJar, mappings); 59 editClasssMatches(classMatchesFile, sourceJar, destJar, mappings);
58 //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile); 60 //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile);
59 61
60 // match fields 62 // match fields
@@ -65,7 +67,7 @@ public class ConvertMain {
65 // match methods/constructors 67 // match methods/constructors
66 //computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile); 68 //computeMethodMatches(methodMatchesFile, destJar, outMappingsFile, classMatchesFile);
67 //editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile); 69 //editMethodMatches(sourceJar, destJar, outMappingsFile, mappings, classMatchesFile, methodMatchesFile);
68 convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile); 70 //convertMappings(outMappingsFile, sourceJar, destJar, mappings, classMatchesFile, fieldMatchesFile, methodMatchesFile);
69 } 71 }
70 72
71 private static void computeClassMatches(File classMatchesFile, JarFile sourceJar, JarFile destJar, Mappings mappings) 73 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 2e164ae..d9ed08e 100644
--- a/src/cuchaz/enigma/convert/ClassIdentity.java
+++ b/src/cuchaz/enigma/convert/ClassIdentity.java
@@ -117,7 +117,7 @@ public class ClassIdentity {
117 117
118 // stuff from the bytecode 118 // stuff from the bytecode
119 119
120 m_classEntry = new ClassEntry(Descriptor.toJvmName(c.getName())); 120 m_classEntry = EntryFactory.getClassEntry(c);
121 m_fields = HashMultiset.create(); 121 m_fields = HashMultiset.create();
122 for (CtField field : c.getDeclaredFields()) { 122 for (CtField field : c.getDeclaredFields()) {
123 m_fields.add(scrubType(field.getSignature())); 123 m_fields.add(scrubType(field.getSignature()));
@@ -180,7 +180,10 @@ public class ClassIdentity {
180 } 180 }
181 } 181 }
182 182
183 m_outer = EntryFactory.getClassEntry(c).getOuterClassName(); 183 m_outer = null;
184 if (m_classEntry.isInnerClass()) {
185 m_outer = m_classEntry.getOuterClassName();
186 }
184 } 187 }
185 188
186 private void addReference(EntryReference<? extends Entry,BehaviorEntry> reference) { 189 private void addReference(EntryReference<? extends Entry,BehaviorEntry> reference) {
@@ -460,7 +463,9 @@ public class ClassIdentity {
460 } 463 }
461 464
462 private int getNumMatches(String a, String b) { 465 private int getNumMatches(String a, String b) {
463 if (a.equals(b)) { 466 if (a == null && b == null) {
467 return 1;
468 } else if (a != null && b != null && a.equals(b)) {
464 return 1; 469 return 1;
465 } 470 }
466 return 0; 471 return 0;
diff --git a/src/cuchaz/enigma/convert/MappingsConverter.java b/src/cuchaz/enigma/convert/MappingsConverter.java
index b457d6c..b404e8f 100644
--- a/src/cuchaz/enigma/convert/MappingsConverter.java
+++ b/src/cuchaz/enigma/convert/MappingsConverter.java
@@ -207,18 +207,35 @@ public class MappingsConverter {
207 newClassMapping = new ClassMapping(newObfClass.getName()); 207 newClassMapping = new ClassMapping(newObfClass.getName());
208 } 208 }
209 209
210 // copy fields 210 // migrate fields
211 for (FieldMapping fieldMapping : oldClassMapping.fields()) { 211 for (FieldMapping fieldMapping : oldClassMapping.fields()) {
212 newClassMapping.addFieldMapping(new FieldMapping(fieldMapping, replacer)); 212 if (canMigrate(fieldMapping.getObfType(), replacer)) {
213 newClassMapping.addFieldMapping(new FieldMapping(fieldMapping, replacer));
214 }
213 } 215 }
214 216
215 // copy methods 217 // migrate methods
216 for (MethodMapping methodMapping : oldClassMapping.methods()) { 218 for (MethodMapping oldMethodMapping : oldClassMapping.methods()) {
217 newClassMapping.addMethodMapping(new MethodMapping(methodMapping, replacer)); 219 if (canMigrate(oldMethodMapping.getObfSignature(), replacer)) {
220 newClassMapping.addMethodMapping(new MethodMapping(oldMethodMapping, replacer));
221 }
218 } 222 }
219 223
220 return newClassMapping; 224 return newClassMapping;
221 } 225 }
226
227 private static boolean canMigrate(Signature obfSignature, ClassNameReplacer replacer) {
228 for (Type type : obfSignature.types()) {
229 if (!canMigrate(type, replacer)) {
230 return false;
231 }
232 }
233 return true;
234 }
235
236 private static boolean canMigrate(Type type, ClassNameReplacer replacer) {
237 return !type.hasClass() || replacer.replace(type.getClassEntry().getClassName()) != null;
238 }
222 239
223 public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) { 240 public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) {
224 241