move clean text to game class

This commit is contained in:
mjkzy 2022-06-02 06:49:43 -05:00
parent 427b4ecff7
commit 313433b4e6
3 changed files with 42 additions and 37 deletions

View File

@ -62,42 +62,6 @@ namespace console
return utils::hook::invoke<LRESULT>(0x142333820_g, hWnd, uMsg, wParam, lParam); return utils::hook::invoke<LRESULT>(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<int>(b - target);
}
void sys_create_console_stub(HINSTANCE hInstance) void sys_create_console_stub(HINSTANCE hInstance)
{ {
// C6262 // C6262
@ -177,7 +141,7 @@ namespace console
SetFocus(*game::s_wcd::hwndInputLine); SetFocus(*game::s_wcd::hwndInputLine);
game::Con_GetTextCopy(text, 0x4000); 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); SetWindowTextA(*game::s_wcd::hwndBuffer, cleanConsoleBuffer);
} }
} }

View File

@ -2,3 +2,42 @@
#include "loader/component_loader.hpp" #include "loader/component_loader.hpp"
#include "game.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<int>(b - target);
}
}

View File

@ -4,6 +4,8 @@
namespace game namespace game
{ {
int Conbuf_CleanText(const char* source, char* target);
template <typename T> template <typename T>
class symbol class symbol
{ {