Skip to content

Commit 135e8e3

Browse files
Merge pull request #16 from JuniorDjjr/main
v0.4
2 parents a6203b2 + 3c2e33c commit 135e8e3

File tree

2 files changed

+198
-136
lines changed

2 files changed

+198
-136
lines changed

GTAFmod/GTAFmod.cpp

+86-24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "Curve.h"
1010
#include "CModelInfo.h"
1111
#include "CFileLoader.h"
12+
#include "CMenuManager.h"
1213

1314
#include <stdio.h>
1415
#include <string>
@@ -86,18 +87,23 @@ class GTAFmod {
8687

8788
Events::drawMenuBackgroundEvent += [] {
8889

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);
9197

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);
94101

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+
}
98105

99-
// Reset texture
100-
RwRenderStateSet(rwRENDERSTATETEXTURERASTER, 0);
106+
MuteAllAudios();
101107
};
102108
}
103109
}
@@ -136,6 +142,16 @@ class GTAFmod {
136142
FMODAudio::CheckError(fmodSystem->update(), "Update Failed");
137143
}
138144
}
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+
}
139155
static void _stdcall OnExitVehicle()
140156
{
141157
CVehicle* veh = FindPlayerVehicle(-1, true);
@@ -150,6 +166,14 @@ class GTAFmod {
150166

151167
if (lastVehicle)
152168
{
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+
153177
//Try with instance
154178
currentAudio = audioInstance[lastVehicle];
155179
//Try with model index
@@ -165,13 +189,18 @@ class GTAFmod {
165189
//Set to default
166190
if (currentAudio == NULL)
167191
{
168-
currentAudio = defaultBank;
192+
if (defaultBank->m_bIsLoaded)
193+
{
194+
currentAudio = defaultBank;
195+
}
169196
}
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+
}
175204
}
176205
}
177206
}
@@ -185,6 +214,12 @@ class GTAFmod {
185214
}
186215
static void _stdcall ProcessVehicleEngine(cVehicleParams* params)
187216
{
217+
if (!lastVehicle || currentAudio == NULL) {
218+
if (params->m_pVehicle) {
219+
CallMethod<0x4FBB10, CAEVehicleAudioEntity*, cVehicleParams*>(&params->m_pVehicle->m_vehicleAudio, params);
220+
}
221+
return;
222+
}
188223

189224
if (lastVehicle && !CTimer::m_UserPause && currentAudio)
190225
{
@@ -193,29 +228,44 @@ class GTAFmod {
193228
float velocity = fabs(params->m_fVelocity);
194229
params->m_nCurrentGear = lastVehicle->m_nCurrentGear;
195230
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)
197233
/ (*(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;
199236

200237
params->m_fVelocityChangingPercentage = currentRatio;
201238

202239
if (!nGear)
203240
params->m_fVelocityChangingPercentage = 0.0;
204241

205242
//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);
207250

208251
//Set 3D space position
209252
CVector camPos = TheCamera.GetPosition();
210253
CVector vehiclePos = lastVehicle->GetPosition();
211254
CVector dirFor;
212255
CVector dirUp;
256+
CVector camDirFor;
257+
CVector camDirUp;
213258
CVector offsetFor = CVector(0, -1, 0);
214259
CVector offsetUp = CVector(0, 0, 1);
215-
CMatrix* matrix = lastVehicle->m_matrix;
260+
261+
CMatrix* matrix = lastVehicle->GetMatrix();
216262
RwV3dTransformPoint((RwV3d*)&dirFor, (RwV3d*)&offsetFor, (RwMatrix*)matrix);
217263
RwV3dTransformPoint((RwV3d*)&dirUp, (RwV3d*)&offsetUp, (RwMatrix*)matrix);
218264

265+
CMatrix* camMatrix = TheCamera.GetMatrix();
266+
RwV3dTransformPoint((RwV3d*)&camDirFor, (RwV3d*)&offsetFor, (RwMatrix*)camMatrix);
267+
RwV3dTransformPoint((RwV3d*)&camDirUp, (RwV3d*)&offsetUp, (RwMatrix*)camMatrix);
268+
219269
currentAudio->m_Attributes.position.x = vehiclePos.x;
220270
currentAudio->m_Attributes.position.y = vehiclePos.y;
221271
currentAudio->m_Attributes.position.z = vehiclePos.z;
@@ -241,15 +291,20 @@ class GTAFmod {
241291
currentAudio->m_ListenerAttributes.position.x = camPos.x;
242292
currentAudio->m_ListenerAttributes.position.y = camPos.y;
243293
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;
246301

247302
fmodSystem->setListenerAttributes(0, &currentAudio->m_ListenerAttributes);
248303

249304
//Get gas pedal
250305
float gasPedal = abs(lastVehicle->m_fGasPedal);
251306
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;
253308

254309
//Gear change time
255310
if (CTimer::m_snTimeInMilliseconds < (nLastGearChangeTime + (currentAudio->m_Ini->m_fGearTime * 0.5)))
@@ -372,14 +427,21 @@ class GTAFmod {
372427
Events::initGameEvent.after.Add(LoadConfigs);
373428

374429
//Update FMOD on game Process
375-
Events::gameProcessEvent += []() {
430+
Events::processScriptsEvent += []() {
376431
if (currentAudio)
377432
{
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);
379437
}
380438
//Update FMOD
381439
FMODAudio::CheckError(fmodSystem->update(), "Update Failed");
382440
};
441+
442+
Events::onPauseAllSounds += []() {
443+
MuteAllAudios();
444+
};
383445
}
384446
} gTAFmod;
385447

0 commit comments

Comments
 (0)