Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void transformEntityPlayerSP(ClassNode entityPlayerSPClass, boolean obfuscated) {
- final String ADD_CHAT_COMPONENT_MESSAGE = (obfuscated) ? "b" : "addChatComponentMessage";
- final String ADD_CHAT_COMPONENT_DESCRIPTOR = (obfuscated) ? "(Lfj;)V" : "(Lnet/minecraft/util/IChatComponent;)V";
- // Find target node
- MethodNode targetMethod = findTargetNode(entityPlayerSPClass, ADD_CHAT_COMPONENT_MESSAGE, ADD_CHAT_COMPONENT_DESCRIPTOR);
- if(targetMethod == null)
- return;
- AbstractInsnNode targetNode = null;
- for(AbstractInsnNode instruction : targetMethod.instructions.toArray()){
- if(instruction.getOpcode() == ALOAD){
- if(((VarInsnNode) instruction).var == 0 && instruction.getNext().getOpcode() == GETFIELD){
- targetNode = instruction;
- break;
- }
- }
- }
- if(targetNode == null)
- return;
- /*
- Replace:
- this.mc.ingameGui.getChatGUI().printChatMessage(p_146105_1_);
- WITH:
- if(!ChatHandler.hasHandledChat(p_146105_1_){
- this.mc.ingameGui.getChatGUI().printChatMessage();
- }
- BYTECODE:
- REPLACE:
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, "net/minecraft/client/entity/EntityPlayerSP", "mc", "Lnet/minecraft/client/Minecraft;");
- v.visitFieldInsn(GETFIELD, "net/minecraft/client/Minecraft", "ingameGUI", "Lnet/minecraft/client/gui/GuiIngame;");
- mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/client/gui/GuiIngame", "getChatGUI", "()Lnet/minecraft/client/gui/GuiNewChat;", false);
- mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/client/gui/GuiNewChat", "printChatMessage", "(Lnet/minecraft/util/IChatComponent;)V", false);
- WIT
- ALOAD 1
- INVOKESTATIC me/mrkirby153/AntiChatSpam/regex/ChatHandler.hasHandledChat (Lnet/minecraft/util/IChatComponent;)Z
- IFEQ newLabelNode
- newLableNode
- RETURN
- mv.visitVarInsn(ALOAD, 0);
- mv.visitFieldInsn(GETFIELD, "net/minecraft/client/entity/EntityPlayerSP", "mc", "Lnet/minecraft/client/Minecraft;");
- v.visitFieldInsn(GETFIELD, "net/minecraft/client/Minecraft", "ingameGUI", "Lnet/minecraft/client/gui/GuiIngame;");
- mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/client/gui/GuiIngame", "getChatGUI", "()Lnet/minecraft/client/gui/GuiNewChat;", false);
- mv.visitVarInsn(ALOAD, 1);
- mv.visitMethodInsn(INVOKEVIRTUAL, "net/minecraft/client/gui/GuiNewChat", "printChatMessage", "(Lnet/minecraft/util/IChatComponent;)V", false);
- LABEL newLabelNode
- */
- AbstractInsnNode insertPoint = targetNode.getPrevious();
- LabelNode returnLabel = new LabelNode();
- InsnList toInsert = new InsnList();
- Type chatHandlerType = Type.getType(ChatHandler.class);
- String handlerDescriptor;
- String thingsDescriptor;
- try {
- handlerDescriptor = Type.getMethodDescriptor(ChatHandler.class.getMethod("hasHandledChat", IChatComponent.class));
- thingsDescriptor = Type.getMethodDescriptor(ChatHandler.class.getMethod("doThings"));
- } catch (Exception e){
- logger.catching(e);
- return;
- }
- toInsert.add(new VarInsnNode(ALOAD, 1));
- toInsert.add(new MethodInsnNode(INVOKESTATIC, chatHandlerType.getInternalName(), "hasHandledChat", handlerDescriptor, false));
- toInsert.add(new JumpInsnNode(IFNE, returnLabel));
- toInsert.add(returnLabel);
- toInsert.add(new InsnNode(RETURN));
- targetMethod.instructions.insert(insertPoint, toInsert);
- // AbstractInsnNode invokeVirtualPrint = targetNode;
- // for(int i = 0; i < 5; i++){
- // invokeVirtualPrint = invokeVirtualPrint.getNext();
- // }
- // LabelNode newLabelNode = new LabelNode();
- // InsnList toInsert = new InsnList();
- // toInsert.add(new VarInsnNode(ALOAD, 1));
- // final String HAS_HANDLED_CHAT_DESCRIPTOR = (obfuscated)? "(Lfj;)V" : "(Lnet/minecraft/util/IChatComponent;)V";
- // toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(ChatHandler.class), "hasHandledChat", HAS_HANDLED_CHAT_DESCRIPTOR, false));
- // toInsert.add(new JumpInsnNode(IFNE, newLabelNode));
- //
- // targetMethod.instructions.insertBefore(targetNode, toInsert);
- // targetMethod.instructions.insert(invokeVirtualPrint, newLabelNode);
- //
- for(AbstractInsnNode n : targetMethod.instructions.toArray()){
- System.out.println(n.getOpcode());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment