From 82e2abd1172109b18b0cb6e2e3659554c2a51bc2 Mon Sep 17 00:00:00 2001 From: redpolline <11156324-redpolline@users.noreply.gitlab.com> Date: Wed, 12 Feb 2025 07:11:01 -0500 Subject: [PATCH] Fix incorrect achievements.json parsing. The correct name for the locked achievement image is "icon_gray". Also fix the debugging counters and properly check for an existing key in the parsed json. --- dll/steam_user_stats.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/dll/steam_user_stats.h b/dll/steam_user_stats.h index 617295a..50352a4 100644 --- a/dll/steam_user_stats.h +++ b/dll/steam_user_stats.h @@ -151,10 +151,21 @@ void load_achievements_db() for (auto & it : defined_achievements) { name = ""; try { - name = static_cast(it["name"]); + auto name_it = it.find("name"); + if (name_it != it.end()) { + name = static_cast(*name_it); + } if (name.length() > 0) { - std::string normal = Local_Storage::get_game_settings_path() + static_cast(it["icon"]); - std::string gray = Local_Storage::get_game_settings_path() + static_cast(it["icongray"]); + auto normal_it = it.find("icon"); + auto gray_it = it.find("icon_gray"); + std::string normal = ""; + std::string gray = ""; + if (normal_it != it.end()) { + normal = Local_Storage::get_game_settings_path() + static_cast(*normal_it); + } + if (gray_it != it.end()) { + gray = Local_Storage::get_game_settings_path() + static_cast(*gray_it); + } if (normal.length() > 0 && gray.length() > 0) { uint32 normal_height = 0; uint32 normal_width = 0; @@ -227,10 +238,10 @@ void load_achievements_db() count, corrupt_count, bad_count); - PRINT_DEBUG("ignored %" PRIu64 " missing normal achivement images.\nignored %" PRIu64 " missing gray achivement images.\n", + PRINT_DEBUG("ignored %" PRIu64 " missing normal achievement images.\nignored %" PRIu64 " missing gray achievement images.\n", missing_normal_images, missing_gray_images); - PRINT_DEBUG("ignored %" PRIu64 " unreadable normal achivement images.\nignored %" PRIu64 " unreadable gray achivement images.\n", + PRINT_DEBUG("ignored %" PRIu64 " unreadable normal achievement images.\nignored %" PRIu64 " unreadable gray achievement images.\n", unreadable_normal_images, unreadable_gray_images); }