Advertisement
kolton

Untitled

Sep 19th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. *   @filename   OOG.js
  3. *   @author     kolton, D3STROY3R
  4. *   @desc       handle out of game operations like creating characters/accounts, maintaining profile datafiles, d2bot# logging etc.
  5. */
  6.  
  7. var D2Bot = {
  8.     printToConsole: function (msg, color) {
  9.         if (arguments.length < 2) {
  10.             sendCopyData(null, "D2Bot #", 0, "printToConsole;" + msg);
  11.         } else {
  12.             sendCopyData(null, "D2Bot #", 0, "printToConsole;" + msg + ";" + color);
  13.         }
  14.     },
  15.     printToItemLog: function (msg, tooltip, code, color1, color2, header, gid) {
  16.         header = header || "";
  17.         gid = gid || "";
  18.  
  19.         sendCopyData(null, "D2Bot #", 0, "printToItemLog;" + msg + "$" + tooltip + "$" + code + "$" + header + "$" + gid + ";" + color1 + ";" + color2 + ";" + header);
  20.     },
  21.     saveItem: function (filename, tooltip, code, color1, color2) {
  22.         sendCopyData(null, "D2Bot #", 0, "saveItem;" + filename + "$" + tooltip + "$" + code + ";" + color1 + ";" + color2);
  23.     },
  24.     updateStatus: function (msg) {
  25.         sendCopyData(null, "D2Bot #", 0, "updateStatus;" + msg);
  26.     },
  27.     updateRuns: function () {
  28.         sendCopyData(null, "D2Bot #", 0, "updateRuns");
  29.     },
  30.     updateChickens: function () {
  31.         sendCopyData(null, "D2Bot #", 0, "updateChickens");
  32.     },
  33.     requestGameInfo: function () {
  34.         sendCopyData(null, "D2Bot #", 0, "requestGameInfo");
  35.         delay(500);
  36.     },
  37.     restart: function (reset) {
  38.         if (arguments.length > 0) {
  39.             sendCopyData(null, "D2Bot #", 0, "restartProfile;" + reset.toString());
  40.         } else {
  41.             sendCopyData(null, "D2Bot #", 0, "restartProfile");
  42.         }
  43.     },
  44.     CDKeyInUse: function () {
  45.         sendCopyData(null, "D2Bot #", 0, "CDKeyInUse");
  46.     },
  47.     CDKeyDisabled: function () {
  48.         sendCopyData(null, "D2Bot #", 0, "CDKeyDisabled");
  49.     },
  50.     CDKeyRD: function () {
  51.         sendCopyData(null, "D2Bot #", 0, "CDKeyRD");
  52.     },
  53.     joinMe: function (window, gameName, gameCount, gamePass, isUp) {
  54.         sendCopyData(null, window, 1, gameName + gameCount + "/" + gamePass + "/" + isUp);
  55.     },
  56.     requestGame: function (who) {
  57.         sendCopyData(null, who, 3, me.profile);
  58.     },
  59.     stop: function () {
  60.         sendCopyData(null, "D2Bot #", 0, "stop"); //this stops current window
  61.     },
  62.     start: function (profile) {
  63.         sendCopyData(null, "D2Bot #", 0, "start;" + profile); //this starts a particular profile.ini
  64.     },
  65.     updateCount: function () {
  66.         sendCopyData(null, "D2Bot #", 0, "updateCount;" + getIP());
  67.     },
  68.     shoutGlobal: function (msg, mode) {
  69.         sendCopyData(null, "D2Bot #", 0, "shoutGlobal;" + msg + ";" + mode.toString() + ";");
  70.     },
  71.     heartBeat: function () {
  72.         sendCopyData(null, "D2Bot #", 0, "heartBeat");
  73.     }
  74. };
  75. var DataFile = {
  76.     create: function () {
  77.         var obj, string;
  78.  
  79.         obj = {
  80.             runs: 0,
  81.             experience: 0,
  82.             deaths: 0,
  83.             lastArea: "",
  84.             gold: 0,
  85.             level: 0
  86.         };
  87.  
  88.         string = JSON.stringify(obj);
  89.  
  90.         //FileTools.writeText("data/" + me.profile + ".json", string);
  91.         Misc.fileAction("data/" + me.profile + ".json", 1, string);
  92.  
  93.         return obj;
  94.     },
  95.  
  96.     getObj: function () {
  97.         var obj, string;
  98.  
  99.         if (!FileTools.exists("data/" + me.profile + ".json")) {
  100.             DataFile.create();
  101.         }
  102.  
  103.         //string = FileTools.readText("data/" + me.profile + ".json");
  104.         string = Misc.fileAction("data/" + me.profile + ".json", 0);
  105.  
  106.         try {
  107.             obj = JSON.parse(string);
  108.         } catch (e) {
  109.             // If we failed, file might be corrupted, so create a new one
  110.             obj = this.create();
  111.         }
  112.  
  113.         return obj;
  114.     },
  115.  
  116.     getStats: function () {
  117.         var obj = this.getObj();
  118.  
  119.         return {runs: obj.runs, experience: obj.experience, lastArea: obj.lastArea, gold: obj.gold, level: obj.level};
  120.     },
  121.  
  122.     updateStats: function (arg, value) {
  123.         var obj, string, area;
  124.  
  125.         obj = this.getObj();
  126.  
  127.         switch (arg) {
  128.         case "runs":
  129.             obj.runs = value;
  130.  
  131.             break;
  132.         case "experience":
  133.             obj.experience = me.getStat(13);
  134.             obj.level = me.getStat(12);
  135.  
  136.             break;
  137.         case "lastArea":
  138.             area = getArea();
  139.  
  140.             if (typeof area !== "object") {
  141.                 return;
  142.             }
  143.  
  144.             if (obj.lastArea === getArea().name) {
  145.                 return;
  146.             }
  147.  
  148.             obj.lastArea = getArea().name;
  149.  
  150.             break;
  151.         case "gold":
  152.             obj.gold = me.getStat(14) + me.getStat(15);
  153.  
  154.             break;
  155.         }
  156.  
  157.         string = JSON.stringify(obj);
  158.  
  159.         //FileTools.writeText("data/" + me.profile + ".json", string);
  160.         Misc.fileAction("data/" + me.profile + ".json", 1, string);
  161.     },
  162.  
  163.     updateDeaths: function () {
  164.         var obj, string;
  165.  
  166.         obj = this.getObj();
  167.         obj.deaths = obj.deaths + 1;
  168.         string = JSON.stringify(obj);
  169.  
  170.         //FileTools.writeText("data/" + me.profile + ".json", string);
  171.         Misc.fileAction("data/" + me.profile + ".json", 1, string);
  172.     }
  173. };
  174.  
  175. var ControlAction = {
  176.     click: function (type, x, y, xsize, ysize, targetx, targety) {
  177.         var control = getControl(type, x, y, xsize, ysize);
  178.  
  179.         if (!control) {
  180.             print("control not found " + type + " " + x + " " + y);
  181.             return false;
  182.         }
  183.  
  184.         //delay(clickdelay);
  185.         delay(200);
  186.         control.click(targetx, targety);
  187.  
  188.         return true;
  189.     },
  190.  
  191.     setText: function (type, x, y, xsize, ysize, text) {
  192.         var control = getControl(type, x, y, xsize, ysize);
  193.  
  194.         if (!control) {
  195.             return false;
  196.         }
  197.  
  198.         //delay(textdelay);
  199.         delay(200);
  200.         control.setText(text);
  201.  
  202.         return true;
  203.     },
  204.  
  205.     getText: function (type, x, y, xsize, ysize) {
  206.         var control = getControl(type, x, y, xsize, ysize);
  207.  
  208.         if (!control) {
  209.             return false;
  210.         }
  211.  
  212.         return control.getText();
  213.     },
  214.  
  215.     clickRealm: function (realm) {
  216.         if (realm < 0 || realm > 3) {
  217.             throw new Error("clickRealm: Invalid realm!");
  218.         }
  219.  
  220.         var control, currentRealm;
  221.  
  222.         me.blockMouse = true;
  223.  
  224. MainLoop:
  225.         while (true) {
  226.             switch (getLocation()) {
  227.             case 8:
  228.                 control = getControl(6, 264, 391, 272, 25);
  229.  
  230.                 if (control) {
  231.                     switch (control.text.split(getLocaleString(11049).substring(0, getLocaleString(11049).length - 2))[1]) {
  232.                     case "U.S. EAST":
  233.                         currentRealm = 1;
  234.  
  235.                         break;
  236.                     case "U.S. WEST":
  237.                         currentRealm = 0;
  238.  
  239.                         break;
  240.                     case "ASIA":
  241.                         currentRealm = 2;
  242.  
  243.                         break;
  244.                     case "EUROPE":
  245.                         currentRealm = 3;
  246.  
  247.                         break;
  248.                     }
  249.                 }
  250.  
  251.                 if (currentRealm === realm) {
  252.                     break MainLoop;
  253.                 }
  254.  
  255.                 this.click(6, 264, 391, 272, 25);
  256.  
  257.                 break;
  258.             case 27:
  259.                 this.click(4, 257, 500, 292, 160, 403, 350 + realm * 25);
  260.                 this.click(6, 281, 538, 96, 32);
  261.  
  262.                 break;
  263.             }
  264.  
  265.             delay(500);
  266.         }
  267.  
  268.         me.blockMouse = false;
  269.  
  270.         return true;
  271.     },
  272.  
  273.     loginAccount: function (info) {
  274.         me.blockMouse = true;
  275.  
  276.         var tick, realms = {
  277.             "uswest": 0,
  278.             "useast": 1,
  279.             "asia": 2,
  280.             "europe": 3
  281.         };
  282.  
  283.         tick = getTickCount();
  284.  
  285. MainLoop:
  286.         while (true) {
  287.             switch (getLocation()) {
  288.             case 8: // main menu
  289.                 if (info.realm) {
  290.                     ControlAction.clickRealm(realms[info.realm]);
  291.                 }
  292.  
  293.                 this.click(6, 264, 366, 272, 35);
  294.  
  295.                 break;
  296.             case 9: // login screen
  297.                 this.setText(1, 322, 342, 162, 19, info.account);
  298.                 this.setText(1, 322, 396, 162, 19, info.password);
  299.                 this.click(6, 264, 484, 272, 35); // log in
  300.  
  301.                 break;
  302.             case 11:
  303.                 // Unable to connect, let the caller handle it.
  304.                 me.blockMouse = false;
  305.                 return false;
  306.             case 12: // char screen - break
  307.                 break MainLoop;
  308.             case 18: // splash
  309.                 this.click(2, 0, 599, 800, 600);
  310.  
  311.                 break;
  312.             case 21: // connecting
  313.             case 23: // char screen connecting
  314.                 break;
  315.             case 42: // empty char screen
  316.                 // make sure we're not on connecting screen
  317.                 delay(2000);
  318.  
  319.                 if (getLocation() === 23) {
  320.                     break;
  321.                 }
  322.  
  323.                 break MainLoop; // break if we're sure we're on empty char screen
  324.             default:
  325.                 me.blockMouse = false;
  326.  
  327.                 return false;
  328.             }
  329.  
  330.             if (getTickCount() - tick >= 20000) {
  331.                 return false;
  332.             }
  333.  
  334.             delay(500);
  335.         }
  336.  
  337.         delay(1000);
  338.  
  339.         me.blockMouse = false;
  340.  
  341.         return getLocation() === 12 || getLocation() === 42;
  342.     },
  343.  
  344.     makeAccount: function (info) {
  345.         me.blockMouse = true;
  346.  
  347.         var realms = {
  348.             "uswest": 0,
  349.             "useast": 1,
  350.             "asia": 2,
  351.             "europe": 3
  352.         };
  353.  
  354.         while (getLocation() !== 42) {// cycle until in empty char screen
  355.             switch (getLocation()) {
  356.             case 8: // main menu
  357.                 ControlAction.clickRealm(realms[info.realm]);
  358.                 this.click(6, 264, 366, 272, 35);
  359.  
  360.                 break;
  361.             case 9: // login screen
  362.                 this.click(6, 264, 572, 272, 35);
  363.  
  364.                 break;
  365.             case 18: // splash
  366.                 this.click(2, 0, 599, 800, 600);
  367.  
  368.                 break;
  369.             case 29: // Char create
  370.                 this.click(6, 33, 572, 128, 35);
  371.  
  372.                 break;
  373.             case 31: // ToU
  374.                 this.click(6, 525, 513, 128, 35);
  375.  
  376.                 break;
  377.             case 32: // new account
  378.                 this.setText(1, 322, 342, 162, 19, info.account);
  379.                 this.setText(1, 322, 396, 162, 19, info.password);
  380.                 this.setText(1, 322, 450, 162, 19, info.password);
  381.                 this.click(6, 627, 572, 128, 35);
  382.  
  383.                 break;
  384.             case 33: // please read
  385.                 this.click(6, 525, 513, 128, 35);
  386.  
  387.                 break;
  388.             case 34: // e-mail
  389.                 if (getControl(6, 415, 412, 128, 35)) {
  390.                     this.click(6, 415, 412, 128, 35);
  391.                 } else {
  392.                     this.click(6, 265, 572, 272, 35);
  393.                 }
  394.  
  395.                 break;
  396.             default:
  397.                 break;
  398.             }
  399.  
  400.             delay(500);
  401.         }
  402.  
  403.         me.blockMouse = false;
  404.  
  405.         return true;
  406.     },
  407.  
  408.     findCharacter: function (info) {
  409.         var control, text;
  410.  
  411.         if (getLocation() === 12) {
  412.             control = getControl(4, 37, 178, 200, 92);
  413.  
  414.             if (control) {
  415.                 do {
  416.                     text = control.getText();
  417.  
  418.                     if (text instanceof Array && typeof text[1] === "string" && text[1] === info.charName) {
  419.                         return true;
  420.                     }
  421.                 } while (control.getNext());
  422.             }
  423.         }
  424.  
  425.         return false;
  426.     },
  427.  
  428.     // get all characters
  429.     getCharacters: function () {
  430.         var control, text,
  431.             list = [];
  432.  
  433.         if (getLocation() === 12) {
  434.             control = getControl(4, 37, 178, 200, 92);
  435.  
  436.             if (control) {
  437.                 do {
  438.                     text = control.getText();
  439.  
  440.                     if (text instanceof Array && typeof text[1] === "string") {
  441.                         list.push(text[1]);
  442.                     }
  443.                 } while (control.getNext());
  444.             }
  445.         }
  446.  
  447.         return list;
  448.     },
  449.  
  450.     // get character position
  451.     getPosition: function () {
  452.         var control, text,
  453.             position = 0;
  454.  
  455.         if (getLocation() === 12) {
  456.             control = getControl(4, 37, 178, 200, 92);
  457.  
  458.             if (control) {
  459.                 do {
  460.                     text = control.getText();
  461.  
  462.                     if (text instanceof Array && typeof text[1] === "string") {
  463.                         position += 1;
  464.                     }
  465.                 } while (control.getNext());
  466.             }
  467.         }
  468.  
  469.         return position;
  470.     },
  471.  
  472.     loginCharacter: function (info) {
  473.         me.blockMouse = true;
  474.  
  475.         var control, text;
  476.  
  477.         while (getLocation() !== 1) { // cycle until in lobby
  478.             switch (getLocation()) {
  479.             case 12: // character select
  480.                 control = getControl(4, 37, 178, 200, 92);
  481.  
  482.                 if (control) {
  483.                     do {
  484.                         text = control.getText();
  485.  
  486.                         if (text instanceof Array && typeof text[1] === "string" && text[1].toLowerCase() === info.charName.toLowerCase()) {
  487.                             control.click();
  488.                             this.click(6, 627, 572, 128, 35);
  489.  
  490.                             break;
  491.                         }
  492.                     } while (control.getNext());
  493.                 }
  494.  
  495.                 break;
  496.             case 42: // empty character select
  497.                 this.click(6, 33, 572, 128, 35);
  498.                 break;
  499.             default:
  500.                 break;
  501.             }
  502.  
  503.             delay(500);
  504.         }
  505.  
  506.         me.blockMouse = false;
  507.  
  508.         return true;
  509.     },
  510.  
  511.     makeCharacter: function (info) {
  512.         me.blockMouse = true;
  513.  
  514.         if (!info.charClass) {
  515.             info.charClass = "barbarian";
  516.         }
  517.  
  518.         var clickCoords = [];
  519.  
  520.         while (getLocation() !== 1) { // cycle until in lobby
  521.             switch (getLocation()) {
  522.             case 12: // character select
  523.             case 42: // empty character select
  524.                 this.click(6, 33, 528, 168, 60);
  525.  
  526.                 break;
  527.             case 29: // select character
  528.                 switch (info.charClass) {
  529.                 case "barbarian":
  530.                     clickCoords = [400, 280];
  531.  
  532.                     break;
  533.                 case "amazon":
  534.                     clickCoords = [100, 280];
  535.  
  536.                     break;
  537.                 case "necromancer":
  538.                     clickCoords = [300, 290];
  539.  
  540.                     break;
  541.                 case "sorceress":
  542.                     clickCoords = [620, 270];
  543.  
  544.                     break;
  545.                 case "assassin":
  546.                     clickCoords = [200, 280];
  547.  
  548.                     break;
  549.                 case "druid":
  550.                     clickCoords = [700, 280];
  551.  
  552.                     break;
  553.                 case "paladin":
  554.                     clickCoords = [521, 260];
  555.  
  556.                     break;
  557.                 }
  558.  
  559.                 // coords:
  560.                 // zon: 100, 280
  561.                 // barb: 400, 280
  562.                 // necro: 300, 290
  563.                 // sin: 200, 280
  564.                 // paladin: 521 260
  565.                 // sorc: 620, 270
  566.                 // druid: 700, 280
  567.  
  568.                 getControl().click(clickCoords[0], clickCoords[1]);
  569.                 delay(500);
  570.  
  571.                 break;
  572.             case 15: // new character
  573.                 if (getControl(6, 421, 337, 96, 32)) { // hardcore char warning
  574.                     this.click(6, 421, 337, 96, 32);
  575.                 } else {
  576.                     this.setText(1, 318, 510, 157, 16, info.charName);
  577.  
  578.                     if (!info.expansion) {
  579.                         this.click(6, 319, 540, 15, 16);
  580.                     }
  581.  
  582.                     if (!info.ladder) {
  583.                         this.click(6, 319, 580, 15, 16);
  584.                     }
  585.  
  586.                     if (info.hardcore) {
  587.                         this.click(6, 319, 560, 15, 16);
  588.                     }
  589.  
  590.                     this.click(6, 627, 572, 128, 35);
  591.                 }
  592.  
  593.                 break;
  594.             case 30: // char name exists
  595.                 ControlAction.click(6, 351, 337, 96, 32);
  596.  
  597.                 me.blockMouse = false;
  598.  
  599.                 return false;
  600.             default:
  601.                 break;
  602.             }
  603.  
  604.             delay(500);
  605.         }
  606.  
  607.         me.blockMouse = false;
  608.  
  609.         return true;
  610.     }
  611. };
  612.  
  613. var ShitList = {
  614.     create: function () {
  615.         var string,
  616.             obj = {
  617.                 shitlist: []
  618.             };
  619.  
  620.         string = JSON.stringify(obj);
  621.  
  622.         //FileTools.writeText("shitlist.json", string);
  623.         Misc.fileAction("shitlist.json", 1, string);
  624.  
  625.         return obj;
  626.     },
  627.  
  628.     getObj: function () {
  629.         var obj,
  630.             //string = FileTools.readText("shitlist.json");
  631.             string = Misc.fileAction("shitlist.json", 0);
  632.  
  633.         try {
  634.             obj = JSON.parse(string);
  635.         } catch (e) {
  636.             obj = this.create();
  637.         }
  638.  
  639.         return obj;
  640.     },
  641.  
  642.     read: function () {
  643.         var obj;
  644.  
  645.         if (!FileTools.exists("shitlist.json")) {
  646.             this.create();
  647.         }
  648.  
  649.         obj = this.getObj();
  650.  
  651.         return obj.shitlist;
  652.     },
  653.  
  654.     add: function (name) {
  655.         var obj, string;
  656.  
  657.         obj = this.getObj();
  658.  
  659.         obj.shitlist.push(name);
  660.  
  661.         string = JSON.stringify(obj);
  662.  
  663.         //FileTools.writeText("shitlist.json", string);
  664.         Misc.fileAction("shitlist.json", 1, string);
  665.     }
  666. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement