Advertisement
Nolifeq

auto x

Apr 15th, 2021 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.61 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Autox z menu
  3. // @version 1.0
  4. // @author yetrr#4049
  5. // @match https://*.margonem.pl/
  6. // @grant none
  7. // ==/UserScript==
  8.  
  9. /* Konfiguracja */
  10. const SCRIPT_CONFIG = {
  11. whitelist: [],
  12. blacklist: [],
  13. mapStatus: 2,
  14. hz: 100,
  15. };
  16.  
  17. const CONFIG = localStorage.getItem("autox-config") !== null ? JSON.parse(localStorage.getItem("autox-config")) : {
  18. windowPosition: ["0px", "0px"],
  19. windowExpanded: true,
  20. enabled: true,
  21. follow: true,
  22. distance: 15,
  23. attackClan: false,
  24. attackFriends: false,
  25. attackAllies: false,
  26. autoFight: false,
  27. minLvl: 100,
  28. maxLvl: 200,
  29. };
  30.  
  31. !function load() {
  32. const box = document.createElement("div");
  33. box.style.left = CONFIG.windowPosition[0];
  34. box.style.top = CONFIG.windowPosition[1];
  35. box.id = "autox-box";
  36.  
  37. if (CONFIG.windowExpanded) {
  38. box.style.height = "273px";
  39. } else {
  40. box.style.height = "30px";
  41. }
  42.  
  43. const header = document.createElement("div");
  44. header.id = "autox-header";
  45.  
  46. const label = document.createElement("span");
  47. label.classList.add("noselect");
  48. label.style.paddingLeft = "10px";
  49. label.textContent = "Konfiguracja autox";
  50. header.appendChild(label);
  51.  
  52. const discord = document.createElement("img");
  53. discord.classList.add("noselect");
  54. discord.style.width = "20px";
  55. discord.style.height = "20px";
  56. discord.style.position = "fixed";
  57. discord.style.paddingLeft = "3px";
  58. discord.src = "https://i.imgur.com/Kq27VR5.png";
  59. discord.tip = "Discord: yetrr#4049";
  60.  
  61. discord.addEventListener("click", () => {
  62. if (CONFIG.windowExpanded) {
  63. box.style.height = "30px";
  64. } else {
  65. box.style.height = "273px";
  66. }
  67.  
  68. CONFIG.windowExpanded = !CONFIG.windowExpanded;
  69. toggleItemsVisibility();
  70. saveConfig();
  71. });
  72.  
  73. const icon = document.createElement("span");
  74. icon.style.marginLeft = "28px";
  75. header.append(discord, icon);
  76.  
  77. icon.addEventListener("click", () => {
  78. if (icon.classList.toString().includes("button-toggle-active")) {
  79. icon.classList.remove("button-toggle-active");
  80. icon.classList.add("button-toggle-inactive");
  81. } else {
  82. icon.classList.remove("button-toggle-inactive");
  83. icon.classList.add("button-toggle-active");
  84. }
  85.  
  86. CONFIG.enabled = !CONFIG.enabled;
  87. saveConfig();
  88. });
  89.  
  90. const slider = document.createElement("div");
  91. slider.classList.add("autox-dummy-item");
  92. slider.style.textAlign = "center";
  93. slider.style.paddingBottom = "10px";
  94.  
  95. const sliderLabel = document.createElement("div");
  96. sliderLabel.classList.add("noselect");
  97. sliderLabel.style.textAlign = "center";
  98. sliderLabel.textContent = "Dystans: " + CONFIG.distance;
  99.  
  100. const sliderInput = document.createElement("input");
  101. sliderInput.classList.add("slider");
  102. sliderInput.type = "range";
  103. sliderInput.min = "1";
  104. sliderInput.max = "16";
  105.  
  106. slider.append(sliderLabel, sliderInput);
  107.  
  108. sliderInput.addEventListener("mousemove", () => {
  109. CONFIG.distance = sliderInput.value;
  110. sliderLabel.textContent = "Dystans: " + CONFIG.distance;
  111. saveConfig();
  112. });
  113.  
  114. box.append(header, slider);
  115.  
  116. createConfigToggleableItem(box, "Pościg za graczem", CONFIG.follow, () => CONFIG.follow = !CONFIG.follow);
  117. createConfigToggleableItem(box, "Atakuj przyjaciół", CONFIG.attackFriends, () => CONFIG.attackFriends = !CONFIG.attackFriends);
  118. createConfigToggleableItem(box, "Atakuj klanowiczów", CONFIG.attackClan, () => CONFIG.attackClan = !CONFIG.attackClan);
  119. createConfigToggleableItem(box, "Atakuj sojuszników", CONFIG.attackAllies, () => CONFIG.attackAllies = !CONFIG.attackAllies);
  120. createConfigToggleableItem(box, "Szybka walka", CONFIG.autoFight, () => CONFIG.autoFight = !CONFIG.autoFight);
  121. createLevelInput(box, "Minimalny poziom", CONFIG.minLvl, (div) => div.style.paddingBottom = "5px", (input) => CONFIG.minLvl = input.value);
  122. createLevelInput(box, "Maksymalny poziom", CONFIG.maxLvl, () => {
  123. }, (input) => CONFIG.maxLvl = input.value);
  124.  
  125. document.body.appendChild(box);
  126. initStyle();
  127.  
  128. icon.classList.add(CONFIG.enabled ? "button-toggle-active" : "button-toggle-inactive");
  129. toggleItemsVisibility();
  130.  
  131. draggable(box, "", "autox-drag")
  132. }();
  133.  
  134. function draggable(a, b, c) {
  135. const d = this;
  136. const f = `undefined` !== typeof window.orientation || -1 !== navigator.userAgent.indexOf(`IEMobile`);
  137. a.ondragstart = () => {
  138. }
  139.  
  140. a.addEventListener(f ? `touchstart` : `mousedown`, b => {
  141. window.g.lock.add(`autox-drag`);
  142. `INPUT` === b.target.tagName || (d[c] = !0,
  143. f && (d.x = b.touches[0].pageX,
  144. d.y = b.touches[0].pageY),
  145. d.start_x = d.x - a.offsetLeft,
  146. d.start_y = d.y - a.offsetTop)
  147. });
  148.  
  149. document.addEventListener(f ? `touchmove` : `mousemove`, b => {
  150. if (b.pageX && (d.x = b.pageX, d.y = b.pageY), f && (d.x = b.touches[0].pageX, d.y = b.touches[0].pageY), d[c]) {
  151. let b = a.offsetWidth,
  152. c = a.offsetHeight,
  153. e = d.x - d.start_x,
  154. f = d.y - d.start_y;
  155.  
  156. 0 > e && (e = 0);
  157. e + b > window.innerWidth && (e = window.innerWidth - b);
  158. a.style.left = `${e}px`;
  159. 0 > f && (f = 0);
  160. f + c > window.innerHeight && (f = window.innerHeight - c);
  161. a.style.top = `${f}px`;
  162. }
  163. });
  164.  
  165. document.addEventListener(f ? `touchend` : `mouseup`, () => {
  166. window.g.lock.remove(`autox-drag`);
  167. CONFIG.windowPosition[0] = a.style.left;
  168. CONFIG.windowPosition[1] = a.style.top;
  169. saveConfig();
  170. d[c] = !1;
  171. });
  172. }
  173.  
  174. function initStyle() {
  175. const style = document.createElement("style");
  176.  
  177. const text =
  178. "#autox-box {" +
  179. "position: absolute;" +
  180. "z-index: 9999;" +
  181. "background: rgba(0, 0, 0, 0.5);" +
  182. "border: 2px solid gold;" +
  183. "border-radius: 15px;" +
  184. "width: 200px;" +
  185. "height: 273px;" +
  186. "}" +
  187.  
  188. "#autox-header {" +
  189. "height: 20px;" +
  190. "border-radius: 15px;" +
  191. "padding-top: 5px;" +
  192. "padding-bottom: 5px;" +
  193. "color: white;" +
  194. "text-align: center;" +
  195. "}" +
  196.  
  197. ".button-toggle-active {" +
  198. "position: relative;" +
  199. "top: 1px;" +
  200. "width: 18px;" +
  201. "height: 18px;" +
  202. "border-radius: 20px;" +
  203. "margin: 0 5px;" +
  204. "display: inline-block;" +
  205. "-webkit-transition: -webkit-box-shadow .2s ease-in-out;" +
  206. "transition: -webkit-box-shadow .2s ease-in-out;" +
  207. "transition: box-shadow .2s ease-in-out;" +
  208. "transition: box-shadow .2s ease-in-out,-webkit-box-shadow .2s ease-in-out;" +
  209. "background: radial-gradient(ellipse at center,#46a31d 0,#101010 100%);" +
  210. "-webkit-box-shadow: 0 0 5px 2px #46a31d;" +
  211. "box-shadow: 0 0 5px 2px #46a31d;" +
  212. "}" +
  213.  
  214. ".button-toggle-inactive {" +
  215. "position: relative;" +
  216. "top: 1px;" +
  217. "width: 18px;" +
  218. "height: 18px;" +
  219. "border-radius: 20px;" +
  220. "margin: 0 5px;" +
  221. "display: inline-block;" +
  222. "-webkit-transition: -webkit-box-shadow .2s ease-in-out;" +
  223. "transition: -webkit-box-shadow .2s ease-in-out;" +
  224. "transition: box-shadow .2s ease-in-out;" +
  225. "transition: box-shadow .2s ease-in-out,-webkit-box-shadow .2s ease-in-out;" +
  226. "background: radial-gradient(ellipse at center,red 0,#101010 100%);" +
  227. "-webkit-box-shadow: 0 0 5px 2px red;" +
  228. "box-shadow: 0 0 5px 2px red;" +
  229. "}" +
  230.  
  231. ".button-toggle-yellow {" +
  232. "position: relative;" +
  233. "top: 1px;" +
  234. "width: 18px;" +
  235. "height: 18px;" +
  236. "border-radius: 20px;" +
  237. "margin: 0 5px;" +
  238. "display: inline-block;" +
  239. "-webkit-transition: -webkit-box-shadow .2s ease-in-out;" +
  240. "transition: -webkit-box-shadow .2s ease-in-out;" +
  241. "transition: box-shadow .2s ease-in-out;" +
  242. "transition: box-shadow .2s ease-in-out,-webkit-box-shadow .2s ease-in-out;" +
  243. "background: radial-gradient(ellipse at center,yellow 0,#101010 100%);" +
  244. "-webkit-box-shadow: 0 0 5px 2px yellow;" +
  245. "box-shadow: 0 0 5px 2px yellow;" +
  246. "}" +
  247.  
  248. ".slider {" +
  249. "-webkit-appearance: none;" +
  250. "width: 90%;" +
  251. "height: 15px;" +
  252. "border-radius: 5px; " +
  253. "background: #d3d3d3;" +
  254. "outline: none;" +
  255. "-webkit-transition: .2s;" +
  256. "transition: opacity .2s;" +
  257. "}" +
  258.  
  259. ".slider::-webkit-slider-thumb {" +
  260. "-webkit-appearance: none;" +
  261. "appearance: none;" +
  262. "width: 19px;" +
  263. "height: 19px;" +
  264. "border-radius: 50%;" +
  265. "background: radial-gradient(ellipse at center,#46a31d 0,#101010 100%);" +
  266. "-webkit-box-shadow: 0 0 5px 2px #46a31d;" +
  267. "box-shadow: 0 0 5px 2px #46a31d;" +
  268. "cursor: pointer;" +
  269. "}" +
  270.  
  271. ".autox-item {" +
  272. "padding-bottom: 3px;" +
  273. "}" +
  274.  
  275. ".autox-dummy-item {}" +
  276.  
  277. ".noselect {" +
  278. "-webkit-touch-callout: none;" +
  279. "-webkit-user-select: none;" +
  280. "-khtml-user-select: none;" +
  281. "-moz-user-select: none;" +
  282. "-ms-user-select: none;" +
  283. "user-select: none;" +
  284. "}" +
  285.  
  286. "*:focus {" +
  287. "outline: 0;" +
  288. "}";
  289.  
  290. style.appendChild(document.createTextNode(text));
  291. document.head.appendChild(style);
  292. }
  293.  
  294. function createConfigToggleableItem(parent, label, value, wrapper) {
  295. const div = document.createElement("div"), icon = document.createElement("span"),
  296. text = document.createElement("span");
  297. div.classList.add("autox-item", "noselect"), text.textContent = label, div.append(icon, text);
  298. icon.classList.add(value ? "button-toggle-active" : "button-toggle-inactive"), parent.appendChild(div);
  299.  
  300. icon.addEventListener("click", () => {
  301. if (icon.classList.toString().includes("button-toggle-active")) {
  302. icon.classList.remove("button-toggle-active");
  303. icon.classList.add("button-toggle-inactive");
  304. } else {
  305. icon.classList.remove("button-toggle-inactive");
  306. icon.classList.add("button-toggle-active");
  307. }
  308.  
  309. wrapper();
  310. saveConfig();
  311. });
  312. }
  313.  
  314. function createLevelInput(parent, text, value, callback = () => {
  315. }, changeCallback) {
  316. const div = document.createElement("div"), label = document.createElement("p"),
  317. input = document.createElement("input");
  318. div.classList.add("autox-dummy-item", "noselect"), input.classList.add("noselect");
  319. label.textContent = text;
  320. input.maxLength = 3;
  321. input.style.background = "#d3d3d3";
  322. input.style.height = "12px";
  323. input.style.textAlign = "center";
  324. input.style.borderRadius = "5px";
  325. input.style.outline = "none";
  326. input.style.webkitAppearance = "none";
  327. input.type = "text";
  328. div.style.textAlign = "center";
  329. input.value = value;
  330. callback(div);
  331.  
  332. input.addEventListener("change", () => {
  333. changeCallback(input);
  334. saveConfig();
  335. });
  336.  
  337. div.append(label, input);
  338. parent.append(div);
  339. }
  340.  
  341. function toggleItemsVisibility() {
  342. Array.from(document.getElementsByClassName("autox-item")).concat(Array.from(document.getElementsByClassName("autox-dummy-item"))).forEach(item => {
  343. item.style.visibility = CONFIG.windowExpanded ? "visible" : "hidden";
  344. });
  345. }
  346.  
  347. function saveConfig() {
  348. localStorage.setItem("autox-config", JSON.stringify(CONFIG));
  349. }
  350.  
  351. class AStar {
  352. constructor(collisionsString, width, height, start, end, additionalCollisions) {
  353. this.width = width;
  354. this.height = height;
  355. this.collisions = this.parseCollisions(collisionsString, width, height);
  356. this.additionalCollisions = additionalCollisions || {};
  357. this.start = this.collisions[start.x][start.y];
  358. this.end = this.collisions[end.x][end.y];
  359. this.start.beginning = true;
  360. this.start.g = 0;
  361. this.start.f = heuristic(this.start, this.end);
  362. this.end.target = true;
  363. this.end.g = 0;
  364. this.addNeighbours();
  365. this.openSet = [];
  366. this.closedSet = [];
  367. this.openSet.push(this.start);
  368. }
  369.  
  370. parseCollisions(collisionsString, width, height) {
  371. const collisions = new Array(width);
  372.  
  373. for (let w = 0; w < width; w++) {
  374. collisions[w] = new Array(height);
  375.  
  376. for (let h = 0; h < height; h++) {
  377. collisions[w][h] = new Point(w, h, collisionsString.charAt(w + h * width) === '1');
  378. }
  379. }
  380.  
  381. return collisions;
  382. }
  383.  
  384. addNeighbours() {
  385. for (let i = 0; i < this.width; i++) {
  386. for (let j = 0; j < this.height; j++) {
  387. this.addPointNeighbours(this.collisions[i][j]);
  388. }
  389. }
  390. }
  391.  
  392. addPointNeighbours(point) {
  393. const x = point.x;
  394. const y = point.y;
  395. const neighbours = [];
  396. if (x > 0) neighbours.push(this.collisions[x - 1][y]);
  397. if (y > 0) neighbours.push(this.collisions[x][y - 1]);
  398. if (x < this.width - 1) neighbours.push(this.collisions[x + 1][y]);
  399. if (y < this.height - 1) neighbours.push(this.collisions[x][y + 1]);
  400. point.neighbours = neighbours;
  401. }
  402.  
  403. anotherFindPath() {
  404. while (this.openSet.length > 0) {
  405. let currentIndex = this.getLowestF();
  406. let current = this.openSet[currentIndex];
  407.  
  408. if (current === this.end) {
  409. return this.reconstructPath();
  410. } else {
  411. this.openSet.splice(currentIndex, 1);
  412. this.closedSet.push(current);
  413.  
  414. for (const neighbour of current.neighbours) {
  415. if (!this.closedSet.includes(neighbour)) {
  416. const tentative_score = current.g + 1;
  417. let isBetter = false;
  418.  
  419. if (this.end == this.collisions[neighbour.x][neighbour.y] || (!this.openSet.includes(neighbour) && !neighbour.collision && !this.additionalCollisions[neighbour.x + 256 * neighbour.y])) {
  420. this.openSet.push(neighbour);
  421. neighbour.h = heuristic(neighbour, this.end);
  422. isBetter = true;
  423. } else if (tentative_score < neighbour.g && !neighbour.collision) {
  424. isBetter = true;
  425. }
  426.  
  427. if (isBetter) {
  428. neighbour.previous = current;
  429. neighbour.g = tentative_score;
  430. neighbour.f = neighbour.g + neighbour.h;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }
  437.  
  438. getLowestF() {
  439. let lowestFIndex = 0;
  440.  
  441. for (let i = 0; i < this.openSet.length; i++) {
  442. if (this.openSet[i].f < this.openSet[lowestFIndex].f) {
  443. lowestFIndex = i;
  444. }
  445. }
  446.  
  447. return lowestFIndex;
  448. }
  449.  
  450. reconstructPath() {
  451. const path = [];
  452. let currentNode = this.end;
  453.  
  454. while (currentNode !== this.start) {
  455. path.push(currentNode);
  456. currentNode = currentNode.previous;
  457. }
  458.  
  459. return path;
  460. }
  461. }
  462.  
  463. class Point {
  464. constructor(x, y, collision) {
  465. this.x = x;
  466. this.y = y;
  467. this.collision = collision;
  468. this.g = 10000000;
  469. this.f = 10000000;
  470. this.neighbours = [];
  471. this.beginning = false;
  472. this.target = false;
  473. this.previous = undefined;
  474. }
  475. }
  476.  
  477. const heuristic = (p1, p2) => {
  478. return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);
  479. }
  480.  
  481. const getWay = (x, y) => {
  482. return (new AStar(map.col, map.x, map.y, {x: hero.x, y: hero.y}, {x: x, y: y}, g.npccol)).anotherFindPath();
  483. }
  484.  
  485. const goTo = (x, y) => {
  486. let _road_ = getWay(x, y);
  487.  
  488. if (!Array.isArray(_road_)) {
  489. return;
  490. }
  491.  
  492. road = _road_;
  493. }
  494.  
  495. const _PI = parseInput;
  496.  
  497. parseInput = (a, b, c) => {
  498. _PI(a, b, c);
  499.  
  500. if (g.battle && $("#autobattleButton").css("display") == "block" && CONFIG.autoFight) {
  501. $("#autobattleButton").click();
  502. }
  503. };
  504.  
  505. const attackNearbyOrFollow = player => {
  506. if (Math.abs(hero.x - player.x) <= 1 && Math.abs(hero.y - player.y) <= 1) {
  507. return _g(`fight&a=attack&id=${player.id}`);
  508. } else if (CONFIG.follow) {
  509. return goTo(player.x, player.y);
  510. }
  511. }
  512.  
  513. function canMove(x, y) {
  514. for (let it in g.townname) {
  515. let coords = g.gwIds[it].split(".");
  516.  
  517. if (coords[0] == x && coords[1] == y) {
  518. return false;
  519. }
  520. }
  521.  
  522. return true;
  523. }
  524.  
  525. const checkIfShouldAttack = player => {
  526. if (g.dead || g.battle || !CONFIG.enabled) {
  527. return false;
  528. }
  529.  
  530. if (Math.sqrt(Math.pow(hero.x - player.x, 2) + Math.pow(hero.y - player.y, 2)) > CONFIG.distance) {
  531. return false;
  532. }
  533.  
  534. if (SCRIPT_CONFIG.blacklist.includes(player.nick)) {
  535. return true;
  536. }
  537.  
  538. if (!CONFIG.attackFriends && player.relation == "fr" || !CONFIG.attackClan && player.relation == "cl" || !CONFIG.attackAllies && player.relation == "cl-fr") {
  539. return false;
  540. }
  541.  
  542. if (SCRIPT_CONFIG.whitelist.includes(player.nick)) {
  543. return false;
  544. }
  545.  
  546. return canMove(player.x, player.y) && player.lvl >= CONFIG.minLvl && player.lvl <= CONFIG.maxLvl;
  547. }
  548.  
  549. const old = newOther;
  550.  
  551. newOther = players => {
  552. if (map.pvp != SCRIPT_CONFIG.mapStatus) {
  553. return old(players);
  554. }
  555.  
  556. for (const id in players) {
  557. if (!player || !players[id].x || !g.other[id]) {
  558. continue;
  559. }
  560.  
  561. if (checkIfShouldAttack(g.other[id])) {
  562. attackNearbyOrFollow(g.other[id]);
  563. }
  564. }
  565.  
  566. return old(players);
  567. }
  568.  
  569. g.loadQueue.push({
  570. fun: () => {
  571. if (map.pvp == SCRIPT_CONFIG.mapStatus) {
  572. setInterval(() => {
  573. for (const player of Object.values(g.other)) {
  574. if (checkIfShouldAttack(player)) {
  575. attackNearbyOrFollow(player);
  576. break;
  577. }
  578. }
  579. }, SCRIPT_CONFIG.hz);
  580. }
  581. }
  582. });
  583.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement