-
Notifications
You must be signed in to change notification settings - Fork 21
/
Form1.cs
2639 lines (2407 loc) · 124 KB
/
Form1.cs
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
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Runtime.Remoting;
using System.Security.Cryptography;
using System.Security.Policy;
using System.Text;
using System.Text.Json;
using Newtonsoft.Json;
using Microsoft.Win32;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using System.Xml.Linq;
using System.Net.Http;
using static Enums;
using static Form1;
using static System.Collections.Specialized.BitVector32;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Button;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolBar;
using static MapAreaStruc;
using System.Linq.Expressions;
public partial class Form1 : Form
{
public string BotVersion = "V3.05R2";
public string D2_LOD_113C_Path = "";
public Process process;
public string ThisEndPath = Application.StartupPath + @"\Extracted\";
public string ThisLogPath = Application.StartupPath + @"\Logs\";
public Dictionary<string, IntPtr> offsets = new Dictionary<string, IntPtr>();
public IntPtr BaseAddress = (IntPtr)0;
public IntPtr processHandle = (IntPtr)0;
public byte[] buffer = new byte[0x3FFFFFF];
public byte[] bufferRead = new byte[0];
public System.Timers.Timer LoopTimer;
public bool Running = false;
public bool RunFinished = false;
public bool HasPointers = false;
public int UnitStrucOffset = -32;
public int hWnd = 0;
public int LoopDone = 0;
public bool CharDied = false;
public bool RestartingBot = false;
public bool BotPaused = false;
public bool BotResuming = false;
public bool PrintedGameTime = false;
public DateTime CheckTime = new DateTime();
public DateTime GameStartedTime = new DateTime();
public DateTime TimeSinceSearchingForGames = new DateTime();
public Rectangle D2Rect = new Rectangle();
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", SetLastError = true)]
private static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public int ScreenX = Screen.PrimaryScreen.Bounds.Width;
public int ScreenY = Screen.PrimaryScreen.Bounds.Height;
//var (ScreenX, ScreenY) = GetWindowResolutionByExe("d2r.exe");
public int CenterX = 0;
public int CenterY = 0;
public int D2Widht = 0;
public int D2Height = 0;
public int ScreenXOffset = 0;
public int ScreenYOffset = 0;
public double centerModeScale = 2.262;
public int renderScale = 3;
public int ScreenYMenu = 180;
public int CurrentGameNumber = 1;
public int CurrentGameNumberFullyDone = 0;
public bool SetGameDone = false;
public int FoundPlayerPointerTryCount = 0;
public int FoundPlayerPointerRetryTimes = 0;
public int TriedToCreateNewGameCount = 0;
public int CurrentGameNumberSinceStart = 1;
public bool ForceSwitch2ndPlayer = false;
public bool BadPlayerPointerFound = false;
public bool PublicGame = false;
public int DebugMenuStyle = 0;
public bool BotJustStarted = true;
public bool SetDeadCount = false;
public bool LoadingBot = true;
public double FPS = 0;
public string mS = "";
public List<double> Averge_FPSList = new List<double>();
public List<int> Averge_mSList = new List<int>();
public double Average_FPS = 0;
public int Average_mS = 0;
public int TotalChickenCount = 0;
public int TotalDeadCount = 0;
public int TotalChickenByTimeCount = 0;
public List<object> AllClassInstances = new List<object>();
public ItemsStruc ItemsStruc_0;
public Mem Mem_0;
public Form1 Form1_0;
public PatternsScan PatternsScan_0;
public GameStruc GameStruc_0;
public PlayerScan PlayerScan_0;
public ItemsAlert ItemsAlert_0;
public UIScan UIScan_0;
public BeltStruc BeltStruc_0;
public ItemsFlags ItemsFlags_0;
public ItemsNames ItemsNames_0;
public InventoryStruc InventoryStruc_0;
public MobsStruc MobsStruc_0;
public NPCStruc NPCStruc_0;
public HoverStruc HoverStruc_0;
public Town Town_0;
public Potions Potions_0;
public SkillsStruc SkillsStruc_0;
public ObjectsStruc ObjectsStruc_0;
public Mover Mover_0;
public Stash Stash_0;
public Shop Shop_0;
public Repair Repair_0;
public ChaosLeech ChaosLeech_0;
public Chaos Chaos_0;
public Duriel Duriel_0;
public Pindleskin Pindleskin_0;
public Battle Battle_0;
public KeyMouse KeyMouse_0;
public Summoner Summoner_0;
public Baal Baal_0;
public BaalLeech BaalLeech_0;
public Travincal Travincal_0;
public Mephisto Mephisto_0;
public Andariel Andariel_0;
public Countess Countess_0;
public MercStruc MercStruc_0;
public StashStruc StashStruc_0;
public Cubing Cubing_0;
public Gamble Gamble_0;
public LowerKurast LowerKurast_0;
public Act3Sewers Act3Sewers_0;
public UpperKurast UpperKurast_0;
public SettingsLoader SettingsLoader_0;
public MapAreaStruc MapAreaStruc_0;
public PathFinding PathFinding_0;
public WPTaker WPTaker_0;
public Cows Cows_0;
public Eldritch Eldritch_0;
public Shenk Shenk_0;
public Nihlatak Nihlatak_0;
public Frozenstein Frozenstein_0;
public ShopBot ShopBot_0;
public Mausoleum Mausoleum_0;
public Crypt Crypt_0;
public ArachnidLair ArachnidLair_0;
public Pit Pit_0;
public AndarielRush AndarielRush_0;
public DarkWoodRush DarkWoodRush_0;
public DurielRush DurielRush_0;
public FarOasisRush FarOasisRush_0;
public HallOfDeadRushCube HallOfDeadRushCube_0;
public KahlimBrainRush KahlimBrainRush_0;
public KahlimEyeRush KahlimEyeRush_0;
public KahlimHeartRush KahlimHeartRush_0;
public LostCityRush LostCityRush_0;
public MephistoRush MephistoRush_0;
public RadamentRush RadamentRush_0;
public SummonerRush SummonerRush_0;
public TravincalRush TravincalRush_0;
public TristramRush TristramRush_0;
public AncientsRush AncientsRush_0;
public AnyaRush AnyaRush_0;
public ChaosRush ChaosRush_0;
public BaalRush BaalRush_0;
public OverlayForm overlayForm;
public ScriptsLoader ScriptsLoader_0;
public TerrorZones TerrorZones_0;
public AreaScript AreaScript_0;
public ItemsViewer ItemsViewer_0;
// REQUIRED CONSTS
const int PROCESS_QUERY_INFORMATION = 0x0400;
const int MEM_COMMIT = 0x00001000;
const int PROCESS_VM_OPERATION = 0x0008;
const int PROCESS_VM_READ = 0x0010;
const int PROCESS_VM_WRITE = 0x0020;
const int SYNCHRONIZE = 0x00100000;
// REQUIRED METHODS
[DllImport("kernel32.dll")]
public static extern IntPtr OpenProcess(int dwDesiredAccess, bool bInheritHandle, int dwProcessId);
[DllImport("kernel32.dll")]
static extern void GetSystemInfo(out SYSTEM_INFO lpSystemInfo);
//[DllImport("user32.dll")]
//private static extern int FindWindow(string ClassName, string WindowName);
[DllImport("user32.dll")]
private static extern int GetWindowRect(int hwnd, out Rectangle rect);
[DllImport("user32.dll")]
private static extern bool GetClientRect(int hwnd, out Rectangle lpRect);
[DllImport("user32.dll")]
static extern bool ClientToScreen(int hWnd, out Point lpPoint);
[DllImport("gdi32.dll")]
static extern int GetDeviceCaps(IntPtr hdc, int nIndex);
public enum DeviceCap
{
VERTRES = 10,
DESKTOPVERTRES = 117,
}
/*public void TestMethod()
{
Console.WriteLine("Executing MyMethod from script #3...");
}*/
// REQUIRED STRUCTS
public struct MEMORY_BASIC_INFORMATION
{
public int BaseAddress;
public int AllocationBase;
public int AllocationProtect;
public int RegionSize;
public int State;
public int Protect;
public int lType;
}
public struct SYSTEM_INFO
{
public ushort processorArchitecture;
ushort reserved;
public uint pageSize;
public IntPtr minimumApplicationAddress;
public IntPtr maximumApplicationAddress;
public IntPtr activeProcessorMask;
public uint numberOfProcessors;
public uint processorType;
public uint allocationGranularity;
public ushort processorLevel;
public ushort processorRevision;
}
public Form1()
{
InitializeComponent();
Form1_0 = this;
(Form1_0.ScreenX, Form1_0.ScreenY) = GetWindowResolutionByExe("d2r.exe");
this.TopMost = true;
this.Text = "D2R - BMBot (" + BotVersion + ")";
labelGames.Text = "";//CurrentGameNumber.ToString();
SetGameStatus("STOPPED");
richTextBox1.HideSelection = false;//Hide selection so that AppendText will auto scroll to the end
richTextBox2.HideSelection = false;//Hide selection so that AppendText will auto scroll to the end
//richTextBox2.Visible = false;
//ModifyMonsterList();
//overlay graphics
if (overlayForm == null || overlayForm.IsDisposed)
{
overlayForm = new OverlayForm(Form1_0);
}
overlayForm.Show();
comboBoxItemsCategory.SelectedIndex = 0;
LabelChickenCount.Text = TotalChickenCount.ToString();
LabelDeadCount.Text = TotalDeadCount.ToString();
SetDebugMenu();
labelGameName.Text = "";
labelGameTime.Text = "";
LoopTimer = new System.Timers.Timer(1);
LoopTimer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
ScreenX = Screen.PrimaryScreen.Bounds.Width;
ScreenY = Screen.PrimaryScreen.Bounds.Height;
//CenterX = CharConfig.ScreenX / 2;
//CenterY = CharConfig.ScreenY / 2;
ItemsStruc_0 = new ItemsStruc();
Mem_0 = new Mem();
PatternsScan_0 = new PatternsScan();
GameStruc_0 = new GameStruc();
PlayerScan_0 = new PlayerScan();
ItemsAlert_0 = new ItemsAlert();
UIScan_0 = new UIScan();
BeltStruc_0 = new BeltStruc();
ItemsFlags_0 = new ItemsFlags();
ItemsNames_0 = new ItemsNames();
InventoryStruc_0 = new InventoryStruc();
MobsStruc_0 = new MobsStruc();
NPCStruc_0 = new NPCStruc();
HoverStruc_0 = new HoverStruc();
Town_0 = new Town();
Potions_0 = new Potions();
SkillsStruc_0 = new SkillsStruc();
ObjectsStruc_0 = new ObjectsStruc();
Mover_0 = new Mover();
Stash_0 = new Stash();
Shop_0 = new Shop();
Repair_0 = new Repair();
Summoner_0 = new Summoner();
ChaosLeech_0 = new ChaosLeech();
Chaos_0 = new Chaos();
Battle_0 = new Battle();
KeyMouse_0 = new KeyMouse();
Duriel_0 = new Duriel();
Pindleskin_0 = new Pindleskin();
BaalLeech_0 = new BaalLeech();
Baal_0 = new Baal();
Travincal_0 = new Travincal();
Mephisto_0 = new Mephisto();
Andariel_0 = new Andariel();
Countess_0 = new Countess();
MercStruc_0 = new MercStruc();
StashStruc_0 = new StashStruc();
Cubing_0 = new Cubing();
Gamble_0 = new Gamble();
LowerKurast_0 = new LowerKurast();
Act3Sewers_0 = new Act3Sewers();
UpperKurast_0 = new UpperKurast();
SettingsLoader_0 = new SettingsLoader();
MapAreaStruc_0 = new MapAreaStruc();
PathFinding_0 = new PathFinding();
WPTaker_0 = new WPTaker();
Cows_0 = new Cows();
Eldritch_0 = new Eldritch();
Shenk_0 = new Shenk();
Nihlatak_0 = new Nihlatak();
Frozenstein_0 = new Frozenstein();
TerrorZones_0 = new TerrorZones();
AreaScript_0 = new AreaScript();
ShopBot_0 = new ShopBot();
Mausoleum_0 = new Mausoleum();
Crypt_0 = new Crypt();
ArachnidLair_0 = new ArachnidLair();
Pit_0 = new Pit();
AndarielRush_0 = new AndarielRush();
DarkWoodRush_0 = new DarkWoodRush();
DurielRush_0 = new DurielRush();
FarOasisRush_0 = new FarOasisRush();
HallOfDeadRushCube_0 = new HallOfDeadRushCube();
KahlimBrainRush_0 = new KahlimBrainRush();
KahlimEyeRush_0 = new KahlimEyeRush();
KahlimHeartRush_0 = new KahlimHeartRush();
LostCityRush_0 = new LostCityRush();
MephistoRush_0 = new MephistoRush();
RadamentRush_0 = new RadamentRush();
SummonerRush_0 = new SummonerRush();
TravincalRush_0 = new TravincalRush();
TristramRush_0 = new TristramRush();
AncientsRush_0 = new AncientsRush();
AnyaRush_0 = new AnyaRush();
ChaosRush_0 = new ChaosRush();
BaalRush_0 = new BaalRush();
ItemsViewer_0 = new ItemsViewer();
AllClassInstances = new List<object>();
//ScriptsLoader_0 = new ScriptsLoader();
//ScriptsLoader_0.SetForm1(Form1_0);
//ScriptsLoader_0.LoadScripts(Application.StartupPath + @"\Scripts\Andariel.cs");
ItemsStruc_0.SetForm1(Form1_0);
Mem_0.SetForm1(Form1_0);
PatternsScan_0.SetForm1(Form1_0);
GameStruc_0.SetForm1(Form1_0);
PlayerScan_0.SetForm1(Form1_0);
ItemsAlert_0.SetForm1(Form1_0);
UIScan_0.SetForm1(Form1_0);
BeltStruc_0.SetForm1(Form1_0);
ItemsFlags_0.SetForm1(Form1_0);
InventoryStruc_0.SetForm1(Form1_0);
MobsStruc_0.SetForm1(Form1_0);
NPCStruc_0.SetForm1(Form1_0);
HoverStruc_0.SetForm1(Form1_0);
Town_0.SetForm1(Form1_0);
Potions_0.SetForm1(Form1_0);
SkillsStruc_0.SetForm1(Form1_0);
ObjectsStruc_0.SetForm1(Form1_0);
Mover_0.SetForm1(Form1_0);
Stash_0.SetForm1(Form1_0);
Shop_0.SetForm1(Form1_0);
Repair_0.SetForm1(Form1_0);
Summoner_0.SetForm1(Form1_0);
ChaosLeech_0.SetForm1(Form1_0);
Chaos_0.SetForm1(Form1_0);
Duriel_0.SetForm1(Form1_0);
Travincal_0.SetForm1(Form1_0);
Battle_0.SetForm1(Form1_0);
KeyMouse_0.SetForm1(Form1_0);
Mephisto_0.SetForm1(Form1_0);
Pindleskin_0.SetForm1(Form1_0);
Baal_0.SetForm1(Form1_0);
BaalLeech_0.SetForm1(Form1_0);
Andariel_0.SetForm1(Form1_0);
Countess_0.SetForm1(Form1_0);
MercStruc_0.SetForm1(Form1_0);
StashStruc_0.SetForm1(Form1_0);
Cubing_0.SetForm1(Form1_0);
Gamble_0.SetForm1(Form1_0);
LowerKurast_0.SetForm1(Form1_0);
Act3Sewers_0.SetForm1(Form1_0);
UpperKurast_0.SetForm1(Form1_0);
SettingsLoader_0.SetForm1(Form1_0);
MapAreaStruc_0.SetForm1(Form1_0);
PathFinding_0.SetForm1(Form1_0);
WPTaker_0.SetForm1(Form1_0);
Cows_0.SetForm1(Form1_0);
Eldritch_0.SetForm1(Form1_0);
Shenk_0.SetForm1(Form1_0);
Nihlatak_0.SetForm1(Form1_0);
Frozenstein_0.SetForm1(Form1_0);
TerrorZones_0.SetForm1(Form1_0);
AreaScript_0.SetForm1(Form1_0);
ShopBot_0.SetForm1(Form1_0);
Mausoleum_0.SetForm1(Form1_0);
Crypt_0.SetForm1(Form1_0);
ArachnidLair_0.SetForm1(Form1_0);
Pit_0.SetForm1(Form1_0);
AndarielRush_0.SetForm1(Form1_0);
DarkWoodRush_0.SetForm1(Form1_0);
DurielRush_0.SetForm1(Form1_0);
FarOasisRush_0.SetForm1(Form1_0);
HallOfDeadRushCube_0.SetForm1(Form1_0);
KahlimBrainRush_0.SetForm1(Form1_0);
KahlimEyeRush_0.SetForm1(Form1_0);
KahlimHeartRush_0.SetForm1(Form1_0);
LostCityRush_0.SetForm1(Form1_0);
MephistoRush_0.SetForm1(Form1_0);
RadamentRush_0.SetForm1(Form1_0);
SummonerRush_0.SetForm1(Form1_0);
TravincalRush_0.SetForm1(Form1_0);
TristramRush_0.SetForm1(Form1_0);
AncientsRush_0.SetForm1(Form1_0);
AnyaRush_0.SetForm1(Form1_0);
ChaosRush_0.SetForm1(Form1_0);
BaalRush_0.SetForm1(Form1_0);
ItemsViewer_0.SetForm1(Form1_0);
SettingsLoader_0.LoadSettings();
if (Form1_0.D2_LOD_113C_Path == "" || !Directory.Exists(Form1_0.D2_LOD_113C_Path))
{
bool LoadedPreSettings = false;
if (CharConfig.PlayerCharName == "CHARNAMEHERE")
{
DialogResult result = MessageBox.Show("Do you want to Import all Settings Files from a previous Version?", "ERROR", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
LoadedPreSettings = true;
folderBrowserDialog1.Description = "Select the Settings folder where your previous bot version is located";
DialogResult result2 = folderBrowserDialog1.ShowDialog();
if (result2 == DialogResult.OK)
{
//Form1_0.D2_LOD_113C_Path = folderBrowserDialog1.SelectedPath;
//load char settings
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Sorceress.txt");
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Paladin.txt");
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Assassin.txt");
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Druid.txt");
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Necromancer.txt");
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Amazon.txt");
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Barbarian.txt");
Form1_0.SettingsLoader_0.LoadThisFileSettings(folderBrowserDialog1.SelectedPath + @"\ItemsSettings.txt");
Form1_0.SettingsLoader_0.LoadThisFileSettings(folderBrowserDialog1.SelectedPath + @"\CubingRecipes.txt");
Form1_0.SettingsLoader_0.LoadThisFileSettings(folderBrowserDialog1.SelectedPath + @"\BotSettings.txt");
Form1_0.SettingsLoader_0.LoadThisFileSettings(folderBrowserDialog1.SelectedPath + @"\CharSettings.txt");
//Load correct character
switch (CharConfig.RunningOnChar)
{
case "Sorceress":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Sorceress.txt");
// Load Sorceress
break;
case "Amazon":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Amazon.txt");
// Load Amazon
break;
case "Assassin":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Assassin.txt");
// Load Sorceress
break;
case "Druid":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Druid.txt");
// Load Amazon
break;
case "Barbarian":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Barbarian.txt");
// Load Sorceress
break;
case "Necromancer":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Necromancer.txt");
// Load Amazon
break;
case "Paladin":
Form1_0.SettingsLoader_0.ReloadCharSettingsFromThisFile(folderBrowserDialog1.SelectedPath + @"\Char\Paladin.txt");
// Load Paladin
break;
}
//Reload Settings (D2 Path, RunNumber)
Form1_0.SettingsLoader_0.LoadThisFileSettings(folderBrowserDialog1.SelectedPath + @"\Settings.txt");
Application.DoEvents();
}
else
{
LoadedPreSettings = false;
}
}
}
if (!LoadedPreSettings)
{
DialogResult result = MessageBox.Show("Diablo2 LOD 1.13C Path is not set correctly!" + Environment.NewLine + Environment.NewLine + "Do you want to select the Path where it's located?", "ERROR", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result == DialogResult.Yes)
{
folderBrowserDialog1.Description = "Select the folder where D2 LOD 1.13C is located";
DialogResult result2 = folderBrowserDialog1.ShowDialog();
if (result2 == DialogResult.OK)
{
Form1_0.D2_LOD_113C_Path = folderBrowserDialog1.SelectedPath;
}
else
{
method_1("ERROR: Diablo2 LOD 1.13C Path NOT SET CORRECTLY!", Color.Red);
method_1("Clic on the settings button and set the path where Diablo2 1.13c (the old legacy diablo2) is located!", Color.Red);
method_1("Make sure the path don't contain any whitespace!", Color.Red);
buttonD2LOD.Visible = true;
}
}
else
{
method_1("ERROR: Diablo2 LOD 1.13C Path NOT SET CORRECTLY!", Color.Red);
method_1("Clic on the settings button and set the path where Diablo2 1.13c (the old legacy diablo2) is located!", Color.Red);
method_1("Make sure the path don't contain any whitespace!", Color.Red);
buttonD2LOD.Visible = true;
}
}
}
KeyMouse_0.proc = KeyMouse_0.HookCallback;
KeyMouse_0.hookID = KeyMouse_0.SetHook(KeyMouse_0.proc);
//ItemsAlert_0.SetParams();
dataGridView1.Rows.Add("Processing Time", "Unknown");
//dataGridView1.Rows.Add("---Player---", "---------");
dataGridView1.Rows.Add("Pointer", "Unknown");
dataGridView1.Rows.Add("Cords", "Unknown"); //
dataGridView1.Rows.Add("LeechCords", "Unknown"); //
dataGridView1.Rows.Add("Life", "Unknown"); //
dataGridView1.Rows.Add("Mana", "Unknown"); //
dataGridView1.Rows.Add("Map Level", "Unknown"); //
//dataGridView1.Rows.Add("Room Exit", "Unknown"); //
//dataGridView1.Rows.Add("Difficulty", "Unknown"); //
dataGridView1.Rows.Add("Merc", "Unknown"); //
//dataGridView1.Rows.Add("Seed", "Unknown"); //
//dataGridView1.Rows.Add("Belt qty", "Unknown"); //
//dataGridView1.Rows.Add("---Items---", "---------");
dataGridView1.Rows.Add("Scanned", "Unknown");
dataGridView1.Rows.Add("On ground", "Unknown");
dataGridView1.Rows.Add("Equipped", "Unknown");
dataGridView1.Rows.Add("InInventory", "Unknown");
dataGridView1.Rows.Add("InBelt", "Unknown");
//dataGridView1.Rows.Add("---Menu---", "---------");
dataGridView1.Rows.Add("Left Open", "Unknown");
dataGridView1.Rows.Add("Right Open", "Unknown");
dataGridView1.Rows.Add("Full Open", "Unknown");
//CheckForUpdates();
comboBoxCollisionArea.Items.Clear();
for (int i = 0; i < 136; i++) comboBoxCollisionArea.Items.Add(((Enums.Area)i + 1).ToString());
LoadingBot = false;
}
public (int width, int height) GetWindowResolutionByExe(string exeName)
{
var process = Process.GetProcessesByName(exeName);
if (process.Length == 0)
{
Console.WriteLine("Process not found!");
return (0, 0);
}
IntPtr windowHandle = process[0].MainWindowHandle;
if (windowHandle == IntPtr.Zero)
{
Console.WriteLine("Main window not found!");
return (0, 0);
}
if (GetWindowRect(windowHandle, out RECT rect))
{
int width = rect.Right - rect.Left;
int height = rect.Bottom - rect.Top;
return (width, height);
}
else
{
Console.WriteLine("Failed to get window rectangle!");
return (0, 0);
}
}
public void CheckForUpdates()
{
string url = "https://raw.githubusercontent.com/bouletmarc/D2R-BMBot/main/Form1.cs";
using (HttpClient client = new HttpClient())
{
try
{
HttpResponseMessage response = client.GetAsync(url).Result;
response.EnsureSuccessStatusCode();
string responseBody = response.Content.ReadAsStringAsync().Result;
if (responseBody.Contains("public string BotVersion = "))
{
string ThisOnlineVString = responseBody.Substring(responseBody.IndexOf('=') + 4, 5);
ThisOnlineVString = ThisOnlineVString.Replace("\"", "").Replace(";", "");
double ThisVersionOnline = double.Parse(ThisOnlineVString, System.Globalization.CultureInfo.InvariantCulture);
double ThisVersionCurrent = double.Parse(BotVersion.Substring(1).Replace("\"", ""), System.Globalization.CultureInfo.InvariantCulture);
if (ThisVersionOnline > ThisVersionCurrent)
{
method_1("New update V" + ThisVersionOnline.ToString().Replace(",", ".") + " available on github!", Color.Red);
buttonUpdate.Visible = true;
}
else if (ThisVersionOnline == ThisVersionCurrent)
{
method_1("BMBot is updated!", Color.DarkGreen);
}
else if (ThisVersionOnline < ThisVersionCurrent)
{
method_1("BMBot is updated (Development Version)!", Color.DarkGreen);
}
}
else
{
method_1("Couldn't check for updates!", Color.Red);
}
}
catch (HttpRequestException e)
{
method_1("Couldn't check for updates! Error:", Color.Red);
method_1(e.Message, Color.Red);
}
}
}
public void LeaveGame(bool BotCompletlyDone)
{
if (CharConfig.RunItemGrabScriptOnly) return;
SetGameStatus("LEAVING");
if (BotCompletlyDone && !SetGameDone)
{
Form1_0.CurrentGameNumberFullyDone++;
SetGameDone = true;
}
if (UIScan_0.OpenUIMenu("quitMenu"))
{
KeyMouse_0.MouseClicc(960, 480);
WaitDelay(5);
KeyMouse_0.MouseClicc(960, 480);
WaitDelay(200);
}
}
void RemovePastDump()
{
string[] FileList = Directory.GetFiles(ThisEndPath, "Dump*");
if (FileList.Length > 0)
{
for (int i = 0; i < FileList.Length; i++)
{
File.Delete(FileList[i]);
}
}
}
public void method_1(string string_3, Color ThisColor, bool LogTime = true)
{
//try
//{
if (richTextBox1.InvokeRequired)
{
// Call this same method but append THREAD2 to the text
Action safeWrite = delegate { method_1(string_3, ThisColor); };
richTextBox1.Invoke(safeWrite);
}
else
{
if (LogTime) string_3 = string_3 + " " + GameStruc_0.GetTimeNow();
Console.WriteLine(string_3);
if (ThisColor == Color.OrangeRed && !CharConfig.LogNotUsefulErrors) return;
richTextBox1.SelectionColor = ThisColor;
richTextBox1.AppendText(string_3 + Environment.NewLine);
overlayForm.AddLogs(string_3, ThisColor);
if (ThisColor == Color.Red || ThisColor == Color.Orange || ThisColor == Color.DarkOrange || ThisColor == Color.OrangeRed) AppendTextErrorLogs(string_3, ThisColor);
if (ThisColor == Color.DarkBlue) AppendTextGameLogs(string_3, ThisColor);
Application.DoEvents();
}
//}
//catch { }
}
public void method_1_Items(string string_3, Color ThisColor)
{
//try
//{
if (richTextBox2.InvokeRequired)
{
// Call this same method but append THREAD2 to the text
Action safeWrite = delegate { method_1_Items(string_3, ThisColor); };
richTextBox2.Invoke(safeWrite);
}
else
{
string LogThis = string_3 + " in " + Town_0.getAreaName((int)PlayerScan_0.levelNo) + " " + GameStruc_0.GetTimeNow();
richTextBox2.SelectionColor = ThisColor;
richTextBox2.AppendText(LogThis + Environment.NewLine);
method_1(LogThis, ThisColor, false);
if (!Directory.Exists(ThisLogPath)) Directory.CreateDirectory(ThisLogPath);
if (!File.Exists(ThisLogPath + "ItemsLogs.txt")) File.Create(ThisLogPath + "ItemsLogs.txt").Dispose();
File.AppendAllText(ThisLogPath + "ItemsLogs.txt", LogThis + Environment.NewLine);
Application.DoEvents();
}
//}
//catch { }
}
public void method_1_SoldItems(string string_3, Color ThisColor)
{
//try
//{
if (richTextBoSoldLogs.InvokeRequired)
{
// Call this same method but append THREAD2 to the text
Action safeWrite = delegate { method_1_SoldItems(string_3, ThisColor); };
richTextBoSoldLogs.Invoke(safeWrite);
}
else
{
string LogThis = string_3 + " " + GameStruc_0.GetTimeNow();
richTextBoSoldLogs.SelectionColor = ThisColor;
richTextBoSoldLogs.AppendText(LogThis + Environment.NewLine);
//method_1(LogThis, ThisColor, false);
if (!Directory.Exists(ThisLogPath)) Directory.CreateDirectory(ThisLogPath);
if (!File.Exists(ThisLogPath + "ItemsSoldLogs.txt")) File.Create(ThisLogPath + "ItemsSoldLogs.txt").Dispose();
File.AppendAllText(ThisLogPath + "ItemsSoldLogs.txt", LogThis + Environment.NewLine);
Application.DoEvents();
}
//}
//catch { }
}
public string PreviousStatus = "IDLE";
public string CurrentStatus = "IDLE";
public void SetGameStatus(string string_3)
{
//try
//{
if (this.InvokeRequired)
{
// Call this same method but append THREAD2 to the text
Action safeWrite = delegate { SetGameStatus(string_3); };
this.Invoke(safeWrite);
}
else
{
string RunText = "STOPPED";
if (Running) RunText = "RUNNING";
if (string_3 == "STOPPED") string_3 = PreviousStatus;
else PreviousStatus = string_3;
CurrentStatus = string_3;
this.Text = "D2R - BMBot " + BotVersion + " | " + RunText + " | " + string_3;
Application.DoEvents();
}
//}
//catch { }
}
public void Grid_SetInfos(string RowName, string ThisInfos)
{
//try
//{
if (dataGridView1.InvokeRequired)
{
// Call this same method but append THREAD2 to the text
Action safeWrite = delegate { Grid_SetInfos(RowName, ThisInfos); };
dataGridView1.Invoke(safeWrite);
}
else
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value.ToString() == RowName)
{
dataGridView1.Rows[i].Cells[1].Value = ThisInfos;
return;
}
}
}
//}
//catch { }
}
public void SetGamesText()
{
/*if (labelGames.InvokeRequired)
{
// Call this same method but append THREAD2 to the text
Action safeWrite = delegate { SetGamesText(); };
labelGames.Invoke(safeWrite);
}
else
{
labelGames.Text = CurrentGameNumberSinceStart.ToString() + " entered. " + CurrentGameNumberFullyDone.ToString() + " fully done";
}*/
labelGames.Text = CurrentGameNumberSinceStart.ToString() + " entered. " + CurrentGameNumberFullyDone.ToString() + " fully done";
}
private float getScalingFactor()
{
Graphics g = Graphics.FromHwnd(IntPtr.Zero);
IntPtr desktop = g.GetHdc();
int LogicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.VERTRES);
int PhysicalScreenHeight = GetDeviceCaps(desktop, (int)DeviceCap.DESKTOPVERTRES);
g.ReleaseHdc(desktop);
float ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
return ScreenScalingFactor; // 1.25 = 125%
}
public void Startt()
{
try
{
SYSTEM_INFO sys_info = new SYSTEM_INFO();
GetSystemInfo(out sys_info);
if (!Directory.Exists(ThisEndPath)) Directory.CreateDirectory(ThisEndPath);
RemovePastDump();
method_1("------------------------------------------", Color.DarkBlue);
method_1("Extracting Infos...", Color.Black);
Process[] ProcList = Process.GetProcessesByName("D2R");
if (!GameStruc_0.IsGameRunning())
{
method_1("D2R is not running!", Color.Red);
return;
}
else
{
SetGameStatus("LOADING");
method_1("D2R is running...", Color.DarkGreen);
hWnd = (int)FindWindow(null, "Diablo II: Resurrected");
//GetWindowRect(hWnd, out D2Rect);
GetClientRect(hWnd, out D2Rect);
Point thiP = new Point();
ClientToScreen(hWnd, out thiP);
D2Widht = D2Rect.Width;
D2Height = D2Rect.Height;
ScreenXOffset = thiP.X;
ScreenYOffset = thiP.Y;
CenterX = (D2Widht / 2) + ScreenXOffset;
CenterY = (D2Height / 2) + ScreenYOffset;
if (IsWindowOnSecondaryMonitor(D2Rect))
{
int FirstMonitorScreenX = Screen.PrimaryScreen.Bounds.Width;
int FirstMonitorScreenY = Screen.PrimaryScreen.Bounds.Height;
ScreenX = Screen.AllScreens[1].Bounds.Width;
ScreenY = Screen.AllScreens[1].Bounds.Height;
ScreenXOffset += FirstMonitorScreenX;
ScreenYOffset += FirstMonitorScreenY;
CenterX = (D2Widht / 2) + ScreenXOffset;
CenterY = (D2Height / 2) + ScreenYOffset;
//Console.WriteLine("is on the secondary monitor.");
}
method_1("Screen Specs:", Color.DarkBlue);
method_1("-> Screen size: " + ScreenX + ", " + ScreenY, Color.DarkBlue);
method_1("-> D2R rect Size: " + D2Widht + ", " + D2Height, Color.DarkBlue);
method_1("-> D2R rect offset: " + ScreenXOffset + ", " + ScreenYOffset, Color.DarkBlue);
method_1("-> D2R Center Position: " + CenterX + ", " + CenterY, Color.DarkBlue);
if (IsWindowOnSecondaryMonitor(D2Rect)) method_1("-> **D2R On Secondary Monitor**!", Color.DarkBlue);
double screenRatio = (double)D2Widht / D2Height;
if (Math.Abs(screenRatio - (16.0 / 9.0)) > 0.01)
{
method_1("D2R rect Size ratio is not 16:9!", Color.Red);
}
if (CenterX >= ((ScreenX / 2) + 15)
|| CenterX <= ((ScreenX / 2) - 15)
|| CenterY >= ((ScreenY / 2) + 15)
|| CenterY <= ((ScreenY / 2) - 15))
{
method_1("D2R rect Position is not in the center of screen, might have some issues!", Color.OrangeRed);
}
if (getScalingFactor() != 1f)
{
method_1("Windows scale factor is not 100%, might have some issues!", Color.OrangeRed);
}
if (ScreenX > 1920)
{
method_1("Screen Resolution is bigger than 1920x1080, might have some issues!", Color.OrangeRed);
}
if (D2_LOD_113C_Path.Contains(" "))
{
method_1("The Path to Diablo2 LOD containt a whitespace, make sure the path doesn't containt any spaces in it!", Color.Red);
}
overlayForm.ScaleScreenSize = (float)Form1_0.D2Widht / 1920f;
overlayForm.ScaleScreenSizeInverted = 1920f / (float)Form1_0.D2Widht;
overlayForm.ResetScaleForDisplay();
process = Process.GetProcessesByName("D2R")[0];
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, false, process.Id);
//processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE | SYNCHRONIZE, false, process.Id);
foreach (ProcessModule module in process.Modules)
{
if (module.ModuleName == "D2R.exe")
{