Search in sources :

Example 16 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.

the class ClassTransformer method patchEntityLivingBase.

private byte[] patchEntityLivingBase(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found EntityLivingBase Class: " + classNode.name);
    MethodNode updatePotionEffects = null;
    MethodNode travel = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_70679_bo"))) {
            updatePotionEffects = mn;
        } else if (mn.name.equals(MCPNames.method("func_191986_a"))) {
            travel = mn;
        }
    }
    if (updatePotionEffects != null) {
        logger.log(Level.DEBUG, "- Found updatePotionEffects (1/2)");
        for (int i = 0; i < updatePotionEffects.instructions.size(); i++) {
            AbstractInsnNode ain = updatePotionEffects.instructions.get(i);
            if (ain instanceof FieldInsnNode) {
                FieldInsnNode fin = (FieldInsnNode) ain;
                if (fin.name.equals(MCPNames.field("field_70180_af"))) {
                    AbstractInsnNode aload = updatePotionEffects.instructions.get(i - 1);
                    InsnList toInsert = new InsnList();
                    LabelNode l1 = new LabelNode(new Label());
                    toInsert.add(new VarInsnNode(ALOAD, 0));
                    toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldRenderPotionParticles", "(Lnet/minecraft/entity/EntityLivingBase;)Z", false));
                    toInsert.add(new JumpInsnNode(IFGT, l1));
                    toInsert.add(new InsnNode(RETURN));
                    toInsert.add(l1);
                    updatePotionEffects.instructions.insertBefore(aload, toInsert);
                    break;
                }
            }
        }
    }
    if (travel != null) {
        logger.log(Level.DEBUG, "- Found travel (2/2)");
        for (int i = 0; i < travel.instructions.size(); i++) {
            AbstractInsnNode ain = travel.instructions.get(i);
            if (ain instanceof LdcInsnNode) {
                LdcInsnNode lin = (LdcInsnNode) ain;
                if (lin.cst.equals(new Float("0.91"))) {
                    AbstractInsnNode next = travel.instructions.get(i + 1);
                    if (next.getOpcode() == Opcodes.FMUL) {
                        InsnList toInsert = new InsnList();
                        toInsert.add(new VarInsnNode(ALOAD, 0));
                        toInsert.add(new VarInsnNode(ALOAD, 0));
                        toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraft/entity/EntityLivingBase", MCPNames.field("field_70170_p"), "Lnet/minecraft/world/World;"));
                        toInsert.add(new VarInsnNode(ALOAD, 5));
                        toInsert.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/world/World", MCPNames.method("func_180495_p"), "(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;", false));
                        toInsert.add(new MethodInsnNode(INVOKEINTERFACE, "net/minecraft/block/state/IBlockState", MCPNames.method("func_177230_c"), "()Lnet/minecraft/block/Block;", true));
                        toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "slipFix", "(FLnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/block/Block;)F", false));
                        travel.instructions.insert(next, toInsert);
                        i += 6;
                    }
                }
            }
        }
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) Label(org.objectweb.asm.Label) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 17 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.

the class ClassTransformer method patchEntitySlime.

private byte[] patchEntitySlime(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found EntitySlime Class: " + classNode.name);
    MethodNode getCanSpawnHere = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_70601_bi"))) {
            getCanSpawnHere = mn;
            break;
        }
    }
    if (getCanSpawnHere != null) {
        logger.log(Level.DEBUG, " - Found getCanSpawnHere");
        for (int i = 0; i < getCanSpawnHere.instructions.size(); i++) {
            AbstractInsnNode ain = getCanSpawnHere.instructions.get(i);
            if (ain instanceof FieldInsnNode) {
                FieldInsnNode fin = (FieldInsnNode) ain;
                if (fin.name.equals("PEACEFUL")) {
                    logger.log(Level.DEBUG, " - Found Insertion Point");
                    AbstractInsnNode skip = getCanSpawnHere.instructions.get(i + 1);
                    LabelNode l0 = new LabelNode(new Label());
                    InsnList toInsert = new InsnList();
                    toInsert.add(new VarInsnNode(ALOAD, 0));
                    toInsert.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/entity/monster/EntitySlime", MCPNames.field("field_70170_p"), "Lnet/minecraft/world/World;"));
                    toInsert.add(new VarInsnNode(ALOAD, 2));
                    toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "overrideSlimeChunk", "(Lnet/minecraft/world/World;Lnet/minecraft/world/chunk/Chunk;)I", false));
                    toInsert.add(new InsnNode(DUP));
                    toInsert.add(new JumpInsnNode(IFLT, l0));
                    toInsert.add(new InsnNode(IRETURN));
                    toInsert.add(l0);
                    toInsert.add(new InsnNode(POP));
                    getCanSpawnHere.instructions.insert(skip, toInsert);
                }
            }
        }
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) Label(org.objectweb.asm.Label) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 18 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.

the class ClassTransformer method patchRenderItem.

private byte[] patchRenderItem(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found RenderItem Class: " + classNode.name);
    MethodNode renderEffect = null;
    MethodNode renderItem = null;
    MethodNode renderQuads = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_191966_a"))) {
            renderEffect = mn;
        } else if (mn.name.equals(MCPNames.method("func_180454_a")) && mn.desc.equals("(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/IBakedModel;)V")) {
            renderItem = mn;
        } else if (mn.name.equals(MCPNames.method("func_191970_a"))) {
            renderQuads = mn;
        }
    }
    if (renderEffect != null) {
        logger.log(Level.DEBUG, "- Found renderEffect (1/3)");
        renderEffect.instructions.insert(new MethodInsnNode(INVOKESTATIC, asmHandler, "preEnchantment", "()V", false));
        for (int i = 0; i < renderEffect.instructions.size(); i++) {
            AbstractInsnNode ain = renderEffect.instructions.get(i);
            if (ain instanceof LdcInsnNode) {
                LdcInsnNode lin = (LdcInsnNode) ain;
                if (lin.cst.equals(new Integer(-8372020))) {
                    logger.log(Level.DEBUG, "- Found Texture Binding");
                    renderEffect.instructions.insert(lin, new MethodInsnNode(INVOKESTATIC, asmHandler, "enchantmentColorHook", "(I)I", false));
                }
            } else if (ain.getOpcode() == RETURN) {
                renderEffect.instructions.insertBefore(ain, new MethodInsnNode(INVOKESTATIC, asmHandler, "postEnchantment", "()V", false));
                i++;
            }
        }
    }
    if (renderItem != null) {
        boolean found = false;
        logger.log(Level.DEBUG, "- Found renderItem (2/3) (" + renderItem.desc + ")");
        for (int i = 0; i < renderItem.instructions.size(); i++) {
            AbstractInsnNode ain = renderItem.instructions.get(i);
            if (ain instanceof MethodInsnNode) {
                MethodInsnNode min = (MethodInsnNode) ain;
                if (!found) {
                    if (min.name.equals(MCPNames.method("func_191966_a"))) {
                        logger.log(Level.DEBUG, "- Found renderEffect calling");
                        InsnList toInsert = new InsnList();
                        toInsert.add(new VarInsnNode(ALOAD, 1));
                        toInsert.add(new FieldInsnNode(PUTSTATIC, asmHandler, "currentlyRendering", "Lnet/minecraft/item/ItemStack;"));
                        renderItem.instructions.insertBefore(min, toInsert);
                        toInsert = new InsnList();
                        toInsert.add(new InsnNode(ACONST_NULL));
                        toInsert.add(new FieldInsnNode(PUTSTATIC, asmHandler, "currentlyRendering", "Lnet/minecraft/item/ItemStack;"));
                        renderItem.instructions.insert(min, toInsert);
                        found = true;
                    }
                }
                if (min.name.equals(MCPNames.method("func_179022_a"))) {
                    LabelNode l1 = new LabelNode(new Label());
                    LabelNode l2 = new LabelNode(new Label());
                    logger.log(Level.DEBUG, "- Inserting TE Item Renderer");
                    InsnList insertBefore = new InsnList();
                    insertBefore.add(new FieldInsnNode(GETSTATIC, "lumien/randomthings/client/RandomThingsTEItemRenderer", "instance", "Llumien/randomthings/client/RandomThingsTEItemRenderer;"));
                    insertBefore.add(new VarInsnNode(ALOAD, 1));
                    insertBefore.add(new MethodInsnNode(INVOKEVIRTUAL, "lumien/randomthings/client/RandomThingsTEItemRenderer", "renderByItem", "(Lnet/minecraft/item/ItemStack;)Z", false));
                    insertBefore.add(new JumpInsnNode(IFEQ, l2));
                    insertBefore.add(new InsnNode(POP));
                    insertBefore.add(new InsnNode(POP));
                    insertBefore.add(new JumpInsnNode(GOTO, l1));
                    insertBefore.add(l2);
                    InsnList insertAfter = new InsnList();
                    insertAfter.add(l1);
                    renderItem.instructions.insertBefore(min, insertBefore);
                    renderItem.instructions.insert(min, insertAfter);
                    i += 8;
                }
            }
        }
    }
    if (renderQuads != null) {
        logger.log(Level.DEBUG, "- Found renderQuads (3/3) (" + renderQuads.desc + ")");
        String luminousHandler = "lumien/randomthings/handler/LuminousHandler";
        InsnList startInsrt = new InsnList();
        startInsrt.add(new VarInsnNode(ALOAD, 4));
        startInsrt.add(new VarInsnNode(ALOAD, 1));
        startInsrt.add(new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookStart", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/BufferBuilder;)V", false));
        renderQuads.instructions.insert(startInsrt);
        for (int i = 0; i < renderQuads.instructions.size(); i++) {
            AbstractInsnNode ain = renderQuads.instructions.get(i);
            if (ain instanceof MethodInsnNode) {
                MethodInsnNode min = (MethodInsnNode) ain;
                if (min.name.equals("renderQuadColor")) {
                    InsnList toInsert = new InsnList();
                    toInsert.add(new VarInsnNode(ALOAD, 8));
                    toInsert.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/client/renderer/block/model/BakedQuad", MCPNames.method("func_178211_c"), "()I", false));
                    toInsert.add(new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookPre", "(I)V", false));
                    toInsert.add(new InsnNode(POP));
                    toInsert.add(new VarInsnNode(ALOAD, 4));
                    toInsert.add(new VarInsnNode(ILOAD, 9));
                    toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "getColorFromItemStack", "(Lnet/minecraft/item/ItemStack;I)I", false));
                    renderQuads.instructions.insertBefore(min, toInsert);
                    i += 7;
                    renderQuads.instructions.insert(min, new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookPost", "()V", false));
                }
            } else if (ain.getOpcode() == RETURN) {
                renderQuads.instructions.insertBefore(ain, new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookEnd", "()V", false));
                i++;
            }
        }
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) Label(org.objectweb.asm.Label) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnList(org.objectweb.asm.tree.InsnList) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 19 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.

the class ClassTransformer method patchBlock.

private byte[] patchBlock(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found Block Class: " + classNode.name);
    MethodNode addCollisionBoxesToList = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals(MCPNames.method("func_185477_a")) && mn.desc.equals("(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/AxisAlignedBB;Ljava/util/List;Lnet/minecraft/entity/Entity;Z)V")) {
            addCollisionBoxesToList = mn;
        }
    }
    if (addCollisionBoxesToList != null) {
        logger.log(Level.DEBUG, "- Found addCollisionBoxesToList (1/1)");
        InsnList toInsert = new InsnList();
        LabelNode l1 = new LabelNode(new Label());
        toInsert.add(new VarInsnNode(ALOAD, 1));
        toInsert.add(new VarInsnNode(ALOAD, 2));
        toInsert.add(new VarInsnNode(ALOAD, 3));
        toInsert.add(new VarInsnNode(ALOAD, 4));
        toInsert.add(new VarInsnNode(ALOAD, 5));
        toInsert.add(new VarInsnNode(ALOAD, 6));
        toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "addCollisionBoxesToList", "(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/AxisAlignedBB;Ljava/util/List;Lnet/minecraft/entity/Entity;)Z", false));
        toInsert.add(new JumpInsnNode(IFEQ, l1));
        toInsert.add(new InsnNode(RETURN));
        toInsert.add(l1);
        addCollisionBoxesToList.instructions.insert(toInsert);
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    return writer.toByteArray();
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) Label(org.objectweb.asm.Label) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Example 20 with LabelNode

use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.

the class ClassTransformer method patchVertexLighterFlat.

private byte[] patchVertexLighterFlat(byte[] basicClass) {
    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(basicClass);
    classReader.accept(classNode, 0);
    logger.log(Level.DEBUG, "Found VertexLighterFlat Class: " + classNode.name);
    MethodNode processQuad = null;
    for (MethodNode mn : classNode.methods) {
        if (mn.name.equals("processQuad")) {
            processQuad = mn;
            break;
        }
    }
    if (processQuad != null) {
        logger.log(Level.DEBUG, " - Found processQuad");
        InsnList resetList = new InsnList();
        resetList.add(new VarInsnNode(ALOAD, 0));
        resetList.add(new InsnNode(ICONST_0));
        resetList.add(new FieldInsnNode(PUTFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "rtFullBright", "Z"));
        processQuad.instructions.insert(resetList);
        AbstractInsnNode tintTarget = null;
        int lightMapTarget = 0;
        AbstractInsnNode updateColorTarget = null;
        LabelNode firstLabel = null;
        LabelNode lastLabel = null;
        for (int i = 0; i < processQuad.instructions.size(); i++) {
            AbstractInsnNode ain = processQuad.instructions.get(i);
            if (ain instanceof VarInsnNode) {
                VarInsnNode vin = (VarInsnNode) ain;
                if (vin.var == 5 && (processQuad.instructions.get(i - 1) instanceof MethodInsnNode)) {
                    tintTarget = vin;
                }
            } else if (ain instanceof LabelNode) {
                LabelNode ln = (LabelNode) ain;
                if (firstLabel == null) {
                    firstLabel = ln;
                }
                lastLabel = ln;
            } else if (ain instanceof MethodInsnNode) {
                MethodInsnNode min = (MethodInsnNode) ain;
                if (min.name.equals(MCPNames.method("func_177369_e"))) {
                    lightMapTarget = i;
                } else if (min.name.equals("updateColor")) {
                    updateColorTarget = min;
                }
            }
        }
        FieldNode fullBrightField = new FieldNode(ACC_PRIVATE, "rtFullBright", "Z", null, false);
        classNode.fields.add(fullBrightField);
        if (lightMapTarget != 0) {
            logger.log(Level.DEBUG, " - Found patch target (lightmap) (1/4)");
            for (int i = lightMapTarget; i < processQuad.instructions.size(); i++) {
                AbstractInsnNode ain = processQuad.instructions.get(i);
                if (ain instanceof InsnNode) {
                    InsnNode in = (InsnNode) ain;
                    if (in.getOpcode() == AALOAD) {
                        logger.log(Level.DEBUG, " - Found lightmap array (2/4)");
                        LabelNode l0 = new LabelNode(new Label());
                        InsnList toInsert = new InsnList();
                        toInsert.add(new VarInsnNode(ALOAD, 0));
                        toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "rtFullBright", "Z"));
                        toInsert.add(new JumpInsnNode(IFEQ, l0));
                        toInsert.add(new InsnNode(POP));
                        toInsert.add(new FieldInsnNode(GETSTATIC, "lumien/randomthings/lib/Constants", "FULLBRIGHT_OVERRIDE", "[F"));
                        toInsert.add(l0);
                        processQuad.instructions.insert(in, toInsert);
                        break;
                    }
                }
            }
        }
        if (tintTarget != null) {
            logger.log(Level.DEBUG, " - Found tintTarget (3/4");
            LabelNode l0 = new LabelNode(new Label());
            LabelNode l1 = new LabelNode(new Label());
            InsnList toInsert = new InsnList();
            toInsert.add(new VarInsnNode(ALOAD, 0));
            toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "blockInfo", "Lnet/minecraftforge/client/model/pipeline/BlockInfo;"));
            toInsert.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraftforge/client/model/pipeline/BlockInfo", "getState", "()Lnet/minecraft/block/state/IBlockState;", false));
            toInsert.add(new MethodInsnNode(INVOKEINTERFACE, "net/minecraft/block/state/IBlockState", MCPNames.method("func_177230_c"), "()Lnet/minecraft/block/Block;", true));
            toInsert.add(new TypeInsnNode(INSTANCEOF, "lumien/randomthings/lib/ILuminousBlock"));
            toInsert.add(new JumpInsnNode(IFEQ, l0));
            toInsert.add(new VarInsnNode(ALOAD, 0));
            toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "blockInfo", "Lnet/minecraftforge/client/model/pipeline/BlockInfo;"));
            toInsert.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraftforge/client/model/pipeline/BlockInfo", "getState", "()Lnet/minecraft/block/state/IBlockState;", false));
            toInsert.add(new InsnNode(DUP));
            toInsert.add(new MethodInsnNode(INVOKEINTERFACE, "net/minecraft/block/state/IBlockState", MCPNames.method("func_177230_c"), "()Lnet/minecraft/block/Block;", true));
            toInsert.add(new InsnNode(SWAP));
            toInsert.add(new VarInsnNode(ALOAD, 0));
            toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "tint", "I"));
            toInsert.add(new MethodInsnNode(INVOKEINTERFACE, "lumien/randomthings/lib/ILuminousBlock", "shouldGlow", "(Lnet/minecraft/block/state/IBlockState;I)Z", true));
            toInsert.add(new JumpInsnNode(IFEQ, l0));
            toInsert.add(new VarInsnNode(ALOAD, 0));
            toInsert.add(new InsnNode(ICONST_0));
            toInsert.add(new FieldInsnNode(PUTFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "diffuse", "Z"));
            toInsert.add(new VarInsnNode(ALOAD, 0));
            toInsert.add(new InsnNode(ICONST_1));
            toInsert.add(new FieldInsnNode(PUTFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "rtFullBright", "Z"));
            toInsert.add(l0);
            processQuad.instructions.insertBefore(tintTarget, toInsert);
        }
        if (updateColorTarget != null) {
            logger.log(Level.DEBUG, " - Found updateColor target (tint) (4/4)");
            LabelNode l0 = new LabelNode(new Label());
            LabelNode l1 = new LabelNode(new Label());
            InsnList toInsert = new InsnList();
            toInsert.add(new VarInsnNode(ALOAD, 0));
            toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraftforge/client/model/pipeline/VertexLighterFlat", "rtFullBright", "Z"));
            toInsert.add(new JumpInsnNode(IFEQ, l1));
            toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "updateColor", "([F[FFFFFI)V", false));
            toInsert.add(new InsnNode(POP));
            toInsert.add(new JumpInsnNode(GOTO, l0));
            toInsert.add(l1);
            processQuad.instructions.insertBefore(updateColorTarget, toInsert);
            processQuad.instructions.insert(updateColorTarget, l0);
        }
    }
    CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    classNode.accept(writer);
    try {
        byte[] result = writer.toByteArray();
        return result;
    } catch (Exception e) {
        e.printStackTrace();
        return basicClass;
    }
}
Also used : LabelNode(org.objectweb.asm.tree.LabelNode) ClassNode(org.objectweb.asm.tree.ClassNode) FieldNode(org.objectweb.asm.tree.FieldNode) Label(org.objectweb.asm.Label) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) InsnList(org.objectweb.asm.tree.InsnList) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) FieldInsnNode(org.objectweb.asm.tree.FieldInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) TypeInsnNode(org.objectweb.asm.tree.TypeInsnNode) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) LdcInsnNode(org.objectweb.asm.tree.LdcInsnNode) AbstractInsnNode(org.objectweb.asm.tree.AbstractInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) JumpInsnNode(org.objectweb.asm.tree.JumpInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode)

Aggregations

LabelNode (org.objectweb.asm.tree.LabelNode)89 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)37 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)32 Label (org.objectweb.asm.Label)28 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)23 InsnList (org.objectweb.asm.tree.InsnList)22 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)21 InsnNode (org.objectweb.asm.tree.InsnNode)20 MethodNode (org.objectweb.asm.tree.MethodNode)19 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)17 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)16 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)15 ClassNode (org.objectweb.asm.tree.ClassNode)14 ClassReader (org.objectweb.asm.ClassReader)12 LineNumberNode (org.objectweb.asm.tree.LineNumberNode)10 Type (org.objectweb.asm.Type)8 LocalVariableNode (org.objectweb.asm.tree.LocalVariableNode)8 LinkedList (java.util.LinkedList)6 ArrayList (java.util.ArrayList)5 LookupSwitchInsnNode (org.objectweb.asm.tree.LookupSwitchInsnNode)5