Try to implement g_log network transfer.

Logging to file is still working.
Logging over network does send something but nothing useful. (????????)
No Crashs.
This commit is contained in:
/dev/sdb 2016-09-02 22:28:51 +02:00
parent b94a311ec4
commit 70ea83b851
2 changed files with 88 additions and 34 deletions

View File

@ -11,10 +11,12 @@ namespace Components
static char* writeFolder;
//static DWORD fsBuildOSPathForThreadHookLoc = 0x642139;
DWORD fsBuildOSPathForThreadHookLocRet = 0x64213F;
Game::dvar_t* iw4m_onelog;
void(*Logger::PipeCallback)(std::string) = nullptr;
void(*Logger::GLogCallback)(std::string) = nullptr;
bool Logger::IsConsoleReady()
{
@ -136,15 +138,27 @@ namespace Components
Logger::PipeCallback = callback;
}
void Logger::GLogOutput(void(*callback)(std::string))
{
Logger::GLogCallback = callback;
}
void Logger::PrintMessagePipe(const char* data)
{
if (Logger::PipeCallback)
{
Logger::PipeCallback(data);
}
}
void Logger::GLogMessagePipe(const char* data)
{
if (Logger::GLogCallback)
{
Logger::GLogCallback(data);
}
}
__declspec(naked) void Logger::PrintMessageStub()
{
__asm
@ -167,6 +181,27 @@ namespace Components
}
}
__declspec(naked) void Logger::GLogPrintfHookStub() {
_asm
{
mov eax, Logger::GLogCallback
test eax, eax
jz returnPrint
call Logger::GLogMessagePipe
returnPrint :
mov eax, 4576C0h
jmp eax
}
}
void Logger::EnqueueMessage(std::string message)
{
Logger::MessageMutex.lock();
@ -186,16 +221,30 @@ namespace Components
//Logger::PrintMessagePipe(message.c_str());
}
void Logger::GPipeOutputStub(std::string message)
{
OutputDebugStringA("Worked");
if (Logger::gaddresses.size()) {
for (size_t i = 0; i < Logger::gaddresses.size(); i++) {
const char* toSend = Utils::String::VA("%s", message);
Network::Send(Logger::gaddresses[i], toSend);
}
}
//Logger::PrintMessagePipe(message.c_str());
}
Logger::Logger()
{
Logger::PipeOutput(&PipeOutputStub);
Logger::GLogOutput(&GPipeOutputStub);
//Logger::PipeOutput(nullptr);
//Logger::GLogOutput(nullptr);
QuickPatch::OnFrame(Logger::Frame);
Utils::Hook(Game::Com_PrintMessage, Logger::PrintMessageStub, HOOK_JUMP).Install()->Quick();
Utils::Hook(Logger::glogprintfHookLoc, Logger::GLogPrintfHookStub, HOOK_CALL).Install()->Quick();
//Logging over network stuff
Game::Cmd_AddCommand("log_add", Game::Cbuf_AddServerText, &sv_log_add, 0);
Game::Cmd_AddServerCommand("log_add", Logger::SV_Log_Add_f, &sv_log_add2);
@ -215,9 +264,9 @@ namespace Components
Game::Cmd_AddCommand("g_log_list", Game::Cbuf_AddServerText, &sv_glog_list, 0);
Game::Cmd_AddServerCommand("g_log_list", Logger::SV_GLog_List_f, &sv_glog_list2);
Utils::Hook(Logger::fsBuildOSPathForThreadHookLoc, FS_BuildOSPathForThreadHookFunc, HOOK_JUMP).Install()->Quick();
Logger::FS_BuildOSPathForThreadHookTest();
iw4m_onelog = (Game::dvar_t*)Game::Dvar_RegisterBool("iw4x_onelog", false, Game::DVAR_FLAG_LATCHED || Game::DVAR_FLAG_SAVED, "Only write the game log to the '" BASEGAME "' OS folder");
//Utils::Hook(Logger::fsBuildOSPathForThreadHookLoc, FS_BuildOSPathForThreadHookFunc, HOOK_JUMP).Install()->Quick();
//Logger::FS_BuildOSPathForThreadHookTest();
//iw4m_onelog = (Game::dvar_t*)Game::Dvar_RegisterBool("iw4x_onelog", false, Game::DVAR_FLAG_LATCHED || Game::DVAR_FLAG_SAVED, "Only write the game log to the '" BASEGAME "' OS folder");
}

View File

@ -20,8 +20,10 @@ namespace Components
static bool IsConsoleReady();
static void PipeOutput(void(*callback)(std::string));
static void GLogOutput(void(*callback)(std::string));
static bool validInt(char* str);
static const DWORD fsBuildOSPathForThreadHookLoc = 0x642139;
static const DWORD glogprintfHookLoc = 0x4B0218;
//static const DWORD fsBuildOSPathForThreadHookLocRet = 0x64213F;
Game::cmd_function_t sv_log_add;
Game::cmd_function_t sv_log_add2;
@ -41,23 +43,26 @@ namespace Components
Game::cmd_function_t sv_glog_list;
Game::cmd_function_t sv_glog_list2;
static void PipeOutputStub(std::string message);
static void GPipeOutputStub(std::string message);
private:
static std::mutex MessageMutex;
static std::vector<std::string> MessageQueue;
static std::vector<Game::netadr_t> addresses;
static std::vector<Game::netadr_t> gaddresses;
static void(*PipeCallback)(std::string);
static void(*GLogCallback)(std::string);
static void Frame();
static void PrintMessageStub();
static void GLogPrintfHookStub();
static void PrintMessagePipe(const char* data);
static void GLogMessagePipe(const char* data);
static void EnqueueMessage(std::string message);
static std::string Format(const char** message);
//Logging over network stuff
static void FS_BuildOSPathForThreadHookFunc();
static void FS_BuildOSPathForThreadHookFunc();
static void FS_BuildOSPathForThreadHookTest();
static void SV_GLog_Add_f();
static void SV_Log_Add_f();