Advertisement
DJOHMSR

SP ClanBots By:DJOHMSR

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