Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ====================================================================================================
  2. // v THIS IS THE JUNK YOU'LL WANT TO EDIT v
  3. // Frendless leech starter setting (set to run with op gotv channel bot by default there will be no help on changing this)
  4. // ====================================================================================================
  5. var gamenames = ["Letsbaal-"];  // Game name to search for (CASE-SENSITIVE)
  6.  
  7. var gamepasswords   = [""];                             // Password for that game.
  8.  
  9. var maxRetriesPerGame   = 3;                    // The # of times to try rejoining a *unique* game
  10. var maxRetries      = 3;                    // The # of *different* games to try joining, if all attempts fail, bot will exit to character selection screen and rejoin lobby
  11.  
  12. // ====================================================================================================
  13.  
  14. var gameMinLength           = 0;        // time in milliseconds, minimum game length, 180 seconds default (1 game/3 minutes)
  15. var unableToConnectRetry    = 5;            // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
  16. var realmDownRetry          = 260;          // time in minutes to retry connecting on a realm down (default is 120 minutes)
  17. var disconnectedRetry       = 5;            // time in minutes to retry on a disconnection (usually ip ban related)
  18. var cdkeyInUseRetry         = 1;            // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
  19. var connectingToBnetTimeout     = 20000;        // time in milliseconds to wait for a login to time out and click cancel and retry
  20. var characterScreenTimeout      = 5000;         // time in milliseconds to wait for character screen to appear
  21. var pleaseWaitTimeout       = 2000;         // time in milliseconds to wait for a please wait popup
  22. var createGameThreshold         = 2000;         // time in milliseconds to wait between making games
  23. var createGameThresholdRandom   = 500;          // time in milliseconds to randomly add +/- to the game create time
  24. var createGameTimeout       = 15000;        // time in milliseconds to register a failed to create game
  25. var waitInLineTimeout       = 60000;        // time in milliseconds to wait in lines for a create game (60 second default)
  26. var characterSelectDelay    = 1000;         // time in milliseconds to wait before selecting a character on the char screen
  27. var loginDelay          = 1000;         // time in milliseconds to wait before submitting login information
  28. var clickDelay          = 500;          // wait X milliseconds before next action after a click event
  29. var textDelay           = 500;          // wait X milliseconds before next action after inserting text into a textbox
  30. var clickDelayRandom        = 500;          // random amount of time to add to a click
  31. var textDelayRandom         = 500;          // random amount of time to add to a text set
  32. var gameDoesNotExistDelayMin    = 1000;         // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
  33. var gameDoesNotExistDelayMax    = 2000;         // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
  34. var gameDoesNotExistTimeout = 50;           // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
  35. var waitBeforeEnterChatMin      = 1000;         // min how long to wait before entering chat
  36. var waitBeforeEnterChatMax      = 2000;         // max how long to wait before entering chat
  37. var waitInChatBeforeActionsMin  = 1000;         // min how long to wait before joining channel
  38. var waitInChatBeforeActionsMax  = 2000;         // max how long to wait before joining channel
  39.  
  40. // DONT EDIT ANYTHING BELOW THIS
  41. var extrafilters = [
  42.                     "", " in ",
  43.                     "New game ", " started by",
  44.                     "", " Is next",
  45.                     "Next game is ", "",
  46.                     "", "<-"
  47.                     ];                              // The 2nd filter should be whatever the bot manager says right after the game name
  48.                                                     // If the 2nd filter is empty, the rest of the line is used as the game name
  49. var joinChannelInChat   = "op gotv";                // leave blank to not join a private channel
  50.  
  51. // D2NT Manager Command
  52. const D2NT_MGR_LOADING = 1;
  53. const D2NT_MGR_READY = 2;
  54. const D2NT_MGR_LOGIN = 3;
  55. const D2NT_MGR_CREATE_GAME = 4;
  56. const D2NT_MGR_INGAME = 5;
  57. const D2NT_MGR_RESTART = 6;
  58. const D2NT_MGR_CHICKEN = 7;
  59. const D2NT_MGR_PRINT_STATUS = 8;
  60. const D2NT_MGR_PRINT_LOG = 9;
  61.  
  62. var lastGameMade = GetTickCount();
  63. var nextGameMake = 0;
  64. var inGameAt = 0;
  65. var chatActionsDone = false;
  66. var lastGameStatus = 0; // 0 = OK, 1 = Processing, 2 = Ready for retry
  67. var game = "";
  68. var gamepassword = "";
  69. var retry = 0;
  70. var fullretry = maxRetries;
  71. var samegame = new Array(gamenames.length); // Empty array for however many runs you might be following (default 6)
  72.  
  73. Include("libs/controlInfo.ntl");
  74.  
  75. var controlData = new controlInfo();
  76.  
  77. function NTMain()
  78. {
  79.     Delay(1000);
  80.  
  81.     var _ingame = false;
  82.  
  83.     controlData.clickDelay = clickDelay;
  84.     controlData.textDelay = textDelay;
  85.     controlData.clickDelayRandom = clickDelayRandom;
  86.     controlData.textDelayRandom = textDelayRandom;
  87.  
  88.     while (1)
  89.     {
  90.         if (me.ingame)
  91.         {
  92.             if (!inGameAt)
  93.                 inGameAt = GetTickCount();
  94.  
  95.             if (!_ingame)
  96.             {
  97.                 RunGC(); // run garbage collector between each game
  98.  
  99.                 if (Load("NTBot/NTBotGame.ntj"))
  100.                 {
  101.                     _ingame = true;
  102.  
  103.                     if (me.playtype > 0)
  104.                         sendEventToOOG(D2NT_MGR_INGAME, "In Game.. [IP:" + me.gameserverip.split(".")[3] + "]", 0);
  105.                     else
  106.                         sendEventToOOG(D2NT_MGR_INGAME, "In Game..", 0);
  107.  
  108.                     fullretry = maxRetries;
  109.                     lastGameStatus = 0;
  110.                     game = "";
  111.                 }
  112.             }
  113.  
  114.             Delay(1000);
  115.         }
  116.         else
  117.         {
  118.             Delay(500);
  119.             if (_ingame)
  120.             {
  121.                 _ingame = false;
  122.  
  123.                 // --------------------------
  124.                 // Prevent NT from closing D2
  125.                 // --------------------------
  126.  
  127.                 // Wait for lobby or lobby chat
  128.                 var _location;
  129.                 do
  130.                 {
  131.                     _location = controlData.getLocation();
  132.                     Delay(50);
  133.                 }
  134.                 while (_location.id != 3 && _location.id != 1);
  135.  
  136.                 if (_location.id == 3) // Lobby Chat
  137.                 {
  138.                     // We need to go somewhere besides the lobby chat so NT can type crap and think its creating a game
  139.                     Delay(100);
  140.                     //Say("/join " + joinChannelInChat);
  141.                     //Delay(1000);
  142.                 }
  143.                 //sendEventToOOG(D2NT_MGR_CREATE_GAME, _location.name, 0);
  144.                 outputGameLength();
  145.                 setNextGameMake();
  146.                 // --------------------------
  147.  
  148.                 sendEventToOOG(D2NT_MGR_READY, "", 0);
  149.             }
  150.  
  151.             locationAction(controlData.getLocation());
  152.  
  153.             Delay(500);
  154.         }
  155.     }
  156. }
  157.  
  158. function locationAction(location)
  159. {
  160.     switch (location.id)
  161.     {
  162.         case 3: // Lobby Chat
  163.  
  164.             // Not retrying anymore, clear the game name so that if user tries to do it themself, bot won't fill in with old game
  165.             if (lastGameStatus == 0 || retry == 0)
  166.             {
  167.                 // Clear these flags just in case
  168.                 retry = 0;
  169.                 game = "";
  170.             }
  171.  
  172.             // Handle non-existent or full games:
  173.             // When the join button is hit, lastGameStatus = 1.
  174.             // When in-game, lastGameStatus = 0.
  175.             // So this gets executed when NTMain() doesn't reset the flag to 0.
  176.             if (lastGameStatus == 1)
  177.             {
  178.                 if (fullretry == 0) // If we have tried [maxRetries] different games ([maxRetriesPerGame] retries for each game)
  179.                 {
  180.                     lastGameStatus = 0;
  181.                     fullretry = maxRetries;
  182.  
  183.                     // We need to close out of chat and come back
  184.                     sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game doesn't exist or its full. Rejoining chat.", 0);
  185.                     controlData.click(controlData.controls.lobby.button.quit);
  186.                 }
  187.                 else
  188.                 {
  189.                     lastGameStatus = 2; // Ready for retry
  190.  
  191.                     if (retry == 0) // If we just failed [maxRetriesPerGame] times for joining this game
  192.                     {
  193.                         Say("/join " + joinChannelInChat);
  194.                         fullretry--;  // Update flag
  195.                     }
  196.  
  197.                     sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game doesn't exist or its full. " + retry + " retries left.", 0);
  198.  
  199.                     inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  200.                     setNextGameMake();
  201.                     chatActionsDone = true; // Undo the flag set by setNextGameMake()
  202.  
  203.                     locationTimeout(gameDoesNotExistTimeout, location);
  204.                 }
  205.                 break;
  206.             }
  207.  
  208.             if (!chatActionsDone || GetTickCount() > nextGameMake + 180000) // Need to join channel or its been 3 minutes and no action, possibly kicked from channel, rejoin
  209.             {
  210.                 if (GetTickCount() > nextGameMake + 180000) // Reset this so that we don't keep joining channel over and over
  211.                     nextGameMake = GetTickCount();
  212.  
  213.                 chatActionsDone = true;
  214.                 Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  215.  
  216.                 Say("/join " + joinChannelInChat);
  217.                 Delay(1000);
  218.                 sendEventToOOG(D2NT_MGR_PRINT_LOG, "Looking for games..", 0);
  219.             }
  220.  
  221.             // Time for action?
  222.             if (GetTickCount() >= nextGameMake)
  223.             {
  224.                 sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  225.  
  226.                 // If we can retry and there is a game to retry
  227.                 if (retry > 0 && game != "" && lastGameStatus == 2)
  228.                 {
  229.                     controlData.click(controlData.controls.lobby.button.join);
  230.                     retry--;
  231.                     break;
  232.                 }
  233.  
  234.                 var chat = controlData.get(controlData.controls.lobby.chat.textBox.channelText);
  235.                 if (chat)
  236.                 {
  237.                     var linewithname = "";
  238.                     lines = chat.GetText();
  239.                     if (lines)
  240.                     {
  241.                         for (var line = 0; line < lines.length; line++)
  242.                         {
  243.                             linewithname = lines[line];
  244.  
  245.                             for (var _filterindex = 0; _filterindex < extrafilters.length; _filterindex += 2)
  246.                             {
  247.                                 // Check filters
  248.                                 if (linewithname.lastIndexOf(extrafilters[_filterindex]) != -1 && linewithname.lastIndexOf(extrafilters[_filterindex+1]) != -1)
  249.                                 {
  250.                                     for (var _gameindex = 0; _gameindex < gamenames.length; _gameindex++)
  251.                                     {
  252.                                         // Check for game name
  253.                                         var index = linewithname.lastIndexOf(gamenames[_gameindex]);
  254.                                         if (index > -1)
  255.                                         {
  256.                                             game = linewithname.substring(index, linewithname.lastIndexOf(extrafilters[_filterindex+1]));
  257.                                             gamepassword = gamepasswords[_gameindex];
  258.        
  259.                                             if (game != "" && game != samegame[_gameindex])
  260.                                             {
  261.                                                 sendEventToOOG(D2NT_MGR_PRINT_LOG, "Joining " + game + "..", 0);
  262.                                                 samegame[_gameindex] = game;
  263.  
  264.                                                 Say("/join " + getRandomString(Random(3,10)));
  265.                                                 Delay(250);
  266.                                                 sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  267.                                                 Delay(500);
  268.                                                
  269.                                                 controlData.click(controlData.controls.lobby.button.join);
  270.                                                 retry = maxRetriesPerGame;
  271.                                                 break;
  272.                                             }
  273.                                         }
  274.                                     }
  275.                                 }
  276.                             }
  277.                         }
  278.                     }
  279.                 }
  280.             }
  281.             else
  282.                 sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((nextGameMake-GetTickCount())/1000) + "s)", 0);
  283.             break;
  284.  
  285.         case 1: // Lobby
  286.  
  287.             // Enter chat
  288.             Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  289.             controlData.click(controlData.controls.lobby.button.enterChat);
  290.             break;
  291.  
  292.         case 2: // Waiting In Line
  293.             if (GetTickCount()-lastGameMade > waitInLineTimeout)
  294.                 controlData.click(controlData.controls.lobby.inLine.button.cancel);
  295.             break;
  296.  
  297.         case 4: // Create Game
  298.             break;
  299.  
  300.         case 5: // Join Game
  301.             if (game != "")
  302.             {
  303.                 sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  304.  
  305.                 controlData.setText( controlData.controls.lobby.join.editBox.gameName, game);
  306.                 Delay (200);
  307.                 controlData.setText( controlData.controls.lobby.join.editBox.password, gamepassword);
  308.                 Delay (200);
  309.                 controlData.click(controlData.controls.lobby.join.button.joinGame);
  310.             }
  311.  
  312.             lastGameMade = GetTickCount();
  313.             lastGameStatus = 1;
  314.             break;
  315.  
  316.         case 6: // Ladder
  317.             break;
  318.  
  319.         case 7: // Channel List
  320.             break;
  321.  
  322.         case 8: // Main Menu
  323.             if (controlData.getCurrentRealmIndex() == me.gatewayid)
  324.             {
  325.                 outputGameLength();
  326.                 controlData.click(controlData.gameTypes[me.playtype]);
  327.             }
  328.             else
  329.                 controlData.click(controlData.controls.mainMenu.button.gateway);
  330.             break;
  331.  
  332.         case 9: // Login
  333.             sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  334.             Delay(loginDelay);
  335.  
  336.             controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  337.  
  338.             sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  339.  
  340.             locationTimeout(5000, location);
  341.             break;
  342.  
  343.         case 10: // Login Error (this is a fatal error, so stop)
  344.             sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  345.             Delay(3500);
  346.             break;
  347.  
  348.         case 11: // Unable To Connect
  349.             timeoutDelay(unableToConnectRetry*60*1000, location)
  350.             controlData.click(controlData.controls.login.unableToConnect.button.ok);
  351.             break;
  352.  
  353.         case 12: // Character Select
  354.             var _time, _control;
  355.  
  356.             sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  357.  
  358.             for (_time = 0; _time < characterScreenTimeout; _time += 500)
  359.             {
  360.                 _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  361.                 if (_control && _control.GetText() != undefined)
  362.                     break;
  363.  
  364.                 Delay(500);
  365.             }
  366.  
  367.             if (_time < characterScreenTimeout)
  368.             {
  369.                 Delay(characterSelectDelay);
  370.  
  371.                 controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  372.                 controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  373.  
  374.                 // reset last game made, so it doesnt make a game immediately
  375.                 inGameAt = 0;
  376.                 setNextGameMake();
  377.             }
  378.             else
  379.             {
  380.                 controlData.click(controlData.controls.characterSelect.button.exit);
  381.                 timeoutDelay(realmDownRetry*60*1000, location);
  382.             }
  383.             break;
  384.  
  385.         case 13: // Realm Down - Character Select screen
  386.             controlData.click(controlData.controls.characterSelect.button.exit);
  387.             timeoutDelay(realmDownRetry*60*1000, location);
  388.             break;
  389.  
  390.         case 14: // Character Select - Disconnected
  391.             timeoutDelay(disconnectedRetry*60*1000, location);
  392.             controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  393.             break;
  394.  
  395.         case 15: // New Character
  396.             break;
  397.  
  398.         case 16: // Character Select - Please Wait popup
  399.             if (!locationTimeout(pleaseWaitTimeout, location))
  400.                 controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  401.             break;
  402.  
  403.         case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  404.             controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  405.             break;
  406.  
  407.         case 18: // D2 Splash
  408.             controlData.click(controlData.controls.d2Splash.textBox.copyright);
  409.             break;
  410.  
  411.         case 19: // Login - Cdkey In Use
  412.             timeoutDelay(cdkeyInUseRetry*60*1000, location);
  413.             controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  414.             break;
  415.  
  416.         case 20: // Single Player - Select Difficulty
  417.             controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  418.             break;
  419.  
  420.         case 21: // Main Menu - Connecting
  421.             if (!locationTimeout(connectingToBnetTimeout, location))
  422.                 controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  423.             break;
  424.  
  425.         case 22: // Login - Invalid Cdkey (classic or xpac)
  426.             sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  427.             Delay(3500);
  428.             break;
  429.  
  430.         case 23: // Character Select - Connecting
  431.             if (!locationTimeout(characterScreenTimeout, location))
  432.                 controlData.click(controlData.controls.characterSelect.button.exit);
  433.             break;
  434.  
  435.         case 24: // Server Down - not much to do but wait..
  436.             break;
  437.  
  438.         case 25: // Lobby - Please Wait
  439.             if (!locationTimeout(pleaseWaitTimeout, location))
  440.                 controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  441.             break;
  442.  
  443.         case 26: // Lobby - Game Name Exists
  444.             sendEventToOOG(D2NT_MGR_PRINT_LOG, "ÿE00000Game already exists.", 0);
  445.  
  446.             inGameAt = 0;
  447.             setNextGameMake();
  448.  
  449.             locationTimeout(15000, location);
  450.             break;
  451.  
  452.         case 27: // Gateway Select
  453.             controlData.clickRealmEntry(me.gatewayid);
  454.             controlData.click(controlData.controls.gateway.button.ok);
  455.             break;
  456.  
  457.         case 28: // Lobby - Game Does Not Exist
  458.             // This is handled in the lobby chat
  459.  
  460.             // Get rid of the message (DNE/Full game) so the lobby chat can handle
  461.             controlData.click(controlData.controls.lobby.button.create);
  462.             Delay(200);
  463.             controlData.click(controlData.controls.lobby.create.button.cancel);
  464.             break;
  465.  
  466.         default:
  467.             break;
  468.     }
  469. }
  470.  
  471. function sendEventToOOG(locationId, statusString, pendingTime)
  472. {
  473.     return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  474. }
  475.  
  476. function setNextGameMake()
  477. {
  478.     lastGameMade = GetTickCount();
  479.     nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  480.     inGameAt = 0;
  481.     chatActionsDone = false;
  482. }
  483.  
  484. function outputGameLength()
  485. {
  486.     if (inGameAt)
  487.     {
  488.         duration = GetTickCount() - inGameAt;
  489.  
  490.         inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  491.     }
  492. }
  493.  
  494. function locationTimeout(time, location)
  495. {
  496.     endtime = GetTickCount() + time;
  497.  
  498.     while (controlData.getLocation().id == location.id && endtime > GetTickCount())
  499.     {
  500.         sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  501.         Delay(500);
  502.     }
  503.  
  504.     return (controlData.getLocation().id != location.id);
  505. }
  506.  
  507. function timeoutDelay(time, location)
  508. {
  509.     endtime = GetTickCount() + time;
  510.  
  511.     while (endtime > GetTickCount())
  512.     {
  513.         sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  514.         Delay(1000);
  515.     }
  516. }
  517.  
  518. function getRandomString(_length)
  519. {
  520.     _retString = "";
  521.     _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  522.  
  523.     while (_length--)
  524.     {
  525.         _retString += _charSet.charAt(Random(0, _charSet.length-1));
  526.         Delay(1);
  527.     }
  528.  
  529.     return _retString;
  530. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement