Base Zones

credits to cazka for basically 99% of this script, no this is not a multiboxing script

目前為 2021-10-14 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Base Zones
// @description  credits to cazka for basically 99% of this script, no this is not a multiboxing script
// @version      1.1.1
// @author       none
// @match        *://diep.io/*
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addValueChangeListener
// @grant        GM_removeValueChangeListener
// @namespace https://greasyfork.org/users/790354
// ==/UserScript==
'use strict';
const refreshRate = 2000;

function fillBlue2(flag) {
    if (player.dead) return;
    ctx.fillStyle = 'rgba(0,100,128,0.45)';
    ctx.beginPath();
    ctx.fillRect(0,1000-compensation,40,40);
    if (flag > 0) {
    if (player.dead) return;
    ctx.save();
    ctx.globalAlpha = 0.20*flag;
    if (player.gamemode === 'teams') {
    ctx.fillStyle = '#006480';
    ctx.beginPath();
    ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
    ctx.fill();
    ctx.restore();
    }
}
}
function fillRed2(flag) {
    if (player.dead) return;
    ctx.fillStyle = 'rgba(150,48,51,0.5)';
    ctx.beginPath();
    ctx.fillRect(40,1040-compensation,40,40);
    if (flag > 0) {
    if (player.dead) return;
    ctx.save();
    ctx.globalAlpha = 0.20*flag;
    if (player.gamemode === 'teams') {
    ctx.fillStyle = '#963033';
    ctx.beginPath();
    ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
    ctx.fill();
    ctx.restore();
    }
}
}
function fillBlue(flag) {
    if (player.dead) return;
    ctx.fillStyle = 'rgba(0,100,128, 0.45)';
    ctx.beginPath();
    ctx.fillRect(0,1000-compensation,40,40);
    if (flag > 0) {
    ctx.save();
    ctx.globalAlpha = 0.20*flag;
    if (player.gamemode === '4teams') {
    ctx.fillStyle = '#006480';
    ctx.beginPath();
    ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
    ctx.fill();
    ctx.restore();
    }
}
}
function fillPurple(flag) {
    if (player.dead) return;
    ctx.fillStyle = 'rgba(100,66,128, 0.5)';
    ctx.beginPath();
    ctx.fillRect(40,1000-compensation,40,40);
    if (flag > 0) {
    ctx.save();
    ctx.globalAlpha = 0.20*flag;
    if (player.gamemode === '4teams') {
    ctx.fillStyle = '#644280';
    ctx.beginPath();
    ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
    ctx.fill();
    ctx.restore();
    }
}
}
function fillGreen(flag) {
    if (player.dead) return;
    ctx.fillStyle = 'rgba(0,128,62, 0.5)';
    ctx.beginPath();
    ctx.fillRect(0,1040-compensation,40,40);
    if (flag > 0) {
    ctx.save();
    ctx.globalAlpha = 0.20*flag;
    if (player.gamemode === '4teams') {
    ctx.fillStyle = '#00803e';
    ctx.beginPath();
    ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
    ctx.fill();
    }
    ctx.restore();
    }
}

function fillRed(flag) {
    if (player.dead) return;
    ctx.fillStyle = 'rgba(150,48,51, 0.5)';
    ctx.beginPath();
    ctx.fillRect(40,1040-compensation,40,40);
    if (flag > 0) {
    ctx.save();
    ctx.globalAlpha = 0.20*flag;
    if (player.gamemode === '4teams') {
    ctx.fillStyle = '#963033';
    ctx.beginPath();
    ctx.arc(960,540-compensation/2,80,0,2*Math.PI);
    ctx.fill();
    ctx.restore();
    }
}
}
class Gui {
    constructor(title) {
        this._buttons = [];
    }
}
class Minimap {
    constructor() {
        this._minimapWidth;
        this._minimapHeight;
        this._x00;
        this._y00;
        this._pointX;
        this._pointY;
        this._pointX_previous;
        this._pointY_previous;
        this._viewportWidth;
        this._viewportHeight;
        this._fov;

        this._minimapHook();
        this._arrowHook();
        this._viewportHook();
        this._fovHook();}
    get x() {
        return this._pointX ? (this._pointX - this._x00) / this._minimapWidth : 0;
    }
    get y() {
        return this._pointY ? (this._pointY - this._y00) / this._minimapHeight : 0;
    }
    get x_previous() {
        return this._pointX_previous ? (this._pointX_previous - this._x00) / this._minimapWidth : 0;
    }
    get y_previous() {
        return this._pointY_previous ? (this._pointY_previous - this._y00) / this._minimapHeight : 0;
    }
    get fov() {
        return this._fov;
    }

    _minimapHook() {
        let setTransformArgs;

        const onsetTransform = (args) => {
            if (args[0] === args[3]) setTransformArgs = args;
        };
        const onstrokeRect = () => {
            if (setTransformArgs) {
                this._minimapWidth = setTransformArgs[0];
                this._minimapHeight = setTransformArgs[3];
                this._x00 = setTransformArgs[4];
                this._y00 = setTransformArgs[5];
                setTransformArgs = undefined;
            }
        };
        this._ctxHook('setTransform', onsetTransform);
        this._ctxHook('strokeRect', onstrokeRect);
    }
    _arrowHook() {
        let index = 0;
        const stack = Array(4);

        let pointA;
        let pointB;
        let pointC;

        const calculatePos = () => {
            const side1 = Math.floor(
                Math.sqrt(Math.pow(pointA[0] - pointB[0], 2) + Math.pow(pointA[1] - pointB[1], 2))
            );
            const side2 = Math.floor(
                Math.sqrt(Math.pow(pointA[0] - pointC[0], 2) + Math.pow(pointA[1] - pointC[1], 2))
            );
            const side3 = Math.floor(
                Math.sqrt(Math.pow(pointB[0] - pointC[0], 2) + Math.pow(pointB[1] - pointC[1], 2))
            );
            if (side1 == side2 && side2 == side3) return;

            this._pointX_previous = this._pointX;
            this._pointY_previous = this._pointY;

            this._pointX = (pointA[0] + pointB[0] + pointC[0]) / 3;
            this._pointY = (pointA[1] + pointB[1] + pointC[1]) / 3;
        };
        const onbeginPath = () => {
            index = 0;
            stack[index++] = 0;
        };
        const onmoveTo = (args) => {
            if (index === 1 && stack[index - 1] === 0) {
                stack[index++] = 1;
                pointA = args;
                return;
            }
            index = 0;
        };
        const onlineTo = (args) => {
            if (index === 2 && stack[index - 1] === 1) {
                stack[index++] = 2;
                pointB = args;
                return;
            }
            if (index === 3 && stack[index - 1] === 2) {
                stack[index++] = 2;
                pointC = args;
                return;
            }
            index = 0;
        };
        const onfill = () => {
            if (index === 4 && stack[index - 1] === 2) {
                calculatePos();
                return;
            }
            index = 0;
        };

        this._ctxHook('beginPath', onbeginPath);
        this._ctxHook('moveTo', onmoveTo);
        this._ctxHook('lineTo', onlineTo);
        this._ctxHook('fill', onfill);
    }
    _viewportHook() {
        let setTransformArgs;

        const onsetTransform = (args) => {
            if ((args[0] / args[3]).toFixed(4) !== (unsafeWindow.innerWidth / unsafeWindow.innerHeight).toFixed(4)) return;
            if (args[0] >= unsafeWindow.innerWidth && args[3] >= unsafeWindow.innerHeight) return;
            setTransformArgs = args;
        };
        const onfillRect = () => {
            if (setTransformArgs) {
                unsafeWindow.input.set_convar('ren_minimap_viewport', true);
                this._viewportWidth = setTransformArgs[0];
                this._viewportHeight = setTransformArgs[3];
                setTransformArgs = undefined;
            }
        };

        this._ctxHook('setTransform', onsetTransform);
        this._ctxHook('fillRect', onfillRect);

        setInterval(() => {
            unsafeWindow.input.set_convar('ren_minimap_viewport', true);
        }, 1000);
    }
    _fovHook() {
        let solid_background = false;
        setTimeout(() => {
            solid_background = unsafeWindow.input.get_convar('ren_solid_background') === 'true' ? true : false;
        }, 1000);

        const calculateFov = (fov) => {
            this._fov = fov * 10;
        };
        function onstroke() {
            if (this.fillStyle === '#cdcdcd') {
                if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', true);
                calculateFov(this.globalAlpha);
            }
        }

        this._ctxHook('stroke', onstroke);

        setInterval(() => {
            if (solid_background) unsafeWindow.input.set_convar('ren_solid_background', false);
        }, 10000);
    }
    _ctxHook(method, hook) {
        const target = window.CanvasRenderingContext2D.prototype;
        target[method] = new Proxy(target[method], {
            apply(target, thisArg, args) {
                args = hook.call(thisArg, args) || args;
                return target.apply(thisArg, args);
            },
        });
    }
}

class Vector {}

class Arena {}
class Player {
    constructor() {
        this._minimap = new Minimap();
        this._dead = true;

        //Dead Listener
        new MutationObserver((args) => {
            this._dead = args[0].target.style.display === 'block';
            if (this.ondead && this._dead) this.ondead();
        }).observe(document.getElementById('a'), { attributes: true });
    }

    get dead() {
        return this._dead;
    }

    get gamemode() {
        return unsafeWindow.localStorage.gamemode;
    }

}

class Chat {
    constructor(player) {
        this._player = player;
        this._hookonkeydown();
        this._hookAnimationFrame();
    }

    _hookonkeydown() {
        const _this = this;
        unsafeWindow.onkeydown = new Proxy(unsafeWindow.onkeydown, {
        });
    }
    _hookAnimationFrame() {
        const _this = this;
        unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
        });
    }
}

const player = new Player();
const arena = new Arena();
const chat = new Chat(player);
const minimap = new Minimap();
const radius = 44;
const width = 149;

var ack = 0.75;
var a,fj,fk,fl,fm,tj,tk,c1,c2,c3,c4,c5,c6 = 0;
var blue = 1;
var purple = 1;
var green = 1;
var red = 1;
var scale = d/175;
var x = minimap._pointX;
var y = minimap._pointY;
var d = minimap._minimapWidth;
var compensation = a * (width+18);

//setup canvas
const ctx = document.getElementById('canvas').getContext('2d');
// run main Loop
document.body.onkeydown = function(e) {
        if (e.keyCode === 70) {
            blue = 1 - blue
            }
        if (e.keyCode === 71) {
            purple = 1 - purple
            }
        if (e.keyCode === 86) {
            green = 1 - green
            }
        if (e.keyCode === 66) {
            red = 1 - red
            }
        }

unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
    apply: function (target, thisArg, args) {
        x = minimap._pointX;
        scale = d / 175;
        y = minimap._pointY;
        compensation = a * (width+18);
        if (player.gamemode === '4teams') {
        //4 teams
        //Blue
            c1 = Math.pow(1920-(1920-1738)*scale-x,2) + Math.pow(1080-(1080-898)*scale-compensation-y,2)
            ack = Math.pow(c1/Math.pow(radius*scale, 2), 0.5)
            fj = 5.5-5*ack;
        //Purple
            c2 = Math.pow(1920-(1920-1738)*scale+width*scale-x,2) + Math.pow(1080-(1080-898)*scale-compensation-y,2)
            ack = Math.pow(c2/Math.pow(radius*scale, 2), 0.5)
            fk = 5.5-5*ack;
        //Green
            c3 = Math.pow(1920-(1920-1738)*scale-x,2) + Math.pow(1080-(1080-898)*scale+width*scale-compensation-y,2)
            ack = Math.pow(c3/Math.pow(radius*scale, 2), 0.5)
            fl = 5.5-5*ack;
        //Red
            c4 = Math.pow(1920-(1920-1738)*scale+width*scale-x,2) + Math.pow(1080-(1080-898)*scale+width*scale-compensation-y,2)
            ack = Math.pow(c4/Math.pow(radius*scale, 2), 0.5)
            fm = 5.5-5*ack;
        }
        else if (player.gamemode === 'teams') {
        //2 teams
        //Blue
            tj = 5.5+5*(1920-(1920-1728)*scale-x)/(40*scale);
        //Red
            tk = 5.5-5*(1920-(1920-1892)*scale-x)/(scale*40);
        }
        //Helpers
            if(window.innerHeight == screen.height) {
            a = 0;} else {a = 1;}
        d = minimap._minimapWidth
        if (blue == 1) {
        fillBlue(fj);
        fillBlue2(tj);
        }
        if (purple == 1) {
        fillPurple(fk);
        }
        if (green == 1) {
        fillGreen(fl);
        }
        if(red == 1) {
        fillRed(fm);
        fillRed2(tk);
        }
        setTimeout(() => Reflect.apply(target, thisArg, args), 0);
    },
});