mirror of
https://github.com/acidicoala/SmokeAPI.git
synced 2026-05-11 23:09:50 -04:00
Refactor
This commit is contained in:
63
src/smoke_api/config.cpp
Normal file
63
src/smoke_api/config.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include <smoke_api/config.hpp>
|
||||
#include <core/paths.hpp>
|
||||
#include <koalabox/util.hpp>
|
||||
#include <koalabox/io.hpp>
|
||||
|
||||
namespace smoke_api::config {
|
||||
Config instance; // NOLINT(cert-err58-cpp)
|
||||
|
||||
// TODO: Reloading via export
|
||||
void init() {
|
||||
const auto path = paths::get_config_path();
|
||||
|
||||
if (exists(path)) {
|
||||
try {
|
||||
instance = Json::parse(koalabox::io::read_file(path)).get<Config>();
|
||||
} catch (const Exception& e) {
|
||||
koalabox::util::panic("Error parsing config: {}", e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_unlocked = app_status == config::AppStatus::UNLOCKED;
|
||||
const auto dlc_unlocked = dlc_status == config::DlcStatus::UNLOCKED ||
|
||||
dlc_status != config::DlcStatus::LOCKED &&
|
||||
original_function();
|
||||
|
||||
return app_unlocked && dlc_unlocked;
|
||||
}
|
||||
|
||||
Vector<DLC> get_extra_dlcs(AppId_t app_id) {
|
||||
return DLC::get_dlcs_from_apps(instance.extra_dlcs, app_id);
|
||||
}
|
||||
}
|
||||
74
src/smoke_api/config.hpp
Normal file
74
src/smoke_api/config.hpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
|
||||
#include <core/types.hpp>
|
||||
#include <koalabox/core.hpp>
|
||||
|
||||
namespace smoke_api::config {
|
||||
enum class AppStatus {
|
||||
LOCKED,
|
||||
UNLOCKED,
|
||||
UNDEFINED
|
||||
};
|
||||
|
||||
NLOHMANN_JSON_SERIALIZE_ENUM(AppStatus, {
|
||||
{ AppStatus::UNDEFINED, nullptr },
|
||||
{ AppStatus::LOCKED, "locked" },
|
||||
{ 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" },
|
||||
})
|
||||
|
||||
struct Config {
|
||||
uint32_t $version = 2;
|
||||
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;
|
||||
// We have to use general json type here since the library doesn't support std::optional
|
||||
Json koalageddon_config;
|
||||
|
||||
NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(
|
||||
Config, // NOLINT(misc-const-correctness)
|
||||
$version,
|
||||
logging,
|
||||
unlock_family_sharing,
|
||||
default_app_status,
|
||||
default_dlc_status,
|
||||
override_app_status,
|
||||
override_dlc_status,
|
||||
extra_dlcs,
|
||||
auto_inject_inventory,
|
||||
extra_inventory_items,
|
||||
koalageddon_config
|
||||
)
|
||||
};
|
||||
|
||||
extern Config instance;
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
#include <smoke_api/smoke_api.hpp>
|
||||
#include <build_config.h>
|
||||
#include <core/config.hpp>
|
||||
#include <smoke_api/config.hpp>
|
||||
#include <core/globals.hpp>
|
||||
#include <core/paths.hpp>
|
||||
#include <steam_functions/steam_functions.hpp>
|
||||
#include <koalabox/dll_monitor.hpp>
|
||||
#include <koalabox/logger.hpp>
|
||||
#include <koalabox/hook.hpp>
|
||||
@@ -11,6 +10,7 @@
|
||||
#include <koalabox/loader.hpp>
|
||||
#include <koalabox/win_util.hpp>
|
||||
#include <koalabox/util.hpp>
|
||||
#include <steam_api_exports/steam_api_exports.hpp>
|
||||
|
||||
#if COMPILE_KOALAGEDDON
|
||||
#include <koalageddon/koalageddon.hpp>
|
||||
|
||||
Reference in New Issue
Block a user