diff --git a/src/xrCore/xr_ini.cpp b/src/xrCore/xr_ini.cpp index 1286e131ea2..0b25b4d1a74 100644 --- a/src/xrCore/xr_ini.cpp +++ b/src/xrCore/xr_ini.cpp @@ -752,6 +752,18 @@ pcstr CInifile::r_string(pcstr S, pcstr L) const return nullptr; } +pcstr CInifile::r_string_try(pcstr S, pcstr L) const +{ + Sect const& I = r_section(S); + auto A = std::lower_bound(I.Data.cbegin(), I.Data.cend(), L, item_pred); + + if (A != I.Data.cend() && xr_strcmp(*A->first, L) == 0) + return *A->second; + + Msg ("! Can't find variable '%s' in '[%s]'", L, S); + return nullptr; +} + shared_str CInifile::r_string_wb(pcstr S, pcstr L) const { pcstr _base = r_string(S, L); diff --git a/src/xrCore/xr_ini.h b/src/xrCore/xr_ini.h index 76add450d55..9eaecc8da5f 100644 --- a/src/xrCore/xr_ini.h +++ b/src/xrCore/xr_ini.h @@ -195,6 +195,7 @@ class XRCORE_API CInifile CLASS_ID r_clsid(pcstr S, pcstr L) const; CLASS_ID r_clsid(const shared_str& S, pcstr L) const { return r_clsid(*S, L); } pcstr r_string(pcstr S, pcstr L) const; // Left quotes in place + pcstr r_string_try(pcstr S, pcstr L) const; // Left quotes in place pcstr r_string(const shared_str& S, pcstr L) const { return r_string(*S, L); } // Left quotes in place shared_str r_string_wb(pcstr S, pcstr L) const; // Remove quotes shared_str r_string_wb(const shared_str& S, pcstr L) const { return r_string_wb(*S, L); } // Remove quotes diff --git a/src/xrGame/HudSound.cpp b/src/xrGame/HudSound.cpp index a8a14a4189d..0b44edeb0c1 100644 --- a/src/xrGame/HudSound.cpp +++ b/src/xrGame/HudSound.cpp @@ -259,6 +259,47 @@ void HUD_SOUND_COLLECTION_LAYERED::LoadSound(pcstr section, pcstr line, pcstr al } } +bool HUD_SOUND_COLLECTION_LAYERED::LoadSoundTry(pcstr section, pcstr line, pcstr alias, bool exclusive, int type) +{ + ZoneScoped; + + pcstr str = pSettings->r_string_try(section, line); + if(!str) + { + return false; + } + + string256 buf_str; + + int count = _GetItemCount(str); + R_ASSERT(count); + + _GetItem(str, 0, buf_str); + + if (pSettings->section_exist(buf_str)) + { + string256 sound_line; + xr_strcpy(sound_line,"snd_1_layer"); + int k = 1; + while (pSettings->line_exist(buf_str, sound_line)) + { + m_sound_layered_items.resize(m_sound_layered_items.size() + 1); + HUD_SOUND_COLLECTION& snd_item = m_sound_layered_items.back(); + snd_item.LoadSound(buf_str, sound_line, alias, exclusive, type); + snd_item.m_alias = alias; + xr_sprintf(sound_line,"snd_%d_layer", ++k); + } + } + else // For compatibility with normal HUD_SOUND_COLLECTION sounds + { + m_sound_layered_items.resize(m_sound_layered_items.size() + 1); + HUD_SOUND_COLLECTION& snd_item = m_sound_layered_items.back(); + snd_item.LoadSound(section, line, alias, exclusive, type); + snd_item.m_alias = alias; + } + return true; +} + void HUD_SOUND_COLLECTION_LAYERED::LoadSound(CInifile const *ini, pcstr section, pcstr line, pcstr alias, bool exclusive, int type) { ZoneScoped; diff --git a/src/xrGame/HudSound.h b/src/xrGame/HudSound.h index 7d5345aea5f..b938b828e54 100644 --- a/src/xrGame/HudSound.h +++ b/src/xrGame/HudSound.h @@ -89,6 +89,7 @@ class HUD_SOUND_COLLECTION_LAYERED void StopAllSounds(); void LoadSound(pcstr section, pcstr line, pcstr alias, bool exclusive = false, int type = sg_SourceType); + bool LoadSoundTry(LPCSTR section, LPCSTR line, LPCSTR alias, bool exclusive = false, int type = sg_SourceType); void LoadSound(CInifile const* ini, pcstr section, pcstr line, pcstr alias, bool exclusive = false, int type = sg_SourceType); diff --git a/src/xrGame/WeaponMagazined.cpp b/src/xrGame/WeaponMagazined.cpp index a6bad977fab..ebf2bb6a2fa 100644 --- a/src/xrGame/WeaponMagazined.cpp +++ b/src/xrGame/WeaponMagazined.cpp @@ -98,7 +98,10 @@ void CWeaponMagazined::Load(LPCSTR section) m_sSilencerSmokeParticles = pSettings->r_string(section, "silencer_smoke_particles"); //Alundaio: LAYERED_SND_SHOOT Silencer - m_layered_sounds.LoadSound(section, "snd_silncer_shot", "sndSilencerShot", false, m_eSoundShot); + if (!m_layered_sounds.LoadSoundTry(section, "snd_silncer_shot", "sndSilencerShot", false, m_eSoundShot)) + { + m_layered_sounds.LoadSound(section, "snd_shoot", "sndSilencerShot", false, m_eSoundShot); + } if (WeaponSoundExist(section, "snd_silncer_shot_actor")) m_layered_sounds.LoadSound(section, "snd_silncer_shot_actor", "sndSilencerShotActor", false, m_eSoundShot); //-Alundaio