Skip to content

Commit

Permalink
Refactor ReinitAudio
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNormalnij committed Feb 4, 2025
1 parent 8351776 commit 7fb152c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
10 changes: 8 additions & 2 deletions Client/game_sa/CAEVehicleAudioEntitySA.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#define FUNC_CAEVehicleAudioEntity__ProcessAIProp 0x4FDFD0
#define FUNC_CAEVehicleAudioEntity__ProcessAIHeli 0x4FEE20

class CVehicleSAInterface;

struct tVehicleSound
{
int m_dwIndex;
Expand Down Expand Up @@ -51,9 +53,13 @@ static_assert(sizeof(CAETwinLoopSoundEntity) == 0xA8, "Invalid size for CAETwinL
class CAEVehicleAudioEntitySAInterface : public CAEAudioEntity
{
public:
void AddAudioEvent(int eventId, float volume)
void AddAudioEvent(int eventId, float volume) { ((void(__thiscall*)(CAEVehicleAudioEntitySAInterface*, int, float))0x4F6420)(this, eventId, volume); }
bool TerminateAudio() { return ((bool(__thiscall*)(CAEVehicleAudioEntitySAInterface*))0x4FB8C0)(this); }
bool SoundJoin() { return ((bool(__thiscall*)(CAEVehicleAudioEntitySAInterface*))0x4F5700)(this); }

int16_t InitAudio(CVehicleSAInterface* vehicle)
{
((void(__thiscall*)(CAEVehicleAudioEntitySAInterface*, int, float))0x4F6420)(this, eventId, volume);
return ((int16_t(__thiscall*)(CAEVehicleAudioEntitySAInterface*, CVehicleSAInterface*))0x4F7670)(this, vehicle);
}

short unk1; // +124
Expand Down
12 changes: 4 additions & 8 deletions Client/game_sa/CVehicleSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2481,17 +2481,13 @@ bool CVehicleSA::SetWindowOpenFlagState(unsigned char ucWindow, bool bState)

void CVehicleSA::ReinitAudio()
{
typedef bool(__thiscall * Function_TerminateAudio)(CAEVehicleAudioEntitySAInterface * pAudio);
((Function_TerminateAudio)(0x4FB8C0))(m_pVehicleAudioEntity->GetInterface());
auto* audioInterface = m_pVehicleAudioEntity->GetInterface();

typedef int16(__thiscall * Function_InitAudio)(CAEVehicleAudioEntitySAInterface * pAudio, CVehicleSAInterface * pVehicleInterface);
((Function_InitAudio)(0x4F7670))(m_pVehicleAudioEntity->GetInterface(), GetVehicleInterface());
audioInterface->TerminateAudio();
audioInterface->InitAudio(GetVehicleInterface());

CPed* pLocalPlayer = pGame->GetPedContext();

if (IsPassenger(pLocalPlayer) || GetDriver() == pLocalPlayer)
{
typedef bool(__thiscall * Function_SoundJoin)(CAEVehicleAudioEntitySAInterface * pAudio);
((Function_SoundJoin)(0x4F5700))(m_pVehicleAudioEntity->GetInterface());
}
audioInterface->SoundJoin();
}

0 comments on commit 7fb152c

Please sign in to comment.