Permalink
Browse files

Fix #9681 (Unable to hear proper engine sounds when sitting in car as…

… passenger)
  • Loading branch information...
lopezloo committed Aug 15, 2017
1 parent 33bb079 commit 415972818a39e317bc7ebadf23ac277a46dd2530
@@ -16,47 +16,27 @@ CAEVehicleAudioEntitySA::CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterf
m_pInterface = pInterface;
}
// Based on CAEVehicleAudioEntity::JustGotInVehicleAsDriver
// Loads accelerate sound bank for planes and helis.
void CAEVehicleAudioEntitySA::LoadDriverSounds ( void )
void CAEVehicleAudioEntitySA::JustGotInVehicleAsDriver ( void )
{
CAEVehicleAudioEntitySAInterface * pVehicleAudioEntity = m_pInterface;
char soundType = pVehicleAudioEntity->m_nSettings.m_nVehicleSoundType;
// If it's heli or plane sound type
if ( soundType == VEHICLE_AUDIO_HELI || soundType == VEHICLE_AUDIO_PLANE || soundType == VEHICLE_AUDIO_SEAPLANE )
m_pInterface->m_bPlayerDriver = true;
DWORD dwFunc = FUNC_CAEVehicleAudioEntity__JustGotInVehicleAsDriver;
DWORD dwThis = (DWORD) m_pInterface;
_asm
{
// If there is accelerate sound bank defined
if ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId != -1 )
{
// We want to hear new sounds ASAP, so we need to stop current ones (which may be from other bankslot, dummy sounds)
unsigned char ucSlot = 0;
while ( ucSlot < 12 )
{
StopVehicleEngineSound ( ucSlot++ );
};
CAEAudioHardware * pAEAudioHardware = pGame->GetAEAudioHardware ();
// If this bank is not already loaded
if ( !pAEAudioHardware->IsSoundBankLoaded ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT ) )
{
// Cancel sounds which uses same bankslot
DWORD dwFunc = FUNC_CAESoundManager__CancelSoundsInBankSlot;
DWORD dwThis = VAR_pAESoundManager;
DWORD dwBankSlot = BANKSLOT_ENGINE_RESIDENT;
bool bUnk = false;
_asm
{
push bUnk
push dwBankSlot
mov ecx, dwThis
call dwFunc
}
mov ecx, dwThis
call dwFunc
}
}
// Load it
pAEAudioHardware->LoadSoundBank ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT );
}
}
void CAEVehicleAudioEntitySA::JustGotOutOfVehicleAsDriver ( void )
{
m_pInterface->m_bPlayerDriver = false;
DWORD dwFunc = FUNC_CAEVehicleAudioEntity__JustGotOutOfVehicleAsDriver;
DWORD dwThis = (DWORD) m_pInterface;
_asm
{
mov ecx, dwThis
call dwFunc
}
}
@@ -121,6 +121,8 @@
#define FUNC_CAEVehicleAudioEntity__ProcessVehicle 0x501E10
#define FUNC_CAEVehicleAudioEntity__Service 0x502280
#define VAR_CAEVehicleAudioEntity__s_pPlayerDriver 0xB6B990
#define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60
#define VAR_pAESoundManager 0xB62CB0
@@ -252,7 +254,8 @@ class CAEVehicleAudioEntitySA : public CAEVehicleAudioEntity
{
public:
CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterface * pInterface );
void LoadDriverSounds ( void );
void JustGotInVehicleAsDriver ( void );
void JustGotOutOfVehicleAsDriver ( void );
void StopVehicleEngineSound ( unsigned char ucSlot );
private:
@@ -287,6 +287,20 @@ CClientPed::~CClientPed ( void )
g_pMultiplayer->RemoveRemoteDataStorage ( m_pPlayerPed );
g_pMultiplayer->DestroyRemoteDataStorage ( m_remoteDataStorage );
m_remoteDataStorage = NULL;
CClientVehicle * pVehicle = GetOccupiedVehicle ();
if ( m_pPlayerPed && pVehicle && GetOccupiedVehicleSeat () == 0 )
{
if ( g_pClientGame->GetLocalPlayer ()->GetOccupiedVehicle () == pVehicle )
{
CVehicle * pGameVehicle = pVehicle->GetGameVehicle ();
if ( pGameVehicle )
{
// Driver from local player vehicle is being destroyed
pGameVehicle->GetVehicleAudioEntity ()->JustGotOutOfVehicleAsDriver ();
}
}
}
}
// We have a player model?
@@ -1440,6 +1454,12 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
{
// Warp him in
InternalWarpIntoVehicle ( pGameVehicle );
if ( m_bIsLocalPlayer || g_pClientGame->GetLocalPlayer ()->GetOccupiedVehicle () == pVehicle )
{
// Tell vehicle audio we have driver
pGameVehicle->GetVehicleAudioEntity ()->JustGotInVehicleAsDriver ();
}
}
// Update the vehicle and us so we know we've occupied it
@@ -1477,10 +1497,10 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
pInTask->Destroy ();
}
if ( m_bIsLocalPlayer )
if ( m_bIsLocalPlayer && pVehicle->IsDriven () )
{
// Load accelerate sound bank so we can hear proper engine sound as passenger
pGameVehicle->GetVehicleAudioEntity ()->LoadDriverSounds ();
// Tell vehicle audio we have driver
pGameVehicle->GetVehicleAudioEntity ()->JustGotInVehicleAsDriver ();
}
}
}
@@ -1551,6 +1571,17 @@ CClientVehicle * CClientPed::RemoveFromVehicle ( bool bSkipWarpIfGettingOut )
CVehicle* pGameVehicle = pVehicle->m_pVehicle;
if ( pGameVehicle )
{
// Did he really was in vehicle and is there driver?
if ( pVehicle != m_pOccupyingVehicle && pVehicle->GetOccupant () )
{
// Local player left vehicle or got abandoned by remote driver
if ( ( m_bIsLocalPlayer || ( m_uiOccupiedVehicleSeat == 0 && g_pClientGame->GetLocalPlayer ()->GetOccupiedVehicle () == pVehicle ) ) )
{
// Tell vehicle audio the driver left
pGameVehicle->GetVehicleAudioEntity ()->JustGotOutOfVehicleAsDriver ();
}
}
// If vehicle was deleted during exit, don't skip warp. Fixes player getting stuck and going invisible.
if ( pVehicle->IsBeingDeleted() )
bSkipWarpIfGettingOut = false;
@@ -1653,10 +1653,9 @@ void CPacketHandler::Packet_Vehicle_InOut ( NetBitStreamInterface& bitStream )
case CClientGame::VEHICLE_NOTIFY_IN_RETURN:
{
// Is he not getting in the vehicle yet?
//if ( !pPlayer->IsGettingIntoVehicle () )
if ( !pPlayer->IsLocalPlayer () || pPlayer->GetOccupiedVehicle () != pVehicle )
{
// Warp him in
// Warp him in. Don't do that for local player as he is already sitting inside.
pPlayer->WarpIntoVehicle ( pVehicle, ucSeat );
}
@@ -1461,6 +1461,14 @@ void CMultiplayerSA::InitHooks()
MemSet ( (void*) 0x6D6517, 0x90, 2 );
MemSet ( (void*) 0x6D0E43, 0x90, 2 );
// Disable vehicle audio driver logic so MTA can reimplement it (#9681)
// Disable updating m_bPlayerDriver in CAEVehicleAudioEntity::Service
MemSet ( (void*) 0x5023B2, 0x90, 6 );
// Disable call to CAEVehicleAudioEntity::JustGotInVehicleAsDriver
MemSet ( (void*) 0x5023E1, 0x90, 5 );
// Disable call to CAEVehicleAudioEntity::JustGotOutOfVehicleAsDriver
MemSet ( (void*) 0x502341, 0x90, 5 );
InitHooks_CrashFixHacks ();
@@ -470,8 +470,6 @@ void SwitchContext ( CVehicle* pVehicle )
// radio etc when they are removed) - issue #95
MemPutFast < BYTE > ( 0x50230C, 0x0 );
MemPutFast < BYTE > ( dwVehicle + 312 + 0xA5, 0 );

This comment has been minimized.

@lopezloo

lopezloo Aug 15, 2017

Member

It was CAEVehicleAudioEntity m_bPlayerDriver.

// For tanks, to prevent our mouse movement affecting remote tanks
// 006AEA25 0F85 60010000 JNZ gta_sa.006AEB8B
// V
@@ -29,5 +29,6 @@ enum eVehicleAudioType
class CAEVehicleAudioEntity
{
public:
virtual void LoadDriverSounds ( void ) = 0;
virtual void JustGotInVehicleAsDriver ( void ) = 0;
virtual void JustGotOutOfVehicleAsDriver ( void ) = 0;
};

0 comments on commit 4159728

Please sign in to comment.