Zombs.io Bad Hack

The best public script for zombs.io

Ajankohdalta 15.4.2022. Katso uusin versio.

// ==UserScript==
// @name         Zombs.io Bad Hack
// @namespace    https://tampermonkey.net/
// @version      4.3.4
// @description  The best public script for zombs.io
// @author       vn_Havy
// @match        http://zombs.io/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==


function thisIsForIframe() {
    if(location.hash.includes("noscript")) { return; }
    document.querySelectorAll('.ad-unit, .ad-unit-medrec, .hud-intro-guide-hints, .hud-intro-left, .hud-intro-youtuber, .hud-intro-footer, .hud-intro-stone, .hud-intro-tree, .hud-intro-social, .hud-intro-more-games, .hud-intro-guide, .hud-day-night-overlay, .hud-respawn-share, .hud-party-joining, .hud-respawn-corner-bottom-left').forEach(el => el.remove());
    document.getElementsByClassName('hud-intro-name')[0].setAttribute('maxlength', 29);
    document.getElementsByClassName('hud-party-tag')[0].setAttribute('maxlength', 49);
    document.querySelector(".hud-chat-messages").style.width = "1800px";

    document.getElementsByClassName("hud-top-center")[0].innerHTML = `
<a id="shopshortcut1"><img src="http://zombs.io/asset/image/ui/inventory/inventory-pickaxe-t7.svg"></a>
<a id="shopshortcut2"><img src="http://zombs.io/asset/image/ui/inventory/inventory-spear-t7.svg"></a>
<a id="shopshortcut3"><img src="http://zombs.io/asset/image/ui/inventory/inventory-bow-t7.svg"></a>
<a id="shopshortcut4"><img src="http://zombs.io/asset/image/ui/inventory/inventory-bomb-t7.svg"></a>
<a id="shopshortcut5"><img src="http://zombs.io/asset/image/ui/inventory/inventory-health-potion.svg"></a>
<a id="shopshortcut6"><img src="http://zombs.io/asset/image/ui/inventory/inventory-pet-health-potion.svg"></a>
<a id="shopshortcut7"><img src="http://zombs.io/asset/image/ui/inventory/inventory-shield-t10.svg"></a>
<a id="shopshortcut8"><img src="http://zombs.io/asset/image/ui/inventory/inventory-pet-ghost-t1.svg"></a>
<a id="shopshortcut9"><img src="http://zombs.io/asset/image/ui/inventory/inventory-pet-miner-t8.svg"></a>
<a id="shopshortcut10"><img src="http://zombs.io/asset/image/ui/inventory/inventory-pet-carl-t8.svg"></a>
`;

    document.getElementById('shopshortcut1').addEventListener('click', buyPickaxe);
    document.getElementById('shopshortcut2').addEventListener('click', buySpear);
    document.getElementById('shopshortcut3').addEventListener('click', buyBow);
    document.getElementById('shopshortcut4').addEventListener('click', buyBomb);
    document.getElementById('shopshortcut5').addEventListener('click', () => {shopShortcut("HealthPotion", 1)});
    document.getElementById('shopshortcut6').addEventListener('click', () => {shopShortcut("PetHealthPotion", 1)});
    document.getElementById('shopshortcut7').addEventListener('click', buyZombieShield);
    document.getElementById('shopshortcut8').addEventListener('click', () => {Game.currentGame.network.sendRpc({name: "DeleteBuilding", uid: game.ui.getPlayerPetUid()})});
    document.getElementById('shopshortcut9').addEventListener('click', () => {buyPet("PetMiner", getPetTier(6))});
    document.getElementById('shopshortcut10').addEventListener('click', () => {buyPet("PetCARL", getPetTier(5))});

    function buyPet(item, tier) {
        if (game.ui.getPlayerPetName() == item) {
            shopShortcut("PetRevive", 1)
        } else {
            let i = 0
            let j = setInterval(function() {
                shopShortcut(item, tier)
                i++
                if (i >= 25 || game.ui.getPlayerPetName() == item) {
                    i = 0
                    clearInterval(j)
                }
            },250);
        }
    }

    function getPetTier(num) {
        if (document.querySelectorAll(".hud-shop-item-tier")[5].childNodes[0].textContent.match(/\d+/) != null) {
            let petLevel = document.querySelectorAll(".hud-shop-item-tier")[num].childNodes[0].textContent.match(/\d+/)[0]
            if (petLevel <= 8) return 1
            if (petLevel <= 16) return 2
            if (petLevel <= 24) return 3
            if (petLevel <= 32) return 4
            if (petLevel <= 48) return 5
            if (petLevel <= 64) return 6
            if (petLevel <= 96) return 7
            if (petLevel > 96) return 8
        } else return 8
    }

    function equipItem(item, tier) {
        game.network.sendRpc({
            name: "EquipItem",
            itemName: item,
            tier: tier
        })
    };

    function buyItem(item, tier) {
        game.network.sendRpc({
            name: "BuyItem",
            itemName: item,
            tier: tier
        })
    }

    function shopShortcut(item, tier) {
        buyItem(item, tier)
        if (game.ui.playerWeaponName !== item) {
            equipItem(item, tier)
        }
    }



    function buyPickaxe() {
        let gold = game.ui.playerTick.gold
        let pickaxe = game.ui.inventory.Pickaxe
        if (pickaxe.tier == 1 && gold >= 1000) {
            shopShortcut("Pickaxe", 2)
            return
        }
        if (pickaxe.tier == 2 && gold >= 3000) {
            shopShortcut("Pickaxe", 3);
            return
        }
        if (pickaxe.tier == 3 && gold >= 5000) {
            shopShortcut("Pickaxe", 4);
            return
        }
        if (pickaxe.tier == 4 && gold >= 8000) {
            shopShortcut("Pickaxe", 5);
            return
        }
        if (pickaxe.tier == 5 && gold >= 24000) {
            shopShortcut("Pickaxe", 6);
            return
        }
        if (pickaxe.tier == 6 && gold >= 90000) {
            shopShortcut("Pickaxe", 7);
            return
        } else if (game.ui.playerWeaponName !== "Pickaxe") {
            equipItem("Pickaxe", game.ui.inventory.Pickaxe.tier)
        }
    }

    function buySpear() {
        let gold = game.ui.playerTick.gold
        let spear = game.ui.inventory.Spear
        if (!spear && gold >= 1400) {
            shopShortcut("Spear", 1)
            return
        }
        if (spear.tier == 1 && gold >= 2800) {
            shopShortcut("Spear", 2)
            return
        }
        if (spear.tier == 2 && gold >= 5600) {
            shopShortcut("Spear", 3)
            return
        }
        if (spear.tier == 3 && gold >= 11200) {
            shopShortcut("Spear", 4)
            return
        }
        if (spear.tier == 4 && gold >= 22500) {
            shopShortcut("Spear", 5)
            return
        }
        if (spear.tier == 5 && gold >= 45000) {
            shopShortcut("Spear", 6)
            return
        }
        if (spear.tier == 6 && gold >= 90000) {
            shopShortcut("Spear", 7)
            return
        } else if (game.ui.playerWeaponName !== "Spear"){
            equipItem("Spear", game.ui.inventory.Spear.tier)
        }
    }

    function buyBow() {
        let gold = game.ui.playerTick.gold
        let bow = game.ui.inventory.Bow
        if (!bow && gold >= 100) {
            shopShortcut("Bow", 1)
            return
        }
        if (bow.tier == 1 && gold >= 400) {
            shopShortcut("Bow", 2)
            return
        }
        if (bow.tier == 2 && gold >= 2000) {
            shopShortcut("Bow", 3)
            return
        }
        if (bow.tier == 3 && gold >= 7000) {
            shopShortcut("Bow", 4)
            return
        }
        if (bow.tier == 4 && gold >= 24000) {
            shopShortcut("Bow", 5)
            return
        }
        if (bow.tier == 5 && gold >= 30000) {
            shopShortcut("Bow", 6)
            return
        }
        if (bow.tier == 6 && gold >= 90000) {
            shopShortcut("Bow", 7)
            return
        } else if (game.ui.playerWeaponName !== "Bow"){
            equipItem("Bow", game.ui.inventory.Bow.tier)
        }
    }

    function buyBomb() {
        let gold = game.ui.playerTick.gold
        let bomb = game.ui.inventory.Bomb
        if (!bomb && gold >= 100) {
            shopShortcut("Bomb", 1)
            return
        }
        if (bomb.tier == 1 && gold >= 400) {
            shopShortcut("Bomb", 2)
            return
        }
        if (bomb.tier == 2 && gold >= 3000) {
            shopShortcut("Bomb", 3)
            return
        }
        if (bomb.tier == 3 && gold >= 5000) {
            shopShortcut("Bomb", 4)
            return
        }
        if (bomb.tier == 4 && gold >= 24000) {
            shopShortcut("Bomb", 5)
            return
        }
        if (bomb.tier == 5 && gold >= 50000) {
            shopShortcut("Bomb", 6)
            return
        }
        if (bomb.tier == 6 && gold >= 90000) {
            shopShortcut("Bomb", 7)
            return
        } else if (game.ui.playerWeaponName !== "Bomb"){
            equipItem("Bomb", game.ui.inventory.Bomb.tier)
        }
    }

    function buyZombieShield() {
        let gold = game.ui.playerTick.gold
        let shield = game.ui.inventory.ZombieShield
        if (!shield && gold >= 1000) {
            buyItem("ZombieShield", 1)
            return
        }
        if (shield.tier == 1 && gold >= 3000) {
            buyItem("ZombieShield", 2)
            return
        }
        if (shield.tier == 2 && gold >= 7000) {
            buyItem("ZombieShield", 3)
            return
        }
        if (shield.tier == 3 && gold >= 14000) {
            buyItem("ZombieShield", 4)
            return
        }
        if (shield.tier == 4 && gold >= 18000) {
            buyItem("ZombieShield", 5)
            return
        }
        if (shield.tier == 5 && gold >= 22000) {
            buyItem("ZombieShield", 6)
            return
        }
        if (shield.tier == 6 && gold >= 24000) {
            buyItem("ZombieShield", 7)
            return
        }
        if (shield.tier == 7 && gold >= 30000) {
            buyItem("ZombieShield", 8)
            return
        }
        if (shield.tier == 8 && gold >= 45000) {
            buyItem("ZombieShield", 9)
            return
        }
        if (shield.tier == 9 && gold >= 70000) {
            buyItem("ZombieShield", 10)
            return
        }
    }


    //Iframe start
    // menu stuff start
    document.querySelector('#hud').insertAdjacentHTML('beforeend', `
<div class="hud-menu-iframe">
<button class="bad-btn bad-cyan" id="sendalt">Send Alt</button>
<button class="bad-btn bad-red" id="delalt">Delete Alt</button>
<input class="bad-textbox" id="delid" style="width: 10%" placeholder="Alt's Id">
<button class="bad-btn bad-red" id="delallalt">Delete All Alt</button>
<button class="bad-btn bad-cyan" id="altmove">Stay</button>
</div>

<style>
.hud-menu-iframe{
text-align: center;
display: none;
position: fixed;
padding: 20px 0px;
top: 48%;
left: 50%;
width: 600px;
height: 400px;
transform: translate(-50%, -52%);
background: rgba(0, 0, 0, 0.6);
color: #eee;
z-index: 20;
}
.hud-menu-icons .hud-menu-icon[data-type=Iframe]::before {
background-image: url("https://media.discordapp.net/attachments/870020008128958525/876133010360107048/unknown.png");
background-size: 30px;
}
</style>
`)

    let mm = document.getElementsByClassName("hud-menu-iframe")[0];
    function iframeMenu() {
        if(["none", ""].includes(mm.style.display)) {
            mm.style.display = "block";
            for(let i of Array.from(document.getElementsByClassName("hud-menu"))) {
                if(i.classList.contains('hud-menu-iframe')) { return; };
                i.style.display = "none";
            };
        } else {
            mm.style.display = "none";
        };
    };

    document.getElementsByClassName("hud-menu-icons")[0].insertAdjacentHTML("beforeend", `<div class="hud-menu-icon" data-type="Iframe"></div>`);
    document.querySelectorAll(".hud-menu-icon")[3].addEventListener("click", iframeMenu)
    document.getElementsByClassName("hud-menu-iframe")[0].style.overflow = "auto";


    for (let i of Array.from(document.querySelector("#hud").childNodes)) {
        if (i.className != "hud-menu-iframe" && i.className != "hud-center-right" && i.className != "hud-center-left") {
            i.addEventListener('click', function() {
                if (document.getElementsByClassName("hud-menu-iframe")[0].style.display == "block") {
                    document.getElementsByClassName("hud-menu-iframe")[0].style.display = "none";
                };
            });
        };
    };

    for (let i of Array.from(document.getElementsByClassName("hud-menu-icon"))) {
        if (i.dataset.type !== "Iframe") {
            i.addEventListener('click', function() {
                if (document.getElementsByClassName("hud-menu-iframe")[0].style.display == "block") {
                    document.getElementsByClassName("hud-menu-iframe")[0].style.display = "none";
                };
            });
        };
    };

    for (let i of Array.from(document.getElementsByClassName("hud-spell-icon"))) {
        if (i.dataset.type !== "HealTowersSpell" && i.dataset.type !== "TimeoutItem") {
            i.addEventListener('click', function() {
                if (document.getElementsByClassName("hud-menu-iframe")[0].style.display == "block") {
                    document.getElementsByClassName("hud-menu-iframe")[0].style.display = "none";
                };
            });
        };
    };

    document.addEventListener("keyup", e => {
        if (document.activeElement.tagName.toLowerCase() !== "input" && document.activeElement.tagName.toLowerCase() !== "textarea") {
            if (e.key === "o" || e.key === "p" || e.key === "b" || e.key === "/" || e.keyCode == 27) {
                if (mm.style.display == "block") {
                    mm.style.display = "none";
                }
            }
        }
    })

    let IframesCount = 0;
    let NearestToCursor;
    document.getElementById('sendalt').addEventListener('click', function(){
        let iframe = document.createElement('iframe');
        IframesCount++;
        iframe.id = "iframeId" + IframesCount;
        iframe.className = "iframeAlts";
        iframe.src = `http://zombs.io/#/${game.options.serverId}/${game.ui.playerPartyShareKey}/${iframe.id}/noscript`;

        iframe.addEventListener('load', function(e) {
            iframe.contentWindow.eval(`
          window.nearestToCursor = false;
          let iframeId = location.hash.split("/")[3];

          document.querySelectorAll("#stats, #hud-intro > div > h2, #hud-intro > div > h1, .hud-menu-settings, .hud-menu-shop, .hud-building-overlay, .hud-menu-party, .hud-day-night-overlay, .hud-announcement-overlay, .hud-popup-overlay, .hud-pip-overlay, .hud-buff-bar, .hud-center-right, .hud-center-left, .hud-bottom-right, .hud-bottom-center, .hud-bottom-left, .hud-top-right, .hud-top-center, .hud-top-left, .hud-reconnect, .hud-respawn, .hud-debug, .hud-preroll-ad, .hud-intro-corner-top-left, .hud-intro-corner-top-right, .hud-intro-corner-bottom-left, .hud-intro-corner-bottom-right, .hud-intro-footer, .hud-intro-tree, .hud-intro-stone, .ad-unit-leaderboard.ad-unit-leaderboard-atf, .hud-intro-left, .hud-intro-guide").forEach(e => e.remove());
          game.renderer.scene.setVisible(false)
          document.getElementsByClassName("hud-intro-play")[0].click();
game.renderer.ground.setVisible(false)
game.renderer.scenery.setVisible(false)
game.renderer.projectiles.setVisible(false)
          var joinedGameCheck = setTimeout(function(){
            if (document.getElementsByClassName('hud-intro-error')[0].innerHTML !== "" && !game.world.inWorld) {
              parent.game.ui.getComponent('PopupOverlay').showHint(document.getElementsByClassName('hud-intro-error')[0].innerHTML, 6000);
              parent.IframesCount--;
              parent.document.getElementById(iframeId).remove();
            }
          }, 2000)

          game.network.addEnterWorldHandler(function(e) {
                clearTimeout(joinedGameCheck);
          })

          function MoveAltTo(position){
            let x = Math.round(position.x);
            let y = Math.round(position.y);

            if (game.ui.playerTick.position.y-y > 100) {
              game.network.sendInput({down: 0})
            } else {
              game.network.sendInput({down: 1})
            }
            if (-game.ui.playerTick.position.y+y > 100) {
               game.network.sendInput({up: 0})
            } else {
               game.network.sendInput({up: 1})
            }
            if (-game.ui.playerTick.position.x+x > 100) {
               game.network.sendInput({left: 0})
            } else {
               game.network.sendInput({left: 1})
            }
            if (game.ui.playerTick.position.x-x > 100) {
               game.network.sendInput({right: 0})
            } else {
               game.network.sendInput({right: 1})
            }
          }

          game.network.addEntityUpdateHandler(() => {
            if (game.ui.playerTick){
              switch (parent.document.getElementById('altmove').innerText){
                case "Follow Player":
                  MoveAltTo(parent.game.ui.playerTick.position);
                  break;
                case "Follow Cursor":
                  MoveAltTo(parent.game.renderer.screenToWorld(parent.game.ui.mousePosition.x, parent.game.ui.mousePosition.y));
                  break;
                case "Stay":
                  game.network.sendInput({left: 0});
                  game.network.sendInput({right: 0});
                  game.network.sendInput({up: 0});
                  game.network.sendInput({down: 0});
                  break;
                case "Move Exactly":
                  if(parent.document.getElementById('hud-chat').className.includes('is-focus')) break;
                  let xyVel = {x: 0, y: 0};
                  if (parent.game.inputManager.keysDown[87]) xyVel.y++; // w
                  if (parent.game.inputManager.keysDown[65]) xyVel.x--; // a
                  if (parent.game.inputManager.keysDown[83]) xyVel.y--; // s
                  if (parent.game.inputManager.keysDown[68]) xyVel.x++; // d
                  game.network.sendInput({up: xyVel.y > 0 ? 1 : 0});
                  game.network.sendInput({left: xyVel.x < 0 ? 1 : 0});
                  game.network.sendInput({down: xyVel.y < 0 ? 1 : 0});
                  game.network.sendInput({right: xyVel.x > 0 ? 1 : 0});
                  break;
              }

              //Aim
              let worldMousePos = parent.game.renderer.screenToWorld(parent.game.ui.mousePosition.x, parent.game.ui.mousePosition.y);
              if (parent.game.inputManager.mouseDown) {
                game.network.sendInput({mouseDown: 0});
                game.network.sendInput({mouseMoved: game.inputPacketCreator.screenToYaw((-game.ui.playerTick.position.x + worldMousePos.x)*100, (-game.ui.playerTick.position.y + worldMousePos.y)*100)});
              }
              if (!parent.game.inputManager.mouseDown) {
                if (!window.nearestToCursor && parent.game.inputManager.keysDown[73]) game.network.sendInput({mouseUp: 0});
                game.network.sendInput({mouseMoved: game.inputPacketCreator.screenToYaw((-game.ui.playerTick.position.x + worldMousePos.x)*100, (-game.ui.playerTick.position.y + worldMousePos.y)*100)});
              }

              if(!parent.game.inputManager.mouseDown){
                if (window.nearestToCursor && parent.game.inputManager.keysDown[73]) {
                  game.network.sendRpc({name: "JoinPartyByShareKey",partyShareKey: parent.document.getElementById('AltHitInput').value});
                  game.network.sendInput({mouseDown: 0});
                }
                if(parent.game.inputManager.keysDown[73] && game.ui.playerPartyShareKey === parent.document.getElementById('AltHitInput').value){
                  game.network.sendRpc({ name: "LeaveParty"})
                  game.network.sendInput({mouseUp: 0});
                }
                else{
                  game.network.sendInput({mouseUp: 0});
                }
              }
              game.network.addRpcHandler("Dead", function(e) {
                game.network.sendPacket(3, { respawn: 1 })
              })

              if(parent.game.inputManager.keysDown[76]) game.network.sendRpc({ name: "LeaveParty"})
            }
          })
          function GetDistanceToCursor(cursorPos){
            let pos = game.ui.playerTick.position;
            let xDistance = Math.abs(pos.x - cursorPos.x);;
            let yDistance = Math.abs(pos.y - cursorPos.y);
            return Math.sqrt((xDistance * xDistance) + (yDistance * yDistance));
          }
        `);
        })
        iframe.style.display = 'none';
        document.body.append(iframe);
    })

    let AltMoveClicks = 0;
    var AltMoveStyle = "Stay";
    document.getElementById('altmove').addEventListener('click', function(){
        let moveOrder = ["Stay", "Follow Cursor", "Follow Player", "Move Exactly"];
        AltMoveClicks++;
        AltMoveStyle = moveOrder[AltMoveClicks % 4]
        document.getElementById('altmove').innerText = AltMoveStyle;
    })

    document.getElementById('delallalt').addEventListener('click', function(){
        let deleteAltLoop = setInterval(function(){
            if (document.getElementsByClassName('iframeAlts').length > 0){
                for(let iframe of document.getElementsByClassName('iframeAlts')){
                    iframe.remove();
                }
            }
            else{
                clearInterval(deleteAltLoop);
            }
        })
        })

    var nearestToCursorIframeId;
    setInterval(() => {
        let nearestIframeDistance = 9999999999999999;
        for(let iframe of document.getElementsByClassName('iframeAlts')){
            if (typeof(iframe.contentWindow.nearestToCursor) === 'undefined') continue;
            iframe.contentWindow.nearestToCursor = false;
            let mousePosition = game.renderer.screenToWorld(game.ui.mousePosition.x, game.ui.mousePosition.y);
            let distance = iframe.contentWindow.GetDistanceToCursor(mousePosition);
            if(distance < nearestIframeDistance){
                nearestIframeDistance = distance;
                nearestToCursorIframeId = iframe.id;
            }
        }
        if (document.getElementById(nearestToCursorIframeId)) {
            let iframeWindow = document.getElementById(nearestToCursorIframeId).contentWindow;
            if (typeof(iframeWindow.nearestToCursor) === 'boolean'){
                iframeWindow.nearestToCursor = true;
            }
        }
    },100)
    /*
//menu stuff end
let numOfAlts = 0
let aitoid = 0
let shouldAITO = false

game.network.addRpcHandler("DayCycle", () => {
    if (shouldAITO) {
        aitoid += 1
        console.log("aito" + aitoid)
        let NewAITO = document.createElement('Iframe');
        NewAITO.id = "aito" + aitoid;
        NewAITO.src = `http://zombs.io/#/${game.options.serverId}/badhack`;
        NewAITO.addEventListener('load', function() {
            NewAITO.contentWindow.eval(`
            document.getElementsByClassName("hud-intro-play")[0].click()
            game.network.addEntityUpdateHandler(() => {
                if (game.world.inWorld && game.network.connected) {
                    if (game.ui.getPlayerPartyShareKey() == window.parent.game.ui.getPlayerPartyShareKey() && game.ui.playerTick.gold >= 10000) {
                         console.log("buy timeout")
                         game.network.sendRpc({
                             name: "BuyItem",
                             itemName: "Pause",
                             tier: 1
                         });
                         setTimeout(() => {
                             window.parent.document.getElementById("aito" + aitoid).remove()
                         }, 250)
                     } else if (game.ui.getPlayerPartyShareKey() != window.parent.game.ui.getPlayerPartyShareKey()){
                         console.log("join party")
                         game.network.sendRpc({
                             name: "JoinPartyByShareKey",
                             partyShareKey: window.parent.game.ui.getPlayerPartyShareKey()
                         });
                     }
                 }
            })
        `)
    })
        NewAITO.style.display = "none"
        document.body.append(NewAITO)
    }
})

document.getElementById("aitobtn").addEventListener("click", function() {
    if (!shouldAITO) {
        shouldAITO = true
        document.getElementById("aitobtn").innerHTML = "AITO On"
    } else {
        shouldAITO = false
        document.getElementById("aitobtn").innerHTML = "AITO Off"
    }

});
document.getElementById("newalt").addEventListener("click", function() {
    numOfAlts++;
    let newDiv = document.createElement('div');
    newDiv.className = "frameholder";
    newDiv.id = "frame" + numOfAlts;
    let newIframe = document.createElement('iFrame');
    newIframe.className = "frames";
    newIframe.src = `http://zombs.io/#/${game.options.serverId}/${game.ui.playerPartyShareKey}`;

    document.getElementsByClassName("hud-menu-more")[0].insertBefore(newDiv, null);
    newDiv.appendChild(newIframe);
});

document.getElementById("delallalt").addEventListener("click", function F_deleteAllAlt() {
    for (let i = 1; i <= numOfAlts; i++) {
        document.getElementById("frame" + i).remove();
    }
    numOfAlts = 0;
});

document.getElementById("delalt").addEventListener("click", function F_deleteAlt() {
    let deletealtnum = parseInt(document.getElementById('delid').value);
    document.getElementById("frame" + deletealtnum).remove();
    for (let i = 1; i <= (numOfAlts - deletealtnum); i++) {
        document.getElementById("frame" + (deletealtnum + i)).id = "frame" + (deletealtnum + i - 1);
    }
    numOfAlts--;
});


//Iframe end
*/

    let mapTimeouts = [];

    function createCoordinates() {
        let x = document.createElement('div')
        x.style = 'position: relative;top: 17px;right: 0px;font-weight: 600;font-family: "Hammersmith One";text-shadow: 1px 0 0 #fff, -1px 0 0 #fff, 0 1px 0 #fff, 0 -1px 0 #fff, 0.5px 0.5px #fff, -0.5px -0.5px 0 #fff, 0.5px -0.5px 0 #fff, -0.5px 0.5px 0 #fff;';
        x.innerHTML = `<p id="coords";">X: 0, Y: 0</p>`
    x.style.textAlign = "center"
        document.querySelector("#hud > div.hud-bottom-left").append(x)
    }

    let mapMouseX;
    let mapMouseY;
    let hasBeenInWorld = false;

    game.network.addEnterWorldHandler(function () {
        if(!hasBeenInWorld) {
            hasBeenInWorld = true
            setInterval(() => {
                document.querySelector("#coords")
                    .innerText = `X: ${game.world.localPlayer.entity?.targetTick?.position.x}, Y: ${game.world.localPlayer.entity?.targetTick?.position.y}`
        }, 16)
            createCoordinates()
        }
        setTimeout(() => {
            document.querySelectorAll(".hud-shop-item-social")[0].childNodes[1].href = "javascript:void(0)"
            document.querySelectorAll(".hud-shop-item-social")[0].childNodes[1].removeAttribute('target')
            setTimeout(() => {
                document.querySelectorAll(".hud-shop-social-twitter.is-disabled")[0].click()
            },2000)
        }, 4000);
    })

    var mousemove;
    addEventListener('mousemove', (e) => {
        mousemove = e;
    })

    var isSpamming = 0;

    function pauseChatSpam(e) {
        if (!isSpamming) {
            window.spammer = setInterval(() => {
                game.network.sendRpc({
                    name: "SendChatMessage",
                    channel: "Local",
                    message: e
                })
            }, 100)
        } else if (isSpamming) {
            clearInterval(window.spammer)
        }
        isSpamming = !isSpamming
    }

    var autoRespawn = false

    game.network.addRpcHandler('ReceiveChatMessage', function(e) {
        if(e.uid == game.ui.playerTick.uid) {
            if(e.message == "!boss") {
                setTimeout(() => {
                    game.network.sendRpc({
                        name: "SendChatMessage",
                        message: "9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 121",
                        channel: "Local"
                    });
                }, 1000);
            };
            if(e.message == "!marker") {
                var map = document.getElementById("hud-map");
                map.insertAdjacentHTML("beforeend", `<div style="color: red; display: block; left: ${parseInt(game.ui.components.Map.playerElems[game.world.getMyUid()].marker.style.left)}%; top: ${parseInt(game.ui.components.Map.playerElems[game.world.getMyUid()].marker.style.top)}%; position: absolute;" class='hud-map-player'></div>`)
                game.ui.components.PopupOverlay.showHint(`Added Marker`);
            };
        };
    });

    function getEntitiesByModel(type) {
        let entities = []
        Object.entries(game.world.entities)
            .forEach((item => {
            if (item[1].targetTick.model == type) {
                entities.push(item)
            }
        }))
        return entities;
    }

    function moveUp() {
        game.inputPacketScheduler.scheduleInput({
            down: 0,
            up: 1
        })
    }

    function moveDown() {
        game.inputPacketScheduler.scheduleInput({
            up: 0,
            down: 1
        })
    }

    function moveLeft() {
        game.inputPacketScheduler.scheduleInput({
            right: 0,
            left: 1
        })
    }

    function moveRight() {
        game.inputPacketScheduler.scheduleInput({
            left: 0,
            right: 1
        })
    }
    var danceCounter = 0
    var danceRandom = true
    var botMode = false
    var danceInterval = setInterval(() => {
        if (botMode) {
            if (danceCounter < moves.length) {
                moves[danceCounter]()
                if (danceRandom) {
                    danceCounter = Math.floor(Math.random() * moves.length)
                } else {
                    danceCounter++
                }
            } else {
                danceCounter = 0;
            }
        }
    }, 500)
    var respawnInterval = setInterval(() => {
        if (document.querySelector('.hud-respawn').style.display == "block" && autoRespawn) {
            document.querySelector('.hud-respawn-btn').click()
        }
    }, 50)
    var moves = [moveUp, moveRight, moveDown, moveLeft]

    window.useSamePI = false

    window.showpriv = true
    if (game.world.inWorld === false) {
        game.network.addPreEnterWorldHandler(() => {
            setInterval(() => {
                document.getElementsByClassName('hud-party-grid')[0].innerHTML = '';

                function checkStatus(party) {
                    if (window.showpriv == true) {
                        if(party.isOpen == 1) {
                            return '<a style = "color: #00e700;opacity: 0.8;">[Open]<a/>';
                        } else if(!party.isOpen == 1) {
                            return '<a style = "color:red;opacity: 0.8;">[Private]<a/>';
                        }
                    } else {
                        return '';
                    }
                };


                let all_parties = game.ui.parties;

                for(let i in all_parties) {
                    let parties = all_parties[i];
                    let tab = document.createElement('div');
                    tab.classList.add('hud-party-link');
                    tab.classList.add('custom-party');
                    tab.id = parties.partyId;
                    tab.isPublic = parties.isOpen;
                    tab.name = parties.partyName;
                    tab.members = parties.memberCount;
                    tab.innerHTML = `
                <strong>${parties.partyName} ${checkStatus(parties)}<strong/>
                <small>id: ${parties.partyId}</small> <span>${parties.memberCount}/4<span/>
            `;

                    if(parties.memberCount == 4) {
                        tab.classList.add('is-disabled');
                    } else {
                        tab.style.display = 'block';
                    }
                    if(parties.partyName == document.getElementsByClassName('hud-party-tag')[0].value) {
                        tab.classList.add('is-active');
                    }
                    if (parties.isOpen !== 1 && window.showpriv == false) {
                        tab.style.display = 'none';
                    }
                    //function for requesting
                    tab.addEventListener('click', function() {
                        let isJoining = true;
                        if(tab.isPublic == 1 && tab.members < 4) {
                            isJoining = true;
                            game.network.sendRpc({
                                name: 'JoinParty',
                                partyId: Math.floor(tab.id)
                            });
                        } else if(!tab.isPublic == 1) {
                            isJoining = false;
                            game.ui.components.PopupOverlay.showHint("You can't request private parties!");
                        }
                    });
                    document.getElementsByClassName('hud-party-grid')[0].appendChild(tab);
                };
            },5000);
        });
    }

    window.isInMenu = false;

    function movePlayer(e) {
        if (!_isInChatbox) {
            switch (e.toLowerCase()
                    .replaceAll(' ', '')) {
                case "a":
                    Game.currentGame.network.sendInput({
                        left: 1
                    })
                    break;
                case "d":
                    Game.currentGame.network.sendInput({
                        right: 1
                    })
                    break;
                case "w":
                    Game.currentGame.network.sendInput({
                        up: 1
                    })
                    break;
                case "s":
                    Game.currentGame.network.sendInput({
                        down: 1
                    })
                    break;
            }
        }
    }

    var lpinterval = setInterval(function () { // loaded player info, ahrc, isInMenu, noob = chatbot
        document.querySelector('#lpi')
            .innerText = "Loaded Player Info: " + JSON.stringify(window.loadedIDS())
        window.isInMenu = document.querySelector('#hud-menu-settings')
            .style.display == "block" ? true : false
    }, 250)

    let settingsHTML = `
<div style="text-align: center">
<button class="bad-btn bad-magenta" id="lagspam-btn">Lag Spam Off</button>
<button class="bad-btn bad-magenta" id="spamchatbtn">Split Chat</button>
<button class="bad-btn bad-magenta" id="togglespmch">Chat Spam Off</button>
<input type="text" id="spamchat" placeholder="Message" class="bad-textbox" style="width: 40%">
<hr>
<input type="text" class="bad-textbox" value="150" id="sell-input" style="width: 15%" placeholder="100-250ms">
<button id="sellall" class="bad-btn bad-red">Sell All</button>
<button id="sellwall" class="bad-btn bad-red">Wall</button>
<button id="selldoor" class="bad-btn bad-red">Door</button>
<button id="selltrap" class="bad-btn bad-red">Slow Trap</button>
<button id="sellharvester" class="bad-btn bad-red">Harvester</button>
<br>
<button id="sellarrow" class="bad-btn bad-red">Arrow</button>
<button id="sellcannon" class="bad-btn bad-red">Cannon</button>
<button id="sellmelee" class="bad-btn bad-red">Melee</button>
<button id="sellbomb" class="bad-btn bad-red">Bomb</button>
<button id="sellmagic" class="bad-btn bad-red">Mage</button>
<button id="sellminer" class="bad-btn bad-red">Gold Miner</button>
<hr>
<button class="bad-btn bad-yellow" id="menu-leaveparty-btn">Leave Party</button>
<button class="bad-btn bad-yellow" id="menu-jpbsk-btn" onclick='Game.currentGame.network.sendRpc({name:"JoinPartyByShareKey", partyShareKey: document.querySelector("#menu-jpbsk-input").value})'>Join Party</button>
<input type="text" class="bad-textbox" id="menu-jpbsk-input" style="width: 40%" placeholder="Share Key">
<button class="bad-btn bad-yellow" id="autoaccept-btn">Accepter Off</button>
<br>
<button class="bad-btn bad-yellow" id="spamallparty-btn">Spam All Party Off</button>
<button class="bad-btn bad-yellow" id="spampartybyid-btn">Spam Party By ID Off</button>
<input type="text" class="bad-textbox" id="party-id-input" style="width: 20%" placeholder="Party ID">
<button class="bad-btn bad-yellow" id="newtab">New Party Tab</button>
<hr>
<button id="healplayer" class="bad-btn bad-green">Heal PLayer On</button>
<input type="text" class="bad-textbox" value="20" id="healplayerinput" style="width: 8%">
<button id="healpet" class="bad-btn bad-green">Heal Pet On</button>
<input type="text" class="bad-textbox" value="30" id="healpetinput" style="width: 8%">
<button id="revivepet" class="bad-btn bad-green">Revive On</button>
<button id="evolvepet" class="bad-btn bad-green">Evolve On</button>
<hr>
<button class="bad-btn bad-blue" id="clearchat-btn">Clear Chat Off</button>
<button class="bad-btn bad-blue" id="autoupgradeall-btn">Upgrade Off</button>
<button class="bad-btn bad-blue" id="togglespinner">Spinner Off</button>
<button class="bad-btn bad-blue" id="toggleaim">Aim Off</button>
<select id="aimOptions" class="bad-textbox"><option value="pl" selected>Players</option><option value="zo">Zombies</option></select>
<br>
<button class="bad-btn bad-blue" id="toggleahrc">AHRC Off</button>
<button class="bad-btn bad-blue" id="toggleresp">Respawn Off</button>
<button class="bad-btn bad-blue" id="togglebot">Bot Off</button>
<button class="bad-btn bad-blue" id="toggleswing">Swing Off</button>
<button class="bad-btn bad-blue" id="togglerb">Rebuild Off</button>
<hr>
<button id="hidechat" class="bad-btn bad-pink">Hide Chat</button>
<button id="hidepop" class="bad-btn bad-pink">Hide Popup</button>
<button id="hideldb" class="bad-btn bad-pink">Hide Leaderboard</button>
<button id="hidemap" class="bad-btn bad-pink">Hide Map</button>
<button id="hidepip" class="bad-btn bad-pink">Hide PIP</button>
<hr>
<button id="hideground" class="bad-btn bad-cyan">Hide Ground</button>
<button id="hidenpcs" class="bad-btn bad-cyan">Hide NPCs</button>
<button id="hideenv" class="bad-btn bad-cyan">Hide Env</button>
<button id="hideproj" class="bad-btn bad-cyan">Hide Proj</button>
<button id="hideall" class="bad-btn bad-cyan">Hide All</button>
<button id="freezegame" class="bad-btn bad-cyan">Stop Game</button>
<hr>
<button class="bad-btn bad-gray" onclick="Game.currentGame.network.disconnect()">Disconnect</button>
<hr>
</div>
<p style="font-size:14px;">Advanced Player Info?</p><input type="checkbox" id="advancedlpi">
<br>
<p style="font-size:14px;">Zoom On Scroll?</p><input type="checkbox" id="zos">
<br>
<p id="lpi">Loaded Player Info: </p>
<style>
.bad-btn{
  border: none;
  color: white;
  padding: 10px 20px;
  text-align: center;
  font-size: 14px;
  margin: 2px 0px;
  opacity: 0.9;
  transition: 0.2s;
  display: inline-block;
  border-radius: 15px;
  cursor: pointer;
  text-shadow: -1px 1px 1.5px #242526;
}
.bad-btn:hover{
  opacity: 1
}
.bad-blue{
  background-color: #5463FF
}
.bad-magenta{
  background-color: #E900FF
}
.bad-gray{
  background-color: #606060
}
.bad-yellow{
  background-color: #FFC600
}
.bad-red{
  background-color: #FF1818
}
.bad-green{
  background-color: #06FF00
}
.bad-pink{
  background-color: #FF6B6B
}
.bad-cyan{
  background-color: #39AEA9
}
.bad-orange{
  background-color: #FF5F00
}
.bad-textbox{
  border: none;
  color: white;
  padding: 10px 10px;
  text-align: center;
  font-size: 14px;
  margin: 2px 0px;
  opacity: 0.9;
  transition: 0.2s;
  display: inline-block;
  border-radius: 15px;
  background-color: #606060;
  text-shadow: -1px 1px 1.5px #242526;
}

</style>
`
    document.getElementById("hud-menu-settings").childNodes[3].innerHTML = "Bad Hack by ︵ℌαʋү༉"
    document.getElementsByClassName("hud-settings-grid")[0].innerHTML = settingsHTML;

    let cssMain = `
#hud-menu-shop {
    top: 58%;
    left: 51%;
    width: 690px;
    height: 450px;
    margin: -350px 0 0 -350px;
    padding: 20px 20px 20px 20px;
}
.hud-menu-shop .hud-shop-grid {
    height: 330px;
}
#hud-menu-settings {
    top: 55%;
    left: 48%;
    width: 780px;
    height: 500px;
    margin: -350px 0 0 -350px;
    padding: 20px 20px 20px 20px;
}
.hud-menu-settings .hud-settings-grid {
    width: 750px;
    height: 420px;

`;

    let stylesMain = document.createElement("style");
    stylesMain.appendChild(document.createTextNode(cssMain));
    document.head.appendChild(stylesMain);
    stylesMain.type = "text/css";

    document.getElementById('lagspam-btn').addEventListener('click', lagSpam)
    document.getElementById('lagspam-btn').addEventListener('click', lagSpambtn)
    document.getElementById("spamallparty-btn").addEventListener("click", spamAllParty);
    document.getElementById("spamallparty-btn").addEventListener("click", spamAllPartybtn);
    document.getElementById("newtab").addEventListener("click", () => window.open(`http://zombs.io/#/${game.options.serverId}/${game.ui.getPlayerPartyShareKey()}`));
    document.getElementById("autoupgradeall-btn").addEventListener("click", autoUpgradeAll);
    document.getElementById("autoupgradeall-btn").addEventListener("click", autoUpgradeAllbtn);
    document.getElementById("spampartybyid-btn").addEventListener("click", spamPartyByID);
    document.getElementById("spampartybyid-btn").addEventListener("click", spamPartyByIDbtn);
    document.getElementById("autoaccept-btn").addEventListener("click", autoAcceptParty);
    document.getElementById("autoaccept-btn").addEventListener("click", autoAcceptPartybtn);
    document.getElementById("toggleswing").addEventListener("click", toggleSwing)
    document.getElementById("toggleahrc").addEventListener("click", toggleAHRC)
    document.getElementById("toggleaim").addEventListener("click", toggleAim)
    document.getElementById("togglerb").addEventListener("click", toggleRebuild);
    document.getElementById("togglespinner").addEventListener("click", spinnerbtn);
    document.getElementById("togglespinner").addEventListener("click", F_spinner);
    document.getElementById("healplayer").addEventListener("click", toggleHealPlayer);
    document.getElementById("healpet").addEventListener("click", toggleHealPet);
    document.getElementById("revivepet").addEventListener("click", toggleRevivePet);
    document.getElementById("evolvepet").addEventListener("click", toggleEvolvePet);
    document.getElementById("sellwall").addEventListener('click', () => { sellAllByType("Wall") });
    document.getElementById("selldoor").addEventListener('click', () => { sellAllByType("Door") });
    document.getElementById("selltrap").addEventListener('click', () => { sellAllByType("SlowTrap") });
    document.getElementById("sellarrow").addEventListener('click', () => { sellAllByType("ArrowTower") });
    document.getElementById("sellcannon").addEventListener('click', () => { sellAllByType("CannonTower") });
    document.getElementById("sellmelee").addEventListener('click', () => { sellAllByType("MeleeTower") });
    document.getElementById("sellbomb").addEventListener('click', () => { sellAllByType("BombTower") });
    document.getElementById("sellmagic").addEventListener('click', () => { sellAllByType("MagicTower") });
    document.getElementById("sellminer").addEventListener('click', () => { sellAllByType("GoldMine") });
    document.getElementById("sellharvester").addEventListener('click', () => { sellAllByType("Harvester") });
    document.getElementById("hidechat").addEventListener("click", hideChat);
    document.getElementById("hidepop").addEventListener("click", hidePopupOverlay);
    document.getElementById("hideldb").addEventListener("click", hideLeaderboard);
    document.getElementById("hidemap").addEventListener("click", hideMap);
    document.getElementById("hidepip").addEventListener("click", hidePIP);
    document.getElementById("hideground").addEventListener("click", hideGround);
    document.getElementById("hidenpcs").addEventListener("click", hideNPCs);
    document.getElementById("hideenv").addEventListener("click", hideEnviroment);
    document.getElementById("hideproj").addEventListener("click", hideProjectiles);
    document.getElementById("hideall").addEventListener("click", hideAll);
    document.getElementById("freezegame").addEventListener("click", freezeGame);

    document.querySelector('#clearchat-btn').addEventListener('click', clearChat)
    document.querySelector('#clearchat-btn').addEventListener('click', clearChatbtn)
    document.querySelector('#menu-leaveparty-btn').addEventListener('click', onLeaveParty)
    document.querySelector('#spamchatbtn').addEventListener('click', spamchatclick)

    function hideGround() {
        if (document.getElementById("hideground").innerHTML == "Show Ground") {
            document.getElementById("hideground").innerHTML = "Hide Ground"
            game.renderer.ground.setVisible(true)
        } else {
            document.getElementById("hideground").innerHTML = "Show Ground"
            game.renderer.ground.setVisible(false)
        }
    }
    function hideNPCs() {
        if (document.getElementById("hidenpcs").innerHTML == "Show NPCs") {
            document.getElementById("hidenpcs").innerHTML = "Hide NPCs"
            game.renderer.npcs.setVisible(true)
        } else {
            document.getElementById("hidenpcs").innerHTML = "Show NPCs"
            game.renderer.npcs.setVisible(false)
        }
    }
    function hideEnviroment() {
        if (document.getElementById("hideenv").innerHTML == "Show Env") {
            document.getElementById("hideenv").innerHTML = "Hide Env"
            game.renderer.scenery.setVisible(true)
        } else {
            document.getElementById("hideenv").innerHTML = "Show Env"
            game.renderer.scenery.setVisible(false)
        }
    }
    function hideProjectiles() {
        if (document.getElementById("hideproj").innerHTML == "Show Proj") {
            document.getElementById("hideproj").innerHTML = "Hide Proj"
            game.renderer.projectiles.setVisible(true)
        } else {
            document.getElementById("hideproj").innerHTML = "Show Proj"
            game.renderer.projectiles.setVisible(false)
        }
    }
    function hideAll() {
        if (document.getElementById("hideall").innerHTML == "Show All") {
            document.getElementById("hideall").innerHTML = "Hide All"
            game.renderer.scene.setVisible(true)
        } else {
            document.getElementById("hideall").innerHTML = "Show All"
            game.renderer.scene.setVisible(false)
        }
    }
    function freezeGame() {
        if (document.getElementById("freezegame").innerHTML == "Start Game") {
            document.getElementById("freezegame").innerHTML = "Stop Game"
            game.start()
        } else {
            document.getElementById("freezegame").innerHTML = "Start Game"
            game.stop()
        }
    }

    let sellUid = []
    function sellAllByType(type) {
        let buildings = Object.values(game.ui.buildings)
        for (let i = 0; i < buildings.length; i++){
            if (Object.values(Object.values(game.ui.buildings)[i])[2] == type){
                sellUid.push(Object.values(Object.values(game.ui.buildings)[i])[4])
            }
        }
        let sellInterval = setInterval(() => {
            if (sellUid.length > 0 && game.ui.playerPartyCanSell) {
                game.network.sendRpc({
                    name: "DeleteBuilding",
                    uid: parseInt(sellUid.shift())
                })
            } else {
                clearInterval(sellInterval)
            }
        },document.getElementById("sell-input").value);
    }

    document.getElementById("sellall").addEventListener('click', function() {
        Game.currentGame.ui.getComponent("PopupOverlay").showConfirmation("Are you sure you want to delete all towers?", 1e4, function() {
            let buildings = Object.values(game.ui.buildings)
            for (let i = 0; i < buildings.length; i++){
                if (Object.values(Object.values(game.ui.buildings)[i])[2] != "GoldStash"){
                    sellUid.push(Object.values(Object.values(game.ui.buildings)[i])[4])
                }
            }
            let sellInterval = setInterval(() => {
                if (sellUid.length > 0 && game.ui.playerPartyCanSell) {
                    game.network.sendRpc({
                        name: "DeleteBuilding",
                        uid: parseInt(sellUid.shift())
                    })
                } else {
                    clearInterval(sellInterval)
                }
            },document.getElementById("sell-input").value);
        })
    })


    function onLeaveParty() {
        Game.currentGame.network.sendRpc({
            name: "LeaveParty"
        })
    }

    function hideChat() {
        if (document.getElementsByClassName("hud-top-left")[0].style.display === "none" && document.getElementById("hidechat").innerHTML == "Show Chat"){
            document.getElementsByClassName("hud-top-left")[0].style.display = "block";
            document.getElementById("hidechat").innerHTML = "Hide Chat";
        } else {
            document.getElementsByClassName("hud-top-left")[0].style.display = "none";
            document.getElementById("hidechat").innerHTML = "Show Chat";
        }
    }
    function hidePopupOverlay() {
        if (document.getElementById("hud-popup-overlay").style.display === "none" && document.getElementById("hidepop").innerHTML == "Show Popup") {
            document.getElementById("hud-popup-overlay").style.display = "block";
            document.getElementById("hidepop").innerHTML = "Hide Popup";
        } else {
            document.getElementById("hud-popup-overlay").style.display = "none";
            document.getElementById("hidepop").innerHTML = "Show Popup";
        }
    }
    function hideLeaderboard() {
        if (document.getElementById("hud-leaderboard").style.display === "none" && document.getElementById("hideldb").innerHTML == "Show Leaderboard") {
            document.getElementById("hud-leaderboard").style.display = "block";
            document.getElementById("hideldb").innerHTML = "Hide Leaderboard";
        } else {
            document.getElementById("hud-leaderboard").style.display = "none";
            document.getElementById("hideldb").innerHTML = "Show Leaderboard";
        }
    }
    function hideMap() {
        if (document.getElementsByClassName("hud-bottom-left")[0].style.display === "none" && document.getElementById("hidemap").innerHTML == "Show Map") {
            document.getElementsByClassName("hud-bottom-left")[0].style.display = "block";
            document.getElementById("hidemap").innerHTML = "Hide Map";
        } else {
            document.getElementsByClassName("hud-bottom-left")[0].style.display = "none";
            document.getElementById("hidemap").innerHTML = "Show Map";
        }
    }
    function hidePIP() {
        if (document.getElementsByClassName("hud-pip-overlay")[0].style.display === "block" || document.getElementsByClassName("hud-pip-overlay")[0].style.display === ""){
            document.getElementsByClassName("hud-pip-overlay")[0].style.display = "none";
            document.getElementById("hidepip").innerHTML = "Show PIP";
        } else {
            document.getElementsByClassName("hud-pip-overlay")[0].style.display = "block";
            document.getElementById("hidepip").innerHTML = "Hide PIP";
        }
    }

    function lagSpambtn() {
        if (document.getElementById("lagspam-btn").innerHTML == "Lag Spam On") {
            document.getElementById("lagspam-btn").innerHTML = "Lag Spam Off";
        } else {
            document.getElementById("lagspam-btn").innerHTML = "Lag Spam On";
        }
    }
    let availableCharacters = ""
    let textLength = 70;
    fetch('https://raw.githubusercontent.com/bits/UTF-8-Unicode-Test-Documents/master/UTF-8_sequence_unseparated/utf8_sequence_0-0xffff_assigned_printable_unseparated.txt')
        .then(response => response.text())
        .then(data => {
        availableCharacters = data;
    });

    var chatSpam = null;
    function lagSpam() {
        clearInterval(chatSpam);
        if (chatSpam !== null) {
            chatSpam = null;
        } else {
            chatSpam = setInterval(function() {
                let text = ""
                for (let i = 0; i < textLength; i++) text += availableCharacters[Math.floor(Math.random() * availableCharacters.length)];
                game.network.sendRpc({
                    name: "SendChatMessage",
                    channel: "Local",
                    message: text
                });
            },1050);
        };
    };

    function spamAllPartybtn() {
        if (document.getElementById("spamallparty-btn").innerHTML == "Spam All Party On") {
            document.getElementById("spamallparty-btn").innerHTML = "Spam All Party Off";
        } else {
            document.getElementById("spamallparty-btn").innerHTML = "Spam All Party On";
        }
    }
    var partyspam = null;
    function spamAllParty() {
        clearInterval(partyspam);
        if (partyspam !== null) {
            partyspam = null;
        } else {
            partyspam = setInterval(function() {
                var party = document.getElementsByClassName('hud-party-link');
                for (var i = 0; i < party.length; i++) {
                    var link = party[i];
                    link.click();
                }
                var confirm = document.getElementsByClassName("btn btn-green hud-confirmation-accept");
                for (var j = 0; j < confirm.length; j++) {
                    var accept = confirm[j];
                    accept.click();
                }
            },10);
        }
    }

    function autoAcceptPartybtn() {
        if (document.getElementById("autoaccept-btn").innerHTML == "Accepter On") {
            document.getElementById("autoaccept-btn").innerHTML = "Accepter Off";
        } else {
            document.getElementById("autoaccept-btn").innerHTML = "Accepter On";
        }
    }
    var acceptparty = null;
    function autoAcceptParty() {
        clearInterval(acceptparty);
        if (acceptparty !== null) {
            acceptparty = null;
        } else {
            acceptparty = setInterval(function() {
                var confirm = document.getElementsByClassName("btn btn-green hud-confirmation-accept");
                for (var j = 0; j < confirm.length; j++) {
                    confirm[j].click();
                }
            },10);
        }
    }

    function autoUpgradeAllbtn() {
        if (document.getElementById("autoupgradeall-btn").innerHTML == "Upgrade On") {
            document.getElementById("autoupgradeall-btn").innerHTML = "Upgrade Off";
        } else {
            document.getElementById("autoupgradeall-btn").innerHTML = "Upgrade On";
        }
    }
    var autoupgradeall = null;
    function autoUpgradeAll() {
        clearInterval(autoupgradeall);
        if (autoupgradeall !== null) {
            autoupgradeall = null;
        } else {
            autoupgradeall = setInterval(function() {
                var entities = Game.currentGame.world.entities;
                for (var uid in entities) {
                    if (!entities.hasOwnProperty(uid)) continue;
                    var obj = entities[uid];
                    Game.currentGame.network.sendRpc({
                        name: "UpgradeBuilding",
                        uid: obj.fromTick.uid
                    })
                }
            },1000)
        }
    }

    function spamPartyByIDbtn() {
        if (document.getElementById("spampartybyid-btn").innerHTML == "Spam Party By ID On") {
            document.getElementById("spampartybyid-btn").innerHTML = "Spam Party By ID Off";
        } else {
            document.getElementById("spampartybyid-btn").innerHTML = "Spam Party By ID On";
        }
    }
    var spampartyid = null;
    function spamPartyByID() {
        clearInterval(spampartyid);
        if (spampartyid !== null) {
            spampartyid = null;
        } else {
            spampartyid = setInterval(function() {
                game.network.sendRpc({
                    name: "JoinParty",
                    partyId: parseInt(document.querySelector("#party-id-input").value)
                })
            },0)
        }
    }

    function clearChatbtn() {
        if (document.getElementById("clearchat-btn").innerHTML == "Clear Chat On") {
            document.getElementById("clearchat-btn").innerHTML = "Clear Chat Off";
        } else {
            document.getElementById("clearchat-btn").innerHTML = "Clear Chat On";
        }
    }
    var shouldClearChat = null;
    function clearChat() {
        clearInterval(shouldClearChat);
        if (shouldClearChat !== null) {
            shouldClearChat = null;
        } else {
            shouldClearChat = setInterval(function () {
                document.querySelector('.hud-chat-messages').innerHTML = ""
            },500)
        }
    }

    function spinnerbtn() {
        if (document.getElementById("togglespinner").innerHTML == "Spinner On") {
            document.getElementById("togglespinner").innerHTML = "Spinner Off";
        } else {
            document.getElementById("togglespinner").innerHTML = "Spinner On";
        }
    }
    var spinner = null;
    function F_spinner() {
        clearInterval(spinner);
        if (spinner !== null) {
            spinner = null;
        } else {
            let yaw = 0
            spinner = setInterval(function () {
                game.inputPacketCreator.lastAnyYaw = yaw;
                game.network.sendPacket(3, {mouseMoved: yaw});
                yaw += 60
                if (yaw >= 359) yaw = 0
            },40)
        }
    }

    function toggleRebuild() {
        if (!shouldAutoRebuild) {
            deadTowers = []
            shouldAutoRebuild = true
            document.getElementById("togglerb").innerHTML = "Rebuild On";
        } else {
            deadTowers = []
            shouldAutoRebuild = false
            document.getElementById("togglerb").innerHTML = "Rebuild Off";
        }
    }

    function toggleSwing () {
        if (!autoSwing) {
            autoSwing = true;
            document.getElementById("toggleswing").innerHTML = "Swing On";
        } else {
            autoSwing = false;
            document.getElementById("toggleswing").innerHTML = "Swing Off";
        }
    }
    function toggleAHRC () {
        if (!shouldAHRC) {
            shouldAHRC = true;
            document.getElementById("toggleahrc").innerHTML = "AHRC On";
        } else {
            shouldAHRC = false;
            document.getElementById("toggleahrc").innerHTML = "AHRC Off";
        }
    }
    function toggleAim () {
        if (!shouldAutoAim) {
            shouldAutoAim = true;
            document.getElementById("toggleaim").innerHTML = "Aim On";
        } else {
            shouldAutoAim = false;
            document.getElementById("toggleaim").innerHTML = "Aim Off";
        }
    }
    function toggleHealPet () {
        if (!shouldAutoHealPet) {
            shouldAutoHealPet = true;
            document.getElementById("healpet").innerHTML = "Heal Pet On";
        } else {
            shouldAutoHealPet = false;
            document.getElementById("healpet").innerHTML = "Heal Pet Off";
        }
    }
    function toggleRevivePet () {
        if (!shouldAutoRevivePet) {
            shouldAutoRevivePet = true
            document.getElementById("revivepet").innerHTML = "Revive On";
        } else {
            shouldAutoRevivePet = false
            document.getElementById("revivepet").innerHTML = "Revive Off";
        }
    }
    function toggleEvolvePet () {
        if (!shouldAutoEvolvePet) {
            shouldAutoEvolvePet = true
            document.getElementById("evolvepet").innerHTML = "Evolve On";
        } else {
            shouldAutoEvolvePet = false
            document.getElementById("evolvepet").innerHTML = "Evolve Off";
        }
    }
    function toggleHealPlayer () {
        if (!shouldAutoHealPlayer) {
            shouldAutoHealPlayer = true
            document.getElementById("healplayer").innerHTML = "Heal Player On"
        } else {
            shouldAutoHealPlayer = false
            document.getElementById("healplayer").innerHTML = "Heal Player Off"
        }
    }
    let lockedYaw
    let shouldAltTrick = false
    let shouldLockYaw = false
    let shouldAutoRebuild = false
    let autoSwing = false
    let shouldAHRC = false
    let shouldAutoAim = false
    let shouldAutoHealPet = true
    let healPetTimeout = false
    let shouldAutoRevivePet = true
    let shouldAutoEvolvePet = true
    let shouldAutoHealPlayer = true
    let playerHealTimeout = false
    let petSpawned = false
    game.network.addEntityUpdateHandler((data) => {
        if (game.world.inWorld && game.network.connected) {
            let myPet = game.world.entities[game.ui.playerTick?.petUid]?.fromTick;
            let petHealth = (myPet?.health/myPet?.maxHealth) * 100;
            let myPlayer = game.world.entities[game.ui.playerTick?.uid]?.fromTick;
            let playerHealth = (myPlayer?.health/myPlayer?.maxHealth) * 100;

            if (game.ui.playerTick?.petUid !== 0) petSpawned = true;
            if (shouldAutoHealPet && petHealth < document.getElementById("healpetinput").value && petHealth > 0 && game.ui.playerTick.gold >= 100 && !healPetTimeout) {
                shopShortcut("PetHealthPotion", 1)
                healPetTimeout = true;
                setTimeout(() => {
                    healPetTimeout = false;
                }, 300);

            }
            if (shouldAutoEvolvePet && petHealth > 0 && game.world.entities[game.ui.playerTick?.uid]?.fromTick?.health > 0) {
                let model = game.world.entities[game.ui.playerTick?.petUid]?.fromTick?.model
                let tokens = document.querySelectorAll(".hud-shop-item-tokens")
                let pToken = game.ui.playerTick.token
                let evolvebtn = document.querySelectorAll(".hud-shop-actions-evolve")
                if (!evolvebtn[0].classList[1] && pToken >= tokens[0].innerHTML && model == "PetCARL") {
                    buyItem("PetCARL", getPetTier(5))
                }
                if (!evolvebtn[1].classList[1] && pToken >= tokens[1].innerHTML && model == "PetMiner") {
                    buyItem("PetMiner", getPetTier(6))
                }
            }
            if (petSpawned && shouldAutoRevivePet && !game.world.entities[game.ui.playerTick?.petUid] && playerHealth > 0) {
                shopShortcut("PetRevive", 1)
            }

            if (playerHealth <= document.getElementById("healplayerinput").value && playerHealth > 0 && game.ui.playerTick.gold >= 100 && shouldAutoHealPlayer && !playerHealTimeout) {
                shopShortcut("HealthPotion", 1)
                playerHealTimeout = true;
                setTimeout(() => {
                    playerHealTimeout = false;
                }, 300)
            }
            if (shouldAHRC) {
                let entities = Game.currentGame.world.entities;
                for (let uid in entities) {
                    let obj = entities[uid];
                    if (obj.fromTick.model == "Harvester") {
                        let amount = obj.fromTick.tier * 0.05 - 0.02;
                        game.network.sendRpc({name: "AddDepositToHarvester", uid: obj.fromTick.uid, deposit: amount});
                        game.network.sendRpc({name: "CollectHarvester", uid: obj.fromTick.uid});
                    };
                };
            };
            if (shouldAutoAim) {
                window.targets = [];
                let entities = game.renderer.npcs.attachments;
                for (let i in entities) {
                    if (document.getElementById('aimOptions').value == 'pl' ?
                        (entities[i].fromTick.model == "GamePlayer" && entities[i].fromTick.uid !== game.ui.playerTick.uid && entities[i].targetTick.partyId !== game.ui.playerPartyId && entities[i].fromTick.dead == 0) :
                        (entities[i].fromTick.model !== "GamePlayer" && entities[i].entityClass !== "Projectile")) {
                        window.targets.push(entities[i].fromTick);
                    };
                };
                if (window.targets.length > 0) {
                    const myPos = game.ui.playerTick.position;
                    window.targets.sort((a, b) => {
                        return measureDistance(myPos, a.position) - measureDistance(myPos, b.position);
                    });

                    const target = window.targets[0];
                    let reversedAim = game.inputPacketCreator.screenToYaw((target.position.x - myPos.x) * 100, (target.position.y - myPos.y) * 100);
                    game.inputPacketCreator.lastAnyYaw = reversedAim;
                    game.network.sendPacket(3, {mouseMoved: reversedAim});
                }
            };
            if (autoSwing) {
                game.network.sendInput({space: 0})
                game.network.sendInput({space: 1})
            }
            if (shouldLockYaw && game.ui.playerTick.aimingYaw != lockedYaw) {
                game.inputPacketCreator.lastAnyYaw = lockedYaw;
                game.network.sendPacket(3, {mouseMoved: lockedYaw});
            }
            if (shouldAutoRebuild && !window.autoBuildTimeout) {
                window.autoBuildTimeout = true
                for (let i of deadTowers) {
                    game.network.sendRpc({
                        name: "MakeBuilding",
                        type: i[0],
                        x: i[1],
                        y: i[2],
                        yaw: i[3],
                    });
                };
                setTimeout(() => {
                    window.autoBuildTimeout = false;
                }, 1000)
            }
        }
    })

    let deadTowers = []
    game.network.addRpcHandler("LocalBuilding", (data) => {
        if (shouldAutoRebuild) {
            for(let e of data) {
                if(!!e.dead) {
                    let yaw = 0;
                    if (["Harvester", "MeleeTower"].includes(e.type)) {
                        if (game.world.entities[e.uid] !== undefined) yaw = game.world.entities[e.uid].targetTick.yaw;
                    }
                    deadTowers.push([e.type, e.x, e.y, yaw, e.tier])
                };
                for (let i of deadTowers) {
                    if (e.type == i[0] && e.x == i[1] && e.y == i[2] && e.dead == 0) {
                        deadTowers.splice(i, 1)
                    }
                };
                if(e.type == "GoldStash") deadTowers = []
            }
        };
    });

    let mousePs = {};
    let should3x3Walls = false;
    let should5x5Walls = false;
    let should7x7Walls = false;
    let should9x9Walls = false;

    addEventListener('keydown', function (e) {
        if(document.activeElement.tagName.toLowerCase() !== "input" && document.activeElement.tagName.toLowerCase() !== "textarea") {
            if (e.key == "z" && !should3x3Walls) {
                game.ui.getComponent("PopupOverlay").showHint('3x3 Walls On',1000)
                should3x3Walls = true;
                should5x5Walls = false;
                should7x7Walls = false;
                should9x9Walls = false;
            }
            if (e.key == "x" && !should5x5Walls) {
                game.ui.getComponent("PopupOverlay").showHint('5x5 Walls On',1000)
                should3x3Walls = false;
                should5x5Walls = true;
                should7x7Walls = false;
                should9x9Walls = false;
            }
            if (e.key == "c" && !should7x7Walls) {
                game.ui.getComponent("PopupOverlay").showHint('7x7 Walls On',1000)
                should3x3Walls = false;
                should5x5Walls = false;
                should7x7Walls = true;
                should9x9Walls = false;
            }
            if (e.key == "v" && !should9x9Walls) {
                game.ui.getComponent("PopupOverlay").showHint('9x9 Walls On',1000)
                should3x3Walls = false;
                should5x5Walls = false;
                should7x7Walls = false;
                should9x9Walls = true;
            }
        }
    })

    addEventListener('keyup', function (e) {
        if(document.activeElement.tagName.toLowerCase() !== "input" && document.activeElement.tagName.toLowerCase() !== "textarea") {
            if (e.key == "z") {
                should3x3Walls = false;
            }
            if (e.key == "x") {
                should5x5Walls = false;
            }
            if (e.key == "c") {
                should7x7Walls = false;
            }
            if (e.key == "v") {
                should9x9Walls = false;
            }
        }
    })

    function placeWall(x, y) {
        game.network.sendRpc({name: 'MakeBuilding', x: x, y: y, type: "Wall", yaw: 0});
    }

    document.addEventListener('mousemove', e => {
        mousePs = {x: e.clientX, y: e.clientY};
        if (game.inputManager.mouseDown && game.ui.components.PlacementOverlay.buildingId == "Wall") {
            var buildingSchema = game.ui.getBuildingSchema();
            var schemaData = buildingSchema.Wall;
            var world = game.world;
            var worldPos = game.renderer.screenToWorld(mousePs.x, mousePs.y);
            var cellIndexes = world.entityGrid.getCellIndexes(worldPos.x, worldPos.y, {width: schemaData.gridWidth, height: schemaData.gridHeight});
            var cellSize = world.entityGrid.getCellSize();
            var cellAverages = { x: 0, y: 0 };
            for (var i in cellIndexes) {
                if (!cellIndexes[i]) {
                    return false;
                }
                var cellPos = world.entityGrid.getCellCoords(cellIndexes[i]);
                cellAverages.x += cellPos.x;
                cellAverages.y += cellPos.y;
            }
            cellAverages.x = cellAverages.x/cellIndexes.length;
            cellAverages.y = cellAverages.y/cellIndexes.length;
            var gridPos = {
                x: cellAverages.x * cellSize + cellSize/2,
                y: cellAverages.y * cellSize + cellSize/2
            };
            if (should3x3Walls) {
                //layer 1
                placeWall(gridPos.x - 48, gridPos.y + 48);
                placeWall(gridPos.x, gridPos.y + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48);
                //layer 2
                placeWall(gridPos.x - 48, gridPos.y);
                placeWall(gridPos.x, gridPos.y);
                placeWall(gridPos.x + 48, gridPos.y);
                //layer 3
                placeWall(gridPos.x - 48, gridPos.y - 48);
                placeWall(gridPos.x, gridPos.y - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48);
            }
            if (should5x5Walls) {
                //layer 1
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48 + 48);
                //layer 2
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48);
                placeWall(gridPos.x, gridPos.y + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48);
                //layer 3
                placeWall(gridPos.x - 48 - 48, gridPos.y);
                placeWall(gridPos.x - 48, gridPos.y);
                placeWall(gridPos.x, gridPos.y);
                placeWall(gridPos.x + 48, gridPos.y);
                placeWall(gridPos.x + 48 + 48, gridPos.y);
                //layer 4
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48);
                placeWall(gridPos.x, gridPos.y - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48);
                //layer 5
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48 - 48);
            }
            if (should7x7Walls) {
                //layer 1
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48 + 48 + 48);
                //layer 2
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48 + 48);
                //layer 3
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48);
                placeWall(gridPos.x, gridPos.y + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48);
                placeWall(gridPos.x + 48 +48, gridPos.y + 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48);
                //layer 4
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y);
                placeWall(gridPos.x - 48 - 48, gridPos.y);
                placeWall(gridPos.x - 48, gridPos.y);
                placeWall(gridPos.x, gridPos.y);
                placeWall(gridPos.x + 48, gridPos.y);
                placeWall(gridPos.x + 48 + 48, gridPos.y);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y);
                //layer 5
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48);
                placeWall(gridPos.x, gridPos.y - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48);
                //layer 6
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48 - 48);
                //layer 7
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48 - 48 - 48);
            }
            if (should9x9Walls) {
                //layer 1
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48 + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y + 48 + 48 + 48 + 48);
                //layer 2
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48 + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y + 48 + 48 + 48);
                //layer 3
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48 +48, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48 + 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y + 48 + 48);
                //layer 4
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y + 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y + 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y + 48);
                placeWall(gridPos.x - 48, gridPos.y + 48);
                placeWall(gridPos.x, gridPos.y + 48);
                placeWall(gridPos.x + 48, gridPos.y + 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y + 48)
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y + 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y + 48);
                //layer 5
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y);
                placeWall(gridPos.x - 48 - 48, gridPos.y);
                placeWall(gridPos.x - 48, gridPos.y);
                placeWall(gridPos.x, gridPos.y);
                placeWall(gridPos.x + 48, gridPos.y);
                placeWall(gridPos.x + 48 + 48, gridPos.y )
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y);
                //layer 6
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y - 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48);
                placeWall(gridPos.x, gridPos.y - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48)
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y - 48);
                //layer 7
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y - 48 - 48);
                //layer 8
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y - 48 - 48 - 48);
                //layer 9
                placeWall(gridPos.x - 48 - 48 - 48 - 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x - 48 - 48 - 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x - 48 - 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x - 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x + 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48, gridPos.y - 48 - 48 - 48 - 48);
                placeWall(gridPos.x + 48 + 48 + 48 + 48, gridPos.y - 48 - 48 - 48 - 48);
            }
        }
    })

    function loadedPlayers() { // loaded player names
        var returns = []
        Object.entries(Game.currentGame.world.entities)
            .forEach((stuff => {
            if (stuff[1].targetTick.entityClass == "PlayerEntity" && ((stuff[1].targetTick.uid !== Game.currentGame.world.entities[Game.currentGame.world.getMyUid()].targetTick.uid) || window.useSamePI)) {
                returns.push(stuff[1].targetTick.name)
            }
        }))
        return returns;
    }
    window.loadedIDS = function () {
        var returns = []
        Object.entries(Game.currentGame.world.entities)
            .forEach((stuff => {
            if (stuff[1].targetTick.entityClass == "PlayerEntity" && ((stuff[1].targetTick.uid !== Game.currentGame.world.entities[Game.currentGame.world.getMyUid()].targetTick.uid) || window.useSamePI)) {
                var h = stuff[1].targetTick
                if (document.querySelector('#advancedlpi')
                    .checked) {
                    returns.push(JSON.stringify(h))
                } else {
                    returns.push(stuff[1].targetTick.name + " - Wood: " + Game.currentGame.world.entities[stuff[1].targetTick.uid].targetTick.wood +
                                 ", Stone: " + Game.currentGame.world.entities[stuff[1].targetTick.uid].targetTick.stone + ", Gold: " + Game.currentGame
                                 .world.entities[stuff[1].targetTick.uid].targetTick.gold)
                }
            }
        }))
        return returns;
    }

    function spamchatclick() { // used to be called spam chat, its split chat now
        var user = document.querySelector('#spamchat')
        .value
        splitChatLength(user)
    }

    let dimension = 1;
    const onWindowResize = () => {
        if (!window.isInMenu && window.zoomonscroll) {
            const renderer = Game.currentGame.renderer;
            let canvasWidth = window.innerWidth * window.devicePixelRatio;
            let canvasHeight = window.innerHeight * window.devicePixelRatio;
            let ratio = canvasHeight / (1080 * dimension);
            renderer.scale = ratio;
            renderer.entities.setScale(ratio);
            renderer.ui.setScale(ratio);
            renderer.renderer.resize(canvasWidth, canvasHeight);
            renderer.viewport.width = renderer.renderer.width / renderer.scale + 2 * renderer.viewportPadding;
            renderer.viewport.height = renderer.renderer.height / renderer.scale + 2 * renderer.viewportPadding;
        }
    } // Zoom by Apex, modified by eh
    onWindowResize();
    var transparentMenu = false;
    window.onresize = onWindowResize;
    window.onwheel = e => {
        if (e.deltaY > 0) {
            dimension += 0.09;
            onWindowResize();
        } else if (e.deltaY < 0) {
            dimension -= 0.09;
            onWindowResize();
        }
    }
    var _isInChatbox = false;

    function doNewSend(sender) {
        if (sender[0] == "ch") {
            Game.currentGame.network.sendRpc({
                name: "SendChatMessage",
                channel: "Local",
                message: sender[1][0]
            })
        }
    }

    function measureDistance(obj1, obj2) {
        if (!(obj1.x && obj1.y && obj2.x && obj2.y)) return Infinity;
        let xDif = obj2.x - obj1.x;
        let yDif = obj2.y - obj1.y;
        return Math.abs((xDif**2) + (yDif**2));
    };

    function splitChatLength(text) {
        let i = 0;
        window.chatSetInterval = setInterval(function () {
            if (i < text.length) {
                doNewSend(['ch', [text.slice(i, i + 45)]])
                i += 45;
            } else {
                clearInterval(window.chatSetInterval)
            }
        }, 1050)
    }
    addEventListener('keyup', function (e) {
        if(document.activeElement.tagName.toLowerCase() !== "input" && document.activeElement.tagName.toLowerCase() !== "textarea") {
            if (e.key == "=") {
                game.ui.getComponent("PopupOverlay").showHint(
                    'Press [/] for menu, press [?] to lock angle, type !boss for boss wave, !marker to leave a mark on map, left click somewhere on the minimap to automatically move there, HOLD "c" for 3x3 wall, "x" for 5x5 and "z" for 7x7',
                    1.5e4
                )
            }
            if (e.key == "/") {
                document.querySelector("#hud-menu-settings")
                    .style.display = document.querySelector("#hud-menu-settings")
                    .style.display == "none" ? "block" : "none"
                document.querySelector("#hud-menu-shop")
                    .style.display = "none"
                document.querySelector("#hud-menu-party")
                    .style.display = "none"
            }
            if (e.key == "`") {
                game.inputManager.onKeyRelease({
                    keyCode: 117
                })
            }
            if (e.keyCode == 27) {
                let mb = document.getElementsByClassName("hud")[0];
                if (mb.style.display === "none") {
                    mb.style.display = "block";
                } else {
                    mb.style.display = "none";
                };
            }
            if (e.key == "?"){
                if (!shouldLockYaw) {
                    lockedYaw = game.ui.playerTick.aimingYaw
                    shouldLockYaw = true
                    game.ui.getComponent("PopupOverlay").showHint('Yaw locked, press [?] to unlock',1.5e4)
                } else {
                    shouldLockYaw = false
                    game.ui.getComponent("PopupOverlay").showHint('Yaw unlocked',1.5e4)
                }
            }
        }
    })

    document.querySelector('#advancedlpi')
        .addEventListener('change', function (e) {
        var THIS_LPI_EVENT = this;
    })
    document.querySelector('#zos')
        .addEventListener('change', function (e) {
        var THIS_ZOS_EVENT = this;
        window.zoomonscroll = THIS_ZOS_EVENT.checked
    })

    document.querySelector('#togglebot')
        .addEventListener('click', function () {
        botMode = !botMode
        this.innerText = botMode ? "Bot On" : "Bot Off"
    })
    document.querySelector('#toggleresp')
        .addEventListener('click', function () {
        autoRespawn = !autoRespawn
        this.innerText = autoRespawn ? "Respawn On" : "Respawn Off"
    })
    document.querySelector('#togglespmch')
        .addEventListener('click', function () {
        pauseChatSpam(document.querySelector('#spamchat').value)
        this.innerText = isSpamming ? "Spam Chat On" : "Spam Chat Off"
    })

    function moveNext(targetX, targetY) {
        let player = game.world.localPlayer.entity.targetTick.position
        if (player.x <= targetX && player.y <= targetY) {
            game.network.sendInput({
                right: 1,
                left: 0,
                up: 0,
                down: 1
            })
        } else if (player.x >= targetX && player.y <= targetY) {
            game.network.sendInput({
                right: 0,
                left: 1,
                up: 0,
                down: 1
            })
        } else if (player.x <= targetX && player.y >= targetY) {
            game.network.sendInput({
                right: 1,
                left: 0,
                up: 1,
                down: 0
            })
        } else if (player.x >= targetX && player.y >= targetY) {
            game.network.sendInput({
                right: 0,
                left: 1,
                up: 1,
                down: 0
            })
        }
    }

    function isXYCloseTo(x, y) {
        let playerTargetTick = game.world.localPlayer.entity.targetTick.position;
        const radius = 50;
        return ((x <= (playerTargetTick.x + radius) && x >= (playerTargetTick.x - radius)) && (y <= (playerTargetTick.y + radius) && y >= (playerTargetTick.y - radius)));
    }

    let moveIsActive = false;

    function goToPos(x, y) {
        moveIsActive = true;
        window.goToPosInterval = setInterval(() => {
            moveNext(x, y)
        }, 250)
        window.checkPosInterval = setInterval(() => {
            if (moveIsActive) {
                if (isXYCloseTo(x, y)) {
                    game.network.sendInput({
                        left: 0,
                        right: 0,
                        up: 0,
                        down: 0
                    })
                    game.ui.getComponent('PopupOverlay')
                        .showHint('Finished moving!', 1e4)
                    moveIsActive = false;
                    mapTimeouts.forEach((item => { clearTimeout(item) }))
                    clearInterval(window.goToPosInterval)
                    clearInterval(window.checkPosInterval)
                }
            } else {
                game.network.sendInput({
                    left: 0,
                    right: 0,
                    up: 0,
                    down: 0
                })
                doNewSend(['ch', ['MapMover: Unexpectedly shut down']])
                mapTimeouts.forEach((item => { clearTimeout(item) }))
                game.ui.getComponent('PopupOverlay')
                    .showHint('MapMover unexpectedly stopped', 1e4)
                clearInterval(window.checkPosInterval)
            }
        }, 10)
        let g = setTimeout(() => {
            clearInterval(window.goToPosInterval)
            game.ui.getComponent('PopupOverlay')
                .showHint('It has been 4 minutes to move to the position on the map, so it has automatically stopped to prevent infinite loops.', 1e4)
            moveIsActive = false;
            game.network.sendInput({
                left: 0,
                right: 0,
                up: 0,
                down: 0
            })
        }, 240000)
        mapTimeouts.push(g)
    }
    let mapContainer = document.createElement('div')

    mapContainer.id = "hud-map-container"
    document.querySelector('.hud-bottom-left')
        .append(mapContainer)
    $('#hud-map')
        .appendTo(document.querySelector('#hud-map-container'))
    document.querySelector("#hud-map-container")
        .addEventListener('mousemove', function (e) {
        var offset = $('#hud-map-container')
        .offset();
        // Then refer to
        mapMouseX = e.pageX - offset.left;
        mapMouseY = e.pageY - offset.top;
    })

    document.querySelector("#hud-map-container")
        .addEventListener('click', function (e) {
        if (!moveIsActive) {
            mapTimeouts.forEach((item => { clearTimeout(item) }))
            let yn = "y"
            game.ui.getComponent('PopupOverlay').showConfirmation('Are you sure you want to move to X:' + (mapMouseX * 170.4390625) + ",Y:" + (mapMouseY * 171.9977142857143) + '? You can right click the minimap to cancel this at any time.', 5e3, function() {
                if (yn.toLowerCase() == "y") {
                    game.ui.getComponent('PopupOverlay').showHint('Starting MapMove...', 3e3)
                    let moveToMapX = (mapMouseX * 170.4390625)
                    let moveToMapY = (mapMouseY * 171.9977142857143)
                    goToPos(moveToMapX, moveToMapY)
                }
            }, function() {
                game.ui.getComponent('PopupOverlay').showHint('OK, did not start MapMove', 3e3)
            })
        } else {
            moveIsActive = false;
            clearInterval(window.goToPosInterval)
            clearInterval(window.checkPosInterval)
            game.network.sendInput({
                left: 0,
                right: 0,
                up: 0,
                down: 0
            })
            mapTimeouts.forEach((item => { clearTimeout(item) }))
            game.ui.getComponent('PopupOverlay').showHint('MapMove is already in process. Restarting and moving to X:' + (mapMouseX * 170.4390625) + ",Y:" + (mapMouseY * 171.9977142857143) + '. You can right click the minimap to cancel this at any time.', 5e3)
            let yn = "y"
            if (yn.toLowerCase() == "y") {
                let moveToMapX = (mapMouseX * 170.4390625)
                let moveToMapY = (mapMouseY * 171.9977142857143)
                goToPos(moveToMapX, moveToMapY)
            }
        }
    })

    document.querySelector('#hud-map-container').addEventListener('contextmenu', function(ev) {
        ev.preventDefault();
        if(moveIsActive) {
            game.ui.getComponent('PopupOverlay').showConfirmation('Are you sure you want to cancel the current MapMove process?', 5e3, function() {
                moveIsActive = false;
                clearInterval(window.goToPosInterval)
                clearInterval(window.checkPosInterval)
                game.network.sendInput({
                    left: 0,
                    right: 0,
                    up: 0,
                    down: 0
                })
                game.ui.getComponent('PopupOverlay').showHint('Successfully stopped MapMover.', 3e3)
                mapTimeouts.forEach((item => { clearTimeout(item) }))
            }, function() {
                game.ui.getComponent('PopupOverlay').showHint('OK, did not stop MapMover.', 3e3)
            })
        } else {
            game.ui.getComponent('PopupOverlay').showHint('You are not in a MapMover process right now. Left click somewhere on the minimap to start one.')
        }
        return false;
    }, false);
}
thisIsForIframe()