MooMoo.io spike = v, trap = f (Working!)

''

// ==UserScript==
// @name         MooMoo.io spike = v, trap = f (Working!)
// @namespace    http://tampermonkey.net/
// @version      3.5
// @author       You
// @match                 *://moomoo.io/*
// @match                 *://sandbox.moomoo.io/*
// @match                 *://dev.moomoo.io/*
// @require               https://greasyfork.org/scripts/368273-msgpack/code/msgpack.js?version=598723
// @grant        none
// @description ''
// ==/UserScript==
var spikeKey = 118;
var trapKey = 102;
var ws;
var msgpack5 = msgpack;
var allMooMooObjects = {};
var goodData;
var coregood = [212, 0, 0, 167, 111, 112, 116, 105, 111, 110, 115, 129, 168, 99, 111, 109, 112];
var targets = [false, false];
$("#spikeControl").on("input", () => {
   var cval = $("#spikeControl").val();
    if (cval){
       spikeKey = cval.charCodeAt(0);
    }
});
$("#trapControl").on("input", () => {
   var cval = $("#trapControl").val();
    if (cval){
       trapKey = cval.charCodeAt(0);
    }
});
var botSpan;
var styleItem = document.createElement("style");
styleItem.type = "text/css";
document.head.appendChild(styleItem);
function encodeSEND(json){
    var OC = msgpack5.encode(json);
    var aAdd = Array.from(OC);
    return new Uint8Array(aAdd).buffer;
}
WebSocket.prototype.oldSend = WebSocket.prototype.send;
WebSocket.prototype.send = function(m){
    if (targets.every(x=>x==false)){
        for (var elementDiv of document.getElementsByClassName("spotDiv")){
            document.body.removeChild(elementDiv);
        }
    }

    if (!ws){
        document.ws = this;
        ws = this;
        socketFound(this);
    }
    var x = new Uint8Array(m);
    var y = Array.from(x);
    var j = [146, 161, 50, 145, 203];
    this.oldSend(m);
    var realData = {};
    var realInfo = msgpack5.decode(x);
    if (realInfo[1] instanceof Array){
    realData.data = [realInfo[0], ...realInfo[1]]
    } else {
        realData.data = realInfo;
    }
    if (realData.data[0]=="3"){
    }
    console.log(realData.data[0]);
    if (realData.data[0]=="s"){
       for (var elem of Object.values(allMooMooObjects)){
          elem.style.opacity = 1;
        }

    }
};
function socketFound(socket){
    socket.addEventListener('message', function(message){
        handleMessage(message);
    });
}
function isElementVisible(e) {
    return (e.offsetParent !== null);
}

function handleMessage(m){
    var td = new Uint8Array(m.data);
    var infotest = msgpack5.decode(td);
    var info;
    if(infotest.length > 1) {
        info = [infotest[0], ...infotest[1]];
        if (info[1] instanceof Array){
             info = info;
        }
    } else {
        info = infotest;
    }
    if (info[0]=="3"){
        playersNear = [];
        var locInfoNow = info[1];
        for (var i=0;i<locInfoNow.length/13;i++){
            var playerData = locInfoNow.slice(13*i, 13*i+13);
            if (playerData[0]==MYID){
                myCLAN = playerData[7];
                myPlayer = new player(playerData[0], playerData[1], playerData[2], playerData[7]);
                if (!targets.every(x => x===false)){
                    var targetXDir = targets[0];
                    var targetYDir = targets[1];
                    var correctAngle = Math.atan2(targetYDir-myPlayer.y, targetXDir-myPlayer.x);
                    document.dns(["3", [correctAngle]]);
                    var totalDist = Math.sqrt( (targetXDir-myPlayer.x)**2  + (targetYDir-myPlayer.y)**2 );
                    var totalTime = Math.ceil(totalDist/319.2);
                    document.getElementById("timeest").innerHTML = `${totalTime} seconds...`;
                    if (totalDist < 100){
                     targets = [false, false];
                     document.dns(["3", [null]]);
                     $("#infoDiv").animate({opacity: 0});
                    }
                }
                continue;
            }
        }
         var nearestPlayerPosition = playersNear.sort( (a,b) => pdist(a, myPlayer) - pdist(b, myPlayer) );
           var nearestPlayer = nearestPlayerPosition[0];
           if (nearestPlayer){
               nearestPlayerAngle = Math.atan2( nearestPlayer.y-myPlayer.y, nearestPlayer.x-myPlayer.x);
               if (autoattack){
               doNewSend(["3", [nearestPlayerAngle]]);
               aim(nearestPlayer.x-myPlayer.x+window.innerWidth/2, nearestPlayer.y-myPlayer.y+window.innerHeight/2);
               $("#tbtn").css({opacity: 1, marginLeft: nearestPlayer.x-myPlayer.x+window.innerWidth/2-20, marginTop: nearestPlayer.y-myPlayer.y+window.innerHeight/2-20});
               }
           }
    }
   if (info[0]=="6"){
        var locInfo = info[1];
        if (locInfo[locInfo.length-1].toString() == MYID){ //Object created
        if (window.innerWidth >= 770){
            console.log(locInfo);
            var itemID = `actionBarItem${locInfo[locInfo.length-2]+16}`;
            var imgURL = document.getElementById(itemID).style.backgroundImage.toString().match(/url\("(.+)?(?=")/)[1];
            console.info(imgURL);
            var mapDisplay = document.getElementById("mapDisplay").getBoundingClientRect();
            var mapSize = [14365, 14365];
            var boxSize = [$("#mapDisplay").width(), $("#mapDisplay").height()];
            var targets = [locInfo[1], locInfo[2]].map(item => (130*item)/14365)
            var newTarget = document.createElement("div");
            newTarget.rawX = targets[0];
            newTarget.rawY = targets[1];
            newTarget.rimgURL = imgURL;
            newTarget.style = `background-image: url("${imgURL}"); background-size: 12px 12px; width:12px; height:12px; position:absolute; left: ${x}px; top:${y}px; opacity:0; z-index:100; cursor: pointer;`;
            newTarget.className = "mapTarget";
            document.getElementsByTagName("body")[0].appendChild(newTarget);
            $(newTarget).animate({opacity: 1});
            s[locInfo[0]] = newTarget;

        }
    }
    }
    if (info[0]=="12"){
       if (Object.keys(allMooMooObjects).includes(info[1].toString())){
            allMooMooObjects[info[1]].remove();
      }
    }
    if (info[0] == "1" && !MYID){
        MYID =  info[1];
    }
}
function pdist(player1, player2){
      return Math.sqrt( Math.pow((player2.y-player1.y), 2) + Math.pow((player2.x-player1.x), 2) );
}
function havePoison(){
    let hasPoison = true;
    if (hasPoison) hasPoison = isElementVisible(document.getElementById("actionBarItem24"));
    return hasPoison;
}
function haveGreat(){
    let hasGreat = true;
    if (hasGreat) hasGreat = isElementVisible(document.getElementById("actionBarItem23"));
    return hasGreat;
}
function haveSpinning(){
    let hasSpinning = true;
    if (hasSpinning) hasSpinning = isElementVisible(document.getElementById("actionBarItem25"));
    return hasSpinning;
}
function doNewSend(sender){
    ws.send(encodeSEND(sender));
}
function placeSpike(item){
  ws.send(encodeSEND( ["5", [item, null]]));
  ws.send(encodeSEND([
  "c",
  [
    1,
    null
  ]
]));
  ws.send(encodeSEND([
  "c",
  [
    0,
    null
  ]
]));
}
document.dns = doNewSend;
$(document).on("click", "#cancelTrip", () => {
           targets = [false, false];
           document.dns(["3", [null]]);
           $("#infoDiv").animate({opacity: 0});
});
document.addEventListener('keypress', (e)=>{
   if (e.keyCode == 116 && document.activeElement.id.toLowerCase() !== 'chatbox'){
       STATE+=1;
       var coreIndex = STATE%2; //STATE%4;
       autoheal = coreIndex == 0; //truthArray[1];
   } else if (e.keyCode == trapKey && document.activeElement.id.toLowerCase() !== 'chatbox') {
        var dataTemplate = {"data":[], "options":{"compress":true}, "nsp": "/", "type": 2};
        var data50 = dataTemplate;
        data50["data"]=["5", [15, 0]];
        ws.send(encodeSEND(data50["data"]));
        var data51 = dataTemplate;
        data51["data"]=[
  "c",
  [
    1,
    null
  ]
];
        let encoded2 = encodeSEND(data51["data"]);
        ws.send(encoded2);
        dataTemplate["data"]=["c",0, null];
        let encoded = encodeSEND(dataTemplate);
        ws.send(encoded);

      } else if (e.keyCode == 112 && document.activeElement.id.toLowerCase() !== 'chatbox'){
         autoattack = !autoattack
         botTag();
    } else if (e.keyCode == spikeKey && document.activeElement.id.toLowerCase() !== 'chatbox') {
           if (havePoison()) {
             placeSpike(8);
           } else if (haveGreat()){
             placeSpike(7);
           } else if (haveSpinning()){
             placeSpike(9);
           } else {
             placeSpike(6);
         }

   } else if (e.keyCode == instaKillKey && document.activeElement.id.toLowerCase() !== 'chatbox') {
       var ctime = new Date().getTime();
       if (!inInstaProcess){
       inInstaProcess = true
        IN_PROCESS = true;

       doNewSend(["13c", [0, bullHelm, 0]]);
          if (currentAccessory == monkeyTail){
               doNewSend(["13c", [0, 0, 1]]);
           }
       doNewSend(["5", [switchToWep, true]]);
       setTimeout( () => {
           doNewSend(["2", [nearestPlayerAngle]]);
           doNewSend([
  "c",
  [
    1,
    null
  ]
]);
           ctime = new Date().getTime();
       }, 20);
       setTimeout( () => {
           doNewSend(["2", [nearestPlayerAngle]]);
           doNewSend(["5", [switchToRange, true]]);
           ctime = new Date().getTime();
       }, document.timeTween); //120-140?
       setTimeout( () => {
           doNewSend(["c", [0, null]]);
           doNewSend(["13c", [0, currentHat, 0]]);
           doNewSend(["5", [switchToWep, true]]);
           ctime = new Date().getTime();
       }, 600);
        setTimeout( () => {
          if (bowWorked){
          doNewSend([
  "c",
  [
    1,
    null
  ]
]);
        }
       }, 840);

      setTimeout( () => {
           if (bowWorked){
          doNewSend(["c", [0, null]]);
        }
       }, 950);

      setTimeout( () => {
          inInstaProcess = false;
          if (bowWorked){
         doNewSend(["5",  [switchToWep, true]]);
              setTimeout( () => {
         doNewSend(["c", [0, null]]);
              }, 300);
         bowWorked = false;
         IN_PROCESS = false;
       }
        IN_PROCESS = false;
       }, 1060);


       }

   } else if (document.activeElement.id.toLowerCase() !== 'chatbox' ){
       if (e.keyCode == 108){ //use pressed "l"; spikes
           let spikeVal;
           if (havePoison()) {
             spikeVal = 8;
           } else if (haveGreat()){
             spikeVal = 7;
           } else if (haveSpinning()){
             spikeVal = 9;
           } else {
             spikeVal = 6;
         }

         for (var i=0;i<4;i++){
             let angle = (Math.PI/2)*i;
             /*let x = Math.cos(angle)*50;
             let y = Math.sin(angle)*50;
             console.log(x, y);
             aim(x, y);*/
             document.dns(["2", [angle]]);
             placeSpike(spikeVal);

         }


       } else if (e.keyCode == 111){ //user pressed "i"; traps
           for (var j=0;j<4;j++){
              document.dns(["2", [(Math.PI/2)*j]]);
              document.dns(["5", [15, 0]]);
              document.dns(["c", [1, null]]);
              document.dns(["c", [0, null]]);
           }

       }
  }
});

document.getElementById("gameName").innerHTML = "MooMoo.io </br>Pit/Trap";
document.getElementById("diedText").innerHTML = "You = Ded... LOL!!!"
document.getElementById("scoreDisplay").style.color = "#F3F781";
$("#chatButton").hide();
$("#joinPartyButton").remove();
$("#partyButton").remove();

(function(){

addEventListener("click", function(e) {
	if (e.target.tagName == "A" && e.target.href == "javascript:window.location.href=window.location.href") {
		e.preventDefault();
		location.replace(location.origin);
	}
});

var sI = -1,
	hideAct = false;

function $(e){
	var a = document.querySelectorAll(e);
	if(a.length == 1){
		return a[0];
	} else if(a.length == 0){
		return null;
	} else {
		return a;
	}
	return a;
}

}());