BadHack

very bad

目前為 2022-04-01 提交的版本,檢視 最新版本

// ==UserScript==
// @name         BadHack
// @namespace    https://tampermonkey.net/
// @version      3.9.3
// @description  very bad
// @author       vn_Havy
// @match        http://zombs.io/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js
// ==/UserScript==

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);

game.renderer.ground.setVisible(false) //(true) for ground
game.renderer.projectiles.setVisible(false) //(true) for projectiles

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-ghost-t1.svg"></a>
<a id="shopshortcut10"><img src="http://zombs.io/asset/image/ui/inventory/inventory-pet-miner-t8.svg"></a>
<a id="shopshortcut11"><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', () => {shopShortcut("PetRevive", 1)});
document.getElementById('shopshortcut9').addEventListener('click', () => {Game.currentGame.network.sendRpc({name: "DeleteBuilding", uid: game.ui.getPlayerPetUid()})});
document.getElementById('shopshortcut10').addEventListener('click', () => {buyPet("PetMiner", getPetTier(6))});
document.getElementById('shopshortcut11').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() {
            console.log(i)
            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
    }
}

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()
    }
}, 10)
var moves = [moveUp, moveRight, moveDown, moveLeft]

window.useSamePI = false
addEventListener('keyup', function (e) {
    if (e.key == "`" && !_isInChatbox) {
        game.inputManager.onKeyRelease({
            keyCode: 117
        })
    }
})

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;
        }
    }
}

function ahrc1() { // 1 ahrc (collect and refuel), used in lpinterval
    var entities = Game.currentGame.world.entities
    for (let uid in entities) {
        if (!entities.hasOwnProperty(uid)) continue;
        let obj = entities[uid];
        Game.currentGame.network.sendRpc({
            name: "CollectHarvester",
            uid: obj.fromTick.uid
        });
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 1) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.07
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 2) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.11
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 3) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.17
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 4) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.22
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 5) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.25
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 6) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.28
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 7) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.42
            });
        }
        if (obj.fromTick.model == "Harvester" && obj.fromTick.tier == 8) {
            Game.currentGame.network.sendRpc({
                name: "AddDepositToHarvester",
                uid: obj.fromTick.uid,
                deposit: 0.65
            });
        }
    }
}
var lpinterval = setInterval(function () { // loaded player info, ahrc, isInMenu, noob = chatbot
    document.querySelector('#lpi')
        .innerText = "Loaded Player Info: " + JSON.stringify(window.loadedIDS())
    if (window.ahrc) {
        ahrc1()
    }
    window.isInMenu = document.querySelector('#hud-menu-settings')
        .style.display == "block" ? true : false
}, 250)

window.addEventListener("keyup", e => {
    switch (e.keyCode) {
        case 27:
            var mb = document.getElementsByClassName("hud")[0];
            if (mb.style.display === "none") {
                mb.style.display = "block";
            } else {
                mb.style.display = "none";
            }
            break;
    }
})

let settingsHTML = `
<button class="btn btn-purple ehack-btn" style="border-radius:25%" id="lagspam-btn">Enable Lag Spam</button>
<button class="btn btn-purple ehack-btn" style="border-radius:25%" id="spamchatbtn">Split Chat</button>
<button class="btn btn-purple ehack-btn" style="border-radius:25%" id="togglespmch">Enable Chat Spam</button>
<input type="text" id="spamchat" placeholder="Message" class="btn btn-white ehack-btn" style="border-radius:25%; width: 39%">
<hr>
<button class="btn btn-blue ehack-btn" style="border-radius:25%" id="clearchat-btn">Enable Auto Clear Chat</button>
<button class="btn btn-blue ehack-btn" style="border-radius:25%" id="autoupgradeall-btn">Enable Auto Upgrade</button>
<button class="btn btn-blue ehack-btn" style="border-radius:25%" id="togglebot">Enable Bot</button>
<button class="btn btn-blue ehack-btn" style="border-radius:25%" id="togglespinner">Enable Spinner (WIP)</button>
<hr>
<button class="btn btn-red ehack-btn ehack-btn" style="border-radius:25%" id="toggleahrc">Enable AHRC</button>
<button class="btn btn-red ehack-btn" style="border-radius:25%" id="toggleswing">Enable Auto Swing</button>
<button class="btn btn-red ehack-btn" style="border-radius:25%" id="toggleresp">Enable Auto Respawn</button>
<button class="btn btn-red ehack-btn" style="border-radius:25%" id="togglerb">Enable Auto Rebuild (WIP)</button>
<hr>
<button class="btn btn-white ehack-btn" style="border-radius:25%" onclick="Game.currentGame.network.disconnect()">Disconnect</button>
<button class="btn btn-gold ehack-btn" style="border-radius:25%" id="menu-leaveparty-btn">Leave Party</button>
<button class="btn btn-gold ehack-btn" style="border-radius:25%" 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="btn btn-white ehack-btn" id="menu-jpbsk-input" style="border-radius:25%; width: 27%" placeholder="Share Key">
<button class="btn btn-gold ehack-btn" style="border-radius:25%" id="autoaccept-btn">Enable Auto Accept</button>
<hr>
<button class="btn btn-gold ehack-btn" style="border-radius:25%" id="spamallparty-btn">Enable Spam All Party</button>
<button class="btn btn-gold ehack-btn" style="border-radius:25%" id="spampartybyid-btn">Enable Spam Party By ID</button>
<input type="text" class="btn btn-white ehack-btn" id="party-id-input" style="border-radius:25%; width: 23%" placeholder="Party ID">
<hr>
<button id="healplayer" class="btn btn-red ehack-btn" style="border-radius:25%">Disable Heal</button>
<input type="text" class="btn btn-white ehack-btn" value="20" id="healplayerinput" style="border-radius:25%; width: 8%">
<button id="healpet" class="btn btn-red ehack-btn" style="border-radius:25%">Disable Heal Pet</button>
<input type="text" class="btn btn-white ehack-btn" value="30" id="healpetinput" style="border-radius:25%; width: 8%">
<button id="revivepet" class="btn btn-red ehack-btn" style="border-radius:25%">Disable Revive</button>
<button id="evolvepet" class="btn btn-red ehack-btn" style="border-radius:25%">Disable Evolve</button>
<hr>
<button id="sellall" class="btn btn-green ehack-btn" style="border-radius:25%">Sell All Towers</button>
<button id="sellwall" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Wall</button>
<button id="selldoor" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Door</button>
<button id="selltrap" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Slow Trap</button>
<button id="sellharvester" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Harvester</button>
<hr>
<button id="sellarrow" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Arrow</button>
<button id="sellcannon" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Cannon</button>
<button id="sellbomb" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Bomb</button>
<button id="sellmelee" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Melee</button>
<button id="sellmagic" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Mage</button>
<button id="sellminer" class="btn btn-green ehack-btn" style="border-radius:25%">Sell Gold Miner</button>
<hr>
<button id="hchat-btn" class="btn btn-purple ehack-btn" style="border-radius:25%">Hide Chat</button>
<button id="hpop-btn" class="btn btn-purple ehack-btn" style="border-radius:25%">Hide Popup</button>
<button id="hldb-btn" class="btn btn-purple ehack-btn" style="border-radius:25%">Hide Leaderboard</button>
<button id="hmap-btn" class="btn btn-purple ehack-btn" style="border-radius:25%">Hide Map</button>
<button id="hss-btn" class="btn btn-purple ehack-btn" style="border-radius:25%">Hide SS</button>
<hr>
<p style="font-size:10px;">Advanced Player Info?</p><input type="checkbox" id="advancedlpi">
<br>
<p style="font-size:10px;">Zoom On Scroll?</p><input type="checkbox" id="zos">
<br>
<p id="lpi">Loaded Player Info: </p>
<style>
.menu-textbox{
    border-radius:25%;
    background-color: rgba(171, 183, 183, 0.25);
    border: 2px solid black;
    color:white;
}
.ehack-btn:hover{
border: 1px solid grey;
}
</style>
`
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("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("togglerb").addEventListener("click", toggleRB);
document.getElementById("togglerb").addEventListener("click", toggleRBbtn);
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.querySelector('#clearchat-btn').addEventListener('click', clearChat)
document.querySelector('#clearchat-btn').addEventListener('click', clearChatbtn)
document.querySelector('#toggleswing').addEventListener('click', autoSwing)
document.querySelector('#hchat-btn').addEventListener('click', hideChat)
document.querySelector('#hpop-btn').addEventListener('click', hidePopupOverlay)
document.querySelector('#hldb-btn').addEventListener('click', hideLeaderboard)
document.querySelector('#hmap-btn').addEventListener('click', hideMap)
document.querySelector('#hss-btn').addEventListener('click', hideShopShortcut)
document.querySelector('#menu-leaveparty-btn').addEventListener('click', onLeaveParty)
document.querySelector('#spamchatbtn').addEventListener('click', spamchatclick)


function sellAllByType(type) {
    if (!game.ui.playerPartyCanSell) return;

    let sellInterval = () => {
        let target = Object.values(game.ui.buildings).find(e => e.type == type);
        if (target !== undefined) {
            Game.currentGame.network.sendRpc({name: "DeleteBuilding", uid: target.uid});
            setTimeout(() => { sellInterval(); }, 100);
        }
    }
    sellInterval();
};

document.getElementById("sellall").addEventListener('click', function() {
    Game.currentGame.ui.getComponent("PopupOverlay").showConfirmation("Are you sure you want to delete all towers?", 1e4, function() {
        let sellInterval = () => {
            if (Object.keys(game.ui.buildings).length > 1 && game.ui.playerPartyCanSell) {
                Game.currentGame.network.sendRpc({name: "DeleteBuilding", uid: parseInt(Object.keys(game.ui.buildings)[1])});
                setTimeout(() => { sellInterval(); }, 100);
            }
        }
        sellInterval();
    })
})

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

function hidePopupOverlay() {
    if (document.getElementById("hud-popup-overlay").style.display === "none" && document.getElementById("hpop-btn").innerHTML == "Show Popup") {
        document.getElementById("hud-popup-overlay").style.display = "block";
        document.getElementById("hpop-btn").innerHTML = "Hide Popup";
    } else {
        document.getElementById("hud-popup-overlay").style.display = "none";
        document.getElementById("hpop-btn").innerHTML = "Show Popup";
    }
}

function hideLeaderboard() {
    if (document.getElementById("hud-leaderboard").style.display === "none" && document.getElementById("hldb-btn").innerHTML == "Show Leaderboard") {
        document.getElementById("hud-leaderboard").style.display = "block";
        document.getElementById("hldb-btn").innerHTML = "Hide Leaderboard";
    } else {
        document.getElementById("hud-leaderboard").style.display = "none";
        document.getElementById("hldb-btn").innerHTML = "Show Leaderboard";
    }
}


function hideMap() {
    if (document.getElementsByClassName("hud-bottom-left")[0].style.display === "none" && document.getElementById("hmap-btn").innerHTML == "Show Map") {
        document.getElementsByClassName("hud-bottom-left")[0].style.display = "block";
        document.getElementById("hmap-btn").innerHTML = "Hide Map";
    } else {
        document.getElementsByClassName("hud-bottom-left")[0].style.display = "none";
        document.getElementById("hmap-btn").innerHTML = "Show Map";
    }
}

function hideChat() {
    if (document.getElementsByClassName("hud-top-left")[0].style.display === "none" && document.getElementById("hchat-btn").innerHTML == "Show Chat"){
        document.getElementsByClassName("hud-top-left")[0].style.display = "block";
        document.getElementById("hchat-btn").innerHTML = "Hide Chat";
    } else {
        document.getElementsByClassName("hud-top-left")[0].style.display = "none";
        document.getElementById("hchat-btn").innerHTML = "Show Chat";
    }
}

function hideShopShortcut() {
    if (document.getElementsByClassName("hud-top-center")[0].style.display === "none" && document.getElementById("hss-btn").innerHTML == "Show SS"){
        document.getElementsByClassName("hud-top-center")[0].style.display = "block";
        document.getElementById("hss-btn").innerHTML = "Hide SS";
    } else {
        document.getElementsByClassName("hud-top-center")[0].style.display = "none";
        document.getElementById("hss-btn").innerHTML = "Show SS";
    }
}

function lagSpambtn() {
    if (document.getElementById("lagspam-btn").innerHTML == "Disable Lag Spam") {
        document.getElementById("lagspam-btn").innerHTML = "Enable Lag Spam";
    } else {
        document.getElementById("lagspam-btn").innerHTML = "Disable Lag Spam";
    }
}
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 == "Disable Spam All Party") {
        document.getElementById("spamallparty-btn").innerHTML = "Enable Spam All Party";
    } else {
        document.getElementById("spamallparty-btn").innerHTML = "Disable Spam All Party";
    }
}
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 == "Disable Auto Accept") {
        document.getElementById("autoaccept-btn").innerHTML = "Enable Auto Accept";
    } else {
        document.getElementById("autoaccept-btn").innerHTML = "Disable Auto Accept";
    }
}
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 == "Disable Auto Upgrade") {
        document.getElementById("autoupgradeall-btn").innerHTML = "Enable Auto Upgrade";
    } else {
        document.getElementById("autoupgradeall-btn").innerHTML = "Disable Auto Upgrade";
    }
}
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 == "Disable Spam Party By ID") {
        document.getElementById("spampartybyid-btn").innerHTML = "Enable Spam Party By ID";
    } else {
        document.getElementById("spampartybyid-btn").innerHTML = "Disable Spam Party By ID";
    }
}
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 == "Disable Auto Clear Chat") {
        document.getElementById("clearchat-btn").innerHTML = "Enable Auto Clear Chat";
    } else {
        document.getElementById("clearchat-btn").innerHTML = "Disable Auto Clear Chat";
    }
}
var shouldClearChat = null;
function clearChat() {
    clearInterval(shouldClearChat);
    if (shouldClearChat !== null) {
        shouldClearChat = null;
    } else {
        shouldClearChat = setInterval(function () {
            document.querySelector('.hud-chat-messages').innerHTML = ""
        },500)
    }
}

let shouldRebuild
let rebuildData = [];
let rebuiltTowers = [];
function toggleRBbtn() {
    if (document.getElementById("togglerb").innerHTML == "Disable Auto Rebuild") {
        document.getElementById("togglerb").innerHTML = "Enable Auto Rebuild";
        shouldRebuild = false
    } else {
        document.getElementById("togglerb").innerHTML = "Disable Auto Rebuild";
        shouldRebuild = true
    }
}
function toggleRB() {}


function toggleHealPet () {
    if (!shouldAutoHealPet) {
        shouldAutoHealPet = true;
        document.getElementById("healpet").innerHTML = "Disable Heal Pet";
    } else {
        shouldAutoHealPet = false;
        document.getElementById("healpet").innerHTML = "Enable Heal Pet";
    }
}
function toggleRevivePet () {
    if (!shouldAutoRevivePet) {
        shouldAutoRevivePet = true
        document.getElementById("revivepet").innerHTML = "Disable Revive";
    } else {
        shouldAutoRevivePet = false
        document.getElementById("revivepet").innerHTML = "Enable Revive";
    }
}
function toggleEvolvePet () {
    if (!shouldAutoEvolvePet) {
        shouldAutoEvolvePet = true
        document.getElementById("evolvepet").innerHTML = "Disable Evolve";
    } else {
        shouldAutoEvolvePet = false
        document.getElementById("evolvepet").innerHTML = "Enable Evolve";
    }
}
function toggleHealPlayer () {
    if (!shouldAutoHealPlayer) {
        shouldAutoHealPlayer = true
        document.getElementById("healplayer").innerHTML = "Disable Heal"
    } else {
        shouldAutoHealPlayer = false
        document.getElementById("healplayer").innerHTML = "Enable Heal"
    }
}


let shouldAutoHealPet = true
let shouldAutoRevivePet = true
let shouldAutoEvolvePet = true
let shouldAutoHealPlayer = true
let petSpawned = false
let myPet = {};
let myPlayer = {};
game.network.addEntityUpdateHandler((data) => {
    if (game.ui.playerTick.petUid !== 0) {
        petSpawned = true;
        if (game.world.entities[game.ui.playerTick.petUid]) {
            let petHealth = (myPet.health/myPet.maxHealth) * 100
            myPet = game.world.entities[game.ui.playerTick.petUid].fromTick;
            if (shouldAutoHealPet && petHealth < document.getElementById("healpetinput").value && petHealth > 0 && game.ui.playerTick.gold >= 100 && shouldAutoHealPet) {
                if (!window.healPet) {
                    shopShortcut("PetHealthPotion", 1)
                    window.healPet = true;
                    setTimeout(() => {
                        window.healPet = 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] && myPlayer.health > 0) {
        shopShortcut("PetRevive", 1)
    }
    myPlayer = game.world.entities[game.ui.playerTick.uid].fromTick
    let playerHealth = (myPlayer.health/myPlayer.maxHealth) * 100;
    if (playerHealth <= document.getElementById("healplayerinput").value && playerHealth > 0 && game.ui.playerTick.gold >= 100 && shouldAutoHealPlayer) {
        if (!window.playerTimeout_1) {
            shopShortcut("HealthPotion", 1)
            window.playerTimeout_1 = true;
            setTimeout(() => {
                window.playerTimeout_1 = false;
            }, 300)
        }
    }
})

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 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)
        }
    }, 1500)
}
addEventListener('keydown', function (e) {
    if (!_isInChatbox && 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"
    } else if (e.key == "=" && !_isInChatbox) {
        game.ui.getComponent("PopupOverlay").showHint(
            'Press [/] for menu, left click somewhere on the minimap to automatically move there, type !boss for boss wave, !marker to leave a mark on map.',
            1.5e4
        )
    }
})
document.querySelector('#toggleahrc')
    .addEventListener('click', function () {
    window.ahrc = !window.ahrc
    document.querySelector('#toggleahrc')
        .innerText = window.ahrc ? "Disable AHRC" : "Enable AHRC"
})

var isSwinging = false;
function autoSwing() {
    if (isSwinging) {
        isSwinging = false
        clearInterval(window.swing)
    } else {
        isSwinging = true
        window.swing = setInterval(function () {
            game.network.sendInput({space: 0})
            game.network.sendInput({space: 1})
        }, 0);
    }
    document.querySelector('#toggleswing')
        .innerText = isSwinging ? "Disable Auto Swing" : "Enable Auto Swing"
}

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 ? "Disable Bot" : "Enable Bot"
})
document.querySelector('#toggleresp')
    .addEventListener('click', function () {
    autoRespawn = !autoRespawn
    this.innerText = autoRespawn ? "Disable Auto Respawn" : "Enable Auto Respawn"
})
document.querySelector('#togglespmch')
    .addEventListener('click', function () {
    pauseChatSpam(document.querySelector('#spamchat').value)
    this.innerText = isSpamming ? "Disable Spam Chat" : "Enable Spam Chat"
})

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);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址