75 _repairNWNPremium(repairNWNPremium), _offsetCorrection(0) {
105 e.
add(
"Failed reading GFF3 file");
127 if ((firstOffset >= 0x30) && (firstOffset <= 0x12F)) {
130 id =
_id = 0xFFFFFFFF;
148 if ((
id != 0xFFFFFFFF) && (
_id !=
id))
165 throw Common::Exception(
"GFF3 header broken: section offset smaller than offset correction");
180 throw Common::Exception(
"GFF3 header broken: section offset points outside stream");
184 static const uint32 kStructSize = 12;
210 std::vector<uint32> rawLists;
212 for (std::vector<uint32>::iterator it = rawLists.begin(); it != rawLists.end(); ++it)
217 for (
size_t i = 0; i < rawLists.size(); i++) {
220 if ((i + n) > rawLists.size())
232 for (
size_t i = 0; i < rawLists.size(); listIndex++) {
235 const uint32 n = rawLists[i++];
236 if ((i + n) > rawLists.size())
239 _lists[listIndex].resize(n);
240 for (
uint32 j = 0; j < n; j++, i++) {
241 const size_t structIndex = rawLists[i];
267 if (listIndex == 0xFFFFFFFF)
270 assert(listIndex <
_lists.size());
364 std::vector<uint32> indices;
368 for (std::vector<uint32>::const_iterator i = indices.begin(); i != indices.end(); ++i)
373 std::vector<uint32> &indices,
uint32 count)
const {
374 indices.reserve(count);
419 FieldMap::const_iterator field =
_fields.find(name);
423 return &field->second;
433 return (
char) f->
data;
511 return getUint(field, def) != 0;
592 float x = 0.0, y = 0.0, z = 0.0;
602 float a = 0.0, b = 0.0, c = 0.0, d = 0.0;
661 float &x,
float &y,
float &z)
const {
677 float &a,
float &b,
float &c,
float &d)
const {
694 double &x,
double &y,
double &z)
const {
710 double &a,
double &b,
double &c,
double &d)
const {
Header _header
The GFF3's header.
int64 getSint(const Common::UString &field, int64 def=0) const
Handling version V3.2/V3.3 of BioWare's GFFs (generic file format).
#define ResMan
Shortcut for accessing the sound manager.
#define MKTAG(a0, a1, a2, a3)
A wrapper macro used around four character constants, like 'DATA', to ensure portability.
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...
bool _repairNWNPremium
Should we try to read GFF3 files found in Neverwinter Nights premium modules?
#define TypeMan
Shortcut for accessing the file type manager.
std::vector< uint32 > _listOffsetToIndex
To convert list offsets found in GFF3 to real indices.
const GFF3List & getList(uint32 i) const
Return a list within the GFF3.
bool getBool(const Common::UString &field, bool def=false) const
bool getLocString(const Common::UString &field, LocString &str) const
void readFields(Common::SeekableReadStream &data, uint32 index, uint32 count)
A class holding an UTF-8 string.
void loadHeader(uint32 id)
virtual size_t seek(ptrdiff_t offset, Origin whence=kOriginBegin)=0
Sets the stream position indicator for the stream.
void reset(PointerType o=0)
Resets the pointer with the new value.
const GFF3Struct & getStruct(uint32 i) const
Return a struct within the GFF3.
MemoryReadStream * readStream(size_t dataSize)
Read the specified amount of data into a new[]'ed buffer which then is wrapped into a MemoryReadStrea...
uint32 _fieldIndex
Field / Field indices index.
void readLocString(Common::SeekableReadStream &stream, uint32 id, uint32 count)
Read a LocString out of a stream.
UString composeString(T value)
Convert any POD integer, float/double or bool type into a string.
uint32 getID() const
Return the struct's ID.
const GFF3File * _parent
The parent GFF3.
bool hasField(const Common::UString &field) const
Does this specific field exist?
String reference, index into a talk table.
void getOrientation(const Common::UString &field, float &a, float &b, float &c, float &d) const
Implementing the reading stream interfaces for plain memory blocks.
Utility functions to handle files used in BioWare's Aurora engine.
StructArray _structs
Our structs.
char getChar(const Common::UString &field, char def='\0') const
const GFF3Struct & getTopLevel() const
Returns the top-level struct.
uint64 getUint(const Common::UString &field, uint64 def=0) const
FieldType getFieldType(const Common::UString &field) const
Return the type of this field, or kFieldTypeNone if such a field doesn't exist.
static const uint32 kVersion32
FieldType type
Type of the field.
Utility templates and functions for working with strings and streams.
FieldMap _fields
The fields, indexed by their label.
const Common::UString & getString(Language language, LanguageGender gender=kLanguageGenderCurrent) const
Get the string of that language.
uint32 data
Data of the field.
Exception that provides a stack of explanations.
FieldType
The type of a GFF3 field.
static void readHeader(Common::ReadStream &stream, uint32 &id, uint32 &version, bool &utf16le)
Read the header out of a stream.
Common::SeekableReadStream & getStream(uint32 offset) const
Return the GFF3 stream.
Basic exceptions to throw.
void getVector(const Common::UString &field, float &x, float &y, float &z) const
Random data of variable length.
double getDouble(const Common::UString &field, double def=0.0) const
void swap(LocString &str)
Swap the contents of the LocString with this LocString's.
A GFF (generic file format) V3.2/V3.3 file, found in all Aurora games except Sonic Chronicles: The Da...
virtual size_t skip(ptrdiff_t offset)
Skip the specified number of bytes, adding that offset to the current position in the stream...
Utility functions for working with differing string encodings.
uint32 _id
The file's ID.
uint32 _version
The file's version.
uint32 _fieldCount
Field count.
Handling BioWare's localized strings.
virtual size_t pos() const =0
Obtains the current value of the stream position indicator of the stream.
uint32 getType() const
Return the GFF3's specific type.
uint64 readUint64LE()
Read an unsigned 64-bit word stored in little endian (LSB first) order from the stream and return it...
std::vector< const GFF3Struct * > GFF3List
uint32 _id
The struct's ID.
uint32 _offsetCorrection
The correctional value for offsets to repair Neverwinter Nights premium modules.
FORCEINLINE float readIEEEFloatLE()
Read a 32-bit IEEE float stored in little endian (LSB first) order from the stream and return it...
Plain, unextended ASCII (7bit clean).
ListArray _lists
Our lists.
const GFF3List & getList(const Common::UString &field) const
Common::SeekableReadStream & getFieldData() const
Return the GFF3 stream seeked to the start of the field data.
A field in the GFF3 struct.
static const uint32 kVersion33
float convertIEEEFloat(uint32 data)
Convert a uint32 holding the bit pattern of a 32-bit IEEE 754 single precision floating point value i...
std::vector< Common::UString > _fieldNames
The names of all fields in this struct.
Resource reference, string.
const GFF3Struct & getStruct(const Common::UString &field) const
UString debugTag(uint32 tag, bool trim)
Create an elaborate string from an integer tag, for debugging purposes.
size_t getFieldCount() const
Return the number of fields in this struct.
FORCEINLINE double readIEEEDoubleLE()
Read a 64-bit IEEE double stored in little endian (LSB first) order from the stream and return it...
FileType
Various file types used by the Aurora engine and found in archives.
Common::SeekableReadStream * getData(const Common::UString &field) const
GFF3Struct(const GFF3File &parent, uint32 offset)
Common::ScopedPtr< Common::SeekableReadStream > _stream
List containing a number of structs.
Common::UString getString(const Common::UString &field, const Common::UString &def="") const
Struct containing a number of fields.
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
void readIndices(Common::SeekableReadStream &data, std::vector< uint32 > &indices, uint32 count) const
SeekableSubReadStream provides access to a SeekableReadStream restricted to the range [begin...
GFF3File(Common::SeekableReadStream *gff3, uint32 id=0xFFFFFFFF, bool repairNWNPremium=false)
Take over this stream and read a GFF3 file out of it.
void readField(Common::SeekableReadStream &data, uint32 index)
bool extended
Does this field need extended data?
Interface for a seekable & readable data stream.
const Field * getField(const Common::UString &name) const
Returns the field with this tag.
byte readByte()
Read an unsigned byte from the stream and return it.
const std::vector< Common::UString > & getFieldNames() const
Return a list of all field names in this struct.
The global resource manager for Aurora resources.
Common::UString readLabel(Common::SeekableReadStream &data, uint32 index) const