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+")
}
group = "org.example"
group = "org.ecorous.esnesnon"
version = "1.0-SNAPSHOT"
repositories {

View file

@ -8,13 +8,9 @@ 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;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
public class MojMapPatcher {
@ -29,35 +25,36 @@ public class MojMapPatcher {
String minecraftJar = args[1];
String outJar = args[2];
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow());
data = data.reverse();
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
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)) {
if (!entry.getName().endsWith(".class")) {
zipOut.putNextEntry(new ZipEntry(entry.getName()));
in.transferTo(zipOut);
continue;
Path out = Paths.get(outJar);
if (!Files.exists(out)){
Files.createFile(out);
}
String className = entry.getName().substring(0, entry.getName().lastIndexOf('.'));
className = data.classes().getOrDefault(className, className);
zipOut.putNextEntry(new ZipEntry(className + ".class"));
try (FileSystem inFs = FileSystems.newFileSystem(Paths.get(minecraftJar));
FileSystem outFs = FileSystems.newFileSystem(out)){
Files.walkFileTree(inFs.getPath(""), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
byte[] bytes = in.readAllBytes();
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);
zipOut.write(writer.toByteArray());
}
}
Files.write(newClass, writer.toByteArray());
} else {
Files.copy(path, outFs.getPath(path.toString()));
}
return FileVisitResult.CONTINUE;
}
});
}
}
}

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() {
}
}