cleanup a bit
This commit is contained in:
parent
dcf69d2e34
commit
aa187beaba
|
@ -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 {
|
||||||
|
|
|
@ -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)) {
|
|
||||||
if (!entry.getName().endsWith(".class")) {
|
|
||||||
zipOut.putNextEntry(new ZipEntry(entry.getName()));
|
|
||||||
in.transferTo(zipOut);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String className = entry.getName().substring(0, entry.getName().lastIndexOf('.'));
|
try (FileSystem inFs = FileSystems.newFileSystem(Paths.get(minecraftJar));
|
||||||
className = data.classes().getOrDefault(className, className);
|
FileSystem outFs = FileSystems.newFileSystem(out)){
|
||||||
zipOut.putNextEntry(new ZipEntry(className + ".class"));
|
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);
|
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());
|
Files.write(newClass, writer.toByteArray());
|
||||||
|
} else {
|
||||||
|
Files.copy(path, outFs.getPath(path.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue