From e14dd35c0c9c9b7b809a13170c95618de7b424e8 Mon Sep 17 00:00:00 2001 From: CoolMineman <62723322+CoolMineman@users.noreply.github.com> Date: Fri, 30 Dec 2022 23:36:28 -0600 Subject: [PATCH] praise the lord, the remapper is actually working --- .../brachyura/fabric/J8FabricProjectTest.java | 2 +- .../fabric/LegFabricProjectTest.java | 106 ++++++++++++++++++ .../brachyura/fabric/NoMixinProjectTest.java | 2 +- buildscript/src/main/java/Buildscript.java | 4 +- .../recombobulator/Recombobulator.java | 2 +- .../remapper/RecombobulatorRemapper.java | 22 ++-- test/fabric/legfabric/.gitignore | 11 ++ .../io/github/coolcrabs/testmod/TestMod.java | 10 ++ .../coolcrabs/testmod/TestModClient.java | 13 +++ .../coolcrabs/testmod/mixin/RandomMixin.java | 21 ++++ .../resources/brachyuratestmod.mixins.json | 13 +++ .../src/main/resources/fabric.mod.json | 19 ++++ .../src/main/resources/testaw.accesswidener | 2 + 13 files changed, 213 insertions(+), 14 deletions(-) create mode 100644 brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/LegFabricProjectTest.java create mode 100644 test/fabric/legfabric/.gitignore create mode 100644 test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestMod.java create mode 100644 test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestModClient.java create mode 100644 test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/mixin/RandomMixin.java create mode 100644 test/fabric/legfabric/src/main/resources/brachyuratestmod.mixins.json create mode 100644 test/fabric/legfabric/src/main/resources/fabric.mod.json create mode 100644 test/fabric/legfabric/src/main/resources/testaw.accesswidener diff --git a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/J8FabricProjectTest.java b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/J8FabricProjectTest.java index c9e38e9b..49bb754f 100644 --- a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/J8FabricProjectTest.java +++ b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/J8FabricProjectTest.java @@ -66,7 +66,7 @@ void compile() { long s2 = System.currentTimeMillis() - s; System.out.println(s2); if (JvmUtil.CURRENT_JAVA_VERSION == 8) // TestMod.java produces different cp order in j8 and j17 - TestUtil.assertSha256(b.jar, "ad51e8ff297d02d7388ddc28f64f85bd5e960ab9120a1172ace969aa9a785835"); + TestUtil.assertSha256(b.jar, "daad101c55eaedccbe8b9650666c63f1e6a5541911c9e202aa71184a2366e4ad"); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/LegFabricProjectTest.java b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/LegFabricProjectTest.java new file mode 100644 index 00000000..3d73c2a6 --- /dev/null +++ b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/LegFabricProjectTest.java @@ -0,0 +1,106 @@ +package io.github.coolcrabs.brachyura.fabric; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.nio.file.Files; +import java.nio.file.Path; + +import org.junit.jupiter.api.Test; + +import io.github.coolcrabs.brachyura.TestUtil; +import io.github.coolcrabs.brachyura.decompiler.BrachyuraDecompiler; +import io.github.coolcrabs.brachyura.dependency.JavaJarDependency; +import io.github.coolcrabs.brachyura.fabric.FabricContext.ModDependencyCollector; +import io.github.coolcrabs.brachyura.fabric.FabricContext.ModDependencyFlag; +import io.github.coolcrabs.brachyura.mappings.Namespaces; +import io.github.coolcrabs.brachyura.maven.Maven; +import io.github.coolcrabs.brachyura.maven.MavenId; +import io.github.coolcrabs.brachyura.minecraft.Minecraft; +import io.github.coolcrabs.brachyura.minecraft.VersionMeta; +import io.github.coolcrabs.brachyura.util.JvmUtil; +import net.fabricmc.mappingio.tree.MappingTree; +import net.fabricmc.mappingio.tree.MemoryMappingTree; + +public class LegFabricProjectTest { + + SimpleFabricProject fabricProject = new SimpleFabricProject() { + static final String LEG_FABRIC_MAVEN = "https://repo.legacyfabric.net/repository/legacyfabric/"; + + @Override + public VersionMeta createMcVersion() { + return Minecraft.getVersion("1.8.9"); + } + + @Override + protected FabricContext createContext() { + return new SimpleFabricContext() { + @Override + protected MappingTree createIntermediary() { + MappingTree tree = Intermediary.ofMaven(LEG_FABRIC_MAVEN, new MavenId("net.legacyfabric", "intermediary", "1.8.9")).tree; + return tree; + }; + }; + }; + + @Override + public MappingTree createMappings() { + MappingTree tree = Yarn.ofMaven(LEG_FABRIC_MAVEN, new MavenId("net.legacyfabric:yarn:1.8.9+build.451")).tree; + tree.getClass("net/minecraft/world/chunk/ServerChunkProvider", tree.getNamespaceId(Namespaces.NAMED)).getMethod("method_3864", "(II)Z", tree.getNamespaceId(Namespaces.INTERMEDIARY)).setDstName("chunkExists", tree.getNamespaceId(Namespaces.NAMED)); + return tree; + } + + @Override + public FabricLoader getLoader() { + return new FabricLoader(FabricMaven.URL, FabricMaven.loader("0.12.5")); + } + + @Override + public Path getProjectDir() { + Path result = TestUtil.ROOT.resolve("test").resolve("fabric").resolve("legfabric"); + assertTrue(Files.isDirectory(result)); + return result; + } + + @Override + public void getModDependencies(ModDependencyCollector d) { + }; + + @Override + public BrachyuraDecompiler decompiler() { + return null; + }; + }; + + @Test + void compile() { + try { + long s = System.currentTimeMillis(); + JavaJarDependency b = fabricProject.build(); + long s2 = System.currentTimeMillis() - s; + System.out.println(s2); + if (JvmUtil.CURRENT_JAVA_VERSION == 8) // TestMod.java produces different cp order in j8 and j17 + TestUtil.assertSha256(b.jar, "09b408c35e71afd037d9eefae98bdb8b5bc64320989b798dad4aa5b96594c52d"); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + void ide() { + long a = System.currentTimeMillis(); + //Todo better api for this? + fabricProject.getTasks(p -> { + try { + if (p.name.equals("netbeans")) p.doTask(new String[]{}); + if (p.name.equals("idea")) p.doTask(new String[]{}); + if (p.name.equals("jdt")) p.doTask(new String[]{}); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + }); + long b = System.currentTimeMillis(); + System.out.println(b - a); + } +} diff --git a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java index bc38a170..8c51c747 100644 --- a/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java +++ b/brachyura-minecraft/src/test/java/io/github/coolcrabs/brachyura/fabric/NoMixinProjectTest.java @@ -58,7 +58,7 @@ void compile() { long s2 = System.currentTimeMillis() - s; System.out.println(s2); if (JvmUtil.CURRENT_JAVA_VERSION == 8) - TestUtil.assertSha256(b.jar, "28752bdbdc185ee2629ccb79667737ca08bdcb3fef679fceac61564350689b69"); + TestUtil.assertSha256(b.jar, "680f6122e8ef0a9f8f42f14189d7ca7e2c0bf252674af89614c5762366d7f748"); } catch (Exception e) { e.printStackTrace(); throw e; diff --git a/buildscript/src/main/java/Buildscript.java b/buildscript/src/main/java/Buildscript.java index 2fa1e5fc..9d378066 100644 --- a/buildscript/src/main/java/Buildscript.java +++ b/buildscript/src/main/java/Buildscript.java @@ -277,7 +277,7 @@ protected List createDependencies() { public final BJavaModule recombobulator = new BJavaModule() { @Override MavenId getId() { - return new MavenId(GROUP, "recombobulator", "0.0.1"); + return new MavenId(GROUP, "recombobulator", "0.0.2"); } @Override @@ -417,7 +417,7 @@ protected List createDependencies() { public final BJavaModule brachyuraMinecraft = new BJavaModule() { @Override MavenId getId() { - return new MavenId(GROUP, "brachyura-minecraft", "0.2"); + return new MavenId(GROUP, "brachyura-minecraft", "0.3"); } @Override diff --git a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/Recombobulator.java b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/Recombobulator.java index f2588bcb..c9a6deb0 100644 --- a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/Recombobulator.java +++ b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/Recombobulator.java @@ -4,6 +4,6 @@ public class Recombobulator { private Recombobulator() { } public static String getVersion() { - return "0.1"; + return "0.2"; } } diff --git a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java index 71bae32c..80bed3e2 100644 --- a/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java +++ b/recombobulator/src/main/java/io/github/coolcrabs/brachyura/recombobulator/remapper/RecombobulatorRemapper.java @@ -5,6 +5,8 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.Collection; +import java.util.HashMap; +import java.util.TreeMap; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.ForkJoinPool; @@ -111,9 +113,10 @@ import io.github.coolcrabs.brachyura.recombobulator.attribute.VerificationTypeObject; import io.github.coolcrabs.brachyura.recombobulator.attribute.VerificationTypeUninitialized; import io.github.coolcrabs.brachyura.recombobulator.util.ConstantPoolRefCounter; -import it.unimi.dsi.fastutil.ints.Int2IntRBTreeMap; import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue; +import it.unimi.dsi.fastutil.ints.IntIntImmutablePair; +import it.unimi.dsi.fastutil.ints.IntIntPair; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; public class RecombobulatorRemapper { @@ -748,7 +751,7 @@ public void visitClassInfo(ClassInfo el) { AttributeMethodParameters params; boolean isDynamic; int[] lvtp; - Int2ObjectRBTreeMap lvtTypeMap; + HashMap lvtTypeMap; @Override public void visitMethodInfo(MethodInfo el) { @@ -758,7 +761,7 @@ public void visitMethodInfo(MethodInfo el) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, mapped.name); el.descriptor_index = getUtf8Index(cp, newCp, utf8Map, openSlots, mapped.desc); params = null; - lvtTypeMap = new Int2ObjectRBTreeMap<>(); + lvtTypeMap = new HashMap<>(); for (Attribute a : el.attributes) { if (a instanceof AttributeMethodParameters) params = (AttributeMethodParameters) a; if (a instanceof AttributeCode) { @@ -767,7 +770,7 @@ public void visitMethodInfo(MethodInfo el) { if (a0 instanceof AttributeLocalVariableTable) { AttributeLocalVariableTable alvt = (AttributeLocalVariableTable) a0; for (EntryLocalVariableTable elvt : alvt.local_variable_table) { - lvtTypeMap.put(elvt.index, Mappings.remapFieldDescriptor(mappings, utf8(cp, elvt.descriptor_index))); + lvtTypeMap.put(new IntIntImmutablePair(elvt.start_pc, elvt.index), Mappings.remapFieldDescriptor(mappings, utf8(cp, elvt.descriptor_index))); } } } @@ -784,11 +787,12 @@ public void visitMethodInfo(MethodInfo el) { lvtp[plvt[i]] = i; } } - if (params == null) { + if (params == null && replaceLvtAndParams && pcount > 0) { ArrayList p = new ArrayList<>(pcount); params = new AttributeMethodParameters(getUtf8Index(cp, newCp, utf8Map, openSlots, AttributeMethodParameters.NAME), p); el.attributes.add(params); } + if (params == null) return; while (params.parameters.size() < pcount) { params.parameters.add(new EntryParameters(0, 0)); } @@ -1187,12 +1191,12 @@ public void visitEntryLocalVariableTypeTable(EntryLocalVariableTypeTable el) { if (replaceLvtAndParams && isDynamic && el.index == 0) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, THIS_STR); } else if (replaceLvtAndParams && el.index < lvtp.length) { - el.name_index = params.parameters.get(lvtp[el.index]).name_index; + el.name_index = params == null ? 0 : params.parameters.get(lvtp[el.index]).name_index; if (el.name_index == 0) { - el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("p" + getLvNameTypeThing(lvtTypeMap.get(el.index)) + lvtp[el.index])); + el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("p" + getLvNameTypeThing(lvtTypeMap.get(new IntIntImmutablePair(el.start_pc, el.index))) + lvtp[el.index])); } } else if (replaceLvtAndParams) { - el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("lv" + getLvNameTypeThing(lvtTypeMap.get(el.index)) + el.index)); + el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("lv" + getLvNameTypeThing(lvtTypeMap.get(new IntIntImmutablePair(el.start_pc, el.index))) + el.index)); } else { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, utf8(cp, el.name_index)); } @@ -1237,7 +1241,7 @@ public void visitEntryLocalVariableTable(EntryLocalVariableTable el) { if (replaceLvtAndParams && isDynamic && el.index == 0) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, THIS_STR); } else if (replaceLvtAndParams && el.index < lvtp.length) { - el.name_index = params.parameters.get(lvtp[el.index]).name_index; + el.name_index = params == null ? 0 : params.parameters.get(lvtp[el.index]).name_index; if (el.name_index == 0) { el.name_index = getUtf8Index(cp, newCp, utf8Map, openSlots, new Mutf8Slice("p" + getLvNameTypeThing(desc) + lvtp[el.index])); } diff --git a/test/fabric/legfabric/.gitignore b/test/fabric/legfabric/.gitignore new file mode 100644 index 00000000..44d02ab2 --- /dev/null +++ b/test/fabric/legfabric/.gitignore @@ -0,0 +1,11 @@ +.vscode +build +.brachyura +run +netbeans +*.iml +.idea +*.launch +.project +.classpath +.settings diff --git a/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestMod.java b/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestMod.java new file mode 100644 index 00000000..cc6e1754 --- /dev/null +++ b/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestMod.java @@ -0,0 +1,10 @@ +package io.github.coolcrabs.testmod; + +import net.fabricmc.api.ModInitializer; + +public class TestMod implements ModInitializer { + @Override + public void onInitialize() { + System.out.println("yate"); + } +} diff --git a/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestModClient.java b/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestModClient.java new file mode 100644 index 00000000..b650e1fb --- /dev/null +++ b/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/TestModClient.java @@ -0,0 +1,13 @@ +package io.github.coolcrabs.testmod; + +import net.fabricmc.api.ClientModInitializer; +import net.minecraft.client.MinecraftClient; + +public class TestModClient implements ClientModInitializer { + + @Override + public void onInitializeClient() { + System.out.println(MinecraftClient.getInstance().isDemo); + } + +} diff --git a/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/mixin/RandomMixin.java b/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/mixin/RandomMixin.java new file mode 100644 index 00000000..da09d631 --- /dev/null +++ b/test/fabric/legfabric/src/main/java/io/github/coolcrabs/testmod/mixin/RandomMixin.java @@ -0,0 +1,21 @@ +package io.github.coolcrabs.testmod.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.client.gui.screen.TitleScreen; + +@Mixin(TitleScreen.class) +public class RandomMixin { + @Shadow + String splashText; + + @Inject(at = @At("HEAD"), method = "init()V") + private void init(CallbackInfo info) { + System.out.println("This line is printed by an example mod mixin!"); + System.out.println(splashText); + } +} diff --git a/test/fabric/legfabric/src/main/resources/brachyuratestmod.mixins.json b/test/fabric/legfabric/src/main/resources/brachyuratestmod.mixins.json new file mode 100644 index 00000000..07abfddd --- /dev/null +++ b/test/fabric/legfabric/src/main/resources/brachyuratestmod.mixins.json @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "io.github.coolcrabs.testmod.mixin", + "compatibilityLevel": "JAVA_8", + "mixins": [], + "client": [ + "RandomMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/test/fabric/legfabric/src/main/resources/fabric.mod.json b/test/fabric/legfabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..3048eded --- /dev/null +++ b/test/fabric/legfabric/src/main/resources/fabric.mod.json @@ -0,0 +1,19 @@ +{ + "schemaVersion": 1, + "id": "brachyuratestmod", + "version": "1337.0.0", + "name": "Test Mod", + "description": "Test mod for brachyura build tool.", + "entrypoints": { + "main": [ + "io.github.coolcrabs.testmod.TestMod" + ], + "client": [ + "io.github.coolcrabs.testmod.TestModClient" + ] + }, + "mixins": [ + "brachyuratestmod.mixins.json" + ], + "accessWidener" : "testaw.accesswidener" +} diff --git a/test/fabric/legfabric/src/main/resources/testaw.accesswidener b/test/fabric/legfabric/src/main/resources/testaw.accesswidener new file mode 100644 index 00000000..ad70eee9 --- /dev/null +++ b/test/fabric/legfabric/src/main/resources/testaw.accesswidener @@ -0,0 +1,2 @@ +accessWidener v1 named +accessible field net/minecraft/client/MinecraftClient isDemo Z