unify mapping loader with tiny-remapper
parent
a2903acd3b
commit
170735618c
|
@ -24,8 +24,7 @@
|
|||
|
||||
package net.fabricmc.loom.mixin;
|
||||
|
||||
import cuchaz.enigma.analysis.Access;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingField;
|
||||
import org.spongepowered.asm.obfuscation.mapping.common.MappingMethod;
|
||||
import org.spongepowered.tools.obfuscation.mapping.common.MappingProvider;
|
||||
|
@ -35,26 +34,11 @@ import javax.annotation.processing.Messager;
|
|||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.nio.file.Files;
|
||||
import java.util.*;
|
||||
|
||||
public class MixinMappingProviderTiny extends MappingProvider {
|
||||
private final String from, to;
|
||||
|
||||
private static class SimpleClassMapper extends Remapper {
|
||||
final Map<String, String> classMap;
|
||||
|
||||
public SimpleClassMapper(Map<String, String> map) {
|
||||
this.classMap = map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(String typeName) {
|
||||
return classMap.get(typeName);
|
||||
}
|
||||
}
|
||||
|
||||
public MixinMappingProviderTiny(Messager messager, Filer filer, String from, String to) {
|
||||
super(messager, filer);
|
||||
this.from = from;
|
||||
|
@ -137,60 +121,19 @@ public class MixinMappingProviderTiny extends MappingProvider {
|
|||
@Override
|
||||
public void read(File input) throws IOException {
|
||||
BufferedReader reader = Files.newBufferedReader(input.toPath());
|
||||
String[] header = reader.readLine().split("\t");
|
||||
if (header.length <= 1
|
||||
|| !header[0].equals("v1")) {
|
||||
throw new IOException("Invalid mapping version!");
|
||||
}
|
||||
|
||||
List<String> headerList = Arrays.asList(removeFirst(header, 1));
|
||||
int fromIndex = headerList.indexOf(from);
|
||||
int toIndex = headerList.indexOf(to);
|
||||
|
||||
if (fromIndex < 0) throw new IOException("Could not find mapping '" + from + "'!");
|
||||
if (toIndex < 0) throw new IOException("Could not find mapping '" + to + "'!");
|
||||
|
||||
Map<String, String> obfFrom = new HashMap<>();
|
||||
Map<String, String> obfTo = new HashMap<>();
|
||||
List<String[]> linesStageTwo = new ArrayList<>();
|
||||
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] splitLine = line.split("\t");
|
||||
if (splitLine.length >= 2) {
|
||||
if ("CLASS".equals(splitLine[0])) {
|
||||
classMap.put(splitLine[1 + fromIndex], splitLine[1 + toIndex]);
|
||||
obfFrom.put(splitLine[1], splitLine[1 + fromIndex]);
|
||||
obfTo.put(splitLine[1], splitLine[1 + toIndex]);
|
||||
} else {
|
||||
linesStageTwo.add(splitLine);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SimpleClassMapper descObfFrom = new SimpleClassMapper(obfFrom);
|
||||
SimpleClassMapper descObfTo = new SimpleClassMapper(obfTo);
|
||||
|
||||
for (String[] splitLine : linesStageTwo) {
|
||||
if ("FIELD".equals(splitLine[0])) {
|
||||
String ownerFrom = obfFrom.getOrDefault(splitLine[1], splitLine[1]);
|
||||
String ownerTo = obfTo.getOrDefault(splitLine[1], splitLine[1]);
|
||||
String descFrom = descObfFrom.mapDesc(splitLine[2]);
|
||||
String descTo = descObfTo.mapDesc(splitLine[2]);
|
||||
fieldMap.put(
|
||||
new MappingField(ownerFrom, splitLine[3 + fromIndex], descFrom),
|
||||
new MappingField(ownerTo, splitLine[3 + toIndex], descTo)
|
||||
);
|
||||
} else if ("METHOD".equals(splitLine[0])) {
|
||||
String ownerFrom = obfFrom.getOrDefault(splitLine[1], splitLine[1]);
|
||||
String ownerTo = obfTo.getOrDefault(splitLine[1], splitLine[1]);
|
||||
String descFrom = descObfFrom.mapMethodDesc(splitLine[2]);
|
||||
String descTo = descObfTo.mapMethodDesc(splitLine[2]);
|
||||
methodMap.put(
|
||||
new MappingMethod(ownerFrom, splitLine[3 + fromIndex], descFrom),
|
||||
new MappingMethod(ownerTo, splitLine[3 + toIndex], descTo)
|
||||
);
|
||||
}
|
||||
}
|
||||
TinyUtils.read(reader, from, to, (classFrom, classTo) -> {
|
||||
classMap.put(classFrom, classTo);
|
||||
}, (fieldFrom, fieldTo) -> {
|
||||
fieldMap.put(
|
||||
new MappingField(fieldFrom.owner, fieldFrom.name, fieldFrom.desc),
|
||||
new MappingField(fieldTo.owner, fieldTo.name, fieldTo.desc)
|
||||
);
|
||||
}, (methodFrom, methodTo) -> {
|
||||
methodMap.put(
|
||||
new MappingMethod(methodFrom.owner, methodFrom.name, methodFrom.desc),
|
||||
new MappingMethod(methodTo.owner, methodTo.name, methodTo.desc)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue