diepAPI

https://github.com/Cazka/diepAPI

От 10.10.2021. Виж последната версия.

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greatest.deepsurf.us/scripts/433681/977858/diepAPI.js

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         diepAPI
// @description  https://github.com/Cazka/diepAPI
// @version      2.0.1
// @author       Cazka
// @match        https://diep.io/*
// @icon         https://www.google.com/s2/favicons?domain=diep.io
// @namespace    https://greatest.deepsurf.us/users/541070
// @run-at       document-start
// @grant        none
// ==/UserScript==
if(window.diepAPI) return;

var diepAPI;(()=>{"use strict";var e={d:(t,s)=>{for(var o in s)e.o(s,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:s[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{CanvasKit:()=>o,Vector:()=>s,arena:()=>p,arenaScaling:()=>d,entityManager:()=>v,game:()=>a,gamepad:()=>i,minimap:()=>r,player:()=>w});class s{x;y;constructor(e,t){this.x=e,this.y=t}static add(e,t){return new s(e.x+t.x,e.y+t.y)}static subtract(e,t){return new s(e.x-t.x,e.y-t.y)}static multiply(e,t){return new s(e.x*t.x,e.y*t.y)}static divide(e,t){return new s(e.x/t.x,e.y/t.y)}static scale(e,t){return new s(e*t.x,e*t.y)}static round(e){return new s(Math.round(e.x),Math.round(e.y))}static len(e){return Math.sqrt(e.x**2+e.y**2)}static distance(e,t){return s.len(s.subtract(e,t))}static centroid(...e){const t=e.reduce(((e,t)=>s.add(e,t)),new s(0,0));return s.scale(1/e.length,t)}static radius(...e){const t=s.centroid(...e);return e.reduce(((e,o)=>e+s.distance(t,o)),0)/e.length}}class o{static hook(e,t){const s=window.CanvasRenderingContext2D.prototype;s[e]=new Proxy(s[e],{apply:(e,s,o)=>("CanvasKit-bypass"!==s.canvas.className&&t(e,s,o),Reflect.apply(e,s,o))})}static replace(e,t){const s=window.CanvasRenderingContext2D.prototype;s[e]=new Proxy(s[e],{apply:(e,s,o)=>"CanvasKit-bypass"!==s.canvas.className?t(e,s,o):Reflect.apply(e,s,o)})}static hookRAF(e){window.requestAnimationFrame=new Proxy(window.requestAnimationFrame,{apply:(t,s,o)=>(e(),Reflect.apply(t,s,o))})}static createCanvas(){const e=document.createElement("canvas");return e.className="CanvasKit-bypass",e.style.pointerEvents="none",e.style.position="fixed",e.style["z-index"]=1,e.style.top="0px",e.style.left="0px",e.style.right="0px",e.style.bottom="0px",e.style.width="100%",e.style.height="100%",e}}const i=new class{#axes;#buttons;connected;constructor(){this.#axes=[0,0,0,0],this.#buttons=[...Array(17)].map((e=>({pressed:!1}))),this.connected=!1,window.navigator.getGamepads=new Proxy(window.navigator.getGamepads,{apply:(e,t,s)=>this.connected?[this.#toGamepad()]:Reflect.apply(e,t,s)})}set x(e){this.#axes[0]=e}set y(e){this.#axes[1]=e}set mx(e){this.#axes[2]=e}set my(e){this.#axes[3]=e}set leftMouse(e){this.#buttons[7].pressed=e}set rightMouse(e){this.#buttons[6].pressed=e}get x(){return this.#axes[0]}get y(){return this.#axes[1]}get mx(){return this.#axes[2]}get my(){return this.#axes[3]}get leftMouse(){return this.#buttons[7].pressed}get rightMouse(){return this.#buttons[6].pressed}#toGamepad(){return{axes:this.#axes,buttons:this.#buttons,mapping:"standard"}}};class n extends EventTarget{emit(e,...t){this.dispatchEvent(new CustomEvent(e,{detail:t}))}on(e,t){this.addEventListener(e,(e=>Reflect.apply(t,this,e.detail)))}once(e,t){this.addEventListener(e,(e=>Reflect.apply(t,this,e.detail)),{once:!0})}off(e,t){this.removeEventListener(e,t)}}const a=new class extends n{#ready=!1;constructor(){super(),o.hookRAF((()=>this.#onframe()))}#onframe(){this.#ready||void 0===window.input||(this.#ready=!0,this.#onready()),super.emit("frame")}#onready(){super.emit("ready")}},r=new class{#minimapDim=new s(1,1);#minimapPos=new s(0,0);#viewportDim=new s(1,1);#viewportPos=new s(0,0);#arrowPos=new s(.5,.5);#drawViewport=!1;constructor(){a.once("ready",(()=>{window.input.set_convar("ren_minimap_viewport","true"),window.input.set_convar=new Proxy(window.input.set_convar,{apply:(e,t,s)=>{"ren_minimap_viewport"===s[0]?this.#drawViewport=s[1]:Reflect.apply(e,t,s)}})})),this._minimapHook(),this._viewportHook(),this._arrowHook()}get minimapDim(){return this.#minimapDim}get minimapPos(){return this.#minimapPos}get viewportDim(){return this.#viewportDim}get viewportPos(){return this.#viewportPos}get arrowPos(){return this.#arrowPos}drawViewport(e){this.#drawViewport=e}_minimapHook(){o.hook("strokeRect",((e,t,o)=>{const i=t.getTransform();this.#minimapDim=new s(i.a,i.d),this.#minimapPos=new s(i.e,i.f)}))}_viewportHook(){o.replace("fillRect",((e,t,o)=>{const i=t.getTransform();return Math.round(i.a/i.d*1e4)!==Math.round(window.innerWidth/window.innerHeight*1e4)||i.a>=window.innerWidth&&i.d>=window.innerHeight?Reflect.apply(e,t,o):(this.#viewportDim=new s(i.a,i.d),this.#viewportPos=new s(i.e,i.f),this.#drawViewport?Reflect.apply(e,t,o):void 0)}))}_arrowHook(){let e,t,i,n=0;const a=()=>{const o=Math.round(s.distance(e,t)),n=Math.round(s.distance(e,i)),a=Math.round(s.distance(t,i));if(o===n&&n===a)return;const r=s.centroid(e,t,i),c=s.subtract(r,this.#minimapPos),d=s.divide(c,this.#minimapDim);this.#arrowPos=d};o.hook("beginPath",((e,t,s)=>{n=1})),o.hook("moveTo",((t,o,i)=>{if(1===n)return n++,void(e=new s(i[0],i[1]));n=0})),o.hook("lineTo",((e,o,a)=>2===n?(n++,void(t=new s(a[0],a[1]))):3===n?(n++,void(i=new s(a[0],a[1]))):void(n=0))),o.hook("fill",((e,t,s)=>{if(4===n)return n++,void a();n=0}))}},c=new class{get position(){const e=s.add(r.viewportPos,s.scale(.5,r.viewportDim)),t=s.subtract(e,r.minimapPos),o=s.divide(t,r.minimapDim);return p.scale(o)}},d=new class{#scalingFactor=1;constructor(){o.hook("stroke",((e,t,s)=>{"#cdcdcd"===t.fillStyle&&0!==t.globalAlpha&&(this.#scalingFactor=10*t.globalAlpha)}))}get scalingFactor(){return this.#scalingFactor}get windowRatio(){return Math.max(window.innerWidth/1920,window.innerHeight/1080)}get fov(){return this.#scalingFactor/this.windowRatio}toArenaUnits(e){return s.scale(1/this.#scalingFactor,e)}toScreenUnits(e){return s.scale(this.#scalingFactor,e)}toArenaPos(e){const t=s.subtract(e,new s(window.innerWidth/2,window.innerHeight/2)),o=this.toArenaUnits(t);return s.add(o,c.position)}toScreenPos(e){const t=s.subtract(e,c.position),o=this.toScreenUnits(t);return s.add(o,new s(window.innerWidth/2,window.innerHeight/2))}},p=new class{#size=1;constructor(){a.on("frame",(()=>{const e=s.divide(r.minimapDim,r.viewportDim),t=s.multiply(e,new s(window.innerWidth,window.innerHeight)),o=s.round(d.toArenaUnits(t));this.#size=o.x}))}get size(){return this.#size}scale(e){const t=e=>Math.round(this.#size*(e-.5));return new s(t(e.x),t(e.y))}unscale(e){const t=e=>e/this.#size+.5;return new s(t(e.x),t(e.y))}};class h{#position=new s(0,0);#velocity=new s(0,0);#velocitySamplesSize=10;#velocitySamples=[];#velocitySamplesIndex=0;#velocityLastNow=performance.now();get position(){return this.#position}get velocity(){return this.#velocity}predictPos(e){const t=(e-this.#velocityLastNow)/1e3;return s.add(this.#position,s.scale(t,this.#velocity))}updatePos(e){this.#updateVelocity(e),this.#position=e}#updateVelocity(e){const t=performance.now(),o=(t-this.#velocityLastNow)/1e3;if(0===o)return;this.#velocityLastNow=t;const i=s.scale(1/o,s.subtract(e,this.#position));this.#velocitySamples[this.#velocitySamplesIndex++]=i,this.#velocitySamplesIndex%=this.#velocitySamplesSize,this.#velocity=s.scale(1/this.#velocitySamples.length,this.#velocitySamples.reduce(((e,t)=>s.add(e,t))))}}const l=new class extends h{constructor(){super(),a.on("frame",(()=>super.updatePos(p.scale(r.arrowPos))))}},u=e=>new Promise(((t,s)=>setTimeout(t,e))),w=new class extends n{#dead=!0;#mouseLock=!1;#mousePos=new s(0,0);constructor(){super(),a.once("ready",(()=>{a.on("frame",(()=>{const e=!window.input.should_prevent_unload();this.#dead!=e&&(this.#dead=e,this.#dead?this.#ondead():this.#onspawn())}));const e=document.getElementById("canvas");e.onmousemove=new Proxy(e.onmousemove,{apply:(e,t,s)=>{if(!this.#mouseLock)return this.#onmousemove(s[0]),Reflect.apply(e,t,s)}}),e.onmousedown=new Proxy(e.onmousedown,{apply:(e,t,s)=>{if(!this.#mouseLock)return this.#onmousedown(s[0]),Reflect.apply(e,t,s)}}),e.onmouseup=new Proxy(e.onmouseup,{apply:(e,t,s)=>{if(!this.#mouseLock)return this.#onmouseup(s[0]),Reflect.apply(e,t,s)}}),window.onkeydown=new Proxy(window.onkeydown,{apply:(e,t,s)=>(this.#onkeydown(s[0]),Reflect.apply(e,t,s))}),window.onkeyup=new Proxy(window.onkeyup,{apply:(e,t,s)=>(this.#onkeyup(s[0]),Reflect.apply(e,t,s))})}))}get position(){return l.position}get velocity(){return l.velocity}get mouse(){return this.#mousePos}predictPos(e){return l.predictPos(e)}async octoBuild(){this.keyDown("k"),await this.upgrade_stat(4,7),await this.upgrade_stat(5,7),await this.upgrade_stat(6,7),await this.upgrade_stat(7,7),await this.upgrade_stat(8,5),await this.upgrade_tank(1),await this.upgrade_tank(2),await this.upgrade_tank(1),this.keyUp("k")}async#ondead(){await u(50),super.emit("dead")}async#onspawn(){await u(50),super.emit("spawn")}useGamepad(e){i.connected=e}keyDown(e){if("string"==typeof e){if(1!=e.length)throw new Error(`diepAPI: Unsupported key: ${e}`);e=e.toUpperCase().charCodeAt(0)}window.input.keyDown(e),this.#onkeydown({keyCode:e})}keyUp(e){if("string"==typeof e){if(1!=e.length)throw new Error(`diepAPI: Unsupported key: ${e}`);e=e.toUpperCase().charCodeAt(0)}window.input.keyUp(e),this.#onkeyup({keyCode:e})}async keyPress(e){this.keyDown(e),await u(200),this.keyUp(e),await u(10)}async spawn(e,t=0){this.#dead&&(void 0!==e&&(document.getElementById("textInput").value=e),await this.keyPress(13),await u(250),await this.spawn(e,t+1))}async upgrade_stat(e,t){if(e<1||e>8)throw`diepAPI: ${e} is not a supported stat`;this.keyDown(85);for(let s=0;s<t;s++)await this.keyPress(48+e);this.keyUp(85),await u(250)}async upgrade_tank(e){const t=(e-=1)%2,s=Math.floor(e/2),o=window.devicePixelRatio*d.windowRatio*(115*t+97.5),i=window.devicePixelRatio*d.windowRatio*(110*s+120);this.#mouseLock=!0,window.input.mouse(o,i),await this.keyPress(1),await u(200),this.#mouseLock=!1,await u(1500)}moveTo(e){if(i.connected){const t=s.subtract(e,this.position),o=s.len(t);if(0===o)return i.x=0,void(i.y=0);const n=s.scale(1/o,t);i.x=n.x,i.y=n.y}else{const t=s.subtract(e,this.position);t.x>0?(this.keyUp("a"),this.keyDown("d")):t.x<0?(this.keyUp("d"),this.keyDown("a")):(this.keyUp("a"),this.keyUp("d")),t.y>0?(this.keyUp("w"),this.keyDown("s")):t.y<0?(this.keyUp("s"),this.keyDown("w")):(this.keyUp("w"),this.keyUp("s"))}}lookAt(e){if(this.#mousePos=e,i.connected){const t=s.subtract(e,this.position);let o=s.scale(d.fov/1200/1.1,t);const n=s.len(o);0!==n&&n<.15&&(o=s.scale(.15/n,o)),i.mx=o.x,i.my=o.y}else{const t=d.toScreenPos(e);window.input.mouse(t.x,t.y)}}#onmousemove(e){const t=d.toArenaPos(new s(e.clientX,e.clientY));this.#mousePos=t,i.connected&&this.lookAt(t)}#onmousedown(e){i.connected&&this.#onkeydown({keyCode:e.which})}#onmouseup(e){i.connected&&this.#onkeyup({keyCode:e.which})}#onkeydown(e){if(i.connected)switch(e.keyCode){case 37:case 65:i.x=-1;break;case 40:case 83:i.y=1;break;case 38:case 87:i.y=-1;break;case 39:case 68:i.x=1;break;case 1:case 32:i.leftMouse=!0;break;case 3:case 16:i.rightMouse=!0}}#onkeyup(e){if(i.connected)switch(e.keyCode){case 37:case 65:i.x=0;break;case 40:case 83:i.y=0;break;case 38:case 87:i.y=0;break;case 39:case 68:i.x=0;break;case 1:case 32:i.leftMouse=!1;break;case 3:case 16:i.rightMouse=!1}}};var y,m;!function(e){e[e.Player=0]="Player",e[e.Bullet=1]="Bullet",e[e.Drone=2]="Drone",e[e.Trap=3]="Trap",e[e.Square=4]="Square",e[e.Triangle=5]="Triangle",e[e.Pentagon=6]="Pentagon",e[e.AlphaPentagon=7]="AlphaPentagon",e[e.Crasher=8]="Crasher",e[e.UNKNOWN=9]="UNKNOWN"}(y||(y={})),function(e){e.TeamBlue="#00b2e1",e.TeamRed="#f14e54",e.TeamPurple="#bf7ff5",e.TeamGreen="#00e16e",e.Square="#ffe869",e.Triangle="#fc7677",e.Pentagon="#768dfc",e.AlphaPentagon="#768dfc",e.Crasher="#f177dd",e.NecromancerDrone="#fcc376"}(m||(m={}));const k=[m.TeamBlue,m.TeamRed,m.TeamPurple,m.TeamGreen];class g extends h{type;extras;constructor(e,t={}){super(),this.type=e,this.extras=t}updatePos(e){super.updatePos(e)}}const v=new class{#entities=[];#entitiesUpdated=[];constructor(){this.#triangleHook(),this.#squareHook(),this.#pentagonHook(),this.#playerHook(),a.on("frame",(()=>{this.#entities=this.#entitiesUpdated,this.#entitiesUpdated=[]}))}get entities(){return this.#entities}#add(e,t,s={}){const o=this.#findEntity(e,t);let i;i=-1===o?new g(e,{id:Math.random().toString(36).slice(2,5),timestamp:performance.now(),...s}):this.#entities[o],i.updatePos(t),this.#entitiesUpdated.push(i)}#findEntity(e,t){let o=-1,i=Number.MAX_SAFE_INTEGER;return this.#entities.forEach(((e,n)=>{const a=s.distance(e.predictPos(performance.now()),t);a<i&&(i=a,o=n)})),i>28||y.UNKNOWN!==e&&this.#entities[o].type!==e?-1:o}#createPolygonHook(e,t){let i=0,n=[];o.hook("beginPath",((e,t,s)=>{i=1,n=[]})),o.hook("moveTo",((e,t,o)=>{if(1===i)return i++,void n.push(new s(o[0],o[1]));i=0})),o.hook("lineTo",((t,o,a)=>{if(i>=2&&i<=e)return i++,void n.push(new s(a[0],a[1]));i=0})),o.hook("fill",((s,o,a)=>{if(i===e+1)return i++,void t(n,o);i=0}))}#triangleHook(){this.#createPolygonHook(3,((e,t)=>{const o=Math.round(s.distance(e[0],e[1])),i=Math.round(s.distance(e[0],e[2])),n=Math.round(s.distance(e[1],e[2]));if(o!==i||i!==n)return;if("#000000"===t.fillStyle)return;e=e.map((e=>d.toArenaPos(e)));const a=s.centroid(...e),r=Math.round(s.radius(...e)),c=t.fillStyle;let p;switch(r){case 23:case 30:k.includes(c)&&(p=y.Drone);break;case 35:m.Crasher===c&&(p=y.Crasher);break;case 40:case 41:case 42:case 43:case 44:case 45:case 46:k.includes(c)&&(p=y.Drone);break;case 55:m.Crasher===c&&(p=y.Crasher),m.Triangle===c&&(p=y.Triangle)}void 0===p&&(p=y.UNKNOWN),this.#add(p,a,{color:c,radius:r})}))}#squareHook(){this.#createPolygonHook(4,((e,t)=>{e=e.map((e=>d.toArenaPos(e)));const o=s.centroid(...e),i=Math.round(s.radius(...e)),n=t.fillStyle;let a;switch(i){case 55:m.Square===n&&(a=y.Square),(k.includes(n)||m.NecromancerDrone===n)&&(a=y.Drone)}void 0===a&&(a=y.UNKNOWN),this.#add(a,o,{color:n,radius:i})}))}#pentagonHook(){this.#createPolygonHook(5,((e,t)=>{e=e.map((e=>d.toArenaPos(e)));const o=s.centroid(...e),i=Math.round(s.radius(...e)),n=t.fillStyle;let a;switch(i){case 75:m.Pentagon===n&&(a=y.Pentagon);break;case 200:m.AlphaPentagon===n&&(a=y.AlphaPentagon)}void 0===a&&(a=y.UNKNOWN),this.#add(a,o,{color:n,radius:i})}))}#playerHook(){let e,t,i,n=0;const a=()=>{e=d.toArenaPos(e),i=d.toArenaUnits(new s(i,i)).x;let o=y.UNKNOWN;o=i>53?y.Player:y.Bullet,this.#add(o,e,{color:t,radius:i})};o.hook("beginPath",((e,t,s)=>{3===n?3!==n?n=0:n++:n=1})),o.hook("arc",((o,r,c)=>{if(1===n){n++;const t=r.getTransform();return e=new s(t.e,t.f),void(i=t.a)}return 4===n?(n++,void(t=r.fillStyle)):6===n?(n++,void a()):void(n=0)})),o.hook("fill",((e,t,s)=>{2!==n&&5!==n?n=0:n++}))}};diepAPI=t})();

window.diepAPI = diepAPI;