Skip to content

Commit

Permalink
Clear Sky: Crash when some weapons(eg. wpn_val) with built in suppres…
Browse files Browse the repository at this point in the history
…sor don't have snd_silncer_shot only snd_shoot
  • Loading branch information
sobkas committed May 20, 2024
1 parent f3383c2 commit 3508daa
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/xrCore/xr_ini.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/xrCore/xr_ini.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions src/xrGame/HudSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/xrGame/HudSound.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 4 additions & 1 deletion src/xrGame/WeaponMagazined.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3508daa

Please sign in to comment.