diff --git a/components/esm/common.hpp b/components/esm/common.hpp index c0e6151e24..90c60ad6ab 100644 --- a/components/esm/common.hpp +++ b/components/esm/common.hpp @@ -25,12 +25,13 @@ namespace ESM VER_120 = 0x3f99999a, // TES3 VER_130 = 0x3fa66666, // TES3 VER_080 = 0x3f4ccccd, // TES4 - VER_100 = 0x3f800000, // TES4 + VER_100 = 0x3f800000, // TES4, FO4 VER_132 = 0x3fa8f5c3, // FONV Courier's Stash, DeadMoney VER_133 = 0x3faa3d71, // FONV HonestHearts VER_134 = 0x3fab851f, // FONV, GunRunnersArsenal, LonesomeRoad, OldWorldBlues VER_094 = 0x3f70a3d7, // TES5/FO3 - VER_170 = 0x3fd9999a // TES5 + VER_170 = 0x3fd9999a, // TES5 + VER_095 = 0x3f733333, // FO4 }; // Defines another files (esm or esp) that this file depends upon. diff --git a/components/esm4/loadnavi.cpp b/components/esm4/loadnavi.cpp index 09868d258f..5b73af606e 100644 --- a/components/esm4/loadnavi.cpp +++ b/components/esm4/loadnavi.cpp @@ -249,9 +249,8 @@ void ESM4::Navigation::load(ESM4::Reader& reader) } case ESM4::SUB_NVPP: { - // FIXME: this is both the version for FO4 and for some TES4 files - // How to distinguish? - if (esmVer == ESM::VER_100) + // FIXME: FO4 updates the format + if (reader.hasFormVersion() && (esmVer == ESM::VER_095 || esmVer == ESM::VER_100)) { reader.skipSubRecordData(); break; diff --git a/components/esm4/loadnavm.cpp b/components/esm4/loadnavm.cpp index 6298964f28..828fd77ca1 100644 --- a/components/esm4/loadnavm.cpp +++ b/components/esm4/loadnavm.cpp @@ -213,7 +213,7 @@ void ESM4::NavMesh::load(ESM4::Reader& reader) { // See FIXME in ESM4::Navigation::load. // FO4 updates the format - if (esmVer == ESM::VER_100) + if (reader.hasFormVersion() && (esmVer == ESM::VER_095 || esmVer == ESM::VER_100)) { reader.skipSubRecordData(); break; diff --git a/components/esm4/loadnpc.cpp b/components/esm4/loadnpc.cpp index 65292e63a8..251af13630 100644 --- a/components/esm4/loadnpc.cpp +++ b/components/esm4/loadnpc.cpp @@ -39,7 +39,7 @@ void ESM4::Npc::load(ESM4::Reader& reader) mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); - mIsTES4 = esmVer == ESM::VER_080 || esmVer == ESM::VER_100; + mIsTES4 = (esmVer == ESM::VER_080 || esmVer == ESM::VER_100) && !reader.hasFormVersion(); mIsFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; // mIsTES5 = esmVer == ESM::VER_094 || esmVer == ESM::VER_170; // WARN: FO3 is also VER_094 diff --git a/components/esm4/loadrace.cpp b/components/esm4/loadrace.cpp index 28f91787e6..7434a7f87f 100644 --- a/components/esm4/loadrace.cpp +++ b/components/esm4/loadrace.cpp @@ -38,7 +38,7 @@ void ESM4::Race::load(ESM4::Reader& reader) mFlags = reader.hdr().record.flags; std::uint32_t esmVer = reader.esmVersion(); - bool isTES4 = esmVer == ESM::VER_080 || esmVer == ESM::VER_100; + bool isTES4 = (esmVer == ESM::VER_080 || esmVer == ESM::VER_100) && !reader.hasFormVersion(); bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; bool isFO3 = false; diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index f81a971e15..ce7f534786 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -201,15 +201,6 @@ namespace ESM4 // restart from the beginning (i.e. "TES4" record header) mStream->seekg(0, mStream->beg); -#if 0 - unsigned int esmVer = mHeader.mData.version.ui; - bool isTes4 = esmVer == ESM::VER_080 || esmVer == ESM::VER_100; - //bool isTes5 = esmVer == ESM::VER_094 || esmVer == ESM::VER_170; - //bool isFONV = esmVer == ESM::VER_132 || esmVer == ESM::VER_133 || esmVer == ESM::VER_134; - - // TES4 header size is 4 bytes smaller than TES5 header - mCtx.recHeaderSize = isTes4 ? sizeof(ESM4::RecordHeader) - 4 : sizeof(ESM4::RecordHeader); -#endif getRecordHeader(); if (mCtx.recordHeader.record.typeId == REC_TES4) { diff --git a/components/esm4/reader.hpp b/components/esm4/reader.hpp index a095c23e85..e18c614885 100644 --- a/components/esm4/reader.hpp +++ b/components/esm4/reader.hpp @@ -249,6 +249,9 @@ namespace ESM4 inline unsigned int esmVersion() const { return mHeader.mData.version.ui; } inline unsigned int numRecords() const { return mHeader.mData.records; } + inline bool hasFormVersion() const { return mCtx.recHeaderSize == sizeof(RecordHeader); } + inline unsigned int formVersion() const { return mCtx.recordHeader.record.version; } + void buildLStringIndex(); void getLocalizedString(std::string& str);