Skip to content

Commit 173cbab

Browse files
committed
Cleanup
1 parent b95ae05 commit 173cbab

File tree

5 files changed

+7342
-33
lines changed

5 files changed

+7342
-33
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CEventSoundQuietSA.h
6+
* PURPOSE: Header file for damage event class
7+
*
8+
* Multi Theft Auto is available from https://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
#include <cstdint>
14+
#include "CVector.h"
15+
16+
class CEntitySAInterface;
17+
18+
class CEventSoundQuietSAInterface
19+
{
20+
public:
21+
std::uint8_t parent[0x14]; // CEventEditableResponse (inherited class)
22+
CEntitySAInterface* entity{nullptr};
23+
float localSoundLevel{};
24+
std::uint32_t startTimeInMs{};
25+
CVector position{};
26+
27+
CEventSoundQuietSAInterface(CEntitySAInterface* ped, float volume, std::uint32_t startTimeInMs = 0, CVector& pos = CVector())
28+
{
29+
((void*(__thiscall*)(CEventSoundQuietSAInterface*, CEntitySAInterface*, float, int, CVector*))0x5E05B0)(this, ped, volume, startTimeInMs, &pos);
30+
}
31+
32+
~CEventSoundQuietSAInterface()
33+
{
34+
((void(__thiscall*)(void*))0x5DEA00)(this);
35+
}
36+
};

Client/game_sa/CPedSA.cpp

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
#include "enums/AdhesionGroup.h"
2929

30+
#include "CEventSoundQuietSA.h"
31+
3032
extern CGameSA* pGame;
3133

3234
static bool g_onlyUpdateRotations = false;
@@ -587,7 +589,9 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
587589
if (!ped->pedFlags.bIsStanding)
588590
return;
589591

590-
auto computeVolumeAndFreq = [](CPedSAInterface* ped, float& volumeOffset, float& relativeFreq)
592+
bool doWooble = false;
593+
594+
auto ComputeVolumeAndFreq = [](CPedSAInterface* ped, float& volumeOffset, float& relativeFreq, bool forAnim = false)
591595
{
592596
volumeOffset = 0.0f;
593597
relativeFreq = 1.0f;
@@ -609,10 +613,12 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
609613
relativeFreq = 1.2f;
610614
break;
611615
default:
612-
volumeOffset = -12.0f;
613-
relativeFreq = 0.9f;
616+
// A custom option so that footstep sounds for animations aren’t quieter than normal steps
617+
volumeOffset = forAnim ? -6.0f : -12.0f;
618+
relativeFreq = forAnim ? 1.0f : 0.9f;
614619
break;
615620
}
621+
616622
if (ped->iMoveAnimGroup == 69) // ANIM_PLAYER_SNEAK_PED
617623
{
618624
volumeOffset -= 6.0f;
@@ -621,10 +627,15 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
621627
}
622628
};
623629

624-
auto addFootstepSound = [](CPedSAInterface* ped, bool isLeftFoot, float volumeOffset, float relativeFreq, bool doWooble)
630+
auto DoFootstep = [doWooble, &ComputeVolumeAndFreq](CPedSAInterface* ped, bool isLeftFoot, bool forAnim = false)
625631
{
626632
if (ped->pedAudio.canAddEvent) // CPedAudio::AddEvent
627-
((void(__thiscall*)(CPedSoundEntitySAInterface*, int, float, float, CEntitySAInterface*, int, int, int))0x4E2BB0)(&ped->pedAudio, isLeftFoot ? 54 : 55, volumeOffset, relativeFreq, nullptr, 0, 0, 0);
633+
{
634+
float volumeOffset, relativeFreq;
635+
ComputeVolumeAndFreq(ped, volumeOffset, relativeFreq, forAnim);
636+
637+
ped->pedAudio.AddAudioEvent(isLeftFoot ? AudioEvents::AE_PED_FOOTSTEP_LEFT : AudioEvents::AE_PED_FOOTSTEP_RIGHT, volumeOffset, relativeFreq, nullptr, 0, 0, 0);
638+
}
628639

629640
// CPed::DoFootLanded
630641
((void(__thiscall*)(CPedSAInterface*, int, bool))0x5E5380)(ped, isLeftFoot ? 1 : 0, doWooble);
@@ -637,7 +648,7 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
637648
CAnimBlendAssociationSAInterface* walkAnim = nullptr;
638649
float partialBlend = 0.0f, walkcycleBlend = 0.0f;
639650

640-
auto updateAnimBlend = [&](CAnimBlendAssociationSAInterface* assoc)
651+
auto UpdateAnimBlend = [&](CAnimBlendAssociationSAInterface* assoc)
641652
{
642653
if (assoc->m_walkAnim)
643654
{
@@ -651,7 +662,7 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
651662
};
652663

653664
for (auto& assoc = anim; assoc != nullptr; assoc = pGame->GetAnimManager()->RpAnimBlendGetNextAssociation(assoc))
654-
updateAnimBlend(assoc->GetInterface());
665+
UpdateAnimBlend(assoc->GetInterface());
655666

656667
if (!walkAnim || walkcycleBlend <= 0.5f || partialBlend >= 1.0f)
657668
return;
@@ -660,7 +671,7 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
660671
static constexpr float DUCK_FOOTSTEP_MOVE_TIME = 6.0f / 30.0f;
661672

662673
eAnimID animID = static_cast<eAnimID>(walkAnim->sAnimID);
663-
bool doWooble = (animID == eAnimID::ANIM_ID_WALK || animID == eAnimID::ANIM_ID_RUN || animID == eAnimID::ANIM_ID_SPRINT);
674+
doWooble = (animID == eAnimID::ANIM_ID_WALK || animID == eAnimID::ANIM_ID_RUN || animID == eAnimID::ANIM_ID_SPRINT);
664675

665676
float leftFootLanded = walkAnim->pAnimHierarchy->fTotalTime * INITIAL_FOOT_LANDED_RATIO;
666677
float rightFootLanded = walkAnim->pAnimHierarchy->fTotalTime / 2.0f + leftFootLanded;
@@ -670,7 +681,7 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
670681
rightFootLanded += DUCK_FOOTSTEP_MOVE_TIME;
671682
}
672683

673-
auto handleFoot = [&](bool isLeftFoot)
684+
auto HandleFoot = [&](bool isLeftFoot)
674685
{
675686
float footTime = isLeftFoot ? leftFootLanded : rightFootLanded;
676687

@@ -705,10 +716,8 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
705716

706717
float downTime = isLeftFoot ? leftDown : rightDown;
707718
if (volume > 0.2f && walkAnim->fCurrentTime > downTime && walkAnim->fCurrentTime - walkAnim->fTimeStep <= downTime)
708-
{
709-
if (ped->pedAudio.canAddEvent) // CPedAudio::AddEvent
710-
((void(__thiscall*)(CPedSoundEntitySAInterface*, int, float, float, CEntitySAInterface*, int, int, int))0x4E2BB0)(&ped->pedAudio, isLeftFoot ? 57 : 56, std::log10(volume) * 20.0f, animID == eAnimID::ANIM_ID_WALK ? 0.75f : 1.0f, nullptr, 0, 0, 0);
711-
}
719+
ped->pedAudio.AddAudioEvent(isLeftFoot ? AudioEvents::AE_PED_SKATE_LEFT : AudioEvents::AE_PED_SKATE_RIGHT, std::log10(volume) * 20.0f, animID == eAnimID::ANIM_ID_WALK ? 0.75f : 1.0f, nullptr, 0, 0, 0);
720+
712721
return;
713722
}
714723

@@ -747,37 +756,22 @@ void __fastcall CPedSA::PlayFootSteps(CPedSAInterface* ped)
747756

748757
if (volume > 0.0f)
749758
{
750-
CVector pos{};
751-
752-
// CMemoryMgr::Malloc
753-
// 0x2C = size of CEventSoundQuiet
754-
void* eventFootstepNoise = ((void*(__cdecl*)(int))0x72F420)(0x2C);
755-
756-
// CEventSoundQuiet::CEventSoundQuiet
757-
((void*(__thiscall*)(void*, CEntitySAInterface*, float, int, CVector*))0x5E05B0)(eventFootstepNoise, ped, volume, -1, &pos);
759+
CEventSoundQuietSAInterface eventFootstepNoise(ped, volume);
758760

759761
// GetEventGlobalGroup
760762
void* eventGlobalGroup = ((void*(__cdecl*)())0x4ABA50)();
761763

762764
// CEventGroup::Add
763-
((void(__thiscall*)(void*, void*, int))0x4AB420)(eventGlobalGroup, eventFootstepNoise, 0);
764-
765-
// CEventSoundQuiet::~CEventSoundQuiet
766-
((void(__thiscall*)(void*))0x5DEA00)(eventFootstepNoise);
767-
768-
// CMemoryMgr::Free
769-
((void(__cdecl*)(void*))0x72F430)(eventFootstepNoise);
765+
((void(__thiscall*)(void*, void*, int))0x4AB420)(eventGlobalGroup, &eventFootstepNoise, 0);
770766
}
771767
}
772768

773-
float volumeOffset, relativeFreq;
774-
computeVolumeAndFreq(ped, volumeOffset, relativeFreq);
775-
addFootstepSound(ped, isLeftFoot, volumeOffset, relativeFreq, doWooble);
769+
DoFootstep(ped, isLeftFoot);
776770
}
777771
};
778772

779-
handleFoot(true);
780-
handleFoot(false);
773+
HandleFoot(true);
774+
HandleFoot(false);
781775

782776
// CTaskManager::GetSimplestActiveTask
783777
auto* task = ((CTaskSAInterface * (__thiscall*)(void*))0x6819D0)(&ped->pPedIntelligence->taskManager);

Client/game_sa/CPedSoundSA.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class CPedSoundEntitySAInterface : public CAEAudioEntity
107107

108108
std::uint8_t field_154[4];
109109
std::uint8_t field_158[4];
110+
111+
void AddAudioEvent(AudioEvents::Enum audioEventID, float volume, float freq, CEntitySAInterface* targetEntity, std::uint32_t surfaceId, int somethingWithFightTask, int maxVolumeDuringFightTask)
112+
{
113+
if (canAddEvent)
114+
((void(__thiscall*)(CPedSoundEntitySAInterface*, int, float, float, CEntitySAInterface*, int, int, int))0x4E2BB0)(this, audioEventID, volume, freq, targetEntity, surfaceId, somethingWithFightTask, maxVolumeDuringFightTask);
115+
}
110116
};
111117
static_assert(sizeof(CPedSoundEntitySAInterface) == 0x15C, "Invalid size for CPedSoundEntitySAInterface");
112118

Client/sdk/game/CAudioEngine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <CVector.h>
1515
#include "Common.h"
1616
#include "CWeaponInfo.h"
17+
#include "enums/AudioEvents.h"
1718

1819
class CEntity;
1920
class CEntitySAInterface;

0 commit comments

Comments
 (0)