Search in sources :

Example 56 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project BetterRain by OreCruncher.

the class Transformer method transformSoundManager.

private byte[] transformSoundManager(final byte[] classBytes) {
    final String[] names;
    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_148594_a" };
    else
        names = new String[] { "getNormalizedVolume" };
    final String[] targetName = new String[] { "getNormalizedVolume" };
    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));
            list.add(new VarInsnNode(ALOAD, 2));
            list.add(new VarInsnNode(ALOAD, 3));
            final String sig = "(Lnet/minecraft/client/audio/ISound;Lnet/minecraft/client/audio/SoundPoolEntry;Lnet/minecraft/client/audio/SoundCategory;)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();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) ClassWriter(org.objectweb.asm.ClassWriter)

Example 57 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project BetterRain by OreCruncher.

the class Transformer method transformEntityRenderer.

private byte[] transformEntityRenderer(final byte[] classBytes) {
    final String[] names;
    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_78474_d", "func_78484_h" };
    else
        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]);
            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]);
            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();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) ClassWriter(org.objectweb.asm.ClassWriter)

Example 58 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project BetterRain by OreCruncher.

the class Transformer method transformWorld.

private byte[] transformWorld(final byte[] classBytes) {
    final String[] names;
    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "updateWeatherBody" };
    else
        names = new String[] { "updateWeatherBody" };
    final String[] targetName = new String[] { "updateWeatherBody" };
    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/World;)V";
            list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/server/WorldHandler", 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();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) ClassWriter(org.objectweb.asm.ClassWriter)

Example 59 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project BetterRain by OreCruncher.

the class Transformer method transformWorldServer.

private byte[] transformWorldServer(final byte[] classBytes) {
    final String[] names;
    if (TransformLoader.runtimeDeobEnabled)
        names = new String[] { "func_73051_P" };
    else
        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();
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) InsnNode(org.objectweb.asm.tree.InsnNode) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode) ClassReader(org.objectweb.asm.ClassReader) InsnList(org.objectweb.asm.tree.InsnList) VarInsnNode(org.objectweb.asm.tree.VarInsnNode) ClassWriter(org.objectweb.asm.ClassWriter)

Example 60 with MethodNode

use of org.objectweb.asm.tree.MethodNode in project Galacticraft by micdoodle8.

the class MCPDeobfuscationTransformer method injectCallback.

private byte[] injectCallback(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes);
    MethodNode mnode = ASMHelper.findMethod(new ObfMapping(cnode.name, "<clinit>", "()V"), cnode);
    mnode.instructions.insert(new MethodInsnNode(INVOKESTATIC, "codechicken/core/asm/MCPDeobfuscationTransformer", "loadCallback", "()V"));
    return ASMHelper.createBytes(cnode, 0);
}
Also used : ClassNode(org.objectweb.asm.tree.ClassNode) ObfMapping(codechicken.lib.asm.ObfMapping) MethodNode(org.objectweb.asm.tree.MethodNode) MethodInsnNode(org.objectweb.asm.tree.MethodInsnNode)

Aggregations

MethodNode (org.objectweb.asm.tree.MethodNode)322 ClassNode (org.objectweb.asm.tree.ClassNode)123 Test (org.junit.Test)94 AbstractInsnNode (org.objectweb.asm.tree.AbstractInsnNode)59 ClassReader (org.objectweb.asm.ClassReader)57 InsnList (org.objectweb.asm.tree.InsnList)49 MethodInsnNode (org.objectweb.asm.tree.MethodInsnNode)47 Label (org.objectweb.asm.Label)44 VarInsnNode (org.objectweb.asm.tree.VarInsnNode)41 InsnNode (org.objectweb.asm.tree.InsnNode)34 ClassWriter (org.objectweb.asm.ClassWriter)26 FieldNode (org.objectweb.asm.tree.FieldNode)26 JumpInsnNode (org.objectweb.asm.tree.JumpInsnNode)26 ArrayList (java.util.ArrayList)24 FieldInsnNode (org.objectweb.asm.tree.FieldInsnNode)24 LdcInsnNode (org.objectweb.asm.tree.LdcInsnNode)21 LabelNode (org.objectweb.asm.tree.LabelNode)19 TypeInsnNode (org.objectweb.asm.tree.TypeInsnNode)19 List (java.util.List)17 Type (org.objectweb.asm.Type)17