Advertisement
kolton

Untitled

Dec 5th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include('controlInfo.dbl')
  2. var gameMaxLength               = 300;    
  3. var gameMinLength               = 50000;    // time in milliseconds, minimum game length, 180 seconds default (1 game/3 minutes)
  4. var unableToConnectRetry        = 5;        // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
  5. var realmDownRetry              = 65;       // time in minutes to retry connecting on a realm down (default is 300 minutes)
  6. var disconnectedRetry           = 5;        // time in minutes to retry on a disconnection (usually ip ban related)
  7. var cdkeyInUseRetry             = 2;        // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
  8. var connectingToBnetTimeout     = 20000;    // time in milliseconds to wait for a login to time out and click cancel and retry
  9. var characterScreenTimeout      = 10000;    // time in milliseconds to wait for character screen to appear
  10. var pleaseWaitTimeout           = 10000;    // time in milliseconds to wait for a please wait popup
  11. var createGameThreshold         = 5000;     // time in milliseconds to wait between making games
  12. var createGameThresholdRandom   = 3000;     // time in milliseconds to randomly add +/- to the game create time
  13. var createGameTimeout           = 5000;     // time in milliseconds to register a failed to create game
  14. var waitInLineTimeout           = 60000;    // time in milliseconds to wait in lines for a create game (60 second default)
  15. var clickdelay                  = 500;      // wait X milliseconds before next action after a click event
  16. var textdelay                   = 500;      // wait X milliseconds before next action after inserting text into a textbox
  17. var clickdelayRandom            = 500;      // random amount of time to add to a click
  18. var textdelayRandom             = 500;      // random amount of time to add to a text set
  19. var gameDoesNotExistdelayMin    = 60000;    // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
  20. var gameDoesNotExistdelayMax    = 60000;    // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
  21. var gameDoesNotExistTimeout     = 30000;    // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
  22. var waitInChatBeforeActionsMin  = 2000;     // min how long to wait before joining channel
  23. var waitInChatBeforeActionsMax  = 3000;     // max how long to wait before joining channel
  24.  
  25. // DONT EDIT ANYTHING BELOW THIS
  26.  
  27.  
  28. // D2BOT Console Command
  29. const D2BOT_JOIN = 1;
  30. const D2BOT_GAMEINFO = 2;
  31. const D2BOT_REQUESTGAME = 3;
  32.  
  33. var lastGameMade = getTickCount();
  34. var lastGameStatus = 0;
  35. var nextGameMake = 0;
  36. var inGameAt = 0;
  37. var chatActionsDone = false;
  38. var lastGameFailed = false;
  39.  
  40. var stallFrequency = 0; //stall after how many games
  41. var stalldelay = 30; //minutes
  42. var currCount = FileTools.readText("data/"+me.profile+".txt");
  43. var gameCount = currCount ? (parseInt(currCount.substring(currCount.indexOf("/") + 1)) + 1) : 1;
  44. var gamePass = "";
  45. var gameName = "";
  46. var difficulty;
  47. var gameFirstRun = true;
  48. var gameStart;
  49. var isUp = false;
  50. var controlData = new controlInfo();
  51. var _ingame = 0;
  52.  
  53. function main()
  54. {
  55.     delay(1000);
  56.     addEventListener('copydata', RecieveCopyData);
  57.     D2Bot.requestGameInfo();   
  58.     controlData.clickdelay = clickdelay;
  59.     controlData.textdelay = textdelay;
  60.     controlData.clickdelayRandom = clickdelayRandom;
  61.     controlData.textdelayRandom = textdelayRandom;
  62.  
  63.     while (1) {
  64.         while (me.gameReady) {
  65.             while(!me.area){ delay(100); }
  66.             isUp = "yes";
  67.            
  68.             if (!_ingame) {
  69.                 D2Bot.updateStatus("Game: " + me.gamename);
  70.                
  71.                 _ingame = true;
  72.                 gameStart = getTickCount();
  73.                 me.maxgametime = gameMaxLength * 1000;
  74.             }
  75.            
  76.             if (me.gamepassword.toLowerCase() !== gamePass.toLowerCase()) {
  77.                 print("leaving game");
  78.                 quit();
  79.             }
  80.            
  81.             if (gameStart) {
  82.                 if (getTickCount() - gameStart >= gameMaxLength * 1000 + 10000) {
  83.                     D2Bot.printToConsole("Deadlock from MAX game time, restarting");
  84.                     D2Bot.restart();
  85.                 }
  86.             }
  87.            
  88.             delay(1000);
  89.         }
  90.        
  91.         isUp = "no";
  92.        
  93.         if (_ingame) {
  94.             D2Bot.printToConsole("Elapsed Time: " + Math.round((getTickCount() - gameStart) / 1000) + "(s)");
  95.             gameCount++;
  96.             FileTools.writeText("data/"+me.profile+".txt", gameCount);
  97.             D2Bot.updateRuns();
  98.             _ingame = false;
  99.         }
  100.        
  101.         locationAction(controlData.getLocation()); 
  102.         delay(400);
  103.     }
  104. }
  105.  
  106. function locationAction(location)
  107. {
  108.     switch(getLocation())
  109.     {
  110.     case 1: // Lobby
  111.         D2Bot.updateStatus("Lobby");
  112.         controlData.click(controlData.controls.lobby.button.create);
  113.        
  114.         //controlData.click(controlData.controls.lobby.button.enterChat);
  115.         //delay (1000);
  116.         break;
  117.     case 2: // Waiting In Line
  118.         D2Bot.updateStatus("Waiting...");
  119.         if(getTickCount()- lastGameMade > waitInLineTimeout)
  120.             controlData.click(controlData.controls.lobby.inLine.button.cancel);
  121.         break;
  122.     case 3: // Lobby Chat
  123.         D2Bot.updateStatus("Lobby Chat");
  124.         if(!chatActionsDone)
  125.         {
  126.             chatActionsDone = true;
  127.             delay(rand(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  128.         }
  129.        
  130.         controlData.click(controlData.controls.lobby.button.create);
  131.         break;
  132.     case 4: // Create Game
  133.         D2Bot.updateStatus("Creating Game");
  134.        
  135.         delay(createGameThreshold);
  136.         controlData.setText( controlData.controls.lobby.create.editBox.gameName, gameName + gameCount );
  137.         delay( 500 );
  138.         if( gamePass != "" )
  139.             controlData.setText( controlData.controls.lobby.create.editBox.password, gamePass );
  140.         delay( 500 );
  141.         if( gameFirstRun ){
  142.             switch( difficulty ){
  143.             case "Normal" : // normal
  144.                 controlData.click( controlData.controls.lobby.create.button.normal );
  145.                 break;
  146.             case "Nightmare" : // nightmare
  147.                 controlData.click( controlData.controls.lobby.create.button.nightmare );
  148.                 break;
  149.             case "Hell" : // hell
  150.                 controlData.click( controlData.controls.lobby.create.button.hell );
  151.                 break;
  152.             }
  153.             gameFirstRun = false;
  154.         }
  155.         delay( 500 );
  156.         controlData.click(controlData.controls.lobby.create.button.createGame);
  157.         break;
  158.  
  159.     case 5: // Join Game
  160.         break;
  161.  
  162.     case 6: // Ladder
  163.         break;
  164.  
  165.     case 7: // Channel List
  166.         break;
  167.  
  168.     case 8: // Main Menu
  169.         D2Bot.updateStatus("Logging In")
  170.        
  171.         try {
  172.             login(me.profile);
  173.         } catch (e) {
  174.        
  175.         }
  176.        
  177.         break;
  178.  
  179.     case 9: // Login
  180.         break;
  181.        
  182.     case 10: // Login Error (this is a fatal error, so stop)
  183.         var i,
  184.             string = "",
  185.             control = getControl(4, 199, 377, 402, 140),
  186.             text = control.getText();
  187.        
  188.         if (text) {
  189.             for (i = 0; i < text.length; i += 1) {
  190.                 string += text[i];
  191.                
  192.                 if (i !== text.length - 1) {
  193.                     string += " ";
  194.                 }
  195.             }
  196.            
  197.             switch (string) {
  198.             case getLocaleString(5199):
  199.                 D2Bot.updateStatus("Disabled CDKey");
  200.                 D2Bot.printToConsole("Disabled CDKey");
  201.                 D2Bot.restart(true);
  202.                
  203.                 break;
  204.             }
  205.         }
  206.        
  207.         D2Bot.updateStatus("Failed Login");
  208.         break;
  209.  
  210.     case 11: // Unable To Connect
  211.         D2Bot.updateStatus("!Connect");
  212.         timeoutdelay(unableToConnectRetry*60*1000, location)
  213.         controlData.click(controlData.controls.login.unableToConnect.button.ok);
  214.         break;
  215.  
  216.     case 12: // Character Select
  217.         break;
  218.     case 13: // Realm Down - Character Select screen
  219.         D2Bot.updateStatus("Realm Down");
  220.         controlData.click(controlData.controls.characterSelect.button.exit);
  221.         delay(realmDownRetry*60*1000);
  222.         D2Bot.restart(true);
  223.         break;
  224.  
  225.     case 14: // Character Select - Disconnected
  226.         break;
  227.  
  228.     case 15: // New Character
  229.         break; 
  230.  
  231.     case 16: // Character Select - Please Wait popup
  232.         break;
  233.  
  234.     case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  235.         controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  236.         break;
  237.  
  238.     case 18: // D2 Splash
  239.         try {
  240.             login(me.profile);
  241.         } catch (e) {
  242.        
  243.         }
  244.        
  245.         break;
  246.  
  247.     case 19: // Login - Cdkey In Use
  248.         D2Bot.CDKeyInUse();
  249.         D2Bot.printToConsole("by" + controlData.get(controlData.controls.login.cdkeyInUse.textBox.byWho).getText());
  250.         D2Bot.restart(true);
  251.         break;
  252.        
  253.     case 20: // Single Player - Select Difficulty
  254.         break;
  255.        
  256.     case 21: // Main Menu - Connecting
  257.         break;
  258.  
  259.     case 22: // Login - Invalid Cdkey (classic or xpac)
  260.         D2Bot.printToConsole("Invalid Cdkey");
  261.         D2Bot.restart(true);
  262.         break;
  263.  
  264.     case 23: // Character Select - Connecting
  265.         if(!locationTimeout(characterScreenTimeout, location))
  266.             controlData.click(controlData.controls.characterSelect.button.exit);
  267.         break;
  268.  
  269.     case 24: // Server Down - not much to do but wait..
  270.         break;
  271.  
  272.     case 25: // Lobby - Please Wait
  273.         delay(pleaseWaitTimeout);
  274.         break;
  275.  
  276.     case 26: // Lobby - Game Name Exists
  277.         gameCount++;  
  278.         break;
  279.  
  280.     case 27: // Gateway Select
  281.         controlData.clickRealmEntry(me.gatewayid);
  282.         controlData.click(controlData.controls.gateway.button.ok);
  283.         break;
  284.  
  285.     case 28: // Lobby - Game Does Not Exist
  286.         inGameAt = rand(gameDoesNotExistdelayMin, gameDoesNotExistdelayMax);
  287.         lastGameStatus = 0;
  288.         setNextGameMake();
  289.         delay(gameDoesNotExistTimeout);
  290.         break;
  291.     }
  292. }
  293.  
  294. function setNextGameMake()
  295. {
  296.     lastGameMade = getTickCount();
  297.     nextGameMake = lastGameMade + createGameThreshold + rand(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  298.     inGameAt = 0;
  299.     chatActionsDone = false;
  300. }
  301.  
  302. function outputGameLength()
  303. {
  304.     if(inGameAt)
  305.     {
  306.         duration = getTickCount() - inGameAt;
  307.  
  308.         inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  309.     }
  310. }
  311.  
  312. function locationTimeout(time, location)
  313. {
  314.     endtime = getTickCount() + time;
  315.  
  316.     while(controlData.getLocation().id == location.id && endtime > getTickCount())
  317.     {
  318.         D2Bot.updateStatus(location.name + " (" + parseInt((endtime-getTickCount())/1000) + "s)");
  319.         delay(500);
  320.     }
  321.  
  322.     return (controlData.getLocation().id != location.id);
  323. }
  324.  
  325. function timeoutdelay(time, location)
  326. {
  327.     endtime = getTickCount() + time;
  328.  
  329.     while(endtime > getTickCount())
  330.     {
  331.         D2Bot.updateStatus(location.name + " (" + parseInt((endtime-getTickCount())/1000) + "s)");
  332.         delay(1000);
  333.     }
  334. }
  335.  
  336. function getRandomString(_length)
  337. {
  338.     var _retString = "";
  339.     var _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  340.  
  341.     while(_length--)
  342.     {
  343.         _retString += _charSet.charAt(rand(0, _charSet.length-1));
  344.         delay(1);
  345.     }
  346.  
  347.     return _retString;
  348. }
  349.  
  350.  
  351. function NT_delay(retry)
  352. {
  353.     if (arguments.length < 1)
  354.         retry = 20;
  355.  
  356.     while (retry-- > 0)
  357.         delay(1000);
  358. }
  359.  
  360. var D2Bot = {
  361.     printToConsole: function(msg) {
  362.         D2BotSendMessage(null, "D2Bot Console", 0, "printToConsole;"+msg);
  363.     },
  364.     printToItemLog: function(msg) {
  365.         D2BotSendMessage(null, "D2Bot Console", 0, "printToItemLog;"+msg);
  366.     },
  367.     updateStatus: function(msg) {
  368.         D2BotSendMessage(null, "D2Bot Console", 0, "updateStatus;"+msg);
  369.     },
  370.     updateRuns: function() {
  371.         D2BotSendMessage(null, "D2Bot Console", 0, "updateRuns");
  372.     },
  373.     updateChickens: function() {
  374.         D2BotSendMessage(null, "D2Bot Console", 0, "updateChickens");
  375.     },
  376.     requestGameInfo: function() {
  377.         D2BotSendMessage(null, "D2Bot Console", 0, "requestGameInfo");
  378.     }, 
  379.     restart: function(reset) {
  380.         D2BotSendMessage(null, "D2Bot Console", 0, "restartProfile;"+reset);
  381.     }, 
  382.     CDKeyInUse: function() {
  383.         D2BotSendMessage(null, "D2Bot Console", 0, "CDKeyInUse");
  384.     },
  385.     joinMe: function(window) {
  386.         D2BotSendMessage(null, window, D2BOT_JOIN, gameName + gameCount+"/"+gamePass+"/"+isUp);
  387.     },
  388.     requestGame: function(who) {
  389.         D2BotSendMessage(null, who, D2BOT_REQUESTGAME, me.profile);
  390.     }  
  391. };
  392.  
  393. function RecieveCopyData(msgID, msg){
  394.     switch(msgID) {
  395.         case D2BOT_GAMEINFO:
  396.             print("Recieved Game Info");
  397.             [gameName, gamePass, difficulty] = msg.split('/');
  398.             break;
  399.         case D2BOT_JOIN:
  400.             [nextGame, gamePass, isUp] = msg.split('/');
  401.             break;
  402.         case D2BOT_REQUESTGAME:
  403.             D2Bot.joinMe(msg);
  404.             break;
  405.     }
  406. }
  407.  
  408. function D2BotSendMessage(winclass, hwnd, msgID, msg){
  409.     for(var i = 0; i < 50; i++){
  410.         if(sendCopyData(winclass, hwnd, msgID,msg)){
  411.             return true;
  412.         }else{
  413.             delay(100);
  414.         }
  415.     }
  416.     return false;
  417. }
  418.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement