Base Zones

diep.io base zone script

目前為 2021-11-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Base Zones
// @description  diep.io base zone script
// @version      1.3.7
// @author       none
// @match        *://diep.io/*
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_addValueChangeListener
// @grant        GM_removeValueChangeListener
// @license      none
// @namespace https://gf.qytechs.cn/users/790354
// @run-at document-end
// ==/UserScript==
'use strict';
function drawZones(x, y) {
    if (player.dead) return;
    let r = 50 * fov;
    let corner1 = 2600 * fov;
    let corner2 = 15850 * fov - corner1;
    ctx.save();
    if (player.gamemode === 'teams') {
        ctx.globalAlpha = 0.1
        ctx.fillStyle = '#00B1DE';
        ctx.beginPath();
        ctx.fillRect(corner1-x, -y, 45*r, 15850);
        ctx.fillStyle = '#F14E54';
        ctx.beginPath();
        ctx.fillRect(corner2-x-45*r, -y, 45*r, 15850);
        ctx.globalAlpha = 0.2
        ctx.fillStyle = '#00B1DE';
        ctx.beginPath();
        ctx.fillRect(corner1-x, -y, 25*r, 15850);
        ctx.fillStyle = '#F14E54';
        ctx.beginPath();
        ctx.fillRect(corner2-x-25*r, -y, 25*r, 15850);
    }
    if (player.gamemode === '4teams') {
    ctx.globalAlpha = 0.1;
    ctx.lineWidth = 20;
    //Calibration (change corner 1 so that the circles align with base center)
    //Blue
    /**
    ctx.strokeStyle = '#000000';
    ctx.beginPath();
    ctx.arc(corner1-x, corner1-y, 65, 0, 2*Math.PI);
    ctx.stroke();
    //Purple
    ctx.strokeStyle = '#000000';
    ctx.beginPath();
    ctx.arc(corner2-x, corner1-y, 65, 0, 2*Math.PI);
    ctx.stroke();
    //Green
    ctx.strokeStyle = '#000000';
    ctx.beginPath();
    ctx.arc(corner1-x, corner2-y, 65, 0, 2*Math.PI);
    ctx.stroke();
    //Red
    ctx.strokeStyle = '#000000';
    ctx.beginPath();
    ctx.arc(corner2-x, corner2-y, 65, 0, 2*Math.PI);
    ctx.stroke();
    */
    //Zone Rendering Outer
    //Blue
    ctx.fillStyle = '#00B1DE';
    ctx.beginPath();
    ctx.ellipse(corner1-x, corner1-y, 65*r,65*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Purple
    ctx.fillStyle = '#BF7FF5';
    ctx.beginPath();
    ctx.ellipse(corner2-x, corner1-y, 65*r,65*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Green
    ctx.fillStyle = '#00E16E';
    ctx.beginPath();
    ctx.ellipse(corner1-x, corner2-y, 65*r,65*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Red
    ctx.fillStyle = '#F14E54';
    ctx.beginPath();
    ctx.ellipse(corner2-x, corner2-y, 65*r,65*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Zone Rendering Inner
    ctx.globalAlpha = 0.2;
    //Blue
    ctx.fillStyle = '#00B1DE';
    ctx.beginPath();
    ctx.ellipse(corner1-x, corner1-y, 45*r,45*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Purple
    ctx.fillStyle = '#BF7FF5';
    ctx.beginPath();
    ctx.ellipse(corner2-x, corner1-y, 45*r,45*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Green
    ctx.fillStyle = '#00E16E';
    ctx.beginPath();
    ctx.ellipse(corner1-x, corner2-y, 45*r,45*r,0, 0, 2*Math.PI);
    ctx.fill();
    //Red
    ctx.fillStyle = '#F14E54';
    ctx.beginPath();
    ctx.ellipse(corner2-x, corner2-y, 45*r,45*r,0, 0, 2*Math.PI);
    ctx.fill();
    }
    ctx.restore();
}
function afkReset() {
    unsafeWindow.input.keyUp('65');
    unsafeWindow.input.keyUp('68');
    unsafeWindow.input.keyUp('87');
    unsafeWindow.input.keyUp('83');
}
function afkSignal() {
    ctx.save();
    ctx.globalAlpha = 0.6;
    let midX = canvas.width/2;
    let midY = 100;
    let dimX = 156;
    let dimY = 28;
    ctx.fillStyle = '#8585DF';
    ctx.beginPath();
    ctx.fillRect(midX - dimX/2, midY - dimY/2, dimX, dimY);
    ctx.restore();
}
function afk(X,Y) {
    if (isAfk == 0) return;
    let dX = X - posX;
    let dY = Y - posY;
    if (player.gamemode === '4teams' || player.gamemode === 'teams') {
        afkSignal();
        if (dX > 0) {
            unsafeWindow.input.keyDown('68');
            unsafeWindow.input.keyUp('65');
        } else {
            unsafeWindow.input.keyDown('65');
            unsafeWindow.input.keyUp('68');
        }
        if (dY > 0) {
            unsafeWindow.input.keyDown('83');
            unsafeWindow.input.keyUp('87');
        } else {
            unsafeWindow.input.keyDown('87');
            unsafeWindow.input.keyUp('83');
        }
    }
}
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 Player {
    constructor() {
        this._minimap = new Minimap();
        this._dead = true;
    }
    get dead() {
        return !(score >=0);
    }
    get gamemode() {
        return unsafeWindow.localStorage.gamemode;
    }
}

const player = new Player();
const minimap = new Minimap();
var arenaDim;
var score = NaN;
var scale, a, x, y, d;
var mouseX, mouseY, angle;
var interX, interY, posX, posY, afkX, afkY, fov;
var isAfk = 0;
//setup canvas
const canvas = document.getElementById('canvas');
const ctx = document.getElementById('canvas').getContext('2d');
// run main Loop
unsafeWindow.requestAnimationFrame = new Proxy(unsafeWindow.requestAnimationFrame, {
    apply: function (target, thisArg, args) {
        x = minimap._pointX;
        y = minimap._pointY;
        d = minimap._minimapWidth;
        scale = d / 169;
        fov = player._minimap.fov / 0.55;
        arenaDim = 12500 * fov;
        //Helpers
        interX = x - (canvas.width-(198)*scale);
        interY = y - (canvas.height-(204)*scale);
        posX = interX / d * arenaDim - (1-fov)*960;
        posY = interY / d * arenaDim - (1-fov)*540;
        drawZones(posX, posY);
        afk(afkX || 0, afkY || 0);
        setTimeout(() => Reflect.apply(target, thisArg, args), 0);
    },
});
document.addEventListener("keydown", function(e) {
    if (e.keyCode == 189) {
        if (isAfk == 0) {
            isAfk = 1;
            afkX = posX;
            afkY = posY;
        }
        else {isAfk = 0; afkReset();}
    }
});
document.addEventListener('mousemove', (event) => {
    mouseX = event.clientX * 3/2 - 960;
    mouseY = 540 - event.clientY * 3/2;
    angle = Math.atan(mouseY / mouseX);
});
CanvasRenderingContext2D.prototype.fillText = new Proxy(CanvasRenderingContext2D.prototype.fillText, {
    apply(fillRect, ctx, [text, x, y, ...blah]) {
        if (text.startsWith("Score:")) {
            score = parseFloat(text.slice(7).replace(',', ''));
        }
        fillRect.call(ctx, text, x, y, ...blah);
    }
});

QingJ © 2025

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