File size: 5,070 Bytes
8524bea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//utility function to return an array of GuiButtons from an array of JS objects, while automatically binding them
function button_utility_script(inputArr, bindingClass, actionBindMode) {
    // By ZXMushroom63
    // action bind mode:
    // 0 - bind to the same as the binding class
    // 1 - do not bind
    // 2 - bind to GuiScreen
    actionBindMode ||= 0;
    var button = ModAPI.reflect.getClassById("net.minecraft.client.gui.GuiButton").constructors.find(x => x.length === 6);
    var originalActionPerformed = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(actionBindMode === 2 ? "net.minecraft.client.gui.GuiScreen" : bindingClass, "actionPerformed")];
    var originalInit = ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(bindingClass, "initGui")];
    var out = inputArr.flatMap(x => {
        var btn = button(x.uid, x.x, x.y, x.w, x.h, ModAPI.util.str(x.text));
        return btn;
    });
    if (actionBindMode !== 1) {
        ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(actionBindMode === 2 ? "net.minecraft.client.gui.GuiScreen" : bindingClass, "actionPerformed")] = function (...args) {
            var id = ModAPI.util.wrap(args[1]).getCorrective().id;
            var jsAction = inputArr.find(x => x.uid === id);
            if (jsAction) {
                jsAction.click(ModAPI.util.wrap(args[0]));
            }
            return originalActionPerformed.apply(this, args);
        }
    }
    ModAPI.hooks.methods[ModAPI.util.getMethodFromPackage(bindingClass, "initGui")] = function (...args) {
        originalInit.apply(this, args);
        var gui = ModAPI.util.wrap(args[0]).getCorrective();
        out.forEach(guiButton => {
            gui.buttonList.add(guiButton);
        });
    }
}


(() => {
    ModAPI.require("player");
    var backlog = [];
    var delayState = false;

    const originalSend = WebSocket.prototype.send;

    //Override WebSocket.send, so when eagler tries to send messages, it runs our code instead
    Object.defineProperty(WebSocket.prototype, 'send', {
        configurable: true,
        enumerable: false,
        writable: false,
        value: function (data) {
            //If blinking, push data to backlog along with it's websocket instance.
            if (delayState) {
                backlog.push({ data: data, thisArg: this });
            } else { //Else send the data as normal
                originalSend.call(this, data);
            }
        }
    });

    ModAPI.meta.title("Dupe Hunting");
    ModAPI.meta.description("⚠️Only works over WS, not local. May induce bans.⚠️");
    ModAPI.meta.credits("by ZXMushroom63");

    var dupeHuntButtons = [{
        text: "Silently Close",
        click: () => {
            ModAPI.minecraft.displayGuiScreen(null);
        },
        x: 0,
        y: 0,
        w: 100,
        h: 20,
        uid: 142715254
    },
    {
        text: "Toggle Delay",
        click: () => {
            delayState = !delayState;
            alert(delayState ? "Delay On" : "Sending Packets...");
            if (delayState === false) {
                for (let i = 0; i < backlog.length; i++) {
                    const backlogItem = backlog[i];
                    originalSend.call(backlogItem.thisArg, backlogItem.data);
                }
                backlog = [];
            }
        },
        x: 0,
        y: 20,
        w: 100,
        h: 20,
        uid: 142715253
    },
    {
        text: "Server Close",
        click: () => {
            var CloseWindow = ModAPI.reflect.getClassByName("C0DPacketCloseWindow").constructors[0];
            ModAPI.player.sendQueue.addToSendQueue(CloseWindow(ModAPI.player.openContainer.getCorrective().windowId));
        },
        x: 0,
        y: 40,
        w: 100,
        h: 20,
        uid: 142715252
    },
    {
        text: "Send & Disconnect",
        click: () => {
            delayState = false;
            for (let i = 0; i < backlog.length; i++) {
                const backlogItem = backlog[i];
                originalSend.call(backlogItem.thisArg, backlogItem.data);
            }
            backlog = [];
            ModAPI.mc.getNetHandler().getNetworkManager().doClientDisconnect(ModAPI.hooks._classMap[ModAPI.util.getCompiledName("net.minecraft.util.ChatComponentText")].constructors[0](ModAPI.util.str("Dupe Hunting Utils Disconnect")));
        },
        x: 0,
        y: 60,
        w: 100,
        h: 20,
        uid: 142715251
    },
    {
        text: "Use Chat",
        click: () => {
            var p = window.prompt("Input chat/command:", "Hello World");
            if (p) {
                ModAPI.player.sendChatMessage(ModAPI.util.str(p));
            }
        },
        x: 0,
        y: 80,
        w: 100,
        h: 20,
        uid: 142715250
    }];

    [
        "net.minecraft.client.gui.inventory.GuiInventory",
        "net.minecraft.client.gui.inventory.GuiContainerCreative",
        "net.minecraft.client.gui.inventory.GuiBeacon"
    ].forEach(ui => {
        button_utility_script(dupeHuntButtons, ui, 0);
    });
})();