From 02603ced1605c03e4d1c637c29139779b6e951fd Mon Sep 17 00:00:00 2001 From: muczc1wek <110698397+muczc1wek@users.noreply.github.com> Date: Sun, 6 Oct 2024 18:14:31 +0200 Subject: [PATCH] Increase the default display dialogue distance if needed - zCDialogDistanceController --- README.md | 2 +- src/Gothic/zMul_Distance.hpp | 36 ++++++++++++++++++++++++++++++++++++ src/Gothic/zMultilogue.hpp | 8 ++++++++ src/Plugin.cpp | 1 + src/Plugin.hpp | 1 + 5 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/Gothic/zMul_Distance.hpp diff --git a/README.md b/README.md index 6e5d1af..611884a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ based on the solution form [AFSP Trialogue package](https://github.com/Bad-Scien ## ToDo - [x] Implement the basic functionality of the multilogue system -- [ ] Increase the default display dialogue distance if needed +- [x] Increase the default display dialogue distance if needed - [ ] Custom camera system - [x] Gothic 1 compatibility diff --git a/src/Gothic/zMul_Distance.hpp b/src/Gothic/zMul_Distance.hpp new file mode 100644 index 0000000..22c9280 --- /dev/null +++ b/src/Gothic/zMul_Distance.hpp @@ -0,0 +1,36 @@ +namespace GOTHIC_NAMESPACE { + static float newDiagDist; + + class zCDialogDistanceController + { + private: + float m_BackupDistance = 0; + int m_Address = zSwitch(0x6B2A07, 0x758740) + 2; + public: + void SetDistance(float distance); + float GetDefaultDistance(); + float GetDistance(); + void RestoreDistance() { SetDistance(m_BackupDistance); } + }; + + inline float zCDialogDistanceController::GetDefaultDistance() + { + if (!m_BackupDistance) { + auto rawMem = ::Union::RawMemory::GetAccess(reinterpret_cast(m_Address), reinterpret_cast(m_Address + 0x4)); + void* addr = rawMem->Get(0); + m_BackupDistance = sqrt(*static_cast(addr)); + } + return m_BackupDistance; + } + + inline void zCDialogDistanceController::SetDistance(float distance) + { + static NH::Logger* log = NH::CreateLogger("zCDialogDistanceController::SetDistance"); + GetDefaultDistance(); + newDiagDist = distance * distance; + auto rawMem = ::Union::RawMemory::GetAccess(reinterpret_cast(m_Address), reinterpret_cast(m_Address + 0x4)); + rawMem->Get(0) = reinterpret_cast(&newDiagDist); + rawMem->Push(); + log->Info("Distance set to {0}.", distance); + } +} \ No newline at end of file diff --git a/src/Gothic/zMultilogue.hpp b/src/Gothic/zMultilogue.hpp index 4715f69..128a533 100644 --- a/src/Gothic/zMultilogue.hpp +++ b/src/Gothic/zMultilogue.hpp @@ -6,6 +6,7 @@ namespace GOTHIC_NAMESPACE { private: zCMultilogueCameraAdapter m_CameraAdapter; + zCDialogDistanceController m_DistanceController; oCNpc* m_LastSelf = nullptr; std::unordered_map m_Npcs; bool m_Running = false; @@ -120,6 +121,7 @@ namespace GOTHIC_NAMESPACE m_Running = false; m_LastSelf = nullptr; m_CameraAdapter.SetTarget(nullptr); + m_DistanceController.RestoreDistance(); log->Info("Finishing multilogue with {0} NPCs.", m_Npcs.size()); m_Npcs.clear(); } @@ -196,6 +198,12 @@ namespace GOTHIC_NAMESPACE static NH::Logger* log = NH::CreateLogger("zCMultilogue::EV_Next"); log->Info("Next NPC: {0}", id); item->second->talkOther = nullptr; + + float npcDistance = player->GetDistanceToVobApprox(*static_cast(GetSelfInstance())); + log->Debug("Distance to player: {0}", npcDistance); + if (npcDistance > m_DistanceController.GetDefaultDistance()) { + m_DistanceController.SetDistance(npcDistance); + } // Currently does nothing m_CameraAdapter.SetTarget(item->second); } diff --git a/src/Plugin.cpp b/src/Plugin.cpp index 0b2930c..884c67d 100644 --- a/src/Plugin.cpp +++ b/src/Plugin.cpp @@ -2,6 +2,7 @@ #pragma warning(disable: 4005) #include +#include #include #include "NH/Logger.h" diff --git a/src/Plugin.hpp b/src/Plugin.hpp index b77caaa..2dee844 100644 --- a/src/Plugin.hpp +++ b/src/Plugin.hpp @@ -1,5 +1,6 @@ #include "Gothic/zMul_Helper.hpp" #include "Gothic/zMul_Camera.hpp" +#include "Gothic/zMul_Distance.hpp" #include "Gothic/zMultilogue.hpp" #include "Gothic/Externals.hpp" #include "Gothic/Hooks.hpp" \ No newline at end of file