-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyBot.run.au3
1431 lines (1280 loc) · 58.3 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
; #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-2018
; MyBot is distributed under the terms of the GNU GPL
; Related .......:
; Link ..........: https://github.com/MyBotRun/MyBot/wiki
; Example .......: No
; ===============================================================================================================================
; AutoIt pragmas
#NoTrayIcon
#RequireAdmin
#AutoIt3Wrapper_UseX64=7n
;#AutoIt3Wrapper_Res_HiDpi=Y ; HiDpi will be set during run-time!
;#AutoIt3Wrapper_Run_AU3Check=n ; enable when running in folder with umlauts!
#AutoIt3Wrapper_Run_Au3Stripper=y ;Start the Stripping process below this line.
#Au3Stripper_Parameters=/rsln /MI=3
;#Au3Stripper_Parameters=/MO ;Marge Only in case of fast testing of error make strip file in a sec. NOTE : Please uncomment when making production strip file
;/SV=0
;#AutoIt3Wrapper_Change2CUI=y
;#pragma compile(Console, true)
#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
Global $g_sModversion = "0.0.2"
; 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\functions\Config\ImageDirectories.au3"
#include "COCBot\functions\Other\ExtMsgBox.au3"
#include "COCBot\functions\Other\MBRFunc.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", 10)
Opt("MouseClickDownDelay", 10)
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()
Local $sTitle = "My Bot " & $g_sBotVersion & " Simple Mod " & $g_sModversion
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)
SetDebugLog("Bot title updated to: " & $g_sBotTitle)
EndFunc ;==>UpdateBotTitle
Func InitializeBot()
ProcessCommandLine()
If FileExists(@ScriptDir & "\EnableMBRDebug.txt") Then ; Set developer mode
$g_bDevMode = True
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
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)
_Crypt_Startup()
__GDIPlus_Startup() ; Start GDI+ Engine (incl. a new thread)
;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()
; 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
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 "/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
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") Then $g_asCmdLine[2] = "BlueStacks2"
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)
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()
SetDebugLog("SetupProfileFolder: " & $g_sProfilePath & "\" & $g_sProfileCurrentName)
$sChatIni = $g_sProfilePath & "\" & $g_sProfileCurrentName & "\rk_config.ini"
$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\'
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)
; 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
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
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()
;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)
$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
SetDebugLog("$g_sProfilePath = " & $g_sProfilePath)
SetDebugLog("$g_sProfileCurrentName = " & $g_sProfileCurrentName)
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)
; check for VC2010, .NET software and MyBot Files and Folders
If CheckPrerequisites(True) Then
MBRFunc(True) ; start MyBot.run.dll, after this point .net is initialized and threads popup all the time
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)
;AdlibRegister("PushBulletRemoteControl", $g_iPBRemoteControlInterval)
;AdlibRegister("PushBulletDeleteOldPushes", $g_iPBDeleteOldPushesInterval)
LoadAmountOfResourcesImages()
; 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..."))
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
SetDebugLog("GUI Process not received, close bot")
BotClose()
Else
SetDebugLog("Linked to GUI Process " & $g_iGuiPID)
EndIf
EndIf
; destroy splash screen here (so we witness the 100% ;)
DestroySplashScreen()
; InitializeVariables();initialize variables used in extrawindows
CheckVersion() ; check latest version on mybot.run site
UpdateMultiStats()
SetDebugLog("Maximum of " & $g_iGlobalActiveBotsAllowed & " bots running at same time configured")
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)
Local $iStartDelay = 0
If $bCheckPrerequisitesOK And ($g_bAutoStart Or $g_bRestarted = True) Then
Local $iDelay = $g_iAutoStartDelay
If $g_bRestarted = True Then $iDelay = 0
$iStartDelay = $iDelay * 1000
$g_iBotAction = $eBotStart
; check if android should be hidden
If $g_bBotLaunchOption_HideAndroid Then $g_bIsHidden = True
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
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
;Check for debug wait command
If FileExists(@ScriptDir & "\EnableMBRDebug.txt") Then
While (FileReadLine(@ScriptDir & "\EnableMBRDebug.txt") = "wait")
If _SleepStatus(15000) = True Then Return
WEnd
EndIf
;Restart bot after these seconds
If $b_iAutoRestartDelay > 0 And __TimerDiff($g_hBotLaunchTime) > $b_iAutoRestartDelay * 1000 Then
If RestartBot(False) = True Then Return
EndIf
PrepareDonateCC()
If Not $g_bRunState Then Return
$g_bRestart = False
$g_bFullArmy = False
$g_iCommandStop = -1
If _Sleep($DELAYRUNBOT1) Then Return
checkMainScreen()
If $g_bRestart = True Then ContinueLoop
chkShieldStatus()
If Not $g_bRunState Then Return
If $g_bRestart = True Then ContinueLoop
checkObstacles() ; trap common error messages also check for reconnecting animation
If $g_bRestart = True Then ContinueLoop
If $g_bQuicklyFirstStart = True Then
$g_bQuicklyFirstStart = False
Else
$g_bQuickAttack = QuickAttack()
EndIf
If CheckAndroidReboot() = True Then ContinueLoop
If $g_bIsClientSyncError = False And $g_bIsSearchLimit = False And ($g_bQuickAttack = False) Then
If BotCommand() Then btnStop()
If _Sleep($DELAYRUNBOT2) Then Return
checkMainScreen(False)
If $g_bRestart = True Then ContinueLoop
If _Sleep($DELAYRUNBOT3) Then Return
;------------------CUSTOM LOGIC By Simple Mod - START------------------
If Not $g_bFirstStart Then
VillageReport()
EndIf
ProfileSwitch()
CheckFarmSchedule()
CheckStopForWar()
;------------------CUSTOM LOGIC By Simple Mod - END------------------
If $g_bOutOfGold = True 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 = True 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 gold 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 = True Then ContinueLoop
;------------------ADDED By Simple Mod - START------------------
;If $g_bFirstStart Then ProfileReport()
;If _Sleep($DELAYRUNBOT5) Then Return
;If $g_bFirstStart Then checkArmyCamp(True, True, False, True)
$g_bCanRequestCC = True
If $g_bReqCCFirst And BalanceRecRec(True) Then
RequestCC()
If _Sleep($DELAYRUNBOT1) = False Then checkMainScreen(False)
EndIf
;------------------ADDED By Simple Mod - END------------------
Local $aRndFuncList = ['LabCheck', 'Collect', 'CheckTombs', 'ReArm', 'CleanYard']
While 1
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If UBound($aRndFuncList) > 1 Then
Local $Index = Random(0, UBound($aRndFuncList), 1)
If $Index > UBound($aRndFuncList) - 1 Then $Index = UBound($aRndFuncList) - 1
_RunFunction($aRndFuncList[$Index])
_ArrayDelete($aRndFuncList, $Index)
Else
_RunFunction($aRndFuncList[0])
ExitLoop
EndIf
If $g_bRestart = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
WEnd
If ($g_iCommandStop = 0 Or $g_iCommandStop = 3) And ProfileSwitchAccountEnabled() And Not $g_abDonateOnly[$g_iCurAccount] Then checkSwitchAcc()
AddIdleTime()
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop
;------------------ADDED By Simple Mod - START------------------
If $iChkForecastBoost = 1 Then
$currentForecast = readCurrentForecast()
If $currentForecast >= Number($iTxtForecastBoost, 3) Then
If _GUICtrlComboBox_GetCurSel($g_hCmbBoostBarracks) > 0 Then
SetLog("Boost Time !", $COLOR_GREEN)
Else
SetLog("Boost barracks disabled!", $COLOR_GREEN)
EndIf
Else
SetLog("Forecast index is below the required value, no boost !", $COLOR_RED)
EndIf
EndIf
If $iChkForecastPause = 1 Then
$currentForecast = readCurrentForecast()
EndIf
;------------------ADDED By Simple Mod - END------------------
If IsSearchAttackEnabled() Then ; if attack is disabled skip reporting, requesting, donating, training, and boosting
Local $aRndFuncList = ['ReplayShare', 'NotifyReport', 'DonateCC,Train', 'RequestCC', 'CollectFreeMagicItems', 'HeroT'] ; EDITED By Simple Mod
While 1
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If UBound($aRndFuncList) > 1 Then
Local $Index = Random(0, UBound($aRndFuncList), 1)
If $Index > UBound($aRndFuncList) - 1 Then $Index = UBound($aRndFuncList) - 1
_RunFunction($aRndFuncList[$Index])
_ArrayDelete($aRndFuncList, $Index)
Else
_RunFunction($aRndFuncList[0])
ExitLoop
EndIf
If CheckAndroidReboot() = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
WEnd
;BoostEverything() ; 1st Check if is to use Training Potion ; REMOVED By Simple Mod
Local $aRndFuncList = ['BoostBarracks', 'BoostSpellFactory', 'BoostKing', 'BoostQueen', 'BoostWarden', 'BoostAll', 'OneGemBost'] ; EDITED By Simple Mod
While 1
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If UBound($aRndFuncList) > 1 Then
Local $Index = Random(0, UBound($aRndFuncList), 1)
If $Index > UBound($aRndFuncList) - 1 Then $Index = UBound($aRndFuncList) - 1
_RunFunction($aRndFuncList[$Index])
_ArrayDelete($aRndFuncList, $Index)
Else
_RunFunction($aRndFuncList[0])
ExitLoop
EndIf
If CheckAndroidReboot() = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
WEnd
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop
If $g_iUnbrkMode >= 1 Then
If Unbreakable() = True Then ContinueLoop
EndIf
EndIf
If ($g_iCommandStop = 3 Or $g_iCommandStop = 0) Then ; Train Donate only - force a donate cc everytime, Ignore any SkipDonate Near Full Values
If BalanceDonRec(True) Then DonateCC()
EndIf
MainSuperXPHandler() ; ADDED By Simple Mod
Local $aRndFuncList = ['Laboratory', 'UpgradeHeroes', 'UpgradeBuilding', 'BuilderBase']
While 1
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
If UBound($aRndFuncList) > 1 Then
$Index = Random(0, UBound($aRndFuncList), 1)
If $Index > UBound($aRndFuncList) - 1 Then $Index = UBound($aRndFuncList) - 1
_RunFunction($aRndFuncList[$Index])
_ArrayDelete($aRndFuncList, $Index)
Else
_RunFunction($aRndFuncList[0])
ExitLoop
EndIf
If CheckAndroidReboot() = True Then ContinueLoop 2 ; must be level 2 due to loop-in-loop
WEnd
If $g_bRunState = False Then Return
If $g_bRestart = True Then ContinueLoop
If IsSearchAttackEnabled() Then ; If attack scheduled has attack disabled now, stop wall upgrades, and attack.
$g_iNbrOfWallsUpped = 0
UpgradeWall()
If _Sleep($DELAYRUNBOT3) Then Return
If $g_bRestart = True Then ContinueLoop
If ProfileSwitchAccountEnabled() And $g_abDonateOnly[$g_iCurAccount] Then checkSwitchAcc()
Idle()
;$g_bFullArmy1 = $g_bFullArmy
If _Sleep($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 = True Then
SetLog("Switching to Halt Attack, Stay Online/Collect mode ...", $COLOR_ERROR)
$g_bFirstStart = True ; reset First time flag to ensure army balancing when returns to training
ContinueLoop
EndIf
If _Sleep($DELAYRUNBOT1) Then Return
If $g_bRestart = True Then ContinueLoop
EndIf
Else
$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
If $g_bQuickAttack Then
SetLog("Quick Restart... ", $COLOR_INFO)
Else
If $g_bIsSearchLimit = True Then
SetLog("Restarted due search limit", $COLOR_INFO)
Else
SetLog("Restarted after Out of Sync Error: Attack Now", $COLOR_INFO)
EndIf
EndIf
If _Sleep($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 = True Then
SetLog("Switching to Halt Attack, Stay Online/Collect mode ...", $COLOR_ERROR)
$g_bFirstStart = True ; reset First time flag to ensure army balancing when returns to training
$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
$g_bIdleState = True
Local $Result = _Idle()
$g_bIdleState = False
Return $Result
EndFunc ;==>Idle
Func _Idle() ;Sequence that runs until Full Army
Static $iCollectCounter = 0 ; Collect counter, when reaches $g_iCollectAtCount, it will collect
Local $TimeIdle = 0 ;In Seconds
ForecastSwitch() ; ADDED By Simple Mod
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)
;------------------ADDED By Simple Mod - START------------------
MainGTFO()
MainKickout()
If $g_bChkChatGlobal = True Or $g_bChkChatClan = True Then
ChatbotMessage()
EndIf
;------------------ADDED By Simple Mod - END------------------
Local $hTimer = __TimerInit()
Local $iReHere = 0, $bNoCheckRedChatIcon = True
If $g_iActiveDonate And $g_bChkDonate Then
Local $aHeroResult = CheckArmyCamp(True, True, True, False)
While $iReHere < 7
If Not $g_bRunState Then Return
$iReHere += 1
If ($g_iCommandStop = 3 Or $g_iCommandStop = 0) Then $bNoCheckRedChatIcon = ($iReHere = 1) ? False : True ; Just to force once to open and check Donations when is Halt mode
If $iReHere = 1 And SkipDonateNearFullTroops(True, $aHeroResult) = False And BalanceDonRec(True) Then
DonateCC($bNoCheckRedChatIcon)
ElseIf SkipDonateNearFullTroops(False, $aHeroResult) = False And BalanceDonRec(False) Then
DonateCC($bNoCheckRedChatIcon)
EndIf
If _Sleep($DELAYIDLE2) Then ExitLoop
If $g_bRestart = True Then ExitLoop
If CheckAndroidReboot() Then ContinueLoop 2
WEnd
EndIf
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
ReplayShare($g_bShareAttackEnableNow)
If _Sleep($DELAYIDLE1) Then Return
If $g_bRestart = True Then ExitLoop
If $iCollectCounter > $g_iCollectAtCount Then ; This is prevent from collecting all the time which isn't needed anyway
Local $aRndFuncList = ['Collect', 'CheckTombs', 'DonateCC', 'CleanYard']
While 1
If $g_bRunState = False Then Return
If $g_bRestart = True Then ExitLoop
If CheckAndroidReboot() Then ContinueLoop 2
If UBound($aRndFuncList) > 1 Then
Local $Index = Random(0, UBound($aRndFuncList), 1)
If $Index > UBound($aRndFuncList) - 1 Then $Index = UBound($aRndFuncList) - 1
_RunFunction($aRndFuncList[$Index])
_ArrayDelete($aRndFuncList, $Index)
Else
_RunFunction($aRndFuncList[0])
ExitLoop
EndIf
WEnd
If $g_bRunState = False Then Return
If $g_bRestart = True Then ExitLoop
If _Sleep($DELAYIDLE1) Or $g_bRunState = False Then ExitLoop
$iCollectCounter = 0
EndIf
$iCollectCounter = $iCollectCounter + 1
AddIdleTime()
checkMainScreen(False) ; required here due to many possible exits
If $g_iCommandStop = -1 Then