2014-08-24 17:27:09 +00:00
|
|
|
///Main header for reading .nif files
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2013-02-24 21:51:56 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
|
|
|
#define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2010-09-02 20:30:39 +00:00
|
|
|
#include <stdexcept>
|
2010-01-04 13:48:18 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2018-08-14 15:42:41 +00:00
|
|
|
#include <components/debug/debuglog.hpp>
|
2015-02-17 16:08:55 +00:00
|
|
|
#include <components/files/constrainedfilestream.hpp>
|
|
|
|
|
2010-06-03 18:44:55 +00:00
|
|
|
#include "record.hpp"
|
2010-01-04 18:35:11 +00:00
|
|
|
|
2010-01-06 11:28:37 +00:00
|
|
|
namespace Nif
|
|
|
|
{
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
struct File
|
|
|
|
{
|
|
|
|
virtual ~File() = default;
|
|
|
|
|
|
|
|
virtual Record *getRecord(size_t index) const = 0;
|
|
|
|
|
|
|
|
virtual size_t numRecords() const = 0;
|
|
|
|
|
|
|
|
virtual Record *getRoot(size_t index = 0) const = 0;
|
|
|
|
|
|
|
|
virtual size_t numRoots() const = 0;
|
|
|
|
|
2019-12-29 12:53:44 +00:00
|
|
|
virtual std::string getString(size_t index) const = 0;
|
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
virtual void setUseSkinning(bool skinning) = 0;
|
|
|
|
|
|
|
|
virtual bool getUseSkinning() const = 0;
|
|
|
|
|
|
|
|
virtual std::string getFilename() const = 0;
|
2019-12-29 12:53:44 +00:00
|
|
|
|
|
|
|
virtual unsigned int getVersion() const = 0;
|
|
|
|
|
|
|
|
virtual unsigned int getUserVersion() const = 0;
|
|
|
|
|
|
|
|
virtual unsigned int getBethVersion() const = 0;
|
2018-07-08 19:22:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class NIFFile final : public File
|
2010-01-04 13:48:18 +00:00
|
|
|
{
|
2019-12-29 12:53:44 +00:00
|
|
|
/// File version, user version, Bethesda version
|
|
|
|
unsigned int ver = 0;
|
|
|
|
unsigned int userVer = 0;
|
|
|
|
unsigned int bethVer = 0;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// File name, used for error messages and opening the file
|
2012-07-03 04:41:21 +00:00
|
|
|
std::string filename;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Record list
|
|
|
|
std::vector<Record*> records;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Root list. This is a select portion of the pointers from records
|
2013-04-06 17:17:09 +00:00
|
|
|
std::vector<Record*> roots;
|
|
|
|
|
2019-12-29 12:53:44 +00:00
|
|
|
/// String table
|
|
|
|
std::vector<std::string> strings;
|
|
|
|
|
|
|
|
bool mUseSkinning = false;
|
2015-03-25 14:39:41 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Parse the file
|
2015-12-09 03:50:59 +00:00
|
|
|
void parse(Files::IStreamPtr stream);
|
2010-01-07 18:11:03 +00:00
|
|
|
|
2014-10-19 06:54:27 +00:00
|
|
|
/// Get the file's version in a human readable form
|
|
|
|
///\returns A string containing a human readable NIF version number
|
|
|
|
std::string printVersion(unsigned int version);
|
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
///Private Copy Constructor
|
2013-01-05 18:58:50 +00:00
|
|
|
NIFFile (NIFFile const &);
|
2014-08-24 17:27:09 +00:00
|
|
|
///\overload
|
2013-01-05 18:58:50 +00:00
|
|
|
void operator = (NIFFile const &);
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
public:
|
2019-12-29 12:53:44 +00:00
|
|
|
enum NIFVersion
|
|
|
|
{
|
|
|
|
// Feature-relevant
|
|
|
|
VER_4_1_0_0 = 0x04010000, // 1-byte booleans (previously 4-byte)
|
|
|
|
VER_5_0_0_1 = 0x05000001, // Optimized record type listings
|
|
|
|
VER_5_0_0_6 = 0x05000006, // Record groups
|
|
|
|
VER_10_0_1_8 = 0x0A000108, // The last version without user version
|
|
|
|
VER_20_1_0_1 = 0x14010001, // String tables
|
|
|
|
VER_20_2_0_5 = 0x14020005, // Record sizes
|
|
|
|
// Game-relevant
|
|
|
|
VER_4_0_0_0 = 0x04000000, // Freedom Force NIFs, supported by Morrowind
|
|
|
|
VER_MW = 0x04000002, // 4.0.0.2. Morrowind and Freedom Force NIFs
|
|
|
|
VER_4_2_1_0 = 0x04020100, // Used in Civ4 and Dark Age of Camelot
|
|
|
|
VER_CI = 0x04020200, // 4.2.2.0. Main Culpa Innata NIF version, also used in Civ4
|
|
|
|
VER_ZT2 = 0x0A000100, // 10.0.1.0. Main Zoo Tycoon 2 NIF version, also used in Oblivion and Civ4
|
|
|
|
VER_OB_OLD = 0x0A000102, // 10.0.1.2. Main older Oblivion NIF version
|
|
|
|
VER_GAMEBRYO = 0x0A010000, // 10.1.0.0. Lots of games use it. The first version that has Gamebryo File Format header.
|
|
|
|
VER_10_2_0_0 = 0x0A020000, // Lots of games use this version as well.
|
|
|
|
VER_CIV4 = 0x14000004, // 20.0.0.4. Main Civilization IV NIF version.
|
|
|
|
VER_OB = 0x14000005, // 20.0.0.5. Main Oblivion NIF version
|
|
|
|
VER_BGS = 0x14020007 // 20.2.0.7. Main Fallout 3/4/76/New Vegas and Skyrim/SkyrimSE NIF version.
|
|
|
|
};
|
|
|
|
enum BethVersion
|
|
|
|
{
|
|
|
|
BETHVER_FO3 = 34, // Fallout 3
|
|
|
|
BETHVER_FO4 = 130 // Fallout 4
|
|
|
|
};
|
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Used if file parsing fails
|
2018-11-08 17:10:23 +00:00
|
|
|
void fail(const std::string &msg) const
|
2010-01-04 13:48:18 +00:00
|
|
|
{
|
2014-12-12 06:36:10 +00:00
|
|
|
std::string err = " NIFFile Error: " + msg;
|
2012-07-03 04:41:21 +00:00
|
|
|
err += "\nFile: " + filename;
|
|
|
|
throw std::runtime_error(err);
|
2010-01-04 13:48:18 +00:00
|
|
|
}
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Used when something goes wrong, but not catastrophically so
|
2018-11-08 17:10:23 +00:00
|
|
|
void warn(const std::string &msg) const
|
2012-07-12 13:47:38 +00:00
|
|
|
{
|
2018-08-14 15:42:41 +00:00
|
|
|
Log(Debug::Warning) << " NIFFile Warning: " << msg << "\nFile: " << filename;
|
2012-07-12 13:47:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 16:08:55 +00:00
|
|
|
/// Open a NIF stream. The name is used for error messages.
|
|
|
|
NIFFile(Files::IStreamPtr stream, const std::string &name);
|
2013-01-05 18:58:50 +00:00
|
|
|
~NIFFile();
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Get a given record
|
2018-07-08 19:22:34 +00:00
|
|
|
Record *getRecord(size_t index) const override
|
2012-07-03 04:41:21 +00:00
|
|
|
{
|
|
|
|
Record *res = records.at(index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/// Number of records
|
2018-07-08 19:22:34 +00:00
|
|
|
size_t numRecords() const override { return records.size(); }
|
2013-04-06 17:17:09 +00:00
|
|
|
|
|
|
|
/// Get a given root
|
2018-07-08 19:22:34 +00:00
|
|
|
Record *getRoot(size_t index=0) const override
|
2013-04-06 17:17:09 +00:00
|
|
|
{
|
|
|
|
Record *res = roots.at(index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/// Number of roots
|
2018-07-08 19:22:34 +00:00
|
|
|
size_t numRoots() const override { return roots.size(); }
|
2014-10-19 06:40:18 +00:00
|
|
|
|
2019-12-29 12:53:44 +00:00
|
|
|
/// Get a given string from the file's string table
|
|
|
|
std::string getString(size_t index) const override
|
|
|
|
{
|
|
|
|
return strings.at(index);
|
|
|
|
}
|
|
|
|
|
2015-03-25 14:39:41 +00:00
|
|
|
/// Set whether there is skinning contained in this NIF file.
|
|
|
|
/// @note This is just a hint for users of the NIF file and has no effect on the loading procedure.
|
2018-07-08 19:22:34 +00:00
|
|
|
void setUseSkinning(bool skinning) override;
|
2015-03-25 14:39:41 +00:00
|
|
|
|
2018-07-08 19:22:34 +00:00
|
|
|
bool getUseSkinning() const override;
|
2015-03-25 14:39:41 +00:00
|
|
|
|
2014-10-19 06:40:18 +00:00
|
|
|
/// Get the name of the file
|
2018-07-08 19:22:34 +00:00
|
|
|
std::string getFilename() const override { return filename; }
|
2019-12-29 12:53:44 +00:00
|
|
|
|
|
|
|
/// Get the version of the NIF format used
|
|
|
|
unsigned int getVersion() const override { return ver; }
|
|
|
|
|
|
|
|
/// Get the user version of the NIF format used
|
|
|
|
unsigned int getUserVersion() const override { return userVer; }
|
|
|
|
|
|
|
|
/// Get the Bethesda version of the NIF format used
|
|
|
|
unsigned int getBethVersion() const override { return bethVer; }
|
2010-01-04 13:48:18 +00:00
|
|
|
};
|
2019-12-29 12:53:44 +00:00
|
|
|
using NIFFilePtr = std::shared_ptr<const Nif::NIFFile>;
|
2010-01-06 11:28:37 +00:00
|
|
|
|
2012-07-12 13:47:38 +00:00
|
|
|
|
|
|
|
|
2010-01-06 11:28:37 +00:00
|
|
|
} // Namespace
|
2010-01-04 13:48:18 +00:00
|
|
|
#endif
|