<commit_before>package net.blay09.mods.trashslot.coremod;

import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

public class TrashSlotClassTransformer implements IClassTransformer {

    public static final String OBF_CLASS = "bex";
    public static final String MCP_CLASS = "net.minecraft.client.gui.inventory.GuiContainer";
    public static final String OBF_METHOD_MOVEDORUP = "func_146286_b";
    public static final String MCP_METHOD_MOVEDORUP = "mouseMovedOrUp";
    public static final String OBF_METHOD_CLICKED = "func_73864_a";
    public static final String MCP_METHOD_CLICKED = "mouseClicked";
    private static final String METHOD_DESC = "(III)V";

    @Override
    public byte[] transform(String className, String transformedClassName, byte[] bytes) {
        String methodNameMovedOrUp;
        String methodNameClicked;
        if(className.equals(OBF_CLASS)) {
            methodNameMovedOrUp = OBF_METHOD_MOVEDORUP;
            methodNameClicked = OBF_METHOD_CLICKED;
        } else if(className.equals(MCP_CLASS)) {
            methodNameMovedOrUp = MCP_METHOD_MOVEDORUP;
            methodNameClicked = MCP_METHOD_CLICKED;
        } else {
            return bytes;
        }
        ClassNode classNode = new ClassNode();
        ClassReader classReader = new ClassReader(bytes);
        classReader.accept(classNode, 0);
        for(MethodNode method : classNode.methods) {
            if(method.name.equals(methodNameMovedOrUp) && method.desc.equals(METHOD_DESC)) {
                MethodNode mn = new MethodNode();
                mn.visitVarInsn(Opcodes.ILOAD, 7); // push flag
                mn.visitVarInsn(Opcodes.ILOAD, 1); // push mouseX
                mn.visitVarInsn(Opcodes.ILOAD, 2); // push mouseY
                mn.visitMethodInsn(Opcodes.INVOKESTATIC, "net/blay09/mods/trashslot/TrashSlot", "canDropStack", "(ZII)Z", false);
                mn.visitVarInsn(Opcodes.ISTORE, 7); // pop into flag1
                final int insertOffset = 55;
                method.instructions.insertBefore(method.instructions.get(insertOffset), mn.instructions);
            } else if(method.name.equals(methodNameClicked) && method.desc.equals(METHOD_DESC)) {
                MethodNode mn = new MethodNode();
                mn.visitVarInsn(Opcodes.ILOAD, 10); // push flag1
                mn.visitVarInsn(Opcodes.ILOAD, 1); // push mouseX
                mn.visitVarInsn(Opcodes.ILOAD, 2); // push mouseY
                mn.visitMethodInsn(Opcodes.INVOKESTATIC, "net/blay09/mods/trashslot/TrashSlot", "canDropStack", "(ZII)Z", false);
                mn.visitVarInsn(Opcodes.ISTORE, 10); // pop into flag1
                final int insertOffset = 119;
                method.instructions.insertBefore(method.instructions.get(insertOffset), mn.instructions);
            }
        }
        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        classNode.accept(writer);
        return writer.toByteArray();
    }

}<commit_msg>Don't use a fixed offset for the class patch or we'll conflict with other coremods.<commit_after>package net.blay09.mods.trashslot.coremod;

import net.minecraft.launchwrapper.IClassTransformer;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;

public class TrashSlotClassTransformer implements IClassTransformer {

    public static final String OBF_CLASS = "bex";
    public static final String MCP_CLASS = "net.minecraft.client.gui.inventory.GuiContainer";
    public static final String OBF_METHOD_MOVEDORUP = "func_146286_b";
    public static final String MCP_METHOD_MOVEDORUP = "mouseMovedOrUp";
    public static final String OBF_METHOD_CLICKED = "func_73864_a";
    public static final String MCP_METHOD_CLICKED = "mouseClicked";
    private static final String METHOD_DESC = "(III)V";

    @Override
    public byte[] transform(String className, String transformedClassName, byte[] bytes) {
        String methodNameMovedOrUp;
        String methodNameClicked;
        if(className.equals(OBF_CLASS)) {
            methodNameMovedOrUp = OBF_METHOD_MOVEDORUP;
            methodNameClicked = OBF_METHOD_CLICKED;
        } else if(className.equals(MCP_CLASS)) {
            methodNameMovedOrUp = MCP_METHOD_MOVEDORUP;
            methodNameClicked = MCP_METHOD_CLICKED;
        } else {
            return bytes;
        }
        ClassNode classNode = new ClassNode();
        ClassReader classReader = new ClassReader(bytes);
        classReader.accept(classNode, 0);
        for(MethodNode method : classNode.methods) {
            if(method.name.equals(methodNameMovedOrUp) && method.desc.equals(METHOD_DESC)) {
                MethodNode mn = new MethodNode();
                mn.visitVarInsn(Opcodes.ILOAD, 7); // push flag
                mn.visitVarInsn(Opcodes.ILOAD, 1); // push mouseX
                mn.visitVarInsn(Opcodes.ILOAD, 2); // push mouseY
                mn.visitMethodInsn(Opcodes.INVOKESTATIC, "net/blay09/mods/trashslot/TrashSlot", "canDropStack", "(ZII)Z", false);
                mn.visitVarInsn(Opcodes.ISTORE, 7); // pop into flag1
                AbstractInsnNode insertBefore = null;
                for(int i = 0; i < method.instructions.size(); i++) {
                    AbstractInsnNode node = method.instructions.get(i);
                    if(node instanceof VarInsnNode) {
                        if(node.getOpcode() == Opcodes.ISTORE && ((VarInsnNode) node).var == 7) {
                            insertBefore = node;
                            break;
                        }
                    }
                }
                if(insertBefore != null) {
                    method.instructions.insert(insertBefore, mn.instructions);
                } else {
                    System.err.println("TrashSlot failed to patch mouseMovedOrUp!");
                }
            } else if(method.name.equals(methodNameClicked) && method.desc.equals(METHOD_DESC)) {
                MethodNode mn = new MethodNode();
                mn.visitVarInsn(Opcodes.ILOAD, 10); // push flag1
                mn.visitVarInsn(Opcodes.ILOAD, 1); // push mouseX
                mn.visitVarInsn(Opcodes.ILOAD, 2); // push mouseY
                mn.visitMethodInsn(Opcodes.INVOKESTATIC, "net/blay09/mods/trashslot/TrashSlot", "canDropStack", "(ZII)Z", false);
                mn.visitVarInsn(Opcodes.ISTORE, 10); // pop into flag1
                AbstractInsnNode insertBefore = null;
                for(int i = 0; i < method.instructions.size(); i++) {
                    AbstractInsnNode node = method.instructions.get(i);
                    if(node instanceof VarInsnNode) {
                        if(node.getOpcode() == Opcodes.ISTORE && ((VarInsnNode) node).var == 10) {
                            insertBefore = node;
                            break;
                        }
                    }
                }
                if(insertBefore != null) {
                    method.instructions.insert(insertBefore, mn.instructions);
                } else {
                    System.err.println("TrashSlot failed to patch mouseMovedOrUp!");
                }
            }
        }
        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        classNode.accept(writer);
        return writer.toByteArray();
    }

}
{'fraction_non_alphanumeric': 0.09729227501990974, 'fraction_numerical': 0.009556676400318556, 'mean_word_length': 2.2689804772234274, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3439549', 'n_tokens_mistral': 2302, 'n_tokens_neox': 2164, 'n_words': 420}