-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathBotEngine.cpp
More file actions
3348 lines (2752 loc) · 153 KB
/
Copy pathBotEngine.cpp
File metadata and controls
3348 lines (2752 loc) · 153 KB
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
#define _CRT_SECURE_NO_WARNINGS
#define NOMINMAX
#include "BotEngine.h"
#include "Language.h"
#include "Discord.h"
#include "tesseract_ocr.h"
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#include "imgui.h"
#include <thread>
#include <chrono>
#include <fstream>
#include <filesystem>
#include <iostream>
#include <cstdlib>
#include <windows.h>
#include <stdio.h>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cctype>
// GLOBAL VARIABLES
namespace fs = std::filesystem;
std::string g_StorageTag = "";
extern TemplateThresholds g_Thresholds;
extern IntervalSettings g_Intervals;
extern std::deque<BotInstance> g_Bots;
extern std::string kAdbPath;
extern std::string kMEmuConsolePath;
extern std::string GetAppDataPath();
extern bool g_EnableBarnWebhook;
extern bool g_EnableWebhookImage;
// --- TEMPLATE PATHS ---
extern std::string f_templatePath; extern std::string w_templatePath; extern std::string s_templatePath;
extern std::string g_templatePath; extern std::string shop_templatePath; extern std::string wheatshop_templatePath;
extern std::string soldcrate_templatePath; extern std::string crate_templatePath; extern std::string arrows_templatePath;
extern std::string plus_templatePath; extern std::string cross_templatePath; extern std::string advertise_templatePath;
extern std::string create_sale_templatePath; extern std::string c_templatePath; extern std::string gc_templatePath;
extern std::string cornshop_templatePath; extern std::string barn_market_templatePath; extern std::string silo_market_templatePath;
extern std::string mailbox_templatePath; extern std::string crate_wheat_templatePath; extern std::string crate_corn_templatePath;
extern std::string levelup_templatePath; extern std::string levelup_continue_templatePath; extern std::string carrot_templatePath;
extern std::string grown_carrot_templatePath; extern std::string carrot_shop_templatePath; extern std::string soybean_templatePath;
extern std::string grown_soybean_templatePath; extern std::string soybean_shop_templatePath; extern std::string sugarcane_templatePath;
extern std::string grown_sugarcane_templatePath; extern std::string sugarcane_shop_templatePath; extern std::string silo_full_templatePath;
extern std::string crate_carrot_templatePath; extern std::string crate_soybean_templatePath; extern std::string crate_sugarcane_templatePath;
extern std::string silo_full_cross_templatePath; extern std::string market_close_crosstemplatePath; extern std::string market_close_crosstemplatePath;
// --- MUTUAL FUNCTIONS ---
extern void AddLog(int instanceId, std::string message, ImVec4 color = ImVec4(0.8f, 0.8f, 0.8f, 1.0f));
extern void SaveConfig();
extern void SaveInventoryData();
extern std::string GetClipboardText();
static std::wstring Utf8ToWide(const std::string& text) {
if (text.empty()) return {};
int length = MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, nullptr, 0);
if (length <= 1) return {};
std::wstring result(static_cast<size_t>(length), L'\0');
MultiByteToWideChar(CP_UTF8, 0, text.c_str(), -1, result.data(), length);
result.pop_back();
return result;
}
static void ShowLocalizedMessage(const std::string& message, const char* title, UINT flags) {
std::wstring wideMessage = Utf8ToWide(message);
std::wstring wideTitle = Utf8ToWide(Tr(title));
MessageBoxW(nullptr, wideMessage.c_str(), wideTitle.c_str(), flags | MB_TOPMOST);
}
// INJECT FOLDERS
const std::string GAME_DATA_PATH = "/data/data/com.supercell.hayday/shared_prefs/storage_new.xml";
const std::string ZOOM_DATA_PATH = "/data/data/com.supercell.hayday/update/data/game_config.csv";
// TRANSFER PART (NOT DONE )
int g_TransferThreshold = 10;
TransferRequest g_TransferRequest;
// ==============================================================================
std::string GetUniversalAdbPath(int instanceId) {
(void)instanceId;
return kAdbPath;
}
static bool RequireConfiguredEmulatorPaths(int instanceId) {
if (AreEmulatorPathsValid()) return true;
AddLog(
instanceId,
Tr("Action blocked: Please correct your PATHs in Settings."),
ImVec4(1.0f, 0.25f, 0.2f, 1.0f));
return false;
}
// ==============================================================================
// RUN CMD IN BACKGROUND BECAUSE WITHOUT THIS , THE CMD WINDOW WILL POP UP (FLICKER, OPEN AND CLOSE IMMEDIATELY) WHICH IS ANNOYING. THIS FUNCTION HIDES THE CMD WINDOW COMPLETELY.
bool RunCmdHidden(const std::string& command) {
STARTUPINFOA si{};
PROCESS_INFORMATION pi{};
si.cb = sizeof(si);
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
std::string finalCmd = command;
std::vector<char> cmdBuffer(finalCmd.begin(), finalCmd.end());
cmdBuffer.push_back(0);
BOOL ok = CreateProcessA(nullptr, cmdBuffer.data(), nullptr, nullptr, FALSE, CREATE_NO_WINDOW, nullptr, nullptr, &si, &pi);
if (!ok) return false;
DWORD waitResult = WaitForSingleObject(pi.hProcess, 10000);
if (waitResult == WAIT_TIMEOUT) {
TerminateProcess(pi.hProcess, 1);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return false;
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return true;
}
struct ProcessCaptureResult {
bool launched = false;
bool timedOut = false;
DWORD exitCode = ERROR_GEN_FAILURE;
std::string output;
bool Succeeded() const {
return launched && !timedOut && exitCode == 0;
}
};
static ProcessCaptureResult RunExecutableCapture(
const std::string& executable,
const std::string& args,
DWORD timeoutMs = 10000) {
ProcessCaptureResult result;
SECURITY_ATTRIBUTES sa{ sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE };
HANDLE readPipe = nullptr;
HANDLE writePipe = nullptr;
if (!CreatePipe(&readPipe, &writePipe, &sa, 0)) {
result.output = "Failed to create output pipe.";
return result;
}
SetHandleInformation(readPipe, HANDLE_FLAG_INHERIT, 0);
STARTUPINFOA si{};
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.hStdOutput = writePipe;
si.hStdError = writePipe;
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
si.wShowWindow = SW_HIDE;
PROCESS_INFORMATION pi{};
std::string commandLine = "\"" + executable + "\"";
if (!args.empty()) commandLine += " " + args;
std::vector<char> commandBuffer(commandLine.begin(), commandLine.end());
commandBuffer.push_back('\0');
BOOL launched = CreateProcessA(
executable.c_str(),
commandBuffer.data(),
nullptr,
nullptr,
TRUE,
CREATE_NO_WINDOW,
nullptr,
nullptr,
&si,
&pi);
CloseHandle(writePipe);
if (!launched) {
result.output = "Failed to start process. Windows error: " + std::to_string(GetLastError());
CloseHandle(readPipe);
return result;
}
result.launched = true;
auto drainOutput = [&]() {
DWORD available = 0;
while (PeekNamedPipe(readPipe, nullptr, 0, nullptr, &available, nullptr) && available > 0) {
char buffer[512];
DWORD bytesRead = 0;
DWORD bytesToRead = (available < sizeof(buffer)) ? available : (DWORD)sizeof(buffer);
if (!ReadFile(readPipe, buffer, bytesToRead, &bytesRead, nullptr) || bytesRead == 0) {
break;
}
result.output.append(buffer, bytesRead);
available -= bytesRead;
}
};
ULONGLONG deadline = GetTickCount64() + timeoutMs;
while (true) {
drainOutput();
DWORD waitResult = WaitForSingleObject(pi.hProcess, 25);
if (waitResult == WAIT_OBJECT_0) break;
if (waitResult == WAIT_FAILED) break;
if (GetTickCount64() >= deadline) {
result.timedOut = true;
TerminateProcess(pi.hProcess, 1);
WaitForSingleObject(pi.hProcess, 1000);
break;
}
}
drainOutput();
GetExitCodeProcess(pi.hProcess, &result.exitCode);
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
CloseHandle(readPipe);
return result;
}
static ProcessCaptureResult RunAdbCapture(const std::string& args, DWORD timeoutMs = 10000) {
return RunExecutableCapture(kAdbPath, args, timeoutMs);
}
static ProcessCaptureResult RunAdbCaptureForInstance(
int instanceId,
const std::string& args,
DWORD timeoutMs = 10000) {
std::string serial = g_Bots[instanceId].adbSerial;
return RunAdbCapture("-s " + serial + " " + args, timeoutMs);
}
static std::string TrimAscii(std::string value) {
auto isNotSpace = [](unsigned char c) { return !std::isspace(c); };
value.erase(value.begin(), std::find_if(value.begin(), value.end(), isNotSpace));
value.erase(std::find_if(value.rbegin(), value.rend(), isNotSpace).base(), value.end());
return value;
}
static std::string ToLowerAsciiCopy(std::string value) {
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
});
return value;
}
std::string GetAdbDevicesList() {
if (!AreEmulatorPathsValid()) {
return "$ adb devices\r\nERROR: Configure valid emulator paths in Settings first.";
}
ProcessCaptureResult result = RunAdbCapture("devices", 15000);
std::ostringstream output;
output << "$ adb devices\r\n";
if (!result.launched) {
output << "ERROR: " << result.output;
}
else if (result.timedOut) {
output << "ERROR: adb devices timed out.";
}
else {
output << (result.output.empty() ? "(no output)" : result.output);
if (result.exitCode != 0) {
output << "\r\n[Exit code: " << result.exitCode << "]";
}
}
return output.str();
}
// GET ADB OUTPUT AND RETURN OUTPUT AS STRING TO READ STUFF LIKE INPUT DEVICE EVENT ETC.
std::string GetAdbOutput(int instanceId, std::string args) {
return RunAdbCaptureForInstance(instanceId, args).output;
}
enum class AdbDeviceState {
Online,
Offline,
Unauthorized,
Unavailable
};
static AdbDeviceState QueryAdbDeviceState(int instanceId, std::string* rawOutput = nullptr) {
ProcessCaptureResult result = RunAdbCaptureForInstance(instanceId, "get-state", 5000);
if (rawOutput) *rawOutput = result.output;
std::istringstream lines(result.output);
std::string line;
while (std::getline(lines, line)) {
if (ToLowerAsciiCopy(TrimAscii(line)) == "device" && result.Succeeded()) {
return AdbDeviceState::Online;
}
}
std::string normalized = ToLowerAsciiCopy(result.output);
if (normalized.find("offline") != std::string::npos) return AdbDeviceState::Offline;
if (normalized.find("unauthorized") != std::string::npos) return AdbDeviceState::Unauthorized;
return AdbDeviceState::Unavailable;
}
static std::string MakeSingleLine(std::string value) {
for (char& c : value) {
if (c == '\r' || c == '\n' || c == '\t') c = ' ';
}
value = TrimAscii(value);
if (value.size() > 300) value = value.substr(0, 300) + "...";
return value;
}
static bool PrepareLdPlayerAdbForBot(int instanceId) {
BotInstance& bot = g_Bots[instanceId];
if (bot.emulatorType != 1) return true;
bot.statusText = "STARTING ADB...";
AddLog(instanceId, Tr("Starting ADB server for LDPlayer..."), ImVec4(0.4f, 0.8f, 1.0f, 1.0f));
ProcessCaptureResult startResult = RunAdbCapture("start-server", 15000);
if (!startResult.Succeeded()) {
AddLog(instanceId, Tr("Bot start failed: Could not start the ADB server."), ImVec4(1, 0, 0, 1));
if (!startResult.output.empty()) {
AddLog(instanceId, std::string(Tr("ADB output: ")) + MakeSingleLine(startResult.output), ImVec4(1, 0.5f, 0.2f, 1));
}
bot.isRunning = false;
bot.statusText = "ADB START FAILED";
return false;
}
std::string serial = bot.adbSerial;
ProcessCaptureResult connectResult = RunAdbCapture("connect " + serial, 10000);
if (!connectResult.output.empty()) {
AddLog(instanceId, std::string(Tr("ADB connection: ")) + MakeSingleLine(connectResult.output), ImVec4(0.65f, 0.75f, 0.85f, 1));
}
AdbDeviceState state = AdbDeviceState::Unavailable;
for (int attempt = 0; attempt < 10 && bot.isRunning; ++attempt) {
state = QueryAdbDeviceState(instanceId);
if (state == AdbDeviceState::Online) {
AddLog(instanceId, Tr("LDPlayer ADB is online. Starting bot..."), ImVec4(0, 1, 0, 1));
return true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));
}
if (!bot.isRunning) return false;
if (state == AdbDeviceState::Offline) {
AddLog(instanceId, Tr("Bot start failed: LDPlayer ADB device is offline."), ImVec4(1, 0, 0, 1));
}
else if (state == AdbDeviceState::Unauthorized) {
AddLog(instanceId, Tr("Bot start failed: LDPlayer ADB device is unauthorized."), ImVec4(1, 0, 0, 1));
}
else {
AddLog(instanceId, Tr("Bot start failed: LDPlayer ADB device was not found."), ImVec4(1, 0, 0, 1));
}
bot.isRunning = false;
bot.statusText = "ADB OFFLINE";
return false;
}
static bool AdbCommandSucceeded(const ProcessCaptureResult& result) {
if (!result.Succeeded()) return false;
std::string output = ToLowerAsciiCopy(result.output);
return output.find("error:") == std::string::npos &&
output.find("device offline") == std::string::npos &&
output.find("unauthorized") == std::string::npos &&
output.find("failed to") == std::string::npos;
}
static void LogInjectionAdbFailure(
int instanceId,
const std::string& step,
const ProcessCaptureResult& result) {
AdbDeviceState state = QueryAdbDeviceState(instanceId);
if (state == AdbDeviceState::Offline) {
AddLog(instanceId, Tr("Injection failed: ADB device is offline. Files were not pushed."), ImVec4(1, 0, 0, 1));
return;
}
if (state == AdbDeviceState::Unauthorized) {
AddLog(instanceId, Tr("Injection failed: ADB device is unauthorized. Files were not pushed."), ImVec4(1, 0, 0, 1));
return;
}
if (state == AdbDeviceState::Unavailable) {
AddLog(instanceId, Tr("Injection failed: ADB device is not connected. Files were not pushed."), ImVec4(1, 0, 0, 1));
return;
}
AddLog(instanceId, Tr("Injection failed. Check the ADB output for details."), ImVec4(1, 0, 0, 1));
if (!result.output.empty()) {
AddLog(instanceId, std::string(Tr("ADB output: ")) + MakeSingleLine(result.output), ImVec4(1, 0.5f, 0.2f, 1));
}
}
static bool RunCheckedInjectionAdbCommand(
int instanceId,
const std::string& args,
const std::string& step,
DWORD timeoutMs = 30000) {
ProcessCaptureResult result = RunAdbCaptureForInstance(instanceId, args, timeoutMs);
if (AdbCommandSucceeded(result)) return true;
LogInjectionAdbFailure(instanceId, step, result);
return false;
}
static bool VerifyInjectedRemoteFile(int instanceId, const std::string& remotePath) {
std::string verifyCommand =
"shell \"su -c 'if [ -s " + remotePath +
" ]; then echo NXRTH_OK; else echo NXRTH_MISSING; fi'\"";
ProcessCaptureResult result = RunAdbCaptureForInstance(instanceId, verifyCommand, 10000);
if (AdbCommandSucceeded(result) &&
result.output.find("NXRTH_OK") != std::string::npos &&
result.output.find("NXRTH_MISSING") == std::string::npos) {
return true;
}
LogInjectionAdbFailure(instanceId, "verifying " + remotePath, result);
return false;
}
// THIS FUNCTION HELPS TO MAKE SURE USER IS USING 640X480 100 DPI RESOLUTION. IF NOT, BOT WON'T START.
std::string GetMEmuConfig(int instanceId, std::string key) {
// FIND MEMUC.EXE BASED ON THE ADB PATH (IN CASE USER MOVED MEmu FOLDER OR RENAMED IT, WE CAN STILL FIND MEMUC.EXE) BECAUSE MEMUC EXE IS IN THE SAME FOLDER AS ADB.EXE
std::string memucPath = kAdbPath;
size_t lastSlash = memucPath.find_last_of("\\/");
if (lastSlash != std::string::npos) {
memucPath = memucPath.substr(0, lastSlash + 1) + "memuc.exe";
// EXAMPLE "D:\MEmu\adb.exe" -> "D:\MEmu\" + "memuc.exe"
}
// 2. PREPARE THE COMMAND
std::string cmd = "cmd.exe /c \"\"" + memucPath + "\" getconfig -i " + std::to_string(instanceId) + " " + key + "\"";
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
HANDLE hRead, hWrite;
CreatePipe(&hRead, &hWrite, &sa, 0);
STARTUPINFOA si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
si.hStdOutput = hWrite;
si.hStdError = hWrite;
si.wShowWindow = SW_HIDE; // CMD DOESNT POPS UP
PROCESS_INFORMATION pi;
ZeroMemory(&pi, sizeof(pi));
if (CreateProcessA(NULL, (LPSTR)cmd.c_str(), NULL, NULL, TRUE, CREATE_NO_WINDOW, NULL, NULL, &si, &pi)) {
WaitForSingleObject(pi.hProcess, 3000); //WAIT UP TO 3 SECONDS
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
CloseHandle(hWrite);
DWORD read;
char buffer[128];
ZeroMemory(buffer, sizeof(buffer));
ReadFile(hRead, buffer, sizeof(buffer) - 1, &read, NULL);
CloseHandle(hRead);
std::string rawResult = buffer;
std::string cleanResult = "";
// CHECK RETURNED STRING AND EXTRACT NECESSARY PART (WE NEED DIGITS ONLY)
for (char c : rawResult) {
if (isdigit(c)) {
cleanResult += c;
}
}
// FOR EXAMPLE: IF RETURNED STRING IS " 640\r\n", cleanResult WILL TURN TO "640".
return cleanResult;
}
// ADB COMMAND RUNNER
void RunAdbCommand(int instanceId, std::string args) {
std::string serial = g_Bots[instanceId].adbSerial;
std::string cmd = "cmd.exe /c \"\"" + kAdbPath + "\" -s " + serial + " " + args + "\"";
RunCmdHidden(cmd);
}
// TAP FUNCTION TO TAP ON THE SCREEN
void AdbTap(int instanceId, int x, int y) {
RunAdbCommand(instanceId, "shell input tap " + std::to_string(x) + " " + std::to_string(y));
}
// FUNCTION USED IN AUTO ITEM TRANSFER, THIS FUNCTION CLOSES ALL THE MENUS BY SEARCHING CROSS AND TAP ON IT OVER AND OVER UNTIL THERES NO CROSS.
void ForceCloseAllMenus(int instanceId) {
AddLog(instanceId, "Closing all menus to return to main screen...", ImVec4(0.8f, 0.8f, 0.2f, 1.0f));
for (int i = 0; i < 3; i++) {
cv::Mat screen = CaptureInstanceScreen(instanceId, kAdbPath, g_Bots[instanceId].adbSerial);
MatchResult crossRes = FindImage(screen, cross_templatePath, g_Thresholds.crossThreshold, false);
if (crossRes.found) {
AdbTap(instanceId, crossRes.x, crossRes.y);
std::this_thread::sleep_for(std::chrono::milliseconds(g_Intervals.menuCloseWait));
}
else {
break; // IF THERES NO CROSS FOUND, ASSUME WE ARE BACK TO THE FARM AND STOP
}
}
}
// TEMPLATE TEST BUTTONS USED IN GUI TO HELP USERS IF THEIR TEMPLATES ARE WORKING PROPERLY OR NOT
void PerformTemplateTest(int instanceId, std::string templatePath, std::string testName, float threshold, bool useGrayscale) {
if (!RequireConfiguredEmulatorPaths(instanceId)) return;
AddLog(instanceId, std::string(Tr("Running ")) + Tr(testName.c_str()) + "...", ImVec4(1, 1, 0, 1));
std::thread([instanceId, templatePath, testName, threshold, useGrayscale]() {
cv::Mat frame = CaptureInstanceScreen(instanceId, kAdbPath, g_Bots[instanceId].adbSerial);
MatchResult res = FindImage(frame, templatePath, threshold, useGrayscale);
if (res.found) {
AddLog(instanceId, Tr(testName.c_str()) + std::string(Tr(" FOUND! Score: ")) + std::to_string((int)(res.score * 100)) + "% at " + std::to_string(res.x) + "," + std::to_string(res.y), ImVec4(0, 1, 0, 1));
AdbTap(instanceId, res.x, res.y);
}
else {
AddLog(instanceId, Tr(testName.c_str()) + std::string(Tr(" NOT Found.")), ImVec4(1, 0.5f, 0, 1));
}
}).detach();
}
// ANOTHER IMPORTANT FUNCTION. HELPS US TO USE TWO FINGER SWIPE. MINITOUCH IS A TOOL THAT CREATES A VIRTUAL TOUCHSCREEN DEVICE ON THE EMULATOR AND LETS US CONTROL IT WITH ADB COMMANDS.
void StartMinitouchStealth(int instanceId) {
int minitouchPort = 1111 + instanceId;
RunAdbCommand(instanceId, "forward tcp:" + std::to_string(minitouchPort) + " localabstract:minitouch");
std::string serial = g_Bots[instanceId].adbSerial;
std::string cmd = "cmd.exe /c \"\"" + kAdbPath + "\" -s " + serial + " shell /data/local/tmp/minitouch\"";
WinExec(cmd.c_str(), SW_HIDE);
}
typedef BOOL(WINAPI* IsHungAppWindowProc)(HWND);
// WATCHDOG FOR THE EMULATOR OR GAME CRASH
void EmulatorCrashWatchdog(int instanceId) {
BotInstance& bot = g_Bots[instanceId];
if (!bot.isRunning) return;
static std::chrono::steady_clock::time_point hungStart[6];
static bool isHungState[6] = { false };
static int pidFailCount[6] = { 0 };
// =====================================================================
// 1. WINDOWS "NOT RESPONDING" WHITE SCREEN ERROR CHECK (EMULATOR CRASHED OR FROZE)
// =====================================================================
HWND hwnd = FindWindowA(NULL, bot.vmName);
if (hwnd != NULL) {
HMODULE hUser32 = GetModuleHandleA("user32.dll");
if (hUser32) {
IsHungAppWindowProc IsHung = (IsHungAppWindowProc)GetProcAddress(hUser32, "IsHungAppWindow");
if (IsHung && IsHung(hwnd)) {
if (!isHungState[instanceId]) {
isHungState[instanceId] = true;
hungStart[instanceId] = std::chrono::steady_clock::now();
AddLog(instanceId, Tr("Emulator is not responding. Waiting 15 seconds..."), ImVec4(1, 0.5f, 0, 1));
}
else {
// CHECK HOW LONG IT HAS BEEN IN HUNG STATE
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - hungStart[instanceId]).count();
if (elapsed >= 15) { // IF ITS BEEN MORE THAN 15 SEC RESTART
AddLog(instanceId, Tr("Emulator is still unresponsive. Restarting..."), ImVec4(1, 0, 0, 1));
if (bot.emulatorType == 1) { // LDPlayer
RunCmdHidden("cmd.exe /c \"\"" + kMEmuConsolePath + "\" quit --index " + std::to_string(bot.emuIndex) + "\"");
std::this_thread::sleep_for(std::chrono::seconds(5));
RunCmdHidden("cmd.exe /c \"\"" + kMEmuConsolePath + "\" launch --index " + std::to_string(bot.emuIndex) + "\"");
}
else { // MEmu
RunCmdHidden("cmd.exe /c \"\"" + kMEmuConsolePath + "\" stop " + bot.vmName + "\"");
std::this_thread::sleep_for(std::chrono::seconds(5));
RunCmdHidden("cmd.exe /c \"\"" + kMEmuConsolePath + "\" " + bot.vmName + "\"");
}
isHungState[instanceId] = false; // CLEAR MEMORY OF HUNG STATE BECAUSE WE JUST RESTARTED THE EMULATOR
std::this_thread::sleep_for(std::chrono::seconds(30)); // WAIT FOR REBOOT
return;
}
}
}
else {
// EMULATOR IS RESPONDING FINE, BUT CHECK IF WE WERE IN HUNG STATE BEFORE. IF YES, LOG RECOVERY.
if (isHungState[instanceId]) {
AddLog(instanceId, Tr("Emulator is responding again."), ImVec4(0, 1, 0, 1));
isHungState[instanceId] = false;
}
}
}
}
// =====================================================================
// CHECK IF GAME CRASHED AND EMULATOR IS IN THE HOME PAGE.
// =====================================================================
std::string serial = bot.adbSerial;
std::string tempFile = "C:\\Users\\Public\\pid_check_" + std::to_string(instanceId) + ".txt";
remove(tempFile.c_str());
std::string cmd = "cmd.exe /c \"\"" + kAdbPath + "\" -s " + serial + " shell pidof com.supercell.hayday > \"" + tempFile + "\"\"";
RunCmdHidden(cmd);
std::string currentAdb = kAdbPath;
std::ifstream file(tempFile);
std::string pidStr;
if (file.is_open()) {
std::getline(file, pidStr);
file.close();
}
if (pidStr.empty() || pidStr.length() < 2) {
pidFailCount[instanceId]++; // INCREMENT FAIL COUNT IF PID NOT FOUND
if (pidFailCount[instanceId] >= 3) { // IF CANT FIND PID FOR 3 TIMES
AddLog(instanceId, Tr("Hay Day process is unavailable. Relaunching..."), ImVec4(1, 0.5f, 0, 1));
std::string launchCmd = "cmd /c \"\"" + currentAdb + "\" -s " + serial + " shell monkey -p com.supercell.hayday -c android.intent.category.LAUNCHER 1\"";
RunCmdHidden(launchCmd);
pidFailCount[instanceId] = 0; // RESET
std::this_thread::sleep_for(std::chrono::seconds(10));
}
else {
AddLog(instanceId, std::string(Tr("Game process check failed: ")) + std::to_string(pidFailCount[instanceId]) + "/3", ImVec4(1, 1, 0, 1));
}
}
else {
// PID IS BACK, RESET FAIL COUNT
pidFailCount[instanceId] = 0;
}
}
void HandleReviveHeartbeat(int instanceId) {
BotInstance& bot = g_Bots[instanceId];
if (!bot.useReviveMode || strlen(bot.reviveTemplatePath) < 5) return;
AddLog(instanceId, Tr("Checking revive template..."), ImVec4(1, 1, 0, 1));
cv::Mat screen = CaptureInstanceScreen(instanceId, kAdbPath, bot.adbSerial);
MatchResult res = FindImage(screen, bot.reviveTemplatePath, 0.70f);
if (res.found) {
AddLog(instanceId, Tr("Revive template found."), ImVec4(0, 1, 0, 1));
bot.reviveFailCounter = 0; // SUCCESS, RESET FAIL COUNTER
}
else {
bot.reviveFailCounter++;
AddLog(instanceId, std::string(Tr("Revive template not found: ")) + std::to_string(bot.reviveFailCounter) + "/3", ImVec4(1, 0.5f, 0, 1));
if (bot.reviveFailCounter >= 3) {
AddLog(instanceId, Tr("Revive check failed three times. Restarting the game..."), ImVec4(1, 0, 0, 1));
// REOPEN HAYDAY
RunAdbCommand(instanceId, "shell am force-stop com.supercell.hayday");
std::this_thread::sleep_for(std::chrono::seconds(2));
RunAdbCommand(instanceId, "shell monkey -p com.supercell.hayday -c android.intent.category.LAUNCHER 1");
bot.reviveFailCounter = 0;
std::this_thread::sleep_for(std::chrono::seconds(15)); // BOOT SLEEP
}
}
}
//IMPORTANT FILES INJECTOR.
// THIS FUNCTION INJECTS(PUSHES) FILES TO THE ROOT.
void InjectImportantFiles(int instanceId) {
if (!RequireConfiguredEmulatorPaths(instanceId)) return;
char buffer[MAX_PATH];
GetModuleFileNameA(NULL, buffer, MAX_PATH);
std::string::size_type pos = std::string(buffer).find_last_of("\\/");
std::string exeDir = std::string(buffer).substr(0, pos);
std::string fontFile = exeDir + "\\injecthacks\\languages.csv";
std::string zoomFile = exeDir + "\\injecthacks\\game_config.csv";
std::string minitouchFile = exeDir + "\\injecthacks\\minitouch";
std::vector<std::string> nxrthFiles = {
"inject.nxrth", "inject2.nxrth", "inject3.nxrth", "inject4.nxrth", "inject5.nxrth"
};
for (const auto& file : nxrthFiles) {
if (!fs::exists(exeDir + "\\injecthacks\\" + file)) {
AddLog(instanceId, std::string(Tr("Missing injection file: ")) + file, ImVec4(1, 0, 0, 1));
return;
}
}
if (!fs::exists(fontFile) || !fs::exists(zoomFile) || !fs::exists(minitouchFile)) {
AddLog(instanceId, Tr("Error: Basic hack files (zoom/font/minitouch) missing!"), ImVec4(1, 0, 0, 1));
return;
}
AddLog(instanceId, Tr("Starting verified file injection. This may take 10-15 seconds..."), ImVec4(0.8f, 0.4f, 1.0f, 1.0f));
std::thread([instanceId, exeDir, fontFile, zoomFile, minitouchFile]() {
std::string initialStateOutput;
AdbDeviceState initialState = QueryAdbDeviceState(instanceId, &initialStateOutput);
if (initialState != AdbDeviceState::Online) {
ProcessCaptureResult stateResult;
stateResult.launched = true;
stateResult.exitCode = 1;
stateResult.output = initialStateOutput;
LogInjectionAdbFailure(instanceId, "checking the ADB device", stateResult);
return;
}
AddLog(instanceId, Tr("ADB device is online. Starting injection..."), ImVec4(0.4f, 0.8f, 1.0f, 1.0f));
// 1. FORCE CLOSE HAY DAY TO AVOID FILE LOCKS
AddLog(instanceId, Tr("Stopping Hay Day..."), ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell am force-stop com.supercell.hayday",
"force stopping Hay Day")) return;
std::this_thread::sleep_for(std::chrono::milliseconds(g_Intervals.pageLoadWait));
// 2. CREATE TARGET FOLDERS
const std::string dataDir = "/data/data/com.supercell.hayday/update/data/";
const std::string scDir = "/data/data/com.supercell.hayday/update/sc/";
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'mkdir -p " + dataDir + "'\"",
"creating the data folder")) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'mkdir -p " + scDir + "'\"",
"creating the asset folder")) return;
// 3. FONT & LANGUAGE HACK
AddLog(instanceId, Tr("1/4: Pushing font and language files..."), ImVec4(0.8f, 0.8f, 0.2f, 1.0f));
const std::string tempFont = "/sdcard/temp_languages.csv";
if (!RunCheckedInjectionAdbCommand(
instanceId,
"push \"" + fontFile + "\" " + tempFont,
"pushing languages.csv",
60000)) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'cp " + tempFont + " " + dataDir + "languages.csv'\"",
"installing languages.csv")) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'chmod 777 " + dataDir + "languages.csv'\"",
"setting languages.csv permissions")) return;
RunAdbCommand(instanceId, "shell rm " + tempFont);
// 4. ZOOM HACK
AddLog(instanceId, Tr("2/4: Pushing view-distance files..."), ImVec4(0.8f, 0.8f, 0.2f, 1.0f));
const std::string tempZoom = "/sdcard/temp_config.csv";
if (!RunCheckedInjectionAdbCommand(
instanceId,
"push \"" + zoomFile + "\" " + tempZoom,
"pushing game_config.csv",
60000)) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'cp " + tempZoom + " " + ZOOM_DATA_PATH + "'\"",
"installing game_config.csv")) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'chmod 777 " + ZOOM_DATA_PATH + "'\"",
"setting game_config.csv permissions")) return;
RunAdbCommand(instanceId, "shell rm " + tempZoom);
// 5. NATURE ASSETS
AddLog(instanceId, Tr("3/4: Preparing and pushing visual assets..."), ImVec4(0.8f, 0.8f, 0.2f, 1.0f));
const std::vector<std::pair<std::string, std::string>> natureMap = {
{"inject.nxrth", "nature_new.sc"},
{"inject2.nxrth", "nature_new_0.sctx"},
{"inject3.nxrth", "nature_new_1.sctx"},
{"inject4.nxrth", "nature_new_2.sctx"},
{"inject5.nxrth", "nature_new_3.sctx"}
};
for (const auto& pair : natureMap) {
std::string nxPath = exeDir + "\\injecthacks\\" + pair.first;
std::string tempPath = exeDir + "\\injecthacks\\temp_" + pair.second;
std::ifstream inFile(nxPath, std::ios::binary);
std::string encryptedData(
(std::istreambuf_iterator<char>(inFile)),
std::istreambuf_iterator<char>());
inFile.close();
std::string rawData = DecryptXORHex(encryptedData, "NXRTH_NATURE_KEY");
if (rawData.empty()) {
AddLog(instanceId, std::string(Tr("Injection failed: Could not decrypt ")) + pair.first + ".", ImVec4(1, 0, 0, 1));
return;
}
std::ofstream outFile(tempPath, std::ios::binary);
if (!outFile.is_open()) {
AddLog(instanceId, std::string(Tr("Injection failed: Could not create a temporary file for ")) + pair.second + ".", ImVec4(1, 0, 0, 1));
return;
}
outFile.write(rawData.data(), rawData.size());
outFile.close();
bool pushed = RunCheckedInjectionAdbCommand(
instanceId,
"push \"" + tempPath + "\" /data/local/tmp/" + pair.second,
"pushing " + pair.second,
60000);
std::error_code removeError;
fs::remove(tempPath, removeError);
if (!pushed) return;
}
AddLog(instanceId, Tr("Applying visual assets..."), ImVec4(0.5f, 0.5f, 0.5f, 1.0f));
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'cp /data/local/tmp/nature_new* " + scDir + "'\"",
"installing visual assets",
60000)) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell \"su -c 'chmod 777 " + scDir + "nature_new*'\"",
"setting visual asset permissions")) return;
RunAdbCommand(instanceId, "shell rm /data/local/tmp/nature_new*");
// 6. MINITOUCH
AddLog(instanceId, Tr("4/4: Pushing Minitouch..."), ImVec4(0.8f, 0.8f, 0.2f, 1.0f));
if (!RunCheckedInjectionAdbCommand(
instanceId,
"push \"" + minitouchFile + "\" /data/local/tmp/minitouch",
"pushing minitouch",
60000)) return;
if (!RunCheckedInjectionAdbCommand(
instanceId,
"shell chmod 777 /data/local/tmp/minitouch",
"setting minitouch permissions")) return;
std::vector<std::string> filesToVerify = {
dataDir + "languages.csv",
ZOOM_DATA_PATH,
scDir + "nature_new.sc",
scDir + "nature_new_0.sctx",
scDir + "nature_new_1.sctx",
scDir + "nature_new_2.sctx",
scDir + "nature_new_3.sctx",
"/data/local/tmp/minitouch"
};
for (const std::string& remoteFile : filesToVerify) {
if (!VerifyInjectedRemoteFile(instanceId, remoteFile)) return;
}
AddLog(instanceId, Tr("All injected files were verified on the emulator."), ImVec4(0, 1, 0, 1));
StartMinitouchStealth(instanceId);
std::this_thread::sleep_for(std::chrono::milliseconds(g_Intervals.tapResponseWait));
AddLog(instanceId, Tr("Injection completed. All files were pushed and verified."), ImVec4(0, 1, 0, 1));
}).detach();
}
// ACCOUNT SAVER
void SaveAccountToSlot(int instanceId, int slotIndex) {
if (!RequireConfiguredEmulatorPaths(instanceId)) return;
AddLog(instanceId, Tr("Saving & Encrypting Account Data..."), ImVec4(1, 1, 0, 1));
// DOĞRUDAN SENİN EXTERN FONKSİYONUNU KULLANIYORUZ
std::string folderPath = GetAppDataPath() + "\\Backups\\Instance_" + std::to_string(instanceId);
if (!fs::exists(folderPath)) fs::create_directories(folderPath);
std::string pcFileName = folderPath + "\\account_" + std::to_string(slotIndex + 1) + ".nxrth";
std::string tempRawFile = folderPath + "\\temp_raw.xml";
std::string tempSdFile = "/sdcard/temp_backup_" + std::to_string(instanceId) + ".xml";
std::string copyCmd = "shell \"su -c 'cat " + GAME_DATA_PATH + " > " + tempSdFile + "'\"";
RunAdbCommand(instanceId, copyCmd);
std::string pullCmd = "pull " + tempSdFile + " \"" + tempRawFile + "\"";
RunAdbCommand(instanceId, pullCmd);
RunAdbCommand(instanceId, "shell rm " + tempSdFile);
std::this_thread::sleep_for(std::chrono::milliseconds(g_Intervals.tapResponseWait));
if (fs::exists(tempRawFile) && fs::file_size(tempRawFile) > 0) {
std::ifstream inFile(tempRawFile, std::ios::binary);
std::string rawData((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
inFile.close();
std::string encryptedData = EncryptXORHex(rawData, "NXRTH_LOCAL_ACCOUNT_KEY"); // SUPER DUPER SECRET KEY
std::ofstream outFile(pcFileName, std::ios::binary);
outFile << encryptedData;
outFile.close();
fs::remove(tempRawFile);
g_Bots[instanceId].accounts[slotIndex].hasFile = true;
g_Bots[instanceId].accounts[slotIndex].fileName = pcFileName;
AddLog(instanceId, Tr("Account Saved & Encrypted Successfully."), ImVec4(0, 1, 0, 1));
}
else {
AddLog(instanceId, Tr("Save Failed. Check Settings."), ImVec4(1, 0, 0, 1));
}
}
// =========================================================
// DECRYPT FUNCTION FOR ACCOUNTS N OTHER STUFF USED.
// =========================================================
std::string DecryptPureXORHex(const std::string& hexStr, const std::string& key) {
std::string text;
if (hexStr.length() % 2 != 0) return "";
for (size_t i = 0; i < hexStr.length(); i += 2) {
std::string byteString = hexStr.substr(i, 2);
char byte = (char)strtol(byteString.c_str(), NULL, 16);
text += (byte ^ key[(i / 2) % key.length()]);
}
return text;
}
// =========================================================
// ACCOUNT LOADER
// =========================================================
void LoadAccountFromSlot(int instanceId, int slotIndex) {
if (!RequireConfiguredEmulatorPaths(instanceId)) return;
// DOĞRUDAN SENİN EXTERN FONKSİYONUNU KULLANIYORUZ
std::string folderPath = GetAppDataPath() + "\\Backups\\Instance_" + std::to_string(instanceId);
std::string pcFileName = folderPath + "\\account_" + std::to_string(slotIndex + 1) + ".nxrth";
if (!fs::exists(pcFileName)) {
AddLog(instanceId, Tr("Error: Slot file empty or missing!"), ImVec4(1, 0, 0, 1));
return;
}
AddLog(instanceId, Tr("Decrypting & Switching Account..."), ImVec4(1, 1, 0, 1));
std::ifstream inFile(pcFileName, std::ios::binary);
std::string encryptedData((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>());
inFile.close();
// 1. DECRYPT ACCOUNT FILES ACCOUNT*.NXRTH'S.
std::string rawData = DecryptXORHex(encryptedData, "NXRTH_LOCAL_ACCOUNT_KEY");
if (rawData.find("<?xml") == std::string::npos) {
rawData = DecryptPureXORHex(encryptedData, "NXRTH_LOCAL_ACCOUNT_KEY");
}
if (rawData.empty() || rawData.find("<?xml") == std::string::npos) {
AddLog(instanceId, Tr("Error: File decryption failed! Corrupted data."), ImVec4(1, 0, 0, 1));
return;
}
std::string tempRawFile = folderPath + "\\temp_decrypted.xml";
std::ofstream outFile(tempRawFile, std::ios::binary);
outFile << rawData;
outFile.close();
RunAdbCommand(instanceId, "shell am force-stop com.supercell.hayday");
std::string tempSdFile = "/sdcard/temp_restore_" + std::to_string(instanceId) + ".xml";
std::string pushCmd = "push \"" + tempRawFile + "\" " + tempSdFile;
RunAdbCommand(instanceId, pushCmd);
// REMOVE THE LEGACY STORAGE.XML BEFORE INSTALLING STORAGE_NEW.XML.
RunAdbCommand(
instanceId,
"shell \"su -c 'rm -f /data/data/com.supercell.hayday/shared_prefs/storage.xml'\"");
// RENAME THE ACTUAL FILE TO STORAGE_NEW.XML
std::string moveCmd = "shell \"su -c 'cat " + tempSdFile + " > /data/data/com.supercell.hayday/shared_prefs/storage_new.xml'\"";
RunAdbCommand(instanceId, moveCmd);
RunAdbCommand(instanceId, "shell \"su -c 'chmod 777 /data/data/com.supercell.hayday/shared_prefs/storage_new.xml'\"");
RunAdbCommand(instanceId, "shell rm " + tempSdFile);
fs::remove(tempRawFile);
std::this_thread::sleep_for(std::chrono::milliseconds(g_Intervals.pageLoadWait));
RunAdbCommand(instanceId, "shell monkey -p com.supercell.hayday -c android.intent.category.LAUNCHER 1");
AddLog(instanceId, Tr("Account Switched. Game Restarting."), ImVec4(0, 1, 0, 1));
}
// AUTO DETECT FOR TOUCH DEVICE (EVENT NUMBER) BECAUSE SOME PEOPLE CAN FORGET USING MANUALLY.
bool AutoDetectTouchDevice(int instanceId) {
AddLog(instanceId, Tr("Detecting Input..."), ImVec4(1, 1, 0, 1));
std::string tempFile = "C:\\Users\\Public\\devicelist_" + std::to_string(instanceId) + ".txt";
remove(tempFile.c_str());
std::string cmd = "cmd /c \"\"" + kAdbPath + "\" -s " + std::string(g_Bots[instanceId].adbSerial) + " shell getevent -pl > \"" + tempFile + "\"\"";
RunCmdHidden(cmd);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
std::ifstream file(tempFile);
if (!file.is_open()) {
AddLog(instanceId, Tr("Error: Could not read list. Check ADB path."), ImVec4(1, 0, 0, 1));
return false;
}
std::string line;
std::string currentDevice = "";
bool found = false;
while (std::getline(file, line)) {
if (line.find("add device") != std::string::npos && line.find("/dev/input/") != std::string::npos) {
size_t startPos = line.find("/dev/input/");
currentDevice = line.substr(startPos);
currentDevice.erase(std::remove(currentDevice.begin(), currentDevice.end(), '\r'), currentDevice.end());
currentDevice.erase(std::remove(currentDevice.begin(), currentDevice.end(), '\n'), currentDevice.end());
}
if (!currentDevice.empty()) {
if (line.find("ABS_MT_POSITION_X") != std::string::npos || line.find("0035") != std::string::npos) {
strcpy(g_Bots[instanceId].inputDevice, currentDevice.c_str());
AddLog(instanceId, std::string(Tr("Input Found: ")) + std::string(g_Bots[instanceId].inputDevice), ImVec4(0, 1, 0, 1));
found = true;
break;
}
}
}
file.close();
if (!found) {