Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @filename D2BotMule.js
- * @author kolton, IMBA
- * @desc Starter for automule profile *continuous muling*
- */
- var StarterConfig = {
- MinGameTime: 30, // Minimum game length in seconds.
- MaxGameTime: 60, // Maximum game length in minutes, only for continuous muling
- SwitchKeyDelay: 300, // Seconds to wait before switching a used/banned key or after realm down
- FTJDelay: 180, // Seconds to wait after failing to create/join a game
- RealmDownDelay: 3, // Minutes to wait after getting Realm Down message
- UnableToConnectDelay: 1, // Minutes to wait after Unable To Connect message
- CDKeyInUseDelay: 1, // Minutes to wait before connecting again if CD-Key is in use.
- ConnectingTimeout: 20, // Seconds to wait before cancelling the 'Connecting...' screen
- PleaseWaitTimeout: 10, // Seconds to wait before cancelling the 'Please Wait...' screen
- WaitInLineTimeout: 600, // Seconds to wait before cancelling the 'Waiting in Line...' screen
- ExitToMenu: false, // Set to true to wait out restriction in main menu or false to wait in lobby.
- };
- var master, gameInfo, connectFail, makeAcc, joinInfo,
- muleMode, muleFilename, muleObj, handle, maxCharCount,
- continuousMule = false,
- firstLogin = true,
- inGame = false,
- makeNext = false,
- status = "loading",
- masterStatus = {
- status: ""
- };
- // Mule Data object manipulates external mule datafile
- var MuleData = {
- // create a new mule datafile
- create: function () {
- var obj, string;
- obj = {
- account: "",
- accNum: 0,
- character: "",
- charNum: 0,
- fullChars: [],
- torchChars: []
- };
- string = JSON.stringify(obj);
- FileTools.writeText(muleFilename, string);
- },
- // read data from the mule datafile and return the data object
- read: function () {
- var obj, string;
- string = FileTools.readText(muleFilename);
- obj = JSON.parse(string);
- return obj;
- },
- // write a data object to the mule datafile
- write: function (obj) {
- var string;
- string = JSON.stringify(obj);
- FileTools.writeText(muleFilename, string);
- }
- };
- function cursorCheck() {
- if (getUnit(100)) {
- if (!isIncluded("common/Prototypes.js")) include("common/Prototypes.js");
- if (!isIncluded("common/Storage.js")) include("common/Storage.js");
- Storage.Init();
- if (!Storage.Inventory.CanFit(getUnit(100)) || !Storage.Inventory.MoveTo(getUnit(100))) {
- getUnit(100).drop();
- }
- }
- return true;
- }
- // stash picked items
- function stashItems() {
- var i,
- items = me.findItems(-1, 0, 3);
- // stash large items first by sorting items by size in descending order
- items.sort(function(a, b) {return (b.sizex * b.sizey - a.sizex * a.sizey);});
- for (i = 0; i < items.length; i += 1) {
- Storage.Stash.MoveTo(items[i]);
- }
- return true;
- }
- // pick items from ground
- function pickItems() {
- var i, items, canFit, item,
- rval = "fail",
- list = [];
- while (!me.name || !me.gameReady) {
- if (!me.ingame) {
- return rval;
- }
- delay(100);
- }
- //delay(1000);
- for (i = 0; i < 3; i += 1) {
- items = me.findItems(-1, 0, 3);
- if (items) {
- break;
- }
- delay(100);
- }
- if (items) {
- for (i = 0; i < items.length; i += 1) {
- if (items[i].mode === 0 && items[i].location === 3 && Town.ignoredItemTypes.indexOf(items[i].itemType) > -1 // drop trash (id/tp scroll primarily)
- && (muleMode === 0 || items[i].classid !== 530)) { // don't drop ID scroll with torch/anni mules
- try {
- items[i].drop();
- } catch (dropError) {
- print("Failed to drop an item.");
- }
- }
- }
- }
- while (me.gameReady) {
- if (masterStatus.status === "done" || continuousMule) {
- item = getUnit(4);
- if (item) {
- do {
- if (getDistance(me, item) < 20 && [3, 5].indexOf(item.mode) > -1 && Town.ignoredItemTypes.indexOf(item.itemType) === -1) { // don't pick up trash
- list.push(copyUnit(item));
- }
- } while (item.getNext());
- }
- // If and only if there is nothing left are we "done"
- if (!continuousMule && list.length === 0) {
- rval = "done";
- break;
- }
- // pick large items first by sorting items by size in descending order and move gheed's charm to the end of the list
- list.sort(function(a, b) {
- if (a.classid === 605 && a.quality === 7 && !Pickit.canPick(a)) {
- return 1;
- }
- if (b.classid === 605 && b.quality === 7 && !Pickit.canPick(b)) {
- return -1;
- }
- return (b.sizex * b.sizey - a.sizex * a.sizey);
- });
- while (list.length > 0) {
- item = list.shift();
- canFit = Storage.Inventory.CanFit(item);
- // Torch handling
- if (muleMode > 0 && item.classid === 604 && item.quality === 7 && !Pickit.canPick(item)) {
- D2Bot.printToConsole("Mule already has a Torch.", 7);
- rval = "next";
- }
- // Anni handling
- if (muleMode > 0 && item.classid === 603 && item.quality === 7 && !Pickit.canPick(item)) {
- D2Bot.printToConsole("Mule already has an Anni.", 7);
- rval = "next";
- }
- // Gheed's Fortune handling
- if (item.classid === 605 && item.quality === 7 && !Pickit.canPick(item)) {
- D2Bot.printToConsole("Mule already has Gheed's.", 7);
- rval = "next";
- }
- if (!canFit) {
- stashItems();
- canFit = Storage.Inventory.CanFit(item);
- }
- if (canFit) {
- Pickit.pickItem(item);
- if (muleMode > 0 && continuousMule && (item.classid === 604 || item.classid === 603)) {
- rval = "next";
- }
- //if (continuousMule && list.length === 0) { // log char on last item pickup (rval done will already trigger logging, this would do it twice in a row)
- // MuleLogger.logChar();
- //}
- } else {
- rval = "next";
- }
- }
- if (rval === "next" || continuousMule) {
- break;
- }
- } else {
- if (!continuousMule) {
- sendCopyData(null, master, 10, JSON.stringify({status: "report"}));
- //D2Bot.shoutGlobal("report", 0);
- }
- }
- delay(500);
- }
- return rval;
- }
- // master/mule communication function
- function ReceiveCopyData(mode, msg) {
- var obj, masterInfo;
- switch (msg) {
- case "Handle":
- handle = mode;
- break;
- }
- // mode check instead of msg check because of crashes
- switch (mode) {
- case 1: // JoinInfo
- //print("Got Join Info");
- joinInfo = JSON.parse(msg);
- break;
- case 2: // game info
- print("Recieved Game Info");
- gameInfo = JSON.parse(msg);
- break;
- case 3: // request game
- break;
- case 4:
- // Heartbeat ping
- if (msg === "pingreq") {
- sendCopyData(null, me.windowtitle, 4, "pingrep");
- }
- break;
- // automule specific
- case 10: // mule request
- obj = JSON.parse(msg);
- if (continuousMule) {
- if (me.ingame) {
- sendCopyData(null, obj.profile, 10, JSON.stringify({status: "ready"}));
- }
- } else {
- if (!master) {
- masterInfo = AutoMule.getMaster(obj);
- if (masterInfo) {
- master = masterInfo.profile;
- muleMode = masterInfo.mode;
- }
- } else {
- if (obj.profile === master) {
- sendCopyData(null, master, 10, JSON.stringify({status: status}));
- } else {
- sendCopyData(null, obj.profile, 10, JSON.stringify({status: "busy"}));
- }
- }
- }
- break;
- case 11: // begin item pickup
- status = "begin";
- break;
- case 12: // get master's status
- masterStatus = JSON.parse(msg);
- break;
- }
- }
- // set next account - increase account number in mule datafile
- function nextAccount() {
- var obj = MuleData.read();
- obj.accNum = obj.accNum + 1;
- obj.account = muleObj.accountPrefix + obj.accNum;
- obj.character = "";
- obj.charNum = 0;
- obj.fullChars = [];
- obj.torchChars = [];
- MuleData.write(obj);
- return obj.account;
- }
- // set next character - increase character number in mule datafile
- function nextChar() {
- var i, num,
- charSuffix = "",
- charNumbers = "abcdefghijklmnopqrstuvwxyz",
- obj = MuleData.read();
- /*if (getLocation() === 12) {
- obj.charNum = ControlAction.getCharacters().length;
- }*/
- // dirty
- if (obj.charNum > 25) {
- obj.charNum = 0;
- }
- num = obj.accNum.toString();
- for (i = 0; i < num.length; i += 1) {
- charSuffix += charNumbers[parseInt(num[i], 10)];
- }
- charSuffix += charNumbers[obj.charNum];
- obj.charNum = obj.charNum + 1;
- obj.character = muleObj.charPrefix + charSuffix;
- MuleData.write(obj);
- return obj.character;
- }
- function locationTimeout(time, location) {
- var endtime = getTickCount() + time;
- while (getLocation() === location && endtime > getTickCount()) {
- delay(500);
- }
- return (getLocation() !== location);
- }
- function ingameTimeout(time) {
- var tick = getTickCount();
- while (getTickCount() - tick < time) {
- if (me.ingame && me.gameReady) {
- return true;
- }
- if (getLocation() === 28) { // game doesn't exist, might need more locs
- break;
- }
- delay(100);
- }
- return me.ingame && me.gameReady;
- }
- function timeoutDelay(text, time) {
- var endTime = getTickCount() + time;
- while (getTickCount() < endTime) {
- D2Bot.updateStatus(text + " (" + Math.floor((endTime - getTickCount()) / 1000) + "s)");
- delay(500);
- }
- }
- function updateCount() {
- D2Bot.updateCount();
- delay(1000);
- ControlAction.click(6, 264, 366, 272, 35);
- var info,
- obj = MuleData.read();
- info = {
- realm: muleObj.realm,
- account: obj.account,
- password: muleObj.accountPassword
- };
- MuleLogger.save(md5(info.realm.toLowerCase() + info.account.toLowerCase()), info.password);
- ControlAction.loginAccount(info);
- delay(1000);
- ControlAction.click(6, 33, 572, 128, 35);
- }
- function checkAnniTorch() {
- while (!me.gameReady) {
- delay(500);
- }
- return me.findItem(603, 0, -1, 7) || me.findItem(604, 0, -1, 7);
- }
- function foreverAlone() {
- var party = getParty();
- if (party) {
- do {
- if (party.name !== me.name) {
- return false;
- }
- } while (party.getNext());
- }
- return true;
- }
- include("json2.js");
- include("oog.js");
- include("automule.js");
- include("mulelogger.js");
- include("torchsystem.js");
- include("NTItemParser.dbl");
- include("common/attack.js");
- include("common/storage.js");
- include("common/pickit.js");
- include("common/town.js");
- include("common/pather.js");
- include("common/misc.js");
- include("common/config.js");
- include("common/prototypes.js");
- include("common/collmap.js");
- addEventListener("copydata", ReceiveCopyData);
- function main() {
- 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 Mule Logger to work properly. Stopping.");
- D2Bot.stop(me.profile, true);
- return;
- }
- D2Bot.updateRuns(); // we need the mule to swap keys somehow after all
- delay(1000);
- continuousMule = AutoMule.isContinousMule();
- if (continuousMule) {
- muleMode = AutoMule.getMuleMode();
- muleObj = AutoMule.getMuleObject(muleMode, "", true);
- muleFilename = AutoMule.getMuleFilename(muleMode, "", true);
- } else {
- // Wait for master before login = give room to determine muling mode (normal or torch)
- while (!master) {
- delay(100);
- }
- print("Master found: " + master);
- muleObj = AutoMule.getMuleObject(muleMode, master);
- muleFilename = AutoMule.getMuleFilename(muleMode, master);
- }
- print("Mule filename: " + muleFilename);
- var obj, tick, idleTick,
- error = 0;
- try {
- // ugly solution to uglier problem - pickItem area update
- if (!FileTools.exists("data/" + me.profile + ".json")) {
- DataFile.create();
- }
- // create mule datafile if it doesn't exist
- if (!FileTools.exists(muleFilename)) {
- MuleData.create();
- }
- obj = MuleData.read();
- if (obj.account && obj.account.indexOf(muleObj.accountPrefix) < 0) {
- MuleData.create();
- }
- } catch (e) {
- print("Caught exception creating data files.");
- print(e);
- D2Bot.printToConsole("DataFileException: " + e.message + " (" + e.fileName.substring(e.fileName.lastIndexOf("\\") + 1, e.fileName.length) + " #" + e.lineNumber + ")");
- }
- while (true) {
- try {
- if (me.ingame && me.gameReady && me.inTown) {
- if (!inGame) {
- if (firstLogin) {
- firstLogin = false;
- } else {
- status = "begin";
- }
- if (status !== "begin") {
- status = "ready";
- }
- D2Bot.updateStatus("In " + (muleMode === 2 ? "anni " : muleMode === 1 ? "torch " : "") + "mule game.");
- D2Bot.printToConsole("In " + (muleMode === 2 ? "anni " : muleMode === 1 ? "torch " : "") + "mule game.", 7);
- tick = getTickCount();
- idleTick = getTickCount() + rand(1200, 1500) * 1000;
- while ((getLocation() !== null || !me.area) && getTickCount() - tick < 5000) {
- delay(200);
- }
- if (!me.ingame || !me.gameReady || !me.inTown) {
- continue;
- }
- Town.goToTown(1);
- Town.move("stash");
- Storage.Init();
- inGame = true;
- if (continuousMule && !muleObj.onlyLogWhenFull) {
- MuleLogger.logChar();
- }
- }
- while (getTickCount() - tick < 60000) {
- if (continuousMule) {
- status = "begin";
- }
- if (status === "begin") {
- break;
- }
- delay(100);
- }
- //print("Delay: " + (getTickCount() - tick));
- if (status !== "begin") {
- D2Bot.printToConsole("Nobody joined - stopping.", 9);
- D2Bot.stop(me.profile, true);
- }
- if (!continuousMule) {
- me.overhead("begin");
- }
- switch (pickItems()) {
- // done picking, tell the master to leave game and kill mule profile
- case "done":
- if (!muleObj.onlyLogWhenFull) MuleLogger.logChar();
- obj = MuleData.read();
- if (checkAnniTorch() && obj.torchChars.indexOf(me.name) === -1) {
- obj.torchChars.push(me.name);
- }
- MuleData.write(obj);
- D2Bot.printToConsole("Done muling.", 7);
- sendCopyData(null, master, 10, JSON.stringify({status: "quit"}));
- //delay(500);
- D2Bot.stop(me.profile, true);
- return;
- // can't fit more items, get to next character or account
- case "next":
- MuleLogger.logChar();
- delay(500);
- makeNext = true;
- obj = MuleData.read();
- if (checkAnniTorch() && obj.torchChars.indexOf(me.name) === -1) {
- obj.torchChars.push(me.name);
- }
- obj.fullChars.push(me.name);
- MuleData.write(obj);
- nextChar();
- D2Bot.printToConsole("Mule full, getting next character.", 7);
- if (StarterConfig.MinGameTime && getTickCount() - tick < StarterConfig.MinGameTime * 1000) {
- while (getTickCount() - tick < StarterConfig.MinGameTime * 1000) {
- me.overhead("Stalling for " + Math.round(((tick + (StarterConfig.MinGameTime * 1000)) - getTickCount()) / 1000) + " Seconds");
- delay(1000);
- }
- }
- cursorCheck();
- D2Bot.restart();
- //quit();
- // TODO: see whether a for loop is better
- while (me.ingame) {
- delay(100);
- }
- break;
- case "fail":
- // Try again
- break;
- }
- if (continuousMule) {
- delay(5000); // pick items every 5s
- if (StarterConfig.MaxGameTime && getTickCount() - tick > StarterConfig.MaxGameTime * 1000 * 60 && foreverAlone()) {
- cursorCheck();
- quit();
- while (me.ingame) {
- delay(100);
- }
- firstLogin = true;
- print("updating runs");
- D2Bot.updateRuns();
- status = "ready";
- inGame = false;
- delay(1000);
- ControlAction.click(6, 693, 490, 80, 20); // Quit from Lobby
- timeoutDelay("Refresh game", 330 * 1000); // 5.5 minutes
- continue;
- }
- }
- if (getTickCount() - idleTick > 0) { // anti-idle
- sendPacket(1, 0x40);
- idleTick += rand(1200, 1500) * 1000;
- }
- }
- if (!me.ingame) {
- delay(1000);
- locationAction(getLocation());
- }
- } catch (e2) {
- showConsole();
- error++;
- print("Caught an exception in the main loop.");
- print(e2);
- D2Bot.printToConsole("MainLoopException: " + e2.message + " (" + e2.fileName.substring(e2.fileName.lastIndexOf("\\") + 1, e2.fileName.length) + " #" + e2.lineNumber + ")");
- var scripts = "Scripts : ";
- var script = getScript();
- if (script) {
- do {
- scripts += script.name + " ";
- } while (script.getNext())
- }
- D2Bot.printToConsole(scripts);
- takeScreenshot();
- if (error > 3) {
- print("Too many errors, restarting...");
- D2Bot.restart();
- }
- delay(5000);
- }
- delay(100);
- }
- }
- function locationAction(location) {
- var i, obj, info, control, string, text, queue;
- MainSwitch:
- switch (location) {
- case 0:
- ControlAction.click();
- break;
- case 1:
- case 3:
- D2Bot.updateStatus("Lobby");
- if (inGame) {
- print("updating runs");
- D2Bot.updateRuns();
- status = "ready";
- inGame = false;
- }
- if (makeNext) {
- ControlAction.click(6, 693, 490, 80, 20);
- break;
- }
- if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
- break;
- }
- if (!locationTimeout(5000, location)) { // in case join button gets bugged
- if (!ControlAction.click(6, 533, 469, 120, 20)) { // Create
- break;
- }
- if (!ControlAction.click(6, 652, 469, 120, 20)) { // Join
- break;
- }
- }
- break;
- case 4: // Create Game
- D2Bot.updateStatus("Creating Game");
- control = getControl(1, 657, 342, 27, 20);
- if (control && control.disabled === 5) {
- ControlAction.click(6, 431, 341, 15, 16); // remove level restriction
- }
- delay(2000);
- // FTJ handler
- if (status === "pending") {
- D2Bot.printToConsole("Failed to create game");
- ControlAction.timeoutDelay("FTJ delay", StarterConfig.FTJDelay * 1e3);
- D2Bot.updateRuns();
- }
- createGame(muleObj.muleGameName[0], muleObj.muleGameName[1]);
- ingameTimeout(5000);
- status = "pending";
- break;
- case 2: // Waiting In Line
- string = "";
- text = ControlAction.getText(4, 427, 234, 300, 100);
- if (text) {
- string = text[3].split("c0")[1].replace(/\s+/g, '');
- queue = parseInt(string);
- if (queue > 0) {
- if (queue < 2000) { // Wait out short queue
- D2Bot.updateStatus("Waiting line... Queue: " + queue);
- if (queue < 10) { // If stuck here for too long, game creation likely failed. Exit to char selection and try again.
- if (!locationTimeout(StarterConfig.WaitInLineTimeout * 1e3, location)) {
- print("Failed to create game");
- ControlAction.click(6, 433, 433, 96, 32); // Cancel creategame
- ControlAction.click(6, 693, 490, 80, 20); // Quit from Lobby
- delay(1000);
- }
- }
- } else if (queue > 20000) { // stop bot if queue is too long
- D2Bot.printToConsole("Restricted... Stopping bot. Queue: " + queue, 9);
- D2Bot.stop(me.profile, true);
- } else {
- print("Restricted... Queue: " + queue);
- D2Bot.printToConsole("Restricted... Queue: " + queue, 9);
- ControlAction.click(6, 433, 433, 96, 32); // Cancel creategame
- if (StarterConfig.ExitToMenu) { // Exit to menu
- ControlAction.click(6, 693, 490, 80, 20); // Quit from Lobby
- delay(1000);
- ControlAction.click(6, 33, 572, 128, 35); // Quit from char selection
- }
- ControlAction.timeoutDelay("Restricted", (queue + 600) * 1000); // Wait out each queue as 1 sec and add extra 10 min
- }
- }
- }
- break;
- case 5: // Join Game
- D2Bot.updateStatus("Join Game");
- if (status === "pending") {
- D2Bot.printToConsole("Failed to join game");
- ControlAction.timeoutDelay("Join Delay", StarterConfig.FTJDelay * 1000);
- D2Bot.updateRuns();
- }
- if (!continuousMule) {
- D2Bot.requestGame(master);
- delay(100);
- }
- delay(2000);
- if (joinInfo && joinInfo.gameName !== "" && joinInfo.inGame) {
- joinGame(joinInfo.gameName, joinInfo.gamePass);
- } else {
- joinGame(muleObj.muleGameName[0], muleObj.muleGameName[1]);
- }
- if (!firstLogin) {
- status = "pending";
- }
- ingameTimeout(5000);
- print("Ingame timeout done.");
- if (getLocation() === 1 && !me.ingame) { // could not join game
- ControlAction.click(6, 533, 469, 120, 20); // create game
- }
- break;
- case 6: // Ladder
- break;
- case 7: // Channel List
- break;
- case 8: // menu
- case 9: // login
- if (makeNext) {
- makeNext = false;
- }
- obj = MuleData.read();
- if (!obj.account || obj.account.indexOf(muleObj.accountPrefix) < 0) {
- nextAccount();
- obj = MuleData.read();
- }
- info = {
- realm: muleObj.realm,
- account: obj.account,
- password: muleObj.accountPassword
- };
- if (makeAcc) {
- ControlAction.makeAccount(info);
- //FileTools.writeText("mules/" + info.account + ".txt", "");
- D2Bot.printToConsole("Made account: " + info.account, 7);
- makeAcc = false;
- break;
- }
- MuleLogger.save(md5(info.realm.toLowerCase() + info.account.toLowerCase()), info.password);
- ControlAction.loginAccount(info);
- 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):
- ControlAction.click(6, 335, 412, 128, 35);
- makeAcc = true;
- break MainSwitch;
- 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 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);
- D2Bot.CDKeyRD();
- 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 18: // splash
- case 12: // char select
- case 15: // new character (selected)
- case 29: // new character (list)
- case 42: // empty char screen
- // Single Player screen fix
- if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
- ControlAction.click(6, 33, 572, 128, 35);
- break;
- }
- 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);
- }
- }
- }
- // Single Player screen fix
- // TODO: see if this is still needed. d2bs doesn't load scripts twice anymore
- if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
- ControlAction.click(6, 33, 572, 128, 35);
- break;
- }
- // Can't create character, button greyed out = high likelyhood of realm down
- if (getLocation() === 42 && getControl(6, 33, 528, 168, 60).disabled === 4) {
- D2Bot.updateStatus("Realm Down");
- delay(1000);
- if (!ControlAction.click(6, 33, 572, 128, 35)) {
- break;
- }
- updateCount();
- timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
- D2Bot.CDKeyRD();
- if (gameInfo.switchKeys) {
- D2Bot.printToConsole("Realm Down - Changing CD-Key");
- timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
- D2Bot.restart(true);
- } else {
- D2Bot.restart();
- }
- }
- obj = MuleData.read();
- maxCharCount = (muleObj.charsPerAcc > 0 ? Math.min(muleObj.charsPerAcc, 18) : 8);
- if (makeNext) {
- if (obj.fullChars.length >= maxCharCount || (muleMode > 0 && obj.torchChars.length >= maxCharCount)) {
- try{
- obj = MuleData.read();
- info = {
- realm: muleObj.realm,
- account: obj.account,
- password: muleObj.accountPassword
- };
- if (!FileTools.exists("PermIt/AddedAccounts.txt")) {
- DataFile.create();
- }
- FileTools.appendText("PermIt/Accounts.txt", me.realm.toLowerCase() + "/" + info.account.toLowerCase() + "/" + muleObj.accountPassword + "\n");
- FileTools.appendText("PermIt/AddedAccounts.txt", me.realm.toLowerCase() + "/" + info.account.toLowerCase() + "/" + muleObj.accountPassword + "\n");
- FileTools.appendText("PermIt/AccountsToLog.txt", me.realm.toLowerCase() + "/" + info.account.toLowerCase() + "/" + muleObj.accountPassword + "\n");
- D2Bot.printToConsole("Added Mule Account: " + info.account.toLowerCase() + " to PermIt", 7);
- }catch(e){
- if (!FileTools.exists("PermIt/FailedAccounts.txt")) {
- DataFile.create();
- }
- FileTools.appendText("PermIt/FailedAccounts.txt", info.account.toLowerCase() + "\n");
- D2Bot.printToConsole("Failed to add mule account: " + info.account.toLowerCase() + "to PermIt", 9);
- }
- ControlAction.click(6, 33, 572, 128, 35);
- nextAccount();
- break;
- }
- makeNext = false;
- }
- if (!obj.character || obj.character.indexOf(muleObj.charPrefix) < 0) {
- nextChar();
- obj = MuleData.read();
- }
- info = {
- account: obj.account,
- charName: obj.character,
- ladder: muleObj.ladder,
- hardcore: muleObj.hardcore,
- expansion: muleObj.expansion,
- charClass: "amazon"
- };
- if (muleMode > 0 && obj.torchChars.indexOf(info.charName) > -1) {
- nextChar();
- break;
- }
- if (me.realm.toLowerCase() !== muleObj.realm) {
- D2Bot.restart();
- }
- if (ControlAction.findCharacter(info)) {
- ControlAction.loginCharacter(info, false);
- } else {
- if (ControlAction.getCharacters().length >= maxCharCount) { // premade account that's already full
- try{
- obj = MuleData.read();
- info = {
- realm: muleObj.realm,
- account: obj.account,
- password: muleObj.accountPassword
- };
- if (!FileTools.exists("PermIt/AddedAccounts.txt")) {
- DataFile.create();
- }
- FileTools.appendText("PermIt/Accounts.txt", me.realm.toLowerCase() + "/" + info.account.toLowerCase() + "/" + muleObj.accountPassword + "\n");
- FileTools.appendText("PermIt/AddedAccounts.txt", me.realm.toLowerCase() + "/" + info.account.toLowerCase() + "/" + muleObj.accountPassword + "\n");
- D2Bot.printToConsole("Added Mule Account: " + info.account.toLowerCase() + " to PermIt", 7);
- }catch(e){
- if (!FileTools.exists("PermIt/FailedAccounts.txt")) {
- DataFile.create();
- }
- FileTools.appendText("PermIt/FailedAccounts.txt", info.account.toLowerCase() + "\n");
- D2Bot.printToConsole("Failed to add Mule Account: " + info.account.toLowerCase() + "to PermIt", 9);
- }
- ControlAction.click(6, 33, 572, 128, 35);
- nextAccount();
- break;
- }
- if (!ControlAction.makeCharacter(info)) {
- // TODO: check if acc is full and cancel location 15 and 29 if true
- nextChar();
- break;
- }
- FileTools.appendText("logs/" + me.profile + ".charlist.txt", info.account + "/" + info.charName + '\n');
- D2Bot.printToConsole("Made character: " + info.charName, 7);
- }
- 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, 528, 168, 60); //Click create char button on infinite "connecting" screen
- delay(1000);
- ControlAction.click(6, 33, 572, 128, 35); //Click exit
- delay(1000);
- if (getLocation() !== 23) {
- break;
- }
- 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: // game already exists
- ControlAction.click(6, 652, 469, 120, 20); // Join
- 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 30: // charname already exists
- ControlAction.click(6, 351, 337, 96, 32);
- ControlAction.click(6, 33, 572, 128, 35);
- break;
- case 34: // Email registration
- if (getControl(6, 415, 412, 128, 35)) {
- ControlAction.click(6, 415, 412, 128, 35);
- } else {
- ControlAction.click(6, 265, 572, 272, 35);
- }
- break;
- case 38: // Game is full
- break; // not sure how/if to handle
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement