Skip to content

Commit

Permalink
Add methods to remap methods and fields, fixes #10, #12
Browse files Browse the repository at this point in the history
Allow instantiation of InsnList, fixes #13
  • Loading branch information
ichttt authored and cpw committed May 11, 2019
1 parent b96f039 commit 0651e55
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dependencies {
testImplementation("org.hamcrest:hamcrest-core:2.1")
testImplementation("org.apache.logging.log4j:log4j-core:2.11.+")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.+")
implementation("cpw.mods:modlauncher:0.10.+")
implementation("cpw.mods:modlauncher:1.0.+")
implementation("org.apache.logging.log4j:log4j-api:2.11.+")
implementation("org.ow2.asm:asm:6.2")
implementation("org.ow2.asm:asm-commons:6.2")
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/minecraftforge/coremod/CoreModEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public class CoreModEngine {
"org.objectweb.asm.tree.AbstractInsnNode","org.objectweb.asm.tree.FieldInsnNode",
"org.objectweb.asm.tree.FrameNode","org.objectweb.asm.tree.IincInsnNode",
"org.objectweb.asm.tree.InsnNode","org.objectweb.asm.tree.IntInsnNode",
"org.objectweb.asm.tree.InvokeDynamicInsnNode","org.objectweb.asm.tree.JumpInsnNode",
"org.objectweb.asm.tree.LabelNode","org.objectweb.asm.tree.LdcInsnNode",
"org.objectweb.asm.tree.LineNumberNode","org.objectweb.asm.tree.LocalVariableAnnotationNode",
"org.objectweb.asm.tree.LocalVariableNode","org.objectweb.asm.tree.LookupSwitchInsnNode",
"org.objectweb.asm.tree.MethodInsnNode","org.objectweb.asm.tree.MultiANewArrayInsnNode",
"org.objectweb.asm.tree.TableSwitchInsnNode","org.objectweb.asm.tree.TryCatchBlockNode",
"org.objectweb.asm.tree.TypeAnnotationNode","org.objectweb.asm.tree.TypeInsnNode",
"org.objectweb.asm.tree.VarInsnNode",
"org.objectweb.asm.tree.InsnList", "org.objectweb.asm.tree.InvokeDynamicInsnNode",
"org.objectweb.asm.tree.JumpInsnNode", "org.objectweb.asm.tree.LabelNode",
"org.objectweb.asm.tree.LdcInsnNode", "org.objectweb.asm.tree.LineNumberNode",
"org.objectweb.asm.tree.LocalVariableAnnotationNode", "org.objectweb.asm.tree.LocalVariableNode",
"org.objectweb.asm.tree.LookupSwitchInsnNode", "org.objectweb.asm.tree.MethodInsnNode",
"org.objectweb.asm.tree.MultiANewArrayInsnNode", "org.objectweb.asm.tree.TableSwitchInsnNode",
"org.objectweb.asm.tree.TryCatchBlockNode", "org.objectweb.asm.tree.TypeAnnotationNode",
"org.objectweb.asm.tree.TypeInsnNode", "org.objectweb.asm.tree.VarInsnNode",

// Adding new fields to classes
"org.objectweb.asm.tree.FieldNode",
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/net/minecraftforge/coremod/api/ASMAPI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package net.minecraftforge.coremod.api;

import cpw.mods.modlauncher.Launcher;
import cpw.mods.modlauncher.api.INameMappingService;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

Expand All @@ -19,4 +21,16 @@ public enum MethodType {
public static MethodInsnNode buildMethodCall(final String ownerName, final String methodName, final String methodDescriptor, final MethodType type) {
return new MethodInsnNode(type.ordinal()+Opcodes.INVOKEVIRTUAL, ownerName, methodName, methodDescriptor, type==MethodType.INTERFACE);
}

public static String mapMethod(String name) {
return map(name, INameMappingService.Domain.METHOD);
}

public static String mapField(String name) {
return map(name, INameMappingService.Domain.FIELD);
}

private static String map(String name, INameMappingService.Domain domain) {
return Launcher.INSTANCE.environment().findNameMapping("srg").map(f -> f.apply(domain, name)).orElse(name);
}
}

0 comments on commit 0651e55

Please sign in to comment.