From ec1a09bbcb1b7814bbe9e58413cb5f77d13c5554 Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Thu, 5 Dec 2024 03:56:13 -0300 Subject: [PATCH 1/7] Fixed GameDir localization issues. I couldn't launch the game without this. --- src/Security/BeamNG.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 9e051c8..0c02437 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -182,7 +182,24 @@ void LegitimacyCheck() { struct passwd* pw = getpwuid(getuid()); std::string homeDir = pw->pw_dir; // Right now only steam is supported - std::ifstream libraryFolders(homeDir + "/.steam/root/steamapps/libraryfolders.vdf"); + std::vector steamappsCommonPaths = { + homeDir + "/.steam/root/steamapps/", // default + homeDir + "/.var/app/com.valvesoftware.Steam/.steam/root/steamapps/", // flatpak + }; + std::string libraryFoldersPath; + bool libraryFoldersFound = false; + for (const std::string& path : steamappsCommonPaths) { + std::string fullPath = path + "/libraryfolders.vdf"; + if (std::filesystem::exists(fullPath)) { + libraryFoldersPath = fullPath; + libraryFoldersFound = true; + break; + } + } + if (!libraryFoldersFound) { + throw std::runtime_error("Failed to find libraryfolders.vdf"); + } + std::ifstream libraryFolders(libraryFoldersPath); auto root = tyti::vdf::read(libraryFolders); for (auto folderInfo : root.childs) { @@ -191,6 +208,13 @@ void LegitimacyCheck() { break; } } + if (GameDir.empty()) { + // Check if user is using Snap, which can't be located from libraryFolders... + const std::string snapPath = + homeDir + "/snap/steam/common/.local/share/Steam/steamapps/common/BeamNG.drive/"; + + if (std::filesystem::exists(snapPath)) GameDir = snapPath; + } #endif } std::string CheckVer(const std::string& dir) { From 80a3feb34989686951eb502125ec51c67ec27908 Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:02:00 -0300 Subject: [PATCH 2/7] Update src/Security/BeamNG.cpp Co-authored-by: Tixx <83774803+WiserTixx@users.noreply.github.com> --- src/Security/BeamNG.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 0c02437..f60311f 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -196,9 +196,6 @@ void LegitimacyCheck() { break; } } - if (!libraryFoldersFound) { - throw std::runtime_error("Failed to find libraryfolders.vdf"); - } std::ifstream libraryFolders(libraryFoldersPath); auto root = tyti::vdf::read(libraryFolders); From a06470cb70df5651bcdf70799fc9ed69027c3743 Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:02:07 -0300 Subject: [PATCH 3/7] Update src/Security/BeamNG.cpp Co-authored-by: Tixx <83774803+WiserTixx@users.noreply.github.com> --- src/Security/BeamNG.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index f60311f..31faa86 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -205,13 +205,6 @@ void LegitimacyCheck() { break; } } - if (GameDir.empty()) { - // Check if user is using Snap, which can't be located from libraryFolders... - const std::string snapPath = - homeDir + "/snap/steam/common/.local/share/Steam/steamapps/common/BeamNG.drive/"; - - if (std::filesystem::exists(snapPath)) GameDir = snapPath; - } #endif } std::string CheckVer(const std::string& dir) { From ebf1579ce486e42641906e8d8e099e3c9f8ce81c Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:03:19 -0300 Subject: [PATCH 4/7] Update src/Security/BeamNG.cpp Co-authored-by: Tixx <83774803+WiserTixx@users.noreply.github.com> --- src/Security/BeamNG.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 31faa86..ff415cb 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -183,9 +183,11 @@ void LegitimacyCheck() { std::string homeDir = pw->pw_dir; // Right now only steam is supported std::vector steamappsCommonPaths = { - homeDir + "/.steam/root/steamapps/", // default - homeDir + "/.var/app/com.valvesoftware.Steam/.steam/root/steamapps/", // flatpak + "/.steam/root/steamapps/", // default + "/.var/app/com.valvesoftware.Steam/.steam/root/steamapps/", // flatpak + "/snap/steam/common/.local/share/Steam/steamapps/" //snap }; + std::string libraryFoldersPath; bool libraryFoldersFound = false; for (const std::string& path : steamappsCommonPaths) { From 89327b8e203e7671494f41358b4a1f82aba30c47 Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Fri, 6 Dec 2024 15:03:25 -0300 Subject: [PATCH 5/7] Update src/Security/BeamNG.cpp Co-authored-by: Tixx <83774803+WiserTixx@users.noreply.github.com> --- src/Security/BeamNG.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index ff415cb..d8bf370 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -191,7 +191,8 @@ void LegitimacyCheck() { std::string libraryFoldersPath; bool libraryFoldersFound = false; for (const std::string& path : steamappsCommonPaths) { - std::string fullPath = path + "/libraryfolders.vdf"; + std::string fullPath = homeDir + path + "/libraryfolders.vdf"; + if (std::filesystem::exists(fullPath)) { libraryFoldersPath = fullPath; libraryFoldersFound = true; From 63aee0396937d0429f6808b0eddb2b489b22b8ec Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Tue, 10 Dec 2024 20:10:07 -0300 Subject: [PATCH 6/7] Update BeamNG.cpp As requested: - Changed 'string' variables that referred to paths to 'filesystem'. - Added error log for when a valid 'GameDir' isn't found. Also readded error log for when 'libraryfolders.vdf' is missing for better contextualization for the 'basic_string::_M_replace_aux' error (the code doesn't reach the GameDir segment when that file is not found). --- src/Security/BeamNG.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index d8bf370..0759e29 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -180,34 +180,44 @@ void LegitimacyCheck() { RegCloseKey(hKey); #elif defined(__linux__) struct passwd* pw = getpwuid(getuid()); - std::string homeDir = pw->pw_dir; + std::filesystem::path homeDir = pw->pw_dir; + // Right now only steam is supported - std::vector steamappsCommonPaths = { - "/.steam/root/steamapps/", // default - "/.var/app/com.valvesoftware.Steam/.steam/root/steamapps/", // flatpak - "/snap/steam/common/.local/share/Steam/steamapps/" //snap + std::vector steamappsCommonPaths = { + ".steam/root/steamapps", // default + ".var/app/com.valvesoftware.Steam/.steam/root/steamapps", // flatpak + "snap/steam/common/.local/share/Steam/steamapps" // snap }; - std::string libraryFoldersPath; + std::filesystem::path libraryFoldersPath; bool libraryFoldersFound = false; - for (const std::string& path : steamappsCommonPaths) { - std::string fullPath = homeDir + path + "/libraryfolders.vdf"; + for (const auto& path : steamappsCommonPaths) { + std::filesystem::path fullPath = homeDir / path / "libraryfolders.vdf"; if (std::filesystem::exists(fullPath)) { libraryFoldersPath = fullPath; libraryFoldersFound = true; break; } } + + if (!libraryFoldersFound) { + error("Did not find a valid path to a libraryfolders.vdf file."); + return; + } + std::ifstream libraryFolders(libraryFoldersPath); auto root = tyti::vdf::read(libraryFolders); - for (auto folderInfo : root.childs) { if (std::filesystem::exists(folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/")) { GameDir = folderInfo.second->attribs["path"] + "/steamapps/common/BeamNG.drive/"; break; } } + if (GameDir.empty()) { + error("The game directory was not found."); + return; + } #endif } std::string CheckVer(const std::string& dir) { @@ -228,4 +238,4 @@ std::string CheckVer(const std::string& dir) { temp += a; } return temp; -} +} \ No newline at end of file From f2b86cd5a025a067a7bd637e9abe373064ed8b20 Mon Sep 17 00:00:00 2001 From: Winos <42523848+Johnny-Connor@users.noreply.github.com> Date: Sun, 15 Dec 2024 16:58:56 -0300 Subject: [PATCH 7/7] Improved error handling as requested. --- src/Security/BeamNG.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Security/BeamNG.cpp b/src/Security/BeamNG.cpp index 0759e29..705c3c3 100644 --- a/src/Security/BeamNG.cpp +++ b/src/Security/BeamNG.cpp @@ -189,20 +189,30 @@ void LegitimacyCheck() { "snap/steam/common/.local/share/Steam/steamapps" // snap }; + std::filesystem::path steamappsPath; std::filesystem::path libraryFoldersPath; + bool steamappsFolderFound = false; bool libraryFoldersFound = false; for (const auto& path : steamappsCommonPaths) { - std::filesystem::path fullPath = homeDir / path / "libraryfolders.vdf"; - if (std::filesystem::exists(fullPath)) { - libraryFoldersPath = fullPath; - libraryFoldersFound = true; - break; + steamappsPath = homeDir / path; + if (std::filesystem::exists(steamappsPath)) { + steamappsFolderFound = true; + libraryFoldersPath = steamappsPath / "libraryfolders.vdf"; + if (std::filesystem::exists(libraryFoldersPath)) { + libraryFoldersPath = libraryFoldersPath; + libraryFoldersFound = true; + break; + } } } + if (!steamappsFolderFound) { + error("Unsupported Steam installation."); + return; + } if (!libraryFoldersFound) { - error("Did not find a valid path to a libraryfolders.vdf file."); + error("libraryfolders.vdf is missing."); return; }