9
9
#include " Curve.h"
10
10
#include " CModelInfo.h"
11
11
#include " CFileLoader.h"
12
+ #include " CMenuManager.h"
12
13
13
14
#include < stdio.h>
14
15
#include < string>
@@ -86,18 +87,23 @@ class GTAFmod {
86
87
87
88
Events::drawMenuBackgroundEvent += [] {
88
89
89
- // Setup texture
90
- RwRenderStateSet (rwRENDERSTATETEXTURERASTER, m_logoTex->raster );
90
+ if (FrontEndMenuManager.m_nCurrentMenuPage == eMenuPage::MENUPAGE_AUDIO_SETTINGS)
91
+ {
92
+ // Setup texture
93
+ RwRenderStateSet (rwRENDERSTATETEXTURERASTER, m_logoTex->raster );
94
+
95
+ // Background
96
+ CRGBA color = CRGBA (255 , 255 , 255 , 255 );
91
97
92
- // Background
93
- CRGBA color = CRGBA (255 , 255 , 255 , 255 );
98
+ CSprite2d::SetVertices (CRect (SCREEN_COORD_LEFT (50 .0f ),
99
+ SCREEN_COORD_BOTTOM (30 .0f + 100 .0f ), SCREEN_COORD_LEFT (30 .0f + 200 .0f ), SCREEN_COORD_BOTTOM (60 .0f )), color, color, color, color);
100
+ RwIm2DRenderPrimitive (rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4 );
94
101
95
- CSprite2d::SetVertices ( CRect ( SCREEN_COORD_LEFT ( 50 . 0f ),
96
- SCREEN_COORD_BOTTOM ( 30 . 0f + 100 . 0f ), SCREEN_COORD_LEFT ( 50 . 0f + 200 . 0f ), SCREEN_COORD_BOTTOM ( 30 . 0f )), color, color, color, color );
97
- RwIm2DRenderPrimitive (rwPRIMTYPETRIFAN, CSprite2d::maVertices, 4 );
102
+ // Reset texture
103
+ RwRenderStateSet (rwRENDERSTATETEXTURERASTER, 0 );
104
+ }
98
105
99
- // Reset texture
100
- RwRenderStateSet (rwRENDERSTATETEXTURERASTER, 0 );
106
+ MuteAllAudios ();
101
107
};
102
108
}
103
109
}
@@ -136,6 +142,16 @@ class GTAFmod {
136
142
FMODAudio::CheckError (fmodSystem->update (), " Update Failed" );
137
143
}
138
144
}
145
+ static void MuteAllAudios ()
146
+ {
147
+ if (currentAudio)
148
+ {
149
+ currentAudio->m_RpmEventInstance ->setVolume (0.0 );
150
+ currentAudio->m_GearEventInstance ->setVolume (0.0 );
151
+ currentAudio->m_BackFireEventInstance ->setVolume (0.0 );
152
+ }
153
+ FMODAudio::CheckError (fmodSystem->update (), " Update Failed" );
154
+ }
139
155
static void _stdcall OnExitVehicle ()
140
156
{
141
157
CVehicle* veh = FindPlayerVehicle (-1 , true );
@@ -150,6 +166,14 @@ class GTAFmod {
150
166
151
167
if (lastVehicle)
152
168
{
169
+ eVehicleApperance vehicleClass = (eVehicleApperance)lastVehicle->GetVehicleAppearance ();
170
+ if (vehicleClass == eVehicleApperance::VEHICLE_APPEARANCE_BIKE && !iniConfig->m_bEnableOnMotorbikes ||
171
+ vehicleClass == eVehicleApperance::VEHICLE_APPEARANCE_AUTOMOBILE && !iniConfig->m_bEnableOnCars ||
172
+ lastVehicle->m_nVehicleFlags .bIsBig && !iniConfig->m_bEnableOnBigVehicles ) {
173
+ lastVehicle = nullptr ;
174
+ return ;
175
+ }
176
+
153
177
// Try with instance
154
178
currentAudio = audioInstance[lastVehicle];
155
179
// Try with model index
@@ -165,13 +189,18 @@ class GTAFmod {
165
189
// Set to default
166
190
if (currentAudio == NULL )
167
191
{
168
- currentAudio = defaultBank;
192
+ if (defaultBank->m_bIsLoaded )
193
+ {
194
+ currentAudio = defaultBank;
195
+ }
169
196
}
170
- if (currentAudio->m_bIsPlaying == false )
171
- {
172
- fRPM = currentAudio->m_Ini ->m_fMinRPM ;
173
- currentAudio->m_RpmEventInstance ->start ();
174
- currentAudio->m_bIsPlaying = true ;
197
+ if (currentAudio) {
198
+ if (currentAudio->m_bIsPlaying == false )
199
+ {
200
+ fRPM = currentAudio->m_Ini ->m_fMinRPM ;
201
+ currentAudio->m_RpmEventInstance ->start ();
202
+ currentAudio->m_bIsPlaying = true ;
203
+ }
175
204
}
176
205
}
177
206
}
@@ -185,6 +214,12 @@ class GTAFmod {
185
214
}
186
215
static void _stdcall ProcessVehicleEngine (cVehicleParams* params)
187
216
{
217
+ if (!lastVehicle || currentAudio == NULL ) {
218
+ if (params->m_pVehicle ) {
219
+ CallMethod<0x4FBB10 , CAEVehicleAudioEntity*, cVehicleParams*>(¶ms->m_pVehicle ->m_vehicleAudio , params);
220
+ }
221
+ return ;
222
+ }
188
223
189
224
if (lastVehicle && !CTimer::m_UserPause && currentAudio)
190
225
{
@@ -193,29 +228,44 @@ class GTAFmod {
193
228
float velocity = fabs (params->m_fVelocity );
194
229
params->m_nCurrentGear = lastVehicle->m_nCurrentGear ;
195
230
params->m_bHandbrakeOn = lastVehicle->m_nVehicleFlags .bIsHandbrakeOn ;
196
- float currentRatio = (velocity - m_pTransmission->m_aGears [nGear].m_fChangeDownVelocity )
231
+
232
+ /* float currentRatio = (velocity - m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity)
197
233
/ (*(float*)&m_pTransmission->m_aGears[nGear].m_fMaxVelocity
198
- - m_pTransmission->m_aGears [nGear].m_fChangeDownVelocity );
234
+ - m_pTransmission->m_aGears[nGear].m_fChangeDownVelocity);*/
235
+ float currentRatio = velocity / m_pTransmission->m_aGears [nGear].m_fMaxVelocity ;
199
236
200
237
params->m_fVelocityChangingPercentage = currentRatio;
201
238
202
239
if (!nGear)
203
240
params->m_fVelocityChangingPercentage = 0.0 ;
204
241
205
242
// Calculate target RPM
206
- float targetRpm = currentAudio->m_Ini ->m_fMinRPM + ((currentAudio->m_Ini ->m_fMaxRPM - 2000 )* params->m_fVelocityChangingPercentage );
243
+ float maxRPM = currentAudio->m_Ini ->m_fMaxRPM ;
244
+ if (iniConfig->m_iRPMmode == 1 )
245
+ {
246
+ maxRPM -= 2000 ;
247
+ }
248
+ float targetRpm = maxRPM * params->m_fVelocityChangingPercentage ;
249
+ targetRpm = max (currentAudio->m_Ini ->m_fMinRPM , targetRpm);
207
250
208
251
// Set 3D space position
209
252
CVector camPos = TheCamera.GetPosition ();
210
253
CVector vehiclePos = lastVehicle->GetPosition ();
211
254
CVector dirFor;
212
255
CVector dirUp;
256
+ CVector camDirFor;
257
+ CVector camDirUp;
213
258
CVector offsetFor = CVector (0 , -1 , 0 );
214
259
CVector offsetUp = CVector (0 , 0 , 1 );
215
- CMatrix* matrix = lastVehicle->m_matrix ;
260
+
261
+ CMatrix* matrix = lastVehicle->GetMatrix ();
216
262
RwV3dTransformPoint ((RwV3d*)&dirFor, (RwV3d*)&offsetFor, (RwMatrix*)matrix);
217
263
RwV3dTransformPoint ((RwV3d*)&dirUp, (RwV3d*)&offsetUp, (RwMatrix*)matrix);
218
264
265
+ CMatrix* camMatrix = TheCamera.GetMatrix ();
266
+ RwV3dTransformPoint ((RwV3d*)&camDirFor, (RwV3d*)&offsetFor, (RwMatrix*)camMatrix);
267
+ RwV3dTransformPoint ((RwV3d*)&camDirUp, (RwV3d*)&offsetUp, (RwMatrix*)camMatrix);
268
+
219
269
currentAudio->m_Attributes .position .x = vehiclePos.x ;
220
270
currentAudio->m_Attributes .position .y = vehiclePos.y ;
221
271
currentAudio->m_Attributes .position .z = vehiclePos.z ;
@@ -241,15 +291,20 @@ class GTAFmod {
241
291
currentAudio->m_ListenerAttributes .position .x = camPos.x ;
242
292
currentAudio->m_ListenerAttributes .position .y = camPos.y ;
243
293
currentAudio->m_ListenerAttributes .position .z = camPos.z ;
244
- currentAudio->m_ListenerAttributes .forward = currentAudio->m_Attributes .forward ;
245
- currentAudio->m_ListenerAttributes .up = currentAudio->m_Attributes .up ;
294
+
295
+ currentAudio->m_ListenerAttributes .forward .x = camDirFor.x - camPos.x ;
296
+ currentAudio->m_ListenerAttributes .forward .y = camDirFor.y - camPos.y ;
297
+ currentAudio->m_ListenerAttributes .forward .z = camDirFor.z - camPos.z ;
298
+ currentAudio->m_ListenerAttributes .up .x = camDirUp.x - camPos.x ;
299
+ currentAudio->m_ListenerAttributes .up .y = camDirUp.y - camPos.y ;
300
+ currentAudio->m_ListenerAttributes .up .z = camDirUp.z - camPos.z ;
246
301
247
302
fmodSystem->setListenerAttributes (0 , ¤tAudio->m_ListenerAttributes );
248
303
249
304
// Get gas pedal
250
305
float gasPedal = abs (lastVehicle->m_fGasPedal );
251
306
CAutomobile* automobile = reinterpret_cast <CAutomobile*>(lastVehicle);
252
- bool clutch = automobile->m_nWheelsOnGround == 0 || params->m_bHandbrakeOn || lastVehicle->m_fWheelSpinForAudio > 0 .6f ;
307
+ bool clutch = automobile->m_nWheelsOnGround <= 1 || params->m_bHandbrakeOn || lastVehicle->m_fWheelSpinForAudio > 0 .6f ;
253
308
254
309
// Gear change time
255
310
if (CTimer::m_snTimeInMilliseconds < (nLastGearChangeTime + (currentAudio->m_Ini ->m_fGearTime * 0.5 )))
@@ -372,14 +427,21 @@ class GTAFmod {
372
427
Events::initGameEvent.after .Add (LoadConfigs);
373
428
374
429
// Update FMOD on game Process
375
- Events::gameProcessEvent += []() {
430
+ Events::processScriptsEvent += []() {
376
431
if (currentAudio)
377
432
{
378
- currentAudio->m_RpmEventInstance ->setVolume (CTimer::m_UserPause ? 0.0 : iniConfig->m_fMasterVolume );
433
+ float volume = iniConfig->m_fMasterVolume * *(float *)0xB5FCCC * 1 .7f ;
434
+ currentAudio->m_RpmEventInstance ->setVolume (volume);
435
+ currentAudio->m_GearEventInstance ->setVolume (volume);
436
+ currentAudio->m_BackFireEventInstance ->setVolume (volume);
379
437
}
380
438
// Update FMOD
381
439
FMODAudio::CheckError (fmodSystem->update (), " Update Failed" );
382
440
};
441
+
442
+ Events::onPauseAllSounds += []() {
443
+ MuteAllAudios ();
444
+ };
383
445
}
384
446
} gTAFmod ;
385
447
0 commit comments