mf22

D2BotLeadStagger.dbj

Apr 13th, 2018
2,102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. *   Starter config with staggered delays for avoiding the creation of new games within 2 minutes, with additions in lines 259-263, 356-376, 561
  3. */
  4.  
  5. var StarterConfig = {
  6.     MinGameTime: rand(150, 180), // Minimum game length in seconds. If a game is ended too soon, the rest of the time is waited in the lobby
  7.     PingQuitDelay: rand(30, 40), // Time in seconds to wait in lobby after quitting due to high ping
  8.     CreateGameDelay: rand(10e3, 15e3), // Milliseconds to wait before creating a new game
  9.     ResetCount: 999, // Reset game count back to 1 every X games.
  10.     CharacterDifference: 99, // Character level difference. Set to false to disable character difference.
  11.     ChatActionsDelay: rand(2e3, 5e3), // Milliseconds to wait in lobby before entering a channel
  12.  
  13.     // ChannelConfig can override these options for individual profiles.
  14.     JoinChannel: "", // Default channel. Can be an array of channels - ["channel 1", "channel 2"]
  15.     FirstJoinMessage: "", // Default join message. Can be an array of messages
  16.     AnnounceGames: false, // Default value
  17.     AfterGameMessage: "", // Default message after a finished game. Can be an array of messages
  18.  
  19.     SwitchKeyDelay: rand(5, 15), // Seconds to wait before switching a used/banned key or after realm down
  20.     CrashDelay: rand(120e3, 150e3), // Milliseconds to wait after a d2 window crash
  21.     FTJDelay: rand(25e3, 30e3), // Milliseconds to wait after failing to create a game
  22.     RealmDownDelay: rand(3, 7), // Minutes to wait after getting Realm Down message
  23.     UnableToConnectDelay: rand(5, 10), // Minutes to wait after Unable To Connect message
  24.     CDKeyInUseDelay: rand(5, 10), // Minutes to wait before connecting again if CD-Key is in use.
  25.     ConnectingTimeout: rand(25e3, 30e3), // Milliseconds to wait before cancelling the 'Connecting...' screen
  26.     PleaseWaitTimeout: rand(20e3, 30e3), // Milliseconds to wait before cancelling the 'Please Wait...' screen
  27.     WaitInLineTimeout: rand(60e3, 90e3), // Milliseconds to wait before cancelling the 'Waiting in Line...' screen
  28.     GameDoesNotExistTimeout: rand(30e3, 40e3) // Milliseconds to wait before cancelling the 'Game does not exist.' screen
  29. };
  30.  
  31. var ChannelConfig = {
  32.     /* Override default values for JoinChannel, FirstJoinMessage, AnnounceGames and AfterGameMessage per profile
  33.         It's possible to override any number of these options (you don't have to put all of them)
  34.  
  35.         **** DO NOT EDIT ANYTHING INSIDE THIS COMMENT BLOCK ***
  36.  
  37.         Format:
  38.  
  39.         "Profile Name": {
  40.             JoinChannel: "channel name", -OR- ["channel 1", "channel 2"],
  41.             FirstJoinMessage: "first message", -OR- ["join msg 1", "join msg 2"],
  42.             AnnounceGames: true,
  43.             AfterGameMessage: "message after a finished run" -OR- ["msg 1", msg 2"]
  44.         }
  45.  
  46.         Multiple entries are separated by a comma
  47.  
  48.         Examples:
  49.  
  50.         "Profile 1": {
  51.             JoinChannel: "my channel",
  52.             FirstJoinMessage: ".login",
  53.             AnnounceGames: true,
  54.             AfterGameMessage: "follow my runs or die"
  55.         },
  56.         "Profile 2": {
  57.             JoinChannel: ["channel 1", "channel 2"],
  58.             FirstJoinMessage: [".login", "^login"],
  59.             AfterGameMessage: ["follow my runs or die", "seriously, you'll die"]
  60.         }
  61.     */
  62.  
  63.     // Add your lines here
  64.  
  65. };
  66.  
  67.  
  68.  
  69. // No touchy!
  70. include("json2.js");
  71. include("OOG.js");
  72. include("automule.js");
  73. include("gambling.js");
  74. include("craftingsystem.js");
  75. include("torchsystem.js");
  76. include("common/misc.js");
  77. include("common/util.js");
  78.  
  79. if (!FileTools.exists("data/" + me.profile + ".json")) {
  80.     DataFile.create();
  81. }
  82.  
  83. var gameInfo, gameStart, ingame, chatActionsDone, pingQuit,
  84.     handle, useChat, firstLogin, connectFail,
  85.     gameCount = DataFile.getStats().runs + 1,
  86.     loginRetry = 0,
  87.     ftj = 0,
  88.     wait = 0,
  89.     lastGameStatus = "ready",
  90.     isUp = "no",
  91.     chanInfo = {
  92.         joinChannel: "",
  93.         firstMsg: "",
  94.         afterMsg: "",
  95.         announce: false
  96.     };
  97.  
  98. function sayMsg(string) {
  99.     if (!useChat) {
  100.         return;
  101.     }
  102.  
  103.     say(string);
  104. }
  105.  
  106. function ReceiveCopyData(mode, msg) {
  107.     var obj;
  108.  
  109.     switch (msg) {
  110.     case "Handle":
  111.         handle = mode;
  112.  
  113.         break;
  114.     }
  115.  
  116.     switch (mode) {
  117.     case 2: // Game info
  118.         print("Recieved Game Info");
  119.  
  120.         gameInfo = JSON.parse(msg);
  121.  
  122.         break;
  123.     case 3: // Game request
  124.         // Don't let others join mule/torch/key/gold drop game
  125.         if (AutoMule.inGame || Gambling.inGame || TorchSystem.inGame || CraftingSystem.inGame) {
  126.             break;
  127.         }
  128.  
  129.         if (gameInfo) {
  130.             obj = JSON.parse(msg);
  131.  
  132.             if (me.gameReady) {
  133.                 D2Bot.joinMe(obj.profile, me.gamename.toLowerCase(), "", me.gamepassword.toLowerCase(), isUp);
  134.             } else {
  135.                 D2Bot.joinMe(obj.profile, gameInfo.gameName.toLowerCase(), gameCount, gameInfo.gamePass.toLowerCase(), isUp);
  136.             }
  137.         }
  138.  
  139.         break;
  140.     case 4: // Heartbeat ping
  141.         if (msg === "pingreq") {
  142.             sendCopyData(null, me.windowtitle, 4, "pingrep");
  143.         }
  144.  
  145.         break;
  146.     case 0xf124: // Cached info retreival
  147.         if (msg !== "null") {
  148.             gameInfo.crashInfo = JSON.parse(msg);
  149.         }
  150.  
  151.         break;
  152.     }
  153. }
  154.  
  155. function setNextGame() {
  156.     var nextGame = gameInfo.gameName;
  157.  
  158.     if (StarterConfig.ResetCount && gameCount + 1 >= StarterConfig.ResetCount) {
  159.         nextGame += 1;
  160.     } else {
  161.         nextGame += (gameCount + 1);
  162.     }
  163.  
  164.     DataFile.updateStats("nextGame", nextGame);
  165. }
  166.  
  167. function locationTimeout(time, location) {
  168.     var endtime = getTickCount() + time;
  169.  
  170.     while (getLocation() === location && endtime > getTickCount()) {
  171.         delay(500);
  172.     }
  173.  
  174.     return (getLocation() !== location);
  175. }
  176.  
  177. function updateCount () {
  178.     D2Bot.updateCount();
  179.     delay(1000);
  180.     ControlAction.click(6, 264, 366, 272, 35);
  181.  
  182.     try {
  183.         login(me.profile);
  184.     } catch (e) {
  185.  
  186.     }
  187.  
  188.     delay(1000);
  189.     ControlAction.click(6, 33, 572, 128, 35);
  190. }
  191.  
  192. function ScriptMsgEvent(msg) {
  193.     switch (msg) {
  194.     case "mule":
  195.         AutoMule.check = true;
  196.  
  197.         break;
  198.     case "muleTorch":
  199.         AutoMule.torchAnniCheck = 1;
  200.  
  201.         break;
  202.     case "muleAnni":
  203.         AutoMule.torchAnniCheck = 2;
  204.  
  205.         break;
  206.     case "torch":
  207.         TorchSystem.check = true;
  208.  
  209.         break;
  210.     case "crafting":
  211.         CraftingSystem.check = true;
  212.  
  213.         break;
  214.     case "getMuleMode":
  215.         if (AutoMule.torchAnniCheck === 2) {
  216.             scriptBroadcast("2");
  217.         } else if (AutoMule.torchAnniCheck === 1) {
  218.             scriptBroadcast("1");
  219.         } else if (AutoMule.check) {
  220.             scriptBroadcast("0");
  221.         }
  222.  
  223.         break;
  224.     case "pingquit":
  225.         pingQuit = true;
  226.  
  227.         break;
  228.     }
  229. }
  230.  
  231. function timer (tick) {
  232.     return " (" + new Date(getTickCount() - tick).toISOString().slice(11, -5) + ")";
  233. }
  234.  
  235. function randomString(len, useNumbers = false) {
  236.     var i, rval = "",
  237.         letters = useNumbers ? "abcdefghijklmnopqrstuvwxyz0123456789" : "abcdefghijklmnopqrstuvwxyz";
  238.  
  239.     len = len ? len : rand(5, 14);
  240.  
  241.     for (i = 0; i < len; i += 1) {
  242.         rval += letters[rand(0, letters.length - 1)];
  243.     }
  244.  
  245.     return rval;
  246. }
  247.  
  248. function main () {
  249.     debugLog(me.profile);
  250.     addEventListener('copydata', ReceiveCopyData);
  251.     addEventListener('scriptmsg', ScriptMsgEvent);
  252.  
  253.     while (!handle) {
  254.         delay(100);
  255.     }
  256.  
  257.     DataFile.updateStats("handle", handle);
  258.     delay(500);
  259.     D2Bot.init();
  260.     load("tools/heartbeat.js");
  261.  
  262.     // if the gameStagger.txt file doesn't exists create new one with 2 minutes discount time stamp
  263.     if (!FileTools.exists("logs/gameStagger.txt")) {
  264.         Misc.fileAction("logs/gameStagger.txt", 1, (getTickCount()-12e4)); 
  265.     }
  266.  
  267.     while (!gameInfo) {
  268.         D2Bot.requestGameInfo();
  269.         delay(500);
  270.     }
  271.  
  272.     if (gameInfo.error) {
  273.         //D2Bot.retrieve();
  274.         delay(200);
  275.  
  276.         if (!!DataFile.getStats().debugInfo) {
  277.             gameInfo.crashInfo = DataFile.getStats().debugInfo;
  278.  
  279.             D2Bot.printToConsole("Crash Info: Script: " + JSON.parse(gameInfo.crashInfo).currScript + " Area: " + JSON.parse(gameInfo.crashInfo).area, 10);
  280.         }
  281.  
  282.         /*if (gameInfo.crashInfo) {
  283.             D2Bot.printToConsole("Crash Info: Script: " + gameInfo.crashInfo.currScript + " Area: " + gameInfo.crashInfo.area + (gameInfo.crashInfo.hasOwnProperty("lastAction") ? " " + gameInfo.crashInfo.lastAction : ""), 10);
  284.         }*/
  285.  
  286.         ControlAction.timeoutDelay("Crash Delay", StarterConfig.CrashDelay);
  287.         D2Bot.updateRuns();
  288.     }
  289.  
  290.     //D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
  291.     DataFile.updateStats("debugInfo", JSON.stringify({currScript: "none", area: "out of game"}));
  292.  
  293.     while (true) {
  294.         while (me.ingame) { // returns true before actually in game so we can't only use this check
  295.             if (me.gameReady) { // returns false when switching acts so we can't use while
  296.                 isUp = "yes";
  297.  
  298.                 if (!ingame) {
  299.                     gameStart = getTickCount();
  300.  
  301.                     print("Updating Status");
  302.                     //D2Bot.updateStatus("Game: " + me.gamename);
  303.  
  304.                     lastGameStatus = "ingame";
  305.                     ingame = true;
  306.  
  307.                     DataFile.updateStats("runs", gameCount);
  308.                     DataFile.updateStats("ingameTick");
  309.                 }
  310.  
  311.                 D2Bot.updateStatus("Game: " + me.gamename + timer(gameStart) + " IP: " + (me.gameserverip.length > 0 ? me.gameserverip.split(".")[3] : "0"));
  312.             }
  313.  
  314.             delay(1000);
  315.         }
  316.  
  317.         isUp = "no";
  318.  
  319.         locationAction(getLocation());
  320.         delay(1000);
  321.     }
  322. }
  323.  
  324. function locationAction(location) {
  325.     var i, control, string, text;
  326.  
  327. MainSwitch:
  328.     switch (location) {
  329.     case 0:
  330.         ControlAction.click();
  331.  
  332.         break;
  333.     case 1: // Lobby
  334.         D2Bot.updateStatus("Lobby");
  335.  
  336.         me.blockKeys = false;
  337.         loginRetry = 0;
  338.  
  339.         if (!firstLogin) {
  340.             firstLogin = true;
  341.         }
  342.  
  343.         if (lastGameStatus === "pending") {
  344.             gameCount += 1;
  345.         }
  346.  
  347.         if (StarterConfig.PingQuitDelay && pingQuit) {
  348.             ControlAction.timeoutDelay("Ping Delay", StarterConfig.PingQuitDelay * 1e3);
  349.  
  350.             pingQuit = false;
  351.         }
  352.  
  353.         if (StarterConfig.JoinChannel !== "" || (ChannelConfig[me.profile] && ChannelConfig[me.profile].JoinChannel !== "")) {
  354.             ControlAction.click(6, 27, 480, 120, 20);
  355.  
  356.             break;
  357.         }
  358.  
  359.         //stagger time stamps for creating games
  360.         var staggerRead = "",
  361.             staggerTime = 0,
  362.             createTime = 0,
  363.             staggerDelay = rand(120e3, 130e3),
  364.             goTime = 0;
  365.  
  366.         while (true) {
  367.             delay(1000);
  368.             staggerRead = Misc.fileAction("logs/gameStagger.txt", 0);
  369.             staggerTime = Number(staggerRead);
  370.             createTime = (staggerTime + staggerDelay);
  371.             goTime = createTime - getTickCount();
  372.  
  373.             if(goTime < 0) {
  374.                 break;
  375.             }
  376.  
  377.             D2Bot.updateStatus("Lobby - stagger time: (" + parseInt(goTime/1e3) + "s)", 0);
  378.         }
  379.  
  380.         if (ingame || gameInfo.error) {
  381.             if (!gameStart) {
  382.                 gameStart = DataFile.getStats().ingameTick;
  383.             }
  384.  
  385.             if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
  386.                 ControlAction.timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
  387.             }
  388.         }
  389.  
  390.         if (ingame) {
  391.             //D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
  392.  
  393.             if (AutoMule.outOfGameCheck() || TorchSystem.outOfGameCheck() || Gambling.outOfGameCheck() || CraftingSystem.outOfGameCheck()) {
  394.                 break;
  395.             }
  396.  
  397.             print("updating runs");
  398.             D2Bot.updateRuns();
  399.  
  400.             gameCount += 1;
  401.             lastGameStatus = "ready";
  402.             ingame = false;
  403.  
  404.             if (StarterConfig.ResetCount && gameCount >= StarterConfig.ResetCount) {
  405.                 gameCount = 1;
  406.  
  407.                 DataFile.updateStats("runs", gameCount);
  408.             }
  409.         }
  410.  
  411.         if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  412.             break;
  413.         }
  414.  
  415.         if (!locationTimeout(5000, location)) { // in case create button gets bugged
  416.             if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
  417.                 break;
  418.             }
  419.  
  420.             if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  421.                 break;
  422.             }
  423.         }
  424.  
  425.         break;
  426.     case 2: // Waiting In Line
  427.         D2Bot.updateStatus("Waiting...");
  428.         wait++;
  429.  
  430.         if (wait > 2) {
  431.             D2Bot.printToConsole(me.profile + " - Waiting in line");
  432.             D2Bot.stop(me.profile, true);
  433.         }
  434.  
  435.         locationTimeout(StarterConfig.WaitInLineTimeout, location);
  436.         ControlAction.click(6, 433, 433, 96, 32);
  437.  
  438.         break;
  439.     case 3: // Lobby Chat
  440.         D2Bot.updateStatus("Lobby Chat");
  441.  
  442.         if (lastGameStatus === "pending") {
  443.             gameCount += 1;
  444.         }
  445.  
  446.         if (ingame || gameInfo.error) {
  447.             if (!gameStart) {
  448.                 gameStart = DataFile.getStats().ingameTick;
  449.             }
  450.  
  451.             if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
  452.                 ControlAction.timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
  453.             }
  454.         }
  455.  
  456.         if (ingame) {
  457.             //D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
  458.  
  459.             if (AutoMule.outOfGameCheck() || TorchSystem.outOfGameCheck() || Gambling.outOfGameCheck() || CraftingSystem.outOfGameCheck()) {
  460.                 break;
  461.             }
  462.  
  463.             print("updating runs");
  464.             D2Bot.updateRuns();
  465.  
  466.             gameCount += 1;
  467.             lastGameStatus = "ready";
  468.             ingame = false;
  469.  
  470.             if (StarterConfig.ResetCount && gameCount >= StarterConfig.ResetCount) {
  471.                 gameCount = 1;
  472.  
  473.                 DataFile.updateStats("runs", gameCount);
  474.             }
  475.  
  476.             if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("AfterGameMessage")) {
  477.                 chanInfo.afterMsg = ChannelConfig[me.profile].AfterGameMessage;
  478.             } else {
  479.                 chanInfo.afterMsg = StarterConfig.AfterGameMessage;
  480.             }
  481.  
  482.             if (chanInfo.afterMsg) {
  483.                 if (typeof chanInfo.afterMsg === "string") {
  484.                     chanInfo.afterMsg = [chanInfo.afterMsg];
  485.                 }
  486.  
  487.                 for (i = 0; i < chanInfo.afterMsg.length; i += 1) {
  488.                     sayMsg(chanInfo.afterMsg[i]);
  489.                     delay(500);
  490.                 }
  491.             }
  492.         }
  493.  
  494.         if (!chatActionsDone) {
  495.             chatActionsDone = true;
  496.  
  497.             if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("JoinChannel")) {
  498.                 chanInfo.joinChannel = ChannelConfig[me.profile].JoinChannel;
  499.             } else {
  500.                 chanInfo.joinChannel = StarterConfig.JoinChannel;
  501.             }
  502.  
  503.             if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("FirstJoinMessage")) {
  504.                 chanInfo.firstMsg = ChannelConfig[me.profile].FirstJoinMessage;
  505.             } else {
  506.                 chanInfo.firstMsg = StarterConfig.FirstJoinMessage;
  507.             }
  508.  
  509.             if (chanInfo.joinChannel) {
  510.                 if (typeof chanInfo.joinChannel === "string") {
  511.                     chanInfo.joinChannel = [chanInfo.joinChannel];
  512.                 }
  513.  
  514.                 if (typeof chanInfo.firstMsg === "string") {
  515.                     chanInfo.firstMsg = [chanInfo.firstMsg];
  516.                 }
  517.  
  518.                 for (i = 0; i < chanInfo.joinChannel.length; i += 1) {
  519.                     ControlAction.timeoutDelay("Chat delay", StarterConfig.ChatActionsDelay);
  520.  
  521.                     if (ControlAction.joinChannel(chanInfo.joinChannel[i])) {
  522.                         useChat = true;
  523.                     } else {
  524.                         print("ÿc1Unable to join channel, disabling chat messages.");
  525.  
  526.                         useChat = false;
  527.                     }
  528.  
  529.                     if (chanInfo.firstMsg[i] !== "") {
  530.                         sayMsg(chanInfo.firstMsg[i]);
  531.                         delay(500);
  532.                     }
  533.                 }
  534.             }
  535.         }
  536.  
  537.         // Announce game
  538.         if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("AnnounceGames")) {
  539.             chanInfo.announce = ChannelConfig[me.profile].AnnounceGames;
  540.         } else {
  541.             chanInfo.announce = StarterConfig.AnnounceGames;
  542.         }
  543.  
  544.         if (chanInfo.announce) {
  545.             sayMsg("Next game is " + gameInfo.gameName + gameCount + (gameInfo.gamePass === "" ? "" : "//" + gameInfo.gamePass));
  546.         }
  547.  
  548.         if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  549.             break;
  550.         }
  551.  
  552.         if (!locationTimeout(5000, location)) { // in case create button gets bugged
  553.             if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
  554.                 break;
  555.             }
  556.  
  557.             if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
  558.                 break;
  559.             }
  560.         }
  561.  
  562.         break;
  563.     case 4: // Create Game
  564.         Misc.fileAction("logs/gameStagger.txt", 1, getTickCount()); // overwrite the time stamp for creating games
  565.         D2Bot.updateStatus("Creating Game");
  566.  
  567.         control = getControl(1, 657, 342, 27, 20);
  568.  
  569.         // Set character difference
  570.         if (typeof StarterConfig.CharacterDifference === "number") {
  571.             if (control.disabled === 4) {
  572.                 ControlAction.click(6, 431, 341, 15, 16);
  573.             }
  574.  
  575.             ControlAction.setText(1, 657, 342, 27, 20, StarterConfig.CharacterDifference.toString());
  576.         } else if (StarterConfig.CharacterDifference === false && control.disabled === 5) {
  577.             ControlAction.click(6, 431, 341, 15, 16);
  578.         }
  579.  
  580.         // Get game name if there is none
  581.         while (!gameInfo.gameName) {
  582.             D2Bot.requestGameInfo();
  583.             delay(500);
  584.         }
  585.  
  586.         // FTJ handler
  587.         if (lastGameStatus === "pending") {
  588.             ftj++;
  589.             isUp = "no";
  590.  
  591.             D2Bot.printToConsole("Failed to create game");
  592.             ControlAction.timeoutDelay("FTJ delay", StarterConfig.FTJDelay);
  593.             D2Bot.updateRuns();
  594.  
  595.             if (ftj > 4) {
  596.                 D2BotLead.update("done", "D2BotLead failed to join game!");
  597.                 D2Bot.stop(me.profile,true);
  598.             }
  599.         }
  600.  
  601.         ControlAction.createGame((gameInfo.gameName === "?" ? randomString(null,true) : gameInfo.gameName + gameCount), (gameInfo.gamePass === "?" ? randomString(null,true) : gameInfo.gamePass), gameInfo.difficulty, StarterConfig.CreateGameDelay);
  602.  
  603.         lastGameStatus = "pending";
  604.  
  605.         setNextGame();
  606.         locationTimeout(10000, location);
  607.  
  608.         break;
  609.     case 5: // Join Game
  610.         break;
  611.     case 6: // Ladder
  612.         break;
  613.     case 7: // Channel List
  614.         break;
  615.     case 8: // Main Menu
  616.     case 9: // Login
  617.     case 12: // Character Select
  618.     case 18: // D2 Splash
  619.         // Single Player screen fix
  620.         if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
  621.             ControlAction.click(6, 33, 572, 128, 35);
  622.  
  623.             break;
  624.         }
  625.  
  626.         if (firstLogin && getLocation() === 9) { // multiple realm botting fix in case of R/D or disconnect
  627.             ControlAction.click(6, 33, 572, 128, 35);
  628.         }
  629.  
  630.         D2Bot.updateStatus("Logging In");
  631.  
  632.         try {
  633.             login(me.profile);
  634.         } catch (e) {
  635.             if (getLocation() === 12 && loginRetry < 2) {
  636.                 if (loginRetry === 0) {
  637.                     // start from beginning of the char list
  638.                     sendKey(0x24);
  639.                 }
  640.  
  641.                 control = getControl(4, 237, 457, 72, 93); // char on 1st column, 4th row
  642.  
  643.                 if (control) {
  644.                     me.blockMouse = true;
  645.                     me.blockKeys = true;
  646.  
  647.                     control.click();
  648.                     sendKey(0x28);
  649.                     sendKey(0x28);
  650.                     sendKey(0x28);
  651.                     sendKey(0x28);
  652.  
  653.                     me.blockMouse = false;
  654.                 }
  655.  
  656.                 loginRetry++;
  657.             } else {
  658.                 me.blockKeys = false;
  659.                 print(e + " " + getLocation());
  660.             }
  661.         }
  662.  
  663.         break;
  664.     case 10: // Login Error
  665.         string = "";
  666.         text = ControlAction.getText(4, 199, 377, 402, 140);
  667.  
  668.         if (text) {
  669.             for (i = 0; i < text.length; i += 1) {
  670.                 string += text[i];
  671.  
  672.                 if (i !== text.length - 1) {
  673.                     string += " ";
  674.                 }
  675.             }
  676.  
  677.             switch (string) {
  678.             case getLocaleString(5207):
  679.                 D2Bot.updateStatus("Invalid Password");
  680.                 D2Bot.printToConsole("Invalid Password");
  681.  
  682.                 break;
  683.             case getLocaleString(5208):
  684.                 D2Bot.updateStatus("Invalid Account");
  685.                 D2Bot.printToConsole("Invalid Account");
  686.  
  687.                 break;
  688.             case getLocaleString(5202): // cd key intended for another product
  689.             case getLocaleString(10915): // lod key intended for another product
  690.                 D2Bot.updateStatus("Invalid CDKey");
  691.                 D2Bot.printToConsole("Invalid CDKey: " + gameInfo.mpq, 6);
  692.                 D2Bot.CDKeyDisabled();
  693.  
  694.                 if (gameInfo.switchKeys) {
  695.                     ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  696.                     D2Bot.restart(true);
  697.                 } else {
  698.                     D2Bot.stop();
  699.                 }
  700.  
  701.                 break;
  702.             case getLocaleString(5199):
  703.                 D2Bot.updateStatus("Disabled CDKey");
  704.                 D2Bot.printToConsole("Disabled CDKey: " + gameInfo.mpq, 6);
  705.                 D2Bot.CDKeyDisabled();
  706.  
  707.                 if (gameInfo.switchKeys) {
  708.                     ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  709.                     D2Bot.restart(true);
  710.                 } else {
  711.                     D2Bot.stop();
  712.                 }
  713.  
  714.                 break;
  715.             case getLocaleString(10913):
  716.                 D2Bot.updateStatus("Disabled LoD CDKey");
  717.                 D2Bot.printToConsole("Disabled LoD CDKey: " + gameInfo.mpq, 6);
  718.                 D2Bot.CDKeyDisabled();
  719.  
  720.                 if (gameInfo.switchKeys) {
  721.                     ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  722.                     D2Bot.restart(true);
  723.                 } else {
  724.                     D2Bot.stop();
  725.                 }
  726.  
  727.                 break;
  728.             case getLocaleString(5347):
  729.                 D2Bot.updateStatus("Disconnected");
  730.                 D2Bot.printToConsole("Disconnected");
  731.                 ControlAction.click(6, 335, 412, 128, 35);
  732.  
  733.                 break MainSwitch;
  734.             default:
  735.                 D2Bot.updateStatus("Login Error");
  736.                 D2Bot.printToConsole("Login Error - " + string);
  737.  
  738.                 if (gameInfo.switchKeys) {
  739.                     ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  740.                     D2Bot.restart(true);
  741.                 } else {
  742.                     D2Bot.stop();
  743.                 }
  744.  
  745.                 break;
  746.             }
  747.         }
  748.  
  749.         ControlAction.click(6, 335, 412, 128, 35);
  750.  
  751.         while (true) {
  752.             delay(1000);
  753.         }
  754.  
  755.         break;
  756.     case 11: // Unable To Connect
  757.         D2Bot.updateStatus("Unable To Connect");
  758.  
  759.         if (connectFail) {
  760.             ControlAction.timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
  761.  
  762.             connectFail = false;
  763.         }
  764.  
  765.         if (!ControlAction.click(6, 335, 450, 128, 35)) {
  766.             break;
  767.         }
  768.  
  769.         connectFail = true;
  770.  
  771.         break;
  772.     case 13: // Realm Down - Character Select screen
  773.         D2Bot.updateStatus("Realm Down");
  774.         delay(1000);
  775.  
  776.         if (!ControlAction.click(6, 33, 572, 128, 35)) {
  777.             break;
  778.         }
  779.  
  780.         updateCount();
  781.         ControlAction.timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
  782.         D2Bot.CDKeyRD();
  783.  
  784.         if (gameInfo.switchKeys && !gameInfo.rdBlocker) {
  785.             D2Bot.printToConsole("Realm Down - Changing CD-Key");
  786.             ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  787.             D2Bot.restart(true);
  788.         } else {
  789.             D2Bot.printToConsole("Realm Down - Restart");
  790.             D2Bot.restart();
  791.         }
  792.  
  793.         break;
  794.     case 14: // Character Select / Main Menu - Disconnected
  795.         D2Bot.updateStatus("Disconnected");
  796.         delay(500);
  797.         ControlAction.click(6, 351, 337, 96, 32);
  798.  
  799.         break;
  800.     case 16: // Character Select - Please Wait popup
  801.         if (!locationTimeout(StarterConfig.PleaseWaitTimeout, location)) {
  802.             ControlAction.click(6, 351, 337, 96, 32);
  803.         }
  804.  
  805.         break;
  806.     case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  807.         delay(1000);
  808.         ControlAction.click(6, 351, 337, 96, 32);
  809.  
  810.         break;
  811.     case 19: // Login - Cdkey In Use
  812.         D2Bot.printToConsole(gameInfo.mpq + " is in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
  813.         D2Bot.CDKeyInUse();
  814.  
  815.         if (gameInfo.switchKeys) {
  816.             ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  817.             D2Bot.restart(true);
  818.         } else {
  819.             ControlAction.click(6, 335, 450, 128, 35);
  820.             ControlAction.timeoutDelay("CD-Key in use", StarterConfig.CDKeyInUseDelay * 6e4);
  821.         }
  822.  
  823.         break;
  824.     case 20: // Single Player - Select Difficulty
  825.         break;
  826.     case 21: // Main Menu - Connecting
  827.         if (!locationTimeout(StarterConfig.ConnectingTimeout, location)) {
  828.             ControlAction.click(6, 330, 416, 128, 35);
  829.         }
  830.  
  831.         break;
  832.     case 22: // Login - Invalid Cdkey (classic or xpac)
  833.         text = ControlAction.getText(4, 162, 270, 477, 50);
  834.         string = "";
  835.  
  836.         if (text) {
  837.             for (i = 0; i < text.length; i += 1) {
  838.                 string += text[i];
  839.  
  840.                 if (i !== text.length - 1) {
  841.                     string += " ";
  842.                 }
  843.             }
  844.         }
  845.  
  846.         switch (string) {
  847.         case getLocaleString(10914):
  848.             D2Bot.printToConsole(gameInfo.mpq + " LoD key in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
  849.             D2Bot.CDKeyInUse();
  850.  
  851.             if (gameInfo.switchKeys) {
  852.                 ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  853.                 D2Bot.restart(true);
  854.             } else {
  855.                 ControlAction.click(6, 335, 450, 128, 35);
  856.                 ControlAction.timeoutDelay("LoD key in use", StarterConfig.CDKeyInUseDelay * 6e4);
  857.             }
  858.  
  859.             break;
  860.         default:
  861.             if (gameInfo.switchKeys) {
  862.                 D2Bot.printToConsole("Invalid CD-Key");
  863.                 ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  864.                 D2Bot.restart(true);
  865.             } else {
  866.                 ControlAction.click(6, 335, 450, 128, 35);
  867.                 ControlAction.timeoutDelay("Invalid CD-Key", StarterConfig.CDKeyInUseDelay * 6e4);
  868.             }
  869.  
  870.             break;
  871.         }
  872.  
  873.         break;
  874.     case 23: // Character Select - Connecting
  875.     case 42: // Empty character screen
  876.         string = "";
  877.         text = ControlAction.getText(4, 45, 318, 531, 140);
  878.  
  879.         if (text) {
  880.             for (i = 0; i < text.length; i += 1) {
  881.                 string += text[i];
  882.  
  883.                 if (i !== text.length - 1) {
  884.                     string += " ";
  885.                 }
  886.             }
  887.  
  888.             if (string === getLocaleString(11161)) { // CDKey disabled from realm play
  889.                 D2Bot.updateStatus("Realm Disabled CDKey");
  890.                 D2Bot.printToConsole("Realm Disabled CDKey: " + gameInfo.mpq, 6);
  891.                 D2Bot.CDKeyDisabled();
  892.  
  893.                 if (gameInfo.switchKeys) {
  894.                     ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  895.                     D2Bot.restart(true);
  896.                 } else {
  897.                     D2Bot.stop();
  898.                 }
  899.             }
  900.         }
  901.  
  902.         if (!locationTimeout(StarterConfig.ConnectingTimeout, location)) {
  903.             ControlAction.click(6, 33, 572, 128, 35);
  904.  
  905.             if (gameInfo.rdBlocker) {
  906.                 D2Bot.restart();
  907.             }
  908.         }
  909.  
  910.         break;
  911.     case 24: // Server Down - not much to do but wait..
  912.         break;
  913.     case 25: // Lobby - Please Wait
  914.         if (!locationTimeout(StarterConfig.PleaseWaitTimeout, location)) {
  915.             ControlAction.click(6, 351, 337, 96, 32);
  916.         }
  917.  
  918.         break;
  919.     case 26: // Lobby - Game Name Exists
  920.         ControlAction.click(6, 533, 469, 120, 20);
  921.  
  922.         gameCount += 1;
  923.         lastGameStatus = "ready";
  924.  
  925.         break;
  926.     case 27: // Gateway Select
  927.         ControlAction.click(6, 436, 538, 96, 32);
  928.  
  929.         break;
  930.     case 28: // Lobby - Game Does Not Exist
  931.         D2Bot.printToConsole("Game doesn't exist");
  932.  
  933.         if (gameInfo.rdBlocker) {
  934.             D2Bot.printToConsole(gameInfo.mpq + " is probably flagged.", 6);
  935.  
  936.             if (gameInfo.switchKeys) {
  937.                 ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
  938.                 D2Bot.restart(true);
  939.             }
  940.         } else {
  941.             locationTimeout(StarterConfig.GameDoesNotExistTimeout, location);
  942.         }
  943.  
  944.         lastGameStatus = "ready";
  945.  
  946.         break;
  947.     case 38: // Game is full
  948.         // doesn't happen when making
  949.         break;
  950.     default:
  951.         if (location !== undefined) {
  952.             D2Bot.printToConsole("Unhandled location " + location);
  953.             //takeScreenshot();
  954.             delay(500);
  955.             D2Bot.restart();
  956.         }
  957.  
  958.         break;
  959.     }
  960. }
Advertisement
Add Comment
Please, Sign In to add comment