summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/ConvertMain.java
blob: cad49f58a036d039cca596c667ae1a984aa08d43 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package cuchaz.enigma;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.jar.JarFile;

import cuchaz.enigma.convert.MappingsConverter;
import cuchaz.enigma.convert.Matches;
import cuchaz.enigma.convert.MatchesReader;
import cuchaz.enigma.convert.MatchesWriter;
import cuchaz.enigma.gui.MatchingGui;
import cuchaz.enigma.gui.MatchingGui.SaveListener;
import cuchaz.enigma.mapping.MappingParseException;
import cuchaz.enigma.mapping.Mappings;
import cuchaz.enigma.mapping.MappingsReader;


public class ConvertMain {

	public static void main(String[] args)
	throws IOException, MappingParseException {
		
		// init files
		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");
		Mappings mappings = new MappingsReader().read(new FileReader(inMappingsFile));
		File matchingFile = new File(inMappingsFile.getName() + ".matching");

		//computeMatches(matchingFile, sourceJar, destJar, mappings);
		editMatches(matchingFile, sourceJar, destJar, mappings);
		//convertMappings(outMappingsFile, mappings, matchingFile);
		
		/* TODO
		// write out the converted mappings
		FileWriter writer = new FileWriter(outMappingsFile);
		new MappingsWriter().write(writer, mappings);
		writer.close();
		System.out.println("Wrote converted mappings to:\n\t" + outMappingsFile.getAbsolutePath());
		*/
	}
	
	private static void computeMatches(File matchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings)
	throws IOException {
		Matches matches = MappingsConverter.computeMatches(sourceJar, destJar, mappings);
		MatchesWriter.write(matches, matchingFile);
		System.out.println("Wrote:\n\t" + matchingFile.getAbsolutePath());
	}
	
	private static void editMatches(final File matchingFile, JarFile sourceJar, JarFile destJar, Mappings mappings)
	throws IOException {
		System.out.println("Reading matches...");
		Matches matches = MatchesReader.read(matchingFile);
		System.out.println("Indexing source jar...");
		Deobfuscator sourceDeobfuscator = new Deobfuscator(sourceJar);
		sourceDeobfuscator.setMappings(mappings);
		System.out.println("Indexing dest jar...");
		Deobfuscator destDeobfuscator = new Deobfuscator(destJar);
		System.out.println("Starting GUI...");
		new MatchingGui(matches, sourceDeobfuscator, destDeobfuscator).setSaveListener(new SaveListener() {
			@Override
			public void save(Matches matches) {
				try {
					MatchesWriter.write(matches, matchingFile);
				} catch (IOException ex) {
					throw new Error(ex);
				}
			}
		});
	}
	
	private static void convertMappings(File outMappingsFile, Mappings mappings, File matchingFile)
	throws IOException {
		Matches matches = MatchesReader.read(matchingFile);
		MappingsConverter.convertMappings(mappings, matches.getUniqueMatches());
	}
}