Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.70 KB | None | 0 0
  1. // ==UserScript==
  2. // @name GammaBots
  3. // @version 1.0
  4. // @author GammaYT
  5. // @match http://soapplus.tk/*
  6. // @match http://mgar.io/*
  7. // @require https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.4.5/socket.io.min.js
  8. // @grant none
  9. // @run-at document-start
  10. // ==/UserScript==
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. (function() {
  18. var amount = 2;
  19. var duration = 1; //ms
  20.  
  21. var overwriting = function(evt) {
  22. if (evt.keyCode === 87) { // KEY_E
  23. for (var i = 0; i < amount; ++i) {
  24. setTimeout(function() {
  25. window.onkeydown({keyCode: 87}); // KEY_W
  26. window.onkeyup({keyCode: 87});
  27. }, i * duration);
  28. }
  29. }
  30. };
  31.  
  32. window.addEventListener('keydown', overwriting);
  33. })();
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46. (function (){
  47. var tazoom_main = function() {
  48. function initialize() {
  49. console.log("Zoom Loaded");
  50.  
  51. var zoomMin = 1.0; // Larger number means able to zoom in closer.
  52. var zoomMax = 0.3; // Smaller number means able to zoom out further.
  53. var zoomInc = 0.05; // Larger number for faster zooming, Smaller number for slower zooming.
  54.  
  55. webfrontend.gui.BackgroundArea.prototype.onHotKeyPress = function(be) {
  56. if(!this.active || be.getTarget() != this.mapContainer)
  57. return;
  58. var bh = be.getKeyIdentifier();
  59. var bf = ClientLib.Vis.VisMain.GetInstance();
  60. switch(bh) {
  61. case "+":
  62. var bg = bf.get_Region().get_ZoomFactor() + zoomInc;
  63. bf.get_Region().set_ZoomFactor(Math.min(zoomMin, Math.max(zoomMax, bg)));
  64. break;
  65. case "-":
  66. var bg = bf.get_Region().get_ZoomFactor() - zoomInc;
  67. bf.get_Region().set_ZoomFactor(Math.min(zoomMin, Math.max(zoomMax, bg)));
  68. break;
  69. }
  70. this.closeCityInfo();
  71. this.closeCityList();
  72. }
  73.  
  74. var backgroundArea = qx.core.Init.getApplication().getBackgroundArea();
  75. qx.bom.Element.removeListener(backgroundArea.mapContainer, "mousewheel", backgroundArea._onMouseWheel, backgroundArea);
  76. qx.bom.Element.removeListener(backgroundArea.mapBlocker, "mousewheel", backgroundArea._onMouseWheel, backgroundArea);
  77. webfrontend.gui.BackgroundArea.prototype._onMouseWheel = function(e) {
  78. if(this.activeSceneView == null)
  79. return;
  80. var bz = e.getWheelDelta();
  81. var by = this.activeSceneView.get_ZoomFactor();
  82. by += bz > 0 ? -zoomInc : zoomInc;
  83. by = Math.min(zoomMin, Math.max(zoomMax, by));
  84. this.activeSceneView.set_ZoomFactor(by);
  85. e.stop();
  86. }
  87. qx.bom.Element.addListener(backgroundArea.mapContainer, "mousewheel", backgroundArea._onMouseWheel, backgroundArea);
  88. qx.bom.Element.addListener(backgroundArea.mapBlocker, "mousewheel", backgroundArea._onMouseWheel, backgroundArea);
  89. }
  90.  
  91. function tazoom_checkIfLoaded() {
  92. try {
  93. if (typeof qx != 'undefined') {
  94. a = qx.core.Init.getApplication(); // application
  95. mb = qx.core.Init.getApplication().getMenuBar();
  96. if (a && mb) {
  97. initialize();
  98. } else
  99. window.setTimeout(tazoom_checkIfLoaded, 1000);
  100. } else {
  101. window.setTimeout(tazoom_checkIfLoaded, 1000);
  102. }
  103. } catch (e) {
  104. if (typeof console != 'undefined') console.log(e);
  105. else if (window.opera) opera.postError(e);
  106. else GM_log(e);
  107. }
  108. }
  109.  
  110. if (/commandandconquer\.com/i.test(document.domain)) {
  111. window.setTimeout(tazoom_checkIfLoaded, 1000);
  112. }
  113. }
  114.  
  115. // injecting, because there seem to be problems when creating game interface with unsafeWindow
  116. var tazoomScript = document.createElement("script");
  117. tazoomScript.innerHTML = "(" + tazoom_main.toString() + ")();";
  118. tazoomScript.type = "text/javascript";
  119. if (/commandandconquer\.com/i.test(document.domain)) {
  120. document.getElementsByTagName("head")[0].appendChild(tazoomScript);
  121. }
  122. })();
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135. alert("Made by GammaYT with help, based on NODE.JS Contact me on Skype: live:beastwolfyt");
  136. window.MC = {};
  137. setTimeout(function() {
  138. var real_minx = -7071;
  139. var real_miny = -7071;
  140. var real_maxx = 7071;
  141. var real_maxy = 7071;
  142. var lastsent = {
  143. minx: 0,
  144. miny: 0,
  145. maxx: 0,
  146. maxy: 0
  147. };
  148.  
  149. function valcompare(Y, Z) {
  150. return 0.01 > Y - Z && -0.01 < Y - Z
  151. }
  152. window.agar.hooks.dimensionsUpdated = function(server_minx, server_miny, server_maxx, server_maxy) {
  153. if (valcompare(server_maxx - server_minx, server_maxy - server_miny)) {
  154. real_minx = server_minx;
  155. real_miny = server_miny;
  156. real_maxx = server_maxx;
  157. real_maxy = server_maxy
  158. } else {
  159. if (valcompare(server_minx, lastsent.minx)) {
  160. if (0.01 < server_maxx - lastsent.maxx || -0.01 > server_maxx - lastsent.maxx) {
  161. real_minx = server_minx;
  162. real_maxx = server_minx + 14142.135623730952
  163. }
  164. }
  165. if (0.01 < server_minx - lastsent.minx || -0.01 > server_minx - lastsent.minx) {
  166. if (valcompare(server_maxx, lastsent.maxx)) {
  167. real_maxx = server_maxx;
  168. real_minx = server_maxx - 14142.135623730952
  169. }
  170. }
  171. if (0.01 < server_miny - lastsent.miny || -0.01 > server_miny - lastsent.miny) {
  172. if (valcompare(server_maxy, lastsent.maxy)) {
  173. real_maxy = server_maxy;
  174. real_miny = server_maxy - 14142.135623730952
  175. }
  176. }
  177. if (valcompare(server_miny, lastsent.miny)) {
  178. if (0.01 < server_maxy - lastsent.maxy || -0.01 > server_maxy - lastsent.maxy) {
  179. real_miny = server_miny;
  180. real_maxy = server_miny + 14142.135623730952
  181. }
  182. }
  183. if (server_minx < real_minx) {
  184. real_minx = server_minx;
  185. real_maxx = server_minx + 14142.135623730952
  186. }
  187. if (server_maxx > real_maxx) {
  188. real_maxx = server_maxx;
  189. real_minx = server_maxx - 14142.135623730952
  190. }
  191. if (server_miny < real_miny) {
  192. real_miny = server_miny;
  193. real_maxy = server_miny + 14142.135623730952
  194. }
  195. if (server_maxy > real_maxy) {
  196. real_maxy = server_maxy;
  197. real_miny = server_maxy - 14142.135623730952
  198. }
  199. lastsent.minx = server_minx;
  200. lastsent.miny = server_miny;
  201. lastsent.maxy = server_maxy;
  202. lastsent.maxx = server_maxx
  203. }
  204. offset_x = real_minx || -7071;
  205. offset_y = real_miny || -7071
  206. };
  207. var socket = io.connect('ws://127.0.0.1:8081');
  208. var canMove = true;
  209. var movetoMouse = true;
  210. var moveEvent = new Array(2);
  211. var canvas = document.getElementById("canvas");
  212. last_transmited_game_server = null;
  213. socket.on('force-login', function(data) {
  214. socket.emit("login", {
  215. "uuid": client_uuid,
  216. "type": "client"
  217. });
  218. transmit_game_server()
  219. });
  220.  
  221. var a = '';
  222. var iDiv = document.createElement('div');
  223. iDiv.id = 'block';
  224. document.getElementsByTagName('body')[0].appendChild(iDiv);
  225. iDiv.innerHTML = '<div style="position: absolute; top: 5px; left: 5px; padding: 0px 0px; font-family: Tahoma; color: white; z-index: 9999; border-radius: 5px; min-height: 15px; min-width: 200px; background-color: transparent;"><br><div id="counter"><center></b></center></div></b>' + a
  226. +'<b><div id="bName"<span class="label label-default pull-right"><span id="minionCount"></span></div></b><b></b></span></div><b><b><<div G GammaHack' + a
  227. +'<br></div>';
  228. $( "#canvas" ).after( "<div style='background-color: #000000; -moz-opacity: 0.4; -khtml-opacity: 0.4; opacity: 0.4; filter: alpha(opacity=40); zoom: 1; width: 250px; top: 150px; left: 10px; display: block; position: absolute; text-align: center; font-size: 20px; color: #ffffff; padding: 5px; font-family: Ubuntu;'> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'>Minion: <a id='minionCount' >waiting..</a> </div>" );
  229. $( "#canvas" ).after( "<div style='background-color: #000000; -moz-opacity: 0.4; -khtml-opacity: 0.4; opacity: 0.4; filter: alpha(opacity=40); zoom: 1; width: 600px; top: 100px; left: 10px; display: block; position: absolute; text-align: center; font-size: 18px; color: #ffffff; padding: 5px; font-family: Ubuntu;'> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'>GammaBots v1<a id='client_uuid' ></a> </div><a id='clientuuid' ></a> </div>" );
  230. $( "#canvas" ).after( "<div style='background-color: #000000; -moz-opacity: 0.4; -khtml-opacity: 0.4; opacity: 0.4; filter: alpha(opacity=40); zoom: 1; width: 205px; top: 210px; left: 10px; display: block; position: absolute; text-align: center; font-size: 18px; color: #ffffff; padding: 5px; font-family: Ubuntu;'> <div style='color:#ffffff; display: inline; -moz-opacity:1; -khtml-opacity: 1; opacity:1; filter:alpha(opacity=100); padding: 10px;'><a id='client_uuid' >A: Cell/Mouse <br> D: Freeze/Unfreeze</a> </div>" );
  231.  
  232.  
  233. setInterval(function(){
  234. if(!movetoMouse){
  235. document.getElementById('mControl').innerHTML = '<div id="mControl">Mouse Control :<span class="label label-danger pull-right">OFF</span></div>';
  236. }else{
  237. document.getElementById('mControl').innerHTML = '<div id="mControl">Mouse Control :<span class="label label-success pull-right">ON</span></div>';
  238. }
  239. if(canMove){
  240. document.getElementById('cMove').innerHTML = '<div id="cMove">Stop Move :<span class="label label-danger pull-right">OFF</span></div>';
  241. }else{
  242. document.getElementById('cMove').innerHTML = '<div id="cMove">Stop Move :<span class="label label-success pull-right">ON</span></div>';
  243. }
  244. }, 1000);
  245. socket.on('spawn-count', function(data) {
  246. document.getElementById('minionCount').innerHTML = data
  247. });
  248. var client_uuid = localStorage.getItem('client_uuid');
  249.  
  250. $("#instructions").replaceWith('<br><div class="input-group"><span class="input-group-addon" id="basic-addon1">UUID</span><input type="text" value="' + client_uuid + '" readonly class="form-control"</div>');
  251.  
  252. if (client_uuid == null) {
  253. console.log("generating a uuid for this user");
  254. client_uuid = ""; var ranStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  255. for (var ii = 0; ii < 15; ii++) client_uuid += ranStr.charAt(Math.floor(Math.random() * ranStr.length));
  256. localStorage.setItem('client_uuid', client_uuid)
  257. }
  258. socket.emit("login", client_uuid);
  259. $("#settings").replaceWith('<br><div class="input-group"><span class="input-group-addon" id="basic-addon1">UUID</span><input type="text" value="' + client_uuid + '" readonly class="form-control"</div>');
  260. $("#settings").replaceWith('<br><div<br><center><span style="font-size=xx-large;color:red;font-weight:bold">GammaBots v1:</span>Press <b><span " style="color:red;">R</b> to eject mass from your bot<br>Press <b><span style="color:red;">E</b> to split your bot <br>Press <br> ');
  261. function isMe(cell) {
  262. for (var i = 0; i < window.agar.myCells.length; i++) {
  263. if (window.agar.myCells[i] == cell.id) {
  264. return true
  265. }
  266. }
  267. return false
  268. }
  269.  
  270. window.agar.hooks.drawCellMass = function(cell, old_draw) {
  271. if(cell.size > 20) return cell;
  272. }
  273.  
  274. window.agar.hooks.cellMassTextScale = function(cell, old_scale) {
  275. }
  276.  
  277. function getCell() {
  278. var me = [];
  279. for (var key in window.agar.allCells) {
  280. var cell = window.agar.allCells[key];
  281. if (isMe(cell)) {
  282. me.push(cell)
  283. }
  284. }
  285. return me[0]
  286. }
  287. var skin_var = 0;
  288.  
  289. function emitPosition() {
  290. for (i = 0; i < agar.myCells.length; i++) {}
  291. x = (mouseX - window.innerWidth / 2) / window.agar.drawScale + window.agar.rawViewport.x;
  292. y = (mouseY - window.innerHeight / 2) / window.agar.drawScale + window.agar.rawViewport.y;
  293. if (!movetoMouse) {
  294. x = getCell().x;
  295. y = getCell().y
  296. }
  297. socket.emit("pos", {
  298. "x": x - (real_minx + 7071),
  299. "y": y - (real_miny + 7071),
  300. "dimensions": [-7071, -7071, 7071, 7071]
  301. })
  302. }
  303.  
  304.  
  305. function emitSplit() {
  306. socket.emit("cmd", {
  307. "name": "split"
  308. })
  309. }
  310.  
  311. function emitMassEject() {
  312. socket.emit("cmd", {
  313. "name": "eject"
  314. })
  315. }
  316.  
  317. function toggleMovement() {
  318. canMove = !canMove;
  319. switch (canMove) {
  320. case true:
  321. canvas.onmousemove = moveEvent[0];
  322. moveEvent[0] = null;
  323. canvas.onmousedown = moveEvent[1];
  324. moveEvent[1] = null;
  325. break;
  326. case false:
  327. canvas.onmousemove({
  328. clientX: innerWidth / 2,
  329. clientY: innerHeight / 2
  330. });
  331. moveEvent[0] = canvas.onmousemove;
  332. canvas.onmousemove = null;
  333. moveEvent[1] = canvas.onmousedown;
  334. canvas.onmousedown = null;
  335. break
  336. }
  337. }
  338. interval_id = setInterval(function() {
  339. emitPosition()
  340. }, 100);
  341. interval_id2 = setInterval(function() {
  342. transmit_game_server_if_changed()
  343. }, 5000);
  344. document.addEventListener('keydown', function(e) {
  345. var key = e.keyCode || e.which;
  346. switch (key) {
  347. case 65:
  348. movetoMouse = !movetoMouse;
  349. if(movetoMouse) { document.getElementById('ismoveToMouse').innerHTML = "On"; } else { document.getElementById('ismoveToMouse').innerHTML = "Off"; }
  350. break;
  351. case 68:
  352. toggleMovement();
  353. if(!canMove) { document.getElementById('isStopMove').innerHTML = "On"; } else { document.getElementById('isStopMove').innerHTML = "Off"; }
  354. break;
  355. case 69:
  356. emitSplit();
  357. break;
  358. case 82:
  359. emitMassEject();
  360. break
  361. }
  362. });
  363.  
  364. function transmit_game_server_if_changed() {
  365. if (last_transmited_game_server != window.agar.ws) {
  366. transmit_game_server()
  367. }
  368. }
  369.  
  370. function transmit_game_server() {
  371. last_transmited_game_server = window.agar.ws;
  372. socket.emit("cmd", {
  373. "name": "connect_server",
  374. "ip": last_transmited_game_server
  375. })
  376. }
  377. var mouseX = 0;
  378. var mouseY = 0;
  379. $("body").mousemove(function(event) {
  380. mouseX = event.clientX;
  381. mouseY = event.clientY
  382. });
  383. window.agar.minScale = -30
  384. }, 5000);
  385.  
  386. var allRules = [
  387. { hostname: ["agar.io"],
  388. scriptUriRe: /^http:\/\/agar\.io\/main_out\.js/,
  389. replace: function (m) {
  390. m.removeNewlines()
  391.  
  392. m.replace("var:allCells",
  393. /(=null;)(\w+)(.hasOwnProperty\(\w+\)?)/,
  394. "$1" + "$v=$2;" + "$2$3",
  395. "$v = {}")
  396.  
  397. m.replace("var:myCells",
  398. /(case 32:)(\w+)(\.push)/,
  399. "$1" + "$v=$2;" + "$2$3",
  400. "$v = []")
  401.  
  402. m.replace("var:top",
  403. /case 49:[^:]+?(\w+)=\[];/,
  404. "$&" + "$v=$1;",
  405. "$v = []")
  406.  
  407. m.replace("var:topTeams",
  408. /case 50:(\w+)=\[];/,
  409. "$&" + "$v=$1;",
  410. "$v = []")
  411.  
  412. var dr = "(\\w+)=\\w+\\.getFloat64\\(\\w+,!0\\);\\w+\\+=8;\\n?"
  413. var dd = 7071.067811865476
  414. m.replace("var:dimensions hook:dimensionsUpdated",
  415. RegExp("case 64:"+dr+dr+dr+dr),
  416. "$&" + "$v = [$1,$2,$3,$4],$H($1,$2,$3,$4),",
  417. "$v = " + JSON.stringify([-dd,-dd,dd,dd]))
  418.  
  419. var vr = "(\\w+)=\\w+\\.getFloat32\\(\\w+,!0\\);\\w+\\+=4;"
  420. m.save() &&
  421. m.replace("var:rawViewport:x,y var:disableRendering:1",
  422. /else \w+=\(5\*\w+\+(\w+)\)\/6,\w+=\(5\*\w+\+(\w+)\)\/6,.*?;/,
  423. "$&" + "$v0.x=$1; $v0.y=$2; if($v1)return;") &&
  424. m.replace("var:disableRendering:2 hook:skipCellDraw",
  425. /(\w+:function\(\w+\){)(if\(this\.\w+\(\)\){\+\+this\.[\w$]+;)/,
  426. "$1" + "if($v || $H(this))return;" + "$2") &&
  427. m.replace("var:rawViewport:scale",
  428. /Math\.pow\(Math\.min\(64\/\w+,1\),\.4\)/,
  429. "($v.scale=$&)") &&
  430. m.replace("var:rawViewport:x,y,scale",
  431. RegExp("case 17:"+vr+vr+vr),
  432. "$&" + "$v.x=$1; $v.y=$2; $v.scale=$3;") &&
  433. m.reset_("window.agar.rawViewport = {x:0,y:0,scale:1};" +
  434. "window.agar.disableRendering = false;") ||
  435. m.restore()
  436.  
  437. m.replace("reset hook:connect var:ws var:webSocket",
  438. /new WebSocket\((\w+)\);/,
  439. "$v1 = $&; $v0=$1;" + m.reset + "$H();",
  440. "$v0 = ''; $v1 = null;")
  441.  
  442. m.replace("property:scale",
  443. /function \w+\(\w+\){\w+\.preventDefault\(\);[^;]+;1>(\w+)&&\(\1=1\)/,
  444. `;${makeProperty("scale", "$1")};$&`)
  445.  
  446. m.replace("var:minScale",
  447. /;1>(\w+)&&\(\1=1\)/,
  448. ";$v>$1 && ($1=$v)",
  449. "$v = 1")
  450.  
  451. m.replace("var:region",
  452. /console\.log\("Find "\+(\w+\+\w+)\);/,
  453. "$&" + "$v=$1;",
  454. "$v = ''")
  455.  
  456. m.replace("cellProperty:isVirus",
  457. /((\w+)=!!\(\w+&1\)[\s\S]{0,400})((\w+).(\w+)=\2;)/,
  458. "$1$4.isVirus=$3")
  459.  
  460. m.replace("var:dommousescroll",
  461. /("DOMMouseScroll",)(\w+),/,
  462. "$1($v=$2),")
  463.  
  464. m.replace("var:skinF hook:cellSkin",
  465. /(\w+.fill\(\))(;null!=(\w+))/,
  466. "$1;" +
  467. "if($v)$3 = $v(this,$3);" +
  468. "if($h)$3 = $h(this,$3);" +
  469. "$2");
  470.  
  471. m.replace("hook:afterCellStroke",
  472. /\((\w+)\.strokeStyle="#000000",\1\.globalAlpha\*=\.1,\1\.stroke\(\)\);\1\.globalAlpha=1;/,
  473. "$&" + "$H(this);")
  474.  
  475. m.replace("var:showStartupBg",
  476. /\w+\?\(\w\.globalAlpha=\w+,/,
  477. "$v && $&",
  478. "$v = true")
  479.  
  480. var vAlive = /\((\w+)\[(\w+)\]==this\){\1\.splice\(\2,1\);/.exec(m.text)
  481. var vEaten = /0<this\.[$\w]+&&(\w+)\.push\(this\)}/.exec(m.text)
  482. !vAlive && console.error("Expose: can't find vAlive")
  483. !vEaten && console.error("Expose: can't find vEaten")
  484. if (vAlive && vEaten)
  485. m.replace("var:aliveCellsList var:eatenCellsList",
  486. RegExp(vAlive[1] + "=\\[\\];" + vEaten[1] + "=\\[\\];"),
  487. "$v0=" + vAlive[1] + "=[];" + "$v1=" + vEaten[1] + "=[];",
  488. "$v0 = []; $v1 = []")
  489.  
  490. m.replace("hook:drawScore",
  491. /(;(\w+)=Math\.max\(\2,(\w+\(\))\);)0!=\2&&/,
  492. "$1($H($3))||0!=$2&&")
  493.  
  494. m.replace("hook:beforeTransform hook:beforeDraw var:drawScale",
  495. /(\w+)\.save\(\);\1\.translate\((\w+\/2,\w+\/2)\);\1\.scale\((\w+),\3\);\1\.translate\((-\w+,-\w+)\);/,
  496. "$v = $3;$H0($1,$2,$3,$4);" + "$&" + "$H1($1,$2,$3,$4);",
  497. "$v = 1")
  498.  
  499. m.replace("hook:afterDraw",
  500. /(\w+)\.restore\(\);(\w+)&&\2\.width&&\1\.drawImage/,
  501. "$H();" + "$&")
  502.  
  503. m.replace("hook:cellColor",
  504. /(\w+=)this\.color,/,
  505. "$1 ($h && $h(this, this.color) || this.color),")
  506.  
  507. m.replace("var:drawGrid",
  508. /(\w+)\.globalAlpha=(\.2\*\w+);/,
  509. "if(!$v)return;" + "$&",
  510. "$v = true")
  511.  
  512. m.replace("hook:drawCellMass",
  513. /&&\((\w+\|\|0==\w+\.length&&\(!this\.\w+\|\|this\.\w+\)&&20<this\.size)\)&&/,
  514. "&&( $h ? $h(this,$1) : ($1) )&&")
  515.  
  516. m.replace("hook:cellMassText",
  517. /(\.\w+)(\(~~\(this\.size\*this\.size\/100\)\))/,
  518. "$1( $h ? $h(this,$2) : $2 )")
  519.  
  520. m.replace("hook:cellMassTextScale",
  521. /(\.\w+)\((this\.\w+\(\))\)([\s\S]{0,1000})\1\(\2\/2\)/,
  522. "$1($2)$3$1( $h ? $h(this,$2/2) : ($2/2) )")
  523.  
  524. m.replace("var:enableDirectionSending",
  525. /;64>(\w+)\*\1\+(\w+)\*\2/,
  526. ";if(!$v)return" + "$&",
  527. "$v = true")
  528.  
  529. m.replace("var:simpleCellDraw",
  530. /(:function\(\){)(var a=10;)/,
  531. "$1 if($v)return true;$2",
  532. "$v=false")
  533.  
  534. m.replace("hook:updateLeaderboard",
  535. /({\w+=null;)(if\(null!=)/,
  536. "$1 if($H())return; $2")
  537.  
  538. var template = (key,n) =>
  539. `this\\.${key}=\\w+\\*\\(this\\.(\\w+)-this\\.(\\w+)\\)\\+this\\.\\${n};`
  540. var re = new RegExp(template('x', 2) + template('y', 4) + template('size', 6))
  541. var match = re.exec(m.text)
  542. if (match) {
  543. m.cellProp.nx = match[1]
  544. m.cellProp.ny = match[3]
  545. m.cellProp.nSize = match[5]
  546. } else
  547. console.error("Expose: cellProp:x,y,size search failed!")
  548.  
  549. }},
  550. ]
  551.  
  552. function makeProperty(name, varname) {
  553. return "'" + name + "' in window.agar || " +
  554. "Object.defineProperty( window.agar, '"+name+"', " +
  555. "{get:function(){return "+varname+"},set:function(){"+varname+"=arguments[0]},enumerable:true})"
  556. }
  557.  
  558. if (window.top != window.self)
  559. return
  560.  
  561. if (document.readyState !== 'loading')
  562. return console.error("Expose: this script should run at document-start")
  563.  
  564. var isFirefox = /Firefox/.test(navigator.userAgent)
  565.  
  566. // Stage 1: Find corresponding rule
  567. var rules
  568. for (var i = 0; i < allRules.length; i++)
  569. if (allRules[i].hostname.indexOf(window.location.hostname) !== -1) {
  570. rules = allRules[i]
  571. break
  572. }
  573. if (!rules)
  574. return console.error("Expose: cant find corresponding rule")
  575.  
  576.  
  577. // Stage 2: Search for `main_out.js`
  578. if (isFirefox) {
  579. function bse_listener(e) { tryReplace(e.target, e) }
  580. window.addEventListener('beforescriptexecute', bse_listener, true)
  581. } else {
  582. // Iterate over document.head child elements and look for `main_out.js`
  583. for (var i = 0; i < document.head.childNodes.length; i++)
  584. if (tryReplace(document.head.childNodes[i]))
  585. return
  586. // If there are no desired element in document.head, then wait until it appears
  587. function observerFunc(mutations) {
  588. for (var i = 0; i < mutations.length; i++) {
  589. var addedNodes = mutations[i].addedNodes
  590. for (var j = 0; j < addedNodes.length; j++)
  591. if (tryReplace(addedNodes[j]))
  592. return observer.disconnect()
  593. }
  594. }
  595. var observer = new MutationObserver(observerFunc)
  596. observer.observe(document.head, {childList: true})
  597. }
  598.  
  599. // Stage 3: Replace found element using rules
  600. function tryReplace(node, event) {
  601. var scriptLinked = rules.scriptUriRe && rules.scriptUriRe.test(node.src)
  602. var scriptEmbedded = rules.scriptTextRe && rules.scriptTextRe.test(node.textContent)
  603. if (node.tagName != "SCRIPT" || (!scriptLinked && !scriptEmbedded))
  604. return false // this is not desired element; get back to stage 2
  605.  
  606. if (isFirefox) {
  607. event.preventDefault()
  608. window.removeEventListener('beforescriptexecute', bse_listener, true)
  609. }
  610.  
  611. var mod = {
  612. reset: "",
  613. text: null,
  614. history: [],
  615. cellProp: {},
  616. save() {
  617. this.history.push({reset:this.reset, text:this.text})
  618. return true
  619. },
  620. restore() {
  621. var state = this.history.pop()
  622. this.reset = state.reset
  623. this.text = state.text
  624. return true
  625. },
  626. reset_(reset) {
  627. this.reset += reset
  628. return true
  629. },
  630. replace(what, from, to, reset) {
  631. var vars = [], hooks = []
  632. what.split(" ").forEach((x) => {
  633. x = x.split(":")
  634. x[0] === "var" && vars.push(x[1])
  635. x[0] === "hook" && hooks.push(x[1])
  636. })
  637. function replaceShorthands(str) {
  638. function nope(letter, array, fun) {
  639. str = str
  640. .split(new RegExp('\\$' + letter + '([0-9]?)'))
  641. .map((v,n) => n%2 ? fun(array[v||0]) : v)
  642. .join("")
  643. }
  644. nope('v', vars, (name) => "window.agar." + name)
  645. nope('h', hooks, (name) => "window.agar.hooks." + name)
  646. nope('H', hooks, (name) =>
  647. "window.agar.hooks." + name + "&&" +
  648. "window.agar.hooks." + name)
  649. return str
  650. }
  651. var newText = this.text.replace(from, replaceShorthands(to))
  652. if(newText === this.text) {
  653. console.error("Expose: `" + what + "` replacement failed!")
  654. return false
  655. } else {
  656. this.text = newText
  657. if (reset)
  658. this.reset += replaceShorthands(reset) + ";"
  659. return true
  660. }
  661. },
  662. removeNewlines() {
  663. this.text = this.text.replace(/([,\/;])\n/mg, "$1")
  664. },
  665. get: function() {
  666. var cellProp = JSON.stringify(this.cellProp)
  667. return `window.agar={hooks:{},cellProp:${cellProp}};` +
  668. this.reset + this.text
  669. }
  670. }
  671.  
  672. if (scriptEmbedded) {
  673. mod.text = node.textContent
  674. rules.replace(mod)
  675. if (isFirefox) {
  676. document.head.removeChild(node)
  677. var script = document.createElement("script")
  678. script.textContent = mod.get()
  679. document.head.appendChild(script)
  680. } else {
  681. node.textContent = mod.get()
  682. }
  683. console.log("Expose: replacement done")
  684. } else {
  685. document.head.removeChild(node)
  686. var request = new XMLHttpRequest()
  687. request.onload = function() {
  688. var script = document.createElement("script")
  689. mod.text = this.responseText
  690. rules.replace(mod)
  691. script.textContent = mod.get()
  692. // `main_out.js` should not executed before jQuery was loaded, so we need to wait jQuery
  693. function insertScript(script) {
  694. if (typeof jQuery === "undefined")
  695. return setTimeout(insertScript, 0, script)
  696. document.head.appendChild(script)
  697. console.log("Expose: replacement done")
  698. }
  699. insertScript(script)
  700. }
  701. request.onerror = function() { console.error("Expose: response was null") }
  702. request.open("get", node.src, true)
  703. request.send()
  704. }
  705.  
  706. return true
  707. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement