This commit is contained in:
parent
8653453644
commit
b1a30431f3
|
@ -3,7 +3,10 @@ package org.ecorous.esnesnon.mojmap_patcher;
|
||||||
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.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
import org.ecorous.esnesnon.mojmap_patcher.api.Mapper;
|
import org.ecorous.esnesnon.mojmap_patcher.api.Mapper;
|
||||||
import org.ecorous.esnesnon.mojmap_patcher.api.data.MappingData;
|
import org.ecorous.esnesnon.mojmap_patcher.api.data.MappingData;
|
||||||
|
@ -15,54 +18,72 @@ 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, InterruptedException {
|
||||||
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);
|
||||||
|
|
||||||
Files.deleteIfExists(outputJar);
|
Files.deleteIfExists(outputJar);
|
||||||
|
|
||||||
try (FileSystem inFs = FileSystems.newFileSystem(inputJar);
|
System.out.println("Remapping...");
|
||||||
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")) {
|
long startTime = System.currentTimeMillis();
|
||||||
String className = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf("."));
|
|
||||||
Path result = outFs.getPath(path.toString()).resolveSibling(data.classes().getOrDefault(className, className)+".class");
|
|
||||||
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());
|
try (ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
||||||
Files.write(newClass, writer.toByteArray());
|
FileSystem inFs = FileSystems.newFileSystem(inputJar);
|
||||||
} else {
|
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
|
||||||
Path result = outFs.getPath(path.toString()).toAbsolutePath();
|
List<Callable<Void>> tasks = new ArrayList<>();
|
||||||
Files.createDirectories(result.getParent());
|
|
||||||
Files.copy(path, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
return FileVisitResult.CONTINUE;
|
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
|
||||||
}
|
@Override
|
||||||
});
|
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
|
||||||
}
|
tasks.add(() -> {
|
||||||
}
|
try {
|
||||||
|
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");
|
||||||
|
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);
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
Files.createDirectories(result.getParent());
|
||||||
// temporary
|
Files.write(newClass, writer.toByteArray());
|
||||||
if (args.length != 3) {
|
} else {
|
||||||
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
|
Path result = outFs.getPath(path.toString()).toAbsolutePath();
|
||||||
return;
|
Files.createDirectories(result.getParent());
|
||||||
}
|
Files.copy(path, result);
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
throw new Error(ex);
|
||||||
|
}
|
||||||
|
|
||||||
String minecraftVersion = args[0];
|
return null;
|
||||||
String minecraftJar = args[1];
|
});
|
||||||
String outJar = args[2];
|
|
||||||
|
|
||||||
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
exec.invokeAll(tasks);
|
||||||
|
|
||||||
|
System.out.printf("Finished remapping (%.2fs)\n", (System.currentTimeMillis() - startTime) / 1000F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
|
// 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];
|
||||||
|
|
||||||
|
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue