Remapper ... thing
This commit is contained in:
parent
3c0a637e7c
commit
4ae8f8c80f
|
@ -1,26 +1,56 @@
|
|||
package io.github.moehreag.mojmap_patcher;
|
||||
|
||||
import io.github.moehreag.mojmap_patcher.api.Mapper;
|
||||
import io.github.moehreag.mojmap_patcher.api.data.MappingData;
|
||||
import io.github.moehreag.mojmap_patcher.provider.MojmapProvider;
|
||||
import io.github.moehreag.mojmap_patcher.parser.ProguardParser;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.commons.ClassRemapper;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Enumeration;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
public class MojMapPatcher {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String version;
|
||||
if (args.length == 0) {
|
||||
version = "latest-release";
|
||||
} else {
|
||||
version = args[0];
|
||||
public static void main(String[] args) throws IOException {
|
||||
// temporary
|
||||
if (args.length != 3) {
|
||||
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
|
||||
return;
|
||||
}
|
||||
|
||||
String minecraftVersion = args[0];
|
||||
String minecraftJar = args[1];
|
||||
String outJar = args[2];
|
||||
|
||||
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow());
|
||||
Mapper mapper = new Mapper(data);
|
||||
|
||||
try (ZipFile zipIn = new ZipFile(minecraftJar);
|
||||
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outJar))) {
|
||||
Enumeration<? extends ZipEntry> entries = zipIn.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
ZipEntry entry = entries.nextElement();
|
||||
try (InputStream in = zipIn.getInputStream(entry)) {
|
||||
zipOut.putNextEntry(new ZipEntry(entry.getName()));
|
||||
if (!entry.getName().endsWith(".class")) {
|
||||
in.transferTo(zipOut);
|
||||
continue;
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
MojmapProvider.get(version).map(ProguardParser::read).ifPresent(s -> {
|
||||
//s.getClassFields().keySet().forEach(System.out::println);
|
||||
String mcObf = s.classes().get("net/minecraft/client/Minecraft");
|
||||
s = s.reverse();
|
||||
s.fields()
|
||||
.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getKey().owner().equals(mcObf))
|
||||
.forEach(entry -> System.out.println(entry.getKey() + " -> " + entry.getValue()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ public class Mapper extends Remapper {
|
|||
|
||||
private MappingData data;
|
||||
|
||||
public static Mapper load() {
|
||||
throw new UnsupportedOperationException("TODO");
|
||||
public Mapper(MappingData data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue