|
|
|
@ -14,7 +14,6 @@
|
|
|
|
|
#define Path _Path
|
|
|
|
|
#define PATH_HACK
|
|
|
|
|
#include <Utils/StringHelper.h>
|
|
|
|
|
#include <Utils/File.h>
|
|
|
|
|
|
|
|
|
|
#include "Window.h"
|
|
|
|
|
#include "Lib/ImGui/imgui_internal.h"
|
|
|
|
@ -426,7 +425,7 @@ static bool SetCVarHandler(const std::vector<std::string>& args) {
|
|
|
|
|
else
|
|
|
|
|
CVar_SetS32(args[1].c_str(), std::stoi(args[2]));
|
|
|
|
|
|
|
|
|
|
DebugConsole_SaveCVars();
|
|
|
|
|
CVar_Save();
|
|
|
|
|
|
|
|
|
|
//INFO("[SOH] Updated player position to [ %.2f, %.2f, %.2f ]", pos.x, pos.y, pos.z);
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
@ -507,123 +506,5 @@ void DebugConsole_Init(void) {
|
|
|
|
|
Ship::ArgumentType::NUMBER,
|
|
|
|
|
}
|
|
|
|
|
} });
|
|
|
|
|
DebugConsole_LoadCVars();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename Numeric> bool is_number(const std::string& s) {
|
|
|
|
|
Numeric n;
|
|
|
|
|
return ((std::istringstream(s) >> n >> std::ws).eof());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugConsole_LoadLegacyCVars() {
|
|
|
|
|
auto cvarsConfig = Ship::GlobalCtx2::GetPathRelativeToAppDirectory("cvars.cfg");
|
|
|
|
|
if (File::Exists(cvarsConfig)) {
|
|
|
|
|
const auto lines = File::ReadAllLines(cvarsConfig);
|
|
|
|
|
|
|
|
|
|
for (const std::string& line : lines) {
|
|
|
|
|
std::vector<std::string> cfg = StringHelper::Split(line, " = ");
|
|
|
|
|
if (line.empty()) continue;
|
|
|
|
|
if (cfg.size() < 2) continue;
|
|
|
|
|
|
|
|
|
|
if (cfg[1].find("\"") == std::string::npos && (cfg[1].find("#") != std::string::npos))
|
|
|
|
|
{
|
|
|
|
|
std::string value(cfg[1]);
|
|
|
|
|
value.erase(std::remove_if(value.begin(), value.end(), [](char c) { return c == '#'; }), value.end());
|
|
|
|
|
auto splitTest = StringHelper::Split(value, "\r")[0];
|
|
|
|
|
|
|
|
|
|
uint32_t val = std::stoul(splitTest, nullptr, 16);
|
|
|
|
|
Color_RGBA8 clr;
|
|
|
|
|
clr.r = val >> 24;
|
|
|
|
|
clr.g = val >> 16;
|
|
|
|
|
clr.b = val >> 8;
|
|
|
|
|
clr.a = val & 0xFF;
|
|
|
|
|
CVar_SetRGBA(cfg[0].c_str(), clr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cfg[1].find("\"") != std::string::npos) {
|
|
|
|
|
std::string value(cfg[1]);
|
|
|
|
|
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
|
|
|
|
|
CVar_SetString(cfg[0].c_str(), ImStrdup(value.c_str()));
|
|
|
|
|
}
|
|
|
|
|
if (is_number<float>(cfg[1])) {
|
|
|
|
|
CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));
|
|
|
|
|
}
|
|
|
|
|
if (is_number<int>(cfg[1])) {
|
|
|
|
|
CVar_SetS32(cfg[0].c_str(), std::stoi(cfg[1]));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fs::remove(cvarsConfig);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugConsole_LoadCVars() {
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
|
|
|
|
|
pConf->reload();
|
|
|
|
|
|
|
|
|
|
for (const auto& item : pConf->rjson["CVars"].items()) {
|
|
|
|
|
auto value = item.value();
|
|
|
|
|
switch (value.type()) {
|
|
|
|
|
case nlohmann::detail::value_t::array:
|
|
|
|
|
break;
|
|
|
|
|
case nlohmann::detail::value_t::object:
|
|
|
|
|
if (value["Type"].get<std::string>() == mercuryRGBAObjectType) {
|
|
|
|
|
Color_RGBA8 clr;
|
|
|
|
|
clr.r = value["R"].get<uint8_t>();
|
|
|
|
|
clr.g = value["G"].get<uint8_t>();
|
|
|
|
|
clr.b = value["B"].get<uint8_t>();
|
|
|
|
|
clr.a = value["A"].get<uint8_t>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
case nlohmann::detail::value_t::string:
|
|
|
|
|
CVar_SetString(item.key().c_str(), value.get<std::string>().c_str());
|
|
|
|
|
break;
|
|
|
|
|
case nlohmann::detail::value_t::boolean:
|
|
|
|
|
CVar_SetS32(item.key().c_str(), value.get<bool>());
|
|
|
|
|
break;
|
|
|
|
|
case nlohmann::detail::value_t::number_unsigned:
|
|
|
|
|
case nlohmann::detail::value_t::number_integer:
|
|
|
|
|
CVar_SetS32(item.key().c_str(), value.get<int>());
|
|
|
|
|
break;
|
|
|
|
|
case nlohmann::detail::value_t::number_float:
|
|
|
|
|
CVar_SetFloat(item.key().c_str(), value.get<float>());
|
|
|
|
|
break;
|
|
|
|
|
default: ;
|
|
|
|
|
}
|
|
|
|
|
if (item.key() == "gOpenMenuBar") {
|
|
|
|
|
int bp = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DebugConsole_LoadLegacyCVars();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DebugConsole_SaveCVars()
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<Mercury> pConf = Ship::GlobalCtx2::GetInstance()->GetConfig();
|
|
|
|
|
|
|
|
|
|
for (const auto &cvar : cvars) {
|
|
|
|
|
const std::string key = StringHelper::Sprintf("CVars.%s", cvar.first.c_str());
|
|
|
|
|
|
|
|
|
|
if (cvar.second->type == CVarType::String && cvar.second->value.valueStr != nullptr)
|
|
|
|
|
pConf->setString(key, std::string(cvar.second->value.valueStr));
|
|
|
|
|
else if (cvar.second->type == CVarType::S32)
|
|
|
|
|
pConf->setInt(key, cvar.second->value.valueS32);
|
|
|
|
|
else if (cvar.second->type == CVarType::Float)
|
|
|
|
|
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;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pConf->save();
|
|
|
|
|
CVar_Load();
|
|
|
|
|
}
|
|
|
|
|