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,16 +1,17 @@
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 {
@ -19,26 +20,31 @@ public class MojMapPatcher {
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<>() {
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());
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.createDirectories(result.getParent());
Files.write(newClass, writer.toByteArray());
} else {
Files.copy(path, outFs.getPath(path.toString()));
Path result = outFs.getPath(path.toString()).toAbsolutePath();
Files.createDirectories(result.getParent());
Files.copy(path, result);
}
return FileVisitResult.CONTINUE;