Skip to content

Commit

Permalink
Merge pull request #2515 from KABoissonneault/feat/custom-sounds
Browse files Browse the repository at this point in the history
Allow custom sound indices in SoundReader.GetAudioClip.
  • Loading branch information
Interkarma authored Jun 18, 2023
2 parents 1f2214a + 8a771c4 commit 2b150e8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions Assets/Scripts/API/BsaFile.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Project: Daggerfall Unity
// Project: Daggerfall Unity
// Copyright: Copyright (C) 2009-2022 Daggerfall Workshop
// Web Site: http://www.dfworkshop.net
// License: MIT License (http://www.opensource.org/licenses/mit-license.php)
Expand Down Expand Up @@ -208,7 +208,7 @@ public int GetRecordIndex(string name)
public int GetRecordLength(int record)
{
// Validate
if (record >= header.DirectoryCount)
if (record < 0 || record >= header.DirectoryCount)
return 0;

// Return length of this record
Expand All @@ -231,7 +231,7 @@ public int GetRecordLength(int record)
public string GetRecordName(int record)
{
// Validate
if (record >= header.DirectoryCount)
if (record < 0 || record >= header.DirectoryCount)
return string.Empty;

// Return name of this record
Expand All @@ -254,7 +254,7 @@ public string GetRecordName(int record)
public uint GetRecordId(int record)
{
// Validate
if (record >= header.DirectoryCount || header.DirectoryType != DirectoryTypes.NumberRecord)
if (record < 0 || record >= header.DirectoryCount || header.DirectoryType != DirectoryTypes.NumberRecord)
return 0;

return numberRecordDirectory[record].RecordId;
Expand All @@ -268,7 +268,7 @@ public uint GetRecordId(int record)
public byte[] GetRecordBytes(int record)
{
// Validate
if (record >= header.DirectoryCount)
if (record < 0 || record >= header.DirectoryCount)
return null;

// Read record data into buffer
Expand Down
8 changes: 6 additions & 2 deletions Assets/Scripts/SoundReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public AudioClip GetAudioClip(int soundIndex)
{
const float divisor = 1.0f / 128.0f;

// Must be ready and have a valid input index
if (!ReadyCheck() || !soundFile.IsValidIndex(soundIndex))
// Must be ready
if (!ReadyCheck())
return null;

// Look for clip in cache
Expand All @@ -78,6 +78,10 @@ public AudioClip GetAudioClip(int soundIndex)
}
else
{
// Must have a valid index
if (!soundFile.IsValidIndex(soundIndex))
return null;

// Get sound data
DFSound dfSound;
if (!soundFile.GetSound(soundIndex, out dfSound))
Expand Down

0 comments on commit 2b150e8

Please sign in to comment.