Guest User

Untitled

a guest
May 22nd, 2018
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.00 KB | None | 0 0
  1. // ==UserScript==
  2. // @name THAIลวงตามาโคV1
  3. // @namespace Agar.io Wumbo's Agar Mini-Map Script!
  4. // @version 1.0.8
  5. // @description This script will show a mini map and your location on agar.io
  6. // @author Wumbo
  7. // @license MIT
  8. // @match http://agar.pro/play/*
  9. // @require http://cdn.jsdelivr.net/msgpack/1.05/msgpack.js
  10. // @require https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js
  11. // @require https://cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js
  12. // @grant none
  13. // @run-at document-body
  14. // ==/UserScript==
  15.  
  16. window.msgpack = this.msgpack;
  17.  
  18. (function() {
  19. var _WebSocket = window._WebSocket = window.WebSocket;
  20. var $ = window.jQuery;
  21. var msgpack = window.msgpack;
  22. var options = {
  23. enableMultiCells: true,
  24. enablePosition: true,
  25. enableCross: true,
  26. showMemberOnly: true,
  27. showPlayerNameInsteadOfId: true,
  28. };
  29.  
  30. /* Configuration for porting */
  31. var Config_poker = {
  32. fieldName : {
  33. region : "#o-region",
  34. gamemode : "#o-gamemode",
  35. room : '#roomIdOrIp'
  36. },
  37. injectOnMessage : false,
  38. };
  39.  
  40. var Config_DaChong = {
  41. fieldName : {
  42. region : "#region",
  43. gamemode : "#gamemode",
  44. room : '#srv-ip'
  45. },
  46. injectOnMessage : true,
  47. };
  48.  
  49. var currentConfig = Config_DaChong;
  50.  
  51. var fieldName = currentConfig.fieldName;
  52. var injectOnMessage = currentConfig.injectOnMessage;
  53. var defaultServer = "ws://eddy.zone.be:8000";
  54.  
  55. // game states
  56. var agarServerAddress = null;
  57. var map_server = null;
  58. var player_name = [];
  59. var players = [];
  60. var id_players = [];
  61. var cells = [];
  62. var current_cell_ids = [];
  63. var start_x = -7000,
  64. start_y = -7000,
  65. end_x = 7000,
  66. end_y = 7000,
  67. length_x = 14000,
  68. length_y = 14000;
  69. var minimapHeight = 300;
  70. var minimapWidth = 300;
  71. var render_timer = null;
  72. var update_server_list_timer = null;
  73. var mini_map_tokens = [];
  74. var mapEvent = [];
  75.  
  76. /* Map Event Object */
  77. function Event(data){
  78. this.x = data.x;
  79. this.y = data.y;
  80. this.type = data.type;
  81. this.origin = data.origin;
  82. this.time = Date.now();
  83. }
  84.  
  85. Event.TYPE_NORMAL = 0;
  86. Event.TYPE_FEED = 1;
  87. Event.TYPE_FAKESPACE = 2;
  88. Event.TYPE_RUN = 3;
  89.  
  90. Event.prototype = {
  91. toSendObject: function(){
  92. return {
  93. x: this.x,
  94. y: this.y,
  95. type: this.type,
  96. message: this.message
  97. };
  98. },
  99. isTimeout : function(){
  100. return Date.now() - this.time > 500;
  101. },
  102. render: function(ctx, xyTransform, maxsize){
  103. var elapsedTime = Date.now() - this.time;
  104. if(elapsedTime > 500){
  105. /* TODO: delete */
  106. return;
  107. }
  108.  
  109. var position = xyTransform(this.x, this.y);
  110. var size = maxsize * elapsedTime / 500;
  111. var color;
  112.  
  113. switch(this.type){
  114. case Event.TYPE_NORMAL: color = "#55FF55"; break;
  115. case Event.TYPE_FEED: color = "#CCCCFF"; break;
  116. case Event.TYPE_FAKESPACE: color = "#FFFFFF"; break;
  117. case Event.TYPE_RUN: color = "#FF0000"; break;
  118. }
  119.  
  120. ctx.save();
  121. ctx.strokeStyle = color;
  122. ctx.globalAlpha = Math.min(2 * (500 - elapsedTime) / 500, 1);
  123. ctx.lineCap = "round";
  124. ctx.lineJoin = "round";
  125. ctx.lineWidth = size * 0.05;
  126. ctx.beginPath();
  127. ctx.arc(position.x,
  128. position.y,
  129. size,
  130. 0,
  131. 2 * Math.PI,
  132. false);
  133. ctx.closePath();
  134. ctx.stroke();
  135. },
  136. };
  137.  
  138. function miniMapSendRawData(data) {
  139. if (map_server !== null && map_server.readyState === window._WebSocket.OPEN) {
  140. var array = new Uint8Array(data);
  141. map_server.send(array.buffer);
  142. }
  143. }
  144.  
  145. function getAgarServerInfo(){
  146. return {
  147. address : agarServerAddress,
  148. region: $(fieldName.region).val(),
  149. gamemode: $(fieldName.gamemode).val() === '' ? ':ffa' : $(fieldName.gamemode).val(),
  150. party: $(fieldName.room).val(),
  151. };
  152. }
  153.  
  154. function miniMapConnectToServer(address, onOpen, onClose) {
  155. if(map_server !== null)return;
  156. var ws = null;
  157. try {
  158. ws = new window._WebSocket(address);
  159. } catch (ex) {
  160. onClose();
  161. console.error(ex);
  162. return false;
  163. }
  164. ws.binaryType = "arraybuffer";
  165.  
  166. ws.onopen = onOpen;
  167.  
  168. ws.onmessage = function(event) {
  169. var buffer = new Uint8Array(event.data);
  170. var packet = msgpack.unpack(buffer);
  171. switch(packet.type) {
  172. case 128: /* Update map */
  173. for (var i=0; i < packet.data.addition.length; ++i) {
  174. var cell = packet.data.addition[i];
  175. if (! miniMapIsRegisteredToken(cell.id))
  176. {
  177. miniMapRegisterToken(
  178. cell.id,
  179. miniMapCreateToken(cell.id, cell.color)
  180. );
  181. }
  182.  
  183. var size_n = cell.size/length_x;
  184. miniMapUpdateToken(cell.id, (cell.x - start_x)/length_x, (cell.y - start_y)/length_y, size_n);
  185. }
  186.  
  187. for (i = 0; i < packet.data.deletion.length; ++i) {
  188. var id = packet.data.deletion[i];
  189. miniMapUnregisterToken(id);
  190. }
  191. break;
  192. case 129: /* Update player */
  193. players = packet.data;
  194. for (var p in players) {
  195. var player = players[p];
  196. var ids = player.ids;
  197. for (i in ids) {
  198. id_players[ids[i]] = player.no;
  199. }
  200. }
  201. console.log('update-list');
  202. window.mini_map_party.trigger('update-list');
  203. break;
  204. case 131: /* Update server list */
  205. $('#server-list').empty();
  206. packet.data.forEach(function(server){
  207. var uid = server.uid;
  208. var info = server.info;
  209. var playerCount = server.playerCount;
  210. var item = $('<a>')
  211. .text(info.address + ' ' + info.gamemode + ' : ' + playerCount)
  212. .click({ token: info.party, uid: uid },function(e){
  213. e.preventDefault();
  214. var target = $(e.currentTarget);
  215. if(e.data.token !== ''){
  216. window.connectJ(e.data.token);
  217. $(fieldName.room).val(e.data.token);
  218. setTimeout(function(){
  219. miniMapSendRawData(msgpack.pack({
  220. type: 51,
  221. data: e.data.uid
  222. }));
  223. }, 1000);
  224.  
  225. }
  226. });
  227.  
  228. var item2 = $('<li>');
  229. item.appendTo(item2);
  230. item2.appendTo($('#server-list'));
  231. });
  232. break;
  233. case 33: /* Add event */
  234. mapEvent.push(new Event(packet.data));
  235. }
  236. };
  237.  
  238. ws.onerror = function() {
  239. onClose();
  240. console.error('failed to connect to map server');
  241. };
  242.  
  243. ws.onclose = onClose;
  244.  
  245. map_server = ws;
  246. }
  247.  
  248. function miniMapRender() {
  249. var canvas = window.mini_map;
  250. var ctx = canvas.getContext('2d');
  251.  
  252. // Background
  253. ctx.clearRect(0, 0, canvas.width, canvas.height);
  254. ctx.globalAlpha = 0.3;
  255. ctx.fillStyle = '#000000';
  256. ctx.fillRect(0, 0, canvas.width, canvas.height);
  257. // Draw coordinate
  258. var yAxis = ['A', 'B', 'C', 'D', 'E'];
  259. var xSize = canvas.width;
  260. var ySize = canvas.height;
  261. ctx.beginPath();
  262. ctx.lineWidth = 2;
  263. ctx.textAlign = 'center';
  264. ctx.textBaseline = 'middle';
  265. ctx.font = (0.6 * xSize / 5) + 'px Arial';
  266. ctx.fillStyle = ctx.strokeStyle = '#AAAAAA';
  267. for (var j = 0; j < 5; ++j) {
  268. for (var i = 0; i < 5; ++i) {
  269. ctx.strokeRect((xSize / 5 * i), (ySize / 5 * j), (xSize / 5), (ySize / 5));
  270. ctx.fillText(yAxis[j] + (i + 1), (xSize / 5 * i) + (xSize / 5 / 2), (ySize / 5 * j) + (ySize / 5 / 2));
  271. }
  272. }
  273. ctx.stroke();
  274. ctx.globalAlpha = 1.0; // restore alpha
  275.  
  276. var rendered_player = [];
  277.  
  278. for (var id in mini_map_tokens) {
  279. var token = mini_map_tokens[id];
  280. var x = token.x * canvas.width;
  281. var y = token.y * canvas.height;
  282. var size = token.size * canvas.width;
  283.  
  284. if (!options.showMemberOnly || id_players[id] !== undefined || current_cell_ids.indexOf(token.id) !== -1) {
  285. if(options.showMemberOnly && size < 7){ /* add an translucent, bigger cell to make it clear*/
  286. ctx.globalAlpha = 0.5;
  287. ctx.beginPath();
  288. ctx.arc(
  289. x,
  290. y,
  291. 7,
  292. 0,
  293. 2 * Math.PI,
  294. false
  295. );
  296. ctx.closePath();
  297. ctx.fillStyle = token.color;
  298. ctx.fill();
  299. ctx.globalAlpha = 1.0;
  300. }
  301. ctx.beginPath();
  302. ctx.arc(
  303. x,
  304. y,
  305. size,
  306. 0,
  307. 2 * Math.PI,
  308. false
  309. );
  310. ctx.closePath();
  311. ctx.fillStyle = token.color;
  312. ctx.fill();
  313. }
  314.  
  315. if (options.enableCross && -1 != current_cell_ids.indexOf(token.id)){
  316. miniMapDrawCross(token.x, token.y, token.color);
  317. }
  318.  
  319. if (id_players[id] !== undefined) {
  320. // Draw you party member's crosshair
  321. if (options.enableCross) {
  322. miniMapDrawCross(token.x, token.y, token.color);
  323. }
  324.  
  325. if(rendered_player.indexOf(id_players[id]) == -1){
  326. if(options.showPlayerNameInsteadOfId){
  327. if(players[id_players[id]].name){
  328. /* draw name only once */
  329. ctx.font = '14px Arial';
  330. ctx.textAlign = 'center';
  331. ctx.textBaseline = 'middle';
  332. ctx.fillStyle = 'white';
  333. ctx.fillText(String.fromCharCode.apply(null, players[id_players[id]].name), x, y + ((size < 10) ? 10 : size * 1.3));
  334. rendered_player.push(id_players[id]);
  335. }
  336. }else{
  337. ctx.font = size * 2 + 'px Arial';
  338. ctx.textAlign = 'center';
  339. ctx.textBaseline = 'middle';
  340. ctx.fillStyle = 'white';
  341. ctx.fillText(id_players[id] + 1, x, y);
  342. }
  343. }
  344. }
  345. }
  346.  
  347. for(var e = 0;e < mapEvent.length; ++e){
  348. if(mapEvent[e]){
  349. mapEvent[e].render(ctx,
  350. function(x,y){
  351. var nx = (x - start_x) / length_x * minimapWidth;
  352. var ny = (y - start_y) / length_y * minimapHeight;
  353. return {x:nx, y:ny};
  354. } ,
  355. 60/* size */);
  356. if(mapEvent[e].isTimeout()){
  357. mapEvent.splice(e, 1);
  358. }
  359. }
  360. }
  361. }
  362.  
  363. function miniMapDrawCross(x, y, color) {
  364. var canvas = window.mini_map;
  365. var ctx = canvas.getContext('2d');
  366. ctx.lineWidth = 0.5;
  367. ctx.beginPath();
  368. ctx.moveTo(0, y * canvas.height);
  369. ctx.lineTo(canvas.width, y * canvas.height);
  370. ctx.moveTo(x * canvas.width, 0);
  371. ctx.lineTo(x * canvas.width, canvas.height);
  372. ctx.closePath();
  373. ctx.strokeStyle = color || '#FFFFFF';
  374. ctx.stroke();
  375. }
  376.  
  377. function miniMapCreateToken(id, color) {
  378. var mini_map_token = {
  379. id: id,
  380. color: color,
  381. x: 0,
  382. y: 0,
  383. size: 0
  384. };
  385. return mini_map_token;
  386. }
  387.  
  388. function miniMapRegisterToken(id, token) {
  389. if (mini_map_tokens[id] === undefined) {
  390. // window.mini_map.append(token);
  391. mini_map_tokens[id] = token;
  392. }
  393. }
  394.  
  395. function miniMapUnregisterToken(id) {
  396. if (mini_map_tokens[id] !== undefined) {
  397. // mini_map_tokens[id].detach();
  398. delete mini_map_tokens[id];
  399. }
  400. }
  401.  
  402. function miniMapIsRegisteredToken(id) {
  403. return mini_map_tokens[id] !== undefined;
  404. }
  405.  
  406. function miniMapUpdateToken(id, x, y, size) {
  407. if (mini_map_tokens[id] !== undefined) {
  408.  
  409. mini_map_tokens[id].x = x;
  410. mini_map_tokens[id].y = y;
  411. mini_map_tokens[id].size = size;
  412.  
  413. return true;
  414. } else {
  415. return false;
  416. }
  417. }
  418.  
  419. function miniMapUpdatePos(x, y) {
  420. window.mini_map_pos.text('x: ' + x.toFixed(0) + ', y: ' + y.toFixed(0));
  421. }
  422.  
  423. function miniMapReset() {
  424. cells = [];
  425. mini_map_tokens = [];
  426. }
  427.  
  428. function miniMapInit() {
  429. mini_map_tokens = [];
  430.  
  431. cells = [];
  432. current_cell_ids = [];
  433. start_x = -7000;
  434. start_y = -7000;
  435. end_x = 7000;
  436. end_y = 7000;
  437. length_x = 14000;
  438. length_y = 14000;
  439.  
  440. /* Right Panel */
  441. if ($('#sidebar-wrapper').length === 0) {
  442. jQuery('body').append(
  443. '<style>' +
  444. '.nav .open > a, ' +
  445. '.nav .open > a:hover, ' +
  446. '.nav .open > a:focus {background-color: transparent;} ' +
  447. ' ' +
  448. '/*-------------------------------*/ ' +
  449. '/* Wrappers */ ' +
  450. '/*-------------------------------*/ ' +
  451. ' ' +
  452. '#sidebar-wrapper { ' +
  453. ' position: absolute; ' +
  454. ' z-index: 1000; ' +
  455. ' margin-right: -310px; ' +
  456. ' left: auto; ' +
  457. ' height: 100%; ' +
  458. ' overflow-y: auto; ' +
  459. ' overflow-x: hidden; ' +
  460. ' background: rgba(26,26,26,0.8); ' +
  461. ' width: 310px; ' +
  462. '} ' +
  463. '#sidebar-wrapper.toggled {' +
  464. ' margin-right: 0px; ' +
  465. '}' +
  466. '/*-------------------------------*/ ' +
  467. '/* Sidebar nav styles */ ' +
  468. '/*-------------------------------*/ ' +
  469. ' ' +
  470. '.sidebar-nav { ' +
  471. ' position: absolute; ' +
  472. ' top: 0; ' +
  473. ' width: 310px; ' +
  474. ' margin: 0; ' +
  475. ' padding: 0; ' +
  476. ' list-style: none; ' +
  477. '} ' +
  478. ' ' +
  479. '.sidebar-nav li { ' +
  480. ' position: relative; ' +
  481. ' line-height: 20px; ' +
  482. ' display: inline-block; ' +
  483. ' width: 100%; ' +
  484. ' background: rgba(40, 40, 40, 0.8);' +
  485. '} ' +
  486. ' ' +
  487. '.sidebar-nav li:before { ' +
  488. ' content: \'\'; ' +
  489. ' position: absolute; ' +
  490. ' top: 0; ' +
  491. ' left: 0; ' +
  492. ' z-index: -1; ' +
  493. ' height: 100%; ' +
  494. ' width: 5px; ' +
  495. ' background-color: #1c1c1c; ' +
  496. ' ' +
  497. '} ' +
  498. '.sidebar-nav li:nth-child(1):before { ' +
  499. ' background-color: #ec122a; ' +
  500. '} ' +
  501. '.sidebar-nav li:nth-child(2):before { ' +
  502. ' background-color: #ec1b5a; ' +
  503. '} ' +
  504. '.sidebar-nav li:nth-child(3):before { ' +
  505. ' background-color: #79aefe; ' +
  506. '} ' +
  507. '.sidebar-nav li:nth-child(4):before { ' +
  508. ' background-color: #314190; ' +
  509. '} ' +
  510. '.sidebar-nav li:nth-child(5):before { ' +
  511. ' background-color: #314120; ' +
  512. '} ' +
  513. '.sidebar-nav li:hover:before, ' +
  514. '.sidebar-nav li.open:hover:before { ' +
  515. ' width: 100%; ' +
  516. ' ' +
  517. '} ' +
  518. ' ' +
  519. '.sidebar-nav li a { ' +
  520. ' display: block; ' +
  521. ' color: #ddd; ' +
  522. ' text-decoration: none; ' +
  523. ' padding: 10px 15px 10px 30px; ' +
  524. '} ' +
  525. ' ' +
  526. '.sidebar-nav li a:hover, ' +
  527. '.sidebar-nav li a:active, ' +
  528. '.sidebar-nav li a:focus, ' +
  529. '.sidebar-nav li.open a:hover, ' +
  530. '.sidebar-nav li.open a:active, ' +
  531. '.sidebar-nav li.open a:focus{ ' +
  532. ' color: #fff; ' +
  533. ' text-decoration: none; ' +
  534. ' background-color: transparent; ' +
  535. '} ' +
  536. ' ' +
  537. '.sidebar-nav > .sidebar-brand { ' +
  538. ' height: 65px; ' +
  539. ' font-size: 20px; ' +
  540. ' line-height: 44px; ' +
  541. ' background-color: #3c3c3c; ' +
  542. '} ' +
  543. '.dropdown-label{ ' +
  544. ' display: block;' +
  545. ' color: #ffffff; ' +
  546. ' padding: 10px 15px 10px 30px;' +
  547. '} ' +
  548. '.dropdown-label:visited, ' +
  549. '.dropdown-label:hover, ' +
  550. '.dropdown-label:active{ ' +
  551. ' color: #cecece; ' +
  552. ' text-decoration: none;' +
  553. '} ' +
  554. '.dropdown-label:after{ ' +
  555. ' content: \' ▶\';' +
  556. ' text-align: right; ' +
  557. ' float:right;' +
  558. '} ' +
  559. '.dropdown-label:hover:after{' +
  560. ' content:\'▼\';' +
  561. ' text-align: right; ' +
  562. ' float:right;' +
  563. '}' +
  564. '.dropdown ul{' +
  565. ' float: left;' +
  566. ' opacity: 0;'+
  567. ' width: 100%; ' +
  568. ' padding: 0px;' +
  569. ' top : 0px;'+
  570. ' visibility: hidden;'+
  571. ' z-index: 1;' +
  572. ' position: absolute;' +
  573. ' border: #555555 1px;' +
  574. ' border-style: solid;' +
  575. '}' +
  576. '.dropdown ul li{' +
  577. ' float: none;' +
  578. ' width: 100%;' +
  579. '}' +
  580. '.dropdown li:before{' +
  581. ' width: 0px;'+
  582. '}' +
  583. '.dropdown:hover ul{' +
  584. ' opacity: 1;'+
  585. ' background: #3c3c3c;'+
  586. ' top : 65px;'+
  587. ' visibility: visible;'+
  588. '}' +
  589. '</style>' +
  590. '<nav class="navbar navbar-inverse navbar-fixed-top" id="sidebar-wrapper" role="navigation">' +
  591. ' <ul class="nav sidebar-nav">' +
  592. ' <div class="sidebar-brand dropdown">' +
  593. ' <a id="tabtitle" class="dropdown-label" href="#">' +
  594. ' เมนู' +
  595. ' </a>' +
  596. ' <ul>' +
  597. ' <li><a data-toggle="tab" href="#tab-serverselect">ปุ่มกด มาโค</a></li>' +
  598. ' <li><a data-toggle="tab" href="#tab-settings">ตั้งค่าแมพ</a></li>' +
  599. ' </ul>' +
  600. ' </div>' +
  601. ' <div class="tab-content">' +
  602. ' <div id="tab-chat" class="tab-pane fade in active">' +
  603. ' <li>' +
  604. ' </a>' +
  605. ' </li>' +
  606. ' <div id="playerlist"><!-- place holder --></div>' +
  607. ' <li>' +
  608. ' </a>' +
  609. ' </li>' +
  610. ' <div id="chat"><p>Not yet implemented :P</p></div>' +
  611. ' </div>' +
  612. ' <div id="tab-serverselect" class="tab-pane fade">' +
  613. ' <li>' +
  614. ' <a href="#">' +
  615. ' มาโควิธีใช้ [Q=ทิค] ' +
  616. ' <a href="#">' +
  617. ' มาโควิธีใช้ [R= ป๊อปไปร์] ' +
  618. ' <a href="#">' +
  619. ' มาโควิธีใช้ [D= ดับเบิลไกล] ' +
  620. ' <a href="#">' +
  621. ' มาโควิธีใช้ [Z= ทิปสไปร์ 3เท่า] ' +
  622. ' </a>' +
  623. ' </li>' +
  624. ' <div id="server-list"><!-- place holder --></div>' +
  625. ' </div>' +
  626. ' <div id="tab-settings" class="tab-pane fade">' +
  627. ' <li>' +
  628. ' <a href="#">' +
  629. ' แมพIP เซิฟเวอร์' +
  630. ' </a>' +
  631. ' </li>' +
  632. ' <div id="minimap-server-connection"><!-- place holder --></div>' +
  633. ' <li>' +
  634. ' <a href="#">' +
  635. ' ตั้งค่ามุมมอง' +
  636. ' </a>' +
  637. ' </li>' +
  638. ' <div id="minimap-setting"><!-- place holder --></div>' +
  639. ' </div>' +
  640. ' </div>' +
  641. ' </ul>' +
  642. '</nav>'
  643. );
  644. }
  645. // '<li>' +
  646. // ' <iframe src="https://discordapp.com/widget?id=103557585675763712&theme=dark" width="350" height="500" allowtransparency="true" frameborder="0"></iframe>' +
  647. // '</li>' +
  648.  
  649. // Minimap
  650. if ($('#mini-map-wrapper').length === 0) {
  651. var wrapper = $('<div>').attr('id', 'mini-map-wrapper').css({
  652. position: 'fixed',
  653. bottom: 5,
  654. right: 5,
  655. width: minimapWidth,
  656. height: minimapHeight,
  657. background: 'rgba(128, 128, 128, 0.58)',
  658. "z-index": '1001'
  659. });
  660.  
  661. var mini_map = $('<canvas>').attr({
  662. id: 'mini-map',
  663. width: minimapWidth,
  664. height: minimapHeight,
  665. }).css({
  666. width: '100%',
  667. height: '100%',
  668. position: 'relative',
  669. cursor: 'cell',
  670. }).on("mousedown",function(e){
  671. if(e.button === 0){
  672. var posX = e.pageX - $(this).offset().left,
  673. posY = e.pageY - $(this).offset().top;
  674. var mapPosX = posX / minimapWidth * length_x + start_x;
  675. var mapPosY = posY / minimapHeight * length_y + start_y;
  676. var event = new Event({
  677. x : mapPosX,
  678. y : mapPosY,
  679. type : Event.TYPE_NORMAL,
  680. origin : -1,
  681. });
  682. miniMapSendRawData(msgpack.pack({
  683. type : 33,
  684. data: event.toSendObject()
  685. }));
  686. }else if(e.button === 2){
  687. window.Minimap.ToggleSidebar();
  688. }
  689. }).on('contextmenu',function(e){
  690. return false;
  691. });
  692.  
  693. wrapper.append(mini_map).appendTo(document.body);
  694.  
  695. window.mini_map = mini_map[0];
  696. }
  697.  
  698. // minimap renderer
  699. if (render_timer === null)
  700. render_timer = setInterval(miniMapRender, 1000 / 30);
  701.  
  702. // update server list every 10 seconds
  703. if (update_server_list_timer === null)
  704. update_server_list_timer = setInterval(function(){
  705. miniMapSendRawData(msgpack.pack({type: 50}));
  706. }, 1000 * 10);
  707.  
  708. // minimap location
  709. if ($('#mini-map-pos').length === 0) {
  710. window.mini_map_pos = $('<div>').attr('id', 'mini-map-pos').css({
  711. bottom: 10,
  712. right: 10,
  713. color: 'white',
  714. fontSize: 15,
  715. fontWeight: 800,
  716. position: 'fixed'
  717. }).appendTo(document.body);
  718. }
  719.  
  720. // minimap options
  721. if ($('#mini-map-options').length === 0) {
  722. window.mini_map_options = $('<div>').attr('id', 'mini-map-options').css({
  723. color: '#EEEEEE',
  724. fontWeight: 400,
  725. padding: '10px 15px 10px 30px'
  726. }).appendTo($('#minimap-setting'));
  727.  
  728. for (var name in options) {
  729.  
  730. var label = $('<label>').css({
  731. display: 'block'
  732. });
  733.  
  734. var checkbox = $('<input>').attr({
  735. type: 'checkbox'
  736. }).prop({
  737. checked: options[name]
  738. });
  739.  
  740. label.append(checkbox);
  741. label.append(' ' + camel2cap(name));
  742.  
  743. checkbox.click( function(options, name) {
  744. return function(evt) {
  745. options[name] = evt.target.checked;
  746. console.log(name, evt.target.checked);
  747. };
  748. }(options, name));
  749.  
  750. label.appendTo(window.mini_map_options);
  751. }
  752.  
  753. var form = $('<div>')
  754. .addClass('form-inline')
  755. .css({
  756. opacity: 0.7,
  757. marginTop: 2
  758. })
  759. .appendTo(window.mini_map_options);
  760.  
  761. var form_group = $('<div>')
  762. .addClass('form-group')
  763. .css({
  764. padding: '10px 15px 10px 30px',
  765. 'margin-bottom': '0px'
  766. })
  767. .appendTo($('#minimap-server-connection'));
  768.  
  769. var addressInput = $('<input>')
  770. .attr('placeholder', defaultServer)
  771. .attr('type', 'text')
  772. .css({
  773. 'background-color':'#3c3c3c',
  774. color: '#FFF',
  775. border: 'none',
  776. 'margin-bottom': '3px'
  777. })
  778. .addClass('form-control')
  779. .val(defaultServer)
  780. .appendTo(form_group);
  781.  
  782. var connect = function (evt) {
  783. var address = addressInput.val();
  784.  
  785. connectBtn.popover('destroy');
  786. connectBtn.text('Disconnect');
  787. miniMapConnectToServer(address, function onOpen() {
  788. miniMapSendRawData(msgpack.pack({
  789. type: 100,
  790. data: getAgarServerInfo(),
  791. }));
  792. miniMapSendRawData(msgpack.pack({
  793. type: 0,
  794. data: player_name
  795. }));
  796. for (var i in current_cell_ids) {
  797. miniMapSendRawData(msgpack.pack({
  798. type: 32,
  799. data: current_cell_ids[i]
  800. }));
  801. }
  802. miniMapSendRawData(msgpack.pack({type: 50}));
  803. console.log(address + ' connected');
  804. }, function onClose() {
  805. map_server = null;
  806. players = [];
  807. id_players = [];
  808. disconnect();
  809. console.log('map server disconnected');
  810. });
  811.  
  812. connectBtn.off('click');
  813. connectBtn.on('click', disconnect);
  814.  
  815. miniMapReset();
  816.  
  817. connectBtn.blur();
  818. };
  819.  
  820. var disconnect = function() {
  821. connectBtn.text('Connect');
  822. connectBtn.off('click');
  823. connectBtn.on('click', connect);
  824. connectBtn.blur();
  825. if (map_server)
  826. map_server.close();
  827.  
  828. miniMapReset();
  829. };
  830.  
  831. var connectBtn = $('<button>')
  832. .attr('id', 'mini-map-connect-btn')
  833. .text('Connect')
  834. .click(connect)
  835. .addClass('btn btn-block btn-primary')
  836. .appendTo(form_group);
  837.  
  838. connectBtn.trigger('click');
  839. }
  840.  
  841. // minimap party
  842. if ($('#mini-map-party').length === 0) {
  843. var mini_map_party = window.mini_map_party = $('<div>')
  844. .css({
  845. color: '#FFF',
  846. fontSize: 20,
  847. fontWeight: 600,
  848. textAlign: 'center',
  849. padding: 10
  850. })
  851. .attr('id', 'mini-map-party')
  852. .appendTo($('#playerlist'));
  853.  
  854. var mini_map_party_list = $('<ol>')
  855. .attr('id', 'mini-map-party-list')
  856. .css({
  857. listStyle: 'none',
  858. padding: 0,
  859. margin: 0
  860. })
  861. .appendTo(mini_map_party);
  862.  
  863. mini_map_party.on('update-list', function(e) {
  864. mini_map_party_list.empty();
  865.  
  866. for (var p in players) {
  867. var player = players[p];
  868. var name = String.fromCharCode.apply(null, player.name);
  869. name = (name === '' ? 'anonymous' : name);
  870. $('<p>')
  871. .text(player.no + 1 + '. ' + name)
  872. .css({
  873. margin: 0
  874. })
  875. .appendTo(mini_map_party_list);
  876. }
  877. });
  878. }
  879. }
  880.  
  881. // cell constructor
  882. function Cell(id, x, y, size, color, name) {
  883. cells[id] = this;
  884. this.id = id;
  885. this.ox = this.x = x;
  886. this.oy = this.y = y;
  887. this.oSize = this.size = size;
  888. this.color = color;
  889. this.points = [];
  890. this.pointsAcc = [];
  891. this.setName(name);
  892. }
  893.  
  894. Cell.prototype = {
  895. id: 0,
  896. points: null,
  897. pointsAcc: null,
  898. name: null,
  899. nameCache: null,
  900. sizeCache: null,
  901. x: 0,
  902. y: 0,
  903. size: 0,
  904. ox: 0,
  905. oy: 0,
  906. oSize: 0,
  907. nx: 0,
  908. ny: 0,
  909. nSize: 0,
  910. updateTime: 0,
  911. updateCode: 0,
  912. drawTime: 0,
  913. destroyed: false,
  914. isVirus: false,
  915. isAgitated: false,
  916. wasSimpleDrawing: true,
  917.  
  918. destroy: function() {
  919. delete cells[this.id];
  920. id = current_cell_ids.indexOf(this.id);
  921. if(-1 != id){
  922. current_cell_ids.splice(id, 1);
  923. }
  924. this.destroyed = true;
  925. if (map_server === null || map_server.readyState !== window._WebSocket.OPEN) {
  926. miniMapUnregisterToken(this.id);
  927. }
  928. },
  929. setName: function(name) {
  930. this.name = name;
  931. },
  932. updatePos: function() {
  933. if (map_server === null || map_server.readyState !== window._WebSocket.OPEN) {
  934. if (options.enableMultiCells || -1 != current_cell_ids.indexOf(this.id)) {
  935. if (! miniMapIsRegisteredToken(this.id))
  936. {
  937. miniMapRegisterToken(
  938. this.id,
  939. miniMapCreateToken(this.id, this.color)
  940. );
  941. }
  942.  
  943. var size_n = this.nSize/length_x;
  944. miniMapUpdateToken(this.id, (this.nx - start_x)/length_x, (this.ny - start_y)/length_y, size_n);
  945. }
  946. }
  947.  
  948. if (options.enablePosition && -1 != current_cell_ids.indexOf(this.id)) {
  949. window.mini_map_pos.show();
  950. miniMapUpdatePos(this.nx, this.ny);
  951. } else {
  952. window.mini_map_pos.hide();
  953. }
  954.  
  955. }
  956. };
  957.  
  958. String.prototype.capitalize = function() {
  959. return this.charAt(0).toUpperCase() + this.slice(1);
  960. };
  961.  
  962. function camel2cap(str) {
  963. return str.replace(/([A-Z])/g, function(s){return ' ' + s.toLowerCase();}).capitalize();
  964. }
  965.  
  966. // create a linked property from slave object
  967. // whenever master[prop] update, slave[prop] update
  968. function refer(master, slave, prop) {
  969. Object.defineProperty(master, prop, {
  970. get: function(){
  971. return slave[prop];
  972. },
  973. set: function(val) {
  974. slave[prop] = val;
  975. },
  976. enumerable: true,
  977. configurable: true
  978. });
  979. }
  980.  
  981. // extract a websocket packet which contains the information of cells
  982. function extractCellPacket(data, offset) {
  983. ////
  984. var dataToSend = {
  985. destroyQueue : [],
  986. nodes : [],
  987. nonVisibleNodes : []
  988. };
  989. ////
  990.  
  991. var I = +new Date();
  992. var qa = false;
  993. var b = Math.random(), c = offset;
  994. var size = data.getUint16(c, true);
  995. c = c + 2;
  996.  
  997. // Nodes to be destroyed (killed)
  998. for (var e = 0; e < size; ++e) {
  999. var p = cells[data.getUint32(c, true)],
  1000. f = cells[data.getUint32(c + 4, true)];
  1001. c = c + 8;
  1002. if(p && f){
  1003. f.destroy();
  1004. f.ox = f.x;
  1005. f.oy = f.y;
  1006. f.oSize = f.size;
  1007. f.nx = p.x;
  1008. f.ny = p.y;
  1009. f.nSize = f.size;
  1010. f.updateTime = I;
  1011. dataToSend.destroyQueue.push(f.id);
  1012. }
  1013. }
  1014.  
  1015. // Nodes to be updated
  1016. for (e = 0; ; ) {
  1017. var id = data.getUint32(c, true); /* playerID */
  1018. c += 4;
  1019. if (0 === id) {
  1020. break;
  1021. }
  1022. ++e;
  1023. var p = data.getInt32(c, true); /* x */
  1024. c = c + 4;
  1025.  
  1026. var f = data.getInt32(c, true); /* y */
  1027. c = c + 4;
  1028.  
  1029. g = data.getInt16(c, true); /* radius */
  1030. c = c + 2;
  1031. for (var h = data.getUint8(c++), m = data.getUint8(c++), q = data.getUint8(c++), h = (h << 16 | m << 8 | q).toString(16); 6 > h.length; )
  1032. h = "0" + h; /* color */
  1033.  
  1034. var h = "#" + h, /* color */
  1035. k = data.getUint8(c++), /* some flags */
  1036. m = !!(k & 1), /* isVirus */
  1037. q = !!(k & 16);/* isAgitated */
  1038.  
  1039. if(k & 2){
  1040. c += 4 + data.getUint32(c, true);
  1041. }
  1042. if(k & 4){
  1043. var ch, mcskin = "";
  1044. for(;;){
  1045. ch = data.getUint8(c++);
  1046. if(0 == ch)
  1047. break;
  1048. mcskin += String.fromCharCode(ch);
  1049. }
  1050. }
  1051.  
  1052. for (var n, k = ""; ; ) {
  1053. n = data.getUint16(c, true);
  1054. c += 2;
  1055. if (0 == n)
  1056. break;
  1057. k += String.fromCharCode(n); /* name */
  1058. }
  1059.  
  1060. n = k;
  1061. k = null;
  1062.  
  1063. var updated = false;
  1064. // if id in cells then modify it, otherwise create a new cell
  1065. if(cells.hasOwnProperty(id)){
  1066. k = cells[id];
  1067. k.updatePos();
  1068. k.ox = k.x;
  1069. k.oy = k.y;
  1070. k.oSize = k.size;
  1071. k.color = h;
  1072. updated = true;
  1073. }else{
  1074. k = new Cell(id, p, f, g, h, n);
  1075. k.pX = p;
  1076. k.pY = f;
  1077. }
  1078.  
  1079. k.isVirus = m;
  1080. k.isAgitated = q;
  1081. k.nx = p;
  1082. k.ny = f;
  1083. k.updateCode = b;
  1084. k.updateTime = I;
  1085. k.nSize = g;
  1086. if(n) k.setName(n);
  1087.  
  1088. // ignore food creation
  1089. if (updated) {
  1090. dataToSend.nodes.push({
  1091. id: k.id,
  1092. x: k.nx,
  1093. y: k.ny,
  1094. size: k.nSize,
  1095. color: k.color
  1096. });
  1097. }
  1098. }
  1099.  
  1100. // Destroy queue + nonvisible nodes
  1101. b = data.getUint32(c, true);
  1102. c += 4;
  1103. for (e = 0; e < b; e++) {
  1104. var d = data.getUint32(c, true);
  1105. c += 4;
  1106. var k = cells[d];
  1107. if(null != k) k.destroy();
  1108. dataToSend.nonVisibleNodes.push(d);
  1109. }
  1110.  
  1111. var packet = {
  1112. type: 16,
  1113. data: dataToSend
  1114. };
  1115.  
  1116. miniMapSendRawData(msgpack.pack(packet));
  1117. }
  1118.  
  1119. // extract the type of packet and dispatch it to a corresponding extractor
  1120. function extractPacket(event) {
  1121. var c = 0;
  1122. var data = new DataView(event.data);
  1123. if(240 == data.getUint8(c)) c += 5;
  1124. var opcode = data.getUint8(c);
  1125. c++;
  1126. switch (opcode) {
  1127. case 16: // cells data
  1128. extractCellPacket(data, c);
  1129. break;
  1130. case 20: // cleanup ids
  1131. current_cell_ids = [];
  1132. break;
  1133. case 32: // cell id belongs me
  1134. var id = data.getUint32(c, true);
  1135.  
  1136. if (current_cell_ids.indexOf(id) === -1)
  1137. current_cell_ids.push(id);
  1138.  
  1139. miniMapSendRawData(msgpack.pack({
  1140. type: 32,
  1141. data: id
  1142. }));
  1143. break;
  1144. case 64: // get borders
  1145. start_x = data.getFloat64(c, !0);
  1146. c += 8;
  1147. start_y = data.getFloat64(c, !0);
  1148. c += 8;
  1149. end_x = data.getFloat64(c, !0);
  1150. c += 8;
  1151. end_y = data.getFloat64(c, !0);
  1152. c += 8;
  1153. center_x = (start_x + end_x) / 2;
  1154. center_y = (start_y + end_y) / 2;
  1155. length_x = Math.abs(start_x - end_x);
  1156. length_y = Math.abs(start_y - end_y);
  1157. }
  1158. }
  1159.  
  1160. function extractSendPacket(data) {
  1161. var view = new DataView(data);
  1162. switch (view.getUint8(0, true)) {
  1163. case 0:
  1164. player_name = [];
  1165. for (var i=1; i < data.byteLength; i+=2) {
  1166. player_name.push(view.getUint16(i, true));
  1167. }
  1168.  
  1169. miniMapSendRawData(msgpack.pack({
  1170. type: 0,
  1171. data: player_name
  1172. }));
  1173. break;
  1174. }
  1175. }
  1176.  
  1177. // the injected point, overwriting the WebSocket constructor
  1178. window.WebSocket = function(url, protocols) {
  1179. console.log('Listen');
  1180.  
  1181. if (protocols === undefined) {
  1182. protocols = [];
  1183. }
  1184.  
  1185. var ws = new _WebSocket(url, protocols);
  1186.  
  1187. refer(this, ws, 'binaryType');
  1188. refer(this, ws, 'bufferedAmount');
  1189. refer(this, ws, 'extensions');
  1190. refer(this, ws, 'protocol');
  1191. refer(this, ws, 'readyState');
  1192. refer(this, ws, 'url');
  1193.  
  1194. this.send = function(data){
  1195. extractSendPacket(data);
  1196. return ws.send.call(ws, data);
  1197. };
  1198.  
  1199. this.close = function(){
  1200. return ws.close.call(ws);
  1201. };
  1202.  
  1203. this.onopen = function(event){};
  1204. this.onclose = function(event){};
  1205. this.onerror = function(event){};
  1206. this.onmessage = function(event){};
  1207.  
  1208. ws.onopen = function(event) {
  1209. var ret;
  1210. if (this.onopen)
  1211. ret = this.onopen.call(ws, event);
  1212. miniMapInit();
  1213. agarServerAddress = this.url;
  1214. miniMapSendRawData(msgpack.pack({
  1215. type: 100,
  1216. data: getAgarServerInfo(),
  1217. }));
  1218. miniMapSendRawData(msgpack.pack({type: 50}));
  1219. return ret;
  1220. }.bind(this);
  1221.  
  1222. ws.onmessage = function(event) {
  1223. var ret;
  1224. if (this.onmessage)
  1225. ret = this.onmessage.call(ws, event);
  1226. if(injectOnMessage){
  1227. extractPacket(event);
  1228. }
  1229. return ret;
  1230. }.bind(this);
  1231.  
  1232. ws.onclose = function(event) {
  1233. if (this.onclose)
  1234. return this.onclose.call(ws, event);
  1235. }.bind(this);
  1236.  
  1237. ws.onerror = function(event) {
  1238. if (this.onerror)
  1239. return this.onerror.call(ws, event);
  1240. }.bind(this);
  1241. };
  1242.  
  1243. window.WebSocket.prototype = _WebSocket;
  1244.  
  1245. $(window.document).ready(function() {
  1246. miniMapInit();
  1247. });
  1248.  
  1249. window.Minimap = {
  1250. /* official server message */
  1251. Clear : function(){
  1252. current_cell_ids = [];
  1253. },
  1254. UpdateData : function(data){
  1255. var packet = {
  1256. type: 16,
  1257. data: data
  1258. };
  1259. miniMapSendRawData(msgpack.pack(packet));
  1260. },
  1261. OwnCell : function(id){
  1262. if (current_cell_ids.indexOf(id) === -1)
  1263. current_cell_ids.push(id);
  1264.  
  1265. miniMapSendRawData(msgpack.pack({
  1266. type: 32,
  1267. data: id
  1268. }));
  1269. },
  1270. SetGameAreaSize : function(mapLeft, mapTop, mapRight, mapBottom){
  1271. start_x = mapLeft;
  1272. start_y = mapTop;
  1273. end_x = mapRight;
  1274. end_y = mapBottom;
  1275. center_x = (start_x + end_x) / 2;
  1276. center_y = (start_y + end_y) / 2;
  1277. length_x = Math.abs(start_x - end_x);
  1278. length_y = Math.abs(start_y - end_y);
  1279. },
  1280.  
  1281. /* Map operation */
  1282. MiniMapUnregisterTokenLocal : function(id){
  1283. if (map_server === null || map_server.readyState !== window._WebSocket.OPEN) {
  1284. miniMapUnregisterToken(id);
  1285. }
  1286. },
  1287. MiniMapUpdateToken : function (id, color, x, y, size) {
  1288. if (map_server === null || map_server.readyState !== window._WebSocket.OPEN) {
  1289. if (!miniMapIsRegisteredToken(id)) {
  1290. miniMapRegisterToken(
  1291. id,
  1292. miniMapCreateToken(id, color)
  1293. );
  1294. }
  1295. miniMapUpdateToken(id,
  1296. (x - start_x)/length_x,
  1297. (y - start_y)/length_y,
  1298. size / length_x);
  1299. }
  1300. },
  1301. MiniMapUpdatePos : function(x, y) {
  1302. miniMapUpdatePos(x, y);
  1303. },
  1304.  
  1305. /* API */
  1306. ToggleSidebar : function(){
  1307. $('#sidebar-wrapper').toggleClass('toggled');
  1308. },
  1309.  
  1310. /* Data Object */
  1311. MapEvent : mapEvent,
  1312. };
  1313.  
  1314. })();
  1315.  
  1316. window.addEventListener('keydown', keydown);
  1317. window.addEventListener('keyup', keyup);
  1318. var Feed = false;
  1319. var Dingus = false;
  1320. var imlost = 25;
  1321. document.getElementById("instructions").innerHTML += "<center><span class='text-muted'><span data-itr='instructions_e'> Press <b>Q</b> to Tricksplit</span></span></center>";
  1322. document.getElementById("instructions").innerHTML += "<center><span class='text-muted'><span data-itr='instructions_3'> Press <b>Z</b> to Triplesplit</span></span></center>";
  1323. document.getElementById("instructions").innerHTML += "<center><span class='text-muted'><span data-itr='instructions_d'> Press <b>D</b> to Doublesplit</span></span></center>";
  1324. document.getElementById("instructions").innerHTML += "<center><span class='text-muted'><span data-itr='instructions_d'> Press <b>R</b> to Popsplit</span></span></center>";
  1325. document.getElementById("instructions").innerHTML += "<center><span class='text-muted'><span data-itr='instructions_q'> Press and hold <b>W</b> for macro feed</span></span></center>";
  1326. load();
  1327. function load() {
  1328. if (document.getElementById("overlays").style.display!="none") {
  1329. document.getElementById("settings").style.display = "block";
  1330. if (document.getElementById('showMass').checked) {document.getElementById('showMass').click();}
  1331. document.getElementById('showMass').click();
  1332. if (document.getElementById('darkTheme').checked) {document.getElementById('darkTheme').click();}
  1333. document.getElementById('darkTheme').click();
  1334. // Don't switch the code becauce the script will not work !
  1335. } else {
  1336. setTimeout(load, 100);
  1337. }
  1338. }
  1339. function keydown(event) {
  1340. if (event.keyCode == 87) {
  1341. Feed = true;
  1342. setTimeout(fukherriteindapussie, imlost);
  1343. } // Tricksplit
  1344. if (event.keyCode == 81) {
  1345. ilikedick();
  1346. setTimeout(ilikedick, imlost);
  1347. setTimeout(ilikedick, imlost*2);
  1348. setTimeout(ilikedick, imlost*3);
  1349. } // Triplesplit
  1350. if (event.keyCode == 90) {
  1351. ilikedick();
  1352. setTimeout(ilikedick, imlost);
  1353. setTimeout(ilikedick, imlost*2);
  1354. } // Doublesplit
  1355. if (event.keyCode == 68) {
  1356. ilikedick();
  1357. setTimeout(ilikedick, imlost);
  1358. } // PopSplit
  1359. if (event.keyCode == 82) {
  1360. ilikedick();
  1361. setTimeout(ilikedick, imlost*5.32232210323424323);
  1362. }
  1363. } // When Player Lets Go Of W, It Stops Feeding
  1364. function keyup(event) {
  1365. if (event.keyCode == 87) {
  1366. Feed = false;
  1367. }
  1368. if (event.keyCode == 79) {
  1369. Dingus = false;
  1370. }
  1371. }
  1372. // Feed Macro With W
  1373. function fukherriteindapussie() {
  1374. if (Feed) {
  1375. window.onkeydown({keyCode: 87});
  1376. window.onkeyup({keyCode: 87});
  1377. setTimeout(fukherriteindapussie, imlost);
  1378. }
  1379. }
  1380. function ilikedick() {
  1381. $("body").trigger($.Event("keydown", { keyCode: 32}));
  1382. $("body").trigger($.Event("keyup", { keyCode: 32}));
  1383. }
Add Comment
Please, Sign In to add comment