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
|
|
|
|
|
|
|
#include <vector>
|
2022-02-11 20:36:08 +00:00
|
|
|
#include <atomic>
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2022-07-16 16:19:56 +00:00
|
|
|
#include <components/files/istreamptr.hpp>
|
2015-02-17 16:08:55 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-03-10 19:44:50 +00:00
|
|
|
virtual std::string getString(uint32_t index) const = 0;
|
2019-12-29 12:53:44 +00:00
|
|
|
|
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
|
|
|
|
2021-11-15 16:40:22 +00:00
|
|
|
virtual std::string getHash() const = 0;
|
2021-11-10 19:24:17 +00:00
|
|
|
|
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;
|
2021-11-15 16:40:22 +00:00
|
|
|
std::string hash;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Record list
|
2022-02-11 19:40:38 +00:00
|
|
|
std::vector<std::unique_ptr<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
|
|
|
|
2022-02-11 20:36:08 +00:00
|
|
|
static std::atomic_bool sLoadUnsupportedFiles;
|
2020-11-09 11:22:48 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Parse the file
|
2022-04-15 00:15:39 +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:
|
2020-02-02 14:08:17 +00:00
|
|
|
// For generic versions NIFStream::generateVersion() is used instead
|
2019-12-29 12:53:44 +00:00
|
|
|
enum NIFVersion
|
|
|
|
{
|
2020-02-02 14:08:17 +00:00
|
|
|
VER_MW = 0x04000002, // 4.0.0.2. Main Morrowind NIF version.
|
|
|
|
VER_OB_OLD = 0x0A000102, // 10.0.1.2. Main older Oblivion NIF version.
|
|
|
|
VER_OB = 0x14000005, // 20.0.0.5. Main Oblivion NIF version.
|
2019-12-29 12:53:44 +00:00
|
|
|
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
|
2022-07-21 11:51:34 +00:00
|
|
|
[[noreturn]] void fail(const std::string &msg) const;
|
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Used when something goes wrong, but not catastrophically so
|
2022-07-21 11:51:34 +00:00
|
|
|
void warn(const std::string &msg) const;
|
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.
|
2022-04-15 00:15:39 +00:00
|
|
|
NIFFile(Files::IStreamPtr&& stream, const std::string &name);
|
2013-01-05 18:58:50 +00:00
|
|
|
|
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
|
|
|
{
|
2022-02-11 19:40:38 +00:00
|
|
|
return records.at(index).get();
|
2012-07-03 04:41:21 +00:00
|
|
|
}
|
|
|
|
/// 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
|
2022-07-21 11:51:34 +00:00
|
|
|
std::string getString(uint32_t index) const override;
|
2019-12-29 12:53:44 +00:00
|
|
|
|
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
|
|
|
|
2021-11-15 16:40:22 +00:00
|
|
|
std::string getHash() const override { return hash; }
|
2021-11-10 19:24:17 +00:00
|
|
|
|
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; }
|
2020-11-09 11:22:48 +00:00
|
|
|
|
|
|
|
static void setLoadUnsupportedFiles(bool load);
|
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
|