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

View file

@ -1,5 +1,5 @@
#Sat Apr 27 20:33:54 CEST 2024 #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 distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

View file

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