From 44f15c34eb72a0f8563d0a5318c092096fb7a3e5 Mon Sep 17 00:00:00 2001 From: KiritoDev <36680385+KiritoDv@users.noreply.github.com> Date: Wed, 11 May 2022 12:18:37 -0500 Subject: [PATCH] Fixed string cvar load and added fipps font --- libultraship/libultraship/GameOverlay.cpp | 11 ++++++++++- soh/soh/Enhancements/debugconsole.cpp | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/libultraship/libultraship/GameOverlay.cpp b/libultraship/libultraship/GameOverlay.cpp index cd06c3dca..a8438643f 100644 --- a/libultraship/libultraship/GameOverlay.cpp +++ b/libultraship/libultraship/GameOverlay.cpp @@ -84,8 +84,17 @@ ImVec2 Ship::GameOverlay::CalculateTextSize(const char* text, const char* text_e void Ship::GameOverlay::Init() { this->LoadFont("Press Start 2P", "assets/ship_of_harkinian/fonts/PressStart2P-Regular.ttf", 12.0f); + this->LoadFont("Fipps", "assets/ship_of_harkinian/fonts/Fipps-Regular.otf", 32.0f); + const std::string DefaultFont = this->Fonts.begin()->first; if(!this->Fonts.empty()) { - this->CurrentFont = CVar_GetString("gOverlayFont", ImStrdup(this->Fonts.begin()->first.c_str())); + const std::string font = CVar_GetString("gOverlayFont", ImStrdup(DefaultFont.c_str())); + for (auto& [name, _] : this->Fonts) { + if (font.starts_with(name)) { + this->CurrentFont = name; + break; + } + this->CurrentFont = DefaultFont; + } } SohImGui::console->Commands["overlay"] = { OverlayCommand, "Draw an overlay using a cvar value" }; } diff --git a/soh/soh/Enhancements/debugconsole.cpp b/soh/soh/Enhancements/debugconsole.cpp index 87252ee92..589e4312e 100644 --- a/soh/soh/Enhancements/debugconsole.cpp +++ b/soh/soh/Enhancements/debugconsole.cpp @@ -421,6 +421,14 @@ template bool is_number(const std::string& s) { return ((std::istringstream(s) >> n >> std::ws).eof()); } +char* Strdup(const char* src) { + const unsigned len = strlen(src) + 1; + char* newstr = static_cast(malloc(len)); + if (newstr) + memcpy(newstr, src, len); + return newstr; +} + void DebugConsole_LoadCVars() { if (File::Exists("cvars.cfg")) { @@ -431,7 +439,9 @@ void DebugConsole_LoadCVars() if (line.empty()) continue; if (cfg.size() < 2) continue; if (cfg[1].find("\"") != std::string::npos) { - CVar_SetString(cfg[0].c_str(), const_cast(cfg[1].c_str())); + std::string value(cfg[1]); + value.erase(std::ranges::remove(value, '\"').begin(), value.end()); + CVar_SetString(cfg[0].c_str(), Strdup(value.c_str())); } if (is_number(cfg[1])) { CVar_SetFloat(cfg[0].c_str(), std::stof(cfg[1]));