diff --git a/README.md b/README.md index f5f9834..8713624 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ SmokeAPI does not require any manual configuration. By default, it uses the most ยน DLC/Item IDs can be obtained from https://steamdb.info. You need to be logged in with your steam account in order to see accurate inventory item IDs. -[SmokeAPI.json]: res/SmokeAPI.json +[SmokeAPI.json]: res/SmokeAPI.config.json [manually maintained list of DLC IDs]: https://github.com/acidicoala/public-entitlements/blob/main/steam/v1/dlc.json diff --git a/res/SmokeAPI.json b/res/SmokeAPI.config.json similarity index 69% rename from res/SmokeAPI.json rename to res/SmokeAPI.config.json index deb8151..36ec107 100644 --- a/res/SmokeAPI.json +++ b/res/SmokeAPI.config.json @@ -3,15 +3,10 @@ "logging": true, "unlock_family_sharing": true, "default_app_status": "unlocked", - "default_dlc_status": "unlocked", "override_app_status": { - "1234": "locked", - "4321": "unlocked" - }, - "override_dlc_status": { - "56789": "locked", - "98765": "unlocked", - "16384": "original" + "1234": "original", + "4321": "unlocked", + "5678": "locked" }, "extra_dlcs": { "1234": { diff --git a/src/smoke_api/config.cpp b/src/smoke_api/config.cpp index 9c290a7..060352a 100644 --- a/src/smoke_api/config.cpp +++ b/src/smoke_api/config.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace smoke_api::config { Config instance; // NOLINT(cert-err58-cpp) @@ -19,42 +20,39 @@ namespace smoke_api::config { } } - AppStatus get_app_status(AppId_t app_id) { - if (app_id == 0) { - // 0 is a special internal value reserved for cases where we don't know id. - // This is typically the case in non-koalageddon modes, hence we treat it as unlocked. - return AppStatus::UNLOCKED; - } + bool is_dlc_unlocked(AppId_t app_id, AppId_t dlc_id, const Function& original_function) { + const auto app_id_str = std::to_string(app_id); + const auto dlc_id_str = std::to_string(dlc_id); - const auto app_id_key = std::to_string(app_id); + auto status = instance.default_app_status; - if (instance.override_app_status.contains(app_id_key)) { - return instance.override_app_status[app_id_key]; + if (instance.override_app_status.contains(app_id_str)) { + status = instance.override_app_status[app_id_str]; } - return instance.default_app_status; - } - - DlcStatus get_dlc_status(AppId_t dlc_id) { - const auto dlc_id_key = std::to_string(dlc_id); - - if (instance.override_dlc_status.contains(dlc_id_key)) { - return instance.override_dlc_status[dlc_id_key]; + if (instance.override_app_status.contains(dlc_id_str)) { + status = instance.override_app_status[dlc_id_str]; } - return instance.default_dlc_status; - } - - bool is_dlc_unlocked(AppId_t app_id, AppId_t dlc_id, const Function& original_function) { - const auto app_status = config::get_app_status(app_id); - const auto dlc_status = config::get_dlc_status(dlc_id); - - const auto app_unlocked = app_status == config::AppStatus::UNLOCKED; - const auto dlc_unlocked = dlc_status == config::DlcStatus::UNLOCKED || - dlc_status != config::DlcStatus::LOCKED && - original_function(); + bool is_unlocked; + switch (status) { + case AppStatus::UNLOCKED: + is_unlocked = true; + break; + case AppStatus::LOCKED: + is_unlocked = false; + break; + case AppStatus::ORIGINAL: + case AppStatus::UNDEFINED: + is_unlocked = original_function(); + break; + } + LOG_TRACE( + "App ID: {}, DLC ID: {}, Status: {}, Original: {}, Is Unlocked: {}", + app_id_str, dlc_id_str, Json(status).dump(), original_function(), is_unlocked + ) - return app_unlocked && dlc_unlocked; + return is_unlocked; } Vector get_extra_dlcs(AppId_t app_id) { diff --git a/src/smoke_api/config.hpp b/src/smoke_api/config.hpp index c560d31..e7f9fcd 100644 --- a/src/smoke_api/config.hpp +++ b/src/smoke_api/config.hpp @@ -4,30 +4,19 @@ #include namespace smoke_api::config { + enum class AppStatus { - LOCKED, + UNDEFINED, + ORIGINAL, UNLOCKED, - UNDEFINED + LOCKED, }; NLOHMANN_JSON_SERIALIZE_ENUM(AppStatus, { { AppStatus::UNDEFINED, nullptr }, - { AppStatus::LOCKED, "locked" }, + { AppStatus::ORIGINAL, "original" }, { AppStatus::UNLOCKED, "unlocked" }, - }) - - enum class DlcStatus { - LOCKED, - UNLOCKED, - ORIGINAL, - UNDEFINED - }; - - NLOHMANN_JSON_SERIALIZE_ENUM(DlcStatus, { - { DlcStatus::UNDEFINED, nullptr }, - { DlcStatus::LOCKED, "locked" }, - { DlcStatus::UNLOCKED, "unlocked" }, - { DlcStatus::ORIGINAL, "original" }, + { AppStatus::LOCKED, "locked" }, }) struct Config { @@ -35,9 +24,7 @@ namespace smoke_api::config { bool logging = false; bool unlock_family_sharing = true; AppStatus default_app_status = AppStatus::UNLOCKED; - DlcStatus default_dlc_status = DlcStatus::UNLOCKED; Map override_app_status; - Map override_dlc_status; AppDlcNameMap extra_dlcs; bool auto_inject_inventory = true; Vector extra_inventory_items; @@ -50,9 +37,7 @@ namespace smoke_api::config { logging, unlock_family_sharing, default_app_status, - default_dlc_status, override_app_status, - override_dlc_status, extra_dlcs, auto_inject_inventory, extra_inventory_items, @@ -64,10 +49,6 @@ namespace smoke_api::config { void init(); - AppStatus get_app_status(uint32_t app_id); - - DlcStatus get_dlc_status(uint32_t dlc_id); - bool is_dlc_unlocked(uint32_t app_id, uint32_t dlc_id, const Function& original_function); Vector get_extra_dlcs(AppId_t app_id);