fix what I broke

This commit is contained in:
moehreag 2024-05-13 13:16:50 +02:00
parent ff6ce3210b
commit 47ea5135d3
3 changed files with 55 additions and 49 deletions

View file

@ -1,5 +1,6 @@
plugins {
id("java")
java
`java-library`
id("io.freefair.lombok").version("8.6+")
`maven-publish`
}
@ -23,8 +24,7 @@ dependencies {
publishing {
publications {
create<MavenPublication>("maven") {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}

View file

@ -1,5 +1,5 @@
#Sat Apr 27 20:33:54 CEST 2024
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists

View file

@ -1,64 +1,70 @@
package org.ecorous.esnesnon.mojmap_patcher;
import org.ecorous.esnesnon.mojmap_patcher.api.Mapper;
import org.ecorous.esnesnon.mojmap_patcher.api.data.MappingData;
import org.ecorous.esnesnon.mojmap_patcher.provider.MojmapProvider;
import org.ecorous.esnesnon.mojmap_patcher.parser.ProguardParser;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.ClassRemapper;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Map;
import org.ecorous.esnesnon.mojmap_patcher.api.Mapper;
import org.ecorous.esnesnon.mojmap_patcher.api.data.MappingData;
import org.ecorous.esnesnon.mojmap_patcher.parser.ProguardParser;
import org.ecorous.esnesnon.mojmap_patcher.provider.MojmapProvider;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.ClassRemapper;
public class MojMapPatcher {
public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException {
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException {
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
Mapper mapper = new Mapper(data);
Mapper mapper = new Mapper(data);
if (!Files.exists(outputJar)){
Files.createFile(outputJar);
}
Files.deleteIfExists(outputJar);
try (FileSystem inFs = FileSystems.newFileSystem(inputJar);
FileSystem outFs = FileSystems.newFileSystem(outputJar)){
Files.walkFileTree(inFs.getPath(""), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
try (FileSystem inFs = FileSystems.newFileSystem(inputJar);
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
@Override
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);
System.out.println(path);
if (path.getFileName().toString().endsWith(".class")) {
String className = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf("."));
Path result = outFs.getPath(path.toString()).resolveSibling(data.classes().getOrDefault(className, className)+".class");
System.out.println("remapping: "+path);
Path newClass = result.toAbsolutePath();
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()));
}
Files.createDirectories(result.getParent());
Files.write(newClass, writer.toByteArray());
} else {
Path result = outFs.getPath(path.toString()).toAbsolutePath();
Files.createDirectories(result.getParent());
Files.copy(path, result);
}
return FileVisitResult.CONTINUE;
}
});
}
}
return FileVisitResult.CONTINUE;
}
});
}
}
public static void main(String[] args) throws IOException {
// temporary
if (args.length != 3) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
return;
}
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];
String minecraftVersion = args[0];
String minecraftJar = args[1];
String outJar = args[2];
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
}
}
}