Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions resource/dist/ModelExtras.ini
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ TailLightShadowIntensity = 80 # Opacity of projected groun
[SOUND]
SoundEffects = 1 # Master toggle for all ModelExtras sound effects
SoundMult = 0.6 # Multiplier for ModelExtras audio effects (0.0 to 1.0)
SoundEffects_GlobalAirbreakSound = 1 # Plays engine air brake sound for big vehicles (check [TABLE])
SoundEffects_GlobalEngineSound = 1 # Plays engine on/off sound
SoundEffects_GlobalIndicatorSound = 1 # Plays indicator on/off sound
SoundEffects_GlobalReverseSound = 1 # Plays reverse sound for big vehicles (check [TABLE])
SoundEffects_NonPlayerVehicles = 1 # Plays sound effects for traffic vehicles too
GlobalAirbreakSound = 1 # Plays engine air brake sound for big vehicles (check [TABLE])
GlobalEngineSound = 1 # Plays engine on/off sound
GlobalIndicatorSound = 1 # Plays indicator on/off sound
GlobalReverseSound = 1 # Plays reverse sound for big vehicles (check [TABLE])
DoorChimeSound = 1 # Plays open door warning chime sound for vehicles (check [TABLE])
DoorChimeOnlySelected = 1 # Open door warning chime for selected vehicles only (check [TABLE])
NonPlayerVehicles = 1 # Plays sound effects for traffic vehicles too

[CONFIG]
EnableLiveReload = 1 # Enables the 'MERELOAD' cheat to live-reload vehicle configs and INI settings without restarting
Expand All @@ -93,5 +95,7 @@ SirenLightKey = 0x4C # Toggle emergency siren lig
SpotLightKey = 0x42 # Toggle police searchlight / spotlight on / off (Default: B [0x42])

[TABLE]
SoundEffects_BigVehicleModels = "403, 406, 407, 408, 414, 416, 427, 428, 431, 433, 437, 443, 455, 456, 486, 498, 499, 508, 514, 515, 524, 525, 528, 530, 532, 544, 552, 573, 574, 578, 588, 601, 609" # Vehicle model IDs for air brake and reverse warning sounds
BigVehicleModels = "403, 406, 407, 408, 414, 416, 427, 428, 431, 433, 437, 443, 455, 456, 486, 498, 499, 508, 514, 515, 524, 525, 528, 530, 532, 544, 552, 573, 574, 578, 588, 601, 609" # Vehicle model IDs for air brake and reverse warning sounds
BackFireEffect_VehicleModels = "402, 411, 415, 424, 429, 434, 439, 451, 461, 468, 475, 477, 480, 494, 496, 502, 503, 504, 506, 521, 522, 535, 541, 558, 559, 560, 561, 562, 565, 581, 587, 589, 603, 604" # Vehicle model IDs for sports exhaust backfire flames
DoorChime_VehicleModels = "400, 401, 402, 405, 409, 410, 411, 413, 415, 416, 418, 420, 421, 422, 426, 429, 436, 440, 445, 451, 458, 459, 470, 477, 480, 482, 489, 490, 492, 496, 500, 505, 506, 507, 516, 517, 526, 527, 529, 533, 540, 541, 546, 547, 550, 551, 554, 558, 559, 560, 561, 562, 565, 579, 582, 585, 587, 589, 596, 597, 598, 599, 602, 603" # Allowed vehicle model IDs for open door warning chime sound

Binary file added resource/dist/ModelExtras/audio/door_chime.mp3
Binary file not shown.
119 changes: 103 additions & 16 deletions src/features/soundeffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using namespace plugin;

std::vector<int> ValidForReverseSound;
std::vector<int> ValidForDoorChime;

#define ANIMGROUP_TRUCK 2
#define ANIMGROUP_BUS 15
Expand All @@ -16,25 +17,65 @@ static bool bReverseSounds = false;
static bool bEngineSounds = false;
static bool bIndicatorSounds = false;
static bool bAirbreakSounds = false;
static bool bDoorChimeSounds = false;
static bool bDoorChimeOnlySelected = false;
static float fDoorChimeVolume = 0.7f;
static bool bOnlyPlayerVehicle = true;

static bool IsVehicleEligibleForDoorChime(int model)
{
if (CModelInfo::IsBikeModel(model) || CModelInfo::IsBmxModel(model) || CModelInfo::IsQuadBikeModel(model) ||
CModelInfo::IsHeliModel(model) || CModelInfo::IsPlaneModel(model) || CModelInfo::IsBoatModel(model) ||
CModelInfo::IsTrailerModel(model))
{
return false;
}
if (!bDoorChimeOnlySelected)
{
return true;
}
return std::find(ValidForDoorChime.begin(), ValidForDoorChime.end(), model) != ValidForDoorChime.end();
}

static std::string GetDoorChimeAudioPath()
{
static std::string path = MOD_DATA_PATH("audio/door_chime.mp3");
return path;
}

void SoundEffects::ReloadConfig()
{
CBaseFeature::ReloadConfig();
std::string line = gConfig.ReadString("TABLE", "SoundEffects_BigVehicleModels", "");
std::string line = gConfig.ReadString("TABLE", "BigVehicleModels", gConfig.ReadString("TABLE", "SoundEffects_BigVehicleModels", ""));
ValidForReverseSound.clear();
Util::GetModelsFromIni(line, ValidForReverseSound);

bReverseSounds = gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalReverseSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalReverseSound", false));
bEngineSounds = gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalEngineSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalEngineSound", false));
bIndicatorSounds = gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalIndicatorSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalIndicatorSound", false));
bAirbreakSounds = gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalAirbreakSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalAirbreakSound", false));
bOnlyPlayerVehicle = !gConfig.ReadBoolean("SOUND", "SoundEffects_NonPlayerVehicles", gConfig.ReadBoolean("FEATURES", "SoundEffects_NonPlayerVehicles", false));
std::string chimeLine = gConfig.ReadString("TABLE", "DoorChime_VehicleModels", "");
ValidForDoorChime.clear();
Util::GetModelsFromIni(chimeLine, ValidForDoorChime);

bReverseSounds = gConfig.ReadBoolean("SOUND", "GlobalReverseSound", gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalReverseSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalReverseSound", false)));
bEngineSounds = gConfig.ReadBoolean("SOUND", "GlobalEngineSound", gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalEngineSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalEngineSound", false)));
bIndicatorSounds = gConfig.ReadBoolean("SOUND", "GlobalIndicatorSound", gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalIndicatorSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalIndicatorSound", false)));
bAirbreakSounds = gConfig.ReadBoolean("SOUND", "GlobalAirbreakSound", gConfig.ReadBoolean("SOUND", "SoundEffects_GlobalAirbreakSound", gConfig.ReadBoolean("FEATURES", "SoundEffects_GlobalAirbreakSound", false)));
bOnlyPlayerVehicle = !gConfig.ReadBoolean("SOUND", "NonPlayerVehicles", gConfig.ReadBoolean("SOUND", "SoundEffects_NonPlayerVehicles", gConfig.ReadBoolean("FEATURES", "SoundEffects_NonPlayerVehicles", false)));

bDoorChimeSounds = gConfig.ReadBoolean("SOUND", "DoorChimeSound", true);
bDoorChimeOnlySelected = gConfig.ReadBoolean("SOUND", "DoorChimeOnlySelected", true);
fDoorChimeVolume = std::clamp(gConfig.ReadFloat("SOUND", "DoorChimeVolume", 0.7f), 0.0f, 1.0f);
}

void SoundEffects::Reload(CVehicle *pVeh)
{
ReloadConfig();
if (pVeh)
{
auto &data = m_VehData.Get(pVeh);
if (data.m_hDoorChimeStream)
{
AudioMgr::StopLoopStream(data.m_hDoorChimeStream);
}
}
}

void SoundEffects::Init()
Expand All @@ -54,21 +95,25 @@ void SoundEffects::ProcessVehicle(CVehicle *pVeh)
return;
}
CPed *pPlayer = FindPlayerPed();
if (!pPlayer) {
auto &data = m_VehData.Get(pVeh);

if (!pPlayer || pVeh->m_fHealth <= 0.0f || pVeh->bEngineBroken || pVeh->bIsDrowning || MathUtil::DistanceSquared(pVeh->GetPosition(), pPlayer->GetPosition()) > (75.0f * 75.0f))
{
if (data.m_hDoorChimeStream)
{
AudioMgr::StopLoopStream(data.m_hDoorChimeStream);
}
return;
}
if (MathUtil::DistanceSquared(pVeh->GetPosition(), pPlayer->GetPosition()) > (75.0f * 75.0f)) {

if (bOnlyPlayerVehicle && pVeh->m_pDriver != pPlayer)
{
return;
}

if (bOnlyPlayerVehicle && pVeh->m_pDriver != pPlayer) {
return;
}

auto &data = m_VehData.Get(pVeh);
float speed = Util::GetVehicleSpeed(pVeh);
int model = pVeh->m_nModelIndex;
bool isPlayerDriver = (pVeh->m_pDriver == pPlayer);
float speed = Util::GetVehicleSpeed(pVeh);
int model = pVeh->m_nModelIndex;
bool isPlayerDriver = (pVeh->m_pDriver == pPlayer);

// Initialize previous state on first detection so newly seen running vehicles don't trigger sound
if (!data.m_bInitialized)
Expand Down Expand Up @@ -175,4 +220,46 @@ void SoundEffects::ProcessVehicle(CVehicle *pVeh)
}
}

if (bDoorChimeSounds && pVeh->m_nVehicleSubClass == VEHICLE_AUTOMOBILE)
{
CAutomobile *pAuto = static_cast<CAutomobile *>(pVeh);
bool isEligible = IsVehicleEligibleForDoorChime(model);
bool isFrontDoorOpen = false;

if (isEligible && !pVeh->bEngineBroken && !pVeh->bIsDrowning)
{
bool leftOpen = (!pAuto->m_doors[eDoors::DOOR_FRONT_LEFT].IsClosed() &&
std::abs(pAuto->m_doors[eDoors::DOOR_FRONT_LEFT].m_fAngle) > 0.15f);
bool rightOpen = (!pAuto->m_doors[eDoors::DOOR_FRONT_RIGHT].IsClosed() &&
std::abs(pAuto->m_doors[eDoors::DOOR_FRONT_RIGHT].m_fAngle) > 0.15f);

if (leftOpen || rightOpen)
{
if (isPlayerDriver || pVeh->bEngineOn || (pPlayer && MathUtil::DistanceSquared(pVeh->GetPosition(), pPlayer->GetPosition()) < (12.0f * 12.0f)))
{
isFrontDoorOpen = true;
}
}
}

if (isFrontDoorOpen)
{
static std::string chimePath = GetDoorChimeAudioPath();
if (!data.m_hDoorChimeStream)
{
data.m_hDoorChimeStream = AudioMgr::PlayLoopStream(chimePath, pVeh->GetPosition(), fDoorChimeVolume, 25.0f);
}
else
{
AudioMgr::UpdateLoopStream(data.m_hDoorChimeStream, pVeh->GetPosition(), fDoorChimeVolume, 25.0f);
}
}
else
{
if (data.m_hDoorChimeStream)
{
AudioMgr::StopLoopStream(data.m_hDoorChimeStream);
}
}
}
}
9 changes: 8 additions & 1 deletion src/features/soundeffects.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ struct SoundEffectsData
unsigned int m_nLastReverseSoundTime = 0;
float m_fBrakePressure = 0.0f;
float m_fMaxPedal = 0.0f;
StreamHandle m_hDoorChimeStream = 0;
SoundEffectsData(CVehicle *pVeh) {}
~SoundEffectsData() {}
~SoundEffectsData()
{
if (m_hDoorChimeStream)
{
AudioMgr::StopLoopStream(m_hDoorChimeStream);
}
}
};

class SoundEffects : public CVehFeature<SoundEffectsData>
Expand Down
2 changes: 1 addition & 1 deletion src/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void ModelExtras::Init()

for (CVehicle *pVeh : CPools::ms_pVehiclePool)
{
if (!pVeh || pVeh->m_fHealth <= 0.0f) continue;
if (!pVeh) continue;

for (auto *pFeature : s_ActiveVehicleFeatures)
{
Expand Down
Loading