Skip to content

Commit

Permalink
Fix #9681 (Unable to hear proper engine sounds when sitting in car as…
Browse files Browse the repository at this point in the history
… passenger)
  • Loading branch information
lopezloo committed Aug 15, 2017
1 parent 33bb079 commit 4159728
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 48 deletions.
56 changes: 18 additions & 38 deletions Client/game_sa/CAEVehicleAudioEntitySA.cpp
Expand Up @@ -16,47 +16,27 @@ CAEVehicleAudioEntitySA::CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterf
m_pInterface = pInterface; m_pInterface = pInterface;
} }


// Based on CAEVehicleAudioEntity::JustGotInVehicleAsDriver void CAEVehicleAudioEntitySA::JustGotInVehicleAsDriver ( void )
// Loads accelerate sound bank for planes and helis.
void CAEVehicleAudioEntitySA::LoadDriverSounds ( void )
{ {
CAEVehicleAudioEntitySAInterface * pVehicleAudioEntity = m_pInterface; m_pInterface->m_bPlayerDriver = true;
char soundType = pVehicleAudioEntity->m_nSettings.m_nVehicleSoundType; DWORD dwFunc = FUNC_CAEVehicleAudioEntity__JustGotInVehicleAsDriver;

DWORD dwThis = (DWORD) m_pInterface;
// If it's heli or plane sound type _asm
if ( soundType == VEHICLE_AUDIO_HELI || soundType == VEHICLE_AUDIO_PLANE || soundType == VEHICLE_AUDIO_SEAPLANE )
{ {
// If there is accelerate sound bank defined mov ecx, dwThis
if ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId != -1 ) call dwFunc
{ }
// 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
}


// Load it void CAEVehicleAudioEntitySA::JustGotOutOfVehicleAsDriver ( void )
pAEAudioHardware->LoadSoundBank ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT ); {
} m_pInterface->m_bPlayerDriver = false;
} DWORD dwFunc = FUNC_CAEVehicleAudioEntity__JustGotOutOfVehicleAsDriver;
DWORD dwThis = (DWORD) m_pInterface;
_asm
{
mov ecx, dwThis
call dwFunc
} }
} }


Expand Down
5 changes: 4 additions & 1 deletion Client/game_sa/CAEVehicleAudioEntitySA.h
Expand Up @@ -121,6 +121,8 @@
#define FUNC_CAEVehicleAudioEntity__ProcessVehicle 0x501E10 #define FUNC_CAEVehicleAudioEntity__ProcessVehicle 0x501E10
#define FUNC_CAEVehicleAudioEntity__Service 0x502280 #define FUNC_CAEVehicleAudioEntity__Service 0x502280


#define VAR_CAEVehicleAudioEntity__s_pPlayerDriver 0xB6B990

#define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60 #define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60
#define VAR_pAESoundManager 0xB62CB0 #define VAR_pAESoundManager 0xB62CB0


Expand Down Expand Up @@ -252,7 +254,8 @@ class CAEVehicleAudioEntitySA : public CAEVehicleAudioEntity
{ {
public: public:
CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterface * pInterface ); CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterface * pInterface );
void LoadDriverSounds ( void ); void JustGotInVehicleAsDriver ( void );
void JustGotOutOfVehicleAsDriver ( void );
void StopVehicleEngineSound ( unsigned char ucSlot ); void StopVehicleEngineSound ( unsigned char ucSlot );


private: private:
Expand Down
37 changes: 34 additions & 3 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Expand Up @@ -287,6 +287,20 @@ CClientPed::~CClientPed ( void )
g_pMultiplayer->RemoveRemoteDataStorage ( m_pPlayerPed ); g_pMultiplayer->RemoveRemoteDataStorage ( m_pPlayerPed );
g_pMultiplayer->DestroyRemoteDataStorage ( m_remoteDataStorage ); g_pMultiplayer->DestroyRemoteDataStorage ( m_remoteDataStorage );
m_remoteDataStorage = NULL; 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? // We have a player model?
Expand Down Expand Up @@ -1440,6 +1454,12 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
{ {
// Warp him in // Warp him in
InternalWarpIntoVehicle ( pGameVehicle ); 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 // Update the vehicle and us so we know we've occupied it
Expand Down Expand Up @@ -1477,10 +1497,10 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
pInTask->Destroy (); pInTask->Destroy ();
} }


if ( m_bIsLocalPlayer ) if ( m_bIsLocalPlayer && pVehicle->IsDriven () )
{ {
// Load accelerate sound bank so we can hear proper engine sound as passenger // Tell vehicle audio we have driver
pGameVehicle->GetVehicleAudioEntity ()->LoadDriverSounds (); pGameVehicle->GetVehicleAudioEntity ()->JustGotInVehicleAsDriver ();
} }
} }
} }
Expand Down Expand Up @@ -1551,6 +1571,17 @@ CClientVehicle * CClientPed::RemoveFromVehicle ( bool bSkipWarpIfGettingOut )
CVehicle* pGameVehicle = pVehicle->m_pVehicle; CVehicle* pGameVehicle = pVehicle->m_pVehicle;
if ( pGameVehicle ) 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 vehicle was deleted during exit, don't skip warp. Fixes player getting stuck and going invisible.
if ( pVehicle->IsBeingDeleted() ) if ( pVehicle->IsBeingDeleted() )
bSkipWarpIfGettingOut = false; bSkipWarpIfGettingOut = false;
Expand Down
5 changes: 2 additions & 3 deletions Client/mods/deathmatch/logic/CPacketHandler.cpp
Expand Up @@ -1653,10 +1653,9 @@ void CPacketHandler::Packet_Vehicle_InOut ( NetBitStreamInterface& bitStream )


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


Expand Down
8 changes: 8 additions & 0 deletions Client/multiplayer_sa/CMultiplayerSA.cpp
Expand Up @@ -1461,6 +1461,14 @@ void CMultiplayerSA::InitHooks()
MemSet ( (void*) 0x6D6517, 0x90, 2 ); MemSet ( (void*) 0x6D6517, 0x90, 2 );
MemSet ( (void*) 0x6D0E43, 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 (); InitHooks_CrashFixHacks ();


Expand Down
2 changes: 0 additions & 2 deletions Client/multiplayer_sa/multiplayer_keysync.cpp
Expand Up @@ -470,8 +470,6 @@ void SwitchContext ( CVehicle* pVehicle )
// radio etc when they are removed) - issue #95 // radio etc when they are removed) - issue #95
MemPutFast < BYTE > ( 0x50230C, 0x0 ); MemPutFast < BYTE > ( 0x50230C, 0x0 );


MemPutFast < BYTE > ( dwVehicle + 312 + 0xA5, 0 );

This comment has been minimized.

Copy link
@lopezloo

lopezloo Aug 15, 2017

Author Member

It was CAEVehicleAudioEntity m_bPlayerDriver.


// For tanks, to prevent our mouse movement affecting remote tanks // For tanks, to prevent our mouse movement affecting remote tanks
// 006AEA25 0F85 60010000 JNZ gta_sa.006AEB8B // 006AEA25 0F85 60010000 JNZ gta_sa.006AEB8B
// V // V
Expand Down
3 changes: 2 additions & 1 deletion Client/sdk/game/CAEVehicleAudioEntity.h
Expand Up @@ -29,5 +29,6 @@ enum eVehicleAudioType
class CAEVehicleAudioEntity class CAEVehicleAudioEntity
{ {
public: 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.