I've switched my code to use ASM now - it works perfectly fine!
For everyone reading this thread, who is interested in how I solved my problem:
private byte[] patchClass(String name, byte[] bytes, boolean obfuscated) throws NotFoundException, CannotCompileException, IOException, ClassNotFoundException, IllegalArgumentException, IllegalAccessException {
String methodName = obfuscated ? "func_147274_a" : "handleTabComplete";
String nhpc = "net/minecraft/client/network/NetHandlerPlayClient";
String gc = obfuscated ? "field_147299_f" : "gameController";
String mc = "net/minecraft/client/Minecraft";
String cs = obfuscated ? "field_71462_r" : "currentScreen";
String gs = "net/minecraft/client/gui/GuiScreen";
String desc = "(Lnet/minecraft/network/play/server/S3APacketTabComplete;)V";
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
int i = 0;
Iterator<MethodNode> methods = classNode.methods.iterator();
while(methods.hasNext()) {
MethodNode m = methods.next();
int fdiv_index = -1;
if(m.name.equals(methodName) && m.desc.equals(desc)) {
int ix = 0;
for(ix = 0; ix<m.instructions.size(); ix++) {
AbstractInsnNode node = m.instructions.get(ix);
if(node instanceof InsnNode) {
if(((InsnNode)node).getOpcode() == Opcodes.RETURN) {
break;
}
}
}
LabelNode ln = new LabelNode(new Label());
InsnList toInject = new InsnList();
//mv.visitVarInsn(ALOAD, 0);
toInject.add(new VarInsnNode(Opcodes.ALOAD, 0));
//mv.visitFieldInsn(GETFIELD, "net/minecraft/client/network/NetHandlerPlayClient", "gameController", "Lnet/minecraft/client/Minecraft;");
toInject.add(new FieldInsnNode(Opcodes.GETFIELD, nhpc, gc, "L"+mc+";"));
//mv.visitFieldInsn(GETFIELD, "net/minecraft/client/Minecraft", "currentScreen", "Lnet/minecraft/client/gui/GuiScreen;");
toInject.add(new FieldInsnNode(Opcodes.GETFIELD, mc, cs, "L"+gs+";"));
//mv.visitTypeInsn(INSTANCEOF, "net/minecraft/client/gui/GuiChat");
toInject.add(new TypeInsnNode(Opcodes.INSTANCEOF, "eu/crushedpixel/commandsyntax/gui/GuiSyntaxCommandBlock"));
Label skipLabel = new Label();
//mv.visitJumpInsn(IFEQ, l3);
toInject.add(new JumpInsnNode(Opcodes.IFEQ, ln));
//mv.visitVarInsn(ALOAD, 0);
toInject.add(new VarInsnNode(Opcodes.ALOAD, 0));
//mv.visitFieldInsn(GETFIELD, "net/minecraft/client/network/NetHandlerPlayClient", "gameController", "Lnet/minecraft/client/Minecraft;");
toInject.add(new FieldInsnNode(Opcodes.GETFIELD, nhpc, gc, "L"+mc+";"));
//mv.visitFieldInsn(GETFIELD, "net/minecraft/client/Minecraft", "currentScreen", "Lnet/minecraft/client/gui/GuiScreen;");
toInject.add(new FieldInsnNode(Opcodes.GETFIELD, mc, cs, "L"+gs+";"));
//mv.visitTypeInsn(CHECKCAST, "net/minecraft/client/gui/GuiChat");
toInject.add(new TypeInsnNode(Opcodes.CHECKCAST, "eu/crushedpixel/commandsyntax/gui/GuiSyntaxCommandBlock"));
//mv.visitVarInsn(ASTORE, 3);
toInject.add(new VarInsnNode(Opcodes.ASTORE, 3));
//mv.visitVarInsn(ALOAD, 3);
toInject.add(new VarInsnNode(Opcodes.ALOAD, 3));
//mv.visitVarInsn(ALOAD, 2);
toInject.add(new VarInsnNode(Opcodes.ALOAD, 2));
//mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/client/gui/GuiChat", "onAutocompleteResponse", "([Ljava/lang/String;)V", false);
toInject.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "eu/crushedpixel/commandsyntax/gui/GuiSyntaxCommandBlock", "onAutocompleteResponse", "([Ljava/lang/String;)V", false));
toInject.add(ln);
m.instructions.insert(m.instructions.get(ix-1), toInject);
}
i++;
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
I am very fond of the great support I received here in the Forums - excellent work <3
This thread is Solved.