Reworked logging

This commit is contained in:
acidicoala
2025-08-16 19:19:03 +05:00
parent 9f8b9befc6
commit 5f1e83adad
26 changed files with 251 additions and 271 deletions

View File

@@ -1,16 +1,19 @@
#include <smoke_api/smoke_api.hpp>
#include <build_config.h>
#include <smoke_api/config.hpp>
#include <core/globals.hpp>
#include <core/paths.hpp>
#include <common/steamclient_exports.hpp>
#include <koalabox/globals.hpp>
#include "koalabox/paths.hpp"
#include <koalabox/dll_monitor.hpp>
#include <koalabox/logger.hpp>
#include <koalabox/globals.hpp>
#include <koalabox/hook.hpp>
#include <koalabox/loader.hpp>
#include <koalabox/win_util.hpp>
#include <koalabox/logger.hpp>
#include <koalabox/util.hpp>
#include <koalabox/win_util.hpp>
#include <build_config.h>
#include <common/steamclient_exports.hpp>
#include <core/globals.hpp>
#include <core/paths.hpp>
#include <smoke_api/config.hpp>
#include <smoke_api/smoke_api.hpp>
#if COMPILE_STORE_MODE
#include <store_mode/store.hpp>
@@ -34,69 +37,62 @@
// Given that hooking steam_api has no apparent benefits, but has inherent flaws,
// the support for it has been dropped from this project.
namespace {
void override_app_id() {
const auto override_app_id = smoke_api::config::instance.override_app_id;
if (override_app_id == 0)
return;
void override_app_id() {
const auto override_app_id = smoke_api::config::instance.override_app_id;
if (override_app_id == 0)
return;
spdlog::default_logger_raw();
LOG_DEBUG("Overriding app id to {}", override_app_id);
LOG_DEBUG("Overriding app id to {}", override_app_id);
SetEnvironmentVariable(TEXT("SteamAppId"), std::to_wstring(override_app_id).c_str());
}
SetEnvironmentVariable(
TEXT("SteamAppId"),
std::to_wstring(override_app_id).c_str()
);
}
void init_proxy_mode() {
LOG_INFO("Detected proxy mode");
void init_proxy_mode() {
LOG_INFO("🔀 Detected proxy mode")
override_app_id();
override_app_id();
globals::steamapi_module =
koalabox::loader::load_original_library(paths::get_self_path(), STEAMAPI_DLL);
}
globals::steamapi_module = koalabox::loader::load_original_library(
paths::get_self_path(),
STEAMAPI_DLL
);
}
void init_hook_mode() {
LOG_INFO("🪝 Detected hook mode");
void init_hook_mode() {
LOG_INFO("🪝 Detected hook mode")
override_app_id();
override_app_id();
koalabox::dll_monitor::init_listener(
STEAMCLIENT_DLL,
[](const HMODULE &library) {
koalabox::dll_monitor::init_listener(STEAMCLIENT_DLL, [](const HMODULE& library) {
globals::steamclient_module = library;
DETOUR_STEAMCLIENT(CreateInterface)
koalabox::dll_monitor::shutdown_listener();
}
);
}
});
}
bool is_valve_steam(const String& exe_name) noexcept {
try {
if (exe_name < not_equals > "steam.exe") {
return false;
}
// Verify that it's steam from valve, and not some other executable coincidentally named
// steam
const HMODULE steam_handle = koalabox::win_util::get_module_handle_or_throw(nullptr);
const auto manifest = koalabox::win_util::get_module_manifest(steam_handle);
// Steam.exe manifest is expected to contain this string
return manifest < contains > "valvesoftware.steam.steam";
} catch (const Exception& e) {
LOG_ERROR("{} -> {}", __func__, e.what());
bool is_valve_steam(const String &exe_name) noexcept {
try {
if (exe_name < not_equals > "steam.exe") {
return false;
}
// Verify that it's steam from valve, and not some other executable coincidentally named steam
const HMODULE steam_handle = koalabox::win_util::get_module_handle_or_throw(nullptr);
const auto manifest = koalabox::win_util::get_module_manifest(
steam_handle);
// Steam.exe manifest is expected to contain this string
return manifest < contains > "valvesoftware.steam.steam";
} catch (const Exception &e) {
LOG_ERROR("{} -> {}", __func__, e.what())
return false;
}
}
namespace smoke_api {
void init(const HMODULE module_handle) {
// FIXME: IMPORTANT! Non ascii paths in directories will result in init errors
@@ -110,33 +106,27 @@ namespace smoke_api {
config::init_config();
if (config::instance.logging) {
koalabox::logger::init_file_logger();
koalabox::logger::init_file_logger(koalabox::paths::get_log_path());
}
// This kind of timestamp is reliable only for CI builds, as it will reflect the compilation
// time stamp only when this file gets recompiled.
LOG_INFO(
"🐨 {} v{} | Compiled at '{}'", PROJECT_NAME,
PROJECT_VERSION,
__TIMESTAMP__
)
// This kind of timestamp is reliable only for CI builds, as it will reflect the
// compilation time stamp only when this file gets recompiled.
LOG_INFO("{} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__);
const Path exe_path = koalabox::win_util::get_module_file_name_or_throw(nullptr);
const auto exe_name = exe_path.filename().string();
LOG_DEBUG("Process name: '{}' [{}-bit]", exe_name, BITNESS)
LOG_DEBUG("Process name: '{}' [{}-bit]", exe_name, BITNESS);
const bool is_hook_mode = koalabox::hook::is_hook_mode(
globals::smokeapi_handle,
STEAMAPI_DLL
);
const bool is_hook_mode =
koalabox::hook::is_hook_mode(globals::smokeapi_handle, STEAMAPI_DLL);
if (is_hook_mode) {
koalabox::hook::init(true);
if (is_valve_steam(exe_name)) {
#if COMPILE_STORE_MODE
LOG_INFO("🛍️ Detected Store mode")
LOG_INFO("Detected Store mode");
store::init_store_mode();
#endif
} else {
@@ -146,11 +136,9 @@ namespace smoke_api {
init_proxy_mode();
}
LOG_INFO("🚀 Initialization complete")
} catch (const Exception &ex) {
koalabox::util::panic(
fmt::format("Initialization error: {}", ex.what())
);
LOG_INFO("Initialization complete");
} catch (const Exception& ex) {
koalabox::util::panic(fmt::format("Initialization error: {}", ex.what()));
}
}
@@ -160,9 +148,11 @@ namespace smoke_api {
koalabox::win_util::free_library(globals::steamapi_module);
}
LOG_INFO("💀 Shutdown complete")
} catch (const Exception &ex) {
LOG_ERROR("Shutdown error: {}", ex.what())
LOG_INFO("Shutdown complete");
} catch (const Exception& ex) {
LOG_ERROR("Shutdown error: {}", ex.what());
}
koalabox::logger::shutdown();
}
}