From 9c793b01126a55427c8f11fc7a10621843332117 Mon Sep 17 00:00:00 2001 From: XiaoPangxie732 <47449269+XiaoPangxie732@users.noreply.github.com> Date: Tue, 29 Oct 2024 03:16:57 +0800 Subject: [PATCH] Override setLocalVariable of namespaced LVT --- .../mapping/component/LocalVariableTable.java | 10 ++++++++++ .../maxpixel/mcdecompiler/test/FunctionTest.java | 15 +++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/modules/mapping-api/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java b/modules/mapping-api/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java index 220aa83..510acfe 100644 --- a/modules/mapping-api/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java +++ b/modules/mapping-api/src/main/java/cn/maxpixel/mcdecompiler/mapping/component/LocalVariableTable.java @@ -100,6 +100,16 @@ public static class Namespaced extends LocalVariableTable imp private String mappedNamespace; private String fallbackNamespace; + @Override + public void setLocalVariable(@Range(from = 0, to = 255) int index, @Nullable("To remove the previous mapping") NamespacedMapping mapping) { + if (mapping != null) { + if (unmappedNamespace != null) mapping.setUnmappedNamespace(unmappedNamespace); + if (mappedNamespace != null) mapping.setMappedNamespace(mappedNamespace); + if (fallbackNamespace != null) mapping.setFallbackNamespace(fallbackNamespace); + } + super.setLocalVariable(index, mapping); + } + public void swapAll(@NotNull String fromNamespace, @NotNull String toNamespace, DescriptorRemapper remapper) { lvt.values().forEach(value -> value.swap(remapper, fromNamespace, toNamespace)); } diff --git a/modules/remapper/src/test/java/cn/maxpixel/mcdecompiler/test/FunctionTest.java b/modules/remapper/src/test/java/cn/maxpixel/mcdecompiler/test/FunctionTest.java index 6fb9c29..5a62ebe 100644 --- a/modules/remapper/src/test/java/cn/maxpixel/mcdecompiler/test/FunctionTest.java +++ b/modules/remapper/src/test/java/cn/maxpixel/mcdecompiler/test/FunctionTest.java @@ -28,10 +28,6 @@ import cn.maxpixel.rewh.logging.Logger; import org.jetbrains.annotations.NotNull; -import java.io.File; -import java.nio.channels.FileChannel; -import java.nio.file.Path; - public class FunctionTest { private static final Logger LOGGER = LogManager.getLogger(); @@ -88,12 +84,10 @@ public class FunctionTest { // } public static void main(String[] args) throws Throwable { - FileChannel.open(Path.of("")).size(); - new File("").length(); -// ClassifiedMapping obf2srg = MappingFormats.TSRG_V2.read(new FileInputStream("downloads/1.19.2/joined.tsrg")); +// ClassifiedMapping obf2srg = MappingFormats.TSRG_V2.read(new FileInputStream("downloads/1.19/joined.tsrg")); // obf2srg.getTrait(NamespacedTrait.class).setMappedNamespace("srg"); // obf2srg.updateCollection(); -// ClassifiedMapping official = MappingFormats.PROGUARD.read(new FileInputStream("downloads/1.19.2/client_mappings.txt")); +// ClassifiedMapping official = MappingFormats.PROGUARD.read(new FileInputStream("downloads/1.19/client_mappings.txt")); // var obf2off = new ClassifiedMappingRemapper(official); // var out = new ClassifiedMapping(); // for (ClassMapping cm : obf2srg.classes) { @@ -107,9 +101,10 @@ public static void main(String[] args) throws Throwable { // } // out.classes.add(ncm); // } -// try (var writer = Files.newBufferedWriter(FileUtil.ensureFileExist(Path.of("downloads/1.19.2/obf2srg.tsrg")))) { +// try (var writer = Files.newBufferedWriter(Path.of("downloads/1.19/obf2srg.tsrg"))) { // MappingFormats.TSRG_V1.write(out, writer); // } + // for (ClassMapping cm : obf2srg.classes) { // String obfClassName = cm.mapping.getUnmappedName(); // ClassMapping ncm = new ClassMapping<>(new PairedMapping(obf2off.mapClass(obfClassName), obf2off.mapClass(obfClassName))); @@ -122,7 +117,7 @@ public static void main(String[] args) throws Throwable { // } // out.classes.add(ncm); // } -// try (var writer = Files.newBufferedWriter(FileUtil.ensureFileExist(Path.of("downloads/1.19.2/srg2moj.tsrg")))) { +// try (var writer = Files.newBufferedWriter(Path.of("downloads/1.19/srg2moj.tsrg"))) { // MappingFormats.TSRG_V1.write(out, writer); // }