feat: add config

This commit is contained in:
2026-06-19 08:32:37 -03:00
parent 51a349c367
commit 612b9429a2
2 changed files with 119 additions and 0 deletions
+71
View File
@@ -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
*/