1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-04 02:41:19 +00:00
OpenMW/components/esm3/projectilestate.cpp
psi29a a6d6e16d48 Merge branch 'readsize' into 'master'
Disallow implicitly sized reads of ESM structs

See merge request OpenMW/openmw!3100
2023-07-28 07:01:32 +00:00

75 lines
2.0 KiB
C++

#include "projectilestate.hpp"
#include "esmreader.hpp"
#include "esmwriter.hpp"
namespace ESM
{
void BaseProjectileState::save(ESMWriter& esm) const
{
esm.writeHNRefId("ID__", mId);
esm.writeHNT("VEC3", mPosition);
esm.writeHNT("QUAT", mOrientation);
esm.writeHNT("ACTO", mActorId);
}
void BaseProjectileState::load(ESMReader& esm)
{
mId = esm.getHNRefId("ID__");
esm.getHNTSized<12>(mPosition, "VEC3");
esm.getHNTSized<16>(mOrientation, "QUAT");
esm.getHNT(mActorId, "ACTO");
}
void MagicBoltState::save(ESMWriter& esm) const
{
BaseProjectileState::save(esm);
esm.writeHNRefId("SPEL", mSpellId);
esm.writeHNT("SPED", mSpeed);
if (mItem.isSet())
esm.writeFormId(mItem, true, "ITEM");
}
void MagicBoltState::load(ESMReader& esm)
{
BaseProjectileState::load(esm);
mSpellId = esm.getHNRefId("SPEL");
if (esm.isNextSub("SRCN")) // for backwards compatibility
esm.skipHSub();
EffectList().load(esm); // for backwards compatibility
esm.getHNT(mSpeed, "SPED");
if (esm.peekNextSub("ITEM"))
mItem = esm.getFormId(true, "ITEM");
if (esm.isNextSub("SLOT")) // for backwards compatibility
esm.skipHSub();
if (esm.isNextSub("STCK")) // for backwards compatibility
esm.skipHSub();
if (esm.isNextSub("SOUN")) // for backwards compatibility
esm.skipHSub();
}
void ProjectileState::save(ESMWriter& esm) const
{
BaseProjectileState::save(esm);
esm.writeHNRefId("BOW_", mBowId);
esm.writeHNT("VEL_", mVelocity);
esm.writeHNT("STR_", mAttackStrength);
}
void ProjectileState::load(ESMReader& esm)
{
BaseProjectileState::load(esm);
mBowId = esm.getHNRefId("BOW_");
esm.getHNTSized<12>(mVelocity, "VEL_");
mAttackStrength = 1.f;
esm.getHNOT(mAttackStrength, "STR_");
}
}