Search in sources :

Example 26 with MethodInsnNode

use of org.objectweb.asm.tree.MethodInsnNode in project malmo by Microsoft.

the class OverclockingClassTransformer method insertTextureHandler.

private static void insertTextureHandler(ClassNode node, boolean isObfuscated) {
    // We're attempting to turn this line from GlStateManager.bindTexture:
    // GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture);
    // into this:
    // TextureHelper.glBindTexture(GL11.GL_TEXTURE_2D, texture);
    // TextureHelpers's method then decides whether or not add a shader to the OpenGL pipeline before
    // passing the call on to GL11.glBindTexture.
    final String methodName = isObfuscated ? "func_179144_i" : "bindTexture";
    // Takes one int, returns void.
    final String methodDescriptor = "(I)V";
    System.out.println("MALMO: Found GlStateManager, attempting to transform it");
    for (MethodNode method : node.methods) {
        if (method.name.equals(methodName) && method.desc.equals(methodDescriptor)) {
            System.out.println("MALMO: Found GlStateManager.bindTexture() method, attempting to transform it");
            for (AbstractInsnNode instruction : method.instructions.toArray()) {
                if (instruction.getOpcode() == Opcodes.INVOKESTATIC) {
                    MethodInsnNode visitMethodNode = (MethodInsnNode) instruction;
                    if (visitMethodNode.name.equals("glBindTexture")) {
                        visitMethodNode.owner = "com/microsoft/Malmo/Utils/TextureHelper";
                        if (isObfuscated) {
                            visitMethodNode.name = "bindTexture";
                        }
                        System.out.println("MALMO: Hooked into call to GlStateManager.bindTexture()");
                    }
                }
            }
        }
    }
}
Also used : MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode)

Aggregations

MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)26 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)12 MethodNode (org.objectweb.asm.tree.MethodNode)5 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)4 ArrayList (java.util.ArrayList)3 Type (org.objectweb.asm.Type)3 InsnList (org.objectweb.asm.tree.InsnList)3 InvokeDynamicInsnNode (org.objectweb.asm.tree.InvokeDynamicInsnNode)3 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)3 BasicValue (org.objectweb.asm.tree.analysis.BasicValue)3 List (java.util.List)2 AnnotationNode (org.objectweb.asm.tree.AnnotationNode)2 ClassNode (org.objectweb.asm.tree.ClassNode)2 FieldNode (org.objectweb.asm.tree.FieldNode)2 InsnNode (org.objectweb.asm.tree.InsnNode)2 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)2 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)2 Frame (org.objectweb.asm.tree.analysis.Frame)2 SuspendableType (co.paralleluniverse.fibers.instrument.MethodDatabase.SuspendableType)1 com.mxgraph.swing.mxGraphComponent (com.mxgraph.swing.mxGraphComponent)1