From 9b801b087693f6ae20f9d737a76982c94e05b02c Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Sun, 10 Sep 2023 02:57:14 +0300 Subject: [PATCH] Fix NiParticlesData loading in Mistify --- components/nif/data.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/components/nif/data.cpp b/components/nif/data.cpp index 799d0cbe43..58cf2f0eff 100644 --- a/components/nif/data.cpp +++ b/components/nif/data.cpp @@ -150,31 +150,31 @@ namespace Nif { NiGeometryData::read(nif); - // Should always match the number of vertices + // Should always match the number of vertices in theory, but doesn't: + // see mist.nif in Mistify mod (https://www.nexusmods.com/morrowind/mods/48112). if (nif->getVersion() <= NIFFile::NIFVersion::VER_MW) nif->read(mNumParticles); - else if (nif->getVersion() != NIFFile::NIFVersion::VER_BGS || nif->getBethVersion() == 0) - mNumParticles = mNumVertices; + bool isBs202 = nif->getVersion() == NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() != 0; bool numRadii = 1; if (nif->getVersion() > NIFStream::generateVersion(10, 0, 1, 0)) - numRadii = nif->get() ? mNumParticles : 0; + numRadii = (nif->get() && !isBs202) ? mNumVertices : 0; nif->readVector(mRadii, numRadii); nif->read(mActiveCount); - if (nif->get()) - nif->readVector(mSizes, mNumParticles); + if (nif->get() && !isBs202) + nif->readVector(mSizes, mNumVertices); if (nif->getVersion() >= NIFStream::generateVersion(10, 0, 1, 0)) { - if (nif->get()) - nif->readVector(mRotations, mNumParticles); + if (nif->get() && !isBs202) + nif->readVector(mRotations, mNumVertices); if (nif->getVersion() >= NIFStream::generateVersion(20, 0, 0, 4)) { - if (nif->get()) - nif->readVector(mRotationAngles, mNumParticles); - if (nif->get()) - nif->readVector(mRotationAxes, mNumParticles); - if (nif->getVersion() == NIFFile::NIFVersion::VER_BGS && nif->getBethVersion() > 0) + if (nif->get() && !isBs202) + nif->readVector(mRotationAngles, mNumVertices); + if (nif->get() && !isBs202) + nif->readVector(mRotationAxes, mNumVertices); + if (isBs202) { nif->read(mHasTextureIndices); uint32_t numSubtextureOffsets; @@ -201,7 +201,7 @@ namespace Nif NiParticlesData::read(nif); if (nif->getVersion() <= NIFStream::generateVersion(4, 2, 2, 0) && nif->get()) - nif->readVector(mRotations, mNumParticles); + nif->readVector(mRotations, mNumVertices); } void NiPosData::read(NIFStream* nif)