diff --git a/KoalaBox b/KoalaBox index d9b0d1a..8dcd746 160000 --- a/KoalaBox +++ b/KoalaBox @@ -1 +1 @@ -Subproject commit d9b0d1a00beb065a9a931a60ef615ce8d1fc7164 +Subproject commit 8dcd746639724d3002493d6604ebf983a31cf060 diff --git a/src/smoke_api/smoke_api.hpp b/src/smoke_api/smoke_api.hpp index 80e53fe..3aabdaf 100644 --- a/src/smoke_api/smoke_api.hpp +++ b/src/smoke_api/smoke_api.hpp @@ -14,7 +14,7 @@ ); #define GET_ORIGINAL_VIRTUAL_FUNCTION(FUNC) \ - static const auto FUNC##_o = hook::get_original_function( \ + const auto FUNC##_o = hook::get_original_function( \ true, \ smoke_api::original_library, \ #FUNC, \ diff --git a/src/steam_api_virtuals/isteamapps.cpp b/src/steam_api_virtuals/isteamapps.cpp index 2acd59a..fbe50bf 100644 --- a/src/steam_api_virtuals/isteamapps.cpp +++ b/src/steam_api_virtuals/isteamapps.cpp @@ -12,8 +12,9 @@ VIRTUAL(bool) ISteamApps_BIsDlcInstalled(PARAMS(AppId_t appID)) { // NOLINT(misc } VIRTUAL(int) ISteamApps_GetDLCCount(PARAMS()) { + GET_ORIGINAL_VIRTUAL_FUNCTION(ISteamApps_GetDLCCount) + return steam_apps::GetDLCCount(__func__, 0, [&]() { - GET_ORIGINAL_VIRTUAL_FUNCTION(ISteamApps_GetDLCCount) return ISteamApps_GetDLCCount_o(ARGS()); }); diff --git a/src/steam_impl/steam_apps.cpp b/src/steam_impl/steam_apps.cpp index 281e281..63a6a6f 100644 --- a/src/steam_impl/steam_apps.cpp +++ b/src/steam_impl/steam_apps.cpp @@ -149,42 +149,49 @@ namespace steam_apps { return installed; } +// std::mutex section; int GetDLCCount(const String& function_name, const AppId_t app_id, const std::function& original_function) { - static std::mutex section; - std::lock_guard guard(section); + try { +// std::lock_guard guard(section); - if (app_id) { - logger->debug("{} -> App ID: {}", function_name, app_id); - } + const auto total_count = [&](int count) { + logger->info("{} -> Responding with DLC count: {}", function_name, count); + return count; + }; - // Compute count only once // FIXME: This doesn't work in Koalageddon mode - static int total_count = [&]() { + if (app_id) { + logger->debug("{} -> App ID: {}", function_name, app_id); + } + + // Compute count only once // FIXME: This doesn't work in Koalageddon mode original_dlc_count = original_function(); logger->debug("{} -> Original DLC count: {}", function_name, original_dlc_count); const auto injected_count = static_cast(config.dlc_ids.size()); logger->debug("{} -> Injected DLC count: {}", function_name, injected_count); - if (original_dlc_count < max_dlc) { - // Steamworks may max out this value at 64, depending on how much unowned DLCs the user has. - // Despite this limit, some games with more than 64 DLCs still keep using this method. - // This means we have to fetch full list of IDs from web api. - return original_dlc_count + injected_count; + if (original_dlc_count < max_dlc) { + return total_count(original_dlc_count + injected_count); } - logger->debug("Game has {} or more DLCs. Fetching DLCs from a web API.", max_dlc); - fetch_and_cache_dlcs(app_id); + // Steamworks may max out this value at 64, depending on how much unowned DLCs the user has. + // Despite this limit, some games with more than 64 DLCs still keep using this method. + // This means we have to fetch full list of IDs from web api. + static std::once_flag flag; + std::call_once(flag, [&]() { + logger->debug("Game has {} or more DLCs. Fetching DLCs from a web API.", max_dlc); + fetch_and_cache_dlcs(app_id); + }); const auto fetched_count = static_cast(cached_dlcs.size()); logger->debug("{} -> Fetched/cached DLC count: {}", function_name, fetched_count); - return fetched_count + injected_count; - }(); - - logger->info("{} -> Responding with DLC count: {}", function_name, total_count); - - return total_count; + return total_count(fetched_count + injected_count); + } catch (const Exception& ex) { + logger->error("{} -> {}", function_name, ex.what()); + return 0; + } } bool GetDLCDataByIndex(