Example usage for org.objectweb.asm Opcodes ACONST_NULL

List of usage examples for org.objectweb.asm Opcodes ACONST_NULL

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes ACONST_NULL.

Prototype

int ACONST_NULL

To view the source code for org.objectweb.asm Opcodes ACONST_NULL.

Click Source Link

Usage

From source file:uk.co.mysterymayhem.tessellatorfix.Transformer.java

private static byte[] patchTessellatorClass(byte[] bytes) {
    String targetMethodName;//w ww.j  av a 2 s .  c  om

    if (Plugin.runtimeDeobfEnabled) {
        targetMethodName = "func_147564_a";
    } else {
        targetMethodName = "getVertexState";
    }

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    Iterator<MethodNode> methods = classNode.methods.iterator();
    while (methods.hasNext()) {
        MethodNode m = methods.next();
        if ((m.name.equals(targetMethodName)
                && m.desc.equals("(FFF)Lnet/minecraft/client/shader/TesselatorVertexState;"))) {
            FMLLog.info("Inside target Tessellator method");

            InsnList toInject = new InsnList();

            // Insertion of "if (this.rawBufferIndex < 1) return"
            LabelNode labelNode = new LabelNode();

            toInject.add(new VarInsnNode(Opcodes.ALOAD, 0));
            String fieldName;
            if (Plugin.runtimeDeobfEnabled) {
                fieldName = "field_147569_p";
            } else {
                fieldName = "rawBufferIndex";
            }
            toInject.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/client/renderer/Tessellator",
                    fieldName, "I"));
            toInject.add(new InsnNode(Opcodes.ICONST_1));
            toInject.add(new JumpInsnNode(Opcodes.IF_ICMPGE, labelNode));
            toInject.add(new InsnNode(Opcodes.ACONST_NULL));
            toInject.add(new InsnNode(Opcodes.ARETURN));
            toInject.add(labelNode);

            // Insert after
            m.instructions.insert(toInject);

            ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
            classNode.accept(writer);
            FMLLog.info("Exiting target Tessellator method");
            return writer.toByteArray();
        }
    }

    FMLLog.warning("Could not find Tessellator method out of:");
    StringBuilder builder = new StringBuilder();
    for (MethodNode methodNode : classNode.methods) {
        builder.append(methodNode.name).append(":").append(methodNode.desc).append("\n");
    }
    FMLLog.info(builder.toString());

    return bytes;
}