From 4403b89ac804219908bcc236fe2fb31ff6455eeb Mon Sep 17 00:00:00 2001 From: Lucwousin Date: Fri, 1 Nov 2019 14:53:15 +0100 Subject: [PATCH] Fixup MixinInjector --- .../com/openosrs/injector/InjectUtil.java | 2 +- .../injector/injectors/MixinInjector.java | 69 +++++++++---------- 2 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/openosrs/injector/InjectUtil.java b/src/main/java/com/openosrs/injector/InjectUtil.java index b20bb05..0179271 100644 --- a/src/main/java/com/openosrs/injector/InjectUtil.java +++ b/src/main/java/com/openosrs/injector/InjectUtil.java @@ -179,7 +179,7 @@ public interface InjectUtil /** * Fail-fast implementation of ClassGroup.findStaticMethod */ - static Method findMethod(ClassGroup group, String name, Signature type) throws Injexception + static Method findStaticMethod(ClassGroup group, String name, Signature type) throws Injexception { Method m = group.findStaticMethod(name, type); if (m == null) diff --git a/src/main/java/com/openosrs/injector/injectors/MixinInjector.java b/src/main/java/com/openosrs/injector/injectors/MixinInjector.java index b108d8d..2ccf7b3 100644 --- a/src/main/java/com/openosrs/injector/injectors/MixinInjector.java +++ b/src/main/java/com/openosrs/injector/injectors/MixinInjector.java @@ -29,6 +29,7 @@ import net.runelite.asm.attributes.code.instruction.types.PushConstantInstructio import net.runelite.asm.attributes.code.instruction.types.ReturnInstruction; import net.runelite.asm.attributes.code.instructions.ALoad; import net.runelite.asm.attributes.code.instructions.ANewArray; +import net.runelite.asm.attributes.code.instructions.CheckCast; import net.runelite.asm.attributes.code.instructions.GetField; import net.runelite.asm.attributes.code.instructions.ILoad; import net.runelite.asm.attributes.code.instructions.InvokeDynamic; @@ -89,6 +90,7 @@ public class MixinInjector extends AbstractInjector } log.info("Injected {}, copied {}, replaced {} methods", injected, copied, replaced); + inject.runChildInjector(new InjectHook(inject, mixinTargets)); inject.runChildInjector(new InjectHookMethod(inject, mixinTargets)); @@ -226,10 +228,10 @@ public class MixinInjector extends AbstractInjector private void injectMethods(Provider mixinProvider, List targetClasses) throws Injexception { - final ClassFile mixinClass = mixinProvider.get(); - for (ClassFile targetClass : targetClasses) { + final ClassFile mixinClass = mixinProvider.get(); + // Keeps mappings between methods annotated with @Copy -> the copied method within the vanilla pack Map copiedMethods = new HashMap<>(); @@ -243,17 +245,10 @@ public class MixinInjector extends AbstractInjector } String copiedName = copyA.getElement().getString(); - // The method we're copying, deob - Method deobSourceMethod; + Signature deobSig = InjectUtil.apiToDeob(inject, mixinMethod.getDescriptor()); + boolean notStat = !mixinMethod.isStatic(); - if (mixinMethod.isStatic()) - { - deobSourceMethod = InjectUtil.findMethod(inject.getDeobfuscated(), copiedName, mixinMethod.getDescriptor().rsApiToRsClient()); - } - else - { - deobSourceMethod = InjectUtil.findMethodDeep(inject.toDeob(targetClass.getName()), copiedName, mixinMethod.getDescriptor().rsApiToRsClient()); - } + Method deobSourceMethod = InjectUtil.findMethod(inject, copiedName, inject.toDeob(targetClass.getName()).getName(), deobSig, notStat, true); if (mixinMethod.isStatic() != deobSourceMethod.isStatic()) { @@ -445,32 +440,32 @@ public class MixinInjector extends AbstractInjector throw new Injexception("Mixin methods cannot have more parameters than their corresponding ob method"); } - //Type returnType = mixinMethod.getDescriptor().getReturnValue(); - //Type deobReturnType = InjectUtil.apiToDeob(inject, returnType); - //if (!returnType.equals(deobReturnType)) - //{ - // ClassFile deobReturnTypeClassFile = inject.getDeobfuscated() - // .findClass(deobReturnType.getInternalName()); - // if (deobReturnTypeClassFile != null) - // { - // ClassFile obReturnTypeClass = inject.toVanilla(deobReturnTypeClassFile); + Type returnType = mixinMethod.getDescriptor().getReturnValue(); + Type deobReturnType = InjectUtil.apiToDeob(inject, returnType); + if (!returnType.equals(deobReturnType)) + { + ClassFile deobReturnTypeClassFile = inject.getDeobfuscated() + .findClass(deobReturnType.getInternalName()); + if (deobReturnTypeClassFile != null) + { + ClassFile obReturnTypeClass = inject.toVanilla(deobReturnTypeClassFile); - // Instructions instructions = mixinMethod.getCode().getInstructions(); - // ListIterator listIter = instructions.listIterator(); - // while (listIter.hasNext()) - // { - // Instruction instr = listIter.next(); - // if (instr instanceof ReturnInstruction) - // { - // listIter.previous(); - // CheckCast checkCast = new CheckCast(instructions); - // checkCast.setType(new Type(obReturnTypeClass.getName())); - // listIter.add(checkCast); - // listIter.next(); - // } - // } - // } - //} + Instructions instructions = mixinMethod.getCode().getInstructions(); + ListIterator listIter = instructions.listIterator(); + while (listIter.hasNext()) + { + Instruction instr = listIter.next(); + if (instr instanceof ReturnInstruction) + { + listIter.previous(); + CheckCast checkCast = new CheckCast(instructions); + checkCast.setType(new Type(obReturnTypeClass.getName())); + listIter.add(checkCast); + listIter.next(); + } + } + } + } moveCode(obMethod, mixinMethod.getCode());