11#include " ErScripts.h"
22
33void ErScripts::AutoAccept () {
4- std::thread ([this ]() {
5- const std::vector<int > targetColor = { 54 , 183 , 82 };
4+ std::thread ([this ]() {
5+ const std::vector<int > targetColor = { 54 , 183 , 82 };
66
7- while (!globals::finish) {
8- if (cfg->autoAcceptState ) {
9- if (foundMatch) {
10- foundMatch = false ;
7+ while (!globals::finish) {
8+ if (cfg->autoAcceptState ) {
9+ if (foundMatch) {
10+ foundMatch = false ;
1111
12- POINT mousePos;
13- GetCursorPos (&mousePos);
12+ POINT mousePos;
13+ GetCursorPos (&mousePos);
1414
15- bool isInCS2 = GetWindowState ();
15+ bool isInCS2 = GetWindowState ();
1616
17- // Maximize cs2
18- ShowWindow (hwnd, SW_RESTORE);
19- SetForegroundWindow (hwnd);
17+ // Maximize cs2
18+ ShowWindow (hwnd, SW_RESTORE);
19+ SetForegroundWindow (hwnd);
2020
21- bool colorState = false ;
22- auto startTime = std::chrono::steady_clock::now ();
21+ bool colorState = false ;
22+ auto startTime = std::chrono::steady_clock::now ();
2323
24- while (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now () - startTime).count () <= cfg->autoAcceptWaitingTime ) {
25- int buttonX = static_cast <int >(round (globals::width / 2 .f + globals::posX)), buttonY = static_cast <int >(round (globals::height / 2 .215f + globals::posY));
24+ while (std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now () - startTime).count () <= cfg->autoAcceptWaitingTime ) {
25+ int buttonX = static_cast <int >(round (globals::width / 2 .f + globals::posX)), buttonY = static_cast <int >(round (globals::height / 2 .215f + globals::posY));
2626
27- if (GetWindowState ()) {
28- std::vector color = GetPixelColor (buttonX, buttonY);
27+ if (GetWindowState ()) {
28+ std::vector color = GetPixelColor (buttonX, buttonY);
2929
30- if (isColorSimilar (targetColor, color, 20 )) {
31- colorState = true ;
32- Logger::logInfo (" AutoAccept button clicking" );
30+ if (isColorSimilar (targetColor, color, 20 )) {
31+ colorState = true ;
32+ Logger::logInfo (" AutoAccept button clicking" );
3333
34- // Move cursor to correct position
35- SetCursorPos (buttonX, buttonY);
36- std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
34+ // Move cursor to correct position
35+ SetCursorPos (buttonX, buttonY);
36+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
3737
38- // Click accept button
39- mouse_event (MOUSEEVENTF_LEFTDOWN, 0 , 0 , 0 , 0 );
40- std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
41- mouse_event (MOUSEEVENTF_LEFTUP, 0 , 0 , 0 , 0 );
42- }
43- else if (colorState) {
44- break ;
45- }
46- }
47- std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
48- }
38+ // Click accept button
39+ mouse_event (MOUSEEVENTF_LEFTDOWN, 0 , 0 , 0 , 0 );
40+ std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
41+ mouse_event (MOUSEEVENTF_LEFTUP, 0 , 0 , 0 , 0 );
42+ }
43+ else if (colorState) {
44+ break ;
45+ }
46+ }
47+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
48+ }
4949
50- if (!isInCS2) {
51- Keyboard (56 , true , false );
52- std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
53- Keyboard (15 , true , false );
54- std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
55- Keyboard (15 , false , false );
56- std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
57- Keyboard (56 , false , false );
58- }
50+ if (!isInCS2) {
51+ Keyboard (56 , true , false );
52+ std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
53+ Keyboard (15 , true , false );
54+ std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
55+ Keyboard (15 , false , false );
56+ std::this_thread::sleep_for (std::chrono::milliseconds ((std::rand () % 32 ) + 16 ));
57+ Keyboard (56 , false , false );
58+ }
5959
60- SetCursorPos (mousePos.x , mousePos.y );
61- }
62- }
63- std::this_thread::sleep_for (std::chrono::microseconds (15625 ));
64- }
65- }).detach ();
60+ SetCursorPos (mousePos.x , mousePos.y );
61+ }
62+ }
63+ std::this_thread::sleep_for (std::chrono::microseconds (15625 ));
64+ }
65+ }).detach ();
6666}
0 commit comments