Updated app id status

This commit is contained in:
acidicoala 2023-01-10 03:17:37 +03:00
parent 59fa68a7b4
commit 30f1076261
No known key found for this signature in database
GPG Key ID: D24C6065B49C645B
4 changed files with 41 additions and 67 deletions

View File

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

View File

@ -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": {

View File

@ -2,6 +2,7 @@
#include <core/paths.hpp>
#include <koalabox/util.hpp>
#include <koalabox/io.hpp>
#include <koalabox/logger.hpp>
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;
}
const auto app_id_key = std::to_string(app_id);
if (instance.override_app_status.contains(app_id_key)) {
return instance.override_app_status[app_id_key];
}
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];
}
return instance.default_dlc_status;
}
bool is_dlc_unlocked(AppId_t app_id, AppId_t dlc_id, const Function<bool()>& 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_id_str = std::to_string(app_id);
const auto dlc_id_str = std::to_string(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();
auto status = instance.default_app_status;
return app_unlocked && dlc_unlocked;
if (instance.override_app_status.contains(app_id_str)) {
status = instance.override_app_status[app_id_str];
}
if (instance.override_app_status.contains(dlc_id_str)) {
status = instance.override_app_status[dlc_id_str];
}
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 is_unlocked;
}
Vector<DLC> get_extra_dlcs(AppId_t app_id) {

View File

@ -4,30 +4,19 @@
#include <koalabox/core.hpp>
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<String, AppStatus> override_app_status;
Map<String, DlcStatus> override_dlc_status;
AppDlcNameMap extra_dlcs;
bool auto_inject_inventory = true;
Vector<uint32_t> 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<bool()>& original_function);
Vector<DLC> get_extra_dlcs(AppId_t app_id);