content: package eu.the5zig.mod.asm.transformers;
  
  import eu.the5zig.mod.asm.LogUtil;
  import eu.the5zig.mod.asm.Names;
  import net.minecraft.launchwrapper.IClassTransformer;
  import org.objectweb.asm.ClassReader;
  import org.objectweb.asm.ClassVisitor;
  import org.objectweb.asm.ClassWriter;
  import org.objectweb.asm.MethodVisitor;
  
  import static org.objectweb.asm.Opcodes.*;
  
  /**
   * Created by 5zig.
   * All rights reserved © 2015
   */
  public class PatchEntityPlayerSP implements IClassTransformer {
  
  	@Override
  	public byte[] transform(String s, String s1, byte[] bytes) {
  		LogUtil.startClass("EntityPlayerSP (%s)", Names.abstractClientPlayer.getName());
  
  		ClassReader reader = new ClassReader(bytes);
  		ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS);
  		ClassPatcher visitor = new ClassPatcher(writer);
  		reader.accept(visitor, 0);
  		LogUtil.endClass();
  		return writer.toByteArray();
  	}
  
  	public class ClassPatcher extends ClassVisitor {
  
  		public ClassPatcher(ClassVisitor visitor) {
  			super(ASM5, visitor);
  		}
  
  		@Override
  		public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
  			if (Names.sendChatMessage.equals(name, desc)) {
  				LogUtil.startMethod(Names.sendChatMessage.getName() + " " + Names.sendChatMessage.getDesc());
  				return new PatchSendChatMessage(cv.visitMethod(access, name, desc, signature, exceptions));
  			}
  			LogUtil.endMethod();
  			return super.visitMethod(access, name, desc, signature, exceptions);
  		}
  
  	}
  
  	public class PatchSendChatMessage extends MethodVisitor {
  
  		public PatchSendChatMessage(MethodVisitor methodVisitor) {
  			super(ASM5, methodVisitor);
  		}
  
  		@Override
  		public void visitCode() {
  			super.visitCode();
  			LogUtil.log("sendChatMessage");
  			mv.visitVarInsn(ALOAD, 1);
  			mv.visitMethodInsn(INVOKESTATIC, "BytecodeHook", "onSendChatMessage", "(Ljava/lang/String;)V", false);
  			mv.visitInsn(RETURN);
  		}
  
  	}
  
  }
  