From 313433b4e6f9f11bd2c0225b4aaba4ff79d24ac9 Mon Sep 17 00:00:00 2001 From: mjkzy Date: Thu, 2 Jun 2022 06:49:43 -0500 Subject: [PATCH] move clean text to game class --- src/client/component/console.cpp | 38 +------------------------------ src/client/game/game.cpp | 39 ++++++++++++++++++++++++++++++++ src/client/game/game.hpp | 2 ++ 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/client/component/console.cpp b/src/client/component/console.cpp index eefb69d6..841e72eb 100644 --- a/src/client/component/console.cpp +++ b/src/client/component/console.cpp @@ -62,42 +62,6 @@ namespace console return utils::hook::invoke(0x142333820_g, hWnd, uMsg, wParam, lParam); } - // cod naming, functionality stolen from https://github.com/id-Software/Quake-III-Arena/blob/master/code/win32/win_syscon.c#L520 - int conbuf_clean_text(const char* source, char* target) - { - char* b = target; - int i = 0; - while (source[i] && ((b - target) < sizeof(target) - 1)) - { - if (source[i] == '\n' && source[i + 1] == '\r') - { - b[0] = '\r'; - b[1] = '\n'; - b += 2; - i++; - } - else if (source[i] == '\r' || source[i] == '\n') - { - b[0] = '\r'; - b[1] = '\n'; - b += 2; - } - else if (source && source[0] == '^' && source[1] && source[1] != '^' && source[1] >= 48 && source[1] <= 64) // Q_IsColorString - { - i++; - } - else - { - *b = source[i]; // C6011 here, should we be worried? - b++; - } - i++; - } - - *b = 0; - return static_cast(b - target); - } - void sys_create_console_stub(HINSTANCE hInstance) { // C6262 @@ -177,7 +141,7 @@ namespace console SetFocus(*game::s_wcd::hwndInputLine); game::Con_GetTextCopy(text, 0x4000); - conbuf_clean_text(text, cleanConsoleBuffer); // Conbuf_CleanText is inlined + game::Conbuf_CleanText(text, cleanConsoleBuffer); SetWindowTextA(*game::s_wcd::hwndBuffer, cleanConsoleBuffer); } } diff --git a/src/client/game/game.cpp b/src/client/game/game.cpp index 15d9662e..2660865c 100644 --- a/src/client/game/game.cpp +++ b/src/client/game/game.cpp @@ -2,3 +2,42 @@ #include "loader/component_loader.hpp" #include "game.hpp" + +namespace game +{ + // inlined in cod, functionality stolen from https://github.com/id-Software/Quake-III-Arena/blob/master/code/win32/win_syscon.c#L520 + int Conbuf_CleanText(const char* source, char* target) + { + char* b = target; + int i = 0; + while (source[i] && ((b - target) < sizeof(target) - 1)) + { + if (source[i] == '\n' && source[i + 1] == '\r') + { + b[0] = '\r'; + b[1] = '\n'; + b += 2; + i++; + } + else if (source[i] == '\r' || source[i] == '\n') + { + b[0] = '\r'; + b[1] = '\n'; + b += 2; + } + else if (source && source[0] == '^' && source[1] && source[1] != '^' && source[1] >= 48 && source[1] <= 64) // Q_IsColorString + { + i++; + } + else + { + *b = source[i]; // C6011 here, should we be worried? + b++; + } + i++; + } + + *b = 0; + return static_cast(b - target); + } +} diff --git a/src/client/game/game.hpp b/src/client/game/game.hpp index 8ee1a258..00d8ac48 100644 --- a/src/client/game/game.hpp +++ b/src/client/game/game.hpp @@ -4,6 +4,8 @@ namespace game { + int Conbuf_CleanText(const char* source, char* target); + template class symbol {