Example usage for org.objectweb.asm.tree ClassNode ClassNode

List of usage examples for org.objectweb.asm.tree ClassNode ClassNode

Introduction

In this page you can find the example usage for org.objectweb.asm.tree ClassNode ClassNode.

Prototype

public ClassNode(final int api) 

Source Link

Document

Constructs a new ClassNode .

Usage

From source file:org.blockartistry.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformEntityRenderer(final byte[] classBytes) {
    final String names[] = { "func_78484_h", "addRainParticles" };
    final String targetName = "addRainParticles";

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);// w  ww.j  av  a2s.co m

    for (final MethodNode m : cn.methods) {
        if (isOneOf(m.name, names)) {
            logger.debug("Hooking " + m.name);
            final InsnList list = new InsnList();
            list.add(new VarInsnNode(ALOAD, 0));
            final String sig = "(Lnet/minecraft/client/renderer/EntityRenderer;)V";
            list.add(new MethodInsnNode(INVOKESTATIC,
                    "org/blockartistry/DynSurround/client/weather/RenderWeather", targetName, sig, false));
            list.add(new InsnNode(RETURN));
            m.instructions.insertBefore(m.instructions.getFirst(), list);
        }
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformWorldServer(final byte[] classBytes) {
    final String names[] = { "func_73051_P", "resetRainAndThunder" };
    final String targetName = "resetRainAndThunder";

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);//from ww w.j ava2 s.c o  m

    for (final MethodNode m : cn.methods) {
        if (isOneOf(m.name, names)) {
            logger.debug("Hooking " + m.name);
            InsnList list = new InsnList();
            list.add(new VarInsnNode(ALOAD, 0));
            final String sig = "(Lnet/minecraft/world/WorldServer;)V";
            list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/DynSurround/server/PlayerSleepHandler",
                    targetName, sig, false));
            list.add(new InsnNode(RETURN));
            m.instructions.insertBefore(m.instructions.getFirst(), list);
            break;
        }
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformSoundManager(final byte[] classBytes) {
    final String managerToReplace = "net/minecraft/client/audio/SoundManager";
    final String newManager = "org/blockartistry/DynSurround/client/sound/SoundManagerReplacement";

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);/*from www.j  a  va 2  s.com*/

    for (final MethodNode m : cn.methods) {
        final ListIterator<AbstractInsnNode> itr = m.instructions.iterator();
        boolean foundNew = false;
        while (itr.hasNext()) {
            final AbstractInsnNode node = itr.next();
            if (node.getOpcode() == NEW) {
                final TypeInsnNode theNew = (TypeInsnNode) node;
                if (managerToReplace.equals(theNew.desc)) {
                    m.instructions.set(node, new TypeInsnNode(NEW, newManager));
                    foundNew = true;
                }
            } else if (node.getOpcode() == INVOKESPECIAL) {
                final MethodInsnNode theInvoke = (MethodInsnNode) node;
                if (managerToReplace.equals(theInvoke.owner)) {
                    if (foundNew) {
                        m.instructions.set(node, new MethodInsnNode(INVOKESPECIAL, newManager, theInvoke.name,
                                theInvoke.desc, false));
                        foundNew = false;
                    }
                }
            }
        }
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.DynSurround.asm.Transformer.java

License:MIT License

private byte[] replaceRandom(final String name, final byte[] classBytes) {

    final String randomToReplace = "java/util/Random";
    final String newRandom = "org/blockartistry/lib/random/XorShiftRandom";

    boolean madeUpdate = false;

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);/*  ww w. ja va2s  . c om*/

    for (final MethodNode m : cn.methods) {
        final ListIterator<AbstractInsnNode> itr = m.instructions.iterator();
        boolean foundNew = false;
        while (itr.hasNext()) {
            final AbstractInsnNode node = itr.next();
            if (node.getOpcode() == NEW) {
                final TypeInsnNode theNew = (TypeInsnNode) node;
                if (randomToReplace.equals(theNew.desc)) {
                    m.instructions.set(node, new TypeInsnNode(NEW, newRandom));
                    madeUpdate = true;
                    foundNew = true;
                }
            } else if (node.getOpcode() == INVOKESPECIAL) {
                final MethodInsnNode theInvoke = (MethodInsnNode) node;
                if (randomToReplace.equals(theInvoke.owner)) {
                    if (foundNew) {
                        m.instructions.set(node, new MethodInsnNode(INVOKESPECIAL, newRandom, theInvoke.name,
                                theInvoke.desc, false));
                        foundNew = false;
                    }
                }
            }
        }
    }

    if (madeUpdate) {
        logger.debug("Replaced Random in " + name);
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        cn.accept(cw);
        return cw.toByteArray();
    }
    return classBytes;
}

From source file:org.blockartistry.mod.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformEntityRenderer(final byte[] classBytes) {
    final String names[];

    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_78474_d", "func_78484_h" };
    else//from   w ww.  j  a  v a  2s  . c om
        names = new String[] { "renderRainSnow", "addRainParticles" };

    final String targetName[] = new String[] { "renderRainSnow", "addRainParticles" };

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);

    for (final MethodNode m : cn.methods) {
        if (m.name.equals(names[0])) {
            logger.debug("Hooking " + names[0]);
            final InsnList list = new InsnList();
            list.add(new VarInsnNode(ALOAD, 0));
            list.add(new VarInsnNode(FLOAD, 1));
            final String sig = "(Lnet/minecraft/client/renderer/EntityRenderer;F)V";
            list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/client/RenderWeather",
                    targetName[0], sig, false));
            list.add(new InsnNode(RETURN));
            m.instructions.insertBefore(m.instructions.getFirst(), list);
        } else if (m.name.equals(names[1])) {
            logger.debug("Hooking " + names[1]);
            final InsnList list = new InsnList();
            list.add(new VarInsnNode(ALOAD, 0));
            final String sig = "(Lnet/minecraft/client/renderer/EntityRenderer;)V";
            list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/client/RenderWeather",
                    targetName[1], sig, false));
            list.add(new InsnNode(RETURN));
            m.instructions.insertBefore(m.instructions.getFirst(), list);
        }
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.mod.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformWorldServer(final byte[] classBytes) {
    final String names[];

    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_73051_P" };
    else//from  w ww.  ja v  a  2s.com
        names = new String[] { "resetRainAndThunder" };

    final String targetName[] = new String[] { "resetRainAndThunder" };

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);

    for (final MethodNode m : cn.methods) {
        if (m.name.equals(names[0])) {
            logger.debug("Hooking " + names[0]);
            InsnList list = new InsnList();
            list.add(new VarInsnNode(ALOAD, 0));
            final String sig = "(Lnet/minecraft/world/WorldServer;)V";
            list.add(new MethodInsnNode(INVOKESTATIC,
                    "org/blockartistry/mod/DynSurround/server/PlayerSleepHandler", targetName[0], sig, false));
            list.add(new InsnNode(RETURN));
            m.instructions.insertBefore(m.instructions.getFirst(), list);
            break;
        }
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.mod.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformWorld(final byte[] classBytes) {
    final String names[];

    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "updateWeatherBody", "func_72896_J", "func_72911_I" };
    else/*www. j ava 2 s. c  o  m*/
        names = new String[] { "updateWeatherBody", "isRaining", "isThundering" };

    final String targetName[] = new String[] { "updateWeatherBody", "isRaining", "isThundering" };

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);

    for (final MethodNode m : cn.methods) {
        int idx = -1;
        if (m.name.equals(names[0]))
            idx = 0;
        else if (m.name.equals(names[1]))
            idx = 1;
        else if (m.name.equals(names[2]))
            idx = 2;
        else
            continue;

        logger.debug("Hooking " + names[idx]);
        InsnList list = new InsnList();
        list.add(new VarInsnNode(ALOAD, 0));
        final String sig;
        if (idx == 0)
            sig = "(Lnet/minecraft/world/World;)V";
        else
            sig = "(Lnet/minecraft/world/World;)Z";

        list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/server/WorldHandler",
                targetName[idx], sig, false));

        if (idx == 0)
            list.add(new InsnNode(RETURN));
        else
            list.add(new InsnNode(IRETURN));
        m.instructions.insertBefore(m.instructions.getFirst(), list);
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.mod.DynSurround.asm.Transformer.java

License:MIT License

private byte[] transformSoundManager(final byte[] classBytes) {
    final String names[];

    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_188770_e" };
    else/*from   www  . j a v a  2 s. co m*/
        names = new String[] { "getClampedVolume" };

    final String targetName[] = new String[] { "getClampedVolume" };

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);

    for (final MethodNode m : cn.methods) {
        if (m.name.equals(names[0])) {
            logger.debug("Hooking " + names[0]);
            final InsnList list = new InsnList();
            list.add(new VarInsnNode(ALOAD, 1));
            final String sig = "(Lnet/minecraft/client/audio/ISound;)F";
            list.add(new MethodInsnNode(INVOKESTATIC,
                    "org/blockartistry/mod/DynSurround/client/sound/SoundManager", targetName[0], sig, false));
            list.add(new InsnNode(FRETURN));
            m.instructions.insertBefore(m.instructions.getFirst(), list);
            break;
        }
    }

    final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.mod.Jiffy.asm.Transformer.java

License:MIT License

private byte[] transformMathUtils(final byte[] classBytes) {

    String names[] = null;//ww  w  .j a v a 2 s.  com

    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_76126_a", "func_76134_b" };
    else
        names = new String[] { "sin", "cos" };

    final String targetName[] = new String[] { "sin", "cos" };

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);

    for (final MethodNode m : cn.methods) {
        int targetId = -1;
        if (m.name.equals(names[0]))
            targetId = 0;
        else if (m.name.equals(names[1]))
            targetId = 1;

        if (targetId != -1) {
            m.localVariables = null;
            m.instructions.clear();
            m.instructions.add(new VarInsnNode(FLOAD, 0));
            final String sig = "(F)F";
            m.instructions.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/util/MathHelper",
                    targetName[targetId], sig, false));
            m.instructions.add(new InsnNode(FRETURN));
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}

From source file:org.blockartistry.mod.Jiffy.asm.Transformer.java

License:MIT License

private byte[] transformBlockLeaves(final byte[] classBytes) {
    String names[] = null;//from  w  w  w . java2s .  co  m

    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "beginLeavesDecay" };
    else
        names = new String[] { "beginLeavesDecay" };

    final String targetName[] = new String[] { "beginLeavesDecay" };

    final ClassReader cr = new ClassReader(classBytes);
    final ClassNode cn = new ClassNode(ASM5);
    cr.accept(cn, 0);

    for (final MethodNode m : cn.methods) {
        if (m.name.equals(names[0])) {
            m.localVariables = null;
            m.instructions.clear();
            m.instructions.add(new VarInsnNode(ALOAD, 1));
            m.instructions.add(new VarInsnNode(ILOAD, 2));
            m.instructions.add(new VarInsnNode(ILOAD, 3));
            m.instructions.add(new VarInsnNode(ILOAD, 4));
            final String sig = "(Lnet/minecraft/world/World;III)V";
            m.instructions.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/block/BlockLeaves",
                    targetName[0], sig, false));
            m.instructions.add(new InsnNode(RETURN));
            break;
        }
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    cn.accept(cw);
    return cw.toByteArray();
}