diff options
author | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-11-03 13:59:32 -0800 |
---|---|---|
committer | thedarkcolour <30441001+thedarkcolour@users.noreply.github.com> | 2019-11-03 13:59:32 -0800 |
commit | 9333b91f5c4104e5c52e0af4d2a4aa80da87294b (patch) | |
tree | b405a0009aa96eb76ce3b2514e914e799475334d /src/main/resources/patcher.js | |
parent | 7955daf73c0b84c5044920e52523e1fa7491247f (diff) | |
download | KotlinForForge-9333b91f5c4104e5c52e0af4d2a4aa80da87294b.tar.gz KotlinForForge-9333b91f5c4104e5c52e0af4d2a4aa80da87294b.tar.bz2 KotlinForForge-9333b91f5c4104e5c52e0af4d2a4aa80da87294b.zip |
Initial 1.14 release
Diffstat (limited to 'src/main/resources/patcher.js')
-rw-r--r-- | src/main/resources/patcher.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/main/resources/patcher.js b/src/main/resources/patcher.js new file mode 100644 index 0000000..fcfe312 --- /dev/null +++ b/src/main/resources/patcher.js @@ -0,0 +1,50 @@ +function initializeCoreMod() { +// Unused, remove + return { + 'KotlinPatcher': { + 'target': { + 'type': 'METHOD', + 'class': 'net.minecraftforge.fml.javafmlmod.FMLModContainer', + 'methodName': 'constructMod', + 'methodDesc': '(Lnet/minecraftforge/fml/LifecycleEventProvider$LifecycleEvent;)V' + }, + 'transformer': function (methodNode) { + var VarInsnNode = Java.type('org.objectweb.asm.tree.VarInsnNode'); + var FieldInsnNode = Java.type('org.objectweb.asm.tree.FieldInsnNode'); + var MethodInsnNode = Java.type('org.objectweb.asm.tree.MethodInsnNode'); + var InsnList = Java.type('org.objectweb.asm.tree.InsnList'); + var Opcodes = Java.type('org.objectweb.asm.Opcodes'); + var list = new InsnList(); + list.add(new FieldInsnNode(Opcodes.GETSTATIC, "thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber", "INSTANCE", "Lthedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber;")); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new FieldInsnNode(Opcodes.GETFIELD, 'net/minecraftforge/fml/javafmlmod/FMLModContainer', 'scanResults', 'Lnet/minecraftforge/forgespi/language/ModFileScanData;')); + list.add(new VarInsnNode(Opcodes.ALOAD, 0)); + list.add(new FieldInsnNode(Opcodes.GETFIELD, 'net/minecraftforge/fml/javafmlmod/FMLModContainer', 'modClass', 'Ljava/lang/Class;')); + list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, 'java/lang/Class', 'getClassLoader', '()Ljava/lang/ClassLoader;', false)); + list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "thedarkcolour/kotlinforforge/AutoKotlinEventBusSubscriber", "inject", "(Lnet/minecraftforge/fml/ModContainer;Lnet/minecraftforge/forgespi/language/ModFileScanData;Ljava/lang/ClassLoader;)V", false)); + + for (var i = 0; i < 1000; ++i) { + var insn = methodNode.instructions.get(i); + //print('bruh moment'); + if (insn instanceof MethodInsnNode) { + //print('FOUND A METHODINSNNODE'); + if (insn.desc === '(Lnet/minecraftforge/fml/ModContainer;Lnet/minecraftforge/forgespi/language/ModFileScanData;Ljava/lang/ClassLoader;)V') { + methodNode.instructions.insertBefore(insn.getPrevious().getPrevious().getPrevious().getPrevious().getPrevious().getPrevious(), list); + //print('PATCHED FMLMODCONTAINER'); + break; + } + } + } + + //var writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); + //methodNode.accept(writer); + //var reader = new ClassReader(writer.toByteArray()); + //var cn = new ClassNode(); + //reader.accept(cn, 0); + + return methodNode; + } + } + } +}
\ No newline at end of file |