Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.66 KB | None | 0 0
  1. var usestaticpw = true; //true = same pw for them all false = use pw list (must containe same # of pws as games in game file)
  2. var staticpassword = "test"; // the pw to use if your using static pws
  3. var loging = true; //set to true to log games joined
  4.  
  5. var gameMinLength = 180000; // no cd key switching leave at 180000 or rd
  6.  
  7. var unableToConnectRetry = 15; // time in minutes to retry connecting on connection fail (real value is +/- 1 min)
  8. var realmDownRetry = 30; // time in minutes to retry connecting on a realm down (default is 300 minutes)
  9. var disconnectedRetry = 5; // time in minutes to retry on a disconnection (usually ip ban related)
  10. var cdkeyInUseRetry = 2; // time in minutes to retry on a cdkey in use error message (set to 0 to stop)
  11. var connectingToBnetTimeout = 20000; // time in milliseconds to wait for a login to time out and click cancel and retry
  12. var characterScreenTimeout = 10000; // time in milliseconds to wait for character screen to appear
  13. var pleaseWaitTimeout = 10000; // time in milliseconds to wait for a please wait popup
  14. var createGameThreshold = 10000; // time in milliseconds to wait between making games
  15. var createGameThresholdRandom = 2500; // time in milliseconds to randomly add +/- to the game create time
  16. var createGameTimeout = 15000; // time in milliseconds to register a failed to create game
  17. var waitInLineTimeout = 60000; // time in milliseconds to wait in lines for a create game (60 second default)
  18. var characterSelectDelay = 1000; // time in milliseconds to wait before selecting a character on the char screen
  19. var loginDelay = 1000; // time in milliseconds to wait before submitting login information
  20. var clickDelay = 500; // wait X milliseconds before next action after a click event
  21. var textDelay = 500; // wait X milliseconds before next action after inserting text into a textbox
  22. var clickDelayRandom = 500; // random amount of time to add to a click
  23. var textDelayRandom = 500; // random amount of time to add to a text set
  24. var gameDoesNotExistDelayMin = 30000; // how long to wait when a Game Does Not Exist occurs - minimum - default 10 minutes
  25. var gameDoesNotExistDelayMax = 45000; // how long to wait when a Game Does Not Exist occurs - maximum - default 15 minutes
  26. var gameDoesNotExistTimeout = 30000; // how long to wait for the dialog to disappear (default 30 seconds, don't change this)
  27. var joinChatAfterGame = false; // join chat after leaving a game
  28. var joinRandomChannel = true; // if this is true, will join a random channel, otherwise it will use the channel below..
  29. var joinChannelInChat = ""; // leave blank to not join a private channel
  30. var waitBeforeEnterChatMin = 1000; // min how long to wait before entering chat
  31. var waitBeforeEnterChatMax = 2000; // max how long to wait before entering chat
  32. var waitInChatBeforeActionsMin = 2000; // min how long to wait before joining channel
  33. var waitInChatBeforeActionsMax = 3000; // max how long to wait before joining channel
  34.  
  35. // DONT EDIT ANYTHING BELOW THIS
  36.  
  37. // D2NT Manager Command
  38. const D2NT_MGR_LOADING = 1;
  39. const D2NT_MGR_READY = 2;
  40. const D2NT_MGR_LOGIN = 3;
  41. const D2NT_MGR_CREATE_GAME = 4;
  42. const D2NT_MGR_INGAME = 5;
  43. const D2NT_MGR_RESTART = 6;
  44. const D2NT_MGR_CHICKEN = 7;
  45. const D2NT_MGR_PRINT_STATUS = 8;
  46. const D2NT_MGR_PRINT_LOG = 9;
  47.  
  48. var lastGameMade = GetTickCount();
  49. var lastGameStatus = 0;
  50. var nextGameMake = 0;
  51. var inGameAt = 0;
  52. var chatActionsDone = false;
  53. var lastGameFailed = false;
  54.  
  55. Include("libs/controlInfo.ntl");
  56.  
  57. var controlData = new controlInfo();
  58.  
  59. function NTMain()
  60. {
  61. Delay(1000);
  62.  
  63. var _ingame = false;
  64.  
  65. controlData.clickDelay = clickDelay;
  66. controlData.textDelay = textDelay;
  67. controlData.clickDelayRandom = clickDelayRandom;
  68. controlData.textDelayRandom = textDelayRandom;
  69.  
  70. while(1)
  71. {
  72. if(me.ingame)
  73. {
  74. if(!inGameAt)
  75. inGameAt = GetTickCount();
  76.  
  77. if(!_ingame)
  78. {
  79. RunGC(); // run garbage collector between each game
  80.  
  81. if(Load("NTBot/NTBotGame.ntj"))
  82. {
  83. _ingame = true;
  84.  
  85. if(me.playtype > 0)
  86. sendEventToOOG(D2NT_MGR_INGAME, "In Game[" + me.gamename + "]", 0);
  87. else
  88. sendEventToOOG(D2NT_MGR_INGAME, "In Game", 0);
  89.  
  90. lastGameStatus = 2; // in game successful
  91. }
  92. }
  93.  
  94. Delay(1000);
  95. }
  96. else
  97. {
  98. if(_ingame)
  99. {
  100. _ingame = false;
  101.  
  102. sendEventToOOG(D2NT_MGR_READY, "", 0);
  103. }
  104.  
  105. locationAction(controlData.getLocation());
  106.  
  107. Delay(500);
  108. }
  109. }
  110. }
  111.  
  112. function locationAction(location)
  113. {
  114.  
  115. switch(location.id)
  116. {
  117. case 3: // Lobby Chat
  118. if(!chatActionsDone)
  119. {
  120. chatActionsDone = true;
  121. Delay(Random(waitInChatBeforeActionsMin, waitInChatBeforeActionsMax));
  122.  
  123. if(joinRandomChannel || joinChannelInChat != "")
  124. {
  125. Say("/join " + (joinRandomChannel ? getRandomString(Random(3,10)) : joinChannelInChat));
  126. Delay(1000);
  127. }
  128. }
  129. case 1: // Lobby
  130.  
  131. if(location.id == 1 && joinChatAfterGame)
  132. {
  133. Delay(Random(waitBeforeEnterChatMin, waitBeforeEnterChatMax));
  134. controlData.click(controlData.controls.lobby.button.enterChat);
  135. break;
  136. }
  137.  
  138. if(GetTickCount() > nextGameMake)
  139. {
  140. var _control;
  141.  
  142. lastGameFailed = false;
  143.  
  144. switch(lastGameStatus)
  145. {
  146. case 0:
  147. _control = controlData.get(controlData.controls.lobby.button.join);
  148. if(_control && _control.pressed)
  149. {
  150. controlData.click(controlData.controls.lobby.button.create);
  151. Delay(500);
  152. }
  153. Delay(200);
  154. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  155. Delay(1000);
  156. controlData.click(controlData.controls.lobby.button.join);
  157. Delay(2000);
  158. nextGameMake = GetTickCount() + createGameTimeout; // set our timeout
  159. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  160. break;
  161. case 1: // game failed, rollover to reset timer
  162. inGameAt = GetTickCount(); // reset inGameAt, to wait how long we should have waited..
  163. lastGameFailed = true;
  164. case 2:
  165. outputGameLength();
  166. lastGameStatus = 0;
  167. setNextGameMake();
  168. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  169. break;
  170. }
  171. }
  172. else
  173. timeoutDelay(nextGameMake-GetTickCount(), location);
  174. break;
  175.  
  176. case 2: // Waiting In Line
  177. if(GetTickCount()-lastGameMade > waitInLineTimeout)
  178. controlData.click(controlData.controls.lobby.inLine.button.cancel);
  179. break;
  180.  
  181. case 4: // Create Game
  182. sendEventToOOG(D2NT_MGR_CREATE_GAME, location.name, 0);
  183.  
  184. locationTimeout(5000, location);
  185.  
  186. lastGameMade = GetTickCount();
  187. lastGameStatus = 1; // pending creation
  188. break;
  189.  
  190. case 5: // Join Game
  191. var gamelist = FileOpen("gamelist.txt", 0); //Opens the file in read only mode.
  192. var games = [];
  193. var arrayIndex = 0;
  194. if(!usestaticpw){
  195. var gamepw = FileOpen("gamepw.txt", 0);
  196. var pws = [];
  197. }
  198. if(loging){
  199. var logs;
  200. var logfile = FileOpen("logs/CompletedGames.txt", 0);
  201. }
  202. if(!gamelist) {
  203. DebugInOOG("no gamelist");//Failed to open file, likely doesnt exist. Insert error crap...Should probably retry incase file is being accessed by another hunter.. but that would be rare
  204. break;
  205. }
  206. if(!usestaticpw){
  207. if(!gamepw) {
  208. DebugInOOG("no game pw list");//Failed to open file, likely doesnt exist. Insert error crap...Should probably retry incase file is being accessed by another hunter.. but that would be rare
  209. break;
  210. }
  211. }
  212. if(loging)
  213. if(!logfile)
  214. DebugInOOG("no log file");//Failed to open file, likely doesnt exist. Insert error crap...Should probably retry incase file is being accessed by another hunter.. but that would be rare
  215. break;
  216. }
  217. }
  218. while(!gamelist.eof){
  219. var gl = gamelist.ReadLine();
  220. if (gl.length > 0) {
  221. games[arrayIndex] = gl;
  222. if(!usestaticpw)
  223. pws[arrayIndex] = gamepw.ReadLine();
  224.  
  225. arrayIndex++;
  226. }
  227. }
  228. gamelist.Close(); //MUST close filehandler as long as it doesn't return null to prevent memory leak!
  229. if(!usestaticpw)
  230. gamepw.Close();
  231. if(loging)
  232. logfile.Close();
  233. if(arrayIndex == 0)
  234. break; // If there were no games found, break.
  235. Delay(100)
  236.  
  237. if(arrayIndex > 0){
  238.  
  239. gamelist = FileOpen("gamelist.txt", 1); //Opens file in Overwrite? mode. Should probably catch null and retry incase file is being accessed by another hunter.. but that would be rare
  240. if(!usestaticpw)
  241. gamepw = FileOpen("gamepw.txt", 1);
  242.  
  243. if (games.length > 1){
  244. for (arrayIndex = 1;arrayIndex < games.length; arrayIndex++){
  245. gamelist.WriteLine(games[arrayIndex]);
  246. if(!usestaticpw)
  247. gamepw.WriteLine(pws[arrayIndex]);
  248. }
  249. }
  250. Delay(100)
  251. gamelist.Close(); //Once again closing the file handler so the programing gods don't smite me
  252. if(!usestaticpw)
  253. gamepw.Close();
  254. }
  255.  
  256. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  257.  
  258. controlData.setText( controlData.controls.lobby.join.editBox.gameName, games[0]); //It will always be the 0th index because we re-write the array
  259. Delay (1250);
  260. if(usestaticpw){
  261. controlData.setText( controlData.controls.lobby.join.editBox.password, staticpassword);
  262. }else{
  263. controlData.setText( controlData.controls.lobby.join.editBox.password, pws[0]);
  264. }
  265. Delay (1250);
  266. controlData.click(controlData.controls.lobby.join.button.joinGame);
  267. if(loging){
  268. logs = FileOpen("logs/CompletedGames.txt", 2);
  269. logs.WriteLine(games[0]);
  270. logs.Close();
  271. }
  272. lastGameStatus = 1;
  273.  
  274. break;
  275.  
  276. case 6: // Ladder
  277. break;
  278.  
  279. case 7: // Channel List
  280. break;
  281.  
  282. case 8: // Main Menu
  283. if(controlData.getCurrentRealmIndex() == me.gatewayid)
  284. {
  285. outputGameLength();
  286. controlData.click(controlData.gameTypes[me.playtype]);
  287. }
  288. else
  289. controlData.click(controlData.controls.mainMenu.button.gateway);
  290. break;
  291.  
  292. case 9: // Login
  293. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  294. Delay(loginDelay);
  295.  
  296. controlData.setText(controlData.controls.login.editBox.accountName, me.account);
  297.  
  298. sendEventToOOG(D2NT_MGR_LOGIN, location.name, 0);
  299.  
  300. locationTimeout(5000, location);
  301. break;
  302.  
  303. case 10: // Login Error (this is a fatal error, so stop)
  304. sendEventToOOG(D2NT_MGR_RESTART, location.name, 10);
  305. Delay(3500);
  306. break;
  307.  
  308. case 11: // Unable To Connect
  309. timeoutDelay(unableToConnectRetry*60*1000, location)
  310. controlData.click(controlData.controls.login.unableToConnect.button.ok);
  311. break;
  312.  
  313. case 12: // Character Select
  314. var _time, _control;
  315.  
  316. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name, 0);
  317.  
  318. for(_time = 0 ; _time < characterScreenTimeout ; _time += 500)
  319. {
  320. _control = controlData.get(controlData.controls.characterSelect.textBox.characterInfo[me.charloc]);
  321. if(_control && _control.GetText() != undefined)
  322. break;
  323.  
  324. Delay(500);
  325. }
  326.  
  327. if(_time < characterScreenTimeout)
  328. {
  329. Delay(characterSelectDelay);
  330.  
  331. controlData.click(controlData.controls.characterSelect.textBox.characters[me.charloc], 0, 0, 1);
  332. controlData.click(controlData.controls.characterSelect.textBox.characterInfo[me.charloc], 0, 0, 1);
  333.  
  334. // reset last game made, so it doesnt make a game immediately
  335. inGameAt = 0;
  336. setNextGameMake();
  337. }
  338. else
  339. {
  340. controlData.click(controlData.controls.characterSelect.button.exit);
  341. timeoutDelay(realmDownRetry*60*1000, location);
  342. }
  343. break;
  344.  
  345. case 13: // Realm Down - Character Select screen
  346. controlData.click(controlData.controls.characterSelect.button.exit);
  347. timeoutDelay(realmDownRetry*60*1000, location);
  348. break;
  349.  
  350. case 14: // Character Select - Disconnected
  351. timeoutDelay(disconnectedRetry*60*1000, location);
  352. controlData.click(controlData.controls.characterSelect.disconnected.button.ok);
  353. break;
  354.  
  355. case 15: // New Character
  356. break;
  357.  
  358. case 16: // Character Select - Please Wait popup
  359. if(!locationTimeout(pleaseWaitTimeout, location))
  360. controlData.click(controlData.controls.characterSelect.pleaseWait.button.cancel);
  361. break;
  362.  
  363. case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
  364. controlData.click(controlData.controls.lobby.lostConnection.button.ok);
  365. break;
  366.  
  367. case 18: // D2 Splash
  368. controlData.click(controlData.controls.d2Splash.textBox.copyright);
  369. break;
  370.  
  371. case 19: // Login - Cdkey In Use
  372. timeoutDelay(cdkeyInUseRetry*60*1000, location);
  373. controlData.click(controlData.controls.login.cdkeyInUse.button.ok);
  374. break;
  375.  
  376. case 20: // Single Player - Select Difficulty
  377. controlData.click(controlData.singlePlayerDifficulties[me.diff]);
  378. break;
  379.  
  380. case 21: // Main Menu - Connecting
  381. if(!locationTimeout(connectingToBnetTimeout, location))
  382. controlData.click(controlData.controls.mainMenu.connecting.button.cancel);
  383. break;
  384.  
  385. case 22: // Login - Invalid Cdkey (classic or xpac)
  386. sendEventToOOG(D2NT_MGR_RESTART, location.name, 3600);
  387. Delay(3500);
  388. break;
  389.  
  390. case 23: // Character Select - Connecting
  391. if(!locationTimeout(characterScreenTimeout, location))
  392. controlData.click(controlData.controls.characterSelect.button.exit);
  393. break;
  394.  
  395. case 24: // Server Down - not much to do but wait..
  396. break;
  397.  
  398. case 25: // Lobby - Please Wait
  399. if(!locationTimeout(pleaseWaitTimeout, location))
  400. controlData.click(controlData.controls.lobby.pleaseWait.button.cancel);
  401. break;
  402.  
  403. case 26: // Lobby - Game Name Exists
  404. sendEventToOOG(D2NT_MGR_PRINT_LOG, "ΓΏE00000Game already exists", 0);
  405.  
  406. inGameAt = 0;
  407. lastGameStatus = 0;
  408. setNextGameMake();
  409.  
  410. locationTimeout(15000, location);
  411. break;
  412.  
  413. case 27: // Gateway Select
  414. controlData.clickRealmEntry(me.gatewayid);
  415. controlData.click(controlData.controls.gateway.button.ok);
  416. break;
  417.  
  418. case 28: // Lobby - Game Does Not Exist
  419. inGameAt = Random(gameDoesNotExistDelayMin, gameDoesNotExistDelayMax);
  420. lastGameStatus = 0;
  421. setNextGameMake();
  422.  
  423. locationTimeout(gameDoesNotExistTimeout, location);
  424. break;
  425. }
  426. }
  427.  
  428. function sendEventToOOG(locationId, statusString, pendingTime)
  429. {
  430. return SendCopyData("D2NT Manager", null, (locationId<<16)|pendingTime, statusString);
  431. }
  432.  
  433. function setNextGameMake()
  434. {
  435. lastGameMade = GetTickCount();
  436. nextGameMake = lastGameMade + createGameThreshold + Random(0-createGameThresholdRandom, createGameThresholdRandom) + inGameAt;
  437. inGameAt = 0;
  438. chatActionsDone = false;
  439. }
  440.  
  441. function outputGameLength()
  442. {
  443. if(inGameAt)
  444. {
  445. duration = GetTickCount() - inGameAt;
  446.  
  447. inGameAt = (duration < gameMinLength ? gameMinLength - duration : 0);
  448. }
  449. }
  450.  
  451. function locationTimeout(time, location)
  452. {
  453. endtime = GetTickCount() + time;
  454.  
  455. while(controlData.getLocation().id == location.id && endtime > GetTickCount())
  456. {
  457. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  458. Delay(500);
  459. }
  460.  
  461. return (controlData.getLocation().id != location.id);
  462. }
  463.  
  464. function timeoutDelay(time, location)
  465. {
  466. endtime = GetTickCount() + time;
  467.  
  468. while(endtime > GetTickCount())
  469. {
  470. sendEventToOOG(D2NT_MGR_PRINT_STATUS, location.name + " (" + parseInt((endtime-GetTickCount())/1000) + "s)", 0);
  471. Delay(1000);
  472. }
  473. }
  474.  
  475. function getRandomString(_length)
  476. {
  477. _retString = "";
  478. _charSet = "0123456789abcdefghijklmnopqrstuvwxyz";
  479.  
  480. while(_length--)
  481. {
  482. _retString += _charSet.charAt(Random(0, _charSet.length-1));
  483. Delay(1);
  484. }
  485.  
  486. return _retString;
  487. }
  488. function DebugInOOG(logString)
  489. {
  490. return SendCopyData("D2NT Manager", null, 9<<16, "-- Debug : " + logString);
  491. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement