[WIP] deadlock fix

master
acidicoala 2 years ago
parent d3a11186d0
commit da43de4065
No known key found for this signature in database
GPG Key ID: D24C6065B49C645B

@ -1 +1 @@
Subproject commit d9b0d1a00beb065a9a931a60ef615ce8d1fc7164
Subproject commit 8dcd746639724d3002493d6604ebf983a31cf060

@ -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(

Loading…
Cancel
Save