-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
MCPMappings.java
83 lines (74 loc) · 3.11 KB
/
MCPMappings.java
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
81
82
83
package me.nallar.tickthreading.mcp;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import me.nallar.tickthreading.patcher.MethodDescription;
public class MCPMappings extends Mappings {
Map<String, String> seargeMappings = new HashMap<String, String>();
Map<MethodDescription, MethodDescription> methodMappings = new HashMap<MethodDescription, MethodDescription>();
Map<String, MethodDescription> parameterlessMethodMappings = new HashMap<String, MethodDescription>();
public MethodDescription obfuscate(Method method) {
return obfuscate(new MethodDescription(method));
}
public MethodDescription obfuscate(MethodDescription methodDescription) {
MethodDescription obfuscated = methodMappings.get(methodDescription);
if (obfuscated == null) {
obfuscated = parameterlessMethodMappings.get(methodDescription.getShortName());
}
return obfuscated;
}
public MCPMappings(File mcpDir) throws IOException {
parse(mcpDir);
}
public void parse(File mcpDir) throws IOException {
loadCsv(new File(mcpDir, "methods.csv"));
loadSrg(new File(mcpDir, "joined.srg"));
seargeMappings.clear();
}
private void loadSrg(File mappingsSrg) throws IOException {
Scanner srgScanner = new Scanner(mappingsSrg);
while (srgScanner.hasNextLine()) {
if (srgScanner.hasNext("MD:")) {
srgScanner.next();
String obfuscatedName = srgScanner.next();
String obfuscatedTypeInfo = srgScanner.next();
String seargeName = srgScanner.next();
String deobfuscatedName = seargeMappings.get(seargeName);
if (deobfuscatedName == null) {
deobfuscatedName = seargeName;
}
String deobfuscatedTypeInfo = srgScanner.next();
String obfuscatedClassName = obfuscatedName.substring(0, obfuscatedName.lastIndexOf('/')).replace('/', '.');
obfuscatedName = obfuscatedName.substring(obfuscatedName.lastIndexOf('/') + 1);
String deobfuscatedClassName = obfuscatedName.substring(0, obfuscatedName.lastIndexOf('/')).replace('/', '.');
deobfuscatedName = obfuscatedName.substring(deobfuscatedName.lastIndexOf('/') + 1);
MethodDescription deobfuscatedMethodDescription = new MethodDescription(deobfuscatedClassName, deobfuscatedName, deobfuscatedTypeInfo);
MethodDescription obfuscatedMethodDescription = new MethodDescription(obfuscatedClassName, obfuscatedName, obfuscatedTypeInfo);
methodMappings.put(deobfuscatedMethodDescription, obfuscatedMethodDescription);
parameterlessMethodMappings.put(deobfuscatedMethodDescription.getShortName(), obfuscatedMethodDescription);
} else {
srgScanner.nextLine();
}
}
}
private void loadCsv(File mappingsCsv) throws IOException {
Scanner in = new Scanner(mappingsCsv);
try {
in.useDelimiter(",");
while (in.hasNextLine()) {
String seargeName = in.next();
String name = in.next();
String side = in.next();
in.nextLine();
if (side.equals("2")) { // 2 = joined 'side'.
seargeMappings.put(seargeName, name);
}
}
} finally {
in.close();
}
}
}