Skip to content

Commit

Permalink
Merge pull request #10 from Silver-Ore-Team/feature/dialog-distance
Browse files Browse the repository at this point in the history
Increase the default display dialogue distance if needed - zCDialogDistanceController
  • Loading branch information
muczc1wek authored Oct 6, 2024
2 parents a0ac288 + 02603ce commit 047fd3e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions src/Gothic/zMul_Distance.hpp
Original file line number Diff line number Diff line change
@@ -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<void*>(m_Address), reinterpret_cast<void*>(m_Address + 0x4));
void* addr = rawMem->Get<void*>(0);
m_BackupDistance = sqrt(*static_cast<float*>(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<void*>(m_Address), reinterpret_cast<void*>(m_Address + 0x4));
rawMem->Get<int>(0) = reinterpret_cast<int>(&newDiagDist);
rawMem->Push();
log->Info("Distance set to {0}.", distance);
}
}
8 changes: 8 additions & 0 deletions src/Gothic/zMultilogue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace GOTHIC_NAMESPACE
{
private:
zCMultilogueCameraAdapter m_CameraAdapter;
zCDialogDistanceController m_DistanceController;
oCNpc* m_LastSelf = nullptr;
std::unordered_map<int, oCNpc*> m_Npcs;
bool m_Running = false;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<zCVob*>(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);
}
Expand Down
1 change: 1 addition & 0 deletions src/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma warning(disable: 4005)

#include <Union/Hook.h>
#include <Union/RawMemory.h>
#include <ZenGin/zGothicAPI.h>

#include "NH/Logger.h"
Expand Down
1 change: 1 addition & 0 deletions src/Plugin.hpp
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 047fd3e

Please sign in to comment.