xoreos  0.0.5
aurorafile.cpp
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 #include "src/common/readstream.h"
26 
27 #include "src/aurora/aurorafile.h"
28 
29 namespace Aurora {
30 
32  clear();
33 }
34 
36  _id = 0;
37  _version = 0;
38  _utf16le = false;
39 }
40 
42  return _id;
43 }
44 
46  return _version;
47 }
48 
49 bool AuroraFile::isUTF16LE() const {
50  return _utf16le;
51 }
52 
53 void AuroraFile::readHeader(Common::ReadStream &stream, uint32 &id, uint32 &version, bool &utf16le) {
54  id = stream.readUint32BE();
55  version = stream.readUint32BE();
56 
57  if (((id & 0x00FF00FF) == 0) && ((version & 0x00FF00FF) == 0)) {
58  // There's 0-bytes in the ID and version, this looks like little-endian UTF-16
59 
60  utf16le = true;
61 
62  id = convertUTF16LE(id, version);
63 
64  uint32 version1 = stream.readUint32BE();
65  uint32 version2 = stream.readUint32BE();
66 
67  version = convertUTF16LE(version1, version2);
68  } else
69  utf16le = false;
70 }
71 
73  bool utf16le;
74  readHeader(stream, id, version, utf16le);
75 }
76 
78  uint32 id, version;
79  readHeader(stream, id, version);
80 
81  return id;
82 }
83 
85  readHeader(stream, _id, _version, _utf16le);
86 }
87 
89  // Take 8 byte and remove every second byte
90 
91  return ((x1 & 0xFF000000) ) | ((x1 & 0x0000FF00) << 8) |
92  ((x2 & 0xFF000000) >> 16) | ((x2 & 0x0000FF00) >> 8);
93 }
94 
95 } // End of namespace Aurora
Generic interface for a readable data stream.
Definition: readstream.h:64
bool _utf16le
The file&#39;s ID and version are in little-endian UTF-16.
Definition: aurorafile.h:79
uint32 getVersion() const
Return the file&#39;s version.
Definition: aurorafile.cpp:45
static void readHeader(Common::ReadStream &stream, uint32 &id, uint32 &version, bool &utf16le)
Read the header out of a stream.
Definition: aurorafile.cpp:53
Base for BioWare&#39;s Aurora engine files.
uint32 _id
The file&#39;s ID.
Definition: aurorafile.h:77
uint32 _version
The file&#39;s version.
Definition: aurorafile.h:78
static uint32 convertUTF16LE(uint32 x1, uint32 x2)
Definition: aurorafile.cpp:88
Basic reading stream interfaces.
uint32 readUint32BE()
Read an unsigned 32-bit word stored in big endian (MSB first) order from the stream and return it...
Definition: readstream.h:166
uint32_t uint32
Definition: types.h:204
static uint32 readHeaderID(Common::ReadStream &stream)
Read the ID out of a stream.
Definition: aurorafile.cpp:77
bool isUTF16LE() const
Were the ID and version encoded in little-endian UTF-16 in the file?
Definition: aurorafile.cpp:49
uint32 getID() const
Return the file&#39;s ID.
Definition: aurorafile.cpp:41