diff --git a/.idea/runConfigurations/linux_exports_generator__32_.xml b/.idea/runConfigurations/linux_exports_generator__32_.xml index 74650f1..977b509 100644 --- a/.idea/runConfigurations/linux_exports_generator__32_.xml +++ b/.idea/runConfigurations/linux_exports_generator__32_.xml @@ -1,5 +1,5 @@ - + diff --git a/KoalaBox b/KoalaBox index 57cee7c..61454a2 160000 --- a/KoalaBox +++ b/KoalaBox @@ -1 +1 @@ -Subproject commit 57cee7c22b4897320edde8927e403f824d296f4f +Subproject commit 61454a2dac30df2f0fbaa89141b82d28fa331248 diff --git a/src/smoke_api/smoke_api.cpp b/src/smoke_api/smoke_api.cpp index d986654..d335e20 100644 --- a/src/smoke_api/smoke_api.cpp +++ b/src/smoke_api/smoke_api.cpp @@ -25,7 +25,7 @@ #include "build_config.h" -#if defined(KB_WIN) +#ifdef KB_WIN #include "koalabox/win.hpp" #elif defined(KB_LINUX) && defined(KB_32) #include "generated/32/proxy_exports.hpp" @@ -64,7 +64,9 @@ namespace { std::set versions; - const auto rdata_section = kb::lib::get_section_or_throw(steamapi_handle, kb::lib::CONST_STR_SECTION); + // On Linux the section name depends on individual lib file, so we can't use generic constants + const std::string str_section_name = kb::platform::is_windows ? ".text" : ".rodata.str"; + const auto rdata_section = kb::lib::get_section_or_throw(steamapi_handle, str_section_name); const auto rdata = rdata_section.to_string(); const std::regex pattern(R"(SteamClient\d{3})"); @@ -229,16 +231,16 @@ namespace smoke_api { kb::globals::init_globals(self_module_handle, PROJECT_NAME); - config::instance = kb::config::parse(); + config::get() = kb::config::parse(); - if(config::instance.logging) { + if(config::get().logging) { kb::logger::init_file_logger(kb::paths::get_log_path()); } else { kb::logger::init_null_logger(); } LOG_INFO("{} v{}{} | Built at '{}'", PROJECT_NAME, PROJECT_VERSION, VERSION_SUFFIX, __TIMESTAMP__); - LOG_DEBUG("Parsed config:\n{}", nlohmann::ordered_json(config::instance).dump(2)); + LOG_DEBUG("Parsed config:\n{}", nlohmann::ordered_json(config::get()).dump(2)); const auto exe_path = kb::lib::get_fs_path(nullptr); const auto exe_name = kb::path::to_str(exe_path.filename()); diff --git a/static/smoke_api/config.cpp b/static/smoke_api/config.cpp index 75b16f7..e88ab58 100644 --- a/static/smoke_api/config.cpp +++ b/static/smoke_api/config.cpp @@ -1,14 +1,16 @@ #include -#include #include #include "smoke_api/config.hpp" namespace smoke_api::config { - Config instance; // NOLINT(cert-err58-cpp) + Config& get() noexcept { + static Config config; + return config; + } std::vector get_extra_dlcs(const uint32_t app_id) { - return DLC::get_dlcs_from_apps(instance.extra_dlcs, app_id); + return DLC::get_dlcs_from_apps(get().extra_dlcs, app_id); } bool is_dlc_unlocked( @@ -16,16 +18,16 @@ namespace smoke_api::config { const AppId_t dlc_id, const std::function& original_function ) { - auto status = instance.default_app_status; + auto status = get().default_app_status; const auto app_id_str = std::to_string(app_id); - if(instance.override_app_status.contains(app_id_str)) { - status = instance.override_app_status[app_id_str]; + if(get().override_app_status.contains(app_id_str)) { + status = get().override_app_status[app_id_str]; } const auto dlc_id_str = std::to_string(dlc_id); - if(instance.override_dlc_status.contains(dlc_id_str)) { - status = instance.override_dlc_status[dlc_id_str]; + if(get().override_dlc_status.contains(dlc_id_str)) { + status = get().override_dlc_status[dlc_id_str]; } bool is_unlocked; diff --git a/static/smoke_api/config.hpp b/static/smoke_api/config.hpp index 0f3fc61..95d12e7 100644 --- a/static/smoke_api/config.hpp +++ b/static/smoke_api/config.hpp @@ -43,7 +43,7 @@ namespace smoke_api::config { ) }; - extern Config instance; + Config& get() noexcept; std::vector get_extra_dlcs(AppId_t app_id); diff --git a/static/smoke_api/interfaces/steam_apps.cpp b/static/smoke_api/interfaces/steam_apps.cpp index 82f5ed9..36455a8 100644 --- a/static/smoke_api/interfaces/steam_apps.cpp +++ b/static/smoke_api/interfaces/steam_apps.cpp @@ -14,8 +14,15 @@ namespace { /// This means we have to get extra DLC IDs from local config, remote config, or cache. constexpr auto MAX_DLC = 64; - std::map> app_dlcs; // NOLINT(cert-err58-cpp) - std::set fully_fetched; // NOLINT(cert-err58-cpp) + auto& get_fully_fetched_apps() { + static std::set fully_fetched_apps; + return fully_fetched_apps; + } + + auto& get_app_dlc_map() { + static std::map> app_dlc_map; + return app_dlc_map; + } std::string get_app_id_log(const uint32_t app_id) { return app_id ? std::format("App ID: {:>8}, ", app_id) : ""; @@ -31,13 +38,13 @@ namespace { if(app_id == 0) { LOG_ERROR("{} -> App ID is 0", __func__); - app_dlcs[app_id] = {}; // Dummy value to avoid checking for presence on each access + get_app_dlc_map()[app_id] = {}; // Dummy value to avoid checking for presence on each access return; } // We want to fetch data only once. However, if any of the remote sources have failed // previously, we want to attempt fetching again. - if(fully_fetched.contains(app_id)) { + if(get_fully_fetched_apps().contains(app_id)) { return; } @@ -67,13 +74,13 @@ namespace { } if(github_dlcs_opt && steam_dlcs_opt) { - fully_fetched.insert(app_id); + get_fully_fetched_apps().insert(app_id); } else { append_dlcs(smoke_api::cache::get_dlcs(app_id), "disk cache"); } // Cache DLCs in memory and cache for future use - app_dlcs[app_id] = aggregated_dlcs; + get_app_dlc_map()[app_id] = aggregated_dlcs; smoke_api::cache::save_dlcs(app_id, aggregated_dlcs); } @@ -137,12 +144,12 @@ namespace smoke_api::steam_apps { fetch_and_cache_dlcs(app_id); - if(app_dlcs.empty()) { + if(get_app_dlc_map().empty()) { LOG_DEBUG("{} -> No cached DLCs, responding with original count", function_name); return total_count(original_count); } - return total_count(static_cast(app_dlcs[app_id].size())); + return total_count(static_cast(get_app_dlc_map()[app_id].size())); } catch(const std::exception& e) { LOG_ERROR("{} -> Uncaught exception: {}", function_name, e.what()); return 0; @@ -188,8 +195,8 @@ namespace smoke_api::steam_apps { pchName[bytes_to_copy] = '\0'; // Ensure null-termination }; - if(!app_dlcs.empty() && app_dlcs.contains(app_id)) { - const auto& dlcs = app_dlcs[app_id]; + if(!get_app_dlc_map().empty() && get_app_dlc_map().contains(app_id)) { + const auto& dlcs = get_app_dlc_map()[app_id]; if(iDLC >= 0 && iDLC < dlcs.size()) { output_dlc(dlcs[iDLC]); diff --git a/static/smoke_api/interfaces/steam_http.cpp b/static/smoke_api/interfaces/steam_http.cpp index 6315abf..b25737f 100644 --- a/static/smoke_api/interfaces/steam_http.cpp +++ b/static/smoke_api/interfaces/steam_http.cpp @@ -14,7 +14,7 @@ namespace smoke_api::steam_http { try { const auto result = original_function(); - if(config::instance.log_steam_http) { + if(config::get().log_steam_http) { const std::string_view buffer = pBodyDataBuffer && unBufferSize ? std::string_view( @@ -50,7 +50,7 @@ namespace smoke_api::steam_http { try { const auto result = original_function(); - if(config::instance.log_steam_http) { + if(config::get().log_steam_http) { const std::string_view buffer = pBodyDataBuffer && unBufferSize ? std::string_view( @@ -87,7 +87,7 @@ namespace smoke_api::steam_http { try { const auto result = original_function(); - if(config::instance.log_steam_http) { + if(config::get().log_steam_http) { const std::string_view content_type = pchContentType ? pchContentType : "smoke_api::N/A"; diff --git a/static/smoke_api/interfaces/steam_inventory.cpp b/static/smoke_api/interfaces/steam_inventory.cpp index ef4ba51..2c3962a 100644 --- a/static/smoke_api/interfaces/steam_inventory.cpp +++ b/static/smoke_api/interfaces/steam_inventory.cpp @@ -70,11 +70,11 @@ namespace smoke_api::steam_inventory { ); static uint32_t original_count = 0; - const auto injected_count = config::instance.extra_inventory_items.size(); + const auto injected_count = config::get().extra_inventory_items.size(); // Automatically get inventory items from steam static std::vector auto_inventory_items; - if(config::instance.auto_inject_inventory) { + if(config::get().auto_inject_inventory) { static std::once_flag inventory_inject_flag; std::call_once( inventory_inject_flag, @@ -126,7 +126,7 @@ namespace smoke_api::steam_inventory { for(int i = 0; i < injected_count; i++) { auto& item = pOutItemsArray[original_count + auto_injected_count + i]; - const auto item_def_id = config::instance.extra_inventory_items[i]; + const auto item_def_id = config::get().extra_inventory_items[i]; item = new_item(item_def_id);