mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2026-01-24 13:32:51 -05:00
[WIP] deadlock fix
This commit is contained in:
2
KoalaBox
2
KoalaBox
Submodule KoalaBox updated: d9b0d1a00b...8dcd746639
@@ -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, \
|
||||
|
||||
@@ -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());
|
||||
});
|
||||
|
||||
@@ -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<int()>& original_function) {
|
||||
static std::mutex section;
|
||||
std::lock_guard<std::mutex> guard(section);
|
||||
try {
|
||||
// std::lock_guard<std::mutex> 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<int>(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<int>(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(
|
||||
|
||||
Reference in New Issue
Block a user