Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.22 KB | None | 0 0
  1. private byte[] transformCommandBroadcast(byte[] byteCode) {
  2.         ClassNode classNode = new ClassNode();
  3.         ClassReader classReader = new ClassReader(byteCode);
  4.         classReader.accept(classNode, 0);
  5.         for (MethodNode m : classNode.methods)
  6.             if (m.name.equals("processCommand") || m.name.equals("func_71515_b")) {
  7.                 Iterator<AbstractInsnNode> nodes = m.instructions.iterator();
  8.                 int opCount = 0;
  9.                 while (nodes.hasNext()) {
  10.                     AbstractInsnNode node = nodes.next();
  11.                     if (node.getOpcode() == INVOKEVIRTUAL && opCount < 2)
  12.                         opCount++;
  13.                     else if (node.getOpcode() == INVOKEVIRTUAL && opCount == 2){
  14.                         InsnList instructions = new InsnList();
  15.                         instructions.add(new VarInsnNode(ALOAD, 1));
  16.                         instructions.add(new VarInsnNode(ALOAD, 3));
  17.                         instructions.add(new MethodInsnNode(INVOKESTATIC, "com/austinv11/collectiveframework/minecraft/hooks/CommonHooks", "onCommandBroadcast", "(Lnet/minecraft/command/ICommandSender;Lnet.minecraft.util.IChatComponent;)V", false));
  18.                         m.instructions.insert(node, instructions);
  19.                         break;
  20.                     }
  21.                 }
  22.             }
  23.         ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  24.         classNode.accept(writer);
  25.         return writer.toByteArray();
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement