71 size_t entryCount, offEntryTable;
79 e.
add(
"Failed reading SSF file");
85 size_t &entryCount,
size_t &offEntryTable) {
105 if ((offEntryTable < ssf.
size()) && ((ssf.
size() - offEntryTable) >= ((4 + 32 + 4) * entryCount)))
108 offEntryTable = entryCount;
109 entryCount = (ssf.
size() - offEntryTable) / 4;
112 if ((offEntryTable > ssf.
size()) || (((ssf.
size() - offEntryTable) % 4) != 0))
147 std::vector<uint32> offsets;
149 offsets.resize(count);
151 for (
size_t i = 0; i < count; i++)
154 for (
size_t i = 0; i < count; i++) {
155 ssf.
seek(offsets[i]);
165 for (SoundSet::iterator sound =
_sounds.begin(); sound !=
_sounds.end(); ++sound)
179 return _sounds[index].soundFile;
197 soundFile =
_sounds[index].soundFile;
198 strRef =
_sounds[index].strRef;
208 _sounds[index].soundFile = soundFile;
218 _sounds[index].strRef = strRef;
228 _sounds[index].soundFile = soundFile;
229 _sounds[index].strRef = strRef;
233 size_t maxSoundFileLen = 0;
234 for (SoundSet::const_iterator s =
_sounds.begin(); s !=
_sounds.end(); ++s)
235 maxSoundFileLen =
MAX(maxSoundFileLen, s->soundFile.size());
237 return maxSoundFileLen;
241 for (SoundSet::const_iterator s =
_sounds.begin(); s !=
_sounds.end(); ++s)
260 throw Common::Exception(
"Sound filenames in SSF V1.0 need to be 16 characters or less");
265 throw Common::Exception(
"Sound filenames in SSF V1.1 (NWN2) need to be 32 characters or less");
270 throw Common::Exception(
"SSF V1.1 (KotOR/KotOR2) does not support sound filenames");
319 if (!file.
open(fileName))
329 static const size_t kOffsetEntryTable = 0x28;
335 for (
size_t i = 16; i < kOffsetEntryTable; i++)
338 size_t offsetData = kOffsetEntryTable +
_sounds.size() * 4;
340 for (SoundSet::const_iterator s =
_sounds.begin(); s !=
_sounds.end();
341 ++s, offsetData += soundFileLen + 4) {
349 for (SoundSet::const_iterator s =
_sounds.begin(); s !=
_sounds.end(); ++s) {
373 for (SoundSet::const_iterator s =
_sounds.begin(); s !=
_sounds.end(); ++s)
#define ResMan
Shortcut for accessing the sound manager.
void setStrRef(size_t index, uint32 strRef)
Set the string reference of the text to display for this sound.
Version determineVersionForGame(GameID game) const
Determine the best version to save this SSF file in, for the specified game.
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
const Common::UString & getSoundFile(size_t index) const
Return the sound file to play for this sound.
Version readSSFHeader(Common::SeekableReadStream &ssf, size_t &entryCount, size_t &offEntryTable)
Read the header of an SSF file and determine the version.
Handling BioWare's SSFs (sound set file).
void add(const char *s,...) GCC_PRINTF(2
uint32 readUint32LE()
Read an unsigned 32-bit word stored in little endian (LSB first) order from the stream and return it...
A class holding an UTF-8 string.
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
void writeString(const UString &str)
Write the given string to the stream, encoded as UTF-8.
Version
The different versions of SSF files that exists.
size_t getMaxSoundFileLen() const
Return the maximum length of a sound filename in characters.
static const uint32 kVersion10
Utility templates and functions for working with strings and streams.
Exception that provides a stack of explanations.
static void readHeader(Common::ReadStream &stream, uint32 &id, uint32 &version, bool &utf16le)
Read the header out of a stream.
A simple scoped smart pointer template.
void setSoundFile(size_t index, const Common::UString &soundFile)
Set the sound file to play for this sound.
SSF V1.0, as found in NWN and NWN2.
Basic exceptions to throw.
static const uint32 kSSFID
utf8::iterator< std::string::const_iterator > iterator
const char * c_str() const
Return the (utf8 encoded) string data.
bool open(const UString &fileName)
Try to open the file with the given fileName.
void load(Common::SeekableReadStream &ssf)
Star Wars: Knights of the Old Republic.
Utility templates and functions.
void writeSSF(Common::WriteStream &out, Version version) const
Write the SSF into a stream, as the specified version.
Basic writing stream interfaces.
void writeKotOR(Common::WriteStream &out) const
Write this SSF into a stream as a V1.1 (KotOR/KotOR2).
static const uint32 kStrRefInvalid
SSF V1.1, as found in KotOR and KotOR.
Utility functions for working with differing string encodings.
uint32 _id
The file's ID.
static const uint32 kVersion11
uint32 _version
The file's version.
void writeByte(byte value)
virtual size_t size() const =0
Obtains the total size of the stream, measured in bytes.
Basic reading stream interfaces.
Generic interface for a writable data stream.
void readEntriesKotOR(Common::SeekableReadStream &ssf)
Read the data entries of the KotOR version.
void readEntries(Common::SeekableReadStream &ssf, Version version, size_t offset)
Read the data entries, depending on the version.
void writeNWN2(Common::WriteStream &out) const
Write this SSF into a stream as a V1.1 (NWN2).
Plain, unextended ASCII (7bit clean).
Sound(const Common::UString &f="", uint32 s=kStrRefInvalid)
void close()
Close the file, if open.
static bool isASCII(uint32 c)
Is the character an ASCII character?
const Exception kSeekError("Seek error")
Exception when seeking a stream failed.
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
static const uint32 kVersion10
Implementing the stream writing interfaces for files.
void setSound(size_t index, const Common::UString &soundFile, uint32 strRef)
Set both the sound file and the string reference for this sound.
void checkVersionFeatures(Version version) const
Make sure this SSF files fits the requirements for specified SSF version.
SSF V1.1, as found in NWN2.
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
static const Common::UString kEmptyString
void readEntriesNWN(Common::SeekableReadStream &ssf, size_t soundFileLen)
Read the data entries of the NWN versions.
void getSound(size_t index, Common::UString &soundFile, uint32 &strRef) const
Return both the sound file and the string reference for this sound.
Star Wars: Knights of the Old Republic II - The Sith Lords.
A simple streaming file writing class.
void clear()
Clear the string's contents.
Interface for a seekable & readable data stream.
void writeUint32LE(uint32 value)
The global resource manager for Aurora resources.
size_t getSoundCount() const
Return the number of sounds in this SSF file.
bool existNonASCIISoundFile() const
Is there a sound filename with non-ASCII characters?
uint32 getStrRef(size_t index) const
Return the string reference of the text to display for this sound.
void writeNWN(Common::WriteStream &out) const
Write this SSF into a stream as a V1.0 (NWN).
void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length)
Write a string into a stream with a given encoding and fixed length in bytes.