Advertisement
kolton

Untitled

Jul 9th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.35 KB | None | 0 0
  1. var StarterConfig = {
  2. MinGameTime: 180, // Minimum game length in seconds. If a game is ended too soon, the rest of the time is waited in the lobby
  3. CreateGameDelay: 5, // Seconds to wait before creating a new game
  4. ResetCount: 99, // Reset game count back to 1 every X games.
  5. CharacterDifference: 99, // Character level difference. Set to false to disable character difference.
  6.  
  7. JoinChannel: "", // Name of the channel to join
  8. FirstJoinMessage: "", // Message to say when first joining a channel, usually ".login"
  9. AnnounceGames: false, // Announce next game in channel
  10. ChatActionsDelay: 2, // Seconds to wait in lobby before entering a channel
  11.  
  12. SwitchKeys: true, // Set to true to switch keys when they're in use, banned or after realm down
  13. SwitchKeyDelay: 0, // Seconds to wait before switching a used/banned key or after realm down
  14.  
  15. CrashDelay: 60, // Seconds to wait after a d2 window crash
  16. FTJDelay: 60, // Seconds to wait after failing to create a game
  17. RealmDownDelay: 3, // Minutes to wait after getting Realm Down message
  18. UnableToConnectDelay: 5, // Minutes to wait after Unable To Connect message
  19. CDKeyInUseDelay: 5, // Minutes to wait before connecting again if CD-Key is in use. SwitchKeys overrides this!
  20. ConnectingTimeout: 20, // Seconds to wait before cancelling the 'Connecting...' screen
  21. PleaseWaitTimeout: 10, // Seconds to wait before cancelling the 'Please Wait...' screen
  22. WaitInLineTimeout: 60, // Seconds to wait before cancelling the 'Waiting in Line...' screen
  23. GameDoesNotExistTimeout: 30 // Seconds to wait before cancelling the 'Game does not exist.' screen
  24. };
  25.  
  26.  
  27.  
  28. // No touchy!
  29. include("json2.js");
  30. include("OOG.js");
  31. include("automule.js");
  32. include("gambling.js");
  33. load("tools/heartbeat.js");
  34.  
  35. var D2BOT_JOIN = 1,
  36. D2BOT_GAMEINFO = 2,
  37. D2BOT_REQUESTGAME = 3,
  38. crashed = false,
  39. lastGameStatus = "ready",
  40. chatActionsDone = false,
  41. connectFail = false,
  42. firstLogin = false,
  43. gameCount = DataFile.getStats().runs + 1,
  44. gamePass = "",
  45. gameName = "",
  46. difficulty,
  47. gameStart,
  48. isUp = "no",
  49. nextGame = "",
  50. muleTrigger = false,
  51. ingame = false;
  52.  
  53. if (!FileTools.exists("data/" + me.profile + ".json")) {
  54. DataFile.create();
  55. }
  56.  
  57. function ReceiveCopyData(msgID, msg) {
  58. switch (msgID) {
  59. case D2BOT_GAMEINFO:
  60. print("Recieved Game Info");
  61. [gameName, gamePass, difficulty] = msg.split('/');
  62. break;
  63. case D2BOT_JOIN:
  64. [nextGame, gamePass, isUp] = msg.split('/');
  65. break;
  66. case D2BOT_REQUESTGAME:
  67. D2Bot.joinMe(msg, gameName, gameCount, gamePass, isUp);
  68. break;
  69. case 4:
  70. if (msg === "@error") {
  71. crashed = true;
  72. }
  73.  
  74. break;
  75. }
  76. }
  77.  
  78. function timeoutDelay(text, time) {
  79. var endTime = getTickCount() + time;
  80.  
  81. while (getTickCount() < endTime) {
  82. D2Bot.updateStatus(text + " (" + Math.floor((endTime - getTickCount()) / 1000) + "s)");
  83. delay(500);
  84. }
  85. }
  86.  
  87. function locationTimeout(time, location) {
  88. var endtime = getTickCount() + time;
  89.  
  90. while (getLocation() === location && endtime > getTickCount()) {
  91. delay(500);
  92. }
  93.  
  94. return (getLocation() !== location);
  95. }
  96.  
  97. function updateCount() {
  98. D2Bot.updateCount();
  99. delay(1000);
  100. ControlAction.click(6, 264, 366, 272, 35);
  101.  
  102. try {
  103. login(me.profile);
  104. } catch (e) {
  105.  
  106. }
  107.  
  108. delay(1000);
  109. ControlAction.click(6, 33, 572, 128, 35);
  110. }
  111.  
  112. function ScriptMsgEvent(msg) {
  113. switch (msg) {
  114. case "mule":
  115. muleTrigger = true;
  116.  
  117. break;
  118. }
  119. }
  120.  
  121. function main() {
  122. addEventListener('copydata', ReceiveCopyData);
  123. addEventListener('scriptmsg', ScriptMsgEvent);
  124. delay(rand(2, 3) * 1000);
  125. D2Bot.requestGameInfo();
  126. D2Bot.getLastError();
  127.  
  128. if (crashed) {
  129. timeoutDelay("Crash Delay", StarterConfig.CrashDelay * 1e3);
  130. D2Bot.updateRuns();
  131. }
  132.  
  133. while (true) {
  134. while (me.ingame) { // returns true before actually in game so we can't only use this check
  135. if (me.gameReady) { // returns false when switching acts so we can't use while
  136. isUp = "yes";
  137.  
  138. if (!ingame) {
  139. if (me.gamepassword.toLowerCase() !== gamePass.toLowerCase()) {
  140. print("leaving game");
  141. quit();
  142. }
  143.  
  144. print("Updating Status");
  145. D2Bot.updateStatus("Game: " + me.gamename);
  146.  
  147. lastGameStatus = "ingame";
  148. ingame = true;
  149. gameStart = getTickCount();
  150.  
  151. DataFile.updateStats("runs", gameCount);
  152. }
  153. }
  154.  
  155. delay(1000);
  156. }
  157.  
  158. isUp = "no";
  159.  
  160. locationAction(getLocation());
  161. delay(1000);
  162. }
  163. }
  164.  
  165. function locationAction(location) {
  166. var i, control, string, text, gambleGame;
  167.  
  168. MainSwitch:
  169. switch (location) {
  170. case 0:
  171. break;
  172. case 1: // Lobby
  173. D2Bot.updateStatus("Lobby");
  174.  
  175. if (StarterConfig.JoinChannel !== "") {
  176. ControlAction.click(6, 27, 480, 120, 20);
  177.  
  178. break;
  179. }
  180.  
  181. if (ingame) {
  182. if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
  183. timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
  184. }
  185.  
  186. // ### automule ###
  187. if (muleTrigger) {
  188. AutoMule.outOfGameCheck();
  189.  
  190. muleTrigger = false;
  191.  
  192. break;
  193. }
  194. // ### automule end ###
  195.  
  196. print("updating runs");
  197. D2Bot.updateRuns();
  198.  
  199. gameCount += 1;
  200. lastGameStatus = "ready";
  201. ingame = false;
  202. }
  203.  
  204. // #### experimental gambling system start ####
  205. gambleGame = Gambling.checkGamblers();
  206.  
  207. if (gambleGame && DataFile.getStats().gold > Gambling.minGold) {
  208. delay(3000);
  209. joinGame(gambleGame[0], gambleGame[1]);
  210. delay(1000);
  211. locationTimeout(5000, location);
  212.  
  213. break;
  214. }
  215. // #### experimental gambling system end ####
  216.  
  217. if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  218. break;
  219. }
  220.  
  221. if (!locationTimeout(5000, location)) { // in case create button gets bugged
  222. if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
  223. break;
  224. }
  225.  
  226. if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  227. break;
  228. }
  229. }
  230.  
  231. break;
  232. case 2: // Waiting In Line
  233. D2Bot.updateStatus("Waiting...");
  234. locationTimeout(StarterConfig.WaitInLineTimeout * 1e3, location);
  235.  
  236. break;
  237. case 3: // Lobby Chat
  238. D2Bot.updateStatus("Lobby Chat");
  239.  
  240. if (ingame) {
  241. if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
  242. timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
  243. }
  244.  
  245. // ### automule ###
  246. if (muleTrigger) {
  247. AutoMule.outOfGameCheck();
  248.  
  249. muleTrigger = false;
  250.  
  251. break;
  252. }
  253. // ### automule end ###
  254.  
  255. print("updating runs");
  256. D2Bot.updateRuns();
  257.  
  258. gameCount += 1;
  259. lastGameStatus = "ready";
  260. ingame = false;
  261. }
  262.  
  263. // #### experimental gambling system start ####
  264. gambleGame = Gambling.checkGamblers();
  265.  
  266. if (gambleGame && DataFile.getStats().gold > Gambling.minGold) {
  267. delay(3000);
  268. joinGame(gambleGame[0], gambleGame[1]);
  269. delay(1000);
  270. locationTimeout(5000, location);
  271.  
  272. break;
  273. }
  274. // #### experimental gambling system end ####
  275.  
  276. if (!chatActionsDone) {
  277. chatActionsDone = true;
  278.  
  279. timeoutDelay("Chat delay", StarterConfig.ChatActionsDelay * 1e3);
  280. say("/j " + StarterConfig.JoinChannel);
  281. delay(1000);
  282.  
  283. if (StarterConfig.FirstJoinMessage !== "") {
  284. say(StarterConfig.FirstJoinMessage);
  285. delay(500);
  286. }
  287. }
  288.  
  289. if (StarterConfig.AnnounceGames) {
  290. delay(1000);
  291. say("Next game is " + gameName + gameCount + (gamePass === "" ? "" : "//" + gamePass));
  292. }
  293.  
  294. if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  295. break;
  296. }
  297.  
  298. if (!locationTimeout(5000, location)) { // in case create button gets bugged
  299. if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
  300. break;
  301. }
  302.  
  303. if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  304. break;
  305. }
  306. }
  307.  
  308. break;
  309. case 4: // Create Game
  310. D2Bot.updateStatus("Creating Game");
  311.  
  312. control = getControl(1, 657, 342, 27, 20);
  313.  
  314. if (typeof StarterConfig.CharacterDifference === "number") {
  315. if (control.disabled === 4) {
  316. ControlAction.click(6, 431, 341, 15, 16);
  317. }
  318.  
  319. ControlAction.setText(1, 657, 342, 27, 20, StarterConfig.CharacterDifference.toString());
  320. } else if (StarterConfig.CharacterDifference === false && control.disabled === 5) {
  321. ControlAction.click(6, 431, 341, 15, 16);
  322. }
  323.  
  324. if (StarterConfig.ResetCount && gameCount >= StarterConfig.ResetCount) {
  325. gameCount = 1;
  326.  
  327. DataFile.updateStats("runs", gameCount);
  328. }
  329.  
  330. while (!gameName) {
  331. D2Bot.requestGameInfo();
  332. delay(500);
  333. }
  334.  
  335. if (lastGameStatus === "pending") {
  336. D2Bot.printToConsole("Failed to create game");
  337. timeoutDelay("FTJ delay", StarterConfig.FTJDelay * 1e3);
  338.  
  339. gameCount += 1;
  340. }
  341.  
  342. timeoutDelay("Make Game Delay", StarterConfig.CreateGameDelay * 1e3);
  343. createGame(gameName + gameCount, gamePass, difficulty === "Hell" ? 2 : difficulty === "Nightmare" ? 1 : 0);
  344.  
  345. lastGameStatus = "pending";
  346.  
  347. locationTimeout(5000, location);
  348.  
  349. break;
  350. case 5: // Join Game
  351. break;
  352. case 6: // Ladder
  353. break;
  354. case 7: // Channel List
  355. break;
  356. case 8: // Main Menu
  357. case 9: // Login
  358. case 18: // D2 Splash
  359. if (firstLogin) { // multiple realm botting fix in case of R/D or disconnect
  360. ControlAction.click(6, 33, 572, 128, 35);
  361. }
  362.  
  363. if (!firstLogin) {
  364. firstLogin = true;
  365. }
  366.  
  367. D2Bot.updateStatus("Logging In");
  368.  
  369. try {
  370. login(me.profile);
  371. } catch (e) {
  372. print(e);
  373. }
  374.  
  375. break;
  376. case 10: // Login Error
  377. string = "";
  378. text = ControlAction.getText(4, 199, 377, 402, 140);
  379.  
  380. if (text) {
  381. for (i = 0; i < text.length; i += 1) {
  382. string += text[i];
  383.  
  384. if (i !== text.length - 1) {
  385. string += " ";
  386. }
  387. }
  388.  
  389. switch (string) {
  390. case getLocaleString(5207):
  391. D2Bot.updateStatus("Invalid Password");
  392. D2Bot.printToConsole("Invalid Password");
  393. break;
  394. case getLocaleString(5208):
  395. D2Bot.updateStatus("Invalid Account");
  396. D2Bot.printToConsole("Invalid Account");
  397. break;
  398. case getLocaleString(5199):
  399. D2Bot.updateStatus("Disabled CDKey");
  400. D2Bot.printToConsole("Disabled CDKey");
  401. D2Bot.CDKeyDisabled();
  402.  
  403. if (StarterConfig.SwitchKeys) {
  404. timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  405. D2Bot.restart(true);
  406. } else {
  407. D2Bot.stop();
  408. }
  409.  
  410. break;
  411. case getLocaleString(5347):
  412. D2Bot.updateStatus("Disconnected");
  413. D2Bot.printToConsole("Disconnected");
  414. ControlAction.click(6, 335, 412, 128, 35);
  415. break MainSwitch;
  416. default:
  417. D2Bot.updateStatus("Login Error");
  418. D2Bot.printToConsole("Login Error - " + string);
  419. break;
  420. }
  421. }
  422.  
  423. ControlAction.click(6, 335, 412, 128, 35);
  424.  
  425. while (true) {
  426. delay(1000);
  427. }
  428.  
  429. break;
  430. case 11: // Unable To Connect
  431. D2Bot.updateStatus("Unable To Connect");
  432.  
  433. if (connectFail) {
  434. timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
  435.  
  436. connectFail = false;
  437. }
  438.  
  439. if (!ControlAction.click(6, 335, 450, 128, 35)) {
  440. break;
  441. }
  442.  
  443. connectFail = true;
  444.  
  445. break;
  446. case 12: // Character Select
  447. try {
  448. login(me.profile);
  449. } catch (e2) {
  450.  
  451. }
  452.  
  453. break;
  454. case 13: // Realm Down - Character Select screen
  455. D2Bot.printToConsole("step 1");
  456. D2Bot.updateStatus("Realm Down");
  457. delay(1000);
  458.  
  459. D2Bot.printToConsole("step 2");
  460.  
  461. if (!ControlAction.click(6, 33, 572, 128, 35)) {
  462. break;
  463. }
  464.  
  465. D2Bot.printToConsole("step 3");
  466. updateCount();
  467. D2Bot.printToConsole("step 4");
  468. timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
  469. D2Bot.printToConsole("step 5");
  470. D2Bot.CDKeyRD();
  471.  
  472. if (StarterConfig.SwitchKeys) {
  473. D2Bot.printToConsole("Realm Down - Changing CD-Key");
  474. timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  475. D2Bot.restart(true);
  476. } else {
  477. D2Bot.restart();
  478. }
  479.  
  480. break;
  481. case 14: // Character Select / Main Menu - Disconnected
  482. D2Bot.updateStatus("Disconnected");
  483. delay(500);
  484. ControlAction.click(6, 351, 337, 96, 32);
  485. break;
  486. case 15: // New Character
  487. break;
  488. case 16: // Character Select - Please Wait popup
  489. if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
  490. ControlAction.click(6, 351, 337, 96, 32);
  491. }
  492.  
  493. break;
  494. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  495. delay(1000);
  496. ControlAction.click(6, 351, 337, 96, 32);
  497. break;
  498. case 19: // Login - Cdkey In Use
  499. D2Bot.printToConsole("CD-Key in use by " + ControlAction.getText(4, 158, 310, 485, 40));
  500. D2Bot.CDKeyInUse();
  501.  
  502. if (StarterConfig.SwitchKeys) {
  503. timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  504. D2Bot.restart(true);
  505. } else {
  506. ControlAction.click(6, 335, 450, 128, 35);
  507. timeoutDelay("CD-Key in use", StarterConfig.CDKeyInUseDelay * 6e4);
  508. }
  509.  
  510. break;
  511. case 20: // Single Player - Select Difficulty
  512. break;
  513. case 21: // Main Menu - Connecting
  514. if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
  515. ControlAction.click(6, 330, 416, 128, 35);
  516. }
  517.  
  518. break;
  519. case 22: // Login - Invalid Cdkey (classic or xpac)
  520. if (StarterConfig.SwitchKeys) {
  521. D2Bot.printToConsole("Invalid CD-Key");
  522. timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  523. D2Bot.restart(true);
  524. } else {
  525. ControlAction.click(6, 335, 450, 128, 35);
  526. timeoutDelay("Invalid CD-Key", StarterConfig.CDKeyInUseDelay * 6e4);
  527. }
  528.  
  529. break;
  530. case 23: // Character Select - Connecting
  531. if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
  532. ControlAction.click(6, 33, 572, 128, 35);
  533. }
  534.  
  535. break;
  536. case 24: // Server Down - not much to do but wait..
  537. break;
  538. case 25: // Lobby - Please Wait
  539. if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
  540. ControlAction.click(6, 351, 337, 96, 32);
  541. }
  542.  
  543. break;
  544. case 26: // Lobby - Game Name Exists
  545. gameCount += 1;
  546.  
  547. delay(500);
  548. ControlAction.click(6, 533, 469, 120, 20);
  549. break;
  550. case 27: // Gateway Select
  551. break;
  552. case 28: // Lobby - Game Does Not Exist
  553. D2Bot.printToConsole("Game doesn't exist");
  554.  
  555. lastGameStatus = "ready";
  556.  
  557. locationTimeout(StarterConfig.GameDoesNotExistTimeout * 1e3, location);
  558.  
  559. break;
  560. case 38: // Game is full
  561. D2Bot.printToConsole("Game is full");
  562.  
  563. lastGameStatus = "ready";
  564.  
  565. delay(500);
  566. ControlAction.click(6, 652, 469, 120, 20);
  567. break;
  568. case 42: // Empty character screen
  569. delay(1000);
  570. ControlAction.click(6, 33, 572, 128, 35);
  571.  
  572. break;
  573. default:
  574. if (location !== undefined) {
  575. D2Bot.printToConsole("Unhandled location " + location);
  576. delay(500);
  577. D2Bot.restart();
  578. }
  579.  
  580. break;
  581. }
  582. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement