Skip to content

Commit 3ee2ef8

Browse files
committed
Fix loading of aircraft SFX breaks other engine SFX
(Addendum to d2ab55f)
1 parent 13b02d6 commit 3ee2ef8

File tree

6 files changed

+107
-4
lines changed

6 files changed

+107
-4
lines changed

Client/game_sa/CAEVehicleAudioEntitySA.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,53 @@ void CAEVehicleAudioEntitySA::LoadDriverSounds ( void )
2424
char soundType = pVehicleAudioEntity->m_nSettings.m_nVehicleSoundType;
2525

2626
// If it's heli or plane sound type
27-
if ( soundType == 4 || soundType == 5 )
27+
if ( soundType == VEHICLE_AUDIO_HELI || soundType == VEHICLE_AUDIO_PLANE || soundType == VEHICLE_AUDIO_SEAPLANE )
2828
{
2929
// If there is accelerate sound bank defined
3030
if ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId != -1 )
3131
{
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+
3239
CAEAudioHardware * pAEAudioHardware = pGame->GetAEAudioHardware ();
3340
// If this bank is not already loaded
3441
if ( !pAEAudioHardware->IsSoundBankLoaded ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT ) )
3542
{
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+
}
55+
3656
// Load it
3757
pAEAudioHardware->LoadSoundBank ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT );
3858
}
3959
}
4060
}
4161
}
62+
63+
void CAEVehicleAudioEntitySA::StopVehicleEngineSound ( unsigned char ucSlot )
64+
{
65+
DWORD dwFunc = FUNC_CAESound__Stop;
66+
tVehicleSound * pVehicleSound = &m_pInterface->m_aEngineSounds [ ucSlot ];
67+
if ( pVehicleSound->m_pSound )
68+
{
69+
DWORD dwThis = (DWORD) pVehicleSound->m_pSound;
70+
_asm
71+
{
72+
mov ecx, dwThis
73+
call dwFunc
74+
}
75+
}
76+
}

Client/game_sa/CAEVehicleAudioEntitySA.h

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

124+
#define FUNC_CAESoundManager__CancelSoundsInBankSlot 0x4EFC60
125+
#define VAR_pAESoundManager 0xB62CB0
126+
124127
struct tVehicleAudioSettings
125128
{
126129
char m_nVehicleSoundType;
@@ -250,6 +253,7 @@ class CAEVehicleAudioEntitySA : public CAEVehicleAudioEntity
250253
public:
251254
CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterface * pInterface );
252255
void LoadDriverSounds ( void );
256+
void StopVehicleEngineSound ( unsigned char ucSlot );
253257

254258
private:
255259
CAEVehicleAudioEntitySAInterface * m_pInterface;

Client/game_sa/CAudioEngineSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define FUNC_CAudioEngine_ReportBulletHit 0x506ec0
4242
#define FUNC_CAudioEngine_ReportWeaponEvent 0x506f40
4343

44+
#define FUNC_CAESound__Stop 0x4EF1C0
45+
4446
class CAudioEngineSAInterface
4547
{
4648
};

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,12 @@ void CClientPed::WarpIntoVehicle ( CClientVehicle* pVehicle, unsigned int uiSeat
14751475
pInTask->ProcessPed ( m_pPlayerPed );
14761476
pInTask->Destroy ();
14771477
}
1478+
1479+
if ( m_bIsLocalPlayer )
1480+
{
1481+
// Load accelerate sound bank so we can hear proper engine sound as passenger
1482+
pGameVehicle->GetVehicleAudioEntity ()->LoadDriverSounds ();
1483+
}
14781484
}
14791485
}
14801486

@@ -4172,9 +4178,6 @@ void CClientPed::InternalWarpIntoVehicle ( CVehicle* pGameVehicle )
41724178
{
41734179
// Make sure we can't fall off
41744180
SetCanBeKnockedOffBike ( false );
4175-
4176-
// Load driver sounds (GTA does it when local player enter vehicle)
4177-
pGameVehicle->GetVehicleAudioEntity ()->LoadDriverSounds ();
41784181
}
41794182

41804183
// Jax: make sure our camera is fixed on the new vehicle

Client/multiplayer_sa/CMultiplayerSA.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ DWORD RETURN_CTaskSimplyGangDriveBy__ProcessPed = 0x62D5AC;
294294
DWORD RETURN_CAERadioTrackManager__ChooseMusicTrackIndex = 0x4EA2A0;
295295
DWORD RETURN_CAERadioTrackManager__ChooseMusicTrackIndex_Regenerate = 0x04EA286;
296296

297+
#define HOOKPOS_CAEVEhicleAudioEntity__ProcessDummyHeli 0x4FE9B9
298+
DWORD RETURN_CAEVEhicleAudioEntity__ProcessDummyHeli = 0x4FEDFB;
299+
DWORD dwFUNC_CAEVehicleAudioEntity__ProcessAIHeli = FUNC_CAEVehicleAudioEntity__ProcessAIHeli;
300+
301+
#define HOOKPOS_CAEVEhicleAudioEntity__ProcessDummyProp 0x4FD96D
302+
DWORD RETURN_CAEVEhicleAudioEntity__ProcessDummyProp = 0x4FDFAB;
303+
DWORD dwFUNC_CAEVehicleAudioEntity__ProcessAIProp = FUNC_CAEVehicleAudioEntity__ProcessAIProp;
304+
297305
CPed* pContextSwitchedPed = 0;
298306
CVector vecCenterOfWorld;
299307
FLOAT fFalseHeading;
@@ -509,6 +517,9 @@ void HOOK_CTaskSimpleGangDriveBy__ProcessPed();
509517

510518
void HOOK_CAERadioTrackManager__ChooseMusicTrackIndex ( );
511519

520+
void HOOK_CAEVehicleAudioEntity__ProcessDummyHeli ();
521+
void HOOK_CAEVehicleAudioEntity__ProcessDummyProp ();
522+
512523
CMultiplayerSA::CMultiplayerSA()
513524
{
514525
// Unprotect all of the GTASA code at once and leave it that way
@@ -724,6 +735,9 @@ void CMultiplayerSA::InitHooks()
724735
HookInstall(HOOKPOS_CAERadioTrackManager__ChooseMusicTrackIndex, (DWORD) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex, 10);
725736
}
726737

738+
HookInstall ( HOOKPOS_CAEVEhicleAudioEntity__ProcessDummyHeli, (DWORD) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli, 5 );
739+
HookInstall ( HOOKPOS_CAEVEhicleAudioEntity__ProcessDummyProp, (DWORD) HOOK_CAEVehicleAudioEntity__ProcessDummyProp, 5 );
740+
727741
// Disable GTA setting g_bGotFocus to false when we minimize
728742
MemSet ( (void *)ADDR_GotFocus, 0x90, pGameInterface->GetGameVersion () == VERSION_EU_10 ? 6 : 10 );
729743

@@ -6923,3 +6937,33 @@ void _declspec(naked) HOOK_CAERadioTrackManager__ChooseMusicTrackIndex ( )
69236937
jmp RETURN_CAERadioTrackManager__ChooseMusicTrackIndex
69246938
}
69256939
}
6940+
6941+
// Use AI heli rotor sound if player sound bank is not loaded
6942+
void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyHeli ()
6943+
{
6944+
_asm
6945+
{
6946+
// push our argument
6947+
push [esp+8Ch+4]
6948+
mov ecx, esi
6949+
// call twin function
6950+
call dwFUNC_CAEVehicleAudioEntity__ProcessAIHeli
6951+
// go back
6952+
jmp RETURN_CAEVEhicleAudioEntity__ProcessDummyHeli
6953+
}
6954+
}
6955+
6956+
// Use AI plane propeller sound if player sound bank is not loaded
6957+
void _declspec(naked) HOOK_CAEVehicleAudioEntity__ProcessDummyProp ()
6958+
{
6959+
_asm
6960+
{
6961+
// push our argument
6962+
push [esp+98h+4]
6963+
mov ecx, esi
6964+
// call twin function
6965+
call dwFUNC_CAEVehicleAudioEntity__ProcessAIProp
6966+
// go back
6967+
jmp RETURN_CAEVEhicleAudioEntity__ProcessDummyProp
6968+
}
6969+
}

Client/sdk/game/CAEVehicleAudioEntity.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@
1111

1212
#pragma once
1313

14+
enum eVehicleAudioType
15+
{
16+
VEHICLE_AUDIO_CAR = 0,
17+
VEHICLE_AUDIO_BIKE,
18+
VEHICLE_AUDIO_BICYCLE,
19+
VEHICLE_AUDIO_BOAT,
20+
VEHICLE_AUDIO_HELI,
21+
VEHICLE_AUDIO_PLANE,
22+
VEHICLE_AUDIO_SEAPLANE, // unused?
23+
24+
VEHICLE_AUDIO_TRAIN = 8,
25+
VEHICLE_AUDIO_SPECIAL, // RC vehicles, vortex, caddy, few trailers
26+
VEHICLE_AUDIO_SILENT
27+
};
28+
1429
class CAEVehicleAudioEntity
1530
{
1631
public:

0 commit comments

Comments
 (0)