diff options
author | Jan <sentrycraft123@gmail.com> | 2023-07-16 22:05:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-16 22:05:37 +0200 |
commit | 06825e30962d512aa374fa9cf0ab5a369e180a57 (patch) | |
tree | 6cd3dc8f01011029122c2fa84a38bae6e3f02823 | |
parent | 24248c7419e9b857f1dbe3e60592714b33cb5b78 (diff) | |
download | NorthstarLauncher-06825e30962d512aa374fa9cf0ab5a369e180a57.tar.gz NorthstarLauncher-06825e30962d512aa374fa9cf0ab5a369e180a57.zip |
Add OS, Wine and Proton logging (#502)
Adds logging for OS, Wine, and Proton versions.
-rw-r--r-- | NorthstarDLL/dllmain.cpp | 4 | ||||
-rw-r--r-- | NorthstarDLL/logging/logging.cpp | 70 | ||||
-rw-r--r-- | NorthstarDLL/logging/logging.h | 1 |
3 files changed, 72 insertions, 3 deletions
diff --git a/NorthstarDLL/dllmain.cpp b/NorthstarDLL/dllmain.cpp index 6fc49be8..87c72dcf 100644 --- a/NorthstarDLL/dllmain.cpp +++ b/NorthstarDLL/dllmain.cpp @@ -52,9 +52,7 @@ bool InitialiseNorthstar() InitialiseCrashHandler(); // Write launcher version to log - spdlog::info("NorthstarLauncher version: {}", version); - spdlog::info("Command line: {}", GetCommandLineA()); - spdlog::info("Using profile: {}", GetNorthstarPrefix()); + StartupLog(); InstallInitialHooks(); diff --git a/NorthstarDLL/logging/logging.cpp b/NorthstarDLL/logging/logging.cpp index 9627f9c1..2e8605d6 100644 --- a/NorthstarDLL/logging/logging.cpp +++ b/NorthstarDLL/logging/logging.cpp @@ -3,8 +3,11 @@ #include "core/convar/concommand.h" #include "config/profile.h" #include "core/tier0.h" +#include "util/version.h" #include "spdlog/sinks/basic_file_sink.h" +#include <winternl.h> +#include <cstdlib> #include <iomanip> #include <sstream> @@ -220,3 +223,70 @@ void NS::log::FlushLoggers() spdlog::default_logger()->flush(); } + +// Wine specific functions +typedef const char*(CDECL* wine_get_host_version_type)(const char**, const char**); +wine_get_host_version_type wine_get_host_version; + +typedef const char*(CDECL* wine_get_build_id_type)(void); +wine_get_build_id_type wine_get_build_id; + +// Not exported Winapi methods +typedef NTSTATUS(WINAPI* RtlGetVersion_type)(PRTL_OSVERSIONINFOW); +RtlGetVersion_type RtlGetVersion; + +void StartupLog() +{ + spdlog::info("NorthstarLauncher version: {}", version); + spdlog::info("Command line: {}", GetCommandLineA()); + spdlog::info("Using profile: {}", GetNorthstarPrefix()); + + HMODULE ntdll = GetModuleHandleA("ntdll.dll"); + if (!ntdll) + { + // How did we get here + spdlog::info("Operating System: Unknown"); + return; + } + + wine_get_host_version = (wine_get_host_version_type)GetProcAddress(ntdll, "wine_get_host_version"); + if (wine_get_host_version) + { + // Load the rest of the functions we need + wine_get_build_id = (wine_get_build_id_type)GetProcAddress(ntdll, "wine_get_build_id"); + + const char* sysname; + wine_get_host_version(&sysname, NULL); + + spdlog::info("Operating System: {} (Wine)", sysname); + spdlog::info("Wine build: {}", wine_get_build_id()); + + char* compatToolPtr = std::getenv("STEAM_COMPAT_TOOL_PATHS"); + if (compatToolPtr) + { + std::string compatToolPath(compatToolPtr); + + spdlog::info("Proton build: {}", compatToolPath.substr(compatToolPath.rfind("/") + 1)); + } + } + else + { + // We are real Windows (hopefully) + const char* win_ver = "Unknown"; + + RTL_OSVERSIONINFOW osvi; + osvi.dwOSVersionInfoSize = sizeof(osvi); + + RtlGetVersion = (RtlGetVersion_type)GetProcAddress(ntdll, "RtlGetVersion"); + if (RtlGetVersion && !RtlGetVersion(&osvi)) + { + // Version reference table + // https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-osversioninfoa#remarks + spdlog::info("Operating System: Windows (NT{}.{})", osvi.dwMajorVersion, osvi.dwMinorVersion); + } + else + { + spdlog::info("Operating System: Windows"); + } + } +} diff --git a/NorthstarDLL/logging/logging.h b/NorthstarDLL/logging/logging.h index 2efee80b..af4b506c 100644 --- a/NorthstarDLL/logging/logging.h +++ b/NorthstarDLL/logging/logging.h @@ -7,6 +7,7 @@ void CreateLogFiles(); void InitialiseLogging(); void InitialiseConsole(); +void StartupLog(); class ColoredLogger; |