Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.98 KB | None | 0 0
  1. // ==UserScript==
  2. // @name WKrox Bots
  3. // @namespace https://twitter.com/SavagedKClerk
  4. // @version 1.0
  5. // @description The WKrox Bots
  6. // @author pcwars
  7. // @license MIT
  8. // @match http://agar.io/*
  9. // @require https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.4/socket.io.min.js
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. //http://agar.io/img/background.png
  15.  
  16. setTimeout(function() {
  17. var socket = io.connect('ws://104.236.100.252:8081');
  18. last_transmited_game_server = null;
  19.  
  20. socket.on('force-login', function (data) {
  21. socket.emit("login", {"uuid":client_uuid, "type":"client"});
  22. transmit_game_server();
  23. });
  24.  
  25. var client_uuid = localStorage.getItem('client_uuid');
  26.  
  27. if(client_uuid == null){
  28. console.log("generating a uuid for this user");
  29. client_uuid = Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
  30. localStorage.setItem('client_uuid', client_uuid);
  31. }
  32.  
  33. console.log("This is your config.client_uuid " + client_uuid);
  34. socket.emit("login", client_uuid);
  35.  
  36. //document.body.innerHTML += '<div style="position:absolute;background:#FFFFFF;z-index:9999;">client_id: '+client_uuid+'</div>';
  37. if(client_uuid != null){
  38. document.getElementById("instructions").innerHTML = "<div><hr><center><b>WKrox Bots</b>><br><p id='msg'></p></center><div class='form-group has-success has-feedback'><input value='YOUR CLIENT UUID: " + client_uuid + "' type='text' class='form-control' id='inputSuccess2' disabled><span class='glyphicon glyphicon-ok form-control-feedback'></span></div></div>";
  39. }else{
  40. document.getElementById("instructions").innerHTML = "<div><hr><center><b>BOTS</b><br><p id='msg'></p></center><div class='form-group has-warning has-feedback'><input value='SERVER ERROR TRY AGAIN LATER' type='text' class='form-control' id='inputDanger2' disabled><span class='glyphicon glyphicon-remove form-control-feedback'></span></div></div>";
  41. }
  42.  
  43. document.getElementById("canvas").innerHTML = '<canvas id="canvas" width="1362" height="979"></canvas>';
  44.  
  45. // values in --> window.agar
  46.  
  47. function emitPosition(){
  48. x = (mouseX - window.innerWidth / 2) / window.agar.drawScale + window.agar.rawViewport.x;
  49. y = (mouseY - window.innerHeight / 2) / window.agar.drawScale + window.agar.rawViewport.y;
  50.  
  51. socket.emit("pos", {"x": x, "y": y} );
  52. }
  53.  
  54. function reName(){
  55. var pcwarsname = document.forms["botrename"]["pcwname"].value;
  56. if (pcwarsname == null || pcwarsname == "") {
  57. alert("Bot Names Not Changed! (An Unnamed Cell)");
  58. return true;
  59. }
  60. alert("Bot Names Successfully Changed!");
  61. socket.emit("cmd", {"name":"renamebot", "nwname": pcwarsname } );
  62. }
  63.  
  64. function emitSplit(){
  65. socket.emit("cmd", {"name":"split"} );
  66. }
  67.  
  68. function fastEject(){
  69. var amount = 3;
  70. var duration = 30; //ms
  71.  
  72. var overwriting = function(evt) {
  73. if (evt.keyCode === 83) { // KEY_E
  74. for (var i = 0; i < amount; ++i) {
  75. setTimeout(function() {
  76. window.onkeydown({keyCode: 87}); // KEY_W
  77. window.onkeyup({keyCode: 87});
  78. }, i * duration);
  79. }
  80. }
  81. };
  82.  
  83. window.addEventListener('keydown', overwriting);
  84. }
  85.  
  86. function emitMassEject(){
  87. socket.emit("cmd", {"name":"eject"} );
  88. }
  89.  
  90. interval_id = setInterval(function() {
  91. emitPosition();
  92. }, 100);
  93.  
  94. interval_id2 = setInterval(function() {
  95. transmit_game_server_if_changed();
  96. }, 5000);
  97.  
  98.  
  99. //if key e is pressed do function split()
  100. document.addEventListener('keydown',function(e){
  101. var key = e.keyCode || e.which;
  102. if(key == 65){
  103. emitSplit();
  104. }
  105. });
  106.  
  107. //if key s is pressed do function fasteject()
  108. document.addEventListener('keydown',function(e){
  109. var key = e.keyCode || e.which;
  110. if(key == 83){
  111. fastEject();
  112. }
  113. });
  114.  
  115. //if key r is pressed do function eject()
  116. document.addEventListener('keydown',function(e){
  117. var key = e.keyCode || e.which;
  118. if(key == 81){
  119. emitMassEject();
  120. }
  121. });
  122.  
  123. function transmit_game_server_if_changed(){
  124. if(last_transmited_game_server != window.agar.ws){
  125. transmit_game_server();
  126. }
  127. }
  128.  
  129. function transmit_game_server(){
  130. last_transmited_game_server = window.agar.ws;
  131. socket.emit("cmd", {"name":"connect_server", "ip": last_transmited_game_server } );
  132. }
  133.  
  134. var mouseX = 0;
  135. var mouseY = 0;
  136.  
  137. $("body").mousemove(function( event ) {
  138. mouseX = event.clientX;
  139. mouseY = event.clientY;
  140. });
  141.  
  142. window.agar.minScale = -30;
  143. }, 5000);
  144.  
  145. //EXPOSED CODE BELOW
  146.  
  147. var allRules = [
  148. { hostname: ["agar.io"],
  149. scriptUriRe: /^http:\/\/agar\.io\/main_out\.js/,
  150. replace: function (m) {
  151. m.removeNewlines()
  152.  
  153. m.replace("var:allCells",
  154. /(=null;)(\w+)(.hasOwnProperty\(\w+\)?)/,
  155. "$1" + "$v=$2;" + "$2$3",
  156. "$v = {}")
  157.  
  158. m.replace("var:myCells",
  159. /(case 32:)(\w+)(\.push)/,
  160. "$1" + "$v=$2;" + "$2$3",
  161. "$v = []")
  162.  
  163. m.replace("var:top",
  164. /case 49:[^:]+?(\w+)=\[];/,
  165. "$&" + "$v=$1;",
  166. "$v = []")
  167.  
  168. m.replace("var:ws",
  169. /new WebSocket\((\w+)[^;]+?;/,
  170. "$&" + "$v=$1;",
  171. "$v = ''")
  172.  
  173. m.replace("var:topTeams",
  174. /case 50:(\w+)=\[];/,
  175. "$&" + "$v=$1;",
  176. "$v = []")
  177.  
  178. var dr = "(\\w+)=\\w+\\.getFloat64\\(\\w+,!0\\);\\w+\\+=8;\\n?"
  179. var dd = 7071.067811865476
  180. m.replace("var:dimensions",
  181. RegExp("case 64:"+dr+dr+dr+dr),
  182. "$&" + "$v = [$1,$2,$3,$4],",
  183. "$v = " + JSON.stringify([-dd,-dd,dd,dd]))
  184.  
  185. var vr = "(\\w+)=\\w+\\.getFloat32\\(\\w+,!0\\);\\w+\\+=4;"
  186. m.save() &&
  187. m.replace("var:rawViewport:x,y var:disableRendering:1",
  188. /else \w+=\(29\*\w+\+(\w+)\)\/30,\w+=\(29\*\w+\+(\w+)\)\/30,.*?;/,
  189. "$&" + "$v0.x=$1; $v0.y=$2; if($v1)return;") &&
  190. m.replace("var:disableRendering:2 hook:skipCellDraw",
  191. /(\w+:function\(\w+\){)(if\(this\.\w+\(\)\){\+\+this\.[\w$]+;)/,
  192. "$1" + "if($v || $H(this))return;" + "$2") &&
  193. m.replace("var:rawViewport:scale",
  194. /Math\.pow\(Math\.min\(64\/\w+,1\),\.4\)/,
  195. "($v.scale=$&)") &&
  196. m.replace("var:rawViewport:x,y,scale",
  197. RegExp("case 17:"+vr+vr+vr),
  198. "$&" + "$v.x=$1; $v.y=$2; $v.scale=$3;") &&
  199. m.reset_("window.agar.rawViewport = {x:0,y:0,scale:1};" +
  200. "window.agar.disableRendering = false;") ||
  201. m.restore()
  202.  
  203.  
  204.  
  205. m.replace("reset",
  206. /new WebSocket\(\w+[^;]+?;/,
  207. "$&" + m.reset)
  208.  
  209. m.replace("property:scale",
  210. /function \w+\(\w+\){\w+\.preventDefault\(\);[^;]+;1>(\w+)&&\(\1=1\)/,
  211. `;${makeProperty("scale", "$1")};$&`)
  212.  
  213. m.replace("var:minScale",
  214. /;1>(\w+)&&\(\1=1\)/,
  215. ";$v>$1 && ($1=$v)",
  216. "$v = 1")
  217.  
  218. m.replace("var:region",
  219. /console\.log\("Find "\+(\w+\+\w+)\);/,
  220. "$&" + "$v=$1;",
  221. "$v = ''")
  222.  
  223. m.replace("cellProperty:isVirus",
  224. /((\w+)=!!\(\w+&1\)[\s\S]{0,400})((\w+).(\w+)=\2;)/,
  225. "$1$4.isVirus=$3")
  226.  
  227. m.replace("var:dommousescroll",
  228. /("DOMMouseScroll",)(\w+),/,
  229. "$1($v=$2),")
  230.  
  231. m.replace("var:skinF hook:cellSkin",
  232. /(\w+.fill\(\))(;null!=(\w+))/,
  233. "$1;" +
  234. "if($v)$3 = $v(this,$3);" +
  235. "if($h)$3 = $h(this,$3);" +
  236. "$2");
  237.  
  238. /*m.replace("bigSkin",
  239. /(null!=(\w+)&&\((\w+)\.save\(\),)(\3\.clip\(\),\w+=)(Math\.max\(this\.size,this\.\w+\))/,
  240. "$1" + "$2.big||" + "$4" + "($2.big?2:1)*" + "$5")*/
  241.  
  242. m.replace("hook:afterCellStroke",
  243. /\((\w+)\.strokeStyle="#000000",\1\.globalAlpha\*=\.1,\1\.stroke\(\)\);\1\.globalAlpha=1;/,
  244. "$&" + "$H(this);")
  245.  
  246. m.replace("var:showStartupBg",
  247. /\w+\?\(\w\.globalAlpha=\w+,/,
  248. "$v && $&",
  249. "$v = true")
  250.  
  251.  
  252. var vAlive = /\((\w+)\[(\w+)\]==this\){\1\.splice\(\2,1\);/.exec(m.text)
  253. var vEaten = /0<this\.[$\w]+&&(\w+)\.push\(this\)}/.exec(m.text)
  254. !vAlive && console.error("Expose: can't find vAlive")
  255. !vEaten && console.error("Expose: can't find vEaten")
  256. if (vAlive && vEaten)
  257. m.replace("var:aliveCellsList var:eatenCellsList",
  258. RegExp(vAlive[1] + "=\\[\\];" + vEaten[1] + "=\\[\\];"),
  259. "$v0=" + vAlive[1] + "=[];" + "$v1=" + vEaten[1] + "=[];",
  260. "$v0 = []; $v1 = []")
  261.  
  262. m.replace("hook:drawScore",
  263. /(;(\w+)=Math\.max\(\2,(\w+\(\))\);)0!=\2&&/,
  264. "$1($H($3))||0!=$2&&")
  265.  
  266. m.replace("hook:beforeTransform hook:beforeDraw var:drawScale",
  267. /(\w+)\.save\(\);\1\.translate\((\w+\/2,\w+\/2)\);\1\.scale\((\w+),\3\);\1\.translate\((-\w+,-\w+)\);/,
  268. "$v = $3;$H0($1,$2,$3,$4);" + "$&" + "$H1($1,$2,$3,$4);",
  269. "$v = 1")
  270.  
  271. m.replace("hook:afterDraw",
  272. /(\w+)\.restore\(\);(\w+)&&\2\.width&&\1\.drawImage/,
  273. "$H();" + "$&")
  274.  
  275.  
  276. m.replace("hook:cellColor",
  277. /(\w+=)this\.color;/,
  278. "$1 ($h && $h(this, this.color) || this.color);")
  279.  
  280. m.replace("var:drawGrid",
  281. /(\w+)\.globalAlpha=(\.2\*\w+);/,
  282. "if(!$v)return;" + "$&",
  283. "$v = true")
  284.  
  285. m.replace("hook:drawCellMass",
  286. /&&\((\w+\|\|0==\w+\.length&&\(!this\.\w+\|\|this\.\w+\)&&20<this\.size)\)&&/,
  287. "&&( $h ? $h(this,$1) : ($1) )&&")
  288.  
  289. m.replace("hook:cellMassText",
  290. /(\.\w+)(\(~~\(this\.size\*this\.size\/100\)\))/,
  291. "$1( $h ? $h(this,$2) : $2 )")
  292.  
  293. m.replace("hook:cellMassTextScale",
  294. /(\.\w+)\((this\.\w+\(\))\)([\s\S]{0,1000})\1\(\2\/2\)/,
  295. "$1($2)$3$1( $h ? $h(this,$2/2) : ($2/2) )")
  296.  
  297. var template = (key,n) =>
  298. `this\\.${key}=\\w+\\*\\(this\\.(\\w+)-this\\.(\\w+)\\)\\+this\\.\\${n};`
  299. var re = new RegExp(template('x', 2) + template('y', 4) + template('size', 6))
  300. var match = re.exec(m.text)
  301. if (match) {
  302. m.cellProp.nx = match[1]
  303. m.cellProp.ny = match[3]
  304. m.cellProp.nSize = match[5]
  305. } else
  306. console.error("Expose: cellProp:x,y,size search failed!")
  307.  
  308. }},
  309. ]
  310.  
  311. function makeProperty(name, varname) {
  312. return "'" + name + "' in window.agar || " +
  313. "Object.defineProperty( window.agar, '"+name+"', " +
  314. "{get:function(){return "+varname+"},set:function(){"+varname+"=arguments[0]},enumerable:true})"
  315. }
  316.  
  317. if (window.top != window.self)
  318. return
  319.  
  320. if (document.readyState !== 'loading')
  321. return console.error("Expose: this script should run at document-start")
  322.  
  323. var isFirefox = /Firefox/.test(navigator.userAgent)
  324.  
  325. // Stage 1: Find corresponding rule
  326. var rules
  327. for (var i = 0; i < allRules.length; i++)
  328. if (allRules[i].hostname.indexOf(window.location.hostname) !== -1) {
  329. rules = allRules[i]
  330. break
  331. }
  332. if (!rules)
  333. return console.error("Expose: cant find corresponding rule")
  334.  
  335.  
  336. // Stage 2: Search for `main_out.js`
  337. if (isFirefox) {
  338. function bse_listener(e) { tryReplace(e.target, e) }
  339. window.addEventListener('beforescriptexecute', bse_listener, true)
  340. } else {
  341. // Iterate over document.head child elements and look for `main_out.js`
  342. for (var i = 0; i < document.head.childNodes.length; i++)
  343. if (tryReplace(document.head.childNodes[i]))
  344. return
  345. // If there are no desired element in document.head, then wait until it appears
  346. function observerFunc(mutations) {
  347. for (var i = 0; i < mutations.length; i++) {
  348. var addedNodes = mutations[i].addedNodes
  349. for (var j = 0; j < addedNodes.length; j++)
  350. if (tryReplace(addedNodes[j]))
  351. return observer.disconnect()
  352. }
  353. }
  354. var observer = new MutationObserver(observerFunc)
  355. observer.observe(document.head, {childList: true})
  356. }
  357.  
  358. // Stage 3: Replace found element using rules
  359. function tryReplace(node, event) {
  360. var scriptLinked = rules.scriptUriRe && rules.scriptUriRe.test(node.src)
  361. var scriptEmbedded = rules.scriptTextRe && rules.scriptTextRe.test(node.textContent)
  362. if (node.tagName != "SCRIPT" || (!scriptLinked && !scriptEmbedded))
  363. return false // this is not desired element; get back to stage 2
  364.  
  365. if (isFirefox) {
  366. event.preventDefault()
  367. window.removeEventListener('beforescriptexecute', bse_listener, true)
  368. }
  369.  
  370. var mod = {
  371. reset: "",
  372. text: null,
  373. history: [],
  374. cellProp: {},
  375. save() {
  376. this.history.push({reset:this.reset, text:this.text})
  377. return true
  378. },
  379. restore() {
  380. var state = this.history.pop()
  381. this.reset = state.reset
  382. this.text = state.text
  383. return true
  384. },
  385. reset_(reset) {
  386. this.reset += reset
  387. return true
  388. },
  389. replace(what, from, to, reset) {
  390. var vars = [], hooks = []
  391. what.split(" ").forEach((x) => {
  392. x = x.split(":")
  393. x[0] === "var" && vars.push(x[1])
  394. x[0] === "hook" && hooks.push(x[1])
  395. })
  396. function replaceShorthands(str) {
  397. function nope(letter, array, fun) {
  398. str = str
  399. .split(new RegExp('\\$' + letter + '([0-9]?)'))
  400. .map((v,n) => n%2 ? fun(array[v||0]) : v)
  401. .join("")
  402. }
  403. nope('v', vars, (name) => "window.agar." + name)
  404. nope('h', hooks, (name) => "window.agar.hooks." + name)
  405. nope('H', hooks, (name) =>
  406. "window.agar.hooks." + name + "&&" +
  407. "window.agar.hooks." + name)
  408. return str
  409. }
  410. var newText = this.text.replace(from, replaceShorthands(to))
  411. if(newText === this.text) {
  412. console.error("Expose: `" + what + "` replacement failed!")
  413. return false
  414. } else {
  415. this.text = newText
  416. if (reset)
  417. this.reset += replaceShorthands(reset) + ";"
  418. return true
  419. }
  420. },
  421. removeNewlines() {
  422. this.text = this.text.replace(/([,\/])\n/mg, "$1")
  423. },
  424. get: function() {
  425. var cellProp = JSON.stringify(this.cellProp)
  426. return `window.agar={hooks:{},cellProp:${cellProp}};` +
  427. this.reset + this.text
  428. }
  429. }
  430.  
  431. if (scriptEmbedded) {
  432. mod.text = node.textContent
  433. rules.replace(mod)
  434. if (isFirefox) {
  435. document.head.removeChild(node)
  436. var script = document.createElement("script")
  437. script.textContent = mod.get()
  438. document.head.appendChild(script)
  439. } else {
  440. node.textContent = mod.get()
  441. }
  442. console.log("Expose: replacement done")
  443. } else {
  444. document.head.removeChild(node)
  445. var request = new XMLHttpRequest()
  446. request.onload = function() {
  447. var script = document.createElement("script")
  448. mod.text = this.responseText
  449. rules.replace(mod)
  450. script.textContent = mod.get()
  451. // `main_out.js` should not executed before jQuery was loaded, so we need to wait jQuery
  452. function insertScript(script) {
  453. if (typeof jQuery === "undefined")
  454. return setTimeout(insertScript, 0, script)
  455. document.head.appendChild(script)
  456. console.log("Expose: replacement done")
  457. }
  458. insertScript(script)
  459. }
  460. request.onerror = function() {
  461. console.error("Expose: response was null");
  462.  
  463. }
  464. request.open("get", node.src, true)
  465. request.send()
  466. }
  467. return true
  468.  
  469. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement