mf22

D2BotTcpIpHost.dbj

Sep 9th, 2019 (edited)
1,530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // No touchy!
  2. include("json2.js");
  3. include("OOG.js");
  4. include("gambling.js");
  5. include("craftingsystem.js");
  6. include("common/misc.js");
  7. include("common/util.js");
  8.  
  9. if (!FileTools.exists("data/" + me.profile + ".json")) {
  10.     DataFile.create();
  11. }
  12.  
  13. var gameInfo, gameStart, ingame, handle,
  14.     gameCount = DataFile.getStats().runs + 1,
  15.     lastGameStatus = "ready",
  16.     isUp = "no";
  17.  
  18. function ReceiveCopyData(mode, msg) {
  19.     var obj;
  20.  
  21.     switch (msg) {
  22.     case "Handle":
  23.         handle = mode;
  24.     break;
  25.     }
  26.  
  27.     switch (mode) {
  28.         case 2: // Game info
  29.             gameInfo = JSON.parse(msg);
  30.         break;
  31.         case 3: // Game request
  32.             // Don't let others join mule/torch/key/gold drop game
  33.             if (AutoMule.inGame || Gambling.inGame || TorchSystem.inGame || CraftingSystem.inGame) {
  34.                 break;
  35.             }
  36.             if (gameInfo) {
  37.                 obj = JSON.parse(msg);
  38.  
  39.                 if (me.gameReady) {
  40.                     D2Bot.joinMe(obj.profile, me.gamename.toLowerCase(), "", me.gamepassword.toLowerCase(), isUp);
  41.                 } else {
  42.                     D2Bot.joinMe(obj.profile, gameInfo.gameName.toLowerCase(), gameCount, gameInfo.gamePass.toLowerCase(), isUp);
  43.                 }
  44.             }
  45.         break;
  46.         case 4: // Heartbeat ping
  47.             if (msg === "pingreq") {
  48.                 sendCopyData(null, me.windowtitle, 4, "pingrep");
  49.             }
  50.         break;
  51.         case 0xf124: // Cached info retreival
  52.             if (msg !== "null") {
  53.                 gameInfo.crashInfo = JSON.parse(msg);
  54.             }
  55.         break;
  56.     }
  57. }
  58.  
  59. function timer (tick) {
  60.     return " (" + new Date(getTickCount() - tick).toISOString().slice(11, -5) + ")";
  61. }
  62.  
  63. function main() {
  64.     debugLog(me.profile);
  65.     addEventListener('copydata', ReceiveCopyData);
  66.  
  67.     while (!handle) {
  68.         delay(100);
  69.     }
  70.  
  71.     DataFile.updateStats("handle", handle);
  72.     delay(500);
  73.     D2Bot.init();
  74.     load("tools/heartbeat.js");
  75.  
  76.     while (!gameInfo) {
  77.         D2Bot.requestGameInfo();
  78.         delay(500);
  79.     }
  80.  
  81.     if (gameInfo.error) {
  82.         delay(200);
  83.         if (!!DataFile.getStats().debugInfo) {
  84.             gameInfo.crashInfo = DataFile.getStats().debugInfo;
  85.             D2Bot.printToConsole("Crash Info: Script: " + JSON.parse(gameInfo.crashInfo).currScript + " Area: " + JSON.parse(gameInfo.crashInfo).area, 10);
  86.         }
  87.         ControlAction.timeoutDelay("Crash Delay", 3000);
  88.         D2Bot.updateRuns();
  89.     }
  90.     DataFile.updateStats("debugInfo", JSON.stringify({currScript: "none", area: "out of game"}));
  91.  
  92.     while (true) {
  93.         while (me.ingame) { // returns true before actually in game so we can't only use this check
  94.             if (me.gameReady) { // returns false when switching acts so we can't use while
  95.                 isUp = "yes";
  96.                 if (!ingame) {
  97.                     gameStart = getTickCount();
  98.                     print("Updating Status");
  99.                     lastGameStatus = "ingame";
  100.                     ingame = true;
  101.                     DataFile.updateStats("runs", gameCount);
  102.                     DataFile.updateStats("ingameTick");
  103.                 }
  104.                 D2Bot.updateStatus("Game: " + me.gamename + timer(gameStart));
  105.             }
  106.             delay(1000);
  107.         }
  108.         isUp = "no";
  109.         locationAction(getLocation());
  110.         print(getLocation());
  111.         delay(1000);
  112.     }
  113. }
  114.  
  115. /*Find a control*/
  116. // for(var y=0; y<1000; y++){
  117.     // for(var x=0; x<1000; x++){
  118.         // for(var w=0; w<150; w++){
  119.             // for(var h=0; h<50; h++){
  120.                 // if(getControl(6, x, y, w, h)){
  121.                     // D2Bot.updateStatus(x+", "+y);
  122.                     // delay(5000);
  123.                 // }
  124.             // }
  125.         // }
  126.     // }
  127. // }
  128.  
  129. function locationAction(location) {
  130.     var i, control, string, text;
  131.    
  132.     MainSwitch:
  133.     switch (location) {
  134.         case 0: // Splash Screen
  135.         break;
  136.         case 8: // Main Screen
  137.             ControlAction.click(6, 264, 433, 272, 35); //Other Multiplayer
  138.         break;
  139.         case 12: // Character Select Screen
  140.             try {
  141.                 login(me.profile);
  142.             } catch (err) {
  143.                 print(err+" "+getLocation());
  144.             }
  145.         break;
  146.         case 39: // Other Multiplayer Screen
  147.             ControlAction.click(6, 264, 350, 272, 35); //TCP/IP Game
  148.         break;
  149.         case 40: // TCP IP Screen
  150.             D2Bot.updateStatus("Create Game");
  151.             ControlAction.click(6, 265, 206, 272, 35); //Host Game
  152.             D2Bot.updateCount();
  153.             // ControlAction.click(6, 265, 264, 272, 35); //Join Game
  154.         break;
  155.         case 41: // Join Game
  156.             ControlAction.click(6, 281, 337, 96, 32); //Cancel
  157.             // ControlAction.click(6, 421, 337, 96, 32); //Join
  158.         break;
  159.         default:
  160.             if (location !== undefined) {
  161.                 D2Bot.printToConsole("Unhandled location " + location);
  162.                 delay(500);
  163.                 D2Bot.restart();
  164.             }
  165.         break;
  166.     }
  167. }
Add Comment
Please, Sign In to add comment