Skip to content

Commit

Permalink
praise the lord, the remapper is actually working
Browse files Browse the repository at this point in the history
  • Loading branch information
CoolMineman committed Dec 31, 2022
1 parent 7ba2c3f commit e14dd35
Show file tree
Hide file tree
Showing 13 changed files with 213 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions buildscript/src/main/java/Buildscript.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected List<JavaJarDependency> 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
Expand Down Expand Up @@ -417,7 +417,7 @@ protected List<JavaJarDependency> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public class Recombobulator {
private Recombobulator() { }

public static String getVersion() {
return "0.1";
return "0.2";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -748,7 +751,7 @@ public void visitClassInfo(ClassInfo el) {
AttributeMethodParameters params;
boolean isDynamic;
int[] lvtp;
Int2ObjectRBTreeMap<Mutf8Slice> lvtTypeMap;
HashMap<IntIntImmutablePair, Mutf8Slice> lvtTypeMap;

@Override
public void visitMethodInfo(MethodInfo el) {
Expand All @@ -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) {
Expand All @@ -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)));
}
}
}
Expand All @@ -784,11 +787,12 @@ public void visitMethodInfo(MethodInfo el) {
lvtp[plvt[i]] = i;
}
}
if (params == null) {
if (params == null && replaceLvtAndParams && pcount > 0) {
ArrayList<EntryParameters> 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));
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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]));
}
Expand Down
11 changes: 11 additions & 0 deletions test/fabric/legfabric/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.vscode
build
.brachyura
run
netbeans
*.iml
.idea
*.launch
.project
.classpath
.settings
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"minVersion": "0.8",
"package": "io.github.coolcrabs.testmod.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [],
"client": [
"RandomMixin"
],
"injectors": {
"defaultRequire": 1
}
}
19 changes: 19 additions & 0 deletions test/fabric/legfabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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"
}
2 changes: 2 additions & 0 deletions test/fabric/legfabric/src/main/resources/testaw.accesswidener
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
accessWidener v1 named
accessible field net/minecraft/client/MinecraftClient isDemo Z

0 comments on commit e14dd35

Please sign in to comment.