Advertisement
Guest User

Untitled

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