Greasy Fork 还支持 简体中文。

2k09__ Bot Mode V-0.1

-

  1. // ==UserScript==
  2. // @name 2k09__ Bot Mode V-0.1
  3. // @namespace -
  4. // @version 0.1
  5. // @description -
  6. // @author 2k09__
  7. // @match https://sploop.io/
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict'
  14.  
  15. alert('||~~ Commands: ||| !md -ab = AddBot ||| !md -rb ~~||');
  16. !~function(
  17. $ = document.querySelector.bind(document),
  18. botID = 0,
  19. bots = [],
  20. isBot = (window.location !== window.parent.location),
  21. playerID, playerX, playerY,
  22. ownerX, ownerY,
  23. touchStart = {x: 0, y: 0},
  24. keys = {}, weaponKey = "1"
  25. ) {
  26.  
  27. class Sploop {
  28. static newKeyEvent(type) {
  29. return function (eventObj) {
  30. const { key, code } = eventObj;
  31. window.KeyboardEvent = Object;
  32. window.getEvents(type)[type == "keydown" ? 1 : 0].listener({key: key, code: code, isTrusted: 1, target: document.body, preventDefault: () => null});
  33. window.KeyboardEvent = KeyBoardEvent;
  34. };
  35. }
  36. static key = {
  37. down: this.newKeyEvent("keydown"),
  38. up: this.newKeyEvent("keyup"),
  39. press(eventObj) {
  40. Sploop.newKeyEvent("keydown")(eventObj);
  41. Sploop.newKeyEvent("keyup")(eventObj);
  42. }
  43. };
  44. static foodPlace() {
  45. //alert("QQQ")
  46. this.key.press({code: "KeyQ"});
  47. this.key.press({code: "Space"});
  48. this.key.press({key: weaponKey});
  49. }
  50. static spikePlace() {
  51. //alert("QQQ")
  52. this.key.press({code: "KeyR"});
  53. this.key.press({code: "Space"});
  54. this.key.press({key: weaponKey});
  55. }
  56. static trapPlace() {
  57. //alert("QQQ")
  58. this.key.press({code: "KeyF"});
  59. this.key.press({code: "Space"});
  60. this.key.press({key: weaponKey});
  61. }
  62. static newTouchEvent = function(type) {
  63. return function (eventObj) {
  64. const { x, y, id } = eventObj;
  65. $("#game-canvas").getEvents(type)[0].listener({changedTouches: [{identifier: id, pageX: x, pageY: y}], preventDefault: () => null, stopPropagation: () => null});
  66. };
  67. };
  68. static touch = {
  69. start: this.newTouchEvent("touchstart"),
  70. move: this.newTouchEvent("touchmove"),
  71. end: this.newTouchEvent("touchend")
  72. }
  73.  
  74. static spawn(name) {
  75. $("#nickname").value = name;
  76. $("#play").getEvents("click")[0].listener();
  77. $("#nickname").value = localStorage.getItem("nickname")||"";
  78. };
  79.  
  80. static changeServer(serverID) {
  81. $("#server-select").options[0].setAttribute("region", serverID)
  82. $("#server-select").selectedIndex = 0;
  83. $("#server-select").getEvents("change")[0].listener();
  84. };
  85. };
  86. window.Sploop = Sploop;
  87.  
  88.  
  89. window.addEventListener("load", ()=> (Object.keys(window.getEvents()).length === 0) && (window.onbeforeunload && (window.onbeforeunload = null), window.location.reload()));
  90.  
  91. WebSocket.prototype._send = WebSocket.prototype.send;
  92. WebSocket.prototype.send = function() {
  93. if(!isBot) {
  94. for(let bot of bots) {
  95. /*
  96. ko: 11, //somethingOnBegin
  97. Uo: 6, //moveByBitmask
  98. yo: 13, //changeAIM
  99. Eo: 2, //selectItemByID
  100. Bo: 19, //attack
  101. Co: 18, //stopAttack
  102. zo: 10, //spawn
  103. Do: 20, //scytheUpgrade
  104. xo: 0, //selectItemByType
  105. Lo: 5,//equipHat
  106. Fo: 7, //sendChat
  107. Oo: 14, //upgrade
  108. jo: 12, //noting
  109. So: 3, //pingStuff
  110. Po: 23, //autoHit
  111. Vo: 1, //moveToDir
  112. No: 15, //removeMoveDir
  113. Ho: 9, //touchStart
  114. Wo: 4, //noting
  115. Go: 8, //touchEnd
  116. Qo: 24, //leaveClan
  117. Yo: 21, //joinInClan
  118. qo: 17, //acceptDecline
  119. Zo: 25, //kick
  120. Xo: 22, //createClan
  121. */
  122. if(![22, 25, 17, 3, 10, 11].includes(arguments[0][0])) (bot.contentWindow.ws || this)._send(...arguments);
  123. }
  124. }
  125. this._send(...arguments);
  126. if(this.HOOKED) return;
  127. this.HOOKED = true;
  128. window.ws = this;
  129. var botSpwned = false;
  130. this.addEventListener("message", (msg)=>{
  131. const d = ("string" != typeof msg.data ? new Uint8Array(msg.data) : JSON.parse(msg.data))
  132. if(d[0] == 35) {
  133. if(isBot && !playerID) Sploop.touch.start({id: 1000, x: innerWidth/4, y: innerHeight/2})
  134. playerID = d[1];
  135. }
  136. if(d[0] == 20) {
  137. for(let i = 1; i < d.byteLength; i += 18) {
  138. const id = d[i + 2] | d[i + 3] << 8;
  139. const x = d[i + 4] | d[i + 5] << 8;
  140. const y = d[i + 6] | d[i + 7] << 8;
  141. if(playerID == id) {
  142. playerX = x;
  143. playerY = y;
  144. if(!isBot) {
  145. for(let bot of bots) bot.isLoaded && bot.contentWindow.updateOwnerPosition(x, y);
  146. }
  147. }
  148. }
  149. if(isBot) {
  150. !botSpwned && (Sploop.spawn( "2k09__Bot", (botSpwned=1)))
  151. }
  152. }
  153. });
  154. if(!isBot) {
  155. this.rg = this.url.split("//")[1].split(".sploop")[0].toLocaleUpperCase();
  156. for(let bot of bots) {
  157. bot.contentWindow.changeServer(this.rg);
  158. }
  159. }
  160. }
  161.  
  162. isBot && (
  163. window.onload = ()=> initBot(),
  164. Object.defineProperty(Object.prototype, "region", {
  165. get: () => window.ownerServer,
  166. set: () => true,
  167. configurable: true
  168. })
  169. );
  170. function initBot() {
  171.  
  172. window.changeServer = function(serverID) {
  173. Sploop.changeServer(serverID);
  174. };
  175.  
  176. window.updateOwnerPosition = function(x, y) {
  177. ownerX = x;
  178. ownerY = y;
  179. }
  180.  
  181. setInterval(()=>{
  182. const angle = Math.atan2(ownerY - playerY, ownerX - playerX);
  183. if (Math.sqrt(Math.pow(((playerX - ownerX)), 2) + Math.pow(((playerY - ownerY)), 2)) > 185) {
  184. Sploop.touch.start({id: 1000, x: innerWidth/4, y: innerHeight/2})
  185. Sploop.touch.move({id: 1000, x: innerWidth/4+50*Math.cos(angle), y: innerHeight/2+50*Math.sin(angle)});
  186. }else{
  187. Sploop.touch.end({id: 1000, x: innerWidth/4, y: innerHeight/2})
  188. }
  189. });
  190.  
  191. const onDeathCallback = function(changedList) {
  192. const display = changedList[0].target.style.display;
  193. if(display == "flex") Sploop.spawn("2k09__Bot");
  194. };
  195. const deathChecker = new MutationObserver(onDeathCallback);
  196. deathChecker.observe($("#homepage"), {attributes: true, attributeFilter: ["style"]});
  197. };
  198.  
  199.  
  200.  
  201.  
  202. !isBot && (window.onload = ()=> initClient());
  203. function initClient() {
  204.  
  205. function createBot(id) {
  206. const div = document.createElement("div");
  207. div.innerHTML = `<iframe id="bot${id}" src="https://sploop.io" width="300" height="600" frameborder="0" scrolling="no" allowfullscreen="true" style="width: 300px; height: 200px; margin: 0; padding: 0; border: 0; position: absolute; top: 0; left: 0"></iframe>`;
  208. const iframe = div.firstChild;
  209. document.body.append(iframe);
  210. iframe.contentWindow.ownerServer = $("#server-select").selectedOptions[0].getAttribute("region");
  211. iframe.onload = ()=>{iframe.isLoaded = true};
  212. return iframe;
  213. };
  214. let placementkeys = {
  215. spike: false,
  216. trap: false
  217. };
  218. setInterval(() => {
  219. if(placementkeys.spike) Sploop.spikePlace()
  220. if(placementkeys.trap) Sploop.trapPlace()
  221. }, 20);
  222. window.addEventListener("keydown", function(e) {
  223. if(e.code == "KeyV") placementkeys.spike = true;
  224. if(e.code == "KeyF") placementkeys.trap = true;
  225. if(!keys[e.keyCode]) {
  226. keys[e.keyCode] = 1;
  227. if(e.code == "Enter" && window.chat && window.chat.value != '') {
  228. if(window.chat.value == "!md -ab") bots.push(createBot(bots.length))
  229. if(window.chat.value == "!md -rb") {
  230. for(let bID in bots) $(`#bot${bID}`).remove()
  231. bots.length = 0
  232. }
  233. if(window.chat.value.split(" ")[0] == "/close") {
  234. const id = window.chat.value.split(" ")[1] - 1
  235. if(!bots[id]) return;
  236. $(`#bot${id}`).remove()
  237. for(let bID in bots) {
  238. if(bID > id && bID != id) $(`#bot${bID}`).id = `bot${bID-1}`
  239. }
  240. bots.splice(id, 1)
  241. }
  242. }
  243. }
  244. });
  245. document.addEventListener("keyup", (e) => {
  246. if(e.code == "KeyV") placementkeys.spike = false;
  247. if(e.code == "KeyF") placementkeys.trap = false;
  248. if(keys[e.keyCode]) {
  249. keys[e.keyCode] = 0;
  250. };
  251. });
  252. };
  253.  
  254. (function autoHeal() {
  255. let allies = [], hp;
  256. const { fillRect, clearRect } = CanvasRenderingContext2D.prototype;
  257. CanvasRenderingContext2D.prototype.clearRect = function () {
  258. if (this.canvas.id === "game-canvas") allies = [];
  259. return clearRect.apply(this, arguments);
  260. };
  261.  
  262. CanvasRenderingContext2D.prototype.fillRect = function (x, y, width, height) {
  263. if(this.fillStyle == "#a4cc4f") {
  264. allies.push({x: x + 45, y: y - 70, hp: Math.round((width / 95) * 100)});
  265. if(allies.length == 1) hp = allies[0].hp;
  266. }
  267. fillRect.apply(this, arguments);
  268. };
  269.  
  270. window.addEventListener("keydown", function(e) {
  271. if(["1", "2"].includes(e.key)) weaponKey = e.key;
  272. });
  273.  
  274. function ah() {
  275. function getDelay(hp) {
  276. var delay = 200;
  277. if(hp < 90) delay = 130;
  278. if(hp < 74) delay = 60;
  279. if(hp < 36) delay = 45;
  280. return delay;
  281. };
  282. if(hp < 100) Sploop.foodPlace();
  283. setTimeout(()=>{ah()}, getDelay(hp));
  284. }
  285. ah();
  286. })();
  287.  
  288. (function hookEvents() {
  289. _setTimeout = setTimeout; console._log = console.log; KeyBoardEvent = KeyboardEvent;
  290. EventTarget.prototype._addEventListener = EventTarget.prototype.addEventListener;
  291. EventTarget.prototype.addEventListener = function(event, handler, c) {
  292. if (c==undefined) c=false;
  293. this._addEventListener(event,handler,c);
  294. if (!this.eventListenerList) this.eventListenerList = {};
  295. if (!this.eventListenerList[event]) this.eventListenerList[event] = [];
  296. this.eventListenerList[event].push({listener:handler,options:c});
  297. };
  298. EventTarget.prototype.getEvents = function(event) {
  299. if (!this.eventListenerList) this.eventListenerList = {};
  300. if (event==undefined) return this.eventListenerList;
  301. return this.eventListenerList[event];
  302. };
  303.  
  304. let array = [HTMLElement.prototype, window, document];
  305. for(let obj of array) {
  306. for(let prop in obj) {
  307. if(!prop.startsWith("on")) continue;
  308. Object.defineProperty(obj, prop, {
  309. get() {
  310. return this["_" + prop];
  311. },
  312. set(value) {
  313. this["_" + prop] = value;
  314. if(prop == "onbeforeunload") return value;
  315. this.addEventListener(prop.split("on")[1], value);
  316. }
  317. });
  318. }
  319. }
  320. })();
  321. }()
  322. })();