2013-03-12 09:16:03 +01:00
|
|
|
#include "loadtes3.hpp"
|
|
|
|
|
2022-01-22 15:58:41 +01:00
|
|
|
#include "components/esm/esmcommon.hpp"
|
2013-03-12 09:16:03 +01:00
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
namespace ESM
|
2013-03-12 09:16:03 +01:00
|
|
|
{
|
2022-04-12 00:18:39 +02:00
|
|
|
|
|
|
|
void Header::blank()
|
2013-03-12 14:33:35 +01:00
|
|
|
{
|
2024-01-01 14:56:48 +04:00
|
|
|
mData.version.ui = VER_130;
|
2013-03-12 09:16:03 +01:00
|
|
|
mData.type = 0;
|
2013-03-12 14:33:35 +01:00
|
|
|
mData.author.clear();
|
|
|
|
mData.desc.clear();
|
|
|
|
mData.records = 0;
|
2023-02-10 13:16:52 +01:00
|
|
|
mFormatVersion = CurrentContentFormatVersion;
|
2013-09-27 11:36:06 +02:00
|
|
|
mMaster.clear();
|
2013-03-12 14:33:35 +01:00
|
|
|
}
|
|
|
|
|
2013-12-21 09:33:05 +01:00
|
|
|
void Header::load(ESMReader& esm)
|
|
|
|
{
|
2023-12-20 12:28:34 +01:00
|
|
|
mFormatVersion = DefaultFormatVersion;
|
|
|
|
esm.getHNOT("FORM", mFormatVersion);
|
2013-11-19 13:44:18 +01:00
|
|
|
|
2013-03-12 09:16:03 +01:00
|
|
|
if (esm.isNextSub("HEDR"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
2024-01-01 14:56:48 +04:00
|
|
|
esm.getT(mData.version.ui);
|
2021-05-05 22:23:06 +03:00
|
|
|
esm.getT(mData.type);
|
2023-02-12 19:36:56 +01:00
|
|
|
mData.author = esm.getMaybeFixedStringSize(32);
|
|
|
|
mData.desc = esm.getMaybeFixedStringSize(256);
|
2013-03-12 09:16:03 +01:00
|
|
|
esm.getT(mData.records);
|
|
|
|
}
|
2015-01-17 00:11:36 +01:00
|
|
|
|
2013-03-12 14:33:35 +01:00
|
|
|
while (esm.isNextSub("MAST"))
|
2022-09-22 21:26:05 +03:00
|
|
|
{
|
2013-03-12 09:16:03 +01:00
|
|
|
MasterData m;
|
|
|
|
m.name = esm.getHString();
|
2021-05-05 22:23:06 +03:00
|
|
|
esm.getHNT(m.size, "DATA");
|
2013-03-12 09:16:03 +01:00
|
|
|
mMaster.push_back(m);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
|
|
|
|
2023-12-20 12:28:34 +01:00
|
|
|
esm.getHNOT("GMDT", mGameData.mCurrentHealth, mGameData.mMaximumHealth, mGameData.mHour, mGameData.unknown1,
|
|
|
|
mGameData.mCurrentCell.mData, mGameData.unknown2, mGameData.mPlayerName.mData);
|
2015-01-17 00:11:36 +01:00
|
|
|
if (esm.isNextSub("SCRD"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
|
|
|
mSCRD.resize(esm.getSubSize());
|
2016-02-22 19:06:12 +01:00
|
|
|
if (!mSCRD.empty())
|
2021-05-05 22:23:06 +03:00
|
|
|
esm.getExact(mSCRD.data(), mSCRD.size());
|
2015-01-17 00:11:36 +01:00
|
|
|
}
|
|
|
|
if (esm.isNextSub("SCRS"))
|
|
|
|
{
|
|
|
|
esm.getSubHeader();
|
|
|
|
mSCRS.resize(esm.getSubSize());
|
2016-02-22 19:06:12 +01:00
|
|
|
if (!mSCRS.empty())
|
2021-05-05 22:23:06 +03:00
|
|
|
esm.getExact(mSCRS.data(), mSCRS.size());
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2015-01-17 00:11:36 +01:00
|
|
|
}
|
2013-03-12 09:16:03 +01:00
|
|
|
|
2022-04-12 00:18:39 +02:00
|
|
|
void Header::save(ESMWriter& esm)
|
2013-03-12 09:16:03 +01:00
|
|
|
{
|
2023-02-10 13:16:52 +01:00
|
|
|
if (mFormatVersion > DefaultFormatVersion)
|
|
|
|
esm.writeHNT("FORM", mFormatVersion);
|
2013-03-12 14:33:35 +01:00
|
|
|
|
2015-06-26 20:16:32 +02:00
|
|
|
esm.startSubRecord("HEDR");
|
|
|
|
esm.writeT(mData.version);
|
|
|
|
esm.writeT(mData.type);
|
2023-02-12 17:03:01 +01:00
|
|
|
esm.writeMaybeFixedSizeString(mData.author, 32);
|
|
|
|
esm.writeMaybeFixedSizeString(mData.desc, 256);
|
2015-06-26 20:16:32 +02:00
|
|
|
esm.writeT(mData.records);
|
|
|
|
esm.endRecord("HEDR");
|
2013-11-19 13:44:18 +01:00
|
|
|
|
2021-05-05 22:23:06 +03:00
|
|
|
for (const Header::MasterData& data : mMaster)
|
2013-03-12 09:16:03 +01:00
|
|
|
{
|
2021-05-05 22:23:06 +03:00
|
|
|
esm.writeHNCString("MAST", data.name);
|
|
|
|
esm.writeHNT("DATA", data.size);
|
2022-09-22 21:26:05 +03:00
|
|
|
}
|
2013-03-12 09:16:03 +01:00
|
|
|
}
|
2022-04-12 00:18:39 +02:00
|
|
|
|
|
|
|
}
|