From 452c8afcf3f3bfecd4a558480780ba1bd7694e06 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 10 May 2022 23:32:44 +0200 Subject: [PATCH] Display '%' symbol properly in console --- r5dev/engine/sys_utils.cpp | 6 +++--- r5dev/gameui/IConsole.cpp | 2 +- r5dev/public/include/utility.h | 3 +++ r5dev/public/utility.cpp | 28 ++++++++++++++++++++++++---- r5dev/squirrel/sqvm.cpp | 4 ++-- 5 files changed, 33 insertions(+), 10 deletions(-) diff --git a/r5dev/engine/sys_utils.cpp b/r5dev/engine/sys_utils.cpp index 329ef727..914f8d9b 100644 --- a/r5dev/engine/sys_utils.cpp +++ b/r5dev/engine/sys_utils.cpp @@ -188,7 +188,7 @@ void DevMsg(eDLL_T idx, const char* fmt, ...) break; } - g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str().c_str(), color)); + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), color)); g_pLogSystem.AddLog(tLog, g_spd_sys_w_oss.str()); g_spd_sys_w_oss.str(""); @@ -265,8 +265,8 @@ void Warning(eDLL_T idx, const char* fmt, ...) #ifndef DEDICATED iconsole->info(svOut); + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); g_pLogSystem.AddLog(LogType_t::WARNING_C, g_spd_sys_w_oss.str()); - g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str(), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); g_spd_sys_w_oss.str(""); g_spd_sys_w_oss.clear(); @@ -342,8 +342,8 @@ void Error(eDLL_T idx, const char* fmt, ...) #ifndef DEDICATED iconsole->info(svOut); + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 0.00f, 0.00f, 1.00f))); g_pLogSystem.AddLog(LogType_t::ERROR_C, g_spd_sys_w_oss.str()); - g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str(), ImVec4(1.00f, 0.00f, 0.00f, 1.00f))); g_spd_sys_w_oss.str(""); g_spd_sys_w_oss.clear(); diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 2de7cec4..ffdf533e 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -520,7 +520,7 @@ void CConsole::FindFromPartial(void) //----------------------------------------------------------------------------- void CConsole::ProcessCommand(const char* pszCommand) { - AddLog(ImVec4(1.00f, 0.80f, 0.60f, 1.00f), "# %s\n", pszCommand); + AddLog(ImVec4(1.00f, 0.80f, 0.60f, 1.00f), "# %s\n", PrintPercentageEscape(pszCommand).c_str()); std::thread t(CEngineClient_CommandExecute, this, pszCommand); t.detach(); // Detach from render thread. diff --git a/r5dev/public/include/utility.h b/r5dev/public/include/utility.h index 2687b244..2cfc21c8 100644 --- a/r5dev/public/include/utility.h +++ b/r5dev/public/include/utility.h @@ -27,8 +27,11 @@ bool CompareStringLexicographically(const string& svA, const string& svB); bool StringReplace(string& svInput, const string& svFrom, const string& svTo); string StringEscape(const string& svInput); string StringUnescape(const string& svInput); + vector StringToBytes(const string& svInput, bool bNullTerminator); vector PatternToBytes(const string& svInput); vector IntToDigits(int value); +string PrintPercentageEscape(const string& svInput); + ///////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/public/utility.cpp b/r5dev/public/utility.cpp index 2d660391..f9dacd35 100644 --- a/r5dev/public/utility.cpp +++ b/r5dev/public/utility.cpp @@ -144,7 +144,7 @@ void PrintLastError(void) } /////////////////////////////////////////////////////////////////////////////// -// For dumping data from a buffer to a file on the disk +// For dumping data from a buffer to a file on the disk. void HexDump(const char* szHeader, const char* szLogger, const void* pData, int nSize) { static unsigned char szAscii[17] = {}; @@ -345,7 +345,7 @@ string Base64Decode(const string& svInput) } /////////////////////////////////////////////////////////////////////////////// -// For comparing input strings alphabetically +// For comparing input strings alphabetically. bool CompareStringAlphabetically(const string& svA, const string& svB) { int i = 0; @@ -358,7 +358,7 @@ bool CompareStringAlphabetically(const string& svA, const string& svB) } /////////////////////////////////////////////////////////////////////////////// -// For comparing input strings lexicographically +// For comparing input strings lexicographically. bool CompareStringLexicographically(const string& svA, const string& svB) { return svA < svB; @@ -384,6 +384,7 @@ string StringEscape(const string& svInput) { string results; results.reserve(svInput.size()); + for (const char c : svInput) { switch (c) @@ -408,6 +409,7 @@ string StringUnescape(const string& svInput) { string results; results.reserve(svInput.size()); + for (const char c : svInput) { switch (c) @@ -475,7 +477,7 @@ vector PatternToBytes(const string& svInput) }; /////////////////////////////////////////////////////////////////////////////// -// For converting a integer into digits +// For converting a integer into digits. vector IntToDigits(int value) { vector vDigits; @@ -486,3 +488,21 @@ vector IntToDigits(int value) std::reverse(vDigits.begin(), vDigits.end()); return vDigits; } + +/////////////////////////////////////////////////////////////////////////////// +// For escaping the '%' character for *rintf. +string PrintPercentageEscape(const string& svInput) +{ + string results; + results.reserve(svInput.size()); + + for (const char c : svInput) + { + switch (c) + { + case '%': results += "%%"; break; + default: results += c; break; + } + } + return results; +} \ No newline at end of file diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index cfd12975..cae6c735 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -147,7 +147,7 @@ SQRESULT HSQVM_PrintFunc(HSQUIRRELVM v, SQChar* fmt, ...) } } - g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str(), color)); + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), color)); g_pLogSystem.AddLog(static_cast(context), g_spd_sys_w_oss.str()); g_spd_sys_w_oss.str(""); @@ -216,7 +216,7 @@ SQRESULT HSQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger* #ifndef DEDICATED iconsole->debug(vmStr); // Emit to in-game console. - g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str(), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); + g_pIConsole->m_ivConLog.push_back(CConLog(PrintPercentageEscape(g_spd_sys_w_oss.str()), ImVec4(1.00f, 1.00f, 0.00f, 0.80f))); g_pLogSystem.AddLog(LogType_t::WARNING_C, g_spd_sys_w_oss.str()); g_spd_sys_w_oss.str("");