[Logger] Filter out coloured strings for stdout

This commit is contained in:
Diavolo 2022-07-04 21:09:26 +02:00
parent abe2380040
commit a3d92939ad
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
4 changed files with 17 additions and 8 deletions

View File

@ -4,7 +4,7 @@ namespace Components
{
Ceg::Ceg()
{
Utils::Hook::Signature signature(0x401000, 0x740000);
Utils::Hook::Signature signature(0x401000, 0x340000);
// Generic killer caller.
signature.add({

View File

@ -26,25 +26,33 @@ namespace Components
void Logger::MessagePrint(const int channel, const std::string& msg)
{
std::string out = msg;
// Filter out coloured strings
if (out[0] == '^' && out[1] != '\0')
{
out = out.substr(2);
}
if (Flags::HasFlag("stdout") || Loader::IsPerformingUnitTests())
{
printf("%s", msg.data());
printf("%s", out.data());
fflush(stdout);
return;
}
if (!Logger::IsConsoleReady())
{
OutputDebugStringA(msg.data());
OutputDebugStringA(out.data());
}
if (!Game::Sys_IsMainThread())
{
Logger::EnqueueMessage(msg);
Logger::EnqueueMessage(out);
}
else
{
Game::Com_PrintMessage(channel, msg.data(), 0);
Game::Com_PrintMessage(channel, out.data(), 0);
}
}
@ -54,7 +62,8 @@ namespace Components
const auto msg = std::vformat(fmt, args);
const auto out = std::format("Debug:\n {}\nFile: {}\nLine: {}\n", msg, loc.file_name(), loc.line());
#else
const auto out = std::vformat(fmt, args) + "\n";
const auto msg = std::vformat(fmt, args);
const auto out = std::format("^2{}\n", msg);
#endif
Logger::MessagePrint(Game::CON_CHANNEL_DONT_FILTER, out);

View File

@ -16,7 +16,6 @@ namespace Components
static void Flush();
static void MessagePrint(int channel, const std::string& msg);
static void PrintInternal(int channel, std::string_view fmt, std::format_args&& args);
static void ErrorInternal(Game::errorParm_t error, std::string_view fmt, std::format_args&& args);
static void PrintErrorInternal(int channel, std::string_view fmt, std::format_args&& args);
@ -99,6 +98,7 @@ namespace Components
static std::vector<Network::Address> LoggingAddresses[2];
static void(*PipeCallback)(const std::string&);
static void MessagePrint(int channel, const std::string& msg);
static void Frame();
static void G_LogPrintfStub(const char* fmt, ...);
static void PrintMessageStub();

View File

@ -9,7 +9,7 @@ namespace Utils
{
if (this->signatures.empty()) return;
char* _start = reinterpret_cast<char*>(this->start);
char* _start = static_cast<char*>(this->start);
unsigned int sigCount = this->signatures.size();
Hook::Signature::Container* containers = this->signatures.data();