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"); _log->info("Spoofer init");
loadConfig();
} }
Spoofer::~Spoofer() Spoofer::~Spoofer()
@@ -42,6 +43,76 @@ void Spoofer::registerListeners(TinyMITMProxy* proxy)
this->serverResponseHandler(url, body, headers, wasBlocked); 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 proxy handlers
*/ */
+48
View File
@@ -14,6 +14,23 @@ namespace seallib
class Logger; class Logger;
} }
struct SpooferConfig
{
std::unordered_map<std::string, int> camperItems;
std::unordered_map<std::string, int> camperAddons;
std::unordered_map<std::string, int> slasherAddons;
std::unordered_map<std::string, int> camperOfferings;
std::unordered_map<std::string, int> slasherOfferings;
std::unordered_map<std::string, int> globalOfferings;
std::unordered_set<std::string> camperPerks;
std::unordered_set<std::string> slasherPerks;
std::unordered_set<std::string> catalogItemIds;
std::unordered_set<std::string> dlcListGRDK;
std::unordered_set<std::string> dlcListEGS;
std::unordered_set<std::string> dlcListSteam;
std::unordered_set<std::string> unlockedCharacters;
};
class Spoofer class Spoofer
{ {
public: public:
@@ -23,12 +40,43 @@ class Spoofer
void registerListeners(TinyMITMProxy* proxy); void registerListeners(TinyMITMProxy* proxy);
private: private:
/*
local config handlers
*/
void loadConfig();
void saveConfig();
/* /*
proxy handlers proxy handlers
*/ */
void serverResponseHandler(const std::string& url, std::string& body, std::string& headers, void serverResponseHandler(const std::string& url, std::string& body, std::string& headers,
bool& blockOutgoing); bool& blockOutgoing);
void clientRequestHandler(const std::string& url, std::string& body, std::string& headers, bool wasBlocked); 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<std::string, int> _camperItems;
std::unordered_map<std::string, int> _camperAddons;
std::unordered_map<std::string, int> _slasherAddons;
std::unordered_map<std::string, int> _camperOfferings;
std::unordered_map<std::string, int> _slasherOfferings;
std::unordered_map<std::string, int> _globalOfferings;
std::unordered_set<std::string> _camperPerks;
std::unordered_set<std::string> _slasherPerks;
std::unordered_set<std::string> _catalogItemIds;
std::unordered_set<std::string> _dlcListGRDK;
std::unordered_set<std::string> _dlcListEGS;
std::unordered_set<std::string> _dlcListSteam;
std::unordered_set<std::string> _unlockedCharacters;
seallib::Logger* _log = nullptr; seallib::Logger* _log = nullptr;
std::mutex _mutex; std::mutex _mutex;
}; };