From ab2a58bf4223bf6462c527a7acd156f2eece4cd2 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sat, 26 Dec 2020 22:52:01 +0200 Subject: [PATCH 01/13] switched to normal filesystem + crash fixes --- src/Network/Resources.cpp | 14 +++++----- src/Security/BeamNG.cpp | 12 ++++++--- src/Security/Login.cpp | 6 +++++ src/Startup.cpp | 56 ++++++++++++--------------------------- src/main.cpp | 7 ++--- 5 files changed, 43 insertions(+), 52 deletions(-) diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index ff492d2..7fedca6 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -21,7 +21,7 @@ #include #include -namespace fs = std::experimental::filesystem; +namespace fs = std::filesystem; std::string ListOfMods; std::vector Split(const std::string& String,const std::string& delimiter){ std::vector Val; @@ -126,11 +126,10 @@ char* TCPRcvRaw(SOCKET Sock,uint64_t& GRcv, uint64_t Size){ } char* File = new char[Size]; uint64_t Rcv = 0; - int32_t Temp; do{ int Len = int(Size-Rcv); if(Len > 1000000)Len = 1000000; - Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL); + int32_t Temp = recv(Sock, &File[Rcv], Len, MSG_WAITALL); if(Temp < 1){ info(std::to_string(Temp)); UUl("Socket Closed Code 1"); @@ -153,6 +152,7 @@ SOCKET InitDSock(){ SOCKET DSock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); SOCKADDR_IN ServerAddr; if(DSock < 1){ + KillSocket(DSock); Terminate = true; return 0; } @@ -244,6 +244,7 @@ void SyncResources(SOCKET Sock){ } if(!FNames.empty())info("Syncing..."); SOCKET DSock = InitDSock(); + uint64_t ModSize; for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) { auto pos = FN->find_last_of('/'); if (pos != std::string::npos) { @@ -252,7 +253,8 @@ void SyncResources(SOCKET Sock){ Pos++; if (fs::exists(a)) { if (FS->find_first_not_of("0123456789") != std::string::npos)continue; - if (fs::file_size(a) == std::stoi(*FS)){ + ModSize = std::stoull(*FS); + if (fs::file_size(a) == ModSize){ UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/'))); std::this_thread::sleep_for(std::chrono::milliseconds(50)); try { @@ -284,7 +286,7 @@ void SyncResources(SOCKET Sock){ std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName; - Data = MultiDownload(Sock,DSock,std::stoull(*FS), Name); + Data = MultiDownload(Sock,DSock,ModSize, Name); if(Terminate)break; UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName); @@ -295,7 +297,7 @@ void SyncResources(SOCKET Sock){ LFS.close(); } - }while(fs::file_size(a) != std::stoi(*FS) && !Terminate); + }while(fs::file_size(a) != ModSize && !Terminate); if(!Terminate){ if(!fs::exists(GetGamePath() + "mods/multiplayer")){ fs::create_directory(GetGamePath() + "mods/multiplayer"); diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 74ea8a6..6a99d90 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #define MAX_KEY_LENGTH 255 #define MAX_VALUE_NAME 16383 @@ -124,11 +125,10 @@ std::string QueryKey(HKEY hKey,int ID){ delete [] buffer; return ""; } -namespace fs = std::experimental::filesystem; +namespace fs = std::filesystem; void FileList(std::vector&a,const std::string& Path){ for (const auto &entry : fs::directory_iterator(Path)) { - auto pos = entry.path().filename().string().find('.'); - if (pos != std::string::npos) { + if (!entry.is_directory()) { a.emplace_back(entry.path().string()); }else FileList(a,entry.path().string()); } @@ -241,18 +241,22 @@ void LegitimacyCheck(){ std::string K2 = R"(Software\Valve\Steam\Apps\284160)"; std::string K3 = R"(Software\BeamNG\BeamNG.drive)"; HKEY hKey; + LONG dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K1.c_str(), &hKey); + if(dwRegOPenKey == ERROR_SUCCESS) { Result = QueryKey(hKey, 1); if(Result.empty())Exit(1); if(fs::exists(Result)){ - if(!Find("284160.json",Result))Exit(2); + if(!Find("284160.json", Result))Exit(2); if(FindHack(Result))SteamExit(1); }else Exit(3); + T = Result; Result.clear(); TraceBack++; }else Exit(4); + K1.clear(); RegCloseKey(hKey); dwRegOPenKey = OpenKey(HKEY_CURRENT_USER, K2.c_str(), &hKey); diff --git a/src/Security/Login.cpp b/src/Security/Login.cpp index ce08b7d..9c8d022 100644 --- a/src/Security/Login.cpp +++ b/src/Security/Login.cpp @@ -40,6 +40,11 @@ std::string GetFail(const std::string& R){ } std::string Login(const std::string& fields){ + if(fields == "LO"){ + LoginAuth = false; + UpdateKey(nullptr); + return ""; + } info("Attempting to authenticate..."); std::string Buffer = PostHTTP("https://auth.beammp.com/userlogin", fields); json::Document d; @@ -47,6 +52,7 @@ std::string Login(const std::string& fields){ if(Buffer == "-1"){ return GetFail("Failed to communicate with the auth system!"); } + if (Buffer.find('{') == -1 || d.HasParseError()) { return GetFail("Invalid answer from authentication servers, please try again later!"); } diff --git a/src/Startup.cpp b/src/Startup.cpp index d5ef74f..8f93ca8 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -19,7 +19,7 @@ extern int TraceBack; bool Dev = false; -namespace fs = std::experimental::filesystem; +namespace fs = std::filesystem; std::string GetEN(){ return "BeamMP-Launcher.exe"; } @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".2"; + return ".3"; } void ReLaunch(int argc,char*args[]){ std::string Arg; @@ -182,7 +182,7 @@ void InitLauncher(int argc, char* argv[]) { CheckName(argc, argv); CheckLocalKey(); //will replace RequestRole Discord_Main(); - Dev = true; + //Dev = true; //RequestRole(); CustomPort(argc, argv); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); @@ -190,47 +190,25 @@ void InitLauncher(int argc, char* argv[]) { void PreGame(int argc, char* argv[],const std::string& GamePath){ info("Game Version : " + CheckVer(GamePath)); - std::string DUI = R"(BeamNG\settings\uiapps-layouts.json)"; - std::string GS = R"(BeamNG\settings\game-settings.ini)"; - std::string link = "https://beammp.com/client-ui-data"; - bool fallback = false; - int i; - if(!fs::exists(DUI)){ - info("Downloading default ui data..."); - i = Download(link,DUI,true); - if(i != -1){ - fallback = true; - remove(DUI.c_str()); - link = "https://backup1.beammp.com/client-ui-data"; - i = Download(link,DUI,true); - if(i != -1) { - error("Failed to download code : " + std::to_string(i)); - std::this_thread::sleep_for(std::chrono::seconds(3)); - ReLaunch(argc, argv); - } - } - info("Download Complete!"); - } - if(!fs::exists(GS)) { - info("Downloading default game settings..."); - if(fallback)link = "https://backup1.beammp.com/client-settings-data"; - else link = "https://beammp.com/client-settings-data"; - Download(link, GS,true); - info("Download Complete!"); - } + if(!Dev) { info("Downloading mod..."); - if(fallback)link = "https://backup1.beammp.com/builds/client"; - else link ="https://beammp.com/builds/client"; - if(!fs::exists(GetGamePath() + "mods")){ - fs::create_directory(GetGamePath() + "mods"); + //if(fallback)link = "https://backup1.beammp.com/builds/client"; + std::string link = "https://beammp.com/builds/client"; + try { + if (!fs::exists(GetGamePath() + "mods")) { + fs::create_directory(GetGamePath() + "mods"); + } + if (!fs::exists(GetGamePath() + "mods/multiplayer")) { + fs::create_directory(GetGamePath() + "mods/multiplayer"); + } + }catch(std::exception&e){ + fatal(e.what()); } - if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); - } - Download(link, GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true); + Download(link, GetGamePath() + R"(mods/multiplayer/BeamMP.zip)", true); info("Download Complete!"); } + /*debug("Name : " + GetDName()); debug("Discriminator : " + GetDTag()); debug("Unique ID : " + GetDID());*/ diff --git a/src/main.cpp b/src/main.cpp index 73f2898..0cdf2eb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,13 +8,14 @@ #include "Network/network.h" #include "Security/Init.h" #include "Startup.h" -#include #include +#include + [[noreturn]] void flush(){ while(true){ std::cout.flush(); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } } @@ -24,7 +25,7 @@ int main(int argc, char* argv[]) { th.detach(); #endif InitLauncher(argc,argv); - CheckDir(argc,argv); + //CheckDir(argc,argv); LegitimacyCheck(); PreGame(argc,argv,GetGameDir()); InitGame(GetGameDir()); From 9a04665c3448daccdbe0c4ac63b377fdccdfebbc Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sat, 26 Dec 2020 23:35:43 +0200 Subject: [PATCH 02/13] Unicode path support --- include/Security/Init.h | 2 +- include/Startup.h | 2 +- src/GameStart.cpp | 14 ++++++++------ src/Network/Resources.cpp | 13 +++++++------ src/Startup.cpp | 19 +++++++++++++------ src/main.cpp | 2 +- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/include/Security/Init.h b/include/Security/Init.h index 7a1d0ea..c6f3db7 100644 --- a/include/Security/Init.h +++ b/include/Security/Init.h @@ -7,7 +7,7 @@ /// #pragma once #include -void PreGame(int argc, char* argv[],const std::string& GamePath); +void PreGame(const std::string& GamePath); std::string CheckVer(const std::string &path); void InitGame(const std::string& Dir); std::string GetGameDir(); diff --git a/include/Startup.h b/include/Startup.h index d0ed404..f2e9d45 100644 --- a/include/Startup.h +++ b/include/Startup.h @@ -9,7 +9,7 @@ #include void InitLauncher(int argc, char* argv[]); void CheckDir(int argc,char* args[]); -std::string GetGamePath(); +std::wstring GetGamePath(); std::string GetVer(); std::string GetEN(); extern bool Dev; \ No newline at end of file diff --git a/src/GameStart.cpp b/src/GameStart.cpp index 1536f5e..c6a69d7 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -11,12 +11,14 @@ #include #include "Logger.h" #include +#include #include +#include unsigned long GamePID = 0; std::string QueryKey(HKEY hKey,int ID); -std::string GetGamePath(){ - static std::string Path; +std::wstring GetGamePath(){ + static std::wstring Path; if(!Path.empty())return Path; HKEY hKey; @@ -25,7 +27,8 @@ std::string GetGamePath(){ if (openRes != ERROR_SUCCESS){ fatal("Please launch the game at least once"); } - Path = QueryKey(hKey,4); + std::string T = QueryKey(hKey,4); + Path = std::wstring(T.begin(),T.end()); if(Path.empty()){ CoInitialize(nullptr); @@ -33,9 +36,8 @@ std::string GetGamePath(){ SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path)); CoTaskMemFree(path); std::wstring ws(path); - std::string s(ws.begin(), ws.end()); - Path = s; - Path += "\\BeamNG.drive\\"; + ws += L"\\BeamNG.drive\\"; + return ws; } return Path; diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 7fedca6..cff99be 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -258,10 +258,11 @@ void SyncResources(SOCKET Sock){ UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/'))); std::this_thread::sleep_for(std::chrono::milliseconds(50)); try { - if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); + if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ + fs::create_directory(GetGamePath() + L"mods/multiplayer"); } - fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')), + std::string P = "mods/multiplayer" + a.substr(a.find_last_of('/')); + fs::copy_file(a, GetGamePath() + std::wstring(P.begin(),P.end()), fs::copy_options::overwrite_existing); } catch (std::exception& e) { error("Failed copy to the mods folder! " + std::string(e.what())); @@ -299,10 +300,10 @@ void SyncResources(SOCKET Sock){ }while(fs::file_size(a) != ModSize && !Terminate); if(!Terminate){ - if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); + if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ + fs::create_directory(GetGamePath() + L"mods/multiplayer"); } - fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing); + fs::copy_file(a,GetGamePath() + L"mods/multiplayer" + std::wstring(FName.begin(),FName.end()), fs::copy_options::overwrite_existing); } WaitForConfirm(); } diff --git a/src/Startup.cpp b/src/Startup.cpp index 8f93ca8..cbfadb0 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -187,8 +187,14 @@ void InitLauncher(int argc, char* argv[]) { CustomPort(argc, argv); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); } +inline std::string to_string(const std::wstring& str){ + auto loc = std::locale{}; + std::vector buf(str.size()); + std::use_facet>(loc).narrow(str.data(), str.data() + str.size(), '?', buf.data()); -void PreGame(int argc, char* argv[],const std::string& GamePath){ + return std::string(buf.data(), buf.size()); +} +void PreGame(const std::string& GamePath){ info("Game Version : " + CheckVer(GamePath)); if(!Dev) { @@ -196,16 +202,17 @@ void PreGame(int argc, char* argv[],const std::string& GamePath){ //if(fallback)link = "https://backup1.beammp.com/builds/client"; std::string link = "https://beammp.com/builds/client"; try { - if (!fs::exists(GetGamePath() + "mods")) { - fs::create_directory(GetGamePath() + "mods"); + if (!fs::exists(GetGamePath() + L"mods")) { + fs::create_directory(GetGamePath() + L"mods"); } - if (!fs::exists(GetGamePath() + "mods/multiplayer")) { - fs::create_directory(GetGamePath() + "mods/multiplayer"); + if (!fs::exists(GetGamePath() + L"mods/multiplayer")) { + fs::create_directory(GetGamePath() + L"mods/multiplayer"); } + std::wstring P = GetGamePath() + LR"(mods/multiplayer/BeamMP.zip)"; + Download(link, to_string(P), true); }catch(std::exception&e){ fatal(e.what()); } - Download(link, GetGamePath() + R"(mods/multiplayer/BeamMP.zip)", true); info("Download Complete!"); } diff --git a/src/main.cpp b/src/main.cpp index 0cdf2eb..a6fcbfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) { InitLauncher(argc,argv); //CheckDir(argc,argv); LegitimacyCheck(); - PreGame(argc,argv,GetGameDir()); + PreGame(GetGameDir()); InitGame(GetGameDir()); CoreNetwork(); } From 9f821a01f07d775453b04f95ad827e34e0644cfe Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 00:23:58 +0200 Subject: [PATCH 03/13] Mod downloading hotfix --- src/Network/Resources.cpp | 8 +++----- src/Startup.cpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index cff99be..19ae203 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -244,7 +244,6 @@ void SyncResources(SOCKET Sock){ } if(!FNames.empty())info("Syncing..."); SOCKET DSock = InitDSock(); - uint64_t ModSize; for(auto FN = FNames.begin(),FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN,++FS) { auto pos = FN->find_last_of('/'); if (pos != std::string::npos) { @@ -253,8 +252,7 @@ void SyncResources(SOCKET Sock){ Pos++; if (fs::exists(a)) { if (FS->find_first_not_of("0123456789") != std::string::npos)continue; - ModSize = std::stoull(*FS); - if (fs::file_size(a) == ModSize){ + if (fs::file_size(a) == std::stoull(*FS)){ UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/'))); std::this_thread::sleep_for(std::chrono::milliseconds(50)); try { @@ -287,7 +285,7 @@ void SyncResources(SOCKET Sock){ std::string Name = std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + FName; - Data = MultiDownload(Sock,DSock,ModSize, Name); + Data = MultiDownload(Sock,DSock,std::stoull(*FS), Name); if(Terminate)break; UpdateUl(false,std::to_string(Pos)+"/"+std::to_string(Amount)+": "+FName); @@ -298,7 +296,7 @@ void SyncResources(SOCKET Sock){ LFS.close(); } - }while(fs::file_size(a) != ModSize && !Terminate); + }while(fs::file_size(a) != std::stoull(*FS) && !Terminate); if(!Terminate){ if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ fs::create_directory(GetGamePath() + L"mods/multiplayer"); diff --git a/src/Startup.cpp b/src/Startup.cpp index cbfadb0..7326e82 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".3"; + return ".4"; } void ReLaunch(int argc,char*args[]){ std::string Arg; From e207f2febde175fca04af1ac33d88e85bfa55245 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 05:14:02 +0200 Subject: [PATCH 04/13] Potential default dir fix --- include/Startup.h | 2 +- src/GameStart.cpp | 23 +++++++++-------------- src/Network/Resources.cpp | 13 ++++++------- src/Startup.cpp | 21 ++++++--------------- 4 files changed, 22 insertions(+), 37 deletions(-) diff --git a/include/Startup.h b/include/Startup.h index f2e9d45..d0ed404 100644 --- a/include/Startup.h +++ b/include/Startup.h @@ -9,7 +9,7 @@ #include void InitLauncher(int argc, char* argv[]); void CheckDir(int argc,char* args[]); -std::wstring GetGamePath(); +std::string GetGamePath(); std::string GetVer(); std::string GetEN(); extern bool Dev; \ No newline at end of file diff --git a/src/GameStart.cpp b/src/GameStart.cpp index c6a69d7..fb9d5bc 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -8,17 +8,14 @@ #include #include "Startup.h" -#include #include "Logger.h" #include -#include #include -#include unsigned long GamePID = 0; std::string QueryKey(HKEY hKey,int ID); -std::wstring GetGamePath(){ - static std::wstring Path; +std::string GetGamePath(){ + static std::string Path; if(!Path.empty())return Path; HKEY hKey; @@ -27,17 +24,15 @@ std::wstring GetGamePath(){ if (openRes != ERROR_SUCCESS){ fatal("Please launch the game at least once"); } - std::string T = QueryKey(hKey,4); - Path = std::wstring(T.begin(),T.end()); + Path = QueryKey(hKey,4); if(Path.empty()){ - CoInitialize(nullptr); - wchar_t * path = nullptr; - SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path)); - CoTaskMemFree(path); - std::wstring ws(path); - ws += L"\\BeamNG.drive\\"; - return ws; + size_t RS; + getenv_s(&RS, nullptr, 0, "USERPROFILE"); + std::string P(RS-1,0); + getenv_s(&RS, &P[0], RS, "USERPROFILE"); + Path = P + R"(\Documents\BeamNG.drive\)"; + return Path; } return Path; diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 19ae203..4333a96 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -256,11 +256,10 @@ void SyncResources(SOCKET Sock){ UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/'))); std::this_thread::sleep_for(std::chrono::milliseconds(50)); try { - if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ - fs::create_directory(GetGamePath() + L"mods/multiplayer"); + if(!fs::exists(GetGamePath() + "mods/multiplayer")){ + fs::create_directory(GetGamePath() + "mods/multiplayer"); } - std::string P = "mods/multiplayer" + a.substr(a.find_last_of('/')); - fs::copy_file(a, GetGamePath() + std::wstring(P.begin(),P.end()), + fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing); } catch (std::exception& e) { error("Failed copy to the mods folder! " + std::string(e.what())); @@ -298,10 +297,10 @@ void SyncResources(SOCKET Sock){ }while(fs::file_size(a) != std::stoull(*FS) && !Terminate); if(!Terminate){ - if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ - fs::create_directory(GetGamePath() + L"mods/multiplayer"); + if(!fs::exists(GetGamePath() + "mods/multiplayer")){ + fs::create_directory(GetGamePath() + "mods/multiplayer"); } - fs::copy_file(a,GetGamePath() + L"mods/multiplayer" + std::wstring(FName.begin(),FName.end()), fs::copy_options::overwrite_existing); + fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing); } WaitForConfirm(); } diff --git a/src/Startup.cpp b/src/Startup.cpp index 7326e82..e3436e6 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".4"; + return ".5"; } void ReLaunch(int argc,char*args[]){ std::string Arg; @@ -187,32 +187,23 @@ void InitLauncher(int argc, char* argv[]) { CustomPort(argc, argv); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); } -inline std::string to_string(const std::wstring& str){ - auto loc = std::locale{}; - std::vector buf(str.size()); - std::use_facet>(loc).narrow(str.data(), str.data() + str.size(), '?', buf.data()); - return std::string(buf.data(), buf.size()); -} void PreGame(const std::string& GamePath){ info("Game Version : " + CheckVer(GamePath)); if(!Dev) { info("Downloading mod..."); - //if(fallback)link = "https://backup1.beammp.com/builds/client"; - std::string link = "https://beammp.com/builds/client"; try { - if (!fs::exists(GetGamePath() + L"mods")) { - fs::create_directory(GetGamePath() + L"mods"); + if (!fs::exists(GetGamePath() + "mods")) { + fs::create_directory(GetGamePath() + "mods"); } - if (!fs::exists(GetGamePath() + L"mods/multiplayer")) { - fs::create_directory(GetGamePath() + L"mods/multiplayer"); + if (!fs::exists(GetGamePath() + "mods/multiplayer")) { + fs::create_directory(GetGamePath() + "mods/multiplayer"); } - std::wstring P = GetGamePath() + LR"(mods/multiplayer/BeamMP.zip)"; - Download(link, to_string(P), true); }catch(std::exception&e){ fatal(e.what()); } + Download("https://beammp.com/builds/client", GetGamePath() + R"(mods\multiplayer\BeamMP.zip)", true); info("Download Complete!"); } From 9734a7f3d56fd07790e588f6fa9aa4e0e5378320 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 05:50:51 +0200 Subject: [PATCH 05/13] Hotfix --- src/Network/Resources.cpp | 4 ++-- src/Startup.cpp | 7 ++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 4333a96..32ee0b0 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -257,7 +257,7 @@ void SyncResources(SOCKET Sock){ std::this_thread::sleep_for(std::chrono::milliseconds(50)); try { if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); + fs::create_directories(GetGamePath() + "mods/multiplayer"); } fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')), fs::copy_options::overwrite_existing); @@ -298,7 +298,7 @@ void SyncResources(SOCKET Sock){ }while(fs::file_size(a) != std::stoull(*FS) && !Terminate); if(!Terminate){ if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); + fs::create_directories(GetGamePath() + "mods/multiplayer"); } fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing); } diff --git a/src/Startup.cpp b/src/Startup.cpp index e3436e6..dda1c8a 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".5"; + return ".6"; } void ReLaunch(int argc,char*args[]){ std::string Arg; @@ -194,11 +194,8 @@ void PreGame(const std::string& GamePath){ if(!Dev) { info("Downloading mod..."); try { - if (!fs::exists(GetGamePath() + "mods")) { - fs::create_directory(GetGamePath() + "mods"); - } if (!fs::exists(GetGamePath() + "mods/multiplayer")) { - fs::create_directory(GetGamePath() + "mods/multiplayer"); + fs::create_directories(GetGamePath() + "mods/multiplayer"); } }catch(std::exception&e){ fatal(e.what()); From 2a03448b3f4a544fd28cab7061e8b31d093cb7d0 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 06:31:03 +0200 Subject: [PATCH 06/13] Fix for custom document location --- src/GameStart.cpp | 15 +++++++++------ src/Security/BeamNG.cpp | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index fb9d5bc..2db479e 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -22,16 +22,19 @@ std::string GetGamePath(){ LPCTSTR sk = "Software\\BeamNG\\BeamNG.drive"; LONG openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); if (openRes != ERROR_SUCCESS){ - fatal("Please launch the game at least once"); + fatal("Please launch the game at least once!"); } Path = QueryKey(hKey,4); if(Path.empty()){ - size_t RS; - getenv_s(&RS, nullptr, 0, "USERPROFILE"); - std::string P(RS-1,0); - getenv_s(&RS, &P[0], RS, "USERPROFILE"); - Path = P + R"(\Documents\BeamNG.drive\)"; + sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)"; + + openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); + if (openRes != ERROR_SUCCESS){ + fatal("Cannot get Documents directory!"); + } + Path = QueryKey(hKey,5); + Path += "\\"; return Path; } diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 6a99d90..ccf7144 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -117,6 +117,7 @@ std::string QueryKey(HKEY hKey,int ID){ case 2: if(key == "Name" && data == "BeamNG.drive")return data;break; case 3: if(key == "rootpath")return data;break; case 4: if(key == "userpath_override")return data; + case 5: if(key == "Personal")return data; default: break; } } From eaa8796c027aa9e496e42b67f06f355607987617 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 06:34:11 +0200 Subject: [PATCH 07/13] final hotfix --- src/GameStart.cpp | 3 +-- src/Startup.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/GameStart.cpp b/src/GameStart.cpp index 2db479e..5e37be7 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -28,13 +28,12 @@ std::string GetGamePath(){ if(Path.empty()){ sk = R"(SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders)"; - openRes = RegOpenKeyEx(HKEY_CURRENT_USER, sk, 0, KEY_ALL_ACCESS, &hKey); if (openRes != ERROR_SUCCESS){ fatal("Cannot get Documents directory!"); } Path = QueryKey(hKey,5); - Path += "\\"; + Path += "\\BeamNG.drive\\"; return Path; } diff --git a/src/Startup.cpp b/src/Startup.cpp index dda1c8a..087395a 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".6"; + return ".7"; } void ReLaunch(int argc,char*args[]){ std::string Arg; From 775e44a68ffd1d4ceefdb1ceed97a4964ca880be Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 23:19:24 +0200 Subject: [PATCH 08/13] fixed crash when starting up --- src/Security/BeamNG.cpp | 7 ++++--- src/Startup.cpp | 4 +--- src/main.cpp | 7 ++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index ccf7144..3b2b01e 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -107,7 +107,7 @@ std::string QueryKey(HKEY hKey,int ID){ DWORD lpData = cbMaxValueData; buffer[0] = '\0'; LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData); - std::string data = reinterpret_cast(buffer); + std::string data = (char *)(buffer); std::string key = achValue; switch (ID){ case 1: if(key == "SteamExe"){ @@ -130,8 +130,8 @@ namespace fs = std::filesystem; void FileList(std::vector&a,const std::string& Path){ for (const auto &entry : fs::directory_iterator(Path)) { if (!entry.is_directory()) { - a.emplace_back(entry.path().string()); - }else FileList(a,entry.path().string()); + a.emplace_back(entry.path().u8string()); + }else FileList(a,entry.path().u8string()); } } bool Find(const std::string& FName,const std::string& Path){ @@ -248,6 +248,7 @@ void LegitimacyCheck(){ if(dwRegOPenKey == ERROR_SUCCESS) { Result = QueryKey(hKey, 1); if(Result.empty())Exit(1); + if(fs::exists(Result)){ if(!Find("284160.json", Result))Exit(2); if(FindHack(Result))SteamExit(1); diff --git a/src/Startup.cpp b/src/Startup.cpp index 087395a..86d0db1 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -118,9 +118,7 @@ void CheckForUpdates(int argc,char*args[],const std::string& CV){ } } URelaunch(argc,args); - }else{ - info("Version is up to date"); - } + }else info("Version is up to date"); TraceBack++; } void CheckDir(int argc,char*args[]){ diff --git a/src/main.cpp b/src/main.cpp index a6fcbfb..9c9313b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include "Security/Init.h" #include "Startup.h" #include +#include "Logger.h" #include @@ -26,7 +27,11 @@ int main(int argc, char* argv[]) { #endif InitLauncher(argc,argv); //CheckDir(argc,argv); - LegitimacyCheck(); + try { + LegitimacyCheck(); + }catch (std::exception&e){ + fatal(e.what()); + } PreGame(GetGameDir()); InitGame(GetGameDir()); CoreNetwork(); From 3572a188d1878b2260112cd941fcf76637c660be Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 23:21:41 +0200 Subject: [PATCH 09/13] added try catch --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 9c9313b..e9ef33c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char* argv[]) { try { LegitimacyCheck(); }catch (std::exception&e){ - fatal(e.what()); + fatal("Main 1 : " + std::string(e.what())); } PreGame(GetGameDir()); InitGame(GetGameDir()); From 6b4211d9cf38a8044aac90beabc195ddd53c0277 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Sun, 27 Dec 2020 23:34:19 +0200 Subject: [PATCH 10/13] bump to 1.80.8 --- src/Startup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Startup.cpp b/src/Startup.cpp index 86d0db1..8f296f3 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".7"; + return ".8"; } void ReLaunch(int argc,char*args[]){ std::string Arg; From fda75670445785959c4e6e5db50ed6133d979974 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Mon, 28 Dec 2020 16:34:24 +0200 Subject: [PATCH 11/13] fixed crash -report --- src/Security/BeamNG.cpp | 2 +- src/Startup.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 3b2b01e..366abb7 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -149,7 +149,7 @@ bool Find(const std::string& FName,const std::string& Path){ bool FindHack(const std::string& Path){ bool s = true; for (const auto &entry : fs::directory_iterator(Path)) { - std::string Name = entry.path().filename().string(); + std::string Name = entry.path().filename().u8string(); for(char&c : Name)c = char(tolower(c)); if(Name == "steam.exe")s = false; if(Name.find("greenluma") != -1)return true; diff --git a/src/Startup.cpp b/src/Startup.cpp index 8f296f3..8400082 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".8"; + return ".9"; } void ReLaunch(int argc,char*args[]){ std::string Arg; From 543183b852dac78b26fc128f0ff66c4056cafdb8 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Mon, 28 Dec 2020 18:05:32 +0200 Subject: [PATCH 12/13] launcher is now more linux friendly --- src/Security/BeamNG.cpp | 17 +++++++++++------ src/Startup.cpp | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 366abb7..783a7a8 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -109,11 +109,15 @@ std::string QueryKey(HKEY hKey,int ID){ LONG dwRes = RegQueryValueEx(hKey, achValue, nullptr, nullptr, buffer, &lpData); std::string data = (char *)(buffer); std::string key = achValue; + switch (ID){ case 1: if(key == "SteamExe"){ - auto p = data.find_last_of('/'); - if(p != std::string::npos)return data.substr(0,p); - }break; + auto p = data.find_last_of("/\\"); + if(p != std::string::npos){ + return data.substr(0,p); + } + } + break; case 2: if(key == "Name" && data == "BeamNG.drive")return data;break; case 3: if(key == "rootpath")return data;break; case 4: if(key == "userpath_override")return data; @@ -136,7 +140,7 @@ void FileList(std::vector&a,const std::string& Path){ } bool Find(const std::string& FName,const std::string& Path){ std::vector FS; - FileList(FS,Path+"/userdata"); + FileList(FS,Path+"\\userdata"); for(std::string&a : FS){ if(a.find(FName) != std::string::npos){ FS.clear(); @@ -223,11 +227,12 @@ std::string GetManifest(const std::string& Man){ }else return ""; } bool IDCheck(std::string Man, std::string steam){ + info("IDCheck Called with : " + Man + " and " + steam); bool a = false,b = true; int pos = int(Man.rfind("steamapps")); if(pos == -1)Exit(5); - Man = Man.substr(0,pos+9) + "/appmanifest_284160.acf"; - steam += "/config/loginusers.vdf"; + Man = Man.substr(0,pos+9) + "\\appmanifest_284160.acf"; + steam += "\\config\\loginusers.vdf"; if(fs::exists(Man) && fs::exists(steam)){ for(const std::string&ID : GetID(steam)){ if(ID == GetManifest(Man))b = false; diff --git a/src/Startup.cpp b/src/Startup.cpp index 8400082..3281f14 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -27,7 +27,7 @@ std::string GetVer(){ return "1.80"; } std::string GetPatch(){ - return ".9"; + return ".10"; } void ReLaunch(int argc,char*args[]){ std::string Arg; From 6b124e89a8df5373a16c558e22ca5de4626c5362 Mon Sep 17 00:00:00 2001 From: Anonymous275 Date: Mon, 28 Dec 2020 18:07:04 +0200 Subject: [PATCH 13/13] Update BeamNG.cpp --- src/Security/BeamNG.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 783a7a8..63d886a 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -227,7 +227,6 @@ std::string GetManifest(const std::string& Man){ }else return ""; } bool IDCheck(std::string Man, std::string steam){ - info("IDCheck Called with : " + Man + " and " + steam); bool a = false,b = true; int pos = int(Man.rfind("steamapps")); if(pos == -1)Exit(5);