Skip to content

Commit 4159728

Browse files
committed
Fix #9681 (Unable to hear proper engine sounds when sitting in car as passenger)
1 parent 33bb079 commit 4159728

File tree

7 files changed

+68
-48
lines changed

7 files changed

+68
-48
lines changed

Client/game_sa/CAEVehicleAudioEntitySA.cpp

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,47 +16,27 @@ CAEVehicleAudioEntitySA::CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterf
1616
m_pInterface = pInterface;
1717
}
1818

19-
// Based on CAEVehicleAudioEntity::JustGotInVehicleAsDriver
20-
// Loads accelerate sound bank for planes and helis.
21-
void CAEVehicleAudioEntitySA::LoadDriverSounds ( void )
19+
void CAEVehicleAudioEntitySA::JustGotInVehicleAsDriver ( void )
2220
{
23-
CAEVehicleAudioEntitySAInterface * pVehicleAudioEntity = m_pInterface;
24-
char soundType = pVehicleAudioEntity->m_nSettings.m_nVehicleSoundType;
25-
26-
// If it's heli or plane sound type
27-
if ( soundType == VEHICLE_AUDIO_HELI || soundType == VEHICLE_AUDIO_PLANE || soundType == VEHICLE_AUDIO_SEAPLANE )
21+
m_pInterface->m_bPlayerDriver = true;
22+
DWORD dwFunc = FUNC_CAEVehicleAudioEntity__JustGotInVehicleAsDriver;
23+
DWORD dwThis = (DWORD) m_pInterface;
24+
_asm
2825
{
29-
// If there is accelerate sound bank defined
30-
if ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId != -1 )
31-
{
32-
// We want to hear new sounds ASAP, so we need to stop current ones (which may be from other bankslot, dummy sounds)
33-
unsigned char ucSlot = 0;
34-
while ( ucSlot < 12 )
35-
{
36-
StopVehicleEngineSound ( ucSlot++ );
37-
};
38-
39-
CAEAudioHardware * pAEAudioHardware = pGame->GetAEAudioHardware ();
40-
// If this bank is not already loaded
41-
if ( !pAEAudioHardware->IsSoundBankLoaded ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT ) )
42-
{
43-
// Cancel sounds which uses same bankslot
44-
DWORD dwFunc = FUNC_CAESoundManager__CancelSoundsInBankSlot;
45-
DWORD dwThis = VAR_pAESoundManager;
46-
DWORD dwBankSlot = BANKSLOT_ENGINE_RESIDENT;
47-
bool bUnk = false;
48-
_asm
49-
{
50-
push bUnk
51-
push dwBankSlot
52-
mov ecx, dwThis
53-
call dwFunc
54-
}
26+
mov ecx, dwThis
27+
call dwFunc
28+
}
29+
}
5530

56-
// Load it
57-
pAEAudioHardware->LoadSoundBank ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT );
58-
}
59-
}
31+
void CAEVehicleAudioEntitySA::JustGotOutOfVehicleAsDriver ( void )
32+
{
33+
m_pInterface->m_bPlayerDriver = false;
34+
DWORD dwFunc = FUNC_CAEVehicleAudioEntity__JustGotOutOfVehicleAsDriver;
35+
DWORD dwThis = (DWORD) m_pInterface;
36+
_asm
37+
{
38+
mov ecx, dwThis
39+
call dwFunc
6040
}
6141
}
6242

Client/game_sa/CAEVehicleAudioEntitySA.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
#define FUNC_CAEVehicleAudioEntity__ProcessVehicle 0x501E10
122122
#define FUNC_CAEVehicleAudioEntity__Service 0x502280
123123

124+
#define VAR_CAEVehicleAudioEntity__s_pPlayerDriver 0xB6B990
125+
124126
#define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60
125127
#define VAR_pAESoundManager 0xB62CB0
126128

@@ -252,7 +254,8 @@ class CAEVehicleAudioEntitySA : public CAEVehicleAudioEntity
252254
{
253255
public:
254256
CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterface * pInterface );
255-
void LoadDriverSounds ( void );
257+
void JustGotInVehicleAsDriver ( void );
258+
void JustGotOutOfVehicleAsDriver ( void );
256259
void StopVehicleEngineSound ( unsigned char ucSlot );
257260

258261
private:

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,20 @@ CClientPed::~CClientPed ( void )
287287
g_pMultiplayer->RemoveRemoteDataStorage ( m_pPlayerPed );
288288
g_pMultiplayer->DestroyRemoteDataStorage ( m_remoteDataStorage );
289289
m_remoteDataStorage = NULL;
290+
291+
CClientVehicle * pVehicle = GetOccupiedVehicle ();
292+
if ( m_pPlayerPed && pVehicle && GetOccupiedVehicleSeat () == 0 )
293+
{
294+
if ( g_pClientGame->GetLocalPlayer ()->GetOccupiedVehicle () == pVehicle )
295+
{
296+
CVehicle * pGameVehicle = pVehicle->GetGameVehicle ();
297+
if ( pGameVehicle )
298+
{
299+
// Driver from local player vehicle is being destroyed
300+
pGameVehicle->GetVehicleAudioEntity ()->JustGotOutOfVehicleAsDriver ();
301+
}
302+
}
303+
}
290304
}
291305

292306
// We have a player model?
@@ -1440,6 +1454,12 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
14401454
{
14411455
// Warp him in
14421456
InternalWarpIntoVehicle ( pGameVehicle );
1457+
1458+
if ( m_bIsLocalPlayer || g_pClientGame->GetLocalPlayer ()->GetOccupiedVehicle () == pVehicle )
1459+
{
1460+
// Tell vehicle audio we have driver
1461+
pGameVehicle->GetVehicleAudioEntity ()->JustGotInVehicleAsDriver ();
1462+
}
14431463
}
14441464

14451465
// Update the vehicle and us so we know we've occupied it
@@ -1477,10 +1497,10 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
14771497
pInTask->Destroy ();
14781498
}
14791499

1480-
if ( m_bIsLocalPlayer )
1500+
if ( m_bIsLocalPlayer && pVehicle->IsDriven () )
14811501
{
1482-
// Load accelerate sound bank so we can hear proper engine sound as passenger
1483-
pGameVehicle->GetVehicleAudioEntity ()->LoadDriverSounds ();
1502+
// Tell vehicle audio we have driver
1503+
pGameVehicle->GetVehicleAudioEntity ()->JustGotInVehicleAsDriver ();
14841504
}
14851505
}
14861506
}
@@ -1551,6 +1571,17 @@ CClientVehicle * CClientPed::RemoveFromVehicle ( bool bSkipWarpIfGettingOut )
15511571
CVehicle* pGameVehicle = pVehicle->m_pVehicle;
15521572
if ( pGameVehicle )
15531573
{
1574+
// Did he really was in vehicle and is there driver?
1575+
if ( pVehicle != m_pOccupyingVehicle && pVehicle->GetOccupant () )
1576+
{
1577+
// Local player left vehicle or got abandoned by remote driver
1578+
if ( ( m_bIsLocalPlayer || ( m_uiOccupiedVehicleSeat == 0 && g_pClientGame->GetLocalPlayer ()->GetOccupiedVehicle () == pVehicle ) ) )
1579+
{
1580+
// Tell vehicle audio the driver left
1581+
pGameVehicle->GetVehicleAudioEntity ()->JustGotOutOfVehicleAsDriver ();
1582+
}
1583+
}
1584+
15541585
// If vehicle was deleted during exit, don't skip warp. Fixes player getting stuck and going invisible.
15551586
if ( pVehicle->IsBeingDeleted() )
15561587
bSkipWarpIfGettingOut = false;

Client/mods/deathmatch/logic/CPacketHandler.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,10 +1653,9 @@ void CPacketHandler::Packet_Vehicle_InOut ( NetBitStreamInterface& bitStream )
16531653

16541654
case CClientGame::VEHICLE_NOTIFY_IN_RETURN:
16551655
{
1656-
// Is he not getting in the vehicle yet?
1657-
//if ( !pPlayer->IsGettingIntoVehicle () )
1656+
if ( !pPlayer->IsLocalPlayer () || pPlayer->GetOccupiedVehicle () != pVehicle )
16581657
{
1659-
// Warp him in
1658+
// Warp him in. Don't do that for local player as he is already sitting inside.
16601659
pPlayer->WarpIntoVehicle ( pVehicle, ucSeat );
16611660
}
16621661

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,14 @@ void CMultiplayerSA::InitHooks()
14611461
MemSet ( (void*) 0x6D6517, 0x90, 2 );
14621462
MemSet ( (void*) 0x6D0E43, 0x90, 2 );
14631463

1464+
// Disable vehicle audio driver logic so MTA can reimplement it (#9681)
1465+
// Disable updating m_bPlayerDriver in CAEVehicleAudioEntity::Service
1466+
MemSet ( (void*) 0x5023B2, 0x90, 6 );
1467+
// Disable call to CAEVehicleAudioEntity::JustGotInVehicleAsDriver
1468+
MemSet ( (void*) 0x5023E1, 0x90, 5 );
1469+
// Disable call to CAEVehicleAudioEntity::JustGotOutOfVehicleAsDriver
1470+
MemSet ( (void*) 0x502341, 0x90, 5 );
1471+
14641472

14651473
InitHooks_CrashFixHacks ();
14661474

Client/multiplayer_sa/multiplayer_keysync.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ void SwitchContext ( CVehicle* pVehicle )
470470
// radio etc when they are removed) - issue #95
471471
MemPutFast < BYTE > ( 0x50230C, 0x0 );
472472

473-
MemPutFast < BYTE > ( dwVehicle + 312 + 0xA5, 0 );
474-
475473
// For tanks, to prevent our mouse movement affecting remote tanks
476474
// 006AEA25 0F85 60010000 JNZ gta_sa.006AEB8B
477475
// V

Client/sdk/game/CAEVehicleAudioEntity.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ enum eVehicleAudioType
2929
class CAEVehicleAudioEntity
3030
{
3131
public:
32-
virtual void LoadDriverSounds ( void ) = 0;
32+
virtual void JustGotInVehicleAsDriver ( void ) = 0;
33+
virtual void JustGotOutOfVehicleAsDriver ( void ) = 0;
3334
};

0 commit comments

Comments
 (0)