Actually make the thing work
This commit is contained in:
parent
4ae8f8c80f
commit
dcf69d2e34
|
@ -30,6 +30,8 @@ public class MojMapPatcher {
|
|||
String outJar = args[2];
|
||||
|
||||
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow());
|
||||
data = data.reverse();
|
||||
|
||||
Mapper mapper = new Mapper(data);
|
||||
|
||||
try (ZipFile zipIn = new ZipFile(minecraftJar);
|
||||
|
@ -38,16 +40,21 @@ public class MojMapPatcher {
|
|||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
try (InputStream in = zipIn.getInputStream(entry)) {
|
||||
zipOut.putNextEntry(new ZipEntry(entry.getName()));
|
||||
if (!entry.getName().endsWith(".class")) {
|
||||
zipOut.putNextEntry(new ZipEntry(entry.getName()));
|
||||
in.transferTo(zipOut);
|
||||
continue;
|
||||
}
|
||||
|
||||
String className = entry.getName().substring(0, entry.getName().lastIndexOf('.'));
|
||||
className = data.classes().getOrDefault(className, className);
|
||||
zipOut.putNextEntry(new ZipEntry(className + ".class"));
|
||||
|
||||
byte[] bytes = in.readAllBytes();
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
ClassWriter writer = new ClassWriter(0);
|
||||
reader.accept(new ClassRemapper(writer, mapper), 0);
|
||||
|
||||
zipOut.write(writer.toByteArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,16 @@ public class Mapper extends Remapper {
|
|||
|
||||
@Override
|
||||
public String map(String internalName) {
|
||||
return data.classes().get(internalName);
|
||||
return data.classes().getOrDefault(internalName, internalName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String descriptor) {
|
||||
return data.methods().get(new Member(owner, name, descriptor));
|
||||
return data.methods().getOrDefault(new Member(owner, name, descriptor), name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFieldName(String owner, String name, String descriptor) {
|
||||
return data.fields().get(new Member(owner, name, descriptor));
|
||||
return data.fields().getOrDefault(new Member(owner, name, descriptor), name);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ public record MappingData(Map<String, String> classes, Map<Member, String> metho
|
|||
Map<Member, String> fieldsReversed = new HashMap<>();
|
||||
|
||||
for (Map.Entry<String, String> clazz : classes.entrySet())
|
||||
classesReversed.put(clazz.getValue(), clazz.getValue());
|
||||
classesReversed.put(clazz.getValue(), clazz.getKey());
|
||||
|
||||
for (Map.Entry<Member, String> method : methods.entrySet()) {
|
||||
methodsReversed.put(
|
||||
|
|
Loading…
Reference in a new issue