From 06825e30962d512aa374fa9cf0ab5a369e180a57 Mon Sep 17 00:00:00 2001 From: Jan Date: Sun, 16 Jul 2023 22:05:37 +0200 Subject: Add OS, Wine and Proton logging (#502) Adds logging for OS, Wine, and Proton versions. --- NorthstarDLL/dllmain.cpp | 4 +-- NorthstarDLL/logging/logging.cpp | 70 ++++++++++++++++++++++++++++++++++++++++ NorthstarDLL/logging/logging.h | 1 + 3 files changed, 72 insertions(+), 3 deletions(-) (limited to 'NorthstarDLL') 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 +#include #include #include @@ -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; -- cgit v1.2.3