Agario Mod V1

A agario mod v1

  1. // ==UserScript==
  2. // @name Agario Mod V1
  3. // @namespace http://agar.io/
  4. // @version V1
  5. // @description A agario mod v1
  6. // @author Odyis
  7. // @match http://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var ourskins = "Odyis;0chan;18-25;1up;8ball;UmguwJ0;ace;agariomods.com;al sahim;alaska;albania;algeria;anarchy;android;anonymous;aperture;apple;atari;avatar;awesome;awwmuffin;baka;bandaid;bane;baseball;basketball;batman;beats;belarus;belgium;bender;bert;bielarus;bitcoin;black widow;blobfish;bluh;bobross;bobsaget;boo;boogie2988;borg;bp;breakfast;breizh;buckballs;burgundy;butters;byzantium;c;catalonia;catalunya;catman;chaika;charmander;chechenya;checkpointplus;cheese;chickfila;chocolate;chrome;chucknorris;cirno;cj;cling on;coca cola;cokacola;colombia;colombiaa;controless;converse;cookie;coookie;cornella;cornellà;coruja;creeper;creepydoll;csfb;cuba;cyprus;czech;czechia;czechrepublic;darksideofmoon;deadpool;deal with it;deathly hallows;deathstar;demon;derp;desu;dhole;dickbutt;doge;doggie;dolan;domo;domokun;dong;donut;doraemon;dreamcast;drunken;ebin;egg;egoraptor;egypt;eksi;electrokitty;epicface;expand;eye;facebook;fast forward;fastforward;fbi;fidel;fiji;finn;firefox;fishies;flash;florida;fnatic;fnaticc;foe;forocoches;freeman;freemason;friesland;frogout;fuckfacebook;gaben;gabenn;garfield;gaston;generikb;getinmybelly;getinthebox;gimper;github;giygas;gnomechild;gonzo;grammar nazi;grayhat;grima;grumpy;hagrid;halflife;halflife3;halo;handicapped;hap;hatty;hawaii;hawkeye;hebrew;heisenburg;helix;hipsterwhale;hispachan;hitler;homestuck;honeycomb;hosokawa;hue;hydro;iceland;ie;illuminati;illuminatiii;imaqtpie;imgur;imperial japan;imperialists;imperialjapan;instagram;iron man;isaac;isis;isreal;itchyfeetleech;ivysaur;jahrein;james bond;java;jew;jewnose;jimmies;jupiter;kalmar union;kame;kappa;kenny;kingdomoffrance;kingjoffrey;kirby;kitty;klingon;knights templar;knightstemplar;knowyourmeme;kurdistan;kyle;ladle;le snake;lenny;lgbt;liberland;libertyy;liechtenstien;linux;llessur;loadingreadyrun;loki;love;luigi;macedonia;malta;mario;mars;maryland;masterball;mastercheif;mcdonalds;meatboy;meatwad;megamilk;mike tyson;mike;mlg;moldova;mortalkombat;mr burns;mr.bean;mr.popo;n64;naga;nasa;nauru;nazi;nick fury;nick;nickelodeon;nipple;northbrabant;northernlion;nosmoking;notch;nsa;obama;obey;osu;ouch;palau;pandaexpress;pedo;pedobear;peka;penguin;pepe;pepsi;pewdiepie;pi;pig;piggy;pika;pinkfloyd;pinkstylist;pirate;piratebay;pizza;pizzaa;playstation;poop;potato;pt;quantum leap;question;rageface;retard smile;rewind;rockstar;rolfharris;roomba;rss;ryukyu;s.h.e.i.l.d;samoa;satan;scream;seal;serbia;sharingan;shell;shine;shrek;sinistar;sir;skull;skype;skyrim;slack;slovakia;slovenia;slowpoke;smash;snafu;snapchat;soccer;soliare;solomid;somalia;space ace;space;spawn;spiderman;spongegar;spore;spqr;spy;squirtle;stalinjr;star wars rebel;starbucks;starchild;starrynight;stitch;stupid;summit1g;sunface;superman;taco;teamfortress;thor;tintin;tonga;transformer;transformers;triforce;trollface;tubbymcfatfuck;turkey;tv;twitch;twitter;uguu;ukip;uppercase;uruguay;utorrent;vatican;vietnam;virus;voat;voyager;wakawaka;wales;walrus;wazowski;wewlad;white light;windows;wit my woes;wwf;wykop;xsk;ycm;yinyang;ylilauta;ylilautaa;yoba;yobaa;yobaaa;yourmom;youtube;zeon;zimbabwe;zoella;zoidberg";
  12.  
  13. var showsh = false;
  14. var showt = localStorage.getItem("showt")=="true";
  15.  
  16. var ldown = false;
  17.  
  18. var showfps = false;
  19. var showpio = false; //packets in/out per second
  20.  
  21.  
  22. if(showt===null){localStorage.setItem("showt","true");showt=true;}
  23.  
  24. setInterval(function(){if(showsh)DrawStats(false);if(showt)count();},300);
  25.  
  26. var gamejs = "", modBlocking = true;
  27. var tester = document.getElementsByTagName("script");
  28. var i = 0, main_out_url = document.location.protocol+"//agar.io/main_out.js", discovered_mainouturl = 0;
  29. var W = '';
  30. var Ja = '';
  31. var b = '';
  32. var c3eg2 = '';
  33. var in_game = false;
  34. var pandb = '';
  35. /*bgm*/
  36. var bgmusic = '';
  37. $('#audiotemplate').clone()[0];
  38. var tracks = ['BotB 17936 Isolation Tank.mp3','BotB 17934 bubblybubblebubblingbubbles.mp3','BotB 17935 bloblobloblboblbolboblboblbobolbloblob.mp3','BotB 17937 Woofytunes.mp3','BotB 17938 slowgrow.mp3'];
  39. /*sfx*/
  40. //sfx play on event (only one of each sfx can play - for sfx that won't overlap with itself)
  41. var ssfxlist = [
  42. 'spawn',
  43. 'gameover'
  44. ];
  45. var ssfxs = [];
  46. for (i=0;i<ssfxlist.length;i++) {
  47. var newsfx = new Audio("//skins.agariomods.com/botb/sfx/" + ssfxlist[i] + ".mp3");
  48. newsfx.loop = false;
  49. ssfxs.push(newsfx);
  50. }
  51. function sfx_play(id) {
  52. if (document.getElementById("sfx").value==0) return;
  53. var event = ssfxs[id];
  54. event.volume = document.getElementById("sfx").value;
  55. event.play();
  56. }
  57.  
  58. //sfx insertion on event (multiple of same sfx can be played simultaneously)
  59. var sfxlist = [
  60. 'pellet',
  61. 'split',
  62. 'eat',
  63. 'bounce',
  64. 'merge',
  65. 'virusfeed',
  66. 'virusshoot',
  67. 'virushit'
  68. ];
  69. var sfxs = [];
  70. for (i=0;i<sfxlist.length;i++) {
  71. var newsfx = new Audio("//skins.agariomods.com/botb/sfx/" + sfxlist[i] + ".mp3");
  72. newsfx.loop = false;
  73. newsfx.onended = function() {
  74. $(this).remove();
  75. }
  76. sfxs.push(newsfx);
  77. }
  78. function sfx_event(id) {
  79. if (document.getElementById("sfx").value==0) return;
  80. var event = jQuery.clone(sfxs[id]);
  81. event.volume = document.getElementById("sfx").value;
  82. event.load();
  83. event.play();
  84. }
  85. /* lets start to deal with regressions */
  86. var test = 0;
  87. var passed = 0;
  88. var failed = 0;
  89.  
  90. var chart_update_interval = 10;
  91. var chart = null;
  92. var chart_data = [];
  93. var chart_counter = 0;
  94. var chart_s = '';
  95. var chart_m = '';
  96. var chart_G = '';
  97. var chart_Na= '';
  98. var chart_k = '';
  99.  
  100. for (i=0; i<tester.length; i++ ){
  101. src = tester[i].src;
  102. if (src.substring(0, main_out_url.length ) == main_out_url) {
  103. discovered_mainouturl = src.replace("//agar.io/","");
  104. }
  105. }
  106.  
  107. if(discovered_mainouturl != 0) {
  108. httpGet(discovered_mainouturl, function(data) {
  109. gamejs = "window.agariomods = " + data.replace("socket open","socket open (agariomods.com mod in place)");
  110. gamejs = gamejs.replace(/\n/g, "");
  111. offset = gamejs.search("..=\"poland;");
  112. Ja = gamejs.substr(offset,2);
  113. offset = gamejs.search(".....src=\"skins");
  114. b = gamejs.substr(offset+2,1);
  115. offset = gamejs.search(".."+b+"..src");
  116. W = gamejs.substr(offset,1);
  117. //this.P&&b.strokeText
  118. var components = /this.(.)&&b.strokeText/.exec(gamejs);
  119. pandb = components[1];
  120. var components = /strokeText\((.{1,14})\);/.exec(gamejs);
  121. c3eg2 = components[1];
  122. var components = /\((.)\=..x,.\=..y\)/.exec(gamejs);
  123. chart_s = components[1];
  124. var components = /\(.\=(.).x,.\=..y\)/.exec(gamejs);
  125. chart_m = components[1];
  126. var components = /(.)\=Math.max\(.,..\(\)\);/.exec(gamejs);
  127. chart_G = components[1];
  128. var components = /.\=Math.max\(.,(..)\(\)\);/.exec(gamejs);
  129. chart_Na = components[1];
  130. var components = /(.)\[0\]\.name\&\&\(/.exec(gamejs);
  131. chart_k = components[1];
  132. //console.log ("chartmod info: chart_m = "+chart_m+"; chart_s = "+chart_s+"; chart_G = "+chart_G+"; chart_Na = "+chart_Na+"; chart_k = "+chart_k);
  133. agariomodsRuntimeInjection();
  134. });
  135. }
  136.  
  137. // XMLHttp, because apparently raven is doing funky stuff with jQuery
  138. function httpGet(theUrl, callback) {
  139. var xmlHttp = new XMLHttpRequest();
  140. xmlHttp.open("GET", theUrl, true);
  141. xmlHttp.send(null);
  142. xmlHttp.onreadystatechange = function() {
  143. if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
  144. callback(xmlHttp.responseText);
  145. }
  146. };
  147. }
  148. function agariomodsRuntimeInjection() {
  149. var script = document.createElement("script");
  150. script.src='//cdnjs.cloudflare.com/ajax/libs/canvasjs/1.4.1/canvas.min.js';
  151. document.head.appendChild(script);
  152. var tester = document.getElementsByTagName("head");
  153. var oldhtml = tester[0].innerHTML;
  154. oldhtml = oldhtml.replace('width:350px;', '');
  155. oldhtml = oldhtml.replace('-webkit-transform:translate(-50%,-50%);', '');
  156. oldhtml = oldhtml.replace('-ms-transform:translate(-50%,-50%);', '');
  157. oldhtml = oldhtml.replace('transform:translate(-50%,-50%);', '');
  158. oldhtml = oldhtml.replace('top:50%;left:50%;','margin:10px;');
  159. tester[0].innerHTML = oldhtml;
  160. var script = document.createElement("script");
  161. agariomodsRuntimePatches();
  162. script.innerHTML = gamejs;
  163. document.head.appendChild(script);
  164. agariomodsRuntimeHacks();
  165. bgmusic = $('#audiotemplate').clone()[0];
  166. bgmusic.src = "//skins.agariomods.com/botb/" + tracks[Math.floor(Math.random() * tracks.length)];
  167. bgmusic.load();
  168. bgmusic.loop = false;
  169. bgmusic.onended = function() {
  170. var track = tracks[Math.floor(Math.random() * tracks.length)];
  171. bgmusic.src = "//skins.agariomods.com/botb/" + track;
  172. bgmusic.play();
  173. }
  174. window.onbeforeunload = function() {
  175. return 'Are you sure you want to quit agar.io?';
  176. };
  177. // as a trackpad user, this fix should reduce the frequency at which I am killed.
  178. $("#canvas").on('mousedown', function(event){
  179. event.preventDefault();
  180. });
  181. $("#chart-container").css("pointerEvents", "none");
  182. $("#chart-container-agariomods").css("pointerEvents", "none");
  183. $("#fps-agariomods").css("pointerEvents", "none");
  184. $("#pi-agariomods").css("pointerEvents", "none");
  185.  
  186. }
  187. function agariomodsRuntimePatches() {
  188. gamejs_patch(")&&this",")&&(this","test");
  189. gamejs_patch(/\w>\w\/1\.1\?.*-50%\)"\);/,"","fixing menu on resize");
  190. gamejs_patch(';reddit;', ';reddit;'+ourskins+';', "add our skinlist to the original game skinlist.");
  191. gamejs_patch(b+'=this.name.toLowerCase();', b+'=this.name.toLowerCase();var agariomods="";var ourskins = "'+ourskins+'";if(('+b+'.length >0) && (ourskins.split(";").indexOf('+b+')>-1)) {agariomods="//skins.agariomods.com/i/"+'+b+'+".png";} else if ('+b+'.substring(0, 2) == "i/" && document.getElementById("imgur").checked) {agariomods="//i.imgur.com/"+this.name.substring(2)+".jpg";} else if (document.getElementById("imgur").checked) {agariomods="//agar.io/skins/" + this.name.toLowerCase() + ".png";}', "add check for which skin mode we are in. be it no skin, default skin, imgur skin, or an agariomods skin.");
  192. gamejs_patch('xa=!1', 'zz=!1,yq=!1,xx=!1,xz=!1,xa=!1', "adding variables");
  193. gamejs_patch(W +'['+b+'].src="skins/"+'+b+'+".png"', W+'['+b+'].src=agariomods', "check for agariomods img src variable");
  194. gamejs_patch("this."+pandb+"&&b.strokeText("+c3eg2+");b.fillText("+c3eg2+")", "if (String(c).substring(0, 2) != \"i/\") {this."+pandb+"&&b.strokeText("+c3eg2+");b.fillText("+c3eg2+")}", "add imgur check for hiding username when using imgur id aka c3eg2");
  195. gamejs_patch(b+"=this.name.toLowerCase();", b+"=this.name.toLowerCase(); if ("+b+".substring(0, 2) == \"i/\") {" +Ja+ "+="+b+";} ;", "add imgur check #2.");
  196. gamejs = addChartHooks(gamejs);
  197. gamejs = addOnCellEatenHook(gamejs);
  198. gamejs = addTeamMassHook(gamejs);
  199. gamejs = addCanvasBGHook(gamejs);
  200. gamejs = addVirusColorHook(gamejs);
  201. gamejs = addFunctions(gamejs);
  202. gamejs = addOnShowOverlayHook(gamejs);
  203. gamejs = addOnHideOverlayHook(gamejs); //Because I don't want to detect when we hide it, only when the game does.
  204. gamejs = addLeaderboardHook(gamejs);
  205. gamejs = addConnectHook(gamejs);
  206. gamejs = addRecieveHook(gamejs);
  207. gamejs = addOnSendHook(gamejs);
  208. gamejs = addOnDrawHook(gamejs);
  209. //gamejs = gamejs.replace(/;/g, '\n');
  210. console.log("Testing complete, "+passed+" units passed and "+failed+" units failed.");
  211. if (failed) console.log(new Error("UNIT FAILED"));
  212. }
  213. function gamejs_patch(search, replace, purpose) {
  214. gamejs = gamejs.replace(search,replace);
  215. testCondition((-1 != gamejs.indexOf(replace)), test++, purpose);
  216. }
  217. function testCondition (condition, id, comment) {
  218. if(condition) {
  219. console.log("test: #"+id+" PASSED - "+ comment);
  220. passed++;
  221. } else {
  222. console.error("test: #"+id+" FAILED - "+ comment);
  223. failed++;
  224. }
  225. }
  226.  
  227.  
  228. function agariomodsRuntimeHacks() {
  229. jQuery('#helloDialog').css({left: '5px'});
  230. jQuery('#helloDialog').css({top: '5px'});
  231. jQuery('#helloDialog').css({margin: '0px'});
  232. jQuery('#helloDialog').css({marginLeft: 'auto'});
  233. jQuery('#helloDialog').css({marginRight: 'auto'});
  234. // opacity: 0.5;
  235. //
  236.  
  237. jQuery('#helloDialog').css({opacity: '0.85'});
  238. jQuery('#helloDialog').css({width: '450px'});
  239. document.body.style.backgroundSize = 'cover';
  240. document.body.style.backgroundRepeat = 'no-repeat';
  241. document.body.style.backgroundAttachment = "fixed";
  242. var nodeDiv = document.createElement("div");
  243. $( document ).ready(function() {
  244. hd = document.getElementById("helloDialog");
  245. cachedhd = hd.innerHTML;
  246. hd.innerHTML = cachedhd.replace("<center>Agar.io</center>", "<a target=\"_blank\" style=\"position:absolute; padding-left:435px;top:-10px; z-index: -1; height:120px;\" href=\"https://www.reddit.com/r/Agario/\"><img src=\"//i.imgur.com/TkTWOrc.png\" height=\"120px\"/></a>");
  247. });
  248. document.getElementById("nick").placeholder = "agariomods.com";
  249. nodeDiv.id = "includedContent";
  250. nodeDiv.style.width = "400px"
  251. nodeDiv.style.backgroundColor = "#000000";
  252. nodeDiv.style.zIndex = 999;
  253. nodeDiv.style.position = "relative";
  254. nodeDiv.style.padding = "8px";
  255. nodeDiv.style.borderRadius = "5px";
  256. nodeDiv.style.color = "#dddddd";
  257. nodeDiv.style.margin = "10px";
  258. nodeDiv.style.marginTop = "0";
  259. nodeDiv.style.maxHeight = "250px"; //The settings and the ad are being pushed down too far on some screens (1366*768). ~Mevin1
  260. nodeDiv.style.overflow = "auto"; //add scroll bar
  261. nodeDiv.innerHTML += '1.9.5: Go catch up with the <a target="_blank" href="http://agariomods.com/documentation.html">Documentation</a><br><h4><a href="http://www.agariomods.com/help.html" target="_blank"><font color="pink">CLICK HERE FOR HELP</font></a></h4>\
  262. <div style="background-color: #ffffff; color: #000000; padding: 2px; margin: 0px;">\
  263. <small><b>Disable ad blockers</b>&nbsp;- They are breaking the game and our modifications in random and unexpected ways.</small>\
  264. </div>';
  265. jQuery('#region').parent().get(0).appendChild(nodeDiv);
  266. jQuery(".form-group:first").replaceWith('<br>');
  267. var selector = jQuery('#region');
  268. var playBtn = jQuery('#playBtn');
  269. var nodeInput = document.createElement("span");
  270. var nodeSpan = document.createElement("span");
  271. var nodeBr = document.createElement("br");
  272. var nodeLinks = document.createElement("div");
  273. nodeLinks.innerHTML = "<big><a href='http://skins.agariomods.com' target='_blank'>SKINS</a> - <a href='http://agariomods.com/chat.html' target='_blank'>CHAT</a> - <a href='http://agariomods.com' target='_blank'>WEBSITE</a> - <a href='http://agariomods.com/help.html' target='_blank'>HELP</a> - <a href onclick=\"alert('---HOTKEYS---\\nHold Z - Show Stats In-Game\\nSuicide - Alt+Q\\nToggle Benchmarker - T\\nClear Benchmarks - Alt+T\\nFPS Counter - Alt+1\\nPackets In/Out Per Second - Alt+2\\nTry Script Lag Recover - Alt+R');return false;\" target='_blank'>HOTKEYS</a></big>";
  274. nodeLinks.style.marginLeft='10px';
  275. nodeSpan.className = "glyphicon glyphicon-refresh btn btn-info";
  276. nodeSpan.style.fontSize = "1.5em";
  277. nodeSpan.style.cssFloat = "left";
  278. nodeSpan.style.paddingTop = "2px";
  279. nodeSpan.style.width = "15%";
  280. nodeSpan.style.height = "33px";
  281. nodeSpan.addEventListener("click", function (e) {
  282. document.getElementById("iphack").value=document.getElementById("iphack").value.replace(/\s+/g, '');
  283. var ip = document.getElementById("iphack").value.replace("ws://","");
  284. if(ip.length>8)connect("ws://"+ip);
  285. });
  286. // nodeInput.className = "form-control";
  287. nodeInput.id = "iphack"
  288. nodeInput.style.width = "85%";
  289. nodeInput.style.cssFloat = "left";
  290. nodeInput.style.cssClear = "right";
  291. nodeInput.style.padding = "5px;";
  292. nodeInput.style.margin = "5px;";
  293. nodeInput.style.border = "2px solid green";
  294. nodeInput.innerHTML = "Zeach, the owner of Agar.io has told us to remove this particular feature, he has banned the ability to connect to a server directly by it's IP which breaks all mods. ";
  295. jQuery('#locationUnknown').prepend(nodeLinks);
  296. jQuery(playBtn).parent().get(0).appendChild(nodeInput);
  297. jQuery(playBtn).parent().get(0).appendChild(nodeSpan);
  298. jQuery(playBtn).parent().get(0).appendChild(nodeBr);
  299. jQuery(playBtn).parent().prepend("<b>Current Server IP: </b><span id='ip'></span>");
  300. var nodeAudio = document.createElement("audio");
  301. nodeAudio.id = 'audiotemplate';
  302. jQuery(playBtn).parent().get(0).appendChild(nodeAudio);
  303. jQuery('#playBtn').off();
  304. $('.btn-needs-server').prop('disabled', true);
  305. jQuery('#playBtn').click(function() {
  306. setNick(document.getElementById('nick').value);
  307. return false;
  308. });
  309. jQuery('.form-group:first').after( "<hr style='margin: 7px; border-width: 2px'>" );
  310. jQuery('.form-group:first').removeAttr("class");
  311. }
  312.  
  313.  
  314.  
  315.  
  316. /* begin mikeys new code */
  317. var chart_update_interval = 10;
  318.  
  319. var chart = null;
  320. var chart_data = [];
  321. var chart_counter = 0;
  322. var stat_canvas = null;
  323.  
  324. var stats = null;
  325. var my_cells = null;
  326. var my_color = "#ff8888";
  327. var pie = null;
  328. var stats_chart;
  329.  
  330. var display_chart = LS_getValue('display_chart', 'true') === 'true';
  331. var display_stats = LS_getValue('display_stats', 'false') === 'true';
  332.  
  333. /////////////////////////////////////////////////////////
  334.  
  335. var g_stat_spacing = 0;
  336. var g_display_width = 220;
  337. var g_layout_width = g_display_width;
  338.  
  339. ////////////////////////////////////////////////////////////////
  340. function addChartHooks(script) {
  341. var match = script.match(/max\((\w+),(\w+)\(/);
  342. var high = match[1];
  343. var current = match[2];
  344. match = script.match(/1==(\w+)\.length&&\(/);
  345. var my_cells = match[1];
  346. var split = script.split(match[0]);
  347. script = split[0] + '1=='+my_cells+'.length&&(OnGameStart('+my_cells+'),' + split[1];
  348. split = script.split(script.match(/"Score: "\+~~\(\w+\/100\)/)[0]);
  349. match = split[1].match(/-(\d+)\)\);/);
  350. var subSplit = split[1].split(match[0]);
  351. split[1] = subSplit[0] + '-'+match[1]+'),('+my_cells+'&&'+my_cells+'[0]&&OnUpdateMass('+current+'())));' + subSplit[1];
  352. return split[0] + '"Current: "+~~('+current+'()/100)+" High: "+~~('+high+'/100)' + split[1];
  353. }
  354.  
  355. function addTeamMassHook(script) {
  356. var match = script.match(/1==(\w+)\.length&&\(/);
  357. var my_cells = match[1];
  358. var match = script.match(/;(\w+)\.(\w+)\(this\.name\)/);
  359. var split = script.split(match[0]);
  360. var avar = match[2];
  361. script = split[0]+";"+match[1]+'.'+match[2]+'(this.name);if(yq){if(p[0]&&N==":teams"&&'+my_cells+'.indexOf(this)==-1){if(this.color.substr(p[0].color.search("ff"),2)=="ff"){this.k.'+match[2]+'(this.name+" ["+~~(this.size*this.size/100)+"]");}}}'+split[1];
  362. var match = script.match(/indexOf\((\w+)\)\)\)\{/);
  363. var split = script.split(match[0]);
  364. return split[0]+'indexOf('+match[1]+')))||(this.size>=32&'+my_cells+'[0]&&N==":teams"&&!this.d)){if(yq){if(this.name==""){this.k=new ka(this.h(),"#FFFFFF",true,"#000000");this.k.'+avar+'(this.name);}};'+split[1];
  365. var split = script.split(match[0]);
  366. }
  367.  
  368.  
  369. function addFunctions(script) {
  370. var match = script.match(/((\w)\.setAcid)/);
  371. var split = script.split(match[0]);
  372. script = split[0]+match[2]+'.Suicide=function(){var b=new ArrayBuffer(1);(new DataView(b)).setUint8(0, 20);q.send(b)};'+match[2]+'.setVColors=function(a){zz=a};'+match[2]+'.setTeamMass=function(a){yq=a;if(a){jQuery(\'#names\').attr(\'checked\',false);check(document.getElementById(\'names\'));}};'+match[2]+'.setBG=function(a){xx=a;if(a){var url=localStorage.getItem("bgurl");if(url==null){url=""};var promp=prompt("Image URL",url);if(null==promp){jQuery("#bgimg").attr("checked",false);check(document.getElementById("bgimg"));xx=!a;return;}localStorage.setItem("bgurl",promp);jQuery("#acid").attr("checked",false);check(document.getElementById("acid"));document.body.style.backgroundImage=\'url("\'+promp+\'")\';xz=confirm("Show Grid Lines?");}};'+match[1]+split[1]
  373. var split = script.split("setNames=function(a){");
  374. return split[0]+"setNames=function(a){if(!a){jQuery(\'#tmass\').attr(\'checked\',false);check(document.getElementById(\'tmass\'));}"+split[1];
  375. }
  376.  
  377. function addCanvasBGHook(script) {
  378. var match = script.match(/rRect\(0,0,(\w),(\w)\)/);
  379. var split = script.split(match[0]);
  380. script = split[0]+'rRect(0,0,'+match[1]+','+match[2]+');xx&&!xz?g.clearRect(0, 0, r, s):'+split[1].substr(1);
  381. var match = script.match(/BFF";/);
  382. var split = script.split(match[0]);
  383. return split[0]+'BFF";xx&&xz?g.clearRect(0,0,r,s):'+split[1];
  384. }
  385.  
  386. function addVirusColorHook(script) {
  387. var match = script.match(/(\?\(\w\.fillStyle=")/);
  388. var split = script.split(match[0]);
  389. return split[0]+'||zz&&this.d'+match[1]+split[1]
  390. }
  391.  
  392. function addLeaderboardHook(script) {
  393. var match = script.match(/(fillStyle="#FFAAAA")(.+)(\w+)(\+1\+"\. ")/);
  394. var split = script.split(match[0]);
  395. return split[0]+match[1]+',OnLeaderboard('+match[3]+'+1)'+match[2]+match[3]+match[4]+split[1]
  396. }
  397.  
  398. function addOnCellEatenHook(script) {
  399. // null!=p&&p.T();
  400. // l&&k&&(k.S()
  401. // var match = script.match(/(\w+)&&(\w+)&&\((\w+)\.S/);
  402. var match = script.match(/(\w+)&&(\w+)&&\((\w+)\.(\w+)/);
  403. var split = script.split(match[0]);
  404. return split[0] + match[1] + '&&' + match[2] + '&&(OnCellEaten('+match[1]+','+match[2]+'),' + match[3] + '.' + match[4] + split[1];
  405. }
  406.  
  407. function addOnShowOverlayHook(script) {
  408. var match = script.match(/\w+\("#overlays"\)\.fadeIn\((\w+)\?\w+:\w+\);/);
  409. var split = script.split(match[0]);
  410. return split[0] + match[0] + 'OnShowOverlay(' + match[1] + ');' + split[1];
  411. }
  412.  
  413. function addConnectHook(script) {
  414. var match = script.match(/console\.log\("Connecting to "\+a\);/);
  415. var split = script.split(match[0]);
  416. return split[0] + match[0] + 'document.getElementById("ip").innerHTML=a.replace(/wss?:\\/\\//,"");' + split[1];
  417. }
  418.  
  419. function addRecieveHook(script) {
  420. // Za(new DataView(a.data))
  421. var match = script.match(/\w\(new DataView\(..data\)\)/);
  422.  
  423. var split = script.split(match[0]);
  424. return split[0] + match[0] + ';Recieve();' + split[1];
  425. }
  426.  
  427. function addOnSendHook(script) {
  428. var match = script.match(/\w+\.send\(\w+\.buffer\)/);
  429. var split = script.split(match[0]);
  430. return split[0] + match[0] + ';OnSend();' + split[1];
  431. }
  432.  
  433. function addOnHideOverlayHook(script) {
  434. var match = script.match(/\w+\("#overlays"\)\.hide\(\)/);
  435. var split = script.split(match[0]);
  436. return split[0] + match[0] + ';OnHideOverlay()' + split[1];
  437. }
  438.  
  439. function addOnDrawHook(script) {
  440. var match = script.match(/\w+\.width&&(\w+)\.drawImage\(\w+,\w+-\w+\.width-10,10\);/);
  441. var split = script.split(match[0]);
  442. return split[0] + match[0] + 'OnDraw(' + match[1] + ');' + split[1];
  443. }
  444.  
  445. var __STORAGE_PREFIX = "mikeyk730__";
  446.  
  447. function LS_getValue(aKey, aDefault) {
  448. var val = localStorage.getItem(__STORAGE_PREFIX + aKey);
  449. if (null === val && 'undefined' != typeof aDefault) return aDefault;
  450. return val;
  451. }
  452. function LS_setValue(aKey, aVal) {
  453. localStorage.setItem(__STORAGE_PREFIX + aKey, aVal);
  454. }
  455.  
  456. function GetRgba(hex_color, opacity)
  457. {
  458. var patt = /^#([\da-fA-F]{2})([\da-fA-F]{2})([\da-fA-F]{2})$/;
  459. var matches = patt.exec(hex_color);
  460. return "rgba("+parseInt(matches[1], 16)+","+parseInt(matches[2], 16)+","+parseInt(matches[3], 16)+","+opacity+")";
  461. }
  462.  
  463. function secondsToHms(d)
  464. {
  465. d = Number(d);
  466. var h = Math.floor(d / 3600);
  467. var m = Math.floor(d % 3600 / 60);
  468. var s = Math.floor(d % 3600 % 60);
  469. return ((h > 0 ? h + ":" + (m < 10 ? "0" : "") : "") + m + ":" + (s < 10 ? "0" : "") + s);
  470. }
  471. ////////////////////////////////////////////////////////////////
  472. jQuery(document).ready(function()
  473. {
  474. jQuery('body').append('<div id="chart-container" style="display:none; position:absolute; height:176px; width:300px; left:10px; bottom:44px"></div>\
  475. <div id="chart-container-agariomods" style="opacity: 0.7; position:absolute; height:20px; width:300px; right:10px; bottom:10px;">&nbsp;agariomods.com - modding <b>without</b> cheating</div>\
  476. <div id="debug" style="position:absolute; top:5px; left:10px;">\
  477. <div id="fps-agariomods" style="color: white; display: none; background-color: rgba(0,0,0,.5); padding:0 4px;"><b>FPS: </b><span>0</span></div>\
  478. <div id="pio-agariomods" style="color: white; display: none; background-color: rgba(0,0,0,.5); padding:0 4px;"><b>PI/O/s: </b><span>0</span>/<span>0</span></div>\
  479. </div>\
  480. <img src="http://kelvin.gq/agariomods?'+Date.now()+'" style="display:none;">');
  481. jQuery('#instructions').remove();
  482. //jQuery('.glyphicon-cog').addClass("glyphicon-refresh")
  483. //jQuery('.glyphicon-cog').removeClass("glyphicon-cog");
  484. //jQuery('.btn-settings').attr('onclick','connect("ws://"+document.getElementById("ip").innerHTML);if(in_game)OnShowOverlay(false);');
  485. //jQuery('.btn-settings').attr('type','button');
  486. //jQuery('#gamemode').removeAttr('required');
  487. //jQuery('.btn-settings').removeClass("btn-settings");
  488. jQuery('.btn-settings').hide();
  489. jQuery('#settings').show();
  490. var checkbox_div = jQuery('#settings input[type=checkbox]').closest('div');
  491. checkbox_div.append('<label><input type="checkbox" id="acid" onchange="setAcid($(this).is(\':checked\'));if($(this).is(\':checked\')){$(\'#bgimg\').attr(\'checked\',false);check(document.getElementById(\'bgimg\'));}">Acid</label>');
  492. checkbox_div.append('<label><input type="checkbox" onchange="if(this.checked){jQuery(\'#chart-container\').show()}else{jQuery(\'#chart-container\').hide()}">Show chart</label>');
  493. checkbox_div.append('<label><input type="checkbox" onchange="setVColors($(this).is(\':checked\'));">Colorless Viruses</label>');
  494. checkbox_div.append('<label><input id="imgur" type="checkbox">Imgur Skins</label>');
  495. checkbox_div.append('<label><input type="checkbox" id="tmass" onchange="setTeamMass($(this).is(\':checked\'));">Show Teamed Mass</label>');
  496. checkbox_div.append('<label><input id="bgimg" type="checkbox" onchange="setBG($(this).is(\':checked\'));">Set Background</label>');
  497. checkbox_div.append('<div id="sliders"><label>SFX<input id="sfx" type="range" value="0" step=".1" min="0" max="1"></label><label>BGM<input type="range" id="bgm" value="0" step=".1" min="0" max="1" oninput="volBGM(this.value);"></label></div>'); jQuery('#overlays').append('<div id="stats" style="opacity: 0.85; position: absolute; top:330px; left: 460px; width: 480px; display: none; background-color: #FFFFFF; border-radius: 15px; padding: 5px 15px 5px 15px; transform: translate(0,-50%); white-space: nowrap; overflow:hidden;"><div id="statArea" style="vertical-align:top; width:250px; display:inline-block;"></div><div id="pieArea" style="vertical-align: top; width:200px; height:150px; display:inline-block; vertical-align:top"> </div><div id="gainArea" style="width:500px; vertical-align:top"></div><div id="lossArea" style="width:500px; "></div><div id="chartArea" style="width:450px; display:inline-block; vertical-align:top"></div></div>');
  498. jQuery('#stats').hide(0);
  499. jQuery('#playBtn').width('74%');
  500. });
  501.  
  502. function ResetChart()
  503. {
  504. chart = null;
  505. chart_data.length = 0;
  506. chart_counter = 0;
  507. jQuery('#chart-container').empty();
  508. }
  509.  
  510. function UpdateChartData(mass)
  511. {
  512. chart_counter++;
  513. if (chart_counter%chart_update_interval > 0)
  514. return false;
  515. chart_data.push({
  516. x: chart_counter,
  517. y: mass/100
  518. });
  519. return true;
  520. }
  521.  
  522. function CreateChart(e, color, interactive)
  523. {
  524. return new CanvasJS.Chart(e,{
  525. interactivityEnabled: interactive,
  526. title: null,
  527. axisX:{
  528. valueFormatString: " ",
  529. lineThickness: 0,
  530. tickLength: 0
  531. },
  532. axisY:{
  533. lineThickness: 0,
  534. tickLength: 0,
  535. gridThickness: 2,
  536. gridColor: "white",
  537. labelFontColor: "white"
  538. },
  539. backgroundColor: "rgba(0,0,0,0.2)",
  540. data: [{
  541. type: "area",
  542. color: color,
  543. dataPoints: chart_data
  544. }]
  545. });
  546. }
  547.  
  548. function UpdateChart(mass, color)
  549. {
  550. my_color = color;
  551. if (chart === null)
  552. chart = CreateChart("chart-container", color, false);
  553. if (UpdateChartData(mass) && display_chart)
  554. chart.render();
  555. jQuery('.canvasjs-chart-credit').hide();
  556. };
  557.  
  558. function ResetStats()
  559. {
  560. stats = {
  561. pellets: {num:0, mass:0},
  562. w: {num:0, mass:0},
  563. cells: {num:0, mass:0},
  564. viruses: {num:0, mass:0},
  565.  
  566. birthday: Date.now(),
  567. time_of_death: null,
  568. high_score: 0,
  569. top_slot: Number.POSITIVE_INFINITY,
  570.  
  571. gains: {},
  572. losses: {},
  573. };
  574. }
  575.  
  576. function OnGainMass(me, other)
  577. {
  578. var mass = other.size * other.size;
  579. if (other.d){
  580. stats.viruses.num++;
  581. if (document.getElementById("gamemode").value!=":teams") stats.viruses.mass += mass; /*DONE: shouldn't add if game mode is teams. TODO: Find a better way of doing this. ~Mevin1*/
  582. sfx_event(7);
  583. }
  584. else if (Math.floor(mass) <= 400 && !other.name){
  585. stats.pellets.num++;
  586. stats.pellets.mass += mass;
  587. sfx_event(0);
  588. }
  589. /* heuristic to determine if mass is 'w', not perfect */
  590. else if (!other.name && mass <= 1444 && (mass >= 1369 || (other.x == other.ox && other.y == other.oy))){
  591. /*console.log('w', mass, other.name, other);*/
  592. if (other.color != me.color){ /*don't count own ejections, again not perfect*/
  593. stats.w.num++;
  594. stats.w.mass += mass;
  595. }
  596. sfx_event(2);
  597. }
  598. else {
  599. /*console.log('cell', mass, other.name, other);*/
  600. var key = other.name + ':' + other.color;
  601. stats.cells.num++;
  602. stats.cells.mass += mass;
  603. if (stats.gains[key] == undefined)
  604. stats.gains[key] = {num: 0, mass: 0};
  605. stats.gains[key].num++;
  606. stats.gains[key].mass += mass;
  607. sfx_event(2);
  608. }
  609. }
  610.  
  611. function OnLoseMass(me, other)
  612. {
  613. var mass = me.size * me.size;
  614. var key = other.name + ':' + other.color;
  615. if (stats.losses[key] == undefined)
  616. stats.losses[key] = {num: 0, mass: 0};;
  617. stats.losses[key].num++;
  618. stats.losses[key].mass += mass;
  619. sfx_event(2);
  620. }
  621.  
  622. function DrawPie(pellet, w, cells, viruses)
  623. {
  624. var total = pellet + w + cells + viruses;
  625. pie = new CanvasJS.Chart("pieArea", {
  626. title: null,
  627. animationEnabled: false,
  628. legend:{
  629. verticalAlign: "center",
  630. horizontalAlign: "left",
  631. fontSize: 12,
  632. fontFamily: "Helvetica"
  633. },
  634. theme: "theme2",
  635. data: [{
  636. type: "pie",
  637. startAngle:-20,
  638. showInLegend: true,
  639. toolTipContent:"{legendText} {y}%",
  640. dataPoints: [
  641. { y: 100*pellet/total, legendText:"pellets"},
  642. { y: 100*cells/total, legendText:"cells"},
  643. { y: 100*w/total, legendText:"w"},
  644. { y: 100*viruses/total, legendText:"viruses"},
  645. ]
  646. }]
  647. });
  648. pie.render();
  649. }
  650.  
  651. function GetTopN(n, p)
  652. {
  653. var r = [];
  654. var a = Object.keys(stats[p]).sort(function(a, b) {return -(stats[p][a].mass - stats[p][b].mass)});
  655. for (var i = 0; i < n && i < a.length; ++i){
  656. var key = a[i];
  657. var mass = stats[p][key].mass;
  658. var name = key.slice(0,key.length-8);
  659. if (!name) name = "An unnamed cell";
  660. var color = key.slice(key.length-7);
  661. r.push({name:name, color:color, mass:Math.floor(mass/100)});
  662. }
  663. return r;
  664. }
  665.  
  666. function AppendTopN(n, p, list)
  667. {
  668. var a = GetTopN(n,p);
  669. for (var i = 0; i < a.length; ++i){
  670. var text = '<bdi>'+a[i].name + '</bdi> (' + (p == 'gains' ? '+' : '-') + a[i].mass + ' mass)';
  671. list.append('<li style="font-size: 12px; "><div style="width: 10px; height: 10px; border-radius: 50%; margin-right:5px; background-color: ' + a[i].color + '; display: inline-block;"></div>' + text + '</li>');
  672. }
  673. return a.length > 0;
  674. }
  675.  
  676. function DrawStats(game_over)
  677. {
  678. if (!game_over != in_game) return;
  679. jQuery('#statArea').empty();
  680. jQuery('#pieArea').empty();
  681. jQuery('#gainArea').empty();
  682. jQuery('#lossArea').empty();
  683. jQuery('#chartArea').empty();
  684. jQuery('#stats').show();
  685. if (game_over){
  686. sfx_play(1);
  687. StopBGM();
  688. }
  689. stats.time_of_death = Date.now();
  690. var time = stats.time_of_death ? stats.time_of_death : Date.now();
  691. var seconds = (time - stats.birthday)/1000;
  692. var list = jQuery('<ul>');
  693. list.append('<li style="font-size: 12px; ">Game time: ' + secondsToHms(seconds) + '</li>');
  694. list.append('<li style="font-size: 12px; ">High score: ' + ~~(stats.high_score/100) + '</li>');
  695. if (stats.top_slot == Number.POSITIVE_INFINITY){
  696. list.append('<li style="font-size: 12px; ">You didn\'t make the leaderboard</li>');
  697. }
  698. else{
  699. list.append('<li style="font-size: 12px; ">Leaderboard max: ' + stats.top_slot + '</li>');
  700. }
  701. list.append('<li style="font-size: 12px; padding-top: 15px">' + stats.pellets.num + " pellets eaten (" + ~~(stats.pellets.mass/100) + ' mass)</li>');
  702. list.append('<li style="font-size: 12px; ">' + stats.cells.num + " cells eaten (" + ~~(stats.cells.mass/100) + ' mass)</li>');
  703. list.append('<li style="font-size: 12px; ">' + stats.w.num + " masses eaten (" + ~~(stats.w.mass/100) + ' mass)</li>');
  704. list.append('<li style="font-size: 12px; ">' + stats.viruses.num + " viruses eaten (" + ~~(stats.viruses.mass/100) + ' mass)</li>');
  705. jQuery('#statArea').append('<b>Game Summary</b>');
  706. jQuery('#statArea').append(list);
  707. DrawPie(stats.pellets.mass, stats.w.mass, stats.cells.mass, stats.viruses.mass);
  708.  
  709. jQuery('#gainArea').append('<b>Top Gains</b>');
  710. list = jQuery('<ol>');
  711. if (AppendTopN(5, 'gains', list))
  712. jQuery('#gainArea').append(list);
  713. else
  714. jQuery('#gainArea').append('<ul><li style="font-size: 12px; ">You have not eaten anybody</li></ul>');
  715. jQuery('#lossArea').append('<b>Top Losses</b>');
  716. list = jQuery('<ol>');
  717. if (AppendTopN(5, 'losses', list))
  718. jQuery('#lossArea').append(list);
  719. else
  720. jQuery('#lossArea').append('<ul><li style="font-size: 12px; ">Nobody has eaten you</li></ul>');
  721. if (stats.time_of_death !== null){
  722. jQuery('#chartArea').width(450).height(150);
  723. stat_chart = CreateChart('chartArea', my_color, true);
  724. stat_chart.render();
  725. }
  726. else {
  727. jQuery('#chartArea').width(450).height(0);
  728. }
  729. jQuery('.canvasjs-chart-credit').hide();
  730. }
  731.  
  732. var styles = {
  733. heading: {font:"20px Ubuntu", spacing: 41, alpha: 1},
  734. subheading: {font:"18px Ubuntu", spacing: 31, alpha: 1},
  735. normal: {font:"12px Ubuntu", spacing: 21, alpha: 0.6}
  736. }
  737.  
  738. function AppendText(text, context, style)
  739. {
  740. context.globalAlpha = styles[style].alpha;
  741. context.font = styles[style].font;
  742. g_stat_spacing += styles[style].spacing;
  743. var width = context.measureText(text).width;
  744. g_layout_width = Math.max(g_layout_width, width);
  745. context.fillText(text, g_layout_width/2 - width/2, g_stat_spacing);
  746. }
  747.  
  748. function RenderStats(reset)
  749. {
  750. if (reset) g_layout_width = g_display_width;
  751. if (!display_stats || !stats) return;
  752. g_stat_spacing = 0;
  753. var gains = GetTopN(3, 'gains');
  754. var losses = GetTopN(3, 'losses');
  755. var height = 30 + styles['heading'].spacing + styles['subheading'].spacing * 2 + styles['normal'].spacing * (4 + gains.length + losses.length);
  756. stat_canvas = document.createElement("canvas");
  757. var scale = Math.min(g_display_width, .3 * window.innerWidth) / g_layout_width;
  758. stat_canvas.width = g_layout_width * scale;
  759. stat_canvas.height = height * scale;
  760. var context = stat_canvas.getContext("2d");
  761. context.scale(scale, scale);
  762. context.globalAlpha = .4;
  763. context.fillStyle = "#000000";
  764. context.fillRect(0, 0, g_layout_width, height);
  765. context.fillStyle = "#FFFFFF";
  766. AppendText("Stats", context, 'heading');
  767. var text = stats.pellets.num + " pellets eaten (" + ~~(stats.pellets.mass/100) + ")";
  768. AppendText(text, context,'normal');
  769. text = stats.w.num + " mass eaten (" + ~~(stats.w.mass/100) + ")";
  770. AppendText(text, context,'normal');
  771. text = stats.cells.num + " cells eaten (" + ~~(stats.cells.mass/100) + ")";
  772. AppendText(text, context,'normal');
  773. text = stats.viruses.num + " viruses eaten (" + ~~(stats.viruses.mass/100) + ")";
  774. AppendText(text, context,'normal');
  775. AppendText("Top Gains",context,'subheading');
  776. for (var j = 0; j < gains.length; ++j){
  777. text = (j+1) + ". " + gains[j].name + " (" + gains[j].mass + ")";
  778. context.fillStyle = gains[j].color;
  779. AppendText(text, context,'normal');
  780. }
  781. context.fillStyle = "#FFFFFF";
  782. AppendText("Top Losses",context,'subheading');
  783. for (var j = 0; j < losses.length; ++j){
  784. text = (j+1) + ". " + losses[j].name + " (" + losses[j].mass + ")";
  785. context.fillStyle = losses[j].color;
  786. AppendText(text, context,'normal');
  787. }
  788. }
  789.  
  790. jQuery(window).resize(function() {
  791. RenderStats(false);
  792. });
  793.  
  794. window.OnGameStart = function(cells)
  795. {
  796. initbench(false);
  797. in_game = true;
  798. my_cells = cells;
  799. ResetChart();
  800. ResetStats();
  801. RenderStats(true);
  802. DrawStats(false);
  803. if (kd == true) {
  804. showsh = false;
  805. document.getElementById("overlays").style.display = "none";
  806. document.getElementById("overlays").style.backgroundColor = "rgba(0,0,0,.498039)";
  807. document.getElementById("overlays").style.pointerEvents = "auto";
  808. document.getElementById("stats").style.opacity = 0.85;
  809. document.getElementById("helloDialog").style.display = "block";
  810. kd = false;
  811. }
  812. StartBGM();
  813. sfx_play(0);
  814. }
  815.  
  816. window.StartBGM = function ()
  817. {
  818. if (document.getElementById("bgm").value==0) return;
  819. if (bgmusic.src == "") bgmusic.src = "//skins.agariomods.com/botb/" + tracks[Math.floor(Math.random() * tracks.length)]; //i guess i'll leave this here ~mevin1
  820. bgmusic.volume = document.getElementById("bgm").value;
  821. bgmusic.play();
  822. }
  823.  
  824. window.StopBGM = function ()
  825. {
  826. if (document.getElementById("bgm").value==0) return;
  827. bgmusic.pause()
  828. bgmusic.src = "//skins.agariomods.com/botb/" + tracks[Math.floor(Math.random() * tracks.length)];
  829. bgmusic.load()
  830. }
  831.  
  832. window.volBGM = function (vol)
  833. {
  834. bgmusic.volume = document.getElementById("bgm").value;
  835. }
  836.  
  837. window.OnShowOverlay = function(game_in_progress)
  838. {
  839. bstyle(true);
  840. if (!game_in_progress) in_game = false;
  841. DrawStats(!game_in_progress);
  842. if (kd == true) {
  843. document.getElementById("overlays").style.display = "block";
  844. document.getElementById("overlays").style.backgroundColor = "rgba(0,0,0,.498039)";
  845. document.getElementById("overlays").style.pointerEvents = "auto";
  846. document.getElementById("stats").style.opacity = 1;
  847. document.getElementById("helloDialog").style.display = "block";
  848. kd = false;
  849. }
  850. if (in_game) {
  851. showsh = true;
  852. canvas.onmousedown(0,0);
  853. }
  854. else
  855. {
  856. showsh = false;
  857. //document.getElementById("benchmarker").style.display = "none";
  858. //showt=false;
  859. }
  860. }
  861.  
  862. var fired = false; //for some reason OnHideOverlay fires twice
  863. window.OnHideOverlay = function()
  864. {
  865. if (fired == true) {fired = false; return;} else {fired = true;} //Only continue on first fire
  866. bstyle(false);
  867. if (showsh == true) showsh = false;
  868. }
  869.  
  870. window.OnUpdateMass = function(mass)
  871. {
  872. stats.high_score = Math.max(stats.high_score, mass);
  873. UpdateChart(mass, GetRgba(my_cells[0].color,0.4));
  874. benchcheck(mass);
  875. }
  876.  
  877. window.OnCellEaten = function(predator, prey)
  878. {
  879. if (!my_cells) return;
  880.  
  881. if (my_cells.indexOf(predator) != -1){
  882. OnGainMass(predator, prey);
  883. RenderStats(false);
  884. }
  885. if (my_cells.indexOf(prey) != -1){
  886. OnLoseMass(prey, predator);
  887. RenderStats(false);
  888. }
  889. }
  890.  
  891. window.OnLeaderboard = function(position)
  892. {
  893. stats.top_slot = Math.min(stats.top_slot, position);
  894. }
  895.  
  896. window.OnDraw = function(context)
  897. {
  898. if (showfps) document.getElementById("fps-agariomods").children[1].innerHTML = countFPS();
  899. display_stats && stat_canvas && context.drawImage(stat_canvas, 10, 10);
  900. }
  901.  
  902. window.Recieve = function()
  903. {
  904. if (showpio) document.getElementById("pio-agariomods").children[1].innerHTML = countPI();
  905. }
  906.  
  907. window.OnSend = function()
  908. {
  909. if (showpio) document.getElementById("pio-agariomods").children[2].innerHTML = countPO();
  910. }
  911.  
  912. window.countFPS = (function () {
  913. var lastLoop = (new Date()).getMilliseconds();
  914. var count = 1;
  915. var fps = 0;
  916.  
  917. return function () {
  918. var currentLoop = (new Date()).getMilliseconds();
  919. if (lastLoop > currentLoop) {
  920. fps = count;
  921. count = 1;
  922. } else {
  923. count += 1;
  924. }
  925. lastLoop = currentLoop;
  926. return fps;
  927. };
  928. }());
  929.  
  930. window.countPI = (function () {
  931. var lastLoop = (new Date()).getMilliseconds();
  932. var count = 1;
  933. var packet = 0;
  934.  
  935. return function () {
  936. var currentLoop = (new Date()).getMilliseconds();
  937. if (lastLoop > currentLoop) {
  938. packet = count;
  939. count = 1;
  940. } else {
  941. count += 1;
  942. }
  943. lastLoop = currentLoop;
  944. return packet;
  945. };
  946. }());
  947.  
  948. window.countPO = (function () {
  949. var lastLoop = (new Date()).getMilliseconds();
  950. var count = 1;
  951. var packet = 0;
  952.  
  953. return function () {
  954. var currentLoop = (new Date()).getMilliseconds();
  955. if (lastLoop > currentLoop) {
  956. packet = count;
  957. count = 1;
  958. } else {
  959. count += 1;
  960. }
  961. lastLoop = currentLoop;
  962. return packet;
  963. };
  964. }());
  965.  
  966. window.onpageshow = function() {
  967. initbench(true);
  968. document.getElementById("bgimg").checked=false;
  969. jQuery('#helloDialog').css({transform: ''});
  970. jQuery('#helloDialog').css({scale: ''});
  971. $("div#settings label").change(function() {
  972. $("div#settings.checkbox input").each(function() {
  973. if (this.id=="bgimg")return;
  974. localStorage.setItem("setting"+$(this).parent().text().replace(" ","_"),this.checked);
  975. });
  976. $("div#settings input[type=range]").each(function() {
  977. localStorage.setItem("setting"+$(this).parent().text().replace(" ","_"),this.value);
  978. });
  979. });
  980. $("div#settings input").each(function() {
  981. check(this);
  982. });
  983. }
  984.  
  985. window.check = function(elem){
  986. var evt = document.createEvent("HTMLEvents");
  987. evt.initEvent("change", false, true);
  988. elem.dispatchEvent(evt);
  989. }
  990.  
  991. $(document).ready(function() {
  992. if (!localStorage.getItem("setting_Imgur Skins")) localStorage.setItem("settingImgur_Skins","true"); localStorage.setItem("settingShow_Chart","true");
  993. $("div#settings.checkbox input").each(function() {
  994. if (this.id=="bgimg")return;
  995. if ($(this).parent().text()==" No names")$(this).attr("id","names");
  996. $(this).attr("checked",(localStorage.getItem("setting"+$(this).parent().text().replace(" ","_")))=="true");
  997. });
  998. $("div#settings input[type=range]").each(function() {
  999. $(this).attr("value",(localStorage.getItem("setting"+$(this).parent().text().replace(" ","_"))));
  1000. });
  1001. });
  1002.  
  1003. var kd = false;
  1004. $(document).keydown(function(e) {
  1005. //Stats Shortcut
  1006. if (e.keyCode == 90) {
  1007. if (kd == false && document.getElementById("overlays").style.display == 'none') {
  1008. kd = true;
  1009. document.getElementById("overlays").style.display = "block";
  1010. document.getElementById("overlays").style.backgroundColor = "rgba(0,0,0,0)";
  1011. document.getElementById("overlays").style.pointerEvents = "none";
  1012. document.getElementById("stats").style.opacity = 1;
  1013. document.getElementById("helloDialog").style.display = "none";
  1014. showsh = true;
  1015. DrawStats(false);
  1016. }
  1017. }
  1018. //Benchmarker Shortcut
  1019. if (e.keyCode == 84&&!e.altKey&&document.activeElement.type!="text") {
  1020. showt = !showt;
  1021. localStorage.setItem("showt",showt);
  1022. document.getElementById("benchmarker").style.display = showt?"block":"none";
  1023. }
  1024. //Benchmarker Clear Shortcut
  1025. if (e.keyCode == 84&&e.altKey) {
  1026. deleteScores();
  1027. }
  1028. //FPS Hotkey
  1029. if (e.altKey && e.keyCode == 49) {
  1030. showfps = !showfps;
  1031. document.getElementById("fps-agariomods").style.display = showfps?"block":"none";
  1032. }
  1033. //Packets In Per Second Hotkey
  1034. if (e.altKey && e.keyCode == 50) {
  1035. showpio = !showpio;
  1036. document.getElementById("pio-agariomods").style.display = showpio?"block":"none";
  1037. }
  1038. //Suicide
  1039. if (e.altKey && e.keyCode == 81 && in_game) {
  1040. jQuery("#overlays").show()
  1041. OnShowOverlay(false);
  1042. Suicide();
  1043. }
  1044. //Firefox Fullscreen
  1045. if (e.ctrlKey && e.keyCode === 70 && navigator.userAgent.match("Firefox")) {
  1046. e.preventDefault();
  1047. if (document.mozFullScreenElement)
  1048. {
  1049. document.mozCancelFullScreen();
  1050. }
  1051. else
  1052. {
  1053. document.getElementById("overlays").mozRequestFullScreen();
  1054. }
  1055. }
  1056. //EXPERIMENTAL
  1057. //Attempts to recover from lag by temporarily pausing Javascript
  1058. //Alt+R
  1059. if (e.keyCode == 82&&e.altKey) {
  1060. if(ldown)return;
  1061. ldown = true
  1062. console.log("pausing");
  1063. var currentTime = new Date().getTime();
  1064. while (currentTime + 500 >= new Date().getTime()){} //0.5 Second Timeout
  1065. }
  1066. });
  1067. $(document).keyup(function(e) {
  1068. //Hide Stats
  1069. if (e.keyCode == 90) {
  1070. if (kd == true) {
  1071. kd = false;
  1072. document.getElementById("overlays").style.display = "none";
  1073. document.getElementById("overlays").style.backgroundColor = "rgba(0,0,0,.498039)";
  1074. document.getElementById("overlays").style.pointerEvents = "auto";
  1075. document.getElementById("stats").style.opacity = 0.85;
  1076. document.getElementById("helloDialog").style.display = "block";
  1077. showsh = false;
  1078. }
  1079. }
  1080. //EXPERIMENTAL
  1081. //To prevent extreamly long pause times fron holding down Alt+R
  1082. if (e.keyCode == 82&&e.altKey) {
  1083. if(ldown)ldown=false;
  1084. }
  1085. });
  1086.  
  1087.  
  1088. //Agar.io Benchmarker Mod
  1089. //Version 0.4 ~ Edited By Mevin1
  1090. /*
  1091. •Changes
  1092. -WTF? An entire other div just for background? nope
  1093. -using Date.now() instead of a benchmarker for timing
  1094. */
  1095. //Create global vars
  1096. var m, benchmarker;
  1097. var benchmarks = ["250mass", "500mass", "1000mass", "2500mass", "5000mass"/*, "Rank10", "Rank1"*/];
  1098. var mass_benchmarks = [250, 500, 1000, 2500, 5000];
  1099. /*var rank_benchmarks = [10, 1];
  1100. var rankPrev = 11;//broken*/
  1101. var massPrev = 0;
  1102. //Create div
  1103. $("body").append('<div id="benchmarker"></div>');
  1104. function initbench(first) {
  1105. //Style div
  1106. $("div#benchmarker").css({
  1107. "backgroundColor": "rgba(0,0,0,0.4)" /*"transparent"*/ ,
  1108. "opacity": "1.0",
  1109. "color": "white",
  1110. "fontFamily": "Ubuntu,Arial,sans-serif",
  1111. "position": "fixed",
  1112. "padding": "10px",
  1113. "text-align": "center",
  1114. "pointer-events": "none"/*,
  1115. "display": "none"*/
  1116. });
  1117. if(first){
  1118. bstyle(true);
  1119. showt?$("div#benchmarker").css({
  1120. "display": "block"
  1121. }):
  1122. $("div#benchmarker").css({
  1123. "display": "none"
  1124. });
  1125. }
  1126. //Create HTML to be added to div
  1127. var newHTML = '<table>' +
  1128. '<h3>Benchmarker</h3>' +
  1129. '<span>Time Elapsed: --:--</span>' +
  1130. '<tr><th>Benchmark</th><th>Time</th><th>Best</th></tr>' + //Headers
  1131. '<tr id="250mass"><td>250 Mass</td><td class="time">-----</td><td class="best">-----</td></tr>' + //250 Mass
  1132. '<tr id="500mass"><td>500 Mass</td><td class="time">-----</td><td class="best">-----</td></tr>' + //500 Mass
  1133. '<tr id="1000mass"><td>1000 Mass</td><td class="time">-----</td><td class="best">-----</td></tr>' + //1000 Mass
  1134. '<tr id="2500mass"><td>2500 Mass</td><td class="time">-----</td><td class="best">-----</td></tr>' + //2500 Mass
  1135. '<tr id="5000mass"><td>5000 Mass</td><td class="time">-----</td><td class="best">-----</td></tr>' + //5000 Mass
  1136. //'<tr id="Rank10"><td>Rank 10</td><td class="time">-----</td><td class="best">-----</td></tr>' + //Rank 10
  1137. //'<tr id="Rank1"><td>Rank 1</td><td class="time">-----</td><td class="best">-----</td></tr>' + //Rank 1
  1138. '</table>';
  1139.  
  1140.  
  1141. //Add HTML to div
  1142. $("div#benchmarker").html(newHTML);
  1143.  
  1144. //Load local storage --- best times
  1145. for (var i = 0; i < benchmarks.length; i++) {
  1146. if (localStorage.getItem("best_" + benchmarks[i])) {
  1147. $("#" + benchmarks[i] + " .best").html(localStorage.getItem("best_" + benchmarks[i]));
  1148. }
  1149. }
  1150. //Style the table
  1151. $("table").css({
  1152. "margin": "8px",
  1153. "padding": "8px"
  1154. });
  1155. //Centering
  1156. $("div#benchmarker h3").css("text-align", "center");
  1157. $("div#benchmarker span").css({
  1158. "text-align": "center",
  1159. "display": "inline-block"
  1160. });
  1161. //Cells
  1162. $("td,th").css({
  1163. "padding": "5px",
  1164. "text-align": "left"
  1165. });
  1166. //Margins
  1167. //$("div#benchmarker span").css({"margin":"0px","padding":"0px"});
  1168. $("div#benchmarker h3").css({
  1169. "margin-top": "4px"
  1170. });
  1171. }
  1172. function bstyle(over){
  1173. over?$("div#benchmarker").css({
  1174. "left": "",
  1175. "top": "",
  1176. "right": "5px",
  1177. "bottom": "5px",
  1178. "z-index": "1000"
  1179. }):$("div#benchmarker").css({
  1180. "left": "5px",
  1181. "top": "5px",
  1182. "right": "",
  1183. "bottom": "",
  1184. "z-index": "1"
  1185. });
  1186. }
  1187. function count() { //Occurs every second
  1188. if (showt&&in_game){
  1189. $("div#benchmarker span").html("Time Elapsed: " + mToMs(Date.now() - stats.birthday));
  1190. }}
  1191. function mToMs(millis) {
  1192. var minutes = Math.floor(millis / 60000);
  1193. var seconds = ((millis % 60000) / 1000).toFixed(0);
  1194. return minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
  1195. }
  1196. function snp(y) { //Turns XX:XX to XXXX
  1197. return y.replace(/[^0-9]+/g, '');
  1198. }
  1199. function logBenchmark(benchmark, time) {
  1200. //Manuallly record benchmark.
  1201. if ($("#" + benchmark + " .time").html() == "-----") { //Checks if the benchmark time is recorded yet
  1202. console.log("Benchmark set: " + benchmark + " at " + time);
  1203. $("#" + benchmark + " .time").html(time); //Record time
  1204. if (($("#" + benchmark + " .best").html() == "-----") || (snp(time) < snp(localStorage.getItem('best_' + benchmark)))) { //Checks if best time is beaten or undefined
  1205. console.log("Best time set: " + benchmark + " at " + time);
  1206. $("#" + benchmark + " .best").html(time); //Record time
  1207. localStorage.setItem("best_" + benchmark, time); //Save to local storage
  1208. }
  1209. }
  1210. }
  1211. function deleteScores() {
  1212. var prompt = confirm("Are you sure you want to delete your best times?");
  1213. if (prompt == true) {
  1214. for (var i = 0; i < benchmarks.length; i++) {
  1215. localStorage.removeItem("best_" + benchmarks[i]);
  1216. $("#" + benchmarks[i] + " .best").html("-----");
  1217. }
  1218. }
  1219. }
  1220. function benchcheck(mass) {
  1221. mass = Math.floor(mass / 100);
  1222. for (var i = 0; i < mass_benchmarks.length; i++) {
  1223. if ((massPrev < mass_benchmarks[i]) && (mass >= mass_benchmarks[i])) {
  1224. //Check if mass has passed from below benchmark to above benchmark
  1225. logBenchmark(mass_benchmarks[i] + "mass", mToMs(Date.now() - stats.birthday));
  1226. }
  1227. }
  1228. }