From 86e1f6f807ff0b0be6564f98a23b4aa935057740 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Sat, 25 Feb 2017 01:17:11 +0100 Subject: [PATCH] [Logger] Add iw4x_onelog dvar --- src/Components/Modules/Logger.cpp | 42 +++++++++++++++++++++++++++++++ src/Components/Modules/Logger.hpp | 3 +++ 2 files changed, 45 insertions(+) diff --git a/src/Components/Modules/Logger.cpp b/src/Components/Modules/Logger.cpp index f632a6c3..c9dcd920 100644 --- a/src/Components/Modules/Logger.cpp +++ b/src/Components/Modules/Logger.cpp @@ -195,8 +195,50 @@ namespace Components Logger::MessageMutex.unlock(); } + void Logger::RedirectOSPath(const char* file, char* folder) + { + if (Dvar::Var("g_log").get() == file) + { + if (folder != "userraw"s) + { + if (Dvar::Var("g_log").get()) + { + strcpy_s(folder, 256, "userraw"); + } + } + } + } + + __declspec(naked) void Logger::BuildOSPathStub() + { + __asm + { + pushad + + push [esp + 28h] + push [esp + 30h] + + call Logger::RedirectOSPath + + add esp, 8h + + popad + + mov eax, [esp + 8h] + push ebp + push esi + mov esi, [esp + 0Ch] + + push 64213Fh + retn + } + } + Logger::Logger() { + Dvar::Register("iw4x_onelog", false, Game::dvar_flag::DVAR_FLAG_LATCHED | Game::dvar_flag::DVAR_FLAG_SAVED, "Only write the game log to the 'userraw' OS folder"); + Utils::Hook(0x642139, Logger::BuildOSPathStub, HOOK_JUMP).install()->quick(); + Logger::PipeOutput(nullptr); QuickPatch::OnFrame(Logger::Frame); diff --git a/src/Components/Modules/Logger.hpp b/src/Components/Modules/Logger.hpp index eabab8fa..accafa62 100644 --- a/src/Components/Modules/Logger.hpp +++ b/src/Components/Modules/Logger.hpp @@ -39,6 +39,9 @@ namespace Components static void PrintMessagePipe(const char* data); static void EnqueueMessage(std::string message); + static void BuildOSPathStub(); + static void RedirectOSPath(const char* file, char* folder); + static void NetworkLog(const char* data, bool gLog); static std::string Format(const char** message);