1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-26 09:35:28 +00:00

Merge branch 'fix_skip_cell_ref_data' into 'master'

Fix skip cell ref data (#6693)

Closes #6693

See merge request OpenMW/openmw!1758
This commit is contained in:
psi29a 2022-04-10 18:53:12 +00:00
commit 7ebf9a3c45
35 changed files with 58 additions and 54 deletions

View File

@ -278,7 +278,7 @@ namespace ESSImport
while (esm.isNextSub("MPCD"))
{
float notepos[3];
esm.getHT(notepos, 3*sizeof(float));
esm.getHTSized<3 * sizeof(float)>(notepos);
// Markers seem to be arranged in a 32*32 grid, notepos has grid-indices.
// This seems to be the reason markers can't be placed everywhere in interior cells,

View File

@ -35,8 +35,8 @@ namespace ESSImport
// DATA should occur for all references, except levelled creature spawners
// I've seen DATA *twice* on a creature record, and with the exact same content too! weird
// alarmvoi0000.ess
esm.getHNOT(mPos, "DATA", 24);
esm.getHNOT(mPos, "DATA", 24);
esm.getHNOTSized<24>(mPos, "DATA");
esm.getHNOTSized<24>(mPos, "DATA");
mDeleted = 0;
if (esm.isNextSub("DELE"))

View File

@ -13,7 +13,7 @@ namespace ESSImport
mActorData.load(esm);
esm.getHNOT(mPos, "DATA", 24);
esm.getHNOTSized<24>(mPos, "DATA");
}
void PCDT::load(ESM::ESMReader &esm)

View File

@ -11,7 +11,7 @@ void ESM::CellId::load (ESMReader &esm)
if (esm.isNextSub ("CIDX"))
{
esm.getHT (mIndex, 8);
esm.getHTSized<8>(mIndex);
mPaged = true;
}
else

View File

@ -114,9 +114,9 @@ namespace ESM
break;
case ESM::fourCC("DATA"):
if constexpr (load)
esm.getHT(cellRef.mPos, 24);
esm.getHTSized<24>(cellRef.mPos);
else
esm.skip(24);
esm.skipHTSized<24, decltype(cellRef.mPos)>();
break;
case ESM::fourCC("NAM0"):
{
@ -150,7 +150,7 @@ namespace ESM
void ESM::RefNum::load(ESMReader& esm, bool wide, ESM::NAME tag)
{
if (wide)
esm.getHNT(*this, tag, 8);
esm.getHNTSized<8>(*this, tag);
else
esm.getHNT(mIndex, tag);
}

View File

@ -16,7 +16,7 @@ void EffectList::load(ESMReader &esm)
void EffectList::add(ESMReader &esm)
{
ENAMstruct s;
esm.getHT(s, 24);
esm.getHTSized<24>(s);
mList.push_back(s);
}

View File

@ -2,7 +2,6 @@
#define OPENMW_ESM_READER_H
#include <cstdint>
#include <cassert>
#include <vector>
#include <sstream>
@ -114,20 +113,18 @@ public:
// Version with extra size checking, to make sure the compiler
// doesn't mess up our struct padding.
template <typename X>
void getHNT(X &x, NAME name, int size)
template <std::size_t size, typename X>
void getHNTSized(X &x, NAME name)
{
assert(sizeof(X) == size);
getSubNameIs(name);
getHT(x);
static_assert(sizeof(X) == size);
getHNT(x, name);
}
template <typename X>
void getHNOT(X &x, NAME name, int size)
template <std::size_t size, typename X>
void getHNOTSized(X &x, NAME name)
{
assert(sizeof(X) == size);
if(isNextSub(name))
getHT(x);
static_assert(sizeof(X) == size);
getHNOT(x, name);
}
// Get data of a given type/size, including subrecord header
@ -151,13 +148,20 @@ public:
// Version with extra size checking, to make sure the compiler
// doesn't mess up our struct padding.
template <typename X>
void getHT(X &x, int size)
template <std::size_t size, typename X>
void getHTSized(X &x)
{
assert(sizeof(X) == size);
static_assert(sizeof(X) == size);
getHT(x);
}
template <std::size_t size, typename T>
void skipHTSized()
{
static_assert(sizeof(T) == size);
skipHT<T>();
}
// Read a string by the given name if it is the next record.
std::string getHNOString(NAME name);

View File

@ -39,7 +39,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("ALDT"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
hasData = true;
break;
case ESM::fourCC("ENAM"):

View File

@ -63,7 +63,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("AODT"):
esm.getHT(mData, 24);
esm.getHTSized<24>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -31,7 +31,7 @@ namespace ESM
mRace = esm.getHString();
break;
case ESM::fourCC("BYDT"):
esm.getHT(mData, 4);
esm.getHTSized<4>(mData);
hasData = true;
break;
case ESM::SREC_DELE:

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("BKDT"):
esm.getHT(mData, 20);
esm.getHTSized<20>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -76,7 +76,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("DATA"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
hasData = true;
break;
case ESM::SREC_DELE:

View File

@ -58,7 +58,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("CLDT"):
esm.getHT(mData, 60);
esm.getHTSized<60>(mData);
if (mData.mIsPlayable > 1)
esm.fail("Unknown bool value");
hasData = true;

View File

@ -33,7 +33,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("CTDT"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -55,11 +55,11 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("CNDT"):
esm.getHT(mWeight, 4);
esm.getHTSized<4>(mWeight);
hasWeight = true;
break;
case ESM::fourCC("FLAG"):
esm.getHT(mFlags, 4);
esm.getHTSized<4>(mFlags);
if (mFlags & 0xf4)
esm.fail("Unknown flags");
if (!(mFlags & 0x8))

View File

@ -50,7 +50,7 @@ namespace ESM {
mScript = esm.getHString();
break;
case ESM::fourCC("NPDT"):
esm.getHT(mData, 96);
esm.getHTSized<96>(mData);
hasNpdt = true;
break;
case ESM::fourCC("FLAG"):

View File

@ -26,7 +26,7 @@ namespace ESM
hasName = true;
break;
case ESM::fourCC("ENDT"):
esm.getHT(mData, 16);
esm.getHTSized<16>(mData);
hasData = true;
break;
case ESM::fourCC("ENAM"):

View File

@ -56,7 +56,7 @@ namespace ESM
mRanks[rankCounter++] = esm.getHString();
break;
case ESM::fourCC("FADT"):
esm.getHT(mData, 240);
esm.getHTSized<240>(mData);
if (mData.mIsHidden > 1)
esm.fail("Unknown flag!");
hasData = true;

View File

@ -26,7 +26,7 @@ namespace ESM
switch (esm.retSubName().toInt())
{
case ESM::fourCC("DATA"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
break;
case ESM::fourCC("ONAM"):
mActor = esm.getHString();

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("IRDT"):
esm.getHT(mData, 56);
esm.getHTSized<56>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -34,7 +34,7 @@ namespace ESM
mIcon = esm.getHString();
break;
case ESM::fourCC("LHDT"):
esm.getHT(mData, 24);
esm.getHTSized<24>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("LKDT"):
esm.getHT(mData, 16);
esm.getHTSized<16>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -195,7 +195,7 @@ void MagicEffect::load(ESMReader &esm, bool &isDeleted)
mId = indexToId (mIndex);
esm.getHNT(mData, "MEDT", 36);
esm.getHNTSized<36>(mData, "MEDT");
if (esm.getFormat() == 0)
{
// don't allow mods to change fixed flags in the legacy format

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("MCDT"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -52,7 +52,7 @@ namespace ESM
mCell = esm.getHString();
break;
case ESM::fourCC("DATA"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
hasData = true;
break;
case ESM::fourCC("PGRP"):

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("PBDT"):
esm.getHT(mData, 16);
esm.getHTSized<16>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -40,7 +40,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("RADT"):
esm.getHT(mData, 140);
esm.getHTSized<140>(mData);
hasData = true;
break;
case ESM::fourCC("DESC"):

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("RIDT"):
esm.getHT(mData, 16);
esm.getHTSized<16>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -144,7 +144,7 @@ namespace ESM
hasIndex = true;
break;
case ESM::fourCC("SKDT"):
esm.getHT(mData, 24);
esm.getHTSized<24>(mData);
hasData = true;
break;
case ESM::fourCC("DESC"):

View File

@ -25,7 +25,7 @@ namespace ESM
hasName = true;
break;
case ESM::fourCC("DATA"):
esm.getHT(mType, 4);
esm.getHTSized<4>(mType);
hasData = true;
break;
case ESM::fourCC("CNAM"):

View File

@ -28,7 +28,7 @@ namespace ESM
mSound = esm.getHString();
break;
case ESM::fourCC("DATA"):
esm.getHT(mData, 3);
esm.getHTSized<3>(mData);
hasData = true;
break;
case ESM::SREC_DELE:

View File

@ -30,12 +30,12 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("SPDT"):
esm.getHT(mData, 12);
esm.getHTSized<12>(mData);
hasData = true;
break;
case ESM::fourCC("ENAM"):
ENAMstruct s;
esm.getHT(s, 24);
esm.getHTSized<24>(s);
mEffects.mList.push_back(s);
break;
case ESM::SREC_DELE:

View File

@ -31,7 +31,7 @@ namespace ESM
mName = esm.getHString();
break;
case ESM::fourCC("WPDT"):
esm.getHT(mData, 32);
esm.getHTSized<32>(mData);
hasData = true;
break;
case ESM::fourCC("SCRI"):

View File

@ -10,12 +10,12 @@ void ESM::Player::load (ESMReader &esm)
mCellId.load (esm);
esm.getHNT (mLastKnownExteriorPosition, "LKEP", 12);
esm.getHNTSized<12>(mLastKnownExteriorPosition, "LKEP");
if (esm.isNextSub ("MARK"))
{
mHasMark = true;
esm.getHT (mMarkedPosition, 24);
esm.getHTSized<24>(mMarkedPosition);
mMarkedCell.load (esm);
}
else

View File

@ -15,7 +15,7 @@ void ESM::SavedGame::load (ESMReader &esm)
mPlayerClassName = esm.getHNOString("PLCN");
mPlayerCell = esm.getHNString("PLCE");
esm.getHNT (mInGameTime, "TSTM", 16);
esm.getHNTSized<16>(mInGameTime, "TSTM");
esm.getHNT (mTimePlayed, "TIME");
mDescription = esm.getHNString ("DESC");