diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/MainFormatConverter.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/MainFormatConverter.java | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/src/main/java/cuchaz/enigma/MainFormatConverter.java b/src/main/java/cuchaz/enigma/MainFormatConverter.java deleted file mode 100644 index 4dd19ea..0000000 --- a/src/main/java/cuchaz/enigma/MainFormatConverter.java +++ /dev/null | |||
| @@ -1,113 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import com.google.common.collect.Maps; | ||
| 14 | |||
| 15 | import java.io.File; | ||
| 16 | import java.lang.reflect.Field; | ||
| 17 | import java.util.Map; | ||
| 18 | import java.util.jar.JarFile; | ||
| 19 | |||
| 20 | import cuchaz.enigma.analysis.JarClassIterator; | ||
| 21 | import cuchaz.enigma.mapping.*; | ||
| 22 | import javassist.CtClass; | ||
| 23 | import javassist.CtField; | ||
| 24 | |||
| 25 | public class MainFormatConverter { | ||
| 26 | |||
| 27 | public static void main(String[] args) | ||
| 28 | throws Exception { | ||
| 29 | |||
| 30 | System.out.println("Getting field types from jar..."); | ||
| 31 | |||
| 32 | JarFile jar = new JarFile(System.getProperty("user.home") + "/.minecraft/versions/1.8/1.8.jar"); | ||
| 33 | Map<String, Type> fieldTypes = Maps.newHashMap(); | ||
| 34 | for (CtClass c : JarClassIterator.classes(jar)) { | ||
| 35 | for (CtField field : c.getDeclaredFields()) { | ||
| 36 | FieldEntry fieldEntry = EntryFactory.getFieldEntry(field); | ||
| 37 | fieldTypes.put(getFieldKey(fieldEntry), moveClasssesOutOfDefaultPackage(fieldEntry.getType())); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | System.out.println("Reading mappings..."); | ||
| 42 | |||
| 43 | File fileMappings = new File("../Enigma Mappings/1.8.mappings"); | ||
| 44 | MappingsReader mappingsReader = new MappingsReader() { | ||
| 45 | |||
| 46 | @Override | ||
| 47 | protected FieldMapping readField(String obf, String deobf, String type) { | ||
| 48 | // assume the void type for now | ||
| 49 | return new FieldMapping(obf, new Type("V"), deobf); | ||
| 50 | } | ||
| 51 | }; | ||
| 52 | Mappings mappings = mappingsReader.read(fileMappings); | ||
| 53 | |||
| 54 | System.out.println("Updating field types..."); | ||
| 55 | |||
| 56 | for (ClassMapping classMapping : mappings.classes()) { | ||
| 57 | updateFieldsInClass(fieldTypes, classMapping); | ||
| 58 | } | ||
| 59 | |||
| 60 | System.out.println("Saving mappings..."); | ||
| 61 | |||
| 62 | new MappingsWriter().write(fileMappings, mappings); | ||
| 63 | |||
| 64 | System.out.println("Done!"); | ||
| 65 | } | ||
| 66 | |||
| 67 | private static Type moveClasssesOutOfDefaultPackage(Type type) { | ||
| 68 | return new Type(type, className -> { | ||
| 69 | ClassEntry entry = new ClassEntry(className); | ||
| 70 | if (entry.isInDefaultPackage()) { | ||
| 71 | return Constants.NONE_PACKAGE + "/" + className; | ||
| 72 | } | ||
| 73 | return null; | ||
| 74 | }); | ||
| 75 | } | ||
| 76 | |||
| 77 | private static void updateFieldsInClass(Map<String, Type> fieldTypes, ClassMapping classMapping) | ||
| 78 | throws Exception { | ||
| 79 | |||
| 80 | // update the fields | ||
| 81 | for (FieldMapping fieldMapping : classMapping.fields()) { | ||
| 82 | setFieldType(fieldTypes, classMapping, fieldMapping); | ||
| 83 | } | ||
| 84 | |||
| 85 | // recurse | ||
| 86 | for (ClassMapping innerClassMapping : classMapping.innerClasses()) { | ||
| 87 | updateFieldsInClass(fieldTypes, innerClassMapping); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | private static void setFieldType(Map<String, Type> fieldTypes, ClassMapping classMapping, FieldMapping fieldMapping) | ||
| 92 | throws Exception { | ||
| 93 | |||
| 94 | // get the new type | ||
| 95 | Type newType = fieldTypes.get(getFieldKey(classMapping, fieldMapping)); | ||
| 96 | if (newType == null) { | ||
| 97 | throw new Error("Can't find type for field: " + getFieldKey(classMapping, fieldMapping)); | ||
| 98 | } | ||
| 99 | |||
| 100 | // hack in the new field type | ||
| 101 | Field field = fieldMapping.getClass().getDeclaredField("m_obfType"); | ||
| 102 | field.setAccessible(true); | ||
| 103 | field.set(fieldMapping, newType); | ||
| 104 | } | ||
| 105 | |||
| 106 | private static Object getFieldKey(ClassMapping classMapping, FieldMapping fieldMapping) { | ||
| 107 | return classMapping.getObfSimpleName() + "." + fieldMapping.getObfName(); | ||
| 108 | } | ||
| 109 | |||
| 110 | private static String getFieldKey(FieldEntry obfFieldEntry) { | ||
| 111 | return obfFieldEntry.getClassEntry().getSimpleName() + "." + obfFieldEntry.getName(); | ||
| 112 | } | ||
| 113 | } | ||