Skip to content

Commit d2ab55f

Browse files
authored
Fix #4166 (Engine Sounds of other Helicopters and planes missing...) (#128)
* Fix #4166 (Engine Sounds of other Helicopters and planes missing unless you get in a Helicopter or plane) * Addendum to last commit Use #pragma once
1 parent 06a3768 commit d2ab55f

15 files changed

+553
-41
lines changed

Client/game_sa/CAEAudioHardwareSA.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CAEAudioHardwareSA.cpp
6+
* PURPOSE: Audio hardware
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#include "StdInc.h"
13+
14+
CAEAudioHardwareSA::CAEAudioHardwareSA ( CAEAudioHardwareSAInterface * pInterface )
15+
{
16+
m_pInterface = pInterface;
17+
}
18+
19+
bool CAEAudioHardwareSA::IsSoundBankLoaded ( short wSoundBankID, short wSoundBankSlotID )
20+
{
21+
DWORD dwSoundBankID = wSoundBankID;
22+
DWORD dwSoundBankSlotID = wSoundBankSlotID;
23+
DWORD dwThis = ( DWORD ) m_pInterface;
24+
DWORD dwFunc = FUNC_CAEAudioHardware__IsSoundBankLoaded;
25+
bool bReturn = false;
26+
_asm
27+
{
28+
push dwSoundBankSlotID
29+
push dwSoundBankID
30+
mov ecx, dwThis
31+
call dwFunc
32+
mov bReturn, al
33+
}
34+
return bReturn;
35+
}
36+
37+
void CAEAudioHardwareSA::LoadSoundBank ( short wSoundBankID, short wSoundBankSlotID )
38+
{
39+
DWORD dwSoundBankID = wSoundBankID;
40+
DWORD dwSoundBankSlotID = wSoundBankSlotID;
41+
DWORD dwThis = ( DWORD ) m_pInterface;
42+
DWORD dwFunc = FUNC_CAEAudioHardware__LoadSoundBank;
43+
_asm
44+
{
45+
push dwSoundBankSlotID
46+
push dwSoundBankID
47+
mov ecx, dwThis
48+
call dwFunc
49+
}
50+
}

Client/game_sa/CAEAudioHardwareSA.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CAEAudioHardwareSA.h
6+
* PURPOSE: Audio hardware header
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#pragma once
13+
14+
#include "Common.h"
15+
#include <game/CAEAudioHardware.h>
16+
17+
#define FUNC_CAEAudioHardware__IsSoundBankLoaded 0x4D88C0
18+
#define FUNC_CAEAudioHardware__LoadSoundBank 0x4D88A0
19+
20+
#define CLASS_CAEAudioHardware 0xB5F8B8
21+
22+
class CAEAudioHardwareSAInterface
23+
{
24+
25+
};
26+
27+
class CAEAudioHardwareSA : public CAEAudioHardware
28+
{
29+
public:
30+
CAEAudioHardwareSA ( CAEAudioHardwareSAInterface * pInterface );
31+
bool IsSoundBankLoaded ( short wSoundBankID, short wSoundBankSlotID );
32+
void LoadSoundBank ( short wSoundBankID, short wSoundBankSlotID );
33+
34+
private:
35+
CAEAudioHardwareSAInterface * m_pInterface;
36+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*****************************************************************************
2+
*
3+
* PROJECT: Multi Theft Auto v1.0
4+
* LICENSE: See LICENSE in the top level directory
5+
* FILE: game_sa/CAEVehicleAudioEntitySA.cpp
6+
* PURPOSE: Vehicle audio entity
7+
*
8+
* Multi Theft Auto is available from http://www.multitheftauto.com/
9+
*
10+
*****************************************************************************/
11+
12+
#include "StdInc.h"
13+
14+
CAEVehicleAudioEntitySA::CAEVehicleAudioEntitySA ( CAEVehicleAudioEntitySAInterface * pInterface )
15+
{
16+
m_pInterface = pInterface;
17+
}
18+
19+
// Based on CAEVehicleAudioEntity::JustGotInVehicleAsDriver
20+
// Loads accelerate sound bank for planes and helis.
21+
void CAEVehicleAudioEntitySA::LoadDriverSounds ( void )
22+
{
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 == 4 || soundType == 5 )
28+
{
29+
// If there is accelerate sound bank defined
30+
if ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId != -1 )
31+
{
32+
CAEAudioHardware * pAEAudioHardware = pGame->GetAEAudioHardware ();
33+
// If this bank is not already loaded
34+
if ( !pAEAudioHardware->IsSoundBankLoaded ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT ) )
35+
{
36+
// Load it
37+
pAEAudioHardware->LoadSoundBank ( pVehicleAudioEntity->m_wEngineAccelerateSoundBankId, BANKSLOT_ENGINE_RESIDENT );
38+
}
39+
}
40+
}
41+
}

Client/game_sa/CAEVehicleAudioEntitySA.h

Lines changed: 256 additions & 0 deletions
Large diffs are not rendered by default.

Client/game_sa/CAudioEngineSA.h

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,38 +55,67 @@ class CAEAudioEntity
5555
public:
5656
CAEAudioEntityVTBL * vtbl;
5757
CEntitySAInterface * pEntity;
58+
char m_tempSound[0x74]; // CAESound
5859
};
60+
static_assert(sizeof(CAEAudioEntity) == 0x7C, "Invalid size for CAEAudioEntity");
5961

6062
class CAESound
6163
{
6264
public:
63-
ushort usGroup; //+0
64-
ushort usIndex; //+2
65-
CAEAudioEntity* pAudioEntity; //+4
66-
CEntitySAInterface* pGameEntity; //+8 Either a player or NULL
67-
int a; //+c = 3
68-
float b; //+10 = -1.f
69-
float c; //+14 = -50.f
70-
float fVolume; //+18 = 1.f
71-
float fPitch; //+1c = 1.f
72-
uint d; //+20
73-
CVector vec1; //+24 = Position of player?
74-
CVector vec2; //+30 = Position of player?
75-
int e; //+3c = 1,621 set from framecounter, no set pos if non zero
76-
int f; //+40 = 300 time in milliseconds
77-
int g; //+44 = 300 set from framecounter
78-
float h; //+48 = 2997.3567f start something?
79-
float j; //+4c = 2997.3567f current something?
80-
float k; //+50 = 1.0f
81-
ushort l; //+54 = 31488
82-
ushort m; //+56 = 1005
83-
int n; //+58 = 1
84-
int o; //+5C = 0
85-
float p; //+60 = -100.f
86-
float q; //+64 = 1.f
87-
ushort r; //+68 = 0 (1 on stop)
88-
ushort s; //+6a = 114
65+
ushort usGroup; // +0
66+
ushort usIndex; // +2
67+
CAEAudioEntity* pAudioEntity; // +4
68+
CEntitySAInterface* pGameEntity; // +8 Either a player or NULL
69+
unsigned int m_dwEvent; // +12
70+
float m_fMaxVolume; // +16
71+
float m_fVolume; // +20
72+
float m_fSoundDistance; // +24
73+
float m_fSpeed; // +28
74+
float unk1; // +32
75+
CVector m_vCurrPosn; // +36
76+
CVector m_vPrevPosn; // +48
77+
int m_dwLastFrameUpdate; // +60
78+
int m_dwCurrTimeUpdate; // +64
79+
int m_dwPrevTimeUpdate; // +68
80+
float m_fCurrCamDist; // +72
81+
float m_fPrevCamDist; // +76
82+
float m_fTimeScale; // +80
83+
char unk2; // +84 = 31488
84+
char unk3; // +85 = 1005
85+
union
86+
{
87+
unsigned short m_wEnvironmentFlags;
88+
struct
89+
{
90+
unsigned short m_bFrontEnd : 1;
91+
unsigned short m_bUncancellable : 1;
92+
unsigned short m_bRequestUpdates : 1;
93+
unsigned short m_bPlayPhysically : 1;
94+
unsigned short m_bUnpausable : 1;
95+
unsigned short m_bStartPercentage : 1;
96+
unsigned short m_bMusicMastered : 1;
97+
unsigned short m_bLifespanTiedToPhysicalEntity : 1;
98+
unsigned short m_bUndackable : 1;
99+
unsigned short m_bUncompressable : 1;
100+
unsigned short m_bRolledOff : 1;
101+
unsigned short m_bSmoothDucking : 1;
102+
unsigned short m_bForcedFront : 1;
103+
};
104+
};
105+
unsigned short m_wIsUsed; // +88
106+
short unk4; // +90 = 1005
107+
short m_wCurrentPlayPosition; // +92
108+
short unk5; // +94 = 0
109+
float m_fFinalVolume; // +96
110+
float m_fFrequency; // +100
111+
short m_wPlayingState; // +104
112+
char unk6[2]; // +106
113+
float m_fSoundHeadRoom; // +108
114+
short unk7; // +112
115+
short unk8; // +114
116+
89117
};
118+
static_assert(sizeof(CAESound) == 0x74, "Invalid size for CAESound");
90119

91120
class CAudioEngineSA : public CAudioEngine
92121
{

Client/game_sa/CGameSA.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ CGameSA::CGameSA()
6666

6767
DEBUG_TRACE("CGameSA::CGameSA()");
6868
this->m_pAudioEngine = new CAudioEngineSA((CAudioEngineSAInterface*)CLASS_CAudioEngine);
69+
this->m_pAEAudioHardware = new CAEAudioHardwareSA((CAEAudioHardwareSAInterface*)CLASS_CAEAudioHardware);
6970
this->m_pAudioContainer = new CAudioContainerSA();
7071
this->m_pWorld = new CWorldSA();
7172
this->m_pPools = new CPoolsSA();
@@ -240,6 +241,7 @@ CGameSA::~CGameSA ( void )
240241
delete reinterpret_cast < CPoolsSA* > ( m_pPools );
241242
delete reinterpret_cast < CWorldSA* > ( m_pWorld );
242243
delete reinterpret_cast < CAudioEngineSA* > ( m_pAudioEngine );
244+
delete reinterpret_cast < CAEAudioHardwareSA* > ( m_pAEAudioHardware );
243245
delete reinterpret_cast < CAudioContainerSA* > ( m_pAudioContainer );
244246
delete reinterpret_cast < CPointLightsSA * > ( m_pPointLights );
245247
}

Client/game_sa/CGameSA.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class CGameSA : public CGame
135135
inline CTheCarGenerators * GetTheCarGenerators() { DEBUG_TRACE("CTheCarGenerators * GetTheCarGenerators()");return m_pTheCarGenerators; };
136136
inline CAERadioTrackManager * GetAERadioTrackManager() { DEBUG_TRACE("CAERadioTrackManager * GetAERadioTrackManager()");return m_pCAERadioTrackManager; };
137137
inline CAudioEngine * GetAudioEngine() { DEBUG_TRACE("CAudio * GetAudioEngine()");return m_pAudioEngine; };
138+
inline CAEAudioHardware * GetAEAudioHardware() { DEBUG_TRACE("CAEAudioHardware * GetAEAudioHardware()");return m_pAEAudioHardware; };
138139
inline CAudioEngine * GetAudio() { DEBUG_TRACE("CAudio * GetAudioEngine()");return m_pAudioEngine; };
139140
inline CAudioContainer * GetAudioContainer() { DEBUG_TRACE("CAudio * GetAudioContainer()");return m_pAudioContainer; };
140141
inline CMenuManager * GetMenuManager() { DEBUG_TRACE("CMenuManager * GetMenuManager()");return m_pMenuManager; };
@@ -296,6 +297,7 @@ class CGameSA : public CGame
296297
CTheCarGenerators * m_pTheCarGenerators;
297298
CAERadioTrackManager * m_pCAERadioTrackManager;
298299
CAudioEngine * m_pAudioEngine;
300+
CAEAudioHardware * m_pAEAudioHardware;
299301
CAudioContainer * m_pAudioContainer;
300302
CMenuManager * m_pMenuManager;
301303
CText * m_pText;

Client/game_sa/CVehicleSA.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ void CVehicleSA::Init ( void )
265265

266266
// only applicable for CAutomobile based vehicles (i.e. not bikes, trains or boats, but includes planes, helis etc)
267267
this->m_pDamageManager = new CDamageManagerSA( m_pInterface, (CDamageManagerSAInterface *)((DWORD)this->GetInterface() + 1440));
268+
269+
this->m_pVehicleAudioEntity = new CAEVehicleAudioEntitySA ( &GetVehicleInterface()->m_VehicleAudioEntity );
268270

269271
// Replace the handling interface with our own to prevent handlig.cfg cheats and allow custom handling stuff.
270272
// We don't use SA's array because we want one handling per vehicle type and also allow custom handlings
@@ -344,6 +346,12 @@ CVehicleSA::~CVehicleSA()
344346
m_pDamageManager = NULL;
345347
}
346348

349+
if ( m_pVehicleAudioEntity )
350+
{
351+
delete m_pVehicleAudioEntity;
352+
m_pVehicleAudioEntity = NULL;
353+
}
354+
347355
if ( m_pSuspensionLines )
348356
{
349357
delete [] m_pSuspensionLines;

Client/game_sa/CVehicleSA.h

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class CVehicleSA;
2929
#include "CDamageManagerSA.h"
3030
#include "CDoorSA.h"
3131
#include "CColPointSA.h"
32+
#include "CAEVehicleAudioEntitySA.h"
3233

3334
#define SIZEOF_CHELI 2584
3435

@@ -322,17 +323,6 @@ struct CTrainFlags
322323
unsigned char unknown7 : 8;
323324
};
324325

325-
326-
// TODO: Size?
327-
class CAEVehicleAudioEntity
328-
{
329-
BYTE pad1[154];
330-
public:
331-
BYTE bCurrentRadioStation;
332-
private:
333-
BYTE pad2;
334-
};
335-
336326
class CAutoPilot
337327
{
338328
BYTE pad[56];
@@ -346,9 +336,7 @@ class CAutoPilot
346336
class CVehicleSAInterface : public CPhysicalSAInterface
347337
{
348338
public:
349-
CAEVehicleAudioEntity m_VehicleAudioEntity; // 312
350-
351-
int padaudio[108];
339+
CAEVehicleAudioEntitySAInterface m_VehicleAudioEntity; // 312
352340

353341
tHandlingDataSA* pHandlingData; // +900
354342
tFlyingHandlingDataSA* pFlyingHandlingData; // +904
@@ -515,6 +503,7 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
515503
friend class CPoolsSA;
516504
private:
517505
CDamageManagerSA* m_pDamageManager;
506+
CAEVehicleAudioEntitySA* m_pVehicleAudioEntity;
518507
CHandlingEntrySA* m_pHandlingData;
519508
void* m_pSuspensionLines;
520509
bool m_bIsDerailable;
@@ -789,6 +778,8 @@ class CVehicleSA : public virtual CVehicle, public virtual CPhysicalSA
789778

790779
void UpdateLandingGearPosition ( );
791780

781+
CAEVehicleAudioEntitySA * GetVehicleAudioEntity ( void ) { return m_pVehicleAudioEntity; };
782+
792783
private:
793784
void RecalculateSuspensionLines ( void );
794785
void CopyGlobalSuspensionLinesToPrivate ( void );

Client/game_sa/StdInc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@
5959
#include "CPedSA.h"
6060
#include "CPedSoundSA.h"
6161
#include "CAudioEngineSA.h"
62+
#include "CAEAudioHardwareSA.h"
63+
#include "CAEVehicleAudioEntitySA.h"
6264
#include "CAudioContainerSA.h"
6365
#include "CPlayerInfoSA.h"
6466
#include "CPopulationSA.h"

0 commit comments

Comments
 (0)