Dstool by doritos

Agario extention with Zoom / Macro Feed / Double Split / Shift

// ==UserScript==
// @name         Dstool by doritos
// @namespace    asd
// @version      1.0.0
// @description  Agario extention with Zoom / Macro Feed / Double Split / Shift
// @author       Doritos
// @match        *://agar.io/*
// @require      https://code.jquery.com/jquery-3.3.1.min.js
// @run-at       document-body
// @grant        none
// ==/UserScript==

//Mousewheel zoom
class mouseWheelZoom {
  constructor() {
    this.mOX = 0;
    this.mOY = 0;
    this.zoomValue = 0;
    this.cellX = 0;
    this.cellY = 0;


  }
  createBuffer(length) {
    return new DataView(new ArrayBuffer(length));
  }
  sendBuffer(buf) {
    if(this.ws && this.ws.readyState == 1) this.ws.send(buf);
  }



  sendMousePacket() {
    let buffer = this.createBuffer(29);
    buffer.setUint8(0, 4);
    buffer.setFloat64(1, ((window.clientXXX - window.innerWidth / 2) / this.zoomValue) + this.cellX, true);
    buffer.setFloat64(9, ((window.clientYYY - window.innerHeight / 2) / this.zoomValue) + this.cellY, true);
    buffer.setFloat64(17, 0, true);
    buffer.setUint32(25, true);
    this.sendBuffer(buffer);
  }

}

var observer = new MutationObserver(function(mutations){
  mutations.forEach(function(mutation) {
    mutation.addedNodes.forEach(function(node) {
      if (/agario\.core\.js/i.test(node.src)){
        observer.disconnect();
        node.parentNode.removeChild(node);
        var request = new XMLHttpRequest();
        request.open("get", node.src, true);
        request.send();
        request.onload = function(){
          var coretext = this.responseText;
          var newscript = document.createElement("script");
          newscript.type = "text/javascript";
          newscript.async = true;
          window._op = new mouseWheelZoom();
          newscript.textContent = replaceCore(coretext);
          document.body.appendChild(newscript);
        };
      }
    });
  });
});
observer.observe(document, {attributes:true, characterData:true, childList:true, subtree:true});

const replaceCore = core => {
  core = core.replace(/;if\((\w)<1\.0\){/i, `;if(0){`);
  core = core.replace(/(\w\[\w>>\d\]=\w\?\w:\w;)((\w).*?;)/i, `var nodesize=$1 $2`);
  //core = core.replace(/(\w\[\w>>\d\]=\w\?\w:\w;)((\w).*?;)/i, `var nodesize=$1 $2 $3=true;`);
  core = core.replace(/0;\w\[\w\+...>>3\]=(\w);\w\[\w\+...>>3\]=(\w);\w\[\w\+...>>3\]=(\w);\w\[\w\+...>>3\]=(\w);/i, `$& if(Math.abs($3-$1)>14e3 && Math.abs($4-$2)>14e3){window._op.mOX = ($1+$3)/2; window._op.mOY = ($2+$4)/2};`);
  core = core.replace(/\w+\(\d+,\w+\[\w+>>2\]\|0,\+\-(\+\w\[\w+\+\d+>>3\]),\+\-(\+\w+\[\w\+\d+>>3\])\)\|0;/i, `$& window._op.sendMousePacket(); window._op.cellX = $1 - window._op.mOX; window._op.cellY = $2 - window._op.mOY;`);
  core = core.replace(/([\w$]+\(\d+,\w\[\w>>2\]\|0,(\+\w),(\+\w)\)\|0;[\w$]+\(\d+,\w\[\w>>2\]\|0,\+-(\+\w\[\w\+\d+>>3\]),\+-(\+\w\[\w\+\d+>>3\])\)\|0;)/i, `$1 window._op.zoomValue=$2;`)
  core = core.replace(/\w\.MC\.onPlayerSpawn\)/i, `$& window._op.sendParty();`);
  return core;
}


// Instructions & ads remove
$(document).ready(function() {
  $('#mainui-play').css({
    'height': '400px'
  });
  $("#title").text('Dstool');
  $("#instructions").append('<center><span class=\'text-muted\'> Press <b>Q</b> to double split</span></center>');
  $("#instructions").append('<center><span class=\'text-muted\'> Press <b>SHIFT</b> to 16 split</span></center>');
  $("#instructions").append('<center><span class=\'text-muted\'> Press <b>S</b> to freeze / stop cell</span></center>');
  $("#instructions").append('<center><span class=\'text-muted\'> Press and hold <b>W</b> to macro feed</span></center>');



  $('#advertisement').remove();
  $('#mainui-promo').remove();
  $('#adsGameOver').remove();
  $('#mainui-ads').remove();
  $('#adsBottom').remove();
});

$(document).ready(function() {
  $('#mainui-party').css({
    'height': '200px'
  });

  $("#mainui-party").append('<hr>');
  $("#mainui-party").append('<h4 data-v-3152cd5c="" class="party-title"><span data-v-3152cd5c="" class="party-title">♻ Auto respawn</span></h4>');
  $("#mainui-party").append('<div data-v-3152cd5c="" class="party-text">In progress..</div>');
});



window.addEventListener('keydown', keydown);
window.addEventListener('keyup', keyup);

var EjectDown = false;
var speed = 25; //in ms

function keydown(event) {
    if (event.keyCode == 87 && EjectDown === false) { // key W
        EjectDown = true;
        setTimeout(eject, speed);
    }
    if (event.keyCode == 81) { //Double split Q
        split();
        setTimeout(split, speed);
    }
    if (event.keyCode == 16) { //Shift 16 split
        split();
        setTimeout(split, speed);
        setTimeout(split, speed*2);
        setTimeout(split, speed*3);
    }
    if (event.keyCode == 83) { //key S
        X = window.innerWidth/2;
        Y = window.innerHeight/2;
        $("canvas").trigger($.Event("mousemove", {clientX: X, clientY: Y}));
    }
}

function keyup(event) {
    if (event.keyCode == 87) { // key W
        EjectDown = false;
    }
}

function eject() {
    if (EjectDown) {
        window.onkeydown({keyCode: 87}); // key W
        window.onkeyup({keyCode: 87});
        setTimeout(eject, speed);
    }
}

function split() {
    $("body").trigger($.Event("keydown", { keyCode: 32})); //key space
    $("body").trigger($.Event("keyup", { keyCode: 32})); //jquery is required for split to work
}




//FPS counter
$(document).ready(function(){

    $("body").append('<div id="fpsbg" style="position:absolute; top:5px; left:5px; background-color:rgba(0,0,0,0.3); color:#ffffff;  padding:5px;border-radius:5px;">🎞️ FPS: <span id="fps"></span></div>');


const fps = {
    sampleSize : 60,
    value : 0,
    _sample_ : [],
    _index_ : 0,
    _lastTick_: false,
    tick : function(){
        // if is first tick, just set tick timestamp and return
        if( !this._lastTick_ ){
            this._lastTick_ = performance.now();
            return 0;
        }
        // calculate necessary values to obtain current tick FPS
        let now = performance.now();
        let delta = (now - this._lastTick_)/1000;
        let fps = 1/delta;
        // add to fps samples, current tick fps value
        this._sample_[ this._index_ ] = Math.round(fps);

        // iterate samples to obtain the average
        let average = 0;
        for(i=0; i<this._sample_.length; i++) average += this._sample_[ i ];

        average = Math.round( average / this._sample_.length);

        // set new FPS
        this.value = average;
        // store current timestamp
        this._lastTick_ = now;
        // increase sample index counter, and reset it
        // to 0 if exceded maximum sampleSize limit
        this._index_++;
        if( this._index_ === this.sampleSize) this._index_ = 0;
        return this.value;
    }
}

function loop(){
    let fpsValue = fps.tick();
    window.fps.innerHTML = fpsValue;
    requestAnimationFrame( loop );
}
// set FPS calulation based in the last 120 loop cicles
fps.sampleSize = 120;
// start loop
loop();

});