diff --git a/libultraship/libultraship/Lib/Mercury/Mercury.cpp b/libultraship/libultraship/Lib/Mercury/Mercury.cpp index d6bf734ea..009b9c0f9 100644 --- a/libultraship/libultraship/Lib/Mercury/Mercury.cpp +++ b/libultraship/libultraship/Lib/Mercury/Mercury.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace fs = std::filesystem; using json = nlohmann::json; @@ -16,18 +17,9 @@ Mercury::Mercury(std::string path) : path_(std::move(path)) { this->reload(); } -std::vector split(const std::string& s, const char delimiter) { - std::vector result; - std::stringstream ss(s); - std::string item; - while (getline(ss, item, delimiter)) { - result.push_back(item); - } - return result; -} - std::string Mercury::formatNestedKey(const std::string& key) { - const std::vector dots = split(key, '.'); + std::vector dots = StringHelper::Split(key, "."); + std::string tmp; if (dots.size() > 1) for (const auto& dot : dots) { @@ -40,7 +32,7 @@ std::string Mercury::formatNestedKey(const std::string& key) { } json Mercury::nested(const std::string& key) { - std::vector dots = split(key, '.'); + std::vector dots = StringHelper::Split(key, "."); if (!this->vjson.is_object()) return this->vjson; json gjson = this->vjson.unflatten(); diff --git a/libultraship/libultraship/Lib/Mercury/Mercury.h b/libultraship/libultraship/Lib/Mercury/Mercury.h index 5c2646d36..92cb2097e 100644 --- a/libultraship/libultraship/Lib/Mercury/Mercury.h +++ b/libultraship/libultraship/Lib/Mercury/Mercury.h @@ -4,6 +4,8 @@ #include #include "../nlohmann/json.hpp" +static const std::string mercuryRGBAObjectType = "RGBA"; + class Mercury { protected: std::string path_; diff --git a/soh/soh/Enhancements/debugconsole.cpp b/soh/soh/Enhancements/debugconsole.cpp index ba866b062..73c54b742 100644 --- a/soh/soh/Enhancements/debugconsole.cpp +++ b/soh/soh/Enhancements/debugconsole.cpp @@ -568,20 +568,18 @@ void DebugConsole_LoadCVars() { switch (value.type()) { case nlohmann::detail::value_t::array: break; - case nlohmann::detail::value_t::string: - if (StringHelper::StartsWith(value.get(), "#")) - { - uint32_t val = std::stoul(&value.get().c_str()[1], nullptr, 16); + case nlohmann::detail::value_t::object: + if (value["Type"].get() == mercuryRGBAObjectType) { Color_RGBA8 clr; - clr.r = val >> 24; - clr.g = val >> 16; - clr.b = val >> 8; - clr.a = val & 0xFF; - - CVar_SetRGBA(item.key().c_str(), clr); + clr.r = value["R"].get(); + clr.g = value["G"].get(); + clr.b = value["B"].get(); + clr.a = value["A"].get(); } - else - CVar_SetString(item.key().c_str(), value.get().c_str()); + + break; + case nlohmann::detail::value_t::string: + CVar_SetString(item.key().c_str(), value.get().c_str()); break; case nlohmann::detail::value_t::boolean: CVar_SetS32(item.key().c_str(), value.get()); @@ -618,10 +616,13 @@ void DebugConsole_SaveCVars() pConf->setFloat(key, cvar.second->value.valueFloat); else if (cvar.second->type == CVarType::RGBA) { + auto keyStr = key.c_str(); Color_RGBA8 clr = cvar.second->value.valueRGBA; - uint32_t val = (clr.r << 24) + (clr.g << 16) + (clr.b << 8) + clr.a; - std::string str = StringHelper::Sprintf("#%08X", val); - pConf->setString(key, str); + pConf->setUInt(StringHelper::Sprintf("%s.R", keyStr), clr.r); + pConf->setUInt(StringHelper::Sprintf("%s.G", keyStr), clr.r); + pConf->setUInt(StringHelper::Sprintf("%s.B", keyStr), clr.r); + pConf->setUInt(StringHelper::Sprintf("%s.A", keyStr), clr.r); + pConf->setString(StringHelper::Sprintf("%s.Type", keyStr), mercuryRGBAObjectType); } }