Search in sources :

Example 21 with PushConstantInstruction

use of net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction in project runelite by runelite.

the class MixinInjector method setOwnersToTargetClass.

private void setOwnersToTargetClass(ClassFile mixinCf, ClassFile cf, Method method, Map<net.runelite.asm.pool.Field, Field> shadowFields, Map<net.runelite.asm.pool.Method, CopiedMethod> copiedMethods) throws InjectionException {
    ListIterator<Instruction> iterator = method.getCode().getInstructions().getInstructions().listIterator();
    while (iterator.hasNext()) {
        Instruction i = iterator.next();
        if (i instanceof InvokeInstruction) {
            InvokeInstruction ii = (InvokeInstruction) i;
            CopiedMethod copiedMethod = copiedMethods.get(ii.getMethod());
            if (copiedMethod != null) {
                ii.setMethod(copiedMethod.obMethod.getPoolMethod());
                // Pass through garbage value if the method has one
                if (copiedMethod.hasGarbageValue) {
                    int garbageIndex = copiedMethod.obMethod.isStatic() ? copiedMethod.obMethod.getDescriptor().size() - 1 : copiedMethod.obMethod.getDescriptor().size();
                    iterator.previous();
                    iterator.add(new ILoad(method.getCode().getInstructions(), garbageIndex));
                    iterator.next();
                }
            } else if (ii.getMethod().getClazz().getName().equals(mixinCf.getName())) {
                ii.setMethod(new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(cf.getName()), ii.getMethod().getName(), ii.getMethod().getType()));
            }
        } else if (i instanceof FieldInstruction) {
            FieldInstruction fi = (FieldInstruction) i;
            Field shadowed = shadowFields.get(fi.getField());
            if (shadowed != null) {
                fi.setField(shadowed.getPoolField());
            } else if (fi.getField().getClazz().getName().equals(mixinCf.getName())) {
                fi.setField(new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(cf.getName()), fi.getField().getName(), fi.getField().getType()));
            }
        } else if (i instanceof PushConstantInstruction) {
            PushConstantInstruction pi = (PushConstantInstruction) i;
            if (mixinCf.getPoolClass().equals(pi.getConstant())) {
                pi.setConstant(cf.getPoolClass());
            }
        }
        verify(mixinCf, i);
    }
}
Also used : PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.Field) PutField(net.runelite.asm.attributes.code.instructions.PutField) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction)

Aggregations

PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)21 Instruction (net.runelite.asm.attributes.code.Instruction)16 Instructions (net.runelite.asm.attributes.code.Instructions)9 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)8 InstructionContext (net.runelite.asm.execution.InstructionContext)8 Field (net.runelite.asm.Field)7 Method (net.runelite.asm.Method)7 StackContext (net.runelite.asm.execution.StackContext)7 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)6 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)6 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)6 LDC (net.runelite.asm.attributes.code.instructions.LDC)6 ClassFile (net.runelite.asm.ClassFile)5 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)5 ArrayList (java.util.ArrayList)4 Type (net.runelite.asm.Type)4 GetStatic (net.runelite.asm.attributes.code.instructions.GetStatic)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 HashSet (java.util.HashSet)3