From 1b260f788b4c0954b1b4d071313704207f15642b Mon Sep 17 00:00:00 2001 From: Andreas Maerten <24669514+Yimura@users.noreply.github.com> Date: Tue, 13 Feb 2024 00:16:10 +0100 Subject: [PATCH] fix: issues with proton installations (#2711) --- src/logger/logger.cpp | 8 +++----- src/main.cpp | 19 ++++++++++++++----- src/util/is_proton.hpp | 13 +++++++++++++ 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/util/is_proton.hpp diff --git a/src/logger/logger.cpp b/src/logger/logger.cpp index 39f877e2..67200f08 100644 --- a/src/logger/logger.cpp +++ b/src/logger/logger.cpp @@ -1,7 +1,6 @@ #pragma once #include "logger.hpp" - -#include "memory/module.hpp" +#include "util/is_proton.hpp" namespace big { @@ -22,8 +21,7 @@ namespace big m_console_handle(nullptr), m_file(file) { - auto module = memory::module("ntdll.dll"); - if (const auto env_no_color = std::getenv("NO_COLOR"); module.get_export("wine_get_version") || (env_no_color && strlen(env_no_color))) + if (is_proton()) { LOG(VERBOSE) << "Using simple logger."; m_console_logger = &logger::format_console_simple; @@ -183,4 +181,4 @@ namespace big m_file_out << "[" << timestamp << "]" << "[" << get_level_string(level) << "/" << file << ":" << location.line() << "] " << msg->Message() << std::flush; } -} \ No newline at end of file +} diff --git a/src/main.cpp b/src/main.cpp index 3b5b68fd..894e35f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -35,6 +35,7 @@ #include "services/vehicle/xml_vehicles_service.hpp" #include "services/xml_maps/xml_map_service.hpp" #include "thread_pool.hpp" +#include "util/is_proton.hpp" #include "version.hpp" namespace big @@ -158,10 +159,18 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) LOG(INFO) << "Yim's Menu Initializing"; LOGF(INFO, "Git Info\n\tBranch:\t{}\n\tHash:\t{}\n\tDate:\t{}", version::GIT_BRANCH, version::GIT_SHA1, version::GIT_DATE); - auto display_version = ReadRegistryKeySZ(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "DisplayVersion"); - auto current_build = ReadRegistryKeySZ(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuild"); - auto UBR = ReadRegistryKeyDWORD(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "UBR"); - LOG(INFO) << GetWindowsVersion() << " Version " << display_version << " (OS Build " << current_build << "." << UBR << ")"; + // more tech debt, YAY! + if (is_proton()) + { + LOG(INFO) << "Running on proton!"; + } + else + { + auto display_version = ReadRegistryKeySZ(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "DisplayVersion"); + auto current_build = ReadRegistryKeySZ(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuild"); + auto UBR = ReadRegistryKeyDWORD(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "UBR"); + LOG(INFO) << GetWindowsVersion() << " Version " << display_version << " (OS Build " << current_build << "." << UBR << ")"; + } #ifndef NDEBUG LOG(WARNING) << "Debug Build. Switch to RelWithDebInfo or Release Build for a more stable experience"; @@ -343,4 +352,4 @@ BOOL APIENTRY DllMain(HMODULE hmod, DWORD reason, PVOID) } return true; -} \ No newline at end of file +} diff --git a/src/util/is_proton.hpp b/src/util/is_proton.hpp new file mode 100644 index 00000000..087c4024 --- /dev/null +++ b/src/util/is_proton.hpp @@ -0,0 +1,13 @@ +#pragma once +#include "memory/module.hpp" + +namespace big +{ + inline bool is_proton() + { + static auto module = memory::module("ntdll.dll"); + + const auto env_no_color = std::getenv("NO_COLOR"); + return module.get_export("wine_get_version") || (env_no_color && strlen(env_no_color)); + } +}