cleanup a bit

This commit is contained in:
moehreag 2024-05-13 11:37:57 +02:00
parent dcf69d2e34
commit aa187beaba
3 changed files with 27 additions and 48 deletions

View file

@ -3,7 +3,7 @@ plugins {
id("io.freefair.lombok").version("8.6+") id("io.freefair.lombok").version("8.6+")
} }
group = "org.example" group = "org.ecorous.esnesnon"
version = "1.0-SNAPSHOT" version = "1.0-SNAPSHOT"
repositories { repositories {

View file

@ -8,13 +8,9 @@ import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter; import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.ClassRemapper; import org.objectweb.asm.commons.ClassRemapper;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.nio.file.*;
import java.util.Enumeration; import java.nio.file.attribute.BasicFileAttributes;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipOutputStream;
public class MojMapPatcher { public class MojMapPatcher {
@ -29,35 +25,36 @@ public class MojMapPatcher {
String minecraftJar = args[1]; String minecraftJar = args[1];
String outJar = args[2]; String outJar = args[2];
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()); MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
data = data.reverse();
Mapper mapper = new Mapper(data); Mapper mapper = new Mapper(data);
try (ZipFile zipIn = new ZipFile(minecraftJar); Path out = Paths.get(outJar);
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(outJar))) { if (!Files.exists(out)){
Enumeration<? extends ZipEntry> entries = zipIn.entries(); Files.createFile(out);
while (entries.hasMoreElements()) { }
ZipEntry entry = entries.nextElement();
try (InputStream in = zipIn.getInputStream(entry)) { try (FileSystem inFs = FileSystems.newFileSystem(Paths.get(minecraftJar));
if (!entry.getName().endsWith(".class")) { FileSystem outFs = FileSystems.newFileSystem(out)){
zipOut.putNextEntry(new ZipEntry(entry.getName())); Files.walkFileTree(inFs.getPath(""), new SimpleFileVisitor<>() {
in.transferTo(zipOut); @Override
continue; public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
if (path.getFileName().toString().endsWith(".class")){
Path newClass = outFs.getPath(path.toString());
byte[] bytes = Files.readAllBytes(path);
ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(0);
reader.accept(new ClassRemapper(writer, mapper), 0);
Files.write(newClass, writer.toByteArray());
} else {
Files.copy(path, outFs.getPath(path.toString()));
} }
String className = entry.getName().substring(0, entry.getName().lastIndexOf('.')); return FileVisitResult.CONTINUE;
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());
} }
} });
} }
} }
} }

View file

@ -1,18 +0,0 @@
package io.github.moehreag.mojmap_patcher.api;
public class Remapper {
private final Mapper mapper;
public Remapper(Mapper mapper) {
this.mapper = mapper;
}
public static Remapper of(Mapper mapper) {
return new Remapper(mapper);
}
public void apply() {
}
}