Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var StarterConfig = {
- 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
- CreateGameDelay: rand(5, 15), // Seconds to wait before creating a new game
- SwitchKeyDelay: 0, // Seconds to wait before switching a used/banned key or after realm down
- CrashDelay: rand(60, 120), // Seconds to wait after a d2 window crash
- RealmDownDelay: rand(3, 6), // Minutes to wait after getting Realm Down message
- UnableToConnectDelay: rand(5, 8), // Minutes to wait after Unable To Connect message
- CDKeyInUseDelay: rand(5, 8), // Minutes to wait before connecting again if CD-Key is in use. SwitchKeys overrides this!
- ConnectingTimeout: rand(20, 30), // Seconds to wait before cancelling the 'Connecting...' screen
- PleaseWaitTimeout: rand(10, 20), // Seconds to wait before cancelling the 'Please Wait...' screen
- WaitInLineTimeout: rand(30, 60) // Seconds to wait before cancelling the 'Waiting in Line...' screen
- };
- var RefreshAccounts = {
- /* Format:
- "account1/password1/realm": ["charname1", "charname2 etc"],
- "account2/password2/realm": ["charnameX", "charnameY etc"],
- "account3/password3/realm": ["all"]
- To log a full account, put "account/password/realm": ["all"]
- realm = useast, uswest, europe or asia
- Individual entries are separated with a comma.
- */
- "account/password/realm": ["all"]
- }
- // No touchy!
- include("json2.js");
- include("OOG.js");
- include("common/misc.js");
- if (!FileTools.exists("data/" + me.profile + ".json")) {
- DataFile.create();
- }
- var handle, gameInfo, connectFail, currAcc, charList,
- accounts = [],
- chars = [];
- function save(hash, data) {
- var filename = "data/secure/" + hash + ".txt";
- FileTools.writeText(filename, data);
- }
- function parseInfo() {
- var i;
- for (i in RefreshAccounts) {
- if (RefreshAccounts.hasOwnProperty(i) && typeof i === "string") {
- accounts.push(i);
- chars.push(RefreshAccounts[i]);
- }
- }
- }
- function ReceiveCopyData(mode, msg) {
- switch (msg) {
- case "Handle":
- handle = mode;
- break;
- }
- switch (mode) {
- case 2: // game info
- print("Recieved Game Info");
- gameInfo = JSON.parse(msg);
- break;
- case 4:
- // Heartbeat ping
- if (msg === "pingreq") {
- sendCopyData(null, me.windowtitle, 4, "pingrep");
- }
- break;
- }
- }
- function timeoutDelay(text, time) {
- var endTime = getTickCount() + time;
- while (getTickCount() < endTime) {
- D2Bot.updateStatus(text + " (" + Math.floor((endTime - getTickCount()) / 1000) + "s)");
- delay(500);
- }
- }
- function locationTimeout(time, location) {
- var endtime = getTickCount() + time;
- while (getLocation() === location && endtime > getTickCount()) {
- delay(500);
- }
- return (getLocation() !== location);
- }
- function updateCount() {
- D2Bot.updateCount();
- delay(1000);
- ControlAction.click(6, 264, 366, 272, 35);
- try {
- login(me.profile);
- } catch (e) {
- }
- delay(1000);
- ControlAction.click(6, 33, 572, 128, 35);
- }
- function countdowntimer (tick) {
- return " (" + new Date(tick - getTickCount()).toISOString().slice(11, -5) + ")";
- }
- function main() {
- addEventListener('copydata', ReceiveCopyData);
- while (!handle) {
- delay(100);
- }
- DataFile.updateStats("handle", handle);
- D2Bot.init();
- load("tools/heartbeat.js");
- while (!gameInfo) {
- D2Bot.requestGameInfo();
- delay(500);
- }
- if (gameInfo.rdBlocker) {
- D2Bot.printToConsole("You must disable RD Blocker for Timer Refresh to work properly. Stopping.");
- D2Bot.stop(me.profile, true);
- return;
- }
- parseInfo();
- if (gameInfo.error) {
- if (!!DataFile.getStats().debugInfo) {
- gameInfo.crashInfo = DataFile.getStats().debugInfo;
- D2Bot.printToConsole("Crash Info: Script: " + JSON.parse(gameInfo.crashInfo).currScript + " Area: " + JSON.parse(gameInfo.crashInfo).area, 10);
- }
- ControlAction.timeoutDelay("Crash Delay", StarterConfig.CrashDelay * 1e3);
- D2Bot.updateRuns();
- }
- DataFile.updateStats("debugInfo", JSON.stringify({currScript: "none", area: "out of game"}));
- while (true) {
- locationAction(getLocation());
- delay(1000);
- }
- }
- function locationAction(location) {
- var i, control, string, text, currChar,
- obj = {};
- MainSwitch:
- switch (location) {
- case 0:
- break;
- case 1: // Lobby
- case 3: // Lobby Chat
- D2Bot.updateStatus("Lobby");
- // delay and show remaining lobby time
- var tick,
- tick = getTickCount() + rand(15000, 25000);
- D2Bot.printToConsole(" char: " + me.charname);
- while (getTickCount() - tick < 0) {
- D2Bot.updateStatus("Lobby: " + countdowntimer(tick));
- delay(1000);
- }
- ControlAction.click(6, 693, 490, 80, 20); // Quit from Lobby
- delay(rand(1500, 3000));
- break;
- case 2: // Waiting In Line
- D2Bot.updateStatus("Waiting...");
- locationTimeout(StarterConfig.WaitInLineTimeout * 1e3, location);
- ControlAction.click(6, 433, 433, 96, 32);
- break;
- case 4: // Create Game
- D2Bot.updateStatus("Creating Game");
- break;
- case 5: // Join Game
- break;
- case 6: // Ladder
- break;
- case 7: // Channel List
- break;
- case 8: // Main Menu
- case 9: // Login
- case 18: // D2 Splash
- if (!accounts.length) {
- FileTools.remove("logs/CharLog.json");
- FileTools.remove("data/" + me.profile + ".json");
- delay(1000);
- D2Bot.printToConsole("Done refreshing countdown timer!");
- D2Bot.stop(me.profile, true);
- break;
- }
- if (FileTools.exists("logs/CharLog.json")) {
- obj = JSON.parse(FileTools.readText("logs/CharLog.json"));
- if (obj.currAcc) {
- for (i = 0; i < accounts.length; i += 1) {
- if (accounts[i].split("/")[0] === obj.currAcc) {
- accounts.splice(0, i);
- chars.splice(0, i);
- i -= 1;
- break;
- }
- }
- }
- }
- currAcc = accounts[0];
- currAcc = currAcc.split("/");
- charList = chars[0];
- obj.currAcc = currAcc[0];
- FileTools.writeText("logs/CharLog.json", JSON.stringify(obj));
- save(md5(currAcc[2].toLowerCase() + currAcc[0].toLowerCase()), currAcc[1]);
- D2Bot.printToConsole("account: " + currAcc[0]);
- delay(rand(500, 1500));
- ControlAction.loginAccount({account: currAcc[0], password: currAcc[1], realm: currAcc[2]});
- delay(rand(500, 1500));
- accounts.shift(); // remove current account from the list
- break;
- case 10: // Login Error
- string = "";
- text = ControlAction.getText(4, 199, 377, 402, 140);
- if (text) {
- for (i = 0; i < text.length; i += 1) {
- string += text[i];
- if (i !== text.length - 1) {
- string += " ";
- }
- }
- switch (string) {
- case getLocaleString(5207):
- D2Bot.updateStatus("Invalid Password");
- D2Bot.printToConsole("Invalid Password");
- break;
- case getLocaleString(5208):
- D2Bot.updateStatus("Invalid Account");
- D2Bot.printToConsole("Invalid Account");
- break;
- case getLocaleString(5202): // cd key intended for another product
- case getLocaleString(10915): // lod key intended for another product
- D2Bot.updateStatus("Invalid CDKey");
- D2Bot.printToConsole("Invalid CDKey: " + gameInfo.mpq, 6);
- D2Bot.CDKeyDisabled();
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.stop(me.profile, true);
- }
- break;
- case getLocaleString(5199):
- D2Bot.updateStatus("Disabled CDKey");
- D2Bot.printToConsole("Disabled CDKey: " + gameInfo.mpq, 6);
- D2Bot.CDKeyDisabled();
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.stop(me.profile, true);
- }
- break;
- case getLocaleString(10913):
- D2Bot.updateStatus("Disabled LoD CDKey");
- D2Bot.printToConsole("Disabled LoD CDKey: " + gameInfo.mpq, 6);
- D2Bot.CDKeyDisabled();
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.stop(me.profile, true);
- }
- break;
- case getLocaleString(5347):
- D2Bot.updateStatus("Disconnected");
- D2Bot.printToConsole("Disconnected");
- ControlAction.click(6, 335, 412, 128, 35);
- break MainSwitch;
- default:
- D2Bot.updateStatus("Login Error");
- D2Bot.printToConsole("Login Error - " + string);
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.stop(me.profile, true);
- }
- break;
- }
- }
- ControlAction.click(6, 335, 412, 128, 35);
- while (true) {
- delay(1000);
- }
- break;
- case 11: // Unable To Connect
- D2Bot.updateStatus("Unable To Connect");
- if (connectFail) {
- timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
- connectFail = false;
- }
- if (!ControlAction.click(6, 335, 450, 128, 35)) {
- break;
- }
- connectFail = true;
- break;
- case 12: // Character Select
- // Single Player screen fix
- if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
- ControlAction.click(6, 33, 572, 128, 35);
- break;
- }
- if (!charList.length) {
- ControlAction.click(6, 33, 572, 128, 35);
- break;
- }
- if (charList[0] === "all") {
- charList = ControlAction.getCharacters();
- }
- if (FileTools.exists("logs/CharLog.json")) {
- obj = JSON.parse(FileTools.readText("logs/CharLog.json"));
- if (obj.currChar) {
- for (i = 0; i < charList.length; i += 1) {
- if (charList[i] === obj.currChar) {
- charList.splice(0, i + 1); // Remove the previous currChar as well
- break;
- }
- }
- }
- }
- // last char in acc = trigger next acc
- if (!charList.length) {
- accounts.shift(); // remove current account from the list
- chars.shift();
- break;
- }
- currChar = charList.shift();
- obj.currChar = currChar;
- FileTools.writeText("logs/CharLog.json", JSON.stringify(obj));
- ControlAction.loginCharacter({charName: currChar});
- break;
- case 13: // Realm Down - Character Select screen
- D2Bot.updateStatus("Realm Down");
- delay(1000);
- if (!ControlAction.click(6, 33, 572, 128, 35)) {
- break;
- }
- updateCount();
- timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
- if (gameInfo.switchKeys) {
- D2Bot.printToConsole("Realm Down - Changing CD-Key");
- timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.restart();
- }
- break;
- case 14: // Character Select / Main Menu - Disconnected
- D2Bot.updateStatus("Disconnected");
- delay(500);
- ControlAction.click(6, 351, 337, 96, 32);
- break;
- case 15: // New Character
- break;
- case 16: // Character Select - Please Wait popup
- if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
- ControlAction.click(6, 351, 337, 96, 32);
- }
- break;
- case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
- delay(1000);
- ControlAction.click(6, 351, 337, 96, 32);
- break;
- case 19: // Login - Cdkey In Use
- D2Bot.printToConsole(gameInfo.mpq + " is in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
- D2Bot.CDKeyInUse();
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- ControlAction.click(6, 335, 450, 128, 35);
- ControlAction.timeoutDelay("CD-Key in use", StarterConfig.CDKeyInUseDelay * 6e4);
- }
- break;
- case 20: // Single Player - Select Difficulty
- break;
- case 21: // Main Menu - Connecting
- if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
- ControlAction.click(6, 330, 416, 128, 35);
- }
- break;
- case 22: // Login - Invalid Cdkey (classic or xpac)
- text = ControlAction.getText(4, 162, 270, 477, 50);
- string = "";
- if (text) {
- for (i = 0; i < text.length; i += 1) {
- string += text[i];
- if (i !== text.length - 1) {
- string += " ";
- }
- }
- }
- switch (string) {
- case getLocaleString(10914):
- D2Bot.printToConsole(gameInfo.mpq + " LoD key in use by " + ControlAction.getText(4, 158, 310, 485, 40), 6);
- D2Bot.CDKeyInUse();
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- ControlAction.click(6, 335, 450, 128, 35);
- ControlAction.timeoutDelay("LoD key in use", StarterConfig.CDKeyInUseDelay * 6e4);
- }
- break;
- default:
- if (gameInfo.switchKeys) {
- D2Bot.printToConsole("Invalid CD-Key");
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- ControlAction.click(6, 335, 450, 128, 35);
- ControlAction.timeoutDelay("Invalid CD-Key", StarterConfig.CDKeyInUseDelay * 6e4);
- }
- break;
- }
- break;
- case 23: // Character Select - Connecting
- if (!locationTimeout(StarterConfig.ConnectingTimeout * 1e3, location)) {
- ControlAction.click(6, 33, 572, 128, 35);
- }
- break;
- case 24: // Server Down - not much to do but wait..
- break;
- case 25: // Lobby - Please Wait
- if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
- ControlAction.click(6, 351, 337, 96, 32);
- }
- break;
- case 26: // Lobby - Game Name Exists
- ControlAction.click(6, 533, 469, 120, 20);
- break;
- case 27: // Gateway Select
- ControlAction.click(6, 436, 538, 96, 32);
- break;
- case 28: // Lobby - Game Does Not Exist
- ControlAction.click(6, 533, 469, 120, 20);
- break;
- case 38: // Game is full
- D2Bot.printToConsole("Game is full");
- break;
- case 42: // Empty character screen
- // TODO: see if this is needed in case 12 too
- string = "";
- text = ControlAction.getText(4, 45, 318, 531, 140);
- if (text) {
- for (i = 0; i < text.length; i += 1) {
- string += text[i];
- if (i !== text.length - 1) {
- string += " ";
- }
- }
- if (string === getLocaleString(11161)) { // CDKey disabled from realm play
- D2Bot.updateStatus("Realm Disabled CDKey");
- D2Bot.printToConsole("Realm Disabled CDKey: " + gameInfo.mpq, 6);
- D2Bot.CDKeyDisabled();
- if (gameInfo.switchKeys) {
- ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.stop(me.profile, true);
- }
- }
- }
- if (!locationTimeout(5000, location)) {
- accounts.shift(); // remove current account from the list
- chars.shift();
- ControlAction.click(6, 33, 572, 128, 35);
- }
- break;
- default:
- if (location !== undefined) {
- D2Bot.printToConsole("Unhandled location " + location);
- delay(500);
- D2Bot.restart();
- }
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement