2014-08-24 13:27:09 -04:00
|
|
|
/// Main header for reading .nif files
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2013-02-24 13:51:56 -08:00
|
|
|
#ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
|
|
|
#define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2022-02-11 21:36:08 +01:00
|
|
|
#include <atomic>
|
2022-07-28 22:20:44 +02:00
|
|
|
#include <filesystem>
|
2010-01-04 14:48:18 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2022-07-16 18:19:56 +02:00
|
|
|
#include <components/files/istreamptr.hpp>
|
2015-02-17 17:08:55 +01:00
|
|
|
|
2010-06-03 20:44:55 +02:00
|
|
|
#include "record.hpp"
|
2010-01-04 19:35:11 +01:00
|
|
|
|
2010-01-06 12:28:37 +01:00
|
|
|
namespace Nif
|
|
|
|
{
|
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
struct NIFFile
|
2018-07-08 22:22:34 +03:00
|
|
|
{
|
2022-09-17 19:24:42 +02:00
|
|
|
// For generic versions NIFStream::generateVersion() is used instead
|
|
|
|
enum NIFVersion
|
|
|
|
{
|
|
|
|
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.
|
|
|
|
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
|
2023-05-22 22:28:05 +03:00
|
|
|
BETHVER_SKY = 83, // Skyrim
|
2023-07-09 10:14:27 +00:00
|
|
|
BETHVER_SSE = 100, // Skyrim SE
|
|
|
|
BETHVER_FO4 = 130, // Fallout 4
|
2023-09-10 00:04:17 +03:00
|
|
|
BETHVER_F76 = 155, // Fallout 76
|
|
|
|
BETHVER_STF = 172, // Starfield
|
2022-09-17 19:24:42 +02:00
|
|
|
};
|
2018-07-08 22:22:34 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// File version, user version, Bethesda version
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t mVersion = 0;
|
|
|
|
std::uint32_t mUserVersion = 0;
|
|
|
|
std::uint32_t mBethVersion = 0;
|
2018-07-08 22:22:34 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// File name, used for error messages and opening the file
|
|
|
|
std::filesystem::path mPath;
|
|
|
|
std::string mHash;
|
2018-07-08 22:22:34 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Record list
|
|
|
|
std::vector<std::unique_ptr<Record>> mRecords;
|
|
|
|
|
|
|
|
/// Root list. This is a select portion of the pointers from records
|
|
|
|
std::vector<Record*> mRoots;
|
2019-12-29 15:53:44 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
bool mUseSkinning = false;
|
|
|
|
|
|
|
|
explicit NIFFile(const std::filesystem::path& path)
|
|
|
|
: mPath(path)
|
|
|
|
{
|
|
|
|
}
|
2022-09-18 14:12:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class FileView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FileView(const NIFFile& file)
|
|
|
|
: mFile(&file)
|
|
|
|
{
|
|
|
|
}
|
2018-07-08 22:22:34 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Get a given root
|
2022-09-18 14:12:49 +02:00
|
|
|
const Record* getRoot(std::size_t index) const { return mFile->mRoots.at(index); }
|
2018-07-08 22:22:34 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Number of roots
|
2022-09-18 14:12:49 +02:00
|
|
|
std::size_t numRoots() const { return mFile->mRoots.size(); }
|
2019-12-29 15:53:44 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Get the name of the file
|
2022-09-18 14:12:49 +02:00
|
|
|
const std::filesystem::path& getFilename() const { return mFile->mPath; }
|
2021-11-10 20:24:17 +01:00
|
|
|
|
2022-09-18 14:12:49 +02:00
|
|
|
const std::string& getHash() const { return mFile->mHash; }
|
2019-12-29 15:53:44 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Get the version of the NIF format used
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t getVersion() const { return mFile->mVersion; }
|
2019-12-29 15:53:44 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Get the user version of the NIF format used
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t getUserVersion() const { return mFile->mUserVersion; }
|
2018-07-08 22:22:34 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Get the Bethesda version of the NIF format used
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t getBethVersion() const { return mFile->mBethVersion; }
|
2022-09-18 14:12:49 +02:00
|
|
|
|
|
|
|
bool getUseSkinning() const { return mFile->mUseSkinning; }
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2022-09-18 14:12:49 +02:00
|
|
|
private:
|
|
|
|
const NIFFile* mFile;
|
2021-11-15 17:40:22 +01:00
|
|
|
};
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
class Reader
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2012-07-02 21:41:21 -07:00
|
|
|
/// File version, user version, Bethesda version
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t& mVersion;
|
|
|
|
std::uint32_t& mUserVersion;
|
|
|
|
std::uint32_t& mBethVersion;
|
2010-01-04 14:48:18 +01:00
|
|
|
|
2014-08-24 13:27:09 -04:00
|
|
|
/// File name, used for error messages and opening the file
|
2023-09-10 00:04:17 +03:00
|
|
|
std::filesystem::path& mFilename;
|
|
|
|
std::string& mHash;
|
2013-04-06 10:17:09 -07:00
|
|
|
|
2019-12-29 15:53:44 +03:00
|
|
|
/// Record list
|
2023-09-10 00:04:17 +03:00
|
|
|
std::vector<std::unique_ptr<Record>>& mRecords;
|
2019-12-29 15:53:44 +03:00
|
|
|
|
|
|
|
/// Root list. This is a select portion of the pointers from records
|
2023-09-10 00:04:17 +03:00
|
|
|
std::vector<Record*>& mRoots;
|
2015-03-25 15:39:41 +01:00
|
|
|
|
2022-02-11 21:36:08 +01:00
|
|
|
/// String table
|
2023-09-10 00:04:17 +03:00
|
|
|
std::vector<std::string> mStrings;
|
2020-11-09 14:22:48 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
bool& mUseSkinning;
|
2010-01-07 19:11:03 +01:00
|
|
|
|
2014-10-19 02:54:27 -04:00
|
|
|
static std::atomic_bool sLoadUnsupportedFiles;
|
2023-02-08 21:36:05 +01:00
|
|
|
static std::atomic_bool sWriteNifDebugLog;
|
2014-10-19 02:54:27 -04:00
|
|
|
|
2020-02-02 17:08:17 +03:00
|
|
|
/// Get the file's version in a human readable form
|
|
|
|
///\returns A string containing a human readable NIF version number
|
2023-09-10 00:04:17 +03:00
|
|
|
std::string versionToString(std::uint32_t version);
|
2019-12-29 15:53:44 +03:00
|
|
|
|
2022-09-22 21:26:05 +03:00
|
|
|
public:
|
2018-07-08 22:22:34 +03:00
|
|
|
/// Open a NIF stream. The name is used for error messages.
|
2022-09-17 19:24:42 +02:00
|
|
|
explicit Reader(NIFFile& file);
|
2014-10-19 02:40:18 -04:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Parse the file
|
|
|
|
void parse(Files::IStreamPtr&& stream);
|
2019-12-29 15:53:44 +03:00
|
|
|
|
2022-09-17 19:24:42 +02:00
|
|
|
/// Get a given record
|
2023-09-10 00:04:17 +03:00
|
|
|
Record* getRecord(size_t index) const { return mRecords.at(index).get(); }
|
2015-03-25 15:39:41 +01:00
|
|
|
|
2019-12-29 15:53:44 +03:00
|
|
|
/// Get a given string from the file's string table
|
2023-09-10 00:04:17 +03:00
|
|
|
std::string getString(std::uint32_t index) const;
|
2015-03-25 15:39:41 +01:00
|
|
|
|
2014-10-19 02:40:18 -04: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.
|
2022-09-17 19:24:42 +02:00
|
|
|
void setUseSkinning(bool skinning);
|
2021-11-10 20:24:17 +01:00
|
|
|
|
2019-12-29 15:53:44 +03:00
|
|
|
/// Get the name of the file
|
2023-09-10 00:04:17 +03:00
|
|
|
std::filesystem::path getFilename() const { return mFilename; }
|
2019-12-29 15:53:44 +03:00
|
|
|
|
|
|
|
/// Get the version of the NIF format used
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t getVersion() const { return mVersion; }
|
2020-11-09 14:22:48 +03:00
|
|
|
|
|
|
|
/// Get the user version of the NIF format used
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t getUserVersion() const { return mUserVersion; }
|
2010-01-06 12:28:37 +01:00
|
|
|
|
2019-12-29 15:53:44 +03:00
|
|
|
/// Get the Bethesda version of the NIF format used
|
2023-09-10 00:04:17 +03:00
|
|
|
std::uint32_t getBethVersion() const { return mBethVersion; }
|
2012-07-12 06:47:38 -07:00
|
|
|
|
2020-11-09 14:22:48 +03:00
|
|
|
static void setLoadUnsupportedFiles(bool load);
|
2023-02-08 21:36:05 +01:00
|
|
|
|
|
|
|
static void setWriteNifDebugLog(bool load);
|
2022-09-22 21:26:05 +03:00
|
|
|
};
|
2019-12-29 15:53:44 +03:00
|
|
|
using NIFFilePtr = std::shared_ptr<const Nif::NIFFile>;
|
2012-07-12 06:47:38 -07:00
|
|
|
|
2010-01-06 12:28:37 +01:00
|
|
|
} // Namespace
|
2010-01-04 14:48:18 +01:00
|
|
|
#endif
|