Bonk Better Spawns

Helps to change the initial position of the player without using teams and without opening editor.

当前为 2024-11-23 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Bonk Better Spawns
// @namespace    https://greasyfork.org/en/users/1272759
// @version      1.1
// @description  Helps to change the initial position of the player without using teams and without opening editor.
// @author       Apx
// @match        https://bonk.io/*
// @match        https://bonkisback.io/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

const scriptName = 'Bonk Better Spawns';

function injector (src) {
    let newSrc = src;
    window.BBSpawns = {
        spawnId: -1,
        playersSelected: [],
        spawnSelected: -1,
        spawnPointData: [],
        lastMap: null,
        keepPositions: [],
    };

    const PIXI = window.PIXI;
    const spawnRenderer = PIXI.autoDetectRenderer({width: 36, height: 36, antialias: true, transparent: true});

    let BBSpawnsCSS = document.createElement('style');
    BBSpawnsCSS.innerHTML = `
	#bbspawns {
		width: 100%;
		height: 100%;
		position: absolute;
	}
	#bbs_container {
		width: fit-content;
		height: fit-content;
        position: absolute;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		margin: auto;
	}
	#bbs {
		width: 700px;
		height: 400px;
		display: flex;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		justify-content: space-between;
    }
	#bbs_shadow {
		outline: 3000px solid rgba(0, 0, 0, 0.50);
	}
		#bbs_leftbox {
		width: 200px;
		position: relative;
		background-color: #cfd8dc;
		border-radius: 7px;
		height: 100%;
	}
	#bbs_midbox {
		width: 200px;
		position: relative;
		background-color: #cfd8dc;
		border-radius: 7px;
		height: 100%;
	}
	#bbs_rightbox {
		width: calc(100% - 435px);
		position: relative;
		background-color: #cfd8dc;
		border-radius: 7px;
		height: 100%;
	}
	.newbonklobby_playerentry_selected {
		width: 100%;
		height: 47px;
		font-family: "futurept_b1";
		position: relative;
		font-size: 15px;
		cursor: pointer;
		box-sizing: border-box;
		border-left: 4px solid #cfd8dc;
		border-right: 4px solid #cfd8dc;
		border-top: 4px solid #cfd8dc;
  		background-color: #55bad430 !important;
		vertical-align: top;
	}
	.bss_entry {
		width: 100%;
		height: 47px;
		font-family: "futurept_b1";
		position: relative;
		font-size: 15px;
		cursor: pointer;
		box-sizing: border-box;
		border-left: 4px solid #cfd8dc;
		border-right: 4px solid #cfd8dc;
		border-top: 4px solid #cfd8dc;
		vertical-align: top;
		overflow-x: hidden;
		background-color: rgba(0, 0, 0, 0.02);
	}
	.bss_entry_selected {
		width: 100%;
		height: 47px;
		font-family: "futurept_b1";
		position: relative;
		font-size: 15px;
		cursor: pointer;
		box-sizing: border-box;
		border-left: 4px solid #cfd8dc;
		border-right: 4px solid #cfd8dc;
		border-top: 4px solid #cfd8dc;
		background-color: #55bad430 !important;
		vertical-align: top;
    	overflow-x: hidden;
		background-color: rgba(0, 0, 0, 0.02);
	}
	.bss_spawnentry:hover {
		background-color: rgba(100,100,100,0.10);
	}
	.bss_spawnentry_name {
		color: #000000;
		position: absolute;
		left: 42px;
		top: 2px;
		pointer-events: none;
	    white-space: pre;
	}
	.bss_elementcontainer {
		width: 100%;
		position: absolute;
		overflow-y: auto;
		top: 34px;
	}
	.bss_elementcontainer::-webkit-scrollbar-track {
		background-color: #cfd8dc;
	}
	.bss_elementcontainer::-webkit-scrollbar-thumb {
		background-color: #757575;
	}
	.bss_elementcontainer::-webkit-scrollbar {
		height: 12px;
		width: 0.6em;
		background-color: #cfd8dc;
	}
	#bss_playerentry_elementcontainer {
		height: calc(100% - 119px);
	}
	#bss_spawnentry_elementcontainer {
		height: calc(100% - 94px);
	}
	.bss_mapimage {
		width: calc(100% - 20px);
		margin: 10px;
		margin-top: 44px;
		position: relative;
	}
	.bss_bottombuttoncontainer {
		width: 90%;
		position: absolute;
		bottom: 0;
		height: fit-content;
		padding: 10px 5% 0 5%;
	}
	#bss_applybutton, #bss_clearplayerpointbutton, #bss_clearplayerselectionbutton, #bss_setforallbutton, #bss_clearspawnselectionbutton {
		margin-bottom: 4px;
	}
	`;

    // draw spawn (like avatar)
    const drawSpawn = (spawnData) => {
        let teams = [spawnData.f,spawnData.r,spawnData.b,spawnData.gr,spawnData.ye, (spawnData.f + spawnData.r + spawnData.b + spawnData.gr + spawnData.ye)];
        let spawn = new PIXI.Graphics();
        let mask = new PIXI.Graphics();
        spawn.beginFill(0x91ada7);
        spawn.drawCircle(0,0,15,1);
        spawn.x = 18;
        spawn.y = 18;
        spawn.endFill();
        for(let i = 0; i < teams[5]; i++){
            let color;
            if(teams[0]){
                teams[0] = false;
                color = 0x1abc9c;
            }
            else if(teams[1]){
                teams[1] = false;
                color = 0xd32f2f;
            }
            else if(teams[2]){
                teams[2] = false;
                color = 0x448aff;
            }
            else if(teams[3]){
                teams[3] = false;
                color = 0x177819;
            }
            else if(teams[4]){
                teams[4] = false;
                color = 0xffd90e;
            }
            spawn.beginFill(color);
            spawn.drawRect(((1/teams[5])*i - 0.5)*30,-15,30,30);
            spawn.endFill();
            spawn.rotation = 45 * (Math.PI/180);
        }
        mask.beginFill(0);
        mask.drawCircle(18,18,15,1);
        spawn.mask = mask;
        let renderer = spawnRenderer;
        renderer.render(spawn);
        return renderer.extract.image();
    }

    document.getElementsByTagName('head')[0].appendChild(BBSpawnsCSS);
    let BBSpawnsMenu = document.createElement('div');
    document.getElementById('newbonkgamecontainer').appendChild(BBSpawnsMenu);
    BBSpawnsMenu.outerHTML = `
	<div id="bbspawns" style="visibility: hidden; opacity: 0; z-index: 2;">
		<div id="bbs_shadow"></div>
        <div id="bbs_container">
			<div id="bbs">
				<div id="bbs_leftbox">
					<div class="windowTopBar windowTopBar_classic">Players</div>
					<div id="bss_playerentry_elementcontainer" class="bss_elementcontainer"></div>
					<div class="bss_bottombuttoncontainer">
						<div id="bss_applybutton" class="brownButton brownButton_classic buttonShadow">Apply</div>
						<div id="bss_clearplayerpointbutton" class="brownButton brownButton_classic buttonShadow">Clear Spawn Point</div>
						<div id="bss_clearplayerselectionbutton" class="brownButton brownButton_classic buttonShadow">Clear Selection</div>
					</div>
				</div>
				<div id="bbs_midbox">
					<div class="windowTopBar windowTopBar_classic">Spawns</div>
					<div id="bss_spawnentry_elementcontainer" class="bss_elementcontainer"></div>
					<div class="bss_bottombuttoncontainer">
					<div id="bss_setforallbutton" class="brownButton brownButton_classic buttonShadow">Set For All</div>
					<div id="bss_clearspawnselectionbutton" class="brownButton brownButton_classic buttonShadow">Clear Selection</div>
				</div>
			</div>
			<div id="bbs_rightbox">
				<div class="windowTopBar windowTopBar_classic">Map Previev</div>
		    	</div>
			</div>
			<div id="bss_closebutton" class="windowCloseButton brownButton brownButton_classic buttonShadow"></div>
		</div>
	</div>
    `;

    window.BBSpawns.exitMenu = () => {
        window.anime({
            targets: document.getElementById("bbspawns"),
            opacity: "0",
            autoplay: true,
            duration: 130,
            easing: "easeOutCubic",
            complete: () => {
                document.getElementById("bbspawns").style.visibility = "hidden";
            }
        });
        clearChildren(document.getElementById("bss_playerentry_elementcontainer"));
        clearChildren(document.getElementById("bss_spawnentry_elementcontainer"));
        clearChildren(document.getElementById("bbs_rightbox"));
    }

    // Exit Button
    document.getElementById("bss_closebutton").onclick = window.BBSpawns.exitMenu;

    // Apply
    document.getElementById("bss_applybutton").onclick = () => {
        if(window.BBSpawns.spawnSelected == -1) return;
        for(let i = 0; i < window.BBSpawns.playersSelected.length; i++) {
            window.BBSpawns.spawnPointData[window.BBSpawns.playersSelected[i]] = window.BBSpawns.spawnSelected;
            window.BBSpawns.keepPositions[window.BBSpawns.playersSelected[i]] = window.BBSpawns.spawnSelected;
        }
        window.BBSpawns.spawnSelected = -1;
        window.BBSpawns.playersSelected = [];
        window.BBSpawns.updateEntries();
    }
    // Clear Spawn Point
    document.getElementById("bss_clearplayerpointbutton").onclick = () => {
        for(let i = 0; i < window.BBSpawns.playersSelected.length; i++){
            window.BBSpawns.spawnPointData[window.BBSpawns.playersSelected[i]] = null;
            window.BBSpawns.keepPositions[window.BBSpawns.playersSelected[i]] = null;
        }
        let players = document.getElementById("bss_playerentry_elementcontainer").children;
        window.BBSpawns.playersSelected = [];
        window.BBSpawns.updateEntries();
    }

    // Clear Player Selection
    document.getElementById("bss_clearplayerselectionbutton").onclick = () => {
        window.BBSpawns.playersSelected = [];
        window.BBSpawns.updateEntries();
    }

    // Set Spawn Point For All
    document.getElementById("bss_setforallbutton").onclick = () => {
        if(window.BBSpawns.spawnSelected == -1) return;
        for(let i = 0; i < window.BBSpawns.players.length; i++){
            if(window.BBSpawns.players[i]){
                window.BBSpawns.spawnPointData[i] = window.BBSpawns.spawnSelected;
                window.BBSpawns.keepPositions[i] = window.BBSpawns.spawnSelected;
            }
        }
        window.BBSpawns.spawnSelected = -1;
        window.BBSpawns.playersSelected = [];
        window.BBSpawns.updateEntries();
    }

    document.getElementById("bss_clearspawnselectionbutton").onclick = () => {
        window.BBSpawns.spawnSelected = -1;
        window.BBSpawns.updateEntries();
    }

    // create image
    const mapImage = (spawnId) => {
        window.BBSpawns.spawnId = spawnId;
        let mapImg = window.BBSpawns.createMapImage(window.BBSpawns.map(),(document.getElementById("bbs_rightbox").clientWidth-20)/730);
        window.BBSpawns.spawnId = null;
        mapImg.classList.add("bss_mapimage");
        document.getElementById("bbs_rightbox").appendChild(mapImg);
    }
    const clearChildren = (element) => {
        while([...element.children].filter((x) => !x.classList.contains("windowTopBar")).length > 0) element.removeChild(element.children[element.children.length-1]);
    }

    window.BBSpawns.updateEntries = () => {
        clearChildren(document.getElementById("bss_playerentry_elementcontainer"));
        clearChildren(document.getElementById("bss_spawnentry_elementcontainer"));
        // players
        for(let id = 0; id < window.BBSpawns.players.length; id++){
            let player = window.BBSpawns.players[id];
            if(player){
                let playerentry = document.createElement("div");
                playerentry.classList.add(window.BBSpawns.playersSelected.find((x) => x == id) != undefined?"bss_entry_selected":"bss_entry");
                playerentry.onclick = () => {
                    if(playerentry.classList.contains("bss_entry")){
                        playerentry.classList.remove("bss_entry");
                        playerentry.classList.add("bss_entry_selected");
                        window.BBSpawns.playersSelected.push(id);
                    } else {
                        playerentry.classList.remove("bss_entry_selected");
                        playerentry.classList.add("bss_entry");

                        window.BBSpawns.playersSelected.splice(window.BBSpawns.playersSelected.indexOf(id));
                    }
                }
                playerentry.onmouseenter = window.BBSpawns.sounds.rlh;
                playerentry.onmousedown = window.BBSpawns.sounds.rlc;
                let playerskin = document.createElement("div");
                playerskin.classList.add("newbonklobby_playerentry_avatar");
                if(window.BBSpawns.avatarData[id] && window.BBSpawns.avatarData[id][1]){
                    playerskin.appendChild(window.BBSpawns.avatarData[id][1].cloneNode(true));
                } else {
                    try {
                        window.BBSpawns.createImage(player.avatar, 0, playerskin, "", 36, 36, window.BBSpawns.avatarData, id, 0, 2, 0.08, 0.3);
                    } catch (e) {}
                }
                let playername = document.createElement("div");
                playername.classList.add("newbonklobby_playerentry_name");
                playername.textContent = player.userName;
                let playerlevel = document.createElement("div");
                playerlevel.classList.add("newbonklobby_playerentry_level");
                playerlevel.textContent = player.guest?"Guest":"Level "+player.level;
                let playerspawnid = document.createElement("div");
                playerspawnid.classList.add("newbonklobby_playerentry_balance");
                playerspawnid.textContent = window.BBSpawns.spawnPointData[id]>-1?window.BBSpawns.spawnPointData[id]:"N/A";
                playerentry.appendChild(playerskin);
                playerentry.appendChild(playername);
                playerentry.appendChild(playerlevel);
                playerentry.appendChild(playerspawnid);
                document.getElementById("bss_playerentry_elementcontainer").appendChild(playerentry);
            }
        }
        // spawns
        let spawns = window.BBSpawns.map().spawns;
        for(let id = 0; id < spawns.length; id++){
            if(spawns[id]){
                let spawnentry = document.createElement("div");
                spawnentry.classList.add(window.BBSpawns.spawnSelected == id?"bss_entry_selected":"bss_entry");
                spawnentry.onclick = () => {
                    if(spawnentry.classList.contains("bss_entry_selected")){
                        spawnentry.classList.remove("bss_entry_selected");
                        spawnentry.classList.add("bss_entry");
                        window.BBSpawns.spawnSelected = -1;
                    } else {
                        for(let element = 0; element < document.getElementById("bss_spawnentry_elementcontainer").children.length; element++){
                            let elem = document.getElementById("bss_spawnentry_elementcontainer").children[element];
                            elem.classList.remove("bss_entry_selected");
                            elem.classList.add("bss_entry");
                        }
                        spawnentry.classList.remove("bss_entry");
                        spawnentry.classList.add("bss_entry_selected");
                        window.BBSpawns.spawnSelected = id;
                    }
                }
                spawnentry.onmouseenter = window.BBSpawns.sounds.rlh;
                spawnentry.onmousedown = window.BBSpawns.sounds.rlc;
                let spawnteams = document.createElement("div");
                spawnteams.classList.add("newbonklobby_playerentry_avatar");
                spawnteams.appendChild(drawSpawn(spawns[id]));
                let spawnname = document.createElement("div");
                spawnname.classList.add("bss_spawnentry_name");
                spawnname.textContent = spawns[id].n;
                let spawnid = document.createElement("div");
                spawnid.classList.add("newbonklobby_playerentry_level");
                spawnid.textContent = `Spawn ID: ${id}`;
                spawnentry.addEventListener("mouseover", () => {clearChildren(document.getElementById("bbs_rightbox"));mapImage(id)});
                spawnentry.addEventListener("mouseout", () => {clearChildren(document.getElementById("bbs_rightbox"));mapImage()});
                spawnentry.appendChild(spawnteams);
                spawnentry.appendChild(spawnname);
                spawnentry.appendChild(spawnid);
                document.getElementById("bss_spawnentry_elementcontainer").appendChild(spawnentry);
            }
        }
    }

    window.BBSpawns.updateSPData = () => {
        let map = window.BBSpawns.map();
        let lastMap = window.BBSpawns.lastMap;
        let clear = () => {window.BBSpawns.spawnPointData = []; window.BBSpawns.keepPositions = [];}
        if(lastMap != null){
            if(map.spawns.length != lastMap.spawns.length) clear();
            if(map.m.rxid != 0 && lastMap.m.rxid != 0 && map.m.rxid != lastMap.m.dbid) clear();
            if(map.m.rxid == 0 && map.m.dbid != lastMap.m.rxid && map.m.dbid != lastMap.m.dbid && map.m.dbid != lastMap.m.rxid) clear();
        }
        window.BBSpawns.lastMap = map;

    }
    window.BBSpawns.roomLeave = () => {
        window.BBSpawns.spawnPointData = [];
        window.BBSpawns.keepPositions = [];
        window.BBSpawns.lastMap = [];
        window.BBSpawns.playersSelected = [];
    }
    window.BBSpawns.displayWindow = (playerID) => {
        document.getElementById("bbspawns").style.visibility = "inherit";
        document.getElementById("bbspawns").style.opacity = "0";
        window.BBSpawns.updateSPData();
        window.anime({
            targets: document.getElementById("bbspawns"),
            opacity: "1",
            autoplay: true,
            duration: 250,
            easing: "easeOutCubic",
        });
        window.BBSpawns.playerSelected = playerID || -1;
        window.BBSpawns.updateEntries();
        mapImage();
    }


    const bigvar = newSrc.match(/[A-Za-z0-9$_]+\[[0-9]{6}\]/)[0].split('[')[0];
    const closePlayerentryMenu = newSrc.match(/this\[[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]\[[0-9]{1,5}]]\);[A-Za-z0-9\$_]{3}\(\);}/)[0].split(";")[1];
    const soundsRegex = newSrc.match(/0x424242\);[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]/)[0].split(';')[1];
    const lobbyPlayerIDRegex = newSrc.match(/\[];[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=\[];[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=function\([A-Za-z0-9\$_]{3}/)[0].split('(')[1];
    const createImageRegex = newSrc.match(/]]]\);}else {try{.../)[0].split("try{")[1].split("[")[0];
    const updatePlayersRegex = newSrc.match(/=\[];[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=\[];[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=function\([A-Za-z0-9\$_]{3}\){/);
    const imageRender = newSrc.match(/(?<=\);function )[A-Za-z0-9\$_]{1,3}(?=\([A-Za-z0-9\$_,]{7}\){\"use strict\")/)[0];

    //get players
    const playerList = newSrc.match(/=\[];[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=\[];[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=function\([A-Za-z0-9\$_]{3}\){.*?\){/)[0].split("if(")[1].match(/[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]\[[0-9]{1,3}]/)[0];
    const avatarData = newSrc.match(/(?<=36,36,)[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]/)[0];
    newSrc = newSrc.replace(updatePlayersRegex, updatePlayersRegex[0] + `window.BBSpawns.players = ${playerList};window.BBSpawns.avatarData = ${avatarData};`);

    // create button
    const moveToButtonRegex = newSrc.match(/\(\);}\);}if/);
    let setSpawnPointButton = `
    let button = document.createElement("div");
    button.classList.add("newbonklobby_playerentry_menu_button");
    button.classList.add("brownButton");
    button.classList.add("brownButton_classic");
    button.classList.add("buttonShadow");
    document.getElementsByClassName("newbonklobby_playerentry_menu")[0].appendChild(button);
    window.BBSpawns.sounds = ${soundsRegex};
    window.BBSpawns.sounds.setButtonSounds([...document.getElementById("bbspawns").getElementsByClassName("buttonShadow")]);
    button.textContent = "Set spawn point";
    button.onclick = function () {
        window.BBSpawns.playersSelected = [${lobbyPlayerIDRegex}];
        window.BBSpawns.displayWindow(${lobbyPlayerIDRegex});
        ${closePlayerentryMenu};
    }
    `;

    // salami
    const toolRegex = newSrc.match(/=new [A-Za-z0-9\$_]{1,3}\(this,[A-Za-z0-9\$_]{1,3}\[0\]\[0\],[A-Za-z0-9\$_]{1,3}\[0\]\[1\]\);/);
    newSrc = newSrc.replace(toolRegex, toolRegex + "window.BBSpawns.tools = this;")
    newSrc = newSrc.replace(moveToButtonRegex, moveToButtonRegex[0].split('}if')[0] + setSpawnPointButton + '}if');

    // spawn selection & spawn color fix
    const spawnColorRegex = newSrc.match(/(?<=5\){[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=0xffd90e;}).*?]]\(.*?\);(?=[A-Za-z0-9\$_]{3}.[A-Za-z0-9\$_]{3}\([0-9]{1,3}\))/);
    const spawnTeamsRegex = newSrc.match(/[A-Za-z0-9\$_]{1,3}\[[0-9]{1,3}]=3;}else if\(.{0,300}== false\){continue;}[^;]*?\({x:/);
    let spawn = spawnTeamsRegex[0].split("==")[0].split("if(")[1].match(/.*?(?=\[...\[[0-9]{1,3}]\[[0-9]{1,3}]] )/)[0];
    let spawnTeams = `
    else if(${spawn}.gr == true){
        ${spawnTeamsRegex[0].split("=3")[0]} = 4;
    }
    else if(${spawn}.ye == true){
        ${spawnTeamsRegex[0].split("=3")[0]} = 5;
    }
    else
    `;
    newSrc = newSrc.replace(spawnColorRegex, spawnColorRegex[0].split("(")[0] + `(window.BBSpawns.spawnId==${newSrc.match(/(?<==false;}for\()[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]/)[0]}?0xffffff:` + spawnColorRegex[0].split("(")[1]);
    newSrc = newSrc.replace(spawnTeamsRegex, spawnTeamsRegex[0].split("else")[0] + spawnTeams + spawnTeamsRegex[0].split("else")[1].replace("continue;", ""))

    // get some things i need (map && create map image)

    const createRoomRegex = newSrc.match(/\(0,[A-Za-z0-9\$_]{1,3}\.[A-Za-z0-9\$_]{1,3}\(.[0-9]{1,4}\)\);.{0,50}=3;}else/g);
    newSrc = newSrc.replace(createRoomRegex, createRoomRegex[0].split(';')[0] + `;
    ${createRoomRegex[0].split(";")[1]};
    window.BBSpawns.map = () => {return ${createRoomRegex[0].match(/(?<=;).*?\[.*?(?=\[)/)}.map};
    window.BBSpawns.createImage = ${createImageRegex}.createImage;
    if(document.getElementById("bbspawns").style.visibility == "inherit"){
        window.BBSpawns.tools.networkEngine.on("newPlayerJoined", () => window.BBSpawns.updateEntries());
        window.BBSpawns.tools.networkEngine.on("nameChange", () => window.BBSpawns.updateEntries());
        window.BBSpawns.tools.networkEngine.on("playerLevelledUp", () => window.BBSpawns.updateEntries());
        window.BBSpawns.tools.networkEngine.on("playerLeft", () => window.BBSpawns.updateEntries());
    }
    window.BBSpawns.createMapImage = ${newSrc.match(/(?<=\);}this\[.{0,8}\[[0-9]{1,5}]]\(\);.{0,8}=)[A-Za-z0-9\$_]{1,3}/)}.createImage;
    }else`);

    // put players on their initial positions
    let newStateRegex = newSrc.match(/B;}[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=.*?\(.*?,true\);/)[0];
    newSrc = newSrc.replace(newStateRegex, newStateRegex + `
    let discs = ${newStateRegex.split("}")[1].split("=")[0]}.discs;
    let map = window.BBSpawns.map();
    window.BBSpawns.updateSPData();
    if(
        window.bonkHost &&
        ${bigvar}.bonkHost.state &&
        document.getElementById("hostPlayerMenuKeepPositions") &&
	    document.getElementById("hostPlayerMenuKeepPositions").checked &&
	    window.bonkHost.toolFunctions.getGameSettings().map.s.re &&
	    window.bonkHost.toolFunctions.getGameSettings().ga === "b" &&
	    ${bigvar}.bonkHost.state.mm.dbid == window.bonkHost.toolFunctions.getGameSettings().map.m.dbid &&
	    ${bigvar}.bonkHost.state.mm.dbv == window.bonkHost.toolFunctions.getGameSettings().map.m.dbv
        ){
        for(let disc = 0; disc < discs.length; disc++){
            if(discs[disc] != null && window.BBSpawns.keepPositions[disc] != null){
                discs[disc].x = (map.spawns[window.BBSpawns.keepPositions[disc]].x + 365) / map.physics.ppm;
                discs[disc].y = (map.spawns[window.BBSpawns.keepPositions[disc]].y + 250) / map.physics.ppm;
                discs[disc].xv = map.spawns[window.BBSpawns.keepPositions[disc]].xv / map.physics.ppm;
                discs[disc].yv = map.spawns[window.BBSpawns.keepPositions[disc]].yv / map.physics.ppm;
                discs[disc].sx = discs[disc].x;
                discs[disc].sy = discs[disc].y;
                discs[disc].sxv = discs[disc].xv;
                discs[disc].syv = discs[disc].yv;
                window.BBSpawns.keepPositions[disc] = null;
                ${bigvar}.bonkHost.state.discs[disc] = null;
            }
        }
    }else{
        for(let disc = 0; disc < discs.length; disc++){
            if(discs[disc] != null && window.BBSpawns.spawnPointData[disc] != null){
                discs[disc].x = (map.spawns[window.BBSpawns.spawnPointData[disc]].x + 365) / map.physics.ppm;
                discs[disc].y = (map.spawns[window.BBSpawns.spawnPointData[disc]].y + 250) / map.physics.ppm;
                discs[disc].xv = map.spawns[window.BBSpawns.spawnPointData[disc]].xv / map.physics.ppm;
                discs[disc].yv = map.spawns[window.BBSpawns.spawnPointData[disc]].yv / map.physics.ppm;
                discs[disc].sx = discs[disc].x;
                discs[disc].sy = discs[disc].y;
                discs[disc].sxv = discs[disc].xv;
                discs[disc].syv = discs[disc].yv;
            }
        }
    }
    window.BBSpawns.exitMenu();
    `);
    let roomLeaveRegex = newSrc.match(/\(\);[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]=null;}[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]\[[A-Za-z0-9\$_]{3}\[[0-9]{1,3}]\[[0-9]{1,3}]]=null;/g);
    newSrc = newSrc.replace(roomLeaveRegex, roomLeaveRegex + `window.BBSpawns.exitMenu();window.BBSpawns.roomLeave();`);
    console.log(`${scriptName} injector run`);
    return newSrc;
}

if(!window.bonkCodeInjectors) window.bonkCodeInjectors = [];

window.bonkCodeInjectors.push(bonkCode => {
    try {
        return injector(bonkCode);
    } catch (error) {
        alert(`Whoops! ${scriptName} was unable to load.`);
        throw error;
    }
});

console.log(`${scriptName} injector loaded`);