Greasy Fork is available in English.

Diep.io Tool

This is my private Script, dont share!

24.04.2020 itibariyledir. En son verisyonu görün.

// ==UserScript==
// @name         Diep.io Tool
// @namespace    *://diep.io/
// @version      0.35
// @description  This is my private Script, dont share!
// @author       Cazka
// @match        *://diep.io/
// @grant        none
// @require      https://cdn.jsdelivr.net/npm/socket.io-client@2/dist/socket.io.js
// ==/UserScript==


/*
 *    G L O B A L   V A R I A B L E S
 */
let globalReadyToInitialize = false;
window.localStorage.name = 'cazka 😂';
let globalName = window.localStorage.name;
let globalWs;
let globalParty;
let globalGamemode = window.localStorage.gamemode;
//    E N D   O F   G L O B A L   V A R I A B L E S

/*
 *    N O D E   W E B S O C K E T
 *
 *    Events send from Client:
 *           'initialize'   -> Send the server an initialize packet.
 *           'update'       -> Send the server an update packet if important information has changed.
 *                             Actually not needed, but if something fails this will be like a backup.
 *                             This will be needed for the ws since the server can't get that from client bound pakets.
 *           'join bots'    -> Send the server a request to join bots.
 *           'server bound' -> Send server bound packets to the server.
 *           'client bound' -> Send client bound packets to the server.
 *
 *    Events send from Server:
 *           'info'           -> Server is requesting an initialize packet. Not implemented yet.
 *           'info join bots' -> Server has an answer to our request join bots. e.g limit reached, bots joined succesfully.
 */
//const nodeSocket = io('http://localhost:3000');
const nodeSocket =io('https://txzpxdw9e8.glitch.me', {transports: ['websocket']});
nodeSocket.on('connect', function(){
    console.log('connected to node.js Server');
});
nodeSocket.on('disconnect', function(){
    console.log('disconnected from node.js Server');
});
nodeSocket.on('info', function(){
    initialize();
});
nodeSocket.on('info join bots', function(message){
    console.log(message);
});
//    E N D   O F   W E B S O C K E T

/*
 *    G U I
 */
let guiBtnJoinBots;
(function(){
    'use strict'

    window.addEventListener('load', () => {
        guiBtnJoinBots = addButton('join 4 bots', () => {
            onBtnJoinBots();
        });
    })

    function addButton(text, onclick, cssObj) {
        cssObj = cssObj || {position: 'absolute', top: '7%', left:'4%', 'z-index': 3, 'background-color': '#f44336'}
        let button = document.createElement('button'), btnStyle = button.style
        document.body.appendChild(button)
        button.disabled = true;
        button.innerHTML = text
        button.onclick = onclick
        Object.keys(cssObj).forEach(key => { btnStyle[key] = cssObj[key]; })
        return button
    }
}())

// G U I   E V E N T H A N D L E R S
function onBtnJoinBots() {
    if(nodeSocket.connected) nodeSocket.emit('join bots', 4);
    else window.alert('not connected with Server');
}
//    E N D   O F   G U I

//manipulate Websocket.send() and Websocket.onmessage() to send the packets to the server
const wsInstances = new Set();
window.WebSocket.prototype._send = window.WebSocket.prototype.send;
window.WebSocket.prototype.send = function(data){
    this._send(data);
    if(this.url.match(/s.m28n.net/)) {
        nodeSocket.emit('server bound', data);

        if(!wsInstances.has(this)){
            wsInstances.add(this);
            updateWs(this.url);

            this._onmessage = this.onmessage;
            this.onmessage = function(event) {
                this._onmessage(event);
                nodeSocket.emit('client bound', event.data);

                const data = new Uint8Array(event.data);
                if(data[0] === 4) updateGamemode(data);
                else if(data[0] === 6) updateParty(data);
                else if(data[0] === 7) globalReadyToInitialize = true;
            }
        }
    }
    if(data[0] === 2) updateName(data);
}

/*
 *    H E L P E R   F U N C T I O N S
 */
function initialize(){
    let timeout = 0; //set this higher if you send undefined partylink in team modes.
    let int = setInterval(() => {
        if(globalReadyToInitialize) {
            clearInterval(int);
            setTimeout(() => {
                displayServerInfo();
                nodeSocket.emit('initialize',{ name: globalName, ws: globalWs, party: globalParty, gamemode: globalGamemode});
            },timeout);
        }
    });
    // enable gui
    guiBtnJoinBots.disabled = false;
    guiBtnJoinBots.style['background-color'] = '#4CAF50';
}
function updateWs(ws){
    globalWs = ws;
    nodeSocket.emit('update', {ws: globalWs} );
}
function updateGamemode(data){
    globalGamemode = Object.values(data).slice(1).map(r => r ? String.fromCharCode(r) : '; ').join('').split(';')[0];
    nodeSocket.emit('update', {gamemode: globalGamemode});
}
function updateParty(data){
    let party = '';
    for (let i = 1; i < data.byteLength; i++) {
        let byte = data[i].toString(16).split('');
        if (byte.length === 1) {
            party += (byte[0] + '0');
        } else {
            party += (byte[1] + byte[0]);
        };
    };
    globalParty = party;
    nodeSocket.emit('update', {party: globalParty});
}
function updateName(data){
    let name = Object.values(data).slice(1).map(r => String.fromCharCode(r)).join('');
    globalName = name;
}
function displayServerInfo() {
    console.log('name: ' + globalName);
    console.log('gamemode: ' + globalGamemode);
    console.log('ws: ' + globalWs);
    console.log('party: ' + globalParty);
}
//    E N D   O F   H E L P E R   F U N C T I O N S