Added config logging

This commit is contained in:
acidicoala
2025-08-27 23:38:56 +05:00
parent 1174dcb57a
commit ec5778d452
10 changed files with 84 additions and 76 deletions

View File

@@ -4,7 +4,7 @@ on: push
jobs:
ci:
name: CI
uses: acidicoala/KoalaBox/.github/workflows/build-and-package.yml@d36e7ec2ce7d73fbf66ca59b034c7a9373419461
uses: acidicoala/KoalaBox/.github/workflows/build-and-package.yml@7652ece92dc3461e07ac099344ec5fc4a472462a
permissions:
contents: write
with:

View File

@@ -83,6 +83,8 @@ namespace smoke_api {
// compilation time stamp only when this file gets recompiled.
LOG_INFO("{} v{} | Compiled at '{}'", PROJECT_NAME, PROJECT_VERSION, __TIMESTAMP__);
LOG_DEBUG("Parsed config:\n{}", nlohmann::json(config::instance).dump(2));
const auto exe_path = kb::win::get_module_path(nullptr);
const auto exe_name = kb::path::to_str(exe_path.filename());

View File

@@ -1,6 +1,7 @@
#include <koalabox/logger.hpp>
#include "steam_api/steam_interface.hpp"
#include "steam_client.hpp"
namespace steam_client {
void* GetGenericInterface(
@@ -11,13 +12,13 @@ namespace steam_client {
try {
auto* const interface = original_function();
LOG_DEBUG("{} -> '{}' @ {}", function_name, interface_version, interface);
LOG_DEBUG("'{}' -> '{}' @ {}", function_name, interface_version, interface);
steam_interface::hook_virtuals(interface, interface_version);
return interface;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: '{}' @ {}", function_name, interface_version, e.what());
LOG_ERROR("'{}' -> Error: '{}' @ {}", function_name, interface_version, e.what());
return nullptr;
}
}

View File

@@ -7,6 +7,7 @@
#include <koalabox/logger.hpp>
#include <koalabox/win.hpp>
#include "steam_api/steam_interface.hpp"
#include "smoke_api.hpp"
#include "virtuals/steam_api_virtuals.hpp"
@@ -32,6 +33,18 @@ namespace {
}
return {
{
STEAM_APPS,
interface_data{
.fallback_version = "STEAMAPPS_INTERFACE_VERSION008",
.entry_map = {
ENTRY(ISteamApps, BIsSubscribedApp),
ENTRY(ISteamApps, BIsDlcInstalled),
ENTRY(ISteamApps, GetDLCCount),
ENTRY(ISteamApps, BGetDLCDataByIndex),
}
}
},
{
STEAM_CLIENT,
interface_data{
@@ -45,14 +58,11 @@ namespace {
}
},
{
STEAM_APPS,
STEAM_GAME_SERVER,
interface_data{
.fallback_version = "STEAMAPPS_INTERFACE_VERSION008",
.fallback_version = "SteamGameServer015",
.entry_map = {
ENTRY(ISteamApps, BIsSubscribedApp),
ENTRY(ISteamApps, BIsDlcInstalled),
ENTRY(ISteamApps, GetDLCCount),
ENTRY(ISteamApps, BGetDLCDataByIndex),
ENTRY(ISteamGameServer, UserHasLicenseForApp),
}
}
},
@@ -76,31 +86,27 @@ namespace {
}
}
},
{
STEAM_GAME_SERVER,
interface_data{
.fallback_version = "SteamGameServer015",
.entry_map = {
ENTRY(ISteamGameServer, UserHasLicenseForApp),
}
}
},
};
}
nlohmann::json read_interface_lookup() {
auto read_interface_lookup() {
std::map<std::string, std::map<std::string, uint16_t>> lookup_map;
const auto lookup_str = b::embed<"res/interface_lookup.json">().str();
return nlohmann::json::parse(lookup_str);
const auto lookup_json = nlohmann::json::parse(lookup_str);
lookup_json.get_to(lookup_map);
return lookup_map;
}
const nlohmann::json& find_lookup(
const std::map<std::string, uint16_t>& find_lookup(
const std::string& interface_version,
const std::string& fallback_version
) {
static const auto lookup = read_interface_lookup();
if(lookup.contains(interface_version)) {
return lookup[interface_version];
return lookup.at(interface_version);
}
LOG_WARN(
@@ -109,7 +115,7 @@ namespace {
fallback_version
);
return lookup[fallback_version];
return lookup.at(fallback_version);
}
}
@@ -137,19 +143,20 @@ namespace steam_interface {
return;
}
static std::mutex section;
const std::lock_guard guard(section);
static std::set<void*> processed_interfaces;
if(processed_interfaces.contains(interface)) {
LOG_DEBUG(
"Interface '{}' at {} has already been processed.",
"Interface '{}' @ {} has already been processed.",
version_string,
interface
);
return;
}
static std::mutex section;
const std::lock_guard guard(section);
processed_interfaces.insert(interface);
static const auto virtual_hook_map = get_virtual_hook_map();
for(const auto& [prefix, data] : virtual_hook_map) {
@@ -161,7 +168,7 @@ namespace steam_interface {
kb::hook::swap_virtual_func(
interface,
entry.function_name,
lookup[function],
lookup.at(function),
entry.function_address
);
}
@@ -170,7 +177,5 @@ namespace steam_interface {
break;
}
}
processed_interfaces.insert(interface);
}
}

View File

@@ -33,8 +33,8 @@ VIRTUAL(void*) ISteamClient_GetISteamUser(
VIRTUAL(void*) ISteamClient_GetISteamGenericInterface(
PARAMS(
HSteamUser hSteamUser,
HSteamPipe hSteamPipe,
const HSteamUser hSteamUser,
const HSteamPipe hSteamPipe,
const char* pchVersion
)
) noexcept {

View File

@@ -30,7 +30,7 @@ namespace {
const std::lock_guard lock(section);
if(app_id == 0) {
LOG_ERROR("{} -> App ID is 0", __func__);
LOG_ERROR("'{}' -> App ID is 0", __func__);
app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access
return;
}
@@ -94,7 +94,7 @@ namespace smoke_api::steam_apps {
);
LOG_INFO(
"{} -> {}DLC ID: {:>8}, Unlocked: {}",
"'{}' -> {}DLC ID: {:>8}, Unlocked: {}",
function_name,
get_app_id_log(app_id),
dlc_id,
@@ -103,7 +103,7 @@ namespace smoke_api::steam_apps {
return unlocked;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
LOG_ERROR("'{}' -> Uncaught exception: {}", function_name, e.what());
return false;
}
}
@@ -115,16 +115,16 @@ namespace smoke_api::steam_apps {
) noexcept {
try {
const auto total_count = [&](int count) {
LOG_INFO("{} -> Responding with DLC count: {}", function_name, count);
LOG_INFO("'{}' -> Responding with DLC count: {}", function_name, count);
return count;
};
if(app_id != 0) {
LOG_DEBUG("{} -> App ID: {}", function_name, app_id);
LOG_DEBUG("'{}' -> App ID: {}", function_name, app_id);
}
const auto original_count = original_function();
LOG_DEBUG("{} -> Original DLC count: {}", function_name, original_count);
LOG_DEBUG("'{}' -> Original DLC count: {}", function_name, original_count);
if(original_count < MAX_DLC) {
return total_count(original_count);
@@ -156,11 +156,11 @@ namespace smoke_api::steam_apps {
const std::function<bool()>& is_originally_unlocked
) noexcept {
try {
LOG_DEBUG("{} -> {}index: {:>3}", function_name, get_app_id_log(app_id), iDLC);
LOG_DEBUG("'{}' -> {}index: {:>3}", function_name, get_app_id_log(app_id), iDLC);
const auto print_dlc_info = [&](const std::string& tag) {
LOG_INFO(
R"({} -> [{:^12}] {}index: {:>3}, DLC ID: {:>8}, available: {:5}, name: "{}")",
R"('{}' -> [{:^12}] {}index: {:>3}, DLC ID: {:>8}, available: {:5}, name: "{}")",
function_name,
tag,
get_app_id_log(app_id),
@@ -190,7 +190,7 @@ namespace smoke_api::steam_apps {
return true;
}
LOG_WARN("{} -> Out of bounds DLC index: {}", function_name, iDLC);
LOG_WARN("'{}' -> Out of bounds DLC index: {}", function_name, iDLC);
return false;
}
@@ -206,12 +206,12 @@ namespace smoke_api::steam_apps {
);
print_dlc_info("original");
} else {
LOG_WARN("{} -> original call failed for index: {}", function_name, iDLC);
LOG_WARN("'{}' -> original call failed for index: {}", function_name, iDLC);
}
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what());
LOG_ERROR("'{}' -> Uncaught exception: {}", function_name, e.what());
return false;
}
}

View File

@@ -24,7 +24,7 @@ namespace smoke_api::steam_http {
: "";
LOG_INFO(
"{} -> handle: {}, size: {}, buffer:\n{}",
"'{}' -> handle: {}, size: {}, buffer:\n{}",
function_name,
hRequest,
unBufferSize,
@@ -34,7 +34,7 @@ namespace smoke_api::steam_http {
return result;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what());
LOG_ERROR("'{}' -> Error: {}", __func__, e.what());
return false;
}
}
@@ -60,7 +60,7 @@ namespace smoke_api::steam_http {
: "";
LOG_INFO(
"{} -> handle: {}, offset: {}, size: {}, buffer:\n{}",
"'{}' -> handle: {}, offset: {}, size: {}, buffer:\n{}",
function_name,
hRequest,
cOffset,
@@ -71,7 +71,7 @@ namespace smoke_api::steam_http {
return result;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what());
LOG_ERROR("'{}' -> Error: {}", __func__, e.what());
return false;
}
}
@@ -97,7 +97,7 @@ namespace smoke_api::steam_http {
: "";
LOG_INFO(
"{} -> handle: {}, content-type: {}, size: {}, buffer:\n{}",
"'{}' -> handle: {}, content-type: {}, size: {}, buffer:\n{}",
function_name,
hRequest,
content_type,
@@ -108,7 +108,7 @@ namespace smoke_api::steam_http {
return result;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", __func__, e.what());
LOG_ERROR("'{}' -> Error: {}", __func__, e.what());
return false;
}
}

View File

@@ -13,7 +13,7 @@ namespace smoke_api::steam_inventory {
const auto status = original_function();
LOG_DEBUG(
"{} -> handle: {}, status: {}",
"'{}' -> handle: {}, status: {}",
function_name,
resultHandle,
static_cast<int>(status)
@@ -21,7 +21,7 @@ namespace smoke_api::steam_inventory {
return status;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return EResult::k_EResultFail;
}
}
@@ -52,17 +52,17 @@ namespace smoke_api::steam_inventory {
};
if(not success) {
LOG_DEBUG("{} -> original result is false", function_name);
LOG_DEBUG("'{}' -> original result is false", function_name);
return success;
}
if(punOutItemsArraySize == nullptr) {
LOG_ERROR("{} -> arraySize pointer is null", function_name);
LOG_ERROR("'{}' -> arraySize pointer is null", function_name);
return success;
}
LOG_DEBUG(
"{} -> handle: {}, pOutItemsArray: {}, arraySize: {}",
"'{}' -> handle: {}, pOutItemsArray: {}, arraySize: {}",
function_name,
resultHandle,
reinterpret_cast<void*>(pOutItemsArray),
@@ -95,7 +95,7 @@ namespace smoke_api::steam_inventory {
original_count = *punOutItemsArraySize;
*punOutItemsArraySize += auto_injected_count + injected_count;
LOG_DEBUG(
"{} -> Original count: {}, Total count: {}",
"'{}' -> Original count: {}, Total count: {}",
function_name,
original_count,
*punOutItemsArraySize
@@ -136,7 +136,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}
@@ -152,7 +152,7 @@ namespace smoke_api::steam_inventory {
) noexcept {
try {
LOG_DEBUG(
"{} -> Handle: {}, Index: {}, Name: '{}'",
"'{}' -> Handle: {}, Index: {}, Name: '{}'",
function_name,
resultHandle,
unItemIndex,
@@ -163,7 +163,7 @@ namespace smoke_api::steam_inventory {
const auto success = original_function();
if(!success) {
LOG_WARN("{} -> Result is false", function_name);
LOG_WARN("'{}' -> Result is false", function_name);
return false;
}
@@ -172,7 +172,7 @@ namespace smoke_api::steam_inventory {
punValueBufferSizeOut && *punValueBufferSizeOut > 0
) {
LOG_DEBUG(
R"({} -> Buffer: "{}")",
R"('{}' -> Buffer: "{}")",
function_name,
std::string(pchValueBuffer, *punValueBufferSizeOut - 1)
);
@@ -180,7 +180,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}
@@ -194,14 +194,14 @@ namespace smoke_api::steam_inventory {
const auto success = original_function();
LOG_DEBUG(
"{} -> Handle: {}",
"'{}' -> Handle: {}",
function_name,
reinterpret_cast<const void*>(pResultHandle)
);
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}
@@ -216,7 +216,7 @@ namespace smoke_api::steam_inventory {
try {
const auto success = original_function();
LOG_DEBUG("{} -> Handle: {}", function_name, fmt::ptr(pResultHandle));
LOG_DEBUG("'{}' -> Handle: {}", function_name, fmt::ptr(pResultHandle));
if(success && pInstanceIDs != nullptr) {
for(int i = 0; i < unCountInstanceIDs; i++) {
@@ -226,7 +226,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}
@@ -243,10 +243,10 @@ namespace smoke_api::steam_inventory {
if(pOutBuffer != nullptr) {
std::string buffer(static_cast<char*>(pOutBuffer), *punOutBufferSize);
LOG_DEBUG("{} -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
LOG_DEBUG("'{}' -> Handle: {}, Buffer: '{}'", function_name, resultHandle, buffer);
} else {
LOG_DEBUG(
"{} -> Handle: {}, Size: '{}'",
"'{}' -> Handle: {}, Size: '{}'",
function_name,
resultHandle,
*punOutBufferSize
@@ -255,7 +255,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}
@@ -270,12 +270,12 @@ namespace smoke_api::steam_inventory {
const auto success = original_function();
if(!success) {
LOG_WARN("{} -> Result is false", function_name);
LOG_WARN("'{}' -> Result is false", function_name);
return false;
}
if(punItemDefIDsArraySize) {
LOG_DEBUG("{} -> Size: {}", function_name, *punItemDefIDsArraySize);
LOG_DEBUG("'{}' -> Size: {}", function_name, *punItemDefIDsArraySize);
} else {
return success;
}
@@ -289,7 +289,7 @@ namespace smoke_api::steam_inventory {
return success;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}
@@ -304,7 +304,7 @@ namespace smoke_api::steam_inventory {
const auto result = original_function();
LOG_DEBUG(
"{} -> handle: {}, steamID: {}, original result: {}",
"'{}' -> handle: {}, steamID: {}, original result: {}",
function_name,
resultHandle,
steamIDExpected,
@@ -313,7 +313,7 @@ namespace smoke_api::steam_inventory {
return true;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return false;
}
}

View File

@@ -14,7 +14,7 @@ namespace smoke_api::steam_user {
const auto result = original_function();
if(result == k_EUserHasLicenseResultNoAuth) {
LOG_WARN("{} -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
LOG_WARN("'{}' -> App ID: {:>8}, Result: NoAuth", function_name, dlcId);
return result;
}
@@ -26,13 +26,13 @@ namespace smoke_api::steam_user {
}
);
LOG_INFO("{} -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license);
LOG_INFO("'{}' -> App ID: {:>8}, HasLicense: {}", function_name, dlcId, has_license);
return has_license
? k_EUserHasLicenseResultHasLicense
: k_EUserHasLicenseResultDoesNotHaveLicense;
} catch(const std::exception& e) {
LOG_ERROR("{} -> Error: {}", function_name, e.what());
LOG_ERROR("'{}' -> Error: {}", function_name, e.what());
return k_EUserHasLicenseResultDoesNotHaveLicense;
}
}