Merge pull request #336 from diamante0018/logger-1

[Logger] Fix output by g_log_list & log_list
This commit is contained in:
Dss0 2022-06-27 13:18:59 +02:00 committed by GitHub
commit 57341b7eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 31 deletions

View File

@ -144,31 +144,41 @@ namespace Components
void Logger::NetworkLog(const char* data, bool gLog)
{
if (!data) return;
if (data == nullptr)
{
return;
}
const std::string buffer(data);
for (const auto& addr : Logger::LoggingAddresses[gLog & 1])
{
Network::SendCommand(addr, "print", buffer);
Network::SendCommand(addr, "print", data);
}
}
__declspec(naked) void Logger::GameLogStub()
void Logger::G_LogPrintfStub(const char* fmt, ...)
{
__asm
char string[1024];
char string2[1024];
va_list ap;
va_start(ap, fmt);
vsnprintf_s(string2, _TRUNCATE, fmt, ap);
va_end(ap);
const auto min = Game::level->time / 1000 / 60;
const auto tens = Game::level->time / 1000 % 60 / 10;
const auto sec = Game::level->time / 1000 % 60 % 10;
const auto len = _snprintf_s(string, _TRUNCATE, "%3i:%i%i %s",
min, tens, sec, string2);
if (Game::level->logFile != nullptr)
{
pushad
push 1
push [esp + 28h]
call Logger::NetworkLog
add esp, 8h
popad
push 4576C0h
retn
Game::FS_Write(string, len, reinterpret_cast<int>(Game::level->logFile));
}
// Allow the network log to run even if logFile was not opened
Logger::NetworkLog(string, true);
}
__declspec(naked) void Logger::PrintMessageStub()
@ -265,7 +275,7 @@ namespace Components
{
if (params->size() < 2) return;
int num = atoi(params->get(1));
const auto num = atoi(params->get(1));
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < Logger::LoggingAddresses[0].size())
{
auto addr = Logger::LoggingAddresses[0].begin() + num;
@ -296,7 +306,7 @@ namespace Components
for (unsigned int i = 0; i < Logger::LoggingAddresses[0].size(); ++i)
{
Logger::Print("{}: {}\n", i, Logger::LoggingAddresses[0][i].getCString());
Logger::Print("#{:03d}: {}\n", i, Logger::LoggingAddresses[0][i].getCString());
}
});
@ -316,7 +326,7 @@ namespace Components
{
if (params->size() < 2) return;
int num = atoi(params->get(1));
const auto num = std::atoi(params->get(1));
if (Utils::String::VA("%i", num) == std::string(params->get(1)) && static_cast<unsigned int>(num) < Logger::LoggingAddresses[1].size())
{
const auto addr = Logger::LoggingAddresses[1].begin() + num;
@ -347,7 +357,7 @@ namespace Components
for (std::size_t i = 0; i < Logger::LoggingAddresses[1].size(); ++i)
{
Logger::Print("{}: {}\n", i, Logger::LoggingAddresses[1][i].getCString());
Logger::Print("#{:03d}: {}\n", i, Logger::LoggingAddresses[1][i].getCString());
}
});
}
@ -361,7 +371,7 @@ namespace Components
Scheduler::Loop(Logger::Frame, Scheduler::Pipeline::SERVER);
Utils::Hook(0x4B0218, Logger::GameLogStub, HOOK_CALL).install()->quick();
Utils::Hook(Game::G_LogPrintf, Logger::G_LogPrintfStub, HOOK_JUMP).install()->quick();
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).install()->quick();
if (Loader::IsPerformingUnitTests())

View File

@ -100,7 +100,7 @@ namespace Components
static void(*PipeCallback)(const std::string&);
static void Frame();
static void GameLogStub();
static void G_LogPrintfStub(const char* fmt, ...);
static void PrintMessageStub();
static void PrintMessagePipe(const char* data);
static void EnqueueMessage(const std::string& message);

View File

@ -19,7 +19,7 @@ namespace Components
void Theatre::RecordGamestateStub()
{
int sequence = (*Game::serverMessageSequence - 1);
Game::FS_Write(&sequence, 4, *Game::demoFile);
Game::FS_WriteToDemo(&sequence, 4, *Game::demoFile);
}
void Theatre::StoreBaseline(PBYTE snapshotMsg)
@ -62,10 +62,10 @@ namespace Components
int byte8 = 8;
char byte0 = 0;
Game::FS_Write(&byte0, 1, *Game::demoFile);
Game::FS_Write(Game::serverMessageSequence, 4, *Game::demoFile);
Game::FS_Write(&fileCompressedSize, 4, *Game::demoFile);
Game::FS_Write(&byte8, 4, *Game::demoFile);
Game::FS_WriteToDemo(&byte0, 1, *Game::demoFile);
Game::FS_WriteToDemo(Game::serverMessageSequence, 4, *Game::demoFile);
Game::FS_WriteToDemo(&fileCompressedSize, 4, *Game::demoFile);
Game::FS_WriteToDemo(&byte8, 4, *Game::demoFile);
for (int i = 0; i < compressedSize; i += 1024)
{
@ -77,7 +77,7 @@ namespace Components
break;
}
Game::FS_Write(&cmpData[i], size, *Game::demoFile);
Game::FS_WriteToDemo(&cmpData[i], size, *Game::demoFile);
}
}

View File

@ -148,7 +148,8 @@ namespace Game
FS_FOpenFileReadForThread_t FS_FOpenFileReadForThread = FS_FOpenFileReadForThread_t(0x643270);
FS_FCloseFile_t FS_FCloseFile = FS_FCloseFile_t(0x462000);
FS_WriteFile_t FS_WriteFile = FS_WriteFile_t(0x426450);
FS_Write_t FS_Write = FS_Write_t(0x4C06E0);
FS_WriteToDemo_t FS_WriteToDemo = FS_WriteToDemo_t(0x4C06E0);
FS_Write_t FS_Write = FS_Write_t(0x4576C0);
FS_Printf_t FS_Printf = FS_Printf_t(0x459320);
FS_Read_t FS_Read = FS_Read_t(0x4A04C0);
FS_Seek_t FS_Seek = FS_Seek_t(0x4A63D0);

View File

@ -365,10 +365,13 @@ namespace Game
typedef bool(__cdecl * FS_FileExists_t)(const char* file);
extern FS_FileExists_t FS_FileExists;
typedef bool(__cdecl * FS_WriteFile_t)(char* filename, char* folder, void* buffer, int size);
typedef bool(__cdecl * FS_WriteFile_t)(const char* filename, const char* folder, const void* buffer, int size);
extern FS_WriteFile_t FS_WriteFile;
typedef int(__cdecl * FS_Write_t)(const void* buffer, size_t size, int file);
typedef int(__cdecl * FS_WriteToDemo_t)(const void* buffer, int size, int file);
extern FS_WriteToDemo_t FS_WriteToDemo;
typedef int(__cdecl * FS_Write_t)(const void* buffer, int len, int h);
extern FS_Write_t FS_Write;
typedef int(__cdecl * FS_Printf_t)(int file, const char* fmt, ...);