diff --git a/Assets/Scripts/API/BsaFile.cs b/Assets/Scripts/API/BsaFile.cs index c72176b003..99efe27749 100644 --- a/Assets/Scripts/API/BsaFile.cs +++ b/Assets/Scripts/API/BsaFile.cs @@ -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) @@ -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 @@ -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 @@ -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; @@ -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 diff --git a/Assets/Scripts/SoundReader.cs b/Assets/Scripts/SoundReader.cs index 7df8ea4309..ca3a80aa32 100644 --- a/Assets/Scripts/SoundReader.cs +++ b/Assets/Scripts/SoundReader.cs @@ -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 @@ -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))