@@ -73,17 +73,19 @@ void checkRegistry();
7373void error (std::string message);
7474std::string generate_random_number ();
7575std::string seed;
76+ void cleanUpSeedData (const std::string& seed);
7677std::string signature;
7778std::string signatureTimestamp;
7879bool initialized;
7980std::string API_PUBLIC_KEY = " 5586b4bc69c7a4b487e4563a4cd96afd39140f919bd31cea7d1c6a1e8439422b" ;
8081bool KeyAuth::api::debug = false ;
82+ std::atomic<bool > LoggedIn (false );
8183
8284void KeyAuth::api::init ()
8385{
84- CreateThread ( 0 , 0 , (LPTHREAD_START_ROUTINE) runChecks, 0 , 0 , 0 );
85- std::string random_num = generate_random_number ();
86- seed = random_num ;
86+ std::thread ( runChecks). detach ( );
87+ seed = generate_random_number ();
88+ std::atexit ([]() { cleanUpSeedData (seed); }) ;
8789 CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)modify, 0 , 0 , 0 );
8890
8991 if (ownerid.length () != 10 )
@@ -293,6 +295,7 @@ void KeyAuth::api::login(std::string username, std::string password, std::string
293295 }
294296
295297 LI_FN (GlobalAddAtomA)(ownerid.c_str ());
298+ LoggedIn.store (true );
296299 }
297300 else {
298301 LI_FN (exit)(12 );
@@ -741,6 +744,7 @@ void KeyAuth::api::web_login()
741744 }
742745
743746 LI_FN (GlobalAddAtomA)(ownerid.c_str ());
747+ LoggedIn.store (true );
744748 }
745749 else {
746750 LI_FN (exit)(12 );
@@ -989,6 +993,7 @@ void KeyAuth::api::regstr(std::string username, std::string password, std::strin
989993 }
990994
991995 LI_FN (GlobalAddAtomA)(ownerid.c_str ());
996+ LoggedIn.store (true );
992997 }
993998 else {
994999 LI_FN (exit)(12 );
@@ -1061,11 +1066,6 @@ std::string generate_random_number() {
10611066}
10621067
10631068void KeyAuth::api::license (std::string key, std::string code) {
1064- // Call threads to start in 15 seconds..
1065- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)checkAtoms, 0 , 0 , 0 );
1066- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)checkFiles, 0 , 0 , 0 );
1067- CreateThread (0 , 0 , (LPTHREAD_START_ROUTINE)checkRegistry, 0 , 0 , 0 );
1068-
10691069 checkInit ();
10701070
10711071 std::string hwid = utils::get_hwid ();
@@ -1119,6 +1119,7 @@ void KeyAuth::api::license(std::string key, std::string code) {
11191119 }
11201120
11211121 LI_FN (GlobalAddAtomA)(ownerid.c_str ());
1122+ LoggedIn.store (true );
11221123 }
11231124 else {
11241125 LI_FN (exit)(12 );
@@ -1800,15 +1801,25 @@ auto check_section_integrity( const char *section_name, bool fix = false ) -> bo
18001801}
18011802
18021803void runChecks () {
1803- Sleep (45000 ); // give people 1 minute to login. (because the functions we call already wait 15 seconds)
1804-
1805- checkAtoms ();
1806- checkFiles ();
1807- checkRegistry ();
1804+ // Wait before starting checks
1805+ int waitTime = 45000 ;
1806+ while (waitTime > 0 ) {
1807+
1808+ if (LoggedIn.load ()) {
1809+ // If the user is logged in, proceed with the checks immediately
1810+ break ;
1811+ }
1812+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
1813+ waitTime -= 1000 ;
1814+ }
1815+
1816+ // Create separate threads for each check
1817+ std::thread (checkAtoms).detach ();
1818+ std::thread (checkFiles).detach ();
1819+ std::thread (checkRegistry).detach ();
18081820}
18091821
18101822void checkAtoms () {
1811- Sleep (15000 ); // enough time for API response, even on slower connections
18121823
18131824 while (true ) {
18141825 if (LI_FN (GlobalFindAtomA)(seed.c_str ()) == 0 ) {
@@ -1820,7 +1831,6 @@ void checkAtoms() {
18201831}
18211832
18221833void checkFiles () {
1823- Sleep (15000 ); // enough time for API response, even on slower connections
18241834
18251835 while (true ) {
18261836 std::string file_path = XorStr (" C:\\ ProgramData\\ " ).c_str () + seed;
@@ -1834,8 +1844,7 @@ void checkFiles() {
18341844}
18351845
18361846void checkRegistry () {
1837- Sleep (15000 ); // enough time for API response, even on slower connections
1838-
1847+
18391848 while (true ) {
18401849 std::string regPath = XorStr (" Software\\ " ).c_str () + seed;
18411850 HKEY hKey;
@@ -1845,8 +1854,8 @@ void checkRegistry() {
18451854 LI_FN (__fastfail)(0 );
18461855 }
18471856 LI_FN (RegCloseKey)(hKey);
1857+ Sleep (1500 ); // thread interval
18481858 }
1849- Sleep (1500 ); // thread interval
18501859}
18511860
18521861std::string checksum ()
@@ -2081,3 +2090,17 @@ void modify()
20812090 Sleep (50 );
20822091 }
20832092}
2093+
2094+ // Clean up seed data (file and registry key)
2095+ void cleanUpSeedData (const std::string& seed) {
2096+
2097+ // Clean up the seed file
2098+ std::string file_path = " C:\\ ProgramData\\ " + seed;
2099+ if (std::filesystem::exists (file_path)) {
2100+ std::filesystem::remove (file_path);
2101+ }
2102+
2103+ // Clean up the seed registry entry
2104+ std::string regPath = " Software\\ " + seed;
2105+ RegDeleteKeyA (HKEY_CURRENT_USER, regPath.c_str ());
2106+ }
0 commit comments