Fixup MixinInjector

This commit is contained in:
Lucwousin
2019-11-01 14:53:15 +01:00
parent d7b5d0d171
commit 4403b89ac8
2 changed files with 33 additions and 38 deletions

View File

@@ -179,7 +179,7 @@ public interface InjectUtil
/** /**
* Fail-fast implementation of ClassGroup.findStaticMethod * 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); Method m = group.findStaticMethod(name, type);
if (m == null) if (m == null)

View File

@@ -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.instruction.types.ReturnInstruction;
import net.runelite.asm.attributes.code.instructions.ALoad; import net.runelite.asm.attributes.code.instructions.ALoad;
import net.runelite.asm.attributes.code.instructions.ANewArray; 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.GetField;
import net.runelite.asm.attributes.code.instructions.ILoad; import net.runelite.asm.attributes.code.instructions.ILoad;
import net.runelite.asm.attributes.code.instructions.InvokeDynamic; 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); log.info("Injected {}, copied {}, replaced {} methods", injected, copied, replaced);
inject.runChildInjector(new InjectHook(inject, mixinTargets)); inject.runChildInjector(new InjectHook(inject, mixinTargets));
inject.runChildInjector(new InjectHookMethod(inject, mixinTargets)); inject.runChildInjector(new InjectHookMethod(inject, mixinTargets));
@@ -226,10 +228,10 @@ public class MixinInjector extends AbstractInjector
private void injectMethods(Provider<ClassFile> mixinProvider, List<ClassFile> targetClasses) throws Injexception private void injectMethods(Provider<ClassFile> mixinProvider, List<ClassFile> targetClasses) throws Injexception
{ {
final ClassFile mixinClass = mixinProvider.get();
for (ClassFile targetClass : targetClasses) for (ClassFile targetClass : targetClasses)
{ {
final ClassFile mixinClass = mixinProvider.get();
// Keeps mappings between methods annotated with @Copy -> the copied method within the vanilla pack // Keeps mappings between methods annotated with @Copy -> the copied method within the vanilla pack
Map<net.runelite.asm.pool.Method, CopiedMethod> copiedMethods = new HashMap<>(); Map<net.runelite.asm.pool.Method, CopiedMethod> copiedMethods = new HashMap<>();
@@ -243,17 +245,10 @@ public class MixinInjector extends AbstractInjector
} }
String copiedName = copyA.getElement().getString(); String copiedName = copyA.getElement().getString();
// The method we're copying, deob Signature deobSig = InjectUtil.apiToDeob(inject, mixinMethod.getDescriptor());
Method deobSourceMethod; boolean notStat = !mixinMethod.isStatic();
if (mixinMethod.isStatic()) Method deobSourceMethod = InjectUtil.findMethod(inject, copiedName, inject.toDeob(targetClass.getName()).getName(), deobSig, notStat, true);
{
deobSourceMethod = InjectUtil.findMethod(inject.getDeobfuscated(), copiedName, mixinMethod.getDescriptor().rsApiToRsClient());
}
else
{
deobSourceMethod = InjectUtil.findMethodDeep(inject.toDeob(targetClass.getName()), copiedName, mixinMethod.getDescriptor().rsApiToRsClient());
}
if (mixinMethod.isStatic() != deobSourceMethod.isStatic()) 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"); throw new Injexception("Mixin methods cannot have more parameters than their corresponding ob method");
} }
//Type returnType = mixinMethod.getDescriptor().getReturnValue(); Type returnType = mixinMethod.getDescriptor().getReturnValue();
//Type deobReturnType = InjectUtil.apiToDeob(inject, returnType); Type deobReturnType = InjectUtil.apiToDeob(inject, returnType);
//if (!returnType.equals(deobReturnType)) if (!returnType.equals(deobReturnType))
//{ {
// ClassFile deobReturnTypeClassFile = inject.getDeobfuscated() ClassFile deobReturnTypeClassFile = inject.getDeobfuscated()
// .findClass(deobReturnType.getInternalName()); .findClass(deobReturnType.getInternalName());
// if (deobReturnTypeClassFile != null) if (deobReturnTypeClassFile != null)
// { {
// ClassFile obReturnTypeClass = inject.toVanilla(deobReturnTypeClassFile); ClassFile obReturnTypeClass = inject.toVanilla(deobReturnTypeClassFile);
// Instructions instructions = mixinMethod.getCode().getInstructions(); Instructions instructions = mixinMethod.getCode().getInstructions();
// ListIterator<Instruction> listIter = instructions.listIterator(); ListIterator<Instruction> listIter = instructions.listIterator();
// while (listIter.hasNext()) while (listIter.hasNext())
// { {
// Instruction instr = listIter.next(); Instruction instr = listIter.next();
// if (instr instanceof ReturnInstruction) if (instr instanceof ReturnInstruction)
// { {
// listIter.previous(); listIter.previous();
// CheckCast checkCast = new CheckCast(instructions); CheckCast checkCast = new CheckCast(instructions);
// checkCast.setType(new Type(obReturnTypeClass.getName())); checkCast.setType(new Type(obReturnTypeClass.getName()));
// listIter.add(checkCast); listIter.add(checkCast);
// listIter.next(); listIter.next();
// } }
// } }
// } }
//} }
moveCode(obMethod, mixinMethod.getCode()); moveCode(obMethod, mixinMethod.getCode());