2013-12-15 15:16:50 +00:00
|
|
|
#include "globalscript.hpp"
|
|
|
|
|
|
|
|
#include "esmreader.hpp"
|
|
|
|
#include "esmwriter.hpp"
|
|
|
|
|
2023-08-20 09:34:05 +00:00
|
|
|
#include <cstdint>
|
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
namespace ESM
|
|
|
|
{
|
|
|
|
|
|
|
|
void GlobalScript::load(ESMReader& esm)
|
2013-12-15 15:16:50 +00:00
|
|
|
{
|
2023-02-12 18:36:56 +00:00
|
|
|
mId = esm.getHNRefId("NAME");
|
2013-12-15 15:16:50 +00:00
|
|
|
|
|
|
|
mLocals.load(esm);
|
|
|
|
|
2023-08-20 09:34:05 +00:00
|
|
|
int32_t running = 0;
|
|
|
|
esm.getHNOT(running, "RUN_");
|
|
|
|
mRunning = running != 0;
|
2014-07-15 11:05:38 +00:00
|
|
|
|
2023-01-09 09:45:07 +00:00
|
|
|
mTargetRef = RefNum{};
|
2023-02-12 18:36:56 +00:00
|
|
|
mTargetId = esm.getHNORefId("TARG");
|
2020-05-10 12:57:06 +00:00
|
|
|
if (esm.peekNextSub("FRMR"))
|
2023-04-07 00:14:32 +00:00
|
|
|
mTargetRef = esm.getFormId(true, "FRMR");
|
2023-08-09 08:21:41 +00:00
|
|
|
if (!esm.applyContentFileMapping(mTargetRef))
|
|
|
|
{
|
|
|
|
mTargetId = ESM::RefId();
|
|
|
|
mTargetRef = ESM::FormId();
|
|
|
|
}
|
2013-12-15 15:16:50 +00:00
|
|
|
}
|
|
|
|
|
2022-04-11 22:18:39 +00:00
|
|
|
void GlobalScript::save(ESMWriter& esm) const
|
2013-12-15 15:16:50 +00:00
|
|
|
{
|
2023-02-12 18:36:56 +00:00
|
|
|
esm.writeHNRefId("NAME", mId);
|
2013-12-15 15:16:50 +00:00
|
|
|
|
|
|
|
mLocals.save(esm);
|
|
|
|
|
|
|
|
if (mRunning)
|
2023-08-20 09:34:05 +00:00
|
|
|
esm.writeHNT("RUN_", int32_t{ 1 });
|
2014-07-15 11:05:38 +00:00
|
|
|
|
2020-05-10 12:57:06 +00:00
|
|
|
if (!mTargetId.empty())
|
|
|
|
{
|
2023-02-12 18:36:56 +00:00
|
|
|
esm.writeHNORefId("TARG", mTargetId);
|
2021-01-22 14:48:37 +00:00
|
|
|
if (mTargetRef.isSet())
|
2023-04-07 00:14:32 +00:00
|
|
|
esm.writeFormId(mTargetRef, true, "FRMR");
|
2022-09-22 18:26:05 +00:00
|
|
|
}
|
2020-05-10 12:57:06 +00:00
|
|
|
}
|
2022-04-11 22:18:39 +00:00
|
|
|
|
|
|
|
}
|