Hordes.io Auto Aim Mod

Hordes.io Auto Aim Mod - Beta.

  1. // ==UserScript==
  2. // @name Hordes.io Auto Aim Mod
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Hordes.io Auto Aim Mod - Beta.
  6. // @author You
  7. // @match Hordes.io
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Your code here...
  15. })(); var playersNear = [];
  16. var ws;
  17. var id;
  18. var f = 0;
  19. var user;
  20. var canvas = document.querySelector("#gameCanvas");
  21. var currentTarget;
  22. var state = EnumStates.BOTH;
  23.  
  24. function Player(id, x, y, tribe){
  25. this.id = id;
  26. this.x = x;
  27. this.y = y;
  28. this.tribe = tribe;
  29. }
  30. Player.prototype.getAngle = function(){
  31. return Math.atan2(this.deltaY, this.deltaX);
  32. };
  33.  
  34. Player.prototype.getDistance = function(){
  35. return Math.sqrt(Math.pow(this.deltaX, 2) + Math.pow(this.deltaY, 2));
  36. };
  37.  
  38. function lookAtPointRelativeToCharacter(x, y){
  39. var centerX = innerWidth / 2;
  40. var centerY = innerHeight / 2;
  41. canvas.dispatchEvent(new MouseEvent("mousemove", {
  42. clientX: centerX + x,
  43. clientY: centerY + y
  44. }));
  45. }
  46.  
  47. WebSocket.prototype.oldSend = WebSocket.prototype.send;
  48. WebSocket.prototype.send = function(m){
  49. var parsed = parseWSMsg(m);
  50. this.oldSend(currentTarget && parsed[0] === "2" ? "42[\"2\"," + currentTarget.getAngle() + "]" : m);
  51. if (!ws){
  52. ws = this;
  53. socketFound(this);
  54. }
  55. };
  56.  
  57. function socketFound(socket){
  58. console.log("found socket object");
  59. socket.addEventListener('message', function(e){
  60. handleMessage(e);
  61. });
  62. }
  63.  
  64. function handleMessage(e){
  65. var m = e.data;
  66. //console.log(m);
  67. var parsed = parseWSMsg(m);
  68. if (parsed[0] === "3"){ //position update
  69. playersNear = [];
  70. var data = parsed[1];
  71. for (var i = 0; i < data.length ; i += 12) { //loop to assign chunks of the array to a player
  72. var playerData = data.slice(i, i + 12);
  73. var player = new Player(playerData[0], playerData[1], playerData[2], playerData[7]);
  74. //console.log(player.id,player.x,player.y);
  75. if (player.id !== id) playersNear.push(player);
  76. else user = player;
  77. }
  78. if (currentTarget) currentTarget = null; //reset it, it'll be updated soon
  79. if ((state === EnumStates.AIM || state === EnumStates.BOTH) && playersNear.length > 0){
  80. var closestPlayer = getClosestPlayer();
  81. if (closestPlayer.getDistance() < 200 && (closestPlayer.tribe !== user.tribe || user.tribe === null)) aimAt(closestPlayer);
  82. }
  83. }
  84. if (parsed[0] === "1" && !id){
  85. id = parsed[1];
  86. console.log("id found: " + id);
  87. }
  88. if (parsed[0] === "10" && parsed[1] === id && parsed[2] !== 100 && (state === EnumStates.HEAL || state === EnumStates.BOTH)){
  89. heal();
  90. }
  91. }
  92.  
  93. function aimAt(target){
  94. lookAtPointRelativeToCharacter(target.deltaX, target.deltaY);
  95. currentTarget = target;
  96. }
  97.  
  98. function getClosestPlayer(){
  99. var closestPlayer;
  100. for (var i = 0 ; i < playersNear.length; i++){
  101. var currentPlayer = playersNear[i];
  102. currentPlayer.deltaX = currentPlayer.x - user.x;
  103. currentPlayer.deltaY = currentPlayer.y - user.y;
  104. if (i === 0 || currentPlayer.getDistance() < closestPlayer.getDistance()){
  105. closestPlayer = currentPlayer;
  106. }
  107. }
  108. return closestPlayer;
  109. }
  110.  
  111. function parseWSMsg(s){
  112. if (s.indexOf("42") === -1) return -1;
  113. var o = s.substring(s.indexOf("["));
  114. return JSON.parse(o);
  115. }