1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/components/esm/loadsoun.cpp
cc9cii 7227a83e60 Preserve "blocked" record flags when saving with OpenCS. This will help outputs of OpenCS to be used with vanilla Morrowind.
Sample use case: users are using the Morrowind Code Patch feature that allows modders to enable this flag to differentiate editor-made potions from player crafted potions for tooltips.
2021-08-28 09:42:54 +10:00

73 lines
1.8 KiB
C++

#include "loadsoun.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
#include "defs.hpp"
namespace ESM
{
unsigned int Sound::sRecordId = REC_SOUN;
void Sound::load(ESMReader &esm, bool &isDeleted)
{
isDeleted = false;
mRecordFlags = esm.getRecordFlags();
bool hasName = false;
bool hasData = false;
while (esm.hasMoreSubs())
{
esm.getSubName();
switch (esm.retSubName().intval)
{
case ESM::SREC_NAME:
mId = esm.getHString();
hasName = true;
break;
case ESM::FourCC<'F','N','A','M'>::value:
mSound = esm.getHString();
break;
case ESM::FourCC<'D','A','T','A'>::value:
esm.getHT(mData, 3);
hasData = true;
break;
case ESM::SREC_DELE:
esm.skipHSub();
isDeleted = true;
break;
default:
esm.fail("Unknown subrecord");
break;
}
}
if (!hasName)
esm.fail("Missing NAME subrecord");
if (!hasData && !isDeleted)
esm.fail("Missing DATA subrecord");
}
void Sound::save(ESMWriter &esm, bool isDeleted) const
{
esm.writeHNCString("NAME", mId);
if (isDeleted)
{
esm.writeHNString("DELE", "", 3);
return;
}
esm.writeHNOCString("FNAM", mSound);
esm.writeHNT("DATA", mData, 3);
}
void Sound::blank()
{
mSound.clear();
mData.mVolume = 128;
mData.mMinRange = 0;
mData.mMaxRange = 255;
}
}