This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathD2BotSoloPlay.dbj
1319 lines (1078 loc) · 35.4 KB
/
D2BotSoloPlay.dbj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
let StarterConfig = {
MinGameTime: 300, // Minimum game length in seconds. If a game is ended too soon, the rest of the time is waited in the lobby
PingQuitDelay: 30, // Time in seconds to wait in lobby after quitting due to high ping
CreateGameDelay: 10, // Seconds to wait before creating a new game
ResetCount: 99, // Reset game count back to 1 every X games.
CharacterDifference: 99, // Character level difference. Set to false to disable character difference.
ChatActionsDelay: 2, // Seconds to wait in lobby before entering a channel
// ChannelConfig can override these options for individual profiles.
JoinChannel: "", // Default channel. Can be an array of channels - ["channel 1", "channel 2"]
FirstJoinMessage: "", // Default join message. Can be an array of messages
AnnounceGames: false, // Default value
AfterGameMessage: "", // Default message after a finished game. Can be an array of messages
SwitchKeyDelay: 300, // Seconds to wait before switching a used/banned key or after realm down
CrashDelay: 10, // Seconds to wait after a d2 window crash
FTJDelay: 300, // Seconds to wait after failing to create a game
RealmDownDelay: 10, // Minutes to wait after getting Realm Down message
InvalidPasswordDelay: 10, // Minutes to wait after getting Invalid Password message
UnableToConnectDelay: 5, // Minutes to wait after Unable To Connect message
TCPIPNoHostDelay: 5, // Seconds to wait after Cannot Connect To Server message
CDKeyInUseDelay: 5, // Minutes to wait before connecting again if CD-Key is in use.
ConnectingTimeout: 20, // Seconds to wait before cancelling the 'Connecting...' screen
PleaseWaitTimeout: 100, // Seconds to wait before cancelling the 'Please Wait...' screen
WaitInLineTimeout: 12000, // Seconds to wait before cancelling the 'Waiting in Line...' screen
GameDoesNotExistTimeout: 600, // Seconds to wait before cancelling the 'Game does not exist.' screen
DelayBeforeLogin: rand(5, 25), // Seconds to wait before logging in
VersionErrorDelay: rand(5, 30), // Seconds to wait after 'unable to identify version' message
GlobalAccountPassword: "" // Set value for a global password for account generation
};
let ChannelConfig = {
/* Override default values for JoinChannel, FirstJoinMessage, AnnounceGames and AfterGameMessage per profile
It's possible to override any number of these options (you don't have to put all of them)
**** DO NOT EDIT ANYTHING INSIDE THIS COMMENT BLOCK ***
Format:
"Profile Name": {
JoinChannel: "channel name", -OR- ["channel 1", "channel 2"],
FirstJoinMessage: "first message", -OR- ["join msg 1", "join msg 2"],
AnnounceGames: true,
AfterGameMessage: "message after a finished run" -OR- ["msg 1", msg 2"]
}
*/
// Add your lines under here
};
// No touchy!
include('polyfill.js');
include("json2.js");
include("OOG.js");
include("automule.js");
include("gambling.js");
include("craftingsystem.js");
include("torchsystem.js");
include("common/misc.js");
include("common/util.js");
include("common/pather.js");
include("SoloPlay/Tools/Developer.js");
include("SoloPlay/Tools/CharData.js");
include("SoloPlay/Tools/Tracker.js");
include("SoloPlay/Tools/NameGen.js");
include("SoloPlay/Tools/OOGOverrides.js");
include("SoloPlay/Functions/SoloEvents.js");
include("SoloPlay/Functions/ConfigOverrides.js");
let firstRun = false;
if (!FileTools.exists("data/" + me.profile + ".json")) {
DataFile.create();
firstRun = true;
delay(Math.floor(rand(1, 20)));
}
if (!FileTools.exists(CharData.filePath)) {
CharData.create();
delay(Math.floor(rand(1, 20)));
}
if (Developer.logPerformance) {
Tracker.initialize();
}
let gameInfo, joinInfo, gameStart, ingame, chatActionsDone, pingQuit, myExp, myGold, resPenalty, frRes, crRes, lrRes, prRes, areaName, diffName,
handle, useChat, firstLogin, connectFail, setUp, deadCheck, connectFailRetry,
battlenet = Profile().type === 2 ? true : false,
gameCount = DataFile.getStats().runs + 1,
lastGameStatus = "ready",
isUp = "no",
chanInfo = {
joinChannel: "",
firstMsg: "",
afterMsg: "",
announce: false
};
function sayMsg (string) {
if (!useChat) {
return;
}
say(string);
}
function ReceiveCopyData (mode, msg) {
var buildCheck, obj;
switch (msg) {
case "Handle":
handle = mode;
break;
}
switch (mode) {
case 1: // Join Info
print("Got Join Info");
joinInfo = JSON.parse(msg);
SoloEvents.gameInfo.gameName = joinInfo.gameName.toLowerCase();
SoloEvents.gameInfo.gamePass = joinInfo.gamePass.toLowerCase();
break;
case 2: // Game info
print("Received Game Info");
gameInfo = JSON.parse(msg);
break;
case 3: // Game request
// Don't let others join mule/torch/key/gold drop game
if (AutoMule.inGame || Gambling.inGame || TorchSystem.inGame || CraftingSystem.inGame) {
break;
}
if (gameInfo) {
obj = JSON.parse(msg);
if (me.gameReady) {
D2Bot.joinMe(obj.profile, me.gamename.toLowerCase(), "", me.gamepassword.toLowerCase(), isUp);
} else {
D2Bot.joinMe(obj.profile, gameInfo.gameName.toLowerCase(), gameCount, gameInfo.gamePass.toLowerCase(), isUp);
}
}
break;
case 4: // Heartbeat ping
if (msg === "pingreq") {
sendCopyData(null, me.windowtitle, 4, "pingrep");
}
break;
case 0xf124: // Cached info retrieval
if (msg !== "null") {
gameInfo.crashInfo = JSON.parse(msg);
}
break;
case 1638:
obj = JSON.parse(msg);
setUp = {};
setUp.profile = me.profile.toUpperCase();
setUp.account = obj.Account;
setUp.password = "";
setUp.charName = obj.Character;
setUp.tag = obj.Tag;
setUp.difficulty = obj.Difficulty;
switch (obj.Realm.toLowerCase()) {
case "east":
setUp.realm = "useast";
break;
case "west":
setUp.realm = "uswest";
break;
case "asia":
setUp.realm = "asia";
break;
case "europe":
setUp.realm = "europe";
break;
}
buildCheck = setUp.profile.split("-"); // SCL-ZON123
setUp.hardcore = buildCheck[0].indexOf("HC") !== -1; // SC softcore = false
setUp.expansion = buildCheck[0].indexOf("CC") === -1; // not CC so not classic - true
setUp.ladder = buildCheck[0].indexOf("NL") === -1; // not NL so its ladder - true
if (buildCheck[1] === undefined || !buildCheck[1]) {
D2Bot.printToConsole('Please update profile name. Example: "HCCNL-PAL" will make a Hardcore Classic NonLadder Paladin', 6);
D2Bot.printToConsole("If you are still confused please read the included readMe. https://github.com/theBGuy/Kolbot-SoloPlay/blob/main/README.md", 6);
D2Bot.stop();
}
buildCheck[1] = buildCheck[1].toString().substring(0, 3); // removes numbers ZON for switch
switch (buildCheck[1]) {
case "ZON":
setUp.charClass = "amazon";
break;
case "SOR":
setUp.charClass = "sorceress";
break;
case "NEC":
setUp.charClass = "necromancer";
break;
case "PAL":
setUp.charClass = "paladin";
break;
case "BAR":
setUp.charClass = "barbarian";
break;
case "DRU":
setUp.charClass = "druid";
break;
case "SIN":
setUp.charClass = "assassin";
break;
default:
D2Bot.updateStatus('Please update profile name. Example: "HCCNL-PAL" will make a Hardcore Classic NonLadder Paladin');
D2Bot.printToConsole('Please update profile name. Example: "HCCNL-PAL" will make a Hardcore Classic NonLadder Paladin', 6);
D2Bot.stop();
break;
}
if (setUp.tag !== "") {
setUp.tag = setUp.tag[0].toUpperCase() + setUp.tag.substring(1).toLowerCase();
let soloStats = CharData.getStats();
if (!soloStats.me.finalBuild || soloStats.me.finalBuild !== setUp.tag) {
D2Bot.setProfile(null, null, null, null, null, setUp.tag);
CharData.updateData("me", "finalBuild", setUp.tag);
soloStats.me.finalBuild = setUp.tag;
}
if (!["Start", "Stepping", "Leveling"].includes(soloStats.me.currentBuild) && soloStats.me.currentBuild !== soloStats.me.finalBuild) {
CharData.updateData("me", "currentBuild", "Leveling");
soloStats.me.currentBuild = "Leveling";
}
} else {
D2Bot.updateStatus('Please update profile InfoTag. Missing the finalBuild.');
D2Bot.printToConsole('Please update profile InfoTag. Missing the finalBuild.', 6);
D2Bot.stop();
break;
}
break;
}
}
function deleteAndRemakeChar (info) {
me.blockMouse = true;
var control, text;
ControlAction.findCharacter(info); //Scroll down until the specific control is visible
MainLoop:
// Cycle until in lobby
while (getLocation() !== 1) {
switch (getLocation()) {
case 12: // character select
control = getControl(4, 37, 178, 200, 92);
if (control) {
do {
text = control.getText();
if (text instanceof Array && typeof text[1] === "string" && text[1].toLowerCase() === info.charName.toLowerCase()) {
control.click();
ControlAction.click(6, 433, 528, 168, 60); // click delete
delay(500);
ControlAction.click(6, 421, 337, 96, 32); // confirm delete
break MainLoop;
}
} while (control.getNext());
}
break;
case 42: // empty character select
break MainLoop;
break;
case 14: // disconnected?
case 30: // player not found?
me.blockMouse = false;
return false;
default:
break;
}
delay(100);
}
me.blockMouse = false;
// Delete old files - leaving csv file's for now as I don't think they interfere with the overlay
CharData.delete(true);
DataFile.create();
CharData.updateData("me", "finalBuild", setUp.tag);
Developer.logPerformance && Tracker.initialize();
D2Bot.printToConsole("Deleted: " + info.charName + ". Now remaking...", 6);
ControlAction.makeCharacter(setUp);
return true;
}
function saveInfo (info) {
// Data-file already exists
if (FileTools.exists("logs/Kolbot-SoloPlay/" + info.realm + "/" + info.charClass + "-" + info.charClass + "-" + info.charName + ".json")) {
return;
}
let folder, string;
if (!FileTools.exists("logs/Kolbot-SoloPlay")) {
folder = dopen("logs");
folder.create("Kolbot-SoloPlay");
}
if (!FileTools.exists("logs/Kolbot-SoloPlay/" + info.realm)) {
folder = dopen("logs/Kolbot-SoloPlay");
folder.create(info.realm);
}
if (!FileTools.exists("logs/Kolbot-SoloPlay/" + info.realm + "/" + info.charClass + "-" + info.charName + ".json")) {
string = JSON.stringify(info);
FileTools.writeText("logs/Kolbot-SoloPlay/" + info.realm + "/" + info.charClass + "-" + info.charName + ".json", string);
}
}
function setNextGame () {
var nextGame = gameInfo.gameName;
if (StarterConfig.ResetCount && gameCount + 1 >= StarterConfig.ResetCount) {
nextGame += 1;
} else {
nextGame += (gameCount + 1);
}
DataFile.updateStats("nextGame", nextGame);
}
function locationTimeout (time, location) {
var endtime = getTickCount() + time;
while (getLocation() === location && endtime > getTickCount()) {
delay(500);
}
return (getLocation() !== location);
}
function updateCount () {
D2Bot.updateCount();
delay(1000);
ControlAction.click(6, 264, 366, 272, 35);
try {
login(me.profile);
} catch (e) {
//
}
delay(1000);
ControlAction.click(6, 33, 572, 128, 35);
}
function ScriptMsgEvent (msg) {
switch (msg) {
case "mule":
AutoMule.check = true;
break;
case "muleTorch":
AutoMule.torchAnniCheck = 1;
break;
case "muleAnni":
AutoMule.torchAnniCheck = 2;
break;
case "torch":
TorchSystem.check = true;
break;
case "crafting":
CraftingSystem.check = true;
break;
case "getMuleMode":
if (AutoMule.torchAnniCheck === 2) {
scriptBroadcast("2");
} else if (AutoMule.torchAnniCheck === 1) {
scriptBroadcast("1");
} else if (AutoMule.check) {
scriptBroadcast("0");
}
break;
case "pingquit":
pingQuit = true;
break;
case "event":
SoloEvents.check = true;
break;
}
}
function timer (tick) {
return " (" + new Date(getTickCount() - tick).toISOString().slice(11, -5) + ")";
}
function randomString (len, useNumbers = false) {
var i, rval = "",
letters = useNumbers ? "abcdefghijklmnopqrstuvwxyz0123456789" : "abcdefghijklmnopqrstuvwxyz";
len = len ? len : rand(5, 14);
for (i = 0; i < len; i += 1) {
rval += letters[rand(0, letters.length - 1)];
}
return rval;
}
function locationAction (location) {
var i, control, string, text;
MainSwitch:
switch (location) {
case 0:
ControlAction.click();
break;
case 1: // Lobby
D2Bot.updateStatus("Lobby");
saveInfo(setUp);
me.blockKeys = false;
if (!firstLogin) {
firstLogin = true;
}
if (lastGameStatus === "pending") {
gameCount += 1;
}
if (StarterConfig.PingQuitDelay && pingQuit) {
ControlAction.timeoutDelay("Ping Delay", StarterConfig.PingQuitDelay * 1e3);
pingQuit = false;
}
if (StarterConfig.JoinChannel !== "" || (ChannelConfig[me.profile] && ChannelConfig[me.profile].JoinChannel !== "")) {
ControlAction.click(6, 27, 480, 120, 20);
break;
}
if (ingame || gameInfo.error) {
if (!gameStart) {
gameStart = DataFile.getStats().ingameTick;
}
if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3 && !joinInfo) {
ControlAction.timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
}
}
if (ingame) {
if (AutoMule.outOfGameCheck() || TorchSystem.outOfGameCheck() || Gambling.outOfGameCheck() || CraftingSystem.outOfGameCheck() || SoloEvents.outOfGameCheck()) {
break;
}
D2Bot.updateRuns();
gameCount += 1;
lastGameStatus = "ready";
ingame = false;
if (StarterConfig.ResetCount && gameCount > StarterConfig.ResetCount) {
gameCount = 1;
DataFile.updateStats("runs", gameCount);
}
}
// Create
if (!ControlAction.click(6, 533, 469, 120, 20)) {
break;
}
deadCheck = setUp.hardcore === true && (getControl(6, 533, 469, 120, 20) && getControl(6, 533, 469, 120, 20).disabled === 4);
if (deadCheck) {
D2Bot.updateStatus("Character died");
D2Bot.PrintToConsole("Character died.", 6);
delay(5000);
ControlAction.click(6, 693, 490, 80, 20);
break;
}
// In case create button gets bugged
if (!locationTimeout(5000, location)) {
// Join
if (!ControlAction.click(6, 652, 469, 120, 20)) {
break;
}
// Create
if (!ControlAction.click(6, 533, 469, 120, 20)) {
break;
}
}
break;
case 2: // Waiting In Line
D2Bot.updateStatus("Waiting...");
locationTimeout(StarterConfig.WaitInLineTimeout * 1e3, location);
ControlAction.click(6, 433, 433, 96, 32);
break;
case 3: // Lobby Chat
D2Bot.updateStatus("Lobby Chat");
if (lastGameStatus === "pending") {
gameCount += 1;
}
if (ingame || gameInfo.error) {
if (!gameStart) {
gameStart = DataFile.getStats().ingameTick;
}
if (getTickCount() - gameStart < StarterConfig.MinGameTime * 1e3) {
ControlAction.timeoutDelay("Min game time wait", StarterConfig.MinGameTime * 1e3 + gameStart - getTickCount());
}
}
if (ingame) {
//D2Bot.store(JSON.stringify({currScript: "none", area: "out of game"}));
if (AutoMule.outOfGameCheck() || TorchSystem.outOfGameCheck() || Gambling.outOfGameCheck() || CraftingSystem.outOfGameCheck() || SoloEvents.outOfGameCheck()) {
break;
}
print("updating runs");
D2Bot.updateRuns();
gameCount += 1;
lastGameStatus = "ready";
ingame = false;
if (StarterConfig.ResetCount && gameCount > StarterConfig.ResetCount) {
gameCount = 1;
DataFile.updateStats("runs", gameCount);
}
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("AfterGameMessage")) {
chanInfo.afterMsg = ChannelConfig[me.profile].AfterGameMessage;
} else {
chanInfo.afterMsg = StarterConfig.AfterGameMessage;
}
if (chanInfo.afterMsg) {
if (typeof chanInfo.afterMsg === "string") {
chanInfo.afterMsg = [chanInfo.afterMsg];
}
for (i = 0; i < chanInfo.afterMsg.length; i += 1) {
sayMsg(chanInfo.afterMsg[i]);
delay(500);
}
}
}
if (!chatActionsDone) {
chatActionsDone = true;
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("JoinChannel")) {
chanInfo.joinChannel = ChannelConfig[me.profile].JoinChannel;
} else {
chanInfo.joinChannel = StarterConfig.JoinChannel;
}
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("FirstJoinMessage")) {
chanInfo.firstMsg = ChannelConfig[me.profile].FirstJoinMessage;
} else {
chanInfo.firstMsg = StarterConfig.FirstJoinMessage;
}
if (chanInfo.joinChannel) {
if (typeof chanInfo.joinChannel === "string") {
chanInfo.joinChannel = [chanInfo.joinChannel];
}
if (typeof chanInfo.firstMsg === "string") {
chanInfo.firstMsg = [chanInfo.firstMsg];
}
for (i = 0; i < chanInfo.joinChannel.length; i += 1) {
ControlAction.timeoutDelay("Chat delay", StarterConfig.ChatActionsDelay * 1e3);
if (ControlAction.joinChannel(chanInfo.joinChannel[i])) {
useChat = true;
} else {
print("ÿc1Unable to join channel, disabling chat messages.");
useChat = false;
}
if (chanInfo.firstMsg[i] !== "") {
sayMsg(chanInfo.firstMsg[i]);
delay(500);
}
}
}
}
// Announce game
if (ChannelConfig[me.profile] && ChannelConfig[me.profile].hasOwnProperty("AnnounceGames")) {
chanInfo.announce = ChannelConfig[me.profile].AnnounceGames;
} else {
chanInfo.announce = StarterConfig.AnnounceGames;
}
if (chanInfo.announce) {
sayMsg("Next game is " + gameInfo.gameName + gameCount + (gameInfo.gamePass === "" ? "" : "//" + gameInfo.gamePass));
}
// Create
if (!ControlAction.click(6, 533, 469, 120, 20)) {
break;
}
// In case create button gets bugged
if (!locationTimeout(5000, location)) {
// Join
if (!ControlAction.click(6, 652, 469, 120, 20)) {
break;
}
// Create
if (!ControlAction.click(6, 533, 469, 120, 20)) {
break;
}
}
break;
case 4: // Create Game
ControlAction.timeoutDelay("Create Game Delay", StarterConfig.DelayBeforeLogin * 1e3);
D2Bot.updateStatus("Creating Game");
control = getControl(1, 657, 342, 27, 20);
// Set character difference
if (battlenet && !!control) {
if (typeof StarterConfig.CharacterDifference === "number") {
if (control.disabled === 4) {
ControlAction.click(6, 431, 341, 15, 16);
}
ControlAction.setText(1, 657, 342, 27, 20, StarterConfig.CharacterDifference.toString());
} else if (StarterConfig.CharacterDifference === false && control.disabled === 5) {
ControlAction.click(6, 431, 341, 15, 16);
}
}
// Get game name if there is none
while (!gameInfo.gameName) {
D2Bot.requestGameInfo();
delay(500);
}
if (CharData.getStats().me.setDifficulty) {
gameInfo.difficulty = CharData.getStats().me.setDifficulty;
// only set the profile if the values aren't already the same
if (gameInfo.difficulty !== setUp.difficulty) {
D2Bot.setProfile(null, null, null, gameInfo.difficulty);
}
delay(200);
}
gameInfo.gameName = DataFile.getStats().gameName;
if (gameInfo.gameName === "") {
gameInfo.gameName = setUp.charName.substring(0, 7) + "-" + randomString(3, false) + "-";
}
// FTJ handler
if (lastGameStatus === "pending") {
isUp = "no";
D2Bot.printToConsole("Failed to create game");
ControlAction.timeoutDelay("FTJ delay", StarterConfig.FTJDelay * 1e3);
D2Bot.updateRuns();
}
ControlAction.createGame((gameInfo.gameName === "Name" ? randomString(null, true) : gameInfo.gameName + gameCount), (gameInfo.gamePass === "Password" ? randomString(null, true) : gameInfo.gamePass), gameInfo.difficulty, StarterConfig.CreateGameDelay * 1000);
lastGameStatus = "pending";
setNextGame();
locationTimeout(10000, location);
break;
case 5: // Join Game
break;
case 6: // Ladder
break;
case 7: // Channel List
break;
case 8: // Main Menu
case 9: // Login
case 18: // D2 Splash
// Single Player screen fix
if (getLocation() === 12 && !getControl(4, 626, 100, 151, 44)) {
ControlAction.click(6, 33, 572, 128, 35);
break;
}
// Multiple realm botting fix in case of R/D or disconnect
if (firstLogin && getLocation() === 9) {
ControlAction.click(6, 33, 572, 128, 35);
}
D2Bot.updateStatus("Logging In");
try {
// make battlenet accounts/characters
if (battlenet) {
ControlAction.timeoutDelay("Login Delay", StarterConfig.DelayBeforeLogin * 1e3);
// existing account
if (setUp.account !== "") {
try {
login(me.profile);
} catch (error) {
if (DataFile.getStats().AcctPswd) {
setUp.account = DataFile.getStats().AcctName;
setUp.password = DataFile.getStats().AcctPswd;
for (let i = 0; i < 5; i++) {
if (ControlAction.loginAccount(setUp)) {
break;
}
ControlAction.timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
setUp.account = DataFile.getStats().AcctName;
setUp.password = DataFile.getStats().AcctPswd;
}
}
}
} else {
// new account
if (setUp.account === "") {
if (StarterConfig.GlobalAccountPassword) {
setUp.account = randomString(12, true);
setUp.password = StarterConfig.GlobalAccountPassword;
print("Generating Account Information");
ControlAction.timeoutDelay("Generating Account Information", StarterConfig.DelayBeforeLogin * 1e3);
} else {
setUp.account = randomString(12, true);
setUp.password = randomString(12, true);
print("Generating Random Account Information");
ControlAction.timeoutDelay("Generating Random Account Information", StarterConfig.DelayBeforeLogin * 1e3);
}
if (ControlAction.makeAccount(setUp)) {
D2Bot.setProfile(setUp.account, setUp.password, null, "Normal");
DataFile.updateStats("AcctName", setUp.account);
DataFile.updateStats("AcctPswd", setUp.password);
break;
} else {
setUp.account = "";
setUp.password = "";
D2Bot.setProfile(setUp.account, setUp.password, null, "Normal");
D2Bot.restart(true);
}
}
}
} else { // SP/TCP characters
try {
login(me.profile);
} catch (err) {
// Try to find the character and if that fails, make character
if (!ControlAction.findCharacter(setUp)) {
// Pop-up that happens when choosing a dead HC char
if (getLocation() === 30) {
ControlAction.click(6, 351, 337, 96, 32); // Exit from that pop-up
D2Bot.printToConsole("Character died", 9);
deleteAndRemakeChar(setUp);
} else {
// If make character fails, check how many characters are on that account
if (!ControlAction.makeCharacter(setUp)) {
// Account is full
if (ControlAction.getCharacters().length >= 18) {
D2Bot.printToConsole("Kolbot-SoloPlay: Account is full", 8);
D2Bot.stop();
}
}
}
}
}
}
} catch (e) {
print(e + " " + getLocation());
}
break;
case 10: // Login Error
string = "";
text = ControlAction.getText(4, 199, 377, 402, 140);
if (text) {
for (i = 0; i < text.length; i += 1) {
string += text[i];
if (i !== text.length - 1) {
string += " ";
}
}
switch (string) {
case getLocaleString(5232): // illegal characters
case getLocaleString(5233): // disallowed words
D2Bot.stop();
break;
case getLocaleString(5207):
D2Bot.updateStatus("Invalid Password");
D2Bot.printToConsole("Invalid Password");
ControlAction.timeoutDelay("Invalid password delay", StarterConfig.InvalidPasswordDelay * 6e4);
D2Bot.printToConsole("Invalid Password - Restart");
D2Bot.restart();
break;
case getLocaleString(5219): // password must be 2 characters
D2Bot.updateStatus("Password must be 2 characters");
D2Bot.printToConsole("Password must be 2 characters");
D2Bot.stop();
break;
case getLocaleString(5208): // Invalid account
case getLocaleString(5239): // An account name already exists
case getLocaleString(5249): // Unable to create account
D2Bot.updateStatus("Invalid Account Name");
D2Bot.printToConsole("Invalid Account Name");
setUp.account = "";
setUp.password = "";
D2Bot.setProfile(setUp.account, setUp.password);
D2Bot.restart(true);
break;
case getLocaleString(5202): // cd key intended for another product
case getLocaleString(10915): // lod key intended for another product
D2Bot.updateStatus("Invalid CDKey");
D2Bot.printToConsole("Invalid CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
case getLocaleString(5199):
D2Bot.updateStatus("Disabled CDKey");
D2Bot.printToConsole("Disabled CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
case getLocaleString(10913):
D2Bot.updateStatus("Disabled LoD CDKey");
D2Bot.printToConsole("Disabled LoD CDKey: " + gameInfo.mpq, 6);
D2Bot.CDKeyDisabled();
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
case getLocaleString(5347):
D2Bot.updateStatus("Disconnected from battle.net.");
D2Bot.printToConsole("Disconnected from battle.net.");
ControlAction.click(6, 351, 337, 96, 32);
ControlAction.click(6, 335, 412, 128, 35);
break MainSwitch;
default:
D2Bot.updateStatus("Login Error");
D2Bot.printToConsole("Login Error - " + string);
if (gameInfo.switchKeys) {
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.stop();
}
break;
}
}
ControlAction.click(6, 335, 412, 128, 35);
delay(1000);
ControlAction.click(6, 33, 572, 128, 35);
break;
case 11: // Unable To Connect
D2Bot.updateStatus("Unable To Connect");
if (connectFailRetry < 2) {
connectFailRetry += 1;
ControlAction.click(6, 335, 450, 128, 35);
break;
}
if (connectFailRetry >= 2) {
connectFail = true;
}
if (connectFail) {
ControlAction.timeoutDelay("Unable to Connect", StarterConfig.UnableToConnectDelay * 6e4);
ControlAction.click(6, 335, 412, 128, 35);
connectFail = false;
}
if (!ControlAction.click(6, 335, 450, 128, 35)) {
break;
}
connectFailRetry = 0;
connectFail = true;
break;
case 13: // Realm Down - Character Select screen
D2Bot.updateStatus("Realm Down");
delay(1000);
if (!ControlAction.click(6, 33, 572, 128, 35)) {
break;
}
updateCount();
ControlAction.timeoutDelay("Realm Down", StarterConfig.RealmDownDelay * 6e4);
D2Bot.CDKeyRD();
if (gameInfo.switchKeys && !gameInfo.rdBlocker) {
D2Bot.printToConsole("Realm Down - Changing CD-Key");
ControlAction.timeoutDelay("Key switch delay", StarterConfig.SwitchKeyDelay * 1000);
D2Bot.restart(true);
} else {
D2Bot.printToConsole("Realm Down - Restart");
D2Bot.restart();
}
break;
case 14: // Character Select / Main Menu - Disconnected
D2Bot.updateStatus("Disconnected");
delay(500);
ControlAction.click(6, 351, 337, 96, 32);
break;
case 16: // Character Select - Please Wait popup
if (!locationTimeout(StarterConfig.PleaseWaitTimeout * 1e3, location)) {
ControlAction.click(6, 351, 337, 96, 32);
}
break;
case 17: // Lobby - Lost Connection - just click okay, since we're toast anyway
delay(1000);
ControlAction.click(6, 351, 337, 96, 32);