Actually make the thing work

This commit is contained in:
TheKodeToad 2024-05-12 23:37:12 +01:00
parent 4ae8f8c80f
commit dcf69d2e34
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E
3 changed files with 12 additions and 5 deletions

View file

@ -30,6 +30,8 @@ public class MojMapPatcher {
String outJar = args[2]; String outJar = args[2];
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()); MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow());
data = data.reverse();
Mapper mapper = new Mapper(data); Mapper mapper = new Mapper(data);
try (ZipFile zipIn = new ZipFile(minecraftJar); try (ZipFile zipIn = new ZipFile(minecraftJar);
@ -38,16 +40,21 @@ public class MojMapPatcher {
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement(); ZipEntry entry = entries.nextElement();
try (InputStream in = zipIn.getInputStream(entry)) { try (InputStream in = zipIn.getInputStream(entry)) {
zipOut.putNextEntry(new ZipEntry(entry.getName()));
if (!entry.getName().endsWith(".class")) { if (!entry.getName().endsWith(".class")) {
zipOut.putNextEntry(new ZipEntry(entry.getName()));
in.transferTo(zipOut); in.transferTo(zipOut);
continue; 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(); byte[] bytes = in.readAllBytes();
ClassReader reader = new ClassReader(bytes); ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(0); ClassWriter writer = new ClassWriter(0);
reader.accept(new ClassRemapper(writer, mapper), 0); reader.accept(new ClassRemapper(writer, mapper), 0);
zipOut.write(writer.toByteArray()); zipOut.write(writer.toByteArray());
} }
} }

View file

@ -18,16 +18,16 @@ public class Mapper extends Remapper {
@Override @Override
public String map(String internalName) { public String map(String internalName) {
return data.classes().get(internalName); return data.classes().getOrDefault(internalName, internalName);
} }
@Override @Override
public String mapMethodName(String owner, String name, String descriptor) { 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 @Override
public String mapFieldName(String owner, String name, String descriptor) { 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);
} }
} }

View file

@ -18,7 +18,7 @@ public record MappingData(Map<String, String> classes, Map<Member, String> metho
Map<Member, String> fieldsReversed = new HashMap<>(); Map<Member, String> fieldsReversed = new HashMap<>();
for (Map.Entry<String, String> clazz : classes.entrySet()) 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()) { for (Map.Entry<Member, String> method : methods.entrySet()) {
methodsReversed.put( methodsReversed.put(