Skip to content

Commit

Permalink
feat: forcefully trigger voice lines
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbeBryssinck committed May 5, 2022
1 parent 9ce4355 commit 671cf08
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
15 changes: 15 additions & 0 deletions Code/client/Events/ActorSpokeEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

/**
* @brief Dispatched whenever an actor talks
*/
struct ActorSpokeEvent
{
ActorSpokeEvent(uint32_t aActorID, String aVoiceFile)
: ActorID(aActorID), VoiceFile(aVoiceFile)
{}

uint32_t ActorID;
String VoiceFile;
};

23 changes: 22 additions & 1 deletion Code/client/Games/References.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include <Events/LockChangeEvent.h>
#include <Events/InitPackageEvent.h>
#include <Events/ActorSpokeEvent.h>

#include <TiltedCore/Serialization.hpp>

Expand Down Expand Up @@ -63,7 +64,7 @@ float CalculateRealDamage(Actor* apHittee, float aDamage) noexcept

float realDamage = aDamage;

if (fabs(aDamage) <= 0.000099999997 || DifficultyMultiplier < 1.0)
if (fabs(aDamage) <= 0.000099999997 || multiplier < 1.0)
realDamage = aDamage * multiplier;

return realDamage;
Expand Down Expand Up @@ -705,6 +706,22 @@ void TP_MAKE_THISCALL(HookInitFromPackage, void, TESPackage* apPackage, TESObjec
return ThisCall(RealInitFromPackage, apThis, apPackage, apTarget, arActor);
}

TP_THIS_FUNCTION(TSpeakSoundFunction, bool, Actor, char* apName, uint32_t* a3, uint32_t a4, uint32_t a5, uint32_t a6, uint64_t a7, uint64_t a8, uint64_t a9, bool a10, uint64_t a11, bool a12, bool a13, bool a14);
static TSpeakSoundFunction* RealSpeakSoundFunction = nullptr;

bool TP_MAKE_THISCALL(HookSpeakSoundFunction, Actor, char* apName, uint32_t* a3, uint32_t a4, uint32_t a5, uint32_t a6, uint64_t a7, uint64_t a8, uint64_t a9, bool a10, uint64_t a11, bool a12, bool a13, bool a14)
{
World::Get().GetRunner().Trigger(ActorSpokeEvent(apThis->formID, apName));
return ThisCall(RealSpeakSoundFunction, apThis, apName, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
}

void Actor::SpeakSound(char* pFile)
{
uint32_t handle[3]{};
handle[0] = -1;
ThisCall(RealSpeakSoundFunction, this, pFile, handle, 0, 0x32, 0, 0, 0, 0, 0, 0, 0, 1, 1);
}

TiltedPhoques::Initializer s_referencesHooks([]()
{
POINTER_SKYRIMSE(TSetPosition, s_setPosition, 19790);
Expand All @@ -731,6 +748,8 @@ TiltedPhoques::Initializer s_referencesHooks([]()
POINTER_SKYRIMSE(TInitFromPackage, s_initFromPackage, 38959);
POINTER_FALLOUT4(TInitFromPackage, s_initFromPackage, 0x140E219A0 - 0x140000000);

POINTER_SKYRIMSE(TSpeakSoundFunction, s_speakSoundFunction, 37542);

RealSetPosition = s_setPosition.Get();
RealRotateX = s_rotateX.Get();
RealRotateY = s_rotateY.Get();
Expand All @@ -739,6 +758,7 @@ TiltedPhoques::Initializer s_referencesHooks([]()
RealLockChange = s_lockChange.Get();
RealCheckForNewPackage = s_checkForNewPackage.Get();
RealInitFromPackage = s_initFromPackage.Get();
RealSpeakSoundFunction = s_speakSoundFunction.Get();

TP_HOOK(&RealSetPosition, HookSetPosition);
TP_HOOK(&RealRotateX, HookRotateX);
Expand All @@ -748,5 +768,6 @@ TiltedPhoques::Initializer s_referencesHooks([]()
TP_HOOK(&RealLockChange, HookLockChange);
TP_HOOK(&RealCheckForNewPackage, HookCheckForNewPackage);
TP_HOOK(&RealInitFromPackage, HookInitFromPackage);
TP_HOOK(&RealSpeakSoundFunction, HookSpeakSoundFunction);
});

1 change: 1 addition & 0 deletions Code/client/Games/Skyrim/Actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ struct Actor : TESObjectREFR
void Respawn() noexcept;
void PickUpObject(TESObjectREFR* apObject, int32_t aCount, bool aUnk1, float aUnk2) noexcept;
void DropObject(TESBoundObject* apObject, ExtraDataList* apExtraData, int32_t aCount, NiPoint3* apLocation, NiPoint3* apRotation) noexcept;
void SpeakSound(char* pFile);

enum ActorFlags
{
Expand Down
13 changes: 13 additions & 0 deletions Code/client/Services/Debug/DebugService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <Services/QuestService.h>

#include <Events/UpdateEvent.h>
#include <Events/ActorSpokeEvent.h>

#include <Games/References.h>

Expand Down Expand Up @@ -86,6 +87,7 @@ DebugService::DebugService(entt::dispatcher& aDispatcher, World& aWorld, Transpo
{
m_updateConnection = m_dispatcher.sink<UpdateEvent>().connect<&DebugService::OnUpdate>(this);
m_drawImGuiConnection = aImguiService.OnDraw.connect<&DebugService::OnDraw>(this);
m_actorSpokeConnection = m_dispatcher.sink<ActorSpokeEvent>().connect<&DebugService::OnActorSpokeEvent>(this);
}

void DebugService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept
Expand Down Expand Up @@ -136,12 +138,23 @@ void DebugService::OnUpdate(const UpdateEvent& acUpdateEvent) noexcept
if (!s_f8Pressed)
{
s_f8Pressed = true;

Actor* pActor = Cast<Actor>(TESForm::GetById(m_spokenActorId));
pActor->SpeakSound(m_voiceFileName.data());
}
}
else
s_f8Pressed = false;
}

void DebugService::OnActorSpokeEvent(const ActorSpokeEvent& acEvent) noexcept
{
m_spokenActorId = acEvent.ActorID;
m_voiceFileName = acEvent.VoiceFile;

spdlog::warn("Actor spoke, id: {:X}, file: {}", acEvent.ActorID, acEvent.VoiceFile.c_str());
}

uint64_t DebugService::DisplayGraphDescriptorKey(BSAnimationGraphManager* pManager) noexcept
{
auto hash = pManager->GetDescriptorKey();
Expand Down
8 changes: 8 additions & 0 deletions Code/client/Services/DebugService.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

struct World;
struct ImguiService;

struct UpdateEvent;
struct ActorSpokeEvent;

struct TransportService;
struct BSAnimationGraphManager;
Expand All @@ -20,6 +22,7 @@ struct DebugService
TP_NOCOPYMOVE(DebugService);

void OnUpdate(const UpdateEvent&) noexcept;
void OnActorSpokeEvent(const ActorSpokeEvent&) noexcept;

protected:

Expand Down Expand Up @@ -57,8 +60,13 @@ struct DebugService

uint32_t m_formId = 0;

uint32_t m_spokenActorId = 0;
String m_voiceFileName = "";

entt::scoped_connection m_updateConnection;
entt::scoped_connection m_drawImGuiConnection;
entt::scoped_connection m_actorSpokeConnection;

bool m_showDebugStuff = false;
bool m_showBuildTag = true;
bool m_toggleComponentWindow = false;
Expand Down

0 comments on commit 671cf08

Please sign in to comment.