From 5477d411cdcf459740f895b4ce8ec87c0e94bc52 Mon Sep 17 00:00:00 2001 From: muczc1wek <110698397+muczc1wek@users.noreply.github.com> Date: Sat, 12 Oct 2024 12:02:35 +0200 Subject: [PATCH] Add .ini options to change logger level --- src/Gothic/Hooks.hpp | 11 ++++++++++ src/Gothic/Options.hpp | 43 ++++++++++++++++++++++++++++++++++++++ src/Gothic/zMul_Helper.hpp | 2 +- src/Plugin.hpp | 3 ++- 4 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 src/Gothic/Options.hpp diff --git a/src/Gothic/Hooks.hpp b/src/Gothic/Hooks.hpp index 4e6d30d..8512d98 100644 --- a/src/Gothic/Hooks.hpp +++ b/src/Gothic/Hooks.hpp @@ -10,6 +10,17 @@ namespace GOTHIC_NAMESPACE { } auto Partial_DefineExternals_Ulfi = Union::CreatePartialHook(oCGame_DefineExternals_Ulfi, &DefineExternals_Ulfi_PartialHook); + // G1: 0x00424AF0 public: void __thiscall CGameManager::Run(void) + // G1A: 0x004275D0 public: void __thiscall CGameManager::Run(void) + // G2: 0x004254F0 public: void __thiscall CGameManager::Run(void) + // G2A: 0x00425830 public: void __thiscall CGameManager::Run(void) + void* CGameManager_Run = reinterpret_cast(zSwitch(0x00424AF0, 0x004275D0, 0x004254F0, 0x00425830)); + void __fastcall CGameManager_Run_PartialHook() { + ApplyOptions(); + }; + auto Partial_CGameManager_Run = Union::CreatePartialHook(CGameManager_Run, CGameManager_Run_PartialHook); + + // G2A: 0x00758130 public: int __thiscall oCNpc::ActivateDialogCam(float) // auto Ivk_oCNpc_ActivateDialogCam = Union::CreateHook(reinterpret_cast(0x00758130), &oCNpc::ActivateDialogCam_Hook); diff --git a/src/Gothic/Options.hpp b/src/Gothic/Options.hpp new file mode 100644 index 0000000..8e26050 --- /dev/null +++ b/src/Gothic/Options.hpp @@ -0,0 +1,43 @@ +namespace GOTHIC_NAMESPACE +{ + void ApplyOptions() + { + if (GetGameVersion() != ENGINE) + { + return; + } + + Union::Array loggers = NH::LoggerFactory::GetInstance()->GetLoggers(); + { + static NH::Logger* log = NH::CreateLogger("zMultilogue::GothicOptions"); + zSTRING unionValue = zoptions->ReadString("ZMULTILOGUE", "LoggerLevelUnion", "INFO"); + zSTRING zSpyValue = zoptions->ReadString("ZMULTILOGUE", "LoggerLevelZSpy", "DEBUG"); + + for (auto it = loggers.begin(); it != loggers.end(); it++) + { + auto* unionAdapter = (*it)->GetAdapter(); + if (unionAdapter) + { + NH::LoggerLevel level = NH::StringToLoggerLevel(unionValue.ToChar()); + if (level != unionAdapter->DEFAULT_LEVEL) + { + NH::UnionConsoleLoggerAdapter::DEFAULT_LEVEL = level; + log->Info("Logger level for UnionConsoleLoggerAdapter: {0}", unionValue.ToChar()); + } + unionAdapter->SetLoggerLevel(level); + } + auto* zSpyAdapter = (*it)->GetAdapter(); + if (zSpyAdapter) + { + NH::LoggerLevel level = NH::StringToLoggerLevel(zSpyValue.ToChar()); + if (level != zSpyAdapter->DEFAULT_LEVEL) + { + NH::ZSpyLoggerAdapter::DEFAULT_LEVEL = level; + log->Info("Logger level for ZSpyLoggerAdapter: {0}", unionValue.ToChar()); + } + zSpyAdapter->SetLoggerLevel(level); + } + } + } + } +} \ No newline at end of file diff --git a/src/Gothic/zMul_Helper.hpp b/src/Gothic/zMul_Helper.hpp index 46d0164..293aab7 100644 --- a/src/Gothic/zMul_Helper.hpp +++ b/src/Gothic/zMul_Helper.hpp @@ -40,7 +40,7 @@ namespace GOTHIC_NAMESPACE //log->Debug("Self and other are the same."); return; } - log->Trace("Synching {0} with {1}", self->idx, other->idx); + // log->Trace("Synching {0} with {1}", self->idx, other->idx); oCMsgConversation* msg = zNEW(oCMsgConversation)(oCMsgConversation::EV_WAITTILLEND,other); int nr = other -> GetEM()->GetNumMessages(); zCEventMessage* watch = nullptr; diff --git a/src/Plugin.hpp b/src/Plugin.hpp index 2dee844..1db37cf 100644 --- a/src/Plugin.hpp +++ b/src/Plugin.hpp @@ -3,4 +3,5 @@ #include "Gothic/zMul_Distance.hpp" #include "Gothic/zMultilogue.hpp" #include "Gothic/Externals.hpp" -#include "Gothic/Hooks.hpp" \ No newline at end of file +#include "Gothic/Options.hpp" +#include "Gothic/Hooks.hpp"