From 868d6ea14aea40cf9c486353560926e34021b0e1 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 10 May 2022 18:09:31 +0200 Subject: [PATCH 1/4] Extraneous string array --- r5dev/squirrel/sqtype.h | 8 -------- r5dev/squirrel/sqvm.cpp | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/r5dev/squirrel/sqtype.h b/r5dev/squirrel/sqtype.h index 45ad0e60..cfcf497e 100644 --- a/r5dev/squirrel/sqtype.h +++ b/r5dev/squirrel/sqtype.h @@ -92,14 +92,6 @@ const static std::string SQVM_LOG_T[4] = "Script(X):" }; -const static std::string SQVM_WARNING_LOG_T[4] = -{ - "Script(S):", - "Script(C):", - "Script(U):", - "Script(X):" -}; - const static std::string SQVM_ANSI_LOG_T[4] = { "\033[38;2;151;149;187mScript(S):", diff --git a/r5dev/squirrel/sqvm.cpp b/r5dev/squirrel/sqvm.cpp index c540c792..cfd12975 100644 --- a/r5dev/squirrel/sqvm.cpp +++ b/r5dev/squirrel/sqvm.cpp @@ -189,7 +189,7 @@ SQRESULT HSQVM_WarningFunc(HSQUIRRELVM v, SQInteger a2, SQInteger a3, SQInteger* static std::shared_ptr wconsole = spdlog::get("win_console"); static std::shared_ptr sqlogger = spdlog::get("sqvm_warn_logger"); - std::string vmStr = SQVM_WARNING_LOG_T[static_cast(context)].c_str(); + std::string vmStr = SQVM_LOG_T[static_cast(context)].c_str(); std::string svConstructor(*ppString, *nStringSize); // Get string from memory via std::string constructor. vmStr.append(svConstructor); From 9ceffb2491191bffbc1c83f8eaed40499787c0d1 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 10 May 2022 18:09:49 +0200 Subject: [PATCH 2/4] Fix forgotten color parameter --- r5dev/gameui/IConsole.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r5dev/gameui/IConsole.cpp b/r5dev/gameui/IConsole.cpp index 61f97802..2de7cec4 100644 --- a/r5dev/gameui/IConsole.cpp +++ b/r5dev/gameui/IConsole.cpp @@ -552,9 +552,9 @@ void CConsole::ProcessCommand(const char* pszCommand) } AddLog(ImVec4(0.81f, 0.81f, 0.81f, 1.00f), "Log types:"); - AddLog(ImVec4(0.59f, 0.58f, 0.73f, 1.00f), "Script(S): = Server DLL (Script VM)"); - AddLog(ImVec4(0.59f, 0.58f, 0.63f, 1.00f), "Script(C): = Client DLL (Script VM)"); - AddLog(ImVec4(0.59f, 0.48f, 0.53f, 1.00f), "Script(U): = UI DLL (Script VM)"); + AddLog(ImVec4(0.59f, 0.58f, 0.73f, 1.00f), "Script(S): = Server DLL (Script)"); + AddLog(ImVec4(0.59f, 0.58f, 0.63f, 1.00f), "Script(C): = Client DLL (Script)"); + AddLog(ImVec4(0.59f, 0.48f, 0.53f, 1.00f), "Script(U): = UI DLL (Script)"); AddLog(ImVec4(0.23f, 0.47f, 0.85f, 1.00f), "Native(S): = Server DLL (Code)"); AddLog(ImVec4(0.46f, 0.46f, 0.46f, 1.00f), "Native(C): = Client DLL (Code)"); @@ -766,7 +766,7 @@ void CConsole::AddLog(ImVec4 color, const char* fmt, ...) IM_FMTARGS(2) vsnprintf(buf, IM_ARRAYSIZE(buf), fmt, args); buf[IM_ARRAYSIZE(buf) - 1] = 0; va_end(args); - m_ivConLog.push_back(CConLog(Strdup(buf), ImVec4(1.00f, 0.80f, 0.60f, 1.00f))); + m_ivConLog.push_back(CConLog(Strdup(buf), color)); } //----------------------------------------------------------------------------- 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 3/4] 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(""); From 27c3ed03657215c697e11caa9d738de921efe3a1 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Tue, 10 May 2022 23:36:01 +0200 Subject: [PATCH 4/4] Add print functions for printing '__m128i' datatypes --- r5dev/public/include/utility.h | 5 +++++ r5dev/public/utility.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/r5dev/public/include/utility.h b/r5dev/public/include/utility.h index 2cfc21c8..a5fc974b 100644 --- a/r5dev/public/include/utility.h +++ b/r5dev/public/include/utility.h @@ -32,6 +32,11 @@ vector StringToBytes(const string& svInput, bool bNullTerminator); vector PatternToBytes(const string& svInput); vector IntToDigits(int value); +void PrintM128i8(__m128i in); +void PrintM128i16(__m128i in); +void PrintM128i32(__m128i in); +void PrintM128i64(__m128i in); + string PrintPercentageEscape(const string& svInput); ///////////////////////////////////////////////////////////////////////////// diff --git a/r5dev/public/utility.cpp b/r5dev/public/utility.cpp index f9dacd35..2b086537 100644 --- a/r5dev/public/utility.cpp +++ b/r5dev/public/utility.cpp @@ -489,6 +489,35 @@ vector IntToDigits(int value) return vDigits; } +/////////////////////////////////////////////////////////////////////////////// +// For printing __m128i datatypes. +void PrintM128i8(__m128i in) +{ + alignas(16) uint8_t v[16]; + _mm_store_si128(reinterpret_cast<__m128i*>(v), in); + printf("v16_u8: %x %x %x %x | %x %x %x %x | %x %x %x %x | %x %x %x %x\n", + v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7], + v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); +} +void PrintM128i16(__m128i in) +{ + alignas(16) uint16_t v[8]; + _mm_store_si128(reinterpret_cast<__m128i*>(v), in); + printf("v8_u16: %x %x %x %x, %x %x %x %x\n", v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); +} +void PrintM128i32(__m128i in) +{ + alignas(16) uint32_t v[4]; + _mm_store_si128(reinterpret_cast<__m128i*>(v), in); + printf("v4_u32: %x %x %x %x\n", v[0], v[1], v[2], v[3]); +} +void PrintM128i64(__m128i in) +{ + alignas(16) uint64_t v[2]; // uint64_t might give format-string warnings with %llx; it's just long in some ABIs + _mm_store_si128(reinterpret_cast<__m128i*>(v), in); + printf("v2_u64: %llx %llx\n", v[0], v[1]); +} + /////////////////////////////////////////////////////////////////////////////// // For escaping the '%' character for *rintf. string PrintPercentageEscape(const string& svInput)