forked from No3Mc/AIO-Mod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyBot.run.au3
1383 lines (1237 loc) · 58.5 KB
/
MyBot.run.au3
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
#NoTrayIcon
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=MyBot.run.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/rsln /MI=3
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; #FUNCTION# ====================================================================================================================
; Name ..........: MBR Bot
; Description ...: This file contains the initialization and main loop sequences f0r the MBR Bot
; Author ........: (2014)
; Modified ......:
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2019
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
; AutoIt pragmas
;#AutoIt3Wrapper_Res_HiDpi=Y ; HiDpi will be set during run-time!
;#AutoIt3Wrapper_Run_AU3Check=n ; enable when running in folder with umlauts!
#include "MyBot.run.version.au3"
#pragma compile(ProductName, My Bot)
#pragma compile(Out, MyBot.run.exe) ; Required
; Enforce variable declarations
Opt("MustDeclareVars", 1)
Global $g_sBotTitle = "" ;~ Don't assign any title here, use Func UpdateBotTitle()
Global $g_hFrmBot = 0 ; The main GUI window
; MBR includes
#include "COCBot\MBR Global Variables.au3"
#include "COCBot\functions\Config\DelayTimes.au3"
#include "COCBot\GUI\MBR GUI Design Splash.au3"
#include "COCBot\functions\Config\ScreenCoordinates.au3"
#include "COCBot\Team__AiO__MOD++\functions\Config\ScreenCoordinates.au3" ; AIO Mod
#include "COCBot\functions\Config\ImageDirectories.au3"
#include "COCBot\Team__AiO__MOD++\functions\Config\ImageDirectories.au3" ; AIO Mod
#include "COCBot\functions\Other\ExtMsgBox.au3"
#include "COCBot\functions\Other\MBRFunc.au3"
#include "COCBot\functions\Other\DissociableFunc.au3"
#include "COCBot\functions\Android\Android.au3"
#include "COCBot\functions\Android\Distributors.au3"
#include "COCBot\MBR GUI Design.au3"
#include "COCBot\MBR GUI Control.au3"
#include "COCBot\MBR Functions.au3"
#include "COCBot\functions\Other\Multilanguage.au3"
; MBR References.au3 must be last include
#include "COCBot\MBR References.au3"
; Autoit Options
Opt("GUIResizeMode", $GUI_DOCKALL) ; Default resize mode for dock android support
Opt("GUIEventOptions", 1) ; Handle minimize and restore for dock android support
Opt("GUICloseOnESC", 0) ; Don't send the $GUI_EVENT_CLOSE message when ESC is pressed.
Opt("WinTitleMatchMode", 3) ; Window Title exact match mode
Opt("GUIOnEventMode", 1)
Opt("MouseClickDelay", GetClickUpDelay()) ;Default: 10 milliseconds
Opt("MouseClickDownDelay", GetClickDownDelay()) ;Default: 5 milliseconds
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)
; All executable code is in a function block, to detect coding errors, such as variable declaration scope problems
InitializeBot()
; Hand over control to main loop
MainLoop(CheckPrerequisites())
Func UpdateBotTitle()
If $g_bDebugFuncCall Then SetLog('@@ (76) :(' & @MIN & ':' & @SEC & ') UpdateBotTitle()' & @CRLF, $COLOR_ACTION) ;### Function Trace
Local $sTitle = "My Bot " & $g_sBotVersion & " - " & "AiO++ MOD " & $g_sModVersion & " -" ; AIO Mod
Local $sConsoleTitle ; Console title has also Android Emulator Name
If $g_sBotTitle = "" Then
$g_sBotTitle = $sTitle
$sConsoleTitle = $sTitle
Else
$g_sBotTitle = $sTitle & " (" & ($g_sAndroidInstance <> "" ? $g_sAndroidInstance : $g_sAndroidEmulator) & ")" ;Do not change this. If you do, multiple instances will not work.
$sConsoleTitle = $sTitle & " " & $g_sAndroidEmulator & " (" & ($g_sAndroidInstance <> "" ? $g_sAndroidInstance : $g_sAndroidEmulator) & ")"
EndIf
If $g_hFrmBot <> 0 Then
; Update Bot Window Title also
WinSetTitle($g_hFrmBot, "", $g_sBotTitle)
GUICtrlSetData($g_hLblBotTitle, $g_sBotTitle)
EndIf
; Update Console Window (if it exists)
DllCall("kernel32.dll", "bool", "SetConsoleTitle", "str", "Console " & $sConsoleTitle)
; Update try icon title
TraySetToolTip($g_sBotTitle)
If $g_bDebugSetlog Then SetDebugLog("Bot title updated to: " & $g_sBotTitle)
EndFunc ;==>UpdateBotTitle
Func InitializeBot()
If $g_bDebugFuncCall Then SetLog('@@ (100) :(' & @MIN & ':' & @SEC & ') InitializeBot()' & @CRLF, $COLOR_ACTION) ;### Function Trace
ProcessCommandLine()
If FileExists(@ScriptDir & "\EnableMBRDebug.txt") Then ; Set developer mode
$g_bDevMode = True
$g_bDOCRDebugImages = True And $g_bDOCRDebugImages
Local $aText = FileReadToArray(@ScriptDir & "\EnableMBRDebug.txt") ; check if special debug flags set inside EnableMBRDebug.txt file
If Not @error Then
For $l = 0 To UBound($aText) - 1
If StringInStr($aText[$l], "DISABLEWATCHDOG", $STR_NOCASESENSEBASIC) <> 0 Then
$g_bBotLaunchOption_NoWatchdog = True
If $g_bDebugSetlog Then SetDebugLog("Watch Dog disabled by Developer Mode File Command", $COLOR_INFO)
EndIf
Next
EndIf
EndIf
SetupProfileFolder() ; Setup profile folders
SetLogCentered(" BOT LOG ") ; Initial text for log
SetSwitchAccLog(_PadStringCenter(" SwitchAcc LOG ", 25, "="), $COLOR_BLACK, "Lucida Console", 8, False)
DetectLanguage()
If $g_iBotLaunchOption_Help Then
ShowCommandLineHelp()
Exit
EndIf
InitAndroidConfig()
; early load of config
Local $bConfigRead = FileExists($g_sProfileConfigPath)
If $bConfigRead Or FileExists($g_sProfileBuildingPath) Then
readConfig()
EndIf
Local $sAndroidInfo = ""
; Disabled process priority tampering as not best practice
;Local $iBotProcessPriority = _ProcessGetPriority(@AutoItPID)
;ProcessSetPriority(@AutoItPID, $PROCESS_BELOWNORMAL) ;~ Boost launch time by increasing process priority (will be restored again when finished launching)
_ITaskBar_Init(False)
_Crypt_Startup()
__GDIPlus_Startup() ; Start GDI+ Engine (incl. a new thread)
TCPStartup() ; Start the TCP service.
;InitAndroidConfig()
CreateMainGUI() ; Just create the main window
CreateSplashScreen() ; Create splash window
; Ensure watchdog is launched (requires Bot Window for messaging)
If Not $g_bBotLaunchOption_NoWatchdog Then LaunchWatchdog()
InitializeMBR($sAndroidInfo, $bConfigRead)
; Create GUI
CreateMainGUIControls() ; Create all GUI Controls
InitializeMainGUI() ; setup GUI Controls
; Files/folders
SetupFilesAndFolders()
; Show main GUI
ShowMainGUI()
If $g_iBotLaunchOption_Dock Then
If AndroidEmbed(True) And $g_iBotLaunchOption_Dock = 2 And $g_bCustomTitleBarActive Then
BotShrinkExpandToggle()
EndIf
EndIf
; Some final setup steps and checks
FinalInitialization($sAndroidInfo)
;ProcessSetPriority(@AutoItPID, $iBotProcessPriority) ;~ Restore process priority
EndFunc ;==>InitializeBot
; #FUNCTION# ====================================================================================================================
; Name ..........: ProcessCommandLine
; Description ...: Handle command line parameters
; Syntax ........:
; Parameters ....: None
; Return values .: None
; Author ........:
; Modified ......: CodeSlinger69 (2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func ProcessCommandLine()
If $g_bDebugFuncCall Then SetLog('@@ (195) :(' & @MIN & ':' & @SEC & ') ProcessCommandLine()' & @CRLF, $COLOR_ACTION) ;### Function Trace
; Handle Command Line Launch Options and fill $g_asCmdLine
If $CmdLine[0] > 0 Then
For $i = 1 To $CmdLine[0]
Local $bOptionDetected = True
Switch $CmdLine[$i]
; terminate bot if it exists (by window title!)
Case "/restart", "/r", "-restart", "-r"
$g_bBotLaunchOption_Restart = True
Case "/autostart", "/a", "-autostart", "-a"
$g_bBotLaunchOption_Autostart = True
Case "/nowatchdog", "/nwd", "-nowatchdog", "-nwd"
$g_bBotLaunchOption_NoWatchdog = True
Case "/dpiaware", "/da", "-dpiaware", "-da"
$g_bBotLaunchOption_ForceDpiAware = True
Case "/dock1", "/d1", "-dock1", "-d1", "/dock", "/d", "-dock", "-d"
$g_iBotLaunchOption_Dock = 1
Case "/dock2", "/d2", "-dock2", "-d2"
$g_iBotLaunchOption_Dock = 2
Case "/nobotslot", "/nbs", "-nobotslot", "-nbs"
$g_bBotLaunchOption_NoBotSlot = True
Case "/debug", "/debugmode", "/dev", "/dm", "-debug", "-debugmode", "-dev", "-dm"
$g_bDevMode = True
$g_bDOCRDebugImages = True And $g_bDOCRDebugImages
Case "/minigui", "/mg", "-minigui", "-mg"
$g_iGuiMode = 2
Case "/nogui", "/ng", "-nogui", "-ng"
$g_iGuiMode = 0
Case "/hideandroid", "/ha", "-hideandroid", "-ha"
$g_bBotLaunchOption_HideAndroid = True
Case "/minimizebot", "/minbot", "/mb", "-minimizebot", "-minbot", "-mb"
$g_bBotLaunchOption_MinimizeBot = True
Case "/console", "/c", "-console", "-c"
$g_iBotLaunchOption_Console = True
ConsoleWindow()
Case "/?", "/h", "/help", "-?", "-h", "-help"
; show command line help and exit
$g_iBotLaunchOption_Help = True
Case Else
If StringInStr($CmdLine[$i], "/guipid=") Then
Local $guidpid = Int(StringMid($CmdLine[$i], 9))
If ProcessExists($guidpid) Then
$g_iGuiPID = $guidpid
Else
If $g_bDebugSetlog Then SetDebugLog("GUI Process doesn't exist: " & $guidpid)
EndIf
ElseIf StringInStr($CmdLine[$i], "/profiles=") = 1 Then
Local $sProfilePath = StringMid($CmdLine[$i], 11)
If StringInStr(FileGetAttrib($sProfilePath), "D") Then
$g_sProfilePath = $sProfilePath
Else
SetLog("Profiles Path doesn't exist: " & $sProfilePath, $COLOR_ERROR) ;
EndIf
Else
$bOptionDetected = False
$g_asCmdLine[0] += 1
ReDim $g_asCmdLine[$g_asCmdLine[0] + 1]
$g_asCmdLine[$g_asCmdLine[0]] = $CmdLine[$i]
EndIf
EndSwitch
If $bOptionDetected Then SetDebugLog("Command Line Option detected: " & $CmdLine[$i])
Next
EndIf
; Handle Command Line Parameters
If $g_asCmdLine[0] > 0 Then
$g_sProfileCurrentName = StringRegExpReplace($g_asCmdLine[1], '[/:*?"<>|]', '_')
If $g_asCmdLine[0] >= 2 Then
If StringInStr($g_asCmdLine[2], "BlueStacks3") Or StringInStr($g_asCmdLine[2], "BlueStacks4") Then
; BlueStacks v3 and v4 use same key as v2
$g_asCmdLine[2] = "BlueStacks2"
EndIf
EndIf
ElseIf FileExists($g_sProfilePath & "\profile.ini") Then
$g_sProfileCurrentName = StringRegExpReplace(IniRead($g_sProfilePath & "\profile.ini", "general", "defaultprofile", ""), '[/:*?"<>|]', '_')
If $g_sProfileCurrentName = "" Or Not FileExists($g_sProfilePath & "\" & $g_sProfileCurrentName) Then $g_sProfileCurrentName = "<No Profiles>"
Else
$g_sProfileCurrentName = "<No Profiles>"
EndIf
EndFunc ;==>ProcessCommandLine
; #FUNCTION# ====================================================================================================================
; Name ..........: InitializeAndroid
; Description ...: Initialize Android
; Syntax ........:
; Parameters ....: $bConfigRead - if config was already read and Android Emulator info loaded
; Return values .: None
; Author ........:
; Modified ......: cosote (Feb-2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func InitializeAndroid($bConfigRead)
If $g_bDebugFuncCall Then SetLog('@@ (292) :(' & @MIN & ':' & @SEC & ') InitializeAndroid()' & @CRLF, $COLOR_ACTION) ;### Function Trace
Local $s = GetTranslatedFileIni("MBR GUI Design - Loading", "StatusBar_Item_06", "Initializing Android...")
SplashStep($s)
If $g_bBotLaunchOption_Restart = False Then
; Change Android type and update variable
If $g_asCmdLine[0] > 1 Then
; initialize Android config
InitAndroidConfig(True)
Local $i
For $i = 0 To UBound($g_avAndroidAppConfig) - 1
If StringCompare($g_avAndroidAppConfig[$i][0], $g_asCmdLine[2]) = 0 Then
$g_iAndroidConfig = $i
SplashStep($s & "(" & $g_avAndroidAppConfig[$i][0] & ")...", False)
If $g_avAndroidAppConfig[$i][1] <> "" And $g_asCmdLine[0] > 2 Then
; Use Instance Name
UpdateAndroidConfig($g_asCmdLine[3])
Else
UpdateAndroidConfig()
EndIf
SplashStep($s & "(" & $g_avAndroidAppConfig[$i][0] & ")", False)
ExitLoop
EndIf
Next
EndIf
SplashStep(GetTranslatedFileIni("MBR GUI Design - Loading", "StatusBar_Item_07", "Detecting Android..."))
If $g_asCmdLine[0] < 2 And Not $bConfigRead Then
DetectRunningAndroid()
If Not $g_bFoundRunningAndroid Then DetectInstalledAndroid()
EndIf
Else
; just increase step
SplashStep($s)
EndIf
CleanSecureFiles()
GetCOCDistributors() ; load of distributors to prevent rare bot freeze during boot
EndFunc ;==>InitializeAndroid
; #FUNCTION# ====================================================================================================================
; Name ..........: SetupProfileFolder
; Description ...: Populate profile-related globals
; Syntax ........:
; Parameters ....: None
; Return values .: None
; Author ........:
; Modified ......: CodeSlinger69 (2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func SetupProfileFolder()
If $g_bDebugFuncCall Then SetLog('@@ (354) :(' & @MIN & ':' & @SEC & ') SetupProfileFolder()' & @CRLF, $COLOR_ACTION) ;### Function Trace
If $g_bDebugSetlog Then SetDebugLog("SetupProfileFolder: " & $g_sProfilePath & "\" & $g_sProfileCurrentName)
$g_sProfileConfigPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\config.ini"
$g_sProfileBuildingStatsPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\stats_buildings.ini"
$g_sProfileBuildingPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\building.ini"
$g_sProfileLogsPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Logs\"
$g_sProfileLootsPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Loots\"
$g_sProfileTempPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Temp\"
$g_sProfileTempDebugPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Temp\Debug\"
$g_sProfileDonateCapturePath = $g_sProfilePath & "\" & $g_sProfileCurrentName & '\Donate\'
$g_sProfileDonateCaptureWhitelistPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & '\Donate\White List\'
$g_sProfileDonateCaptureBlacklistPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & '\Donate\Black List\'
$g_sProfileTempDebugDOCRPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Temp\Debug\DOCR\"
EndFunc ;==>SetupProfileFolder
; #FUNCTION# ====================================================================================================================
; Name ..........: InitializeMBR
; Description ...: MBR setup routine
; Syntax ........:
; Parameters ....: $sAI - populated with AndroidInfo string in this function
; $bConfigRead - if config was already read and Android Emulator info loaded
; Return values .: None
; Author ........:
; Modified ......: CodeSlinger69 (2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func InitializeMBR(ByRef $sAI, $bConfigRead)
If $g_bDebugFuncCall Then SetLog('@@ (385) :(' & @MIN & ':' & @SEC & ') InitializeMBR()' & @CRLF, $COLOR_ACTION) ;### Function Trace
; license
If Not FileExists(@ScriptDir & "\License.txt") Then
Local $hDownload = InetGet("http://www.gnu.org/licenses/gpl-3.0.txt", @ScriptDir & "\License.txt")
; Wait for the download to complete by monitoring when the 2nd index value of InetGetInfo returns True.
Local $i = 0
Do
Sleep($DELAYDOWNLOADLICENSE)
$i += 1
Until InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE) Or $i > 25
InetClose($hDownload)
EndIf
; multilanguage
If Not FileExists(@ScriptDir & "\Languages") Then DirCreate(@ScriptDir & "\Languages")
;DetectLanguage()
_ReadFullIni()
; must be called after language is detected
TranslateTroopNames()
InitializeCOCDistributors()
; check for compiled x64 version
Local $sMsg = GetTranslatedFileIni("MBR GUI Design - Loading", "Compile_Script", "Don't Run/Compile the Script as (x64)! Try to Run/Compile the Script as (x86) to get the bot to work.\r\n" & _
"If this message still appears, try to re-install AutoIt.")
If @AutoItX64 = 1 Then
DestroySplashScreen()
MsgBox(0, "", $sMsg)
__GDIPlus_Shutdown()
Exit
EndIf
; Initialize Android emulator
InitializeAndroid($bConfigRead)
; Update Bot title
UpdateBotTitle()
UpdateSplashTitle($g_sBotTitle & GetTranslatedFileIni("MBR GUI Design - Loading", "Loading_Profile", ", Profile: %s", $g_sProfileCurrentName))
If $g_bBotLaunchOption_Restart = True Then
If CloseRunningBot($g_sBotTitle, True) Then
SplashStep(GetTranslatedFileIni("MBR GUI Design - Loading", "Closing_previous", "Closing previous bot..."), False)
If CloseRunningBot($g_sBotTitle) = True Then
; wait for Mutexes to get disposed
Sleep(3000)
; check if Android is running
WinGetAndroidHandle()
EndIf
EndIf
EndIf
Local $cmdLineHelp = GetTranslatedFileIni("MBR GUI Design - Loading", "Commandline_multiple_Bots", "By using the commandline (or a shortcut) you can start multiple Bots:\r\n" & _
" MyBot.run.exe [ProfileName] [EmulatorName] [InstanceName]\r\n\r\n" & _
"With the first command line parameter, specify the Profilename (you can create profiles on the Bot/Profiles tab, if a " & _
"profilename contains a {space}, then enclose the profilename in double quotes). " & _
"With the second, specify the name of the Emulator and with the third, an Android Instance (not for BlueStacks). \r\n" & _
"Supported Emulators are MEmu, Droid4X, Nox, BlueStacks2, BlueStacks, KOPlayer and LeapDroid.\r\n\r\n" & _
"Examples:\r\n" & _
" MyBot.run.exe MyVillage BlueStacks2\r\n" & _
" MyBot.run.exe ""My Second Village"" MEmu MEmu_1")
$g_hMutex_BotTitle = CreateMutex($g_sBotTitle)
$sAI = GetTranslatedFileIni("MBR GUI Design - Loading", "Android_instance_01", "%s", $g_sAndroidEmulator)
Local $sAndroidInfo2 = GetTranslatedFileIni("MBR GUI Design - Loading", "Android_instance_02", "%s (instance %s)", $g_sAndroidEmulator, $g_sAndroidInstance)
If $g_sAndroidInstance <> "" Then
$sAI = $sAndroidInfo2
EndIf
; Check if we are already running for this instance
$sMsg = GetTranslatedFileIni("MBR GUI Design - Loading", "Msg_Android_instance_01", "My Bot for %s is already running.\r\n\r\n", $sAI)
If $g_hMutex_BotTitle = 0 Then
If $g_bDebugSetlog Then SetDebugLog($g_sBotTitle & " is already running, exit now")
DestroySplashScreen()
MsgBox(BitOR($MB_OK, $MB_ICONINFORMATION, $MB_TOPMOST), $g_sBotTitle, $sMsg & $cmdLineHelp)
__GDIPlus_Shutdown()
Exit
EndIf
$sMsg = GetTranslatedFileIni("MBR GUI Design - Loading", "Msg_Android_instance_02", "My Bot with Profile %s is already in use.\r\n\r\n", $g_sProfileCurrentName)
; Check if we are already running for this profile
If aquireProfileMutex() = 0 Then
ReleaseMutex($g_hMutex_BotTitle)
releaseProfilesMutex(True)
DestroySplashScreen()
MsgBox(BitOR($MB_OK, $MB_ICONINFORMATION, $MB_TOPMOST), $g_sBotTitle, $sMsg & $cmdLineHelp)
__GDIPlus_Shutdown()
Exit
EndIf
; Get mutex
$g_hMutex_MyBot = CreateMutex("MyBot.run")
$g_bOnlyInstance = $g_hMutex_MyBot <> 0 ; And False
If $g_bDebugSetlog Then SetDebugLog("My Bot is " & ($g_bOnlyInstance ? "" : "not ") & "the only running instance")
EndFunc ;==>InitializeMBR
; #FUNCTION# ====================================================================================================================
; Name ..........: SetupFilesAndFolders
; Description ...: Checks for presence of needed files and folders, cleans up and creates as required
; Syntax ........:
; Parameters ....: None
; Return values .: None
; Author ........:
; Modified ......: CodeSlinger69 (2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func SetupFilesAndFolders()
If $g_bDebugFuncCall Then SetLog('@@ (498) :(' & @MIN & ':' & @SEC & ') SetupFilesAndFolders()' & @CRLF, $COLOR_ACTION) ;### Function Trace
;Migrate old shared_prefs locations
Local $sOldProfiles = @MyDocumentsDir & "\MyBot.run-Profiles"
If FileExists($sOldProfiles) = 1 And FileExists($g_sPrivateProfilePath) = 0 Then
SetLog("Moving shared_prefs profiles folder")
If DirMove($sOldProfiles, $g_sPrivateProfilePath) = 0 Then
SetLog("Error moving folder " & $sOldProfiles, $COLOR_ERROR)
SetLog("to new location " & $g_sPrivateProfilePath, $COLOR_ERROR)
SetLog("Please resolve manually!", $COLOR_ERROR)
Else
SetLog("Moved shared_prefs profiles to " & $g_sPrivateProfilePath, $COLOR_SUCCESS)
EndIf
EndIf
;DirCreate($sTemplates)
DirCreate($g_sProfilePresetPath)
DirCreate($g_sPrivateProfilePath & "\" & $g_sProfileCurrentName)
DirCreate($g_sProfilePath & "\" & $g_sProfileCurrentName)
DirCreate($g_sProfileLogsPath)
DirCreate($g_sProfileLootsPath)
DirCreate($g_sProfileTempPath)
DirCreate($g_sProfileTempDebugPath)
DirCreate($g_sProfileTempDebugDOCRPath)
$g_sProfileDonateCapturePath = $g_sProfilePath & "\" & $g_sProfileCurrentName & '\Donate\'
$g_sProfileDonateCaptureWhitelistPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & '\Donate\White List\'
$g_sProfileDonateCaptureBlacklistPath = $g_sProfilePath & "\" & $g_sProfileCurrentName & '\Donate\Black List\'
DirCreate($g_sProfileDonateCapturePath)
DirCreate($g_sProfileDonateCaptureWhitelistPath)
DirCreate($g_sProfileDonateCaptureBlacklistPath)
;Migrate old bot without profile support to current one
FileMove(@ScriptDir & "\*.ini", $g_sProfilePath & "\" & $g_sProfileCurrentName, $FC_OVERWRITE + $FC_CREATEPATH)
DirCopy(@ScriptDir & "\Logs", $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Logs", $FC_OVERWRITE + $FC_CREATEPATH)
DirCopy(@ScriptDir & "\Loots", $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Loots", $FC_OVERWRITE + $FC_CREATEPATH)
DirCopy(@ScriptDir & "\Temp", $g_sProfilePath & "\" & $g_sProfileCurrentName & "\Temp", $FC_OVERWRITE + $FC_CREATEPATH)
DirRemove(@ScriptDir & "\Logs", 1)
DirRemove(@ScriptDir & "\Loots", 1)
DirRemove(@ScriptDir & "\Temp", 1)
;Setup profile if doesn't exist yet
If FileExists($g_sProfileConfigPath) = 0 Then
createProfile(True)
applyConfig()
EndIf
If $g_bDeleteLogs Then DeleteFiles($g_sProfileLogsPath, "*.*", $g_iDeleteLogsDays, 0)
If $g_bDeleteLoots Then DeleteFiles($g_sProfileLootsPath, "*.*", $g_iDeleteLootsDays, 0)
If $g_bDeleteTemp Then
DeleteFiles($g_sProfileTempPath, "*.*", $g_iDeleteTempDays, 0)
DeleteFiles($g_sProfileTempDebugPath, "*.*", $g_iDeleteTempDays, 0, $FLTAR_RECUR)
EndIf
If $g_bDebugSetlog Then SetDebugLog("$g_sProfilePath = " & $g_sProfilePath)
If $g_bDebugSetlog Then SetDebugLog("$g_sProfileCurrentName = " & $g_sProfileCurrentName)
If $g_bDebugSetlog Then SetDebugLog("$g_sProfileLogsPath = " & $g_sProfileLogsPath)
EndFunc ;==>SetupFilesAndFolders
; #FUNCTION# ====================================================================================================================
; Name ..........: FinalInitialization
; Description ...: Finalize various setup requirements
; Syntax ........:
; Parameters ....: $sAI: AndroidInfo for displaying in the log
; Return values .: None
; Author ........:
; Modified ......: CodeSlinger69 (2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func FinalInitialization(Const $sAI)
If $g_bDebugFuncCall Then SetLog('@@ (573) :(' & @MIN & ':' & @SEC & ') FinalInitialization()' & @CRLF, $COLOR_ACTION) ;### Function Trace
; check for VC2010, .NET software and MyBot Files and Folders
Local $bCheckPrerequisitesOK = CheckPrerequisites(True)
If $bCheckPrerequisitesOK Then
MBRFunc(True) ; start MyBot.run.dll, after this point .net is initialized and threads popup all the time
DissociableFunc(True)
setAndroidPID() ; set Android PID
SetBotGuiPID() ; set GUI PID
EndIf
If $g_bFoundRunningAndroid Then
SetLog(GetTranslatedFileIni("MBR GUI Design - Loading", "Msg_Android_instance_03", "Found running %s %s", $g_sAndroidEmulator, $g_sAndroidVersion), $COLOR_SUCCESS)
EndIf
If $g_bFoundInstalledAndroid Then
SetLog("Found installed " & $g_sAndroidEmulator & " " & $g_sAndroidVersion, $COLOR_SUCCESS)
EndIf
SetLog(GetTranslatedFileIni("MBR GUI Design - Loading", "Msg_Android_instance_04", "Android Emulator Configuration: %s", $sAI), $COLOR_SUCCESS)
; reset GUI to wait for remote GUI in no GUI mode
$g_iGuiPID = @AutoItPID
; Remember time in Milliseconds bot launched
$g_iBotLaunchTime = __TimerDiff($g_hBotLaunchTime)
; wait for remote GUI to show when no GUI in this process
If $g_iGuiMode = 0 Then
SplashStep(GetTranslatedFileIni("MBR GUI Design - Loading", "Waiting_for_Remote_GUI", "Waiting for remote GUI..."))
If $g_bDebugSetlog Then SetDebugLog("Wait for GUI Process...")
Local $timer = __TimerInit()
While $g_iGuiPID = @AutoItPID And __TimerDiff($timer) < 60000
; wait for GUI Process updating $g_iGuiPID
Sleep(50) ; must be Sleep as no run state!
WEnd
If $g_iGuiPID = @AutoItPID Then
If $g_bDebugSetlog Then SetDebugLog("GUI Process not received, close bot")
BotClose()
$bCheckPrerequisitesOK = False
Else
If $g_bDebugSetlog Then SetDebugLog("Linked to GUI Process " & $g_iGuiPID)
EndIf
EndIf
Local $aBotGitVersion = CheckModVersion(True) ; Update check without delay - Team AIO Mod++ - Must be Before Official CheckVersion()
; destroy splash screen here (so we witness the 100% ;)
DestroySplashScreen(False)
If $bCheckPrerequisitesOK Then
; only when bot can run, register with forum
ForumAuthentication()
EndIf
; allow now other bots to launch
DestroySplashScreen()
#Region - Update check without delay - Team AIO Mod++
If IsArray($aBotGitVersion) And UBound($aBotGitVersion) = 2 Then
SetLog(" ")
SetLog(" • " & "AIO++ MOD " & $g_sModVersion, ($aBotGitVersion[1] = False) ? ($COLOR_SUCCESS) : ($COLOR_ERROR))
SetLog(" • " & "AIO++ MOD LAST VERSION " & $aBotGitVersion[0], ($aBotGitVersion[1] = False) ? ($COLOR_SUCCESS) : ($COLOR_ERROR))
SetLog(" • " & "Based On MBR " & $g_sBotVersion, $COLOR_SUCCESS)
SetLog(" • " & "Create a New Profile", $COLOR_SUCCESS)
SetLog(" • " & "AIO++ Gang : @vDragon, @Eloy, @Approchable-123, @Boldina, @Dissociable.", $COLOR_SUCCESS)
SetLog(" • " & "Thanks: Nguyen, Chilly-Chill, Demen,", $COLOR_SUCCESS)
SetLog(" • " & "Samkie, and ChacalGyn, all moders and MyBot/AIO++ Team.", $COLOR_SUCCESS)
SetLog(" ")
EndIf
#EndRegion - Update check without delay - Team AIO Mod++
; InitializeVariables();initialize variables used in extrawindows
CheckVersion() ; check latest version on mybot.run site
UpdateMultiStats()
If $g_bDebugSetlog Then SetDebugLog("Maximum of " & $g_iGlobalActiveBotsAllowed & " bots running at same time configured")
If $g_bDebugSetlog Then SetDebugLog("MyBot.run launch time " & Round($g_iBotLaunchTime) & " ms.")
If $g_bAndroidShieldEnabled = False Then
SetLog(GetTranslatedFileIni("MBR GUI Design - Loading", "Msg_Android_instance_05", "Android Shield not available for %s", @OSVersion), $COLOR_ACTION)
EndIf
DisableProcessWindowsGhosting()
UpdateMainGUI()
EndFunc ;==>FinalInitialization
; #FUNCTION# ====================================================================================================================
; Name ..........: MainLoop
; Description ...: Main application loop
; Syntax ........:
; Parameters ....: None
; Return values .: None
; Author ........:
; Modified ......: CodeSlinger69 (2017)
; Remarks .......: This file is part of MyBot, previously known as ClashGameBot. Copyright 2015-2017
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
Func MainLoop($bCheckPrerequisitesOK = True)
If $g_bDebugFuncCall Then SetLog('@@ (674) :(' & @MIN & ':' & @SEC & ') MainLoop()' & @CRLF, $COLOR_ACTION) ;### Function Trace
Local $iStartDelay = 0
If $bCheckPrerequisitesOK And ($g_bAutoStart Or $g_bRestarted) Then
Local $iDelay = $g_iAutoStartDelay
If $g_bRestarted Then $iDelay = 0
$iStartDelay = $iDelay * 1000
$g_iBotAction = $eBotStart
; check if android should be hidden
If $g_bBotLaunchOption_HideAndroid Then $g_bIsHidden = True
; check if bot should be minimized
If $g_bBotLaunchOption_MinimizeBot Then BotMinimizeRequest()
EndIf
Local $hStarttime = _Timer_Init()
; Check the Supported Emulator versions
CheckEmuNewVersions()
;Reset Telegram message
NotifyGetLastMessageFromTelegram()
$g_iTGLastRemote = $g_sTGLast_UID
While 1
_Sleep($DELAYSLEEP, True, False)
Local $diffhStarttime = _Timer_Diff($hStarttime)
If Not $g_bRunState And $g_bNotifyTGEnable And $g_bNotifyRemoteEnable And $diffhStarttime > 1000 * 15 Then ; 15seconds
$hStarttime = _Timer_Init()
NotifyRemoteControlProcBtnStart()
EndIf
Switch $g_iBotAction
Case $eBotStart
BotStart($iStartDelay)
$iStartDelay = 0 ; don't autostart delay in future
If $g_iBotAction = $eBotStart Then $g_iBotAction = $eBotNoAction
; test error handling when bot started and then stopped
; force app crash for debugging/testing purposes
;DllCallAddress("NONE", 0)
; force au3 script error for debugging/testing purposes
;Local $iTmp = $iStartDelay[0]
Case $eBotStop
BotStop()
If $g_iBotAction = $eBotStop Then $g_iBotAction = $eBotNoAction
; Reset Telegram message
$g_iTGLastRemote = $g_sTGLast_UID
Case $eBotSearchMode
BotSearchMode()
If $g_iBotAction = $eBotSearchMode Then $g_iBotAction = $eBotNoAction
Case $eBotClose
BotClose()
EndSwitch
WEnd
EndFunc ;==>MainLoop
Func runBot() ;Bot that runs everything in order
If $g_bDebugFuncCall Then SetLog('@@ (734) :(' & @MIN & ':' & @SEC & ') runBot()' & @CRLF, $COLOR_ACTION) ;### Function Trace
Local $iWaitTime
InitiateSwitchAcc()
If ProfileSwitchAccountEnabled() And $g_bReMatchAcc Then
SetLog("Rematching Account [" & $g_iNextAccount + 1 & "] with Profile [" & GUICtrlRead($g_ahCmbProfile[$g_iNextAccount]) & "]")
SwitchCoCAcc($g_iNextAccount)
EndIf
FirstCheck()
While 1
;Restart bot after these seconds
If $b_iAutoRestartDelay > 0 And __TimerDiff($g_hBotLaunchTime) > $b_iAutoRestartDelay * 1000 Then
If RestartBot(False) Then Return
EndIf
PrepareDonateCC()
If Not $g_bRunState Then Return
$g_bRestart = False
$g_bFullArmy = False
$g_bIsFullArmywithHeroesAndSpells = False
$g_iCommandStop = -1
If _Sleep($DELAYRUNBOT1) Then Return
checkMainScreen()
If $g_bRestart Then ContinueLoop
chkShieldStatus()
If Not $g_bRunState Then Return
If $g_bRestart Then ContinueLoop
#Region - GTFO - Team AIO Mod++
If $g_bChkOnlyFarm = False Then
MainGTFO()
MainKickout()
EndIf
#EndRegion - GTFO - Team AIO Mod++
checkObstacles() ; trap common error messages also check for reconnecting animation
If $g_bRestart Then ContinueLoop
If CheckAndroidReboot() Then ContinueLoop
If Not $g_bIsClientSyncError And Not $g_bIsSearchLimit Then
checkMainScreen(False)
If $g_bRestart Then ContinueLoop
If RandomSleep($DELAYRUNBOT3) Then Return
VillageReport()
CheckStopForWar() ; War Preparation - Team AIO Mod++
ProfileSwitch() ; Team AIO Mod++
CheckFarmSchedule() ; Team AIO Mod++
If _Sleep($DELAYRUNBOT2) Then Return
If BotCommand() Then btnStop()
If Not $g_bRunState Then Return
If $g_bOutOfGold And (Number($g_aiCurrentLoot[$eLootGold]) >= Number($g_iTxtRestartGold)) Then ; check if enough gold to begin searching again
$g_bOutOfGold = False ; reset out of gold flag
SetLog("Switching back to normal after no gold to search ...", $COLOR_SUCCESS)
ContinueLoop ; Restart bot loop to reset $g_iCommandStop & $g_bTrainEnabled + $g_bDonationEnabled via BotCommand()
EndIf
If $g_bOutOfElixir And (Number($g_aiCurrentLoot[$eLootElixir]) >= Number($g_iTxtRestartElixir)) And (Number($g_aiCurrentLoot[$eLootDarkElixir]) >= Number($g_iTxtRestartDark)) Then ; check if enough elixir to begin searching again
$g_bOutOfElixir = False ; reset out of elixir flag
SetLog("Switching back to normal setting after no elixir to train ...", $COLOR_SUCCESS)
ContinueLoop ; Restart bot loop to reset $g_iCommandStop & $g_bTrainEnabled + $g_bDonationEnabled via BotCommand()
EndIf
If _Sleep($DELAYRUNBOT5) Then Return
checkMainScreen(False)
If $g_bRestart Then ContinueLoop
#Region - Request form chat / on a loop - Team AIO Mod++
If $g_bChkReqCCAlways Then
$g_bCanRequestCC = True
RequestCC()
If _Sleep($DELAYRUNBOT1) = False Then checkMainScreen(False)
EndIf
#EndRegion - Request form chat / on a loop - Team AIO Mod++
#Region - Only farm - Team AIO Mod++
If Not $g_bChkOnlyFarm Then
Local $aRndFuncList = ['LabCheck', 'Collect', 'CheckTombs', 'CleanYard', 'CollectFreeMagicItems', 'DailyChallenge', 'BoostSuperTroop'] ; AIO Mod
Else
Local $aRndFuncList = ['Collect', 'CollectFreeMagicItems', 'DailyChallenge', 'BoostSuperTroop'] ; AIO Mod
EndIf
#EndRegion - Only farm - Team AIO Mod++
_ArrayShuffle($aRndFuncList)
For $Index In $aRndFuncList
If Not $g_bRunState Then Return
_RunFunction($Index)
If $g_bRestart Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
Next
If Not $g_bChkOnlyFarm Then AddIdleTime() ; AIO Mod
If Not $g_bRunState Then Return
If $g_bRestart Then ContinueLoop
If IsSearchAttackEnabled() Then ; if attack is disabled skip reporting, requesting, donating, training, and boosting
#Region - Only farm - Team AIO Mod++
If Not $g_bChkOnlyFarm Then
Local $aRndFuncList = ['ReplayShare', 'NotifyReport', 'DonateCC,Train', 'RequestCC']
Else
Local $aRndFuncList = ['NotifyReport', 'DonateCC,Train', 'RequestCC']
EndIf
#EndRegion - Only farm - Team AIO Mod++
_ArrayShuffle($aRndFuncList)
For $Index In $aRndFuncList
If Not $g_bRunState Then Return
_RunFunction($Index)
If $g_bRestart Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If CheckAndroidReboot() Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
Next
BoostEverything() ; 1st Check if is to use Training Potion
If $g_bRestart Then ContinueLoop
#Region - Only farm - Team AIO Mod++
Local $aRndFuncList = ['BoostBarracks', 'BoostSpellFactory', 'BoostWorkshop', 'BoostKing', 'BoostQueen', 'BoostWarden', 'BoostChampion']
#EndRegion - Only farm - Team AIO Mod++
_ArrayShuffle($aRndFuncList)
For $Index In $aRndFuncList
If Not $g_bRunState Then Return
_RunFunction($Index)
If $g_bRestart Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If CheckAndroidReboot() Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
Next
If Not $g_bRunState Then Return
If $g_iUnbrkMode >= 1 Then
If Unbreakable() Then ContinueLoop
MainSXHandler() ; SuperXP / GoblinXP - Team AiO MOD++
EndIf
If $g_bRestart Then ContinueLoop
EndIf
; Train Donate only - force a donate cc everytime
If ($g_iCommandStop = 3 Or $g_iCommandStop = 0) Then _RunFunction('DonateCC,Train')
If $g_bRestart Then ContinueLoop
If $g_bChkOnlyFarm = False Then MainSXHandler() ; Super XP - Team AIO Mod++
#Region - Only farm - Team AIO Mod++
If Not $g_bChkOnlyFarm Then
Local $aRndFuncList = ['Laboratory', 'UpgradeHeroes', 'UpgradeBuilding']
Else
Local $aRndFuncList[0]
; Don't eat glass.
If $g_bUpgradeKingEnable Or $g_bUpgradeQueenEnable Or $g_bUpgradeWardenEnable Or $g_bUpgradeChampionEnable Then _ArrayAdd($aRndFuncList, 'UpgradeHeroes')
; 667, 27, F5DD71 ; Full gold. 668, 77, E292E2 ; Full elixir.
If _ColorCheck(_GetPixelColor(667, 27, True), Hex(0xF5DD71, 6), 25) Or _ColorCheck(_GetPixelColor(668, 77, True), Hex(0xE292E2, 6), 25) Then _ArrayAdd($aRndFuncList, 'UpgradeBuilding')
; 668, 77, E292E2 ; Full elixir.
If $g_bAutoLabUpgradeEnable And _ColorCheck(_GetPixelColor(668, 77, True), Hex(0xE292E2, 6), 25) Then _ArrayAdd($aRndFuncList, 'Laboratory')
EndIf
#EndRegion - Only farm - Team AIO Mod++
_ArrayShuffle($aRndFuncList)
For $Index In $aRndFuncList
If Not $g_bRunState Then Return
_RunFunction($Index)
If $g_bRestart Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If CheckAndroidReboot() Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
Next
; Ensure, that wall upgrade is last of the upgrades
#Region - Only farm - Team AIO Mod++
Local $aRndFuncList[0]
If Not $g_bChkOnlyFarm Then _ArrayAdd($aRndFuncList, 'BuilderBase')
If $g_bAutoUpgradeWallsEnable = True Then
; 667, 27, F5DD71 ; Full gold. Or 668, 77, E292E2 ; Full elixir.
If Not $g_bChkOnlyFarm Or (_ColorCheck(_GetPixelColor(667, 27, True), Hex(0xF5DD71, 6), 25) Or _ColorCheck(_GetPixelColor(668, 77, True), Hex(0xE292E2, 6), 25)) Then _ArrayAdd($aRndFuncList, 'UpgradeWall')
EndIf
#EndRegion - Only farm - Team AIO Mod++
_ArrayShuffle($aRndFuncList)
For $Index In $aRndFuncList
If Not $g_bRunState Then Return
_RunFunction($Index)
If $g_bRestart Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If CheckAndroidReboot() Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
Next
If Not $g_bRunState Then Return
If $g_bFirstStart Then SetDebugLog("First loop completed!")
$g_bFirstStart = False ; already finished first loop since bot started.
If Not $g_bChkOnlyFarm Then ChatActions() ; ChatActions - Team AiO MOD++
If ProfileSwitchAccountEnabled() And ($g_iCommandStop = 0 Or $g_iCommandStop = 3 Or $g_abDonateOnly[$g_iCurAccount] Or $g_bForceSwitch) Then checkSwitchAcc()
If IsSearchAttackEnabled() Then ; If attack scheduled has attack disabled now, stop wall upgrades, and attack.
Idle()
;$g_bFullArmy1 = $g_bFullArmy
If RandomSleep($DELAYRUNBOT3) Then Return
If $g_bRestart = True Then ContinueLoop
If $g_iCommandStop <> 0 And $g_iCommandStop <> 3 Then
AttackMain()
$g_bSkipFirstZoomout = False
If $g_bOutOfGold Then
SetLog("Switching to Halt Attack, Stay Online/Collect mode ...", $COLOR_ERROR)
ContinueLoop
EndIf
If _Sleep($DELAYRUNBOT1) Then Return
If $g_bRestart = True Then ContinueLoop
EndIf
Else
If ProfileSwitchAccountEnabled() Then
$g_iCommandStop = 2
_RunFunction('DonateCC,Train')
checkSwitchAcc()
EndIf
$iWaitTime = Random($DELAYWAITATTACK1, $DELAYWAITATTACK2)
SetLog("Attacking Not Planned and Skipped, Waiting random " & StringFormat("%0.1f", $iWaitTime / 1000) & " Seconds", $COLOR_WARNING)
If _SleepStatus($iWaitTime) Then Return False
EndIf
Else ;When error occours directly goes to attack
Local $sRestartText = $g_bIsSearchLimit ? " due search limit" : " after Out of Sync Error: Attack Now"
SetLog("Restarted" & $sRestartText, $COLOR_INFO)
If RandomSleep($DELAYRUNBOT3) Then Return
; OCR read current Village Trophies when OOS restart maybe due PB or else DropTrophy skips one attack cycle after OOS
$g_aiCurrentLoot[$eLootTrophy] = Number(getTrophyMainScreen($aTrophies[0], $aTrophies[1]))
If $g_bDebugSetlog Then SetDebugLog("Runbot Trophy Count: " & $g_aiCurrentLoot[$eLootTrophy], $COLOR_DEBUG)
AttackMain()
If Not $g_bRunState Then Return
$g_bSkipFirstZoomout = False
If $g_bOutOfGold Then
SetLog("Switching to Halt Attack, Stay Online/Collect mode ...", $COLOR_ERROR)
$g_bIsClientSyncError = False ; reset fast restart flag to stop OOS mode and start collecting resources
ContinueLoop
EndIf
If _Sleep($DELAYRUNBOT5) Then Return
If $g_bRestart = True Then ContinueLoop
EndIf
WEnd
EndFunc ;==>runBot
Func Idle() ;Sequence that runs until Full Army
If $g_bDebugFuncCall Then SetLog('@@ (922) :(' & @MIN & ':' & @SEC & ') Idle()' & @CRLF, $COLOR_ACTION) ;### Function Trace
$g_bIdleState = True
Local $Result = _Idle()
$g_bIdleState = False
Return $Result
EndFunc ;==>Idle
Func _Idle() ;Sequence that runs until Full Army
If $g_bDebugFuncCall Then SetLog('@@ (930) :(' & @MIN & ':' & @SEC & ') _Idle()' & @CRLF, $COLOR_ACTION) ;### Function Trace
Local $TimeIdle = 0 ;In Seconds
If $g_bDebugSetlog Then SetDebugLog("Func Idle ", $COLOR_DEBUG)
While $g_bIsFullArmywithHeroesAndSpells = False
CheckAndroidReboot()
;Execute Notify Pending Actions
NotifyPendingActions()
If _Sleep($DELAYIDLE1) Then Return
If $g_iCommandStop = -1 Then SetLog("====== Waiting for full army ======", $COLOR_SUCCESS)
If Not $g_bChkOnlyFarm Then ChatActions() ; ChatActions - Team AiO MOD++
Local $hTimer = __TimerInit()
If Not $g_bChkOnlyFarm Then BotHumanization() ; Humanization - Team AiO MOD++
If _Sleep($DELAYIDLE1) Then ExitLoop
checkObstacles() ; trap common error messages also check for reconnecting animation
checkMainScreen(False) ; required here due to many possible exits
If ($g_iCommandStop = 3 Or $g_iCommandStop = 0) And $g_bTrainEnabled = True Then
CheckArmyCamp(True, True)
If _Sleep($DELAYIDLE1) Then Return
If ($g_bIsFullArmywithHeroesAndSpells = False) Then
SetLog("Army Camp is not full, Training Continues...", $COLOR_ACTION)
$g_iCommandStop = 0
EndIf
EndIf
If $g_bRestart Then ExitLoop
If Random(0, $g_iCollectAtCount - 1, 1) = 0 Then ; This is prevent from collecting all the time which isn't needed anyway, chance to run is 1/$g_iCollectAtCount
Local $aRndFuncList = ['Collect', 'CheckTombs', 'RequestCC', 'DonateCC', 'CleanYard']
_ArrayShuffle($aRndFuncList)
For $Index In $aRndFuncList
If Not $g_bRunState Then Return