Advertisement
Guest User

Untitled

a guest
Sep 18th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.87 KB | None | 0 0
  1. import { Library, PacketHook,Client } from './../core';
  2.  
  3. import { UpdatePacket, AccountListPacket,TradeRequestedPacket,TradeStartPacket, TradeChangedPacket, TradeDonePacket } from './../networking/packets/incoming';
  4. import { RequestTradePacket,ChangeTradePacket, AcceptTradePacket,InvSwapPacket } from './../networking/packets/outgoing';
  5. import { Classes, AccountInfo,Account } from '../models';
  6. import {Storage} from './../services';
  7. import { CLI } from '../cli';
  8. import fs = require('fs');
  9. import './../../acc-config.json'
  10. import { WorldPosData, SlotObjectData } from '../networking';
  11. const readline = require('readline');
  12.  
  13. @Library({
  14. name: 'Bot Automation',
  15. author: 'Gabes',
  16. enabled: false
  17. })
  18.  
  19.  
  20.  
  21. class YourPluginName {
  22.  
  23. private assigned:boolean = false;
  24. private server:string;
  25. private username:string;
  26. private objectType:number;
  27. private class:string;
  28. private classinfo:Map<string, number[]> = new Map<string,number[]>();
  29. private vaulted:boolean = false;
  30. private currentClass:string;
  31. private currentPotion:number; // matches to the potion in the array below
  32. private potionNumbers:string[] = ['dex','spd','wis','vit','att','def','mana','life'];
  33. private currentClientOffer:boolean[] = [];
  34. private currentPartnerOffer:boolean[] = [false,false,false,false,false,false,false,false];
  35. private count: number = 0;
  36. private accounts:string[];
  37. constructor() {
  38. //reads the accounts
  39. let data = fs.readFileSync('./../../Dan/nrelay/acc.txt').toString('utf-8'); {
  40. this.accounts = data.split("\n")
  41. };
  42. //creates a readline
  43. const rl = readline.createInterface({
  44. input: process.stdin,
  45. output: process.stdout
  46. });
  47. rl.on('line', (this.command));
  48. }
  49. public command(input:string): void {
  50. //checks input
  51. if (input.length <= 0) {
  52. return;
  53. }
  54. //trade:AsiaSouthEast:LukeFlame:Warrior,0,2,0,0,0,0,0,0
  55. //trade:server:username:class1,amount of dex,amount of spd,wis,vit,att,def,mana,life:class2,amount of dex,spd,wis,vit,att,def,mana,life, etc.
  56. //assigns classes
  57. let command = input.split(':');
  58. if (command[0]!=='trade') {
  59. return;
  60. }
  61. let classinfo:Map<string, number[]> = new Map<string,number[]>();
  62. this.server = command[1];
  63. this.username = command[2];
  64. for (let i = 3;i<command.length;i++) {
  65. let potions = command[i].split(',');
  66. let classPotions:number[] = [];
  67. for (let j = 1;j<potions.length;j++) {
  68. classPotions.push(parseInt(potions[j]));
  69.  
  70. }
  71. for (let i = 0;i<classPotions.length;i++) {
  72. console.log(classPotions[i]);
  73. }
  74. console.log(potions[0]);
  75. classinfo.set(potions[0],classPotions);
  76. }
  77. this.assigned = true;
  78. this.classinfo = classinfo;
  79. for (let key in this.classinfo.keys()) {
  80. let potInfo = this.classinfo.get(key);
  81. for (let i = 0;i<potInfo.length;i++) {
  82. if (potInfo[i] !== 0) {
  83. this.currentClass = key;
  84. this.currentPotion = i;
  85. this.tradeclass(this.potionNumbers[i]);
  86. return;
  87. }
  88. }
  89. }
  90. }
  91. tradeclass(potionType:string) {
  92. //add a client
  93. if (this.assigned) {
  94. for (let i = 0;i<this.accounts.length;i++) {
  95. let accountInfoSplit = this.accounts[i].split(':');
  96. if (accountInfoSplit[2] === potionType) {
  97. let account = {alias: accountInfoSplit[2],guid: accountInfoSplit[0],password: accountInfoSplit[1], serverPref: this.server} as Account;
  98. CLI.addClient(account);
  99. return;
  100. }
  101. }
  102. }
  103. }
  104. @PacketHook()
  105. onUpdate(client:Client,updatepacket:UpdatePacket):void {
  106. //takes item if in vault
  107. if (client.mapInfo.name === "Vault") {
  108. for (let x of updatepacket.newObjects) //looping through all newobjects your client recieves
  109. {
  110. if(x.objectType === 0x0504) //vault portals object type, found in the Objects.json
  111. {
  112. let currentVaultItemTypes: number[] = []; // saving the itemTypes temp
  113. for (let index = 0; index < x.status.stats.length; index++) {
  114. if (x.status.stats[index].statType<16 && x.status.stats[index].statType>7) {
  115. currentVaultItemTypes.push(x.status.stats[index].statValue);
  116. // item types needed for invswap packet
  117. }
  118. }
  119. setTimeout(() => {
  120. this.swap(client,currentVaultItemTypes,x.status.objectId);
  121. },this.calculateTime(client,x.status.pos));
  122. }
  123. }
  124. }
  125. //checks if person is here
  126. for (let x of updatepacket.newObjects) {
  127. if (this.assigned = true) {
  128. const temp = x.status.stats;
  129. for (let i = 0;i<temp.length;i++) {
  130. if (temp[i].statType === 31) {
  131. if (temp[i].stringStatValue === this.username) {
  132. console.log('Found: ' + this.username);
  133. this.objectType = x.objectType;
  134. this.class = Classes[x.objectType];
  135. for (let i = 4;i<client.playerData.inventory.length;i++) {
  136. if (client.playerData.inventory[i] !== -1) {
  137. const trade = new RequestTradePacket();
  138. trade.name = this.username;
  139. client.packetio.sendPacket(trade);
  140. return;
  141. }
  142. }
  143. if (this.vaulted) {
  144. this.deleteAcc(client);
  145. this.tradeclass(this.potionNumbers[this.currentPotion]);
  146. }
  147. else {
  148. setTimeout(() => {
  149. client.gameId = -5;
  150. client.connect();
  151. this.vaulted = true;
  152. },3000);
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. @PacketHook()
  161. onTrade(client:Client,tradestart:TradeStartPacket) {
  162. let offer:boolean[] = [];
  163. offer.push(false);
  164. offer.push(false);
  165. offer.push(false);
  166. offer.push(false);
  167. let total = this.classinfo.get(this.currentClass)[this.currentPotion];
  168. for (let i = 4;i<tradestart.clientItems.length;i++) {
  169. if (total === 0) {
  170. offer.push(false);
  171. }
  172. else if (tradestart.clientItems[i].item !== -1) {
  173. total--;
  174. offer.push(true);
  175. this.count++;
  176. }
  177. else {
  178. offer.push(false);
  179. }
  180. }
  181. const selectItems = new ChangeTradePacket();
  182. this.currentClientOffer = offer;
  183. selectItems.offer = this.currentClientOffer;
  184. client.packetio.sendPacket(selectItems);
  185. const acceptTrade = new AcceptTradePacket();
  186. acceptTrade.clientOffer = this.currentClientOffer;
  187. acceptTrade.partnerOffer = this.currentPartnerOffer;
  188. client.packetio.sendPacket(acceptTrade);
  189. }
  190. @PacketHook()
  191. onTradeChange(client:Client,tradechange:TradeChangedPacket) {
  192. this.currentPartnerOffer = tradechange.offer;
  193. const acceptTrade = new AcceptTradePacket();
  194. acceptTrade.clientOffer = this.currentClientOffer;
  195. acceptTrade.partnerOffer = this.currentPartnerOffer;
  196. client.packetio.sendPacket(acceptTrade);
  197. }
  198. @PacketHook()
  199. onTradeDone(client:Client,tradedone:TradeDonePacket) {
  200. /* trying to send the new trade command and check vault
  201. */
  202. if (tradedone.code === 0) {
  203. if (this.vaulted) {
  204. this.deleteAcc(client);
  205. }
  206. this.currentClientOffer = [];
  207. this.currentPartnerOffer = [false,false,false,false,false,false,false,false];
  208. let newAmount = this.classinfo.get(this.currentClass)[this.currentPotion];
  209. newAmount = newAmount-this.count;
  210. this.count = 0;
  211. this.classinfo.get(this.currentClass)[this.currentPotion] = newAmount;
  212. if (newAmount === 0 && this.currentPotion === 7) {
  213. this.classinfo.delete(this.currentClass);
  214. if (this.classinfo.size === 0) {
  215. this.assigned = false;
  216. this.class = undefined;
  217. this.classinfo = new Map<string,number[]>();
  218. this.currentClass = undefined;
  219. this.currentPotion = undefined;
  220. this.objectType = undefined;
  221. this.potionNumbers = [];
  222. this.server = undefined;
  223. this.username = undefined;
  224. }
  225. else if (!this.vaulted) {
  226. setTimeout(() => {
  227. client.gameId = -5;
  228. client.connect();
  229. this.vaulted = true;
  230. },3000);
  231. }
  232. else {
  233. this.nextAcc();
  234. }
  235. }
  236. else if (!this.vaulted) {
  237. setTimeout(() => {
  238. client.gameId = -5;
  239. client.connect();
  240. this.vaulted = true;
  241. },3000);
  242. }
  243. else {
  244. this.nextAcc();
  245. }
  246. }
  247. else {
  248. const trade = new RequestTradePacket();
  249. trade.name = this.username;
  250. client.packetio.sendPacket(trade);
  251. }
  252. }
  253. private nextAcc():void {
  254. this.vaulted = false;
  255. for (let key in this.classinfo.keys()) {
  256. let potInfo = this.classinfo.get(key);
  257. for (let i = 0;i<potInfo.length;i++) {
  258. if (potInfo[i] !== 0) {
  259. this.currentClass = key;
  260. this.currentPotion = i;
  261. this.tradeclass(this.potionNumbers[this.currentPotion]);
  262. return;
  263. }
  264. }
  265. }
  266. }
  267. private deleteAcc(client:Client): void {
  268. for (let i = 0;i<this.accounts.length;i++) {
  269. let accountInfo = this.accounts[i].split(':');
  270. if (accountInfo[2] === client.guid) {
  271. this.accounts.splice(i,1);
  272.  
  273. fs.unlink("./../../Dan/nrelay/acc.txt", (err) => {
  274. if (err) {
  275. console.log(err);
  276. } else {
  277. console.log('success');
  278. }
  279. });
  280. setTimeout(() => {
  281. fs.writeFile("./../../Dan/nrelay/acc.txt", "", { flag: 'wx' }, function (err) {
  282. if (err) throw err;
  283. console.log("New Account File Created");
  284. });
  285. var stream = fs.createWriteStream("./../../Dan/nrelay/acc.txt");
  286. for (let i = 0;i<this.accounts.length;i++) {
  287. let temp = this.accounts[i].split(':');
  288. let email = temp[0].substring(1,temp[0].length-1);
  289. console.log(email);
  290. if (i === this.accounts.length-1) {
  291. var write = this.accounts[i];
  292. stream.write(write, function() {
  293. });
  294. }
  295. else {
  296. var write = this.accounts[i] + "\n";
  297. stream.write(write, function() {
  298. });
  299. }
  300. }
  301. console.log('Updated Accounts');
  302. stream.end();
  303. },500);
  304. return;
  305. }
  306. }
  307. }
  308. private calculateTime(client:Client,location:WorldPosData):number {
  309. let x = Math.sqrt(client.worldPos.squareDistanceTo(location));
  310. let spd = 4+5.6*(client.playerData.spd/75);
  311. return 1000*x/spd;
  312. }
  313. private swap(client:Client,ObjectType:number[],objectID:number) {
  314. let j = 0;
  315. let count = 0;
  316. while (j<8) {
  317. if (ObjectType[j] !== -1) {
  318. count+=600;
  319. let X = j;
  320. setTimeout(() => {
  321. let invswap = new InvSwapPacket();
  322. let vaultItem = new SlotObjectData;
  323. vaultItem.objectId = objectID;
  324. vaultItem.objectType = ObjectType[j];
  325. vaultItem.slotId = X;
  326. invswap.slotObject1 = vaultItem;
  327. let temp = new SlotObjectData();
  328. temp.objectType = client.playerData.inventory[j];
  329. temp.slotId = X;
  330. temp.objectId = client.objectId;
  331. invswap.slotObject2 = temp;
  332. invswap.position = client.worldPos;
  333. invswap.time = client.getTime();
  334. client.packetio.sendPacket(invswap);
  335. },count);
  336. }
  337. }
  338. for (let key in this.classinfo.keys()) {
  339. let potInfo = this.classinfo.get(key);
  340. for (let i = 0;i<potInfo.length;i++) {
  341. if (potInfo[i] !== 0) {
  342. this.currentClass = key;
  343. this.currentPotion = i;
  344. }
  345. }
  346. }
  347. if (client.alias === this.potionNumbers[this.currentPotion]) {
  348. setTimeout(() => {
  349. client.gameId = -2;
  350. client.connect();
  351. },count+4000);
  352. }
  353. else {
  354. this.deleteAcc(client);
  355. this.tradeclass(this.potionNumbers[this.currentPotion]);
  356. }
  357. }
  358. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement