xoreos  0.0.5
ssffile.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef AURORA_SSFFILE_H
26 #define AURORA_SSFFILE_H
27 
28 #include <vector>
29 
30 #include "src/common/types.h"
31 #include "src/common/ustring.h"
32 
33 #include "src/aurora/types.h"
34 #include "src/aurora/aurorafile.h"
35 
36 namespace Common {
37  class SeekableReadStream;
38  class WriteStream;
39 }
40 
41 namespace Aurora {
42 
55 class SSFFile : public AuroraFile {
56 public:
58  enum Version {
62  };
63 
64  SSFFile();
66  SSFFile(const Common::UString &ssf);
67  ~SSFFile();
68 
70  size_t getSoundCount() const;
71 
72  // .--- Reading sounds from the sound set
74  const Common::UString &getSoundFile(size_t index) const;
76  uint32 getStrRef(size_t index) const;
78  void getSound(size_t index, Common::UString &soundFile, uint32 &strRef) const;
79  // '---
80 
81  // .--- Writing sounds to the sound set
83  void setSoundFile(size_t index, const Common::UString &soundFile);
85  void setStrRef(size_t index, uint32 strRef);
87  void setSound(size_t index, const Common::UString &soundFile, uint32 strRef);
88  // '---
89 
90  // .--- Writing SSF files
93 
95  void writeSSF(Common::WriteStream &out, Version version) const;
97  bool writeSSF(const Common::UString &fileName, Version version) const;
98  // '---
99 
100 private:
102  struct Sound {
105 
106  Sound(const Common::UString &f = "", uint32 s = kStrRefInvalid);
107  };
108 
109  typedef std::vector<Sound> SoundSet;
110 
112 
113  void load(Common::SeekableReadStream &ssf);
114 
116  Version readSSFHeader(Common::SeekableReadStream &ssf, size_t &entryCount, size_t &offEntryTable);
117 
119  void readEntries(Common::SeekableReadStream &ssf, Version version, size_t offset);
121  void readEntriesNWN(Common::SeekableReadStream &ssf, size_t soundFileLen);
124 
126  size_t getMaxSoundFileLen() const;
128  bool existNonASCIISoundFile() const;
130  void checkVersionFeatures(Version version) const;
131 
133  void writeNWN(Common::WriteStream &out) const;
135  void writeNWN2(Common::WriteStream &out) const;
137  void writeKotOR(Common::WriteStream &out) const;
138 
140  void writeNWN(Common::WriteStream &out, size_t soundFileLen) const;
141 };
142 
143 } // End of namespace Aurora
144 
145 #endif // AURORA_SSFFILE_H
void setStrRef(size_t index, uint32 strRef)
Set the string reference of the text to display for this sound.
Definition: ssffile.cpp:211
Version determineVersionForGame(GameID game) const
Determine the best version to save this SSF file in, for the specified game.
Definition: ssffile.cpp:278
const Common::UString & getSoundFile(size_t index) const
Return the sound file to play for this sound.
Definition: ssffile.cpp:173
Version readSSFHeader(Common::SeekableReadStream &ssf, size_t &entryCount, size_t &offEntryTable)
Read the header of an SSF file and determine the version.
Definition: ssffile.cpp:84
GameID
Definition: types.h:393
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
Class to hold a sound set.
Definition: ssffile.h:55
size_t getMaxSoundFileLen() const
Return the maximum length of a sound filename in characters.
Definition: ssffile.cpp:232
void setSoundFile(size_t index, const Common::UString &soundFile)
Set the sound file to play for this sound.
Definition: ssffile.cpp:201
Definition: game.h:37
SSF V1.0, as found in NWN and NWN2.
Definition: ssffile.h:59
void load(Common::SeekableReadStream &ssf)
Definition: ssffile.cpp:69
uint32 strRef
StrRef of the text to display.
Definition: ssffile.h:104
void writeSSF(Common::WriteStream &out, Version version) const
Write the SSF into a stream, as the specified version.
Definition: ssffile.cpp:299
SoundSet _sounds
Definition: ssffile.h:111
Common::UString soundFile
The name of the sound file to play.
Definition: ssffile.h:103
Base for BioWare&#39;s Aurora engine files.
void writeKotOR(Common::WriteStream &out) const
Write this SSF into a stream as a V1.1 (KotOR/KotOR2).
Definition: ssffile.cpp:368
static const uint32 kStrRefInvalid
Definition: types.h:444
SSF V1.1, as found in KotOR and KotOR.
Definition: ssffile.h:61
Low-level type definitions to handle fixed width types portably.
Generic interface for a writable data stream.
Definition: writestream.h:64
void readEntriesKotOR(Common::SeekableReadStream &ssf)
Read the data entries of the KotOR version.
Definition: ssffile.cpp:162
void readEntries(Common::SeekableReadStream &ssf, Version version, size_t offset)
Read the data entries, depending on the version.
Definition: ssffile.cpp:119
void writeNWN2(Common::WriteStream &out) const
Write this SSF into a stream as a V1.1 (NWN2).
Definition: ssffile.cpp:362
Unicode string handling.
std::vector< Sound > SoundSet
Definition: ssffile.h:109
Basic type definitions to handle files used in BioWare&#39;s Aurora engine.
Sound(const Common::UString &f="", uint32 s=kStrRefInvalid)
Definition: ssffile.cpp:47
uint32_t uint32
Definition: types.h:204
Base class for most files found in games using BioWare&#39;s Aurora engine.
Definition: aurorafile.h:52
void setSound(size_t index, const Common::UString &soundFile, uint32 strRef)
Set both the sound file and the string reference for this sound.
Definition: ssffile.cpp:221
void checkVersionFeatures(Version version) const
Make sure this SSF files fits the requirements for specified SSF version.
Definition: ssffile.cpp:249
SSF V1.1, as found in NWN2.
Definition: ssffile.h:60
void readEntriesNWN(Common::SeekableReadStream &ssf, size_t soundFileLen)
Read the data entries of the NWN versions.
Definition: ssffile.cpp:140
void getSound(size_t index, Common::UString &soundFile, uint32 &strRef) const
Return both the sound file and the string reference for this sound.
Definition: ssffile.cpp:189
Interface for a seekable & readable data stream.
Definition: readstream.h:265
size_t getSoundCount() const
Return the number of sounds in this SSF file.
Definition: ssffile.cpp:169
bool existNonASCIISoundFile() const
Is there a sound filename with non-ASCII characters?
Definition: ssffile.cpp:240
uint32 getStrRef(size_t index) const
Return the string reference of the text to display for this sound.
Definition: ssffile.cpp:182
void writeNWN(Common::WriteStream &out) const
Write this SSF into a stream as a V1.0 (NWN).
Definition: ssffile.cpp:356