From 612b9429a2a81197262ada3179a1448677fb575e Mon Sep 17 00:00:00 2001 From: neru Date: Fri, 19 Jun 2026 08:32:37 -0300 Subject: [PATCH] feat: add config --- src/unlocker/spoofer.cpp | 71 ++++++++++++++++++++++++++++++++++++++++ src/unlocker/spoofer.h | 48 +++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) diff --git a/src/unlocker/spoofer.cpp b/src/unlocker/spoofer.cpp index 2f945b8..6344b73 100644 --- a/src/unlocker/spoofer.cpp +++ b/src/unlocker/spoofer.cpp @@ -22,6 +22,7 @@ Spoofer::Spoofer() _log->info("Spoofer init"); + loadConfig(); } Spoofer::~Spoofer() @@ -42,6 +43,76 @@ void Spoofer::registerListeners(TinyMITMProxy* proxy) this->serverResponseHandler(url, body, headers, wasBlocked); }); } + +/* + config +*/ +struct FileConfig +{ + SpooferConfig profile; + WSMessages::Toggles toggles; +}; + +void Spoofer::loadConfig() +{ + FileConfig conf; + std::string buffer; + std::string configPath = utils::getExePath() + "config.json"; + auto errCtx = glz::read_file_json(conf, configPath, buffer); + if (errCtx.ec == glz::error_code::none) + { + _camperItems = conf.profile.camperItems; + _camperAddons = conf.profile.camperAddons; + _slasherAddons = conf.profile.slasherAddons; + _camperOfferings = conf.profile.camperOfferings; + _slasherOfferings = conf.profile.slasherOfferings; + _globalOfferings = conf.profile.globalOfferings; + _camperPerks = conf.profile.camperPerks; + _slasherPerks = conf.profile.slasherPerks; + _catalogItemIds = conf.profile.catalogItemIds; + _dlcListGRDK = conf.profile.dlcListGRDK; + _dlcListEGS = conf.profile.dlcListEGS; + _dlcListSteam = conf.profile.dlcListSteam; + _unlockedCharacters = conf.profile.unlockedCharacters; + _spoofItems = conf.toggles.spoofItems; + _spoofPerks = conf.toggles.spoofPerks; + _spoofCatalog = conf.toggles.spoofCatalog; + _spoofDLCs = conf.toggles.spoofDLCs; + _log->info("Config loaded successfully from {}", configPath); + } + else + { + _log->info("Config not found or invalid at {}, creating default.", configPath); + saveConfig(); + } +} + +void Spoofer::saveConfig() +{ + std::string configPath = utils::getExePath() + "config.json"; + + FileConfig conf; + conf.profile.camperItems = _camperItems; + conf.profile.camperAddons = _camperAddons; + conf.profile.slasherAddons = _slasherAddons; + conf.profile.camperOfferings = _camperOfferings; + conf.profile.slasherOfferings = _slasherOfferings; + conf.profile.globalOfferings = _globalOfferings; + conf.profile.camperPerks = _camperPerks; + conf.profile.slasherPerks = _slasherPerks; + conf.profile.catalogItemIds = _catalogItemIds; + conf.profile.dlcListGRDK = _dlcListGRDK; + conf.profile.dlcListEGS = _dlcListEGS; + conf.profile.dlcListSteam = _dlcListSteam; + conf.profile.unlockedCharacters = _unlockedCharacters; + conf.toggles.spoofItems = _spoofItems; + conf.toggles.spoofPerks = _spoofPerks; + conf.toggles.spoofCatalog = _spoofCatalog; + conf.toggles.spoofDLCs = _spoofDLCs; + std::string buffer; + auto errCtx = glz::write_file_json(conf, configPath, buffer); + if (errCtx.ec != glz::error_code::none) _log->error("Failed to save config to {}", configPath); +} /* proxy handlers */ diff --git a/src/unlocker/spoofer.h b/src/unlocker/spoofer.h index 4f7d48d..57cab96 100644 --- a/src/unlocker/spoofer.h +++ b/src/unlocker/spoofer.h @@ -14,6 +14,23 @@ namespace seallib class Logger; } +struct SpooferConfig +{ + std::unordered_map camperItems; + std::unordered_map camperAddons; + std::unordered_map slasherAddons; + std::unordered_map camperOfferings; + std::unordered_map slasherOfferings; + std::unordered_map globalOfferings; + std::unordered_set camperPerks; + std::unordered_set slasherPerks; + std::unordered_set catalogItemIds; + std::unordered_set dlcListGRDK; + std::unordered_set dlcListEGS; + std::unordered_set dlcListSteam; + std::unordered_set unlockedCharacters; +}; + class Spoofer { public: @@ -23,12 +40,43 @@ class Spoofer void registerListeners(TinyMITMProxy* proxy); private: + /* + local config handlers + */ + void loadConfig(); + void saveConfig(); /* proxy handlers */ void serverResponseHandler(const std::string& url, std::string& body, std::string& headers, bool& blockOutgoing); void clientRequestHandler(const std::string& url, std::string& body, std::string& headers, bool wasBlocked); + + /* + config + */ + bool _spoofItems = false; + bool _spoofPerks = false; + bool _spoofCatalog = false; + bool _spoofDLCs = false; + + std::unordered_map _camperItems; + std::unordered_map _camperAddons; + std::unordered_map _slasherAddons; + std::unordered_map _camperOfferings; + std::unordered_map _slasherOfferings; + std::unordered_map _globalOfferings; + + std::unordered_set _camperPerks; + std::unordered_set _slasherPerks; + + std::unordered_set _catalogItemIds; + + std::unordered_set _dlcListGRDK; + std::unordered_set _dlcListEGS; + std::unordered_set _dlcListSteam; + + std::unordered_set _unlockedCharacters; seallib::Logger* _log = nullptr; std::mutex _mutex; };