1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-27 03:35:27 +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")) while (esm.isNextSub("MPCD"))
{ {
float notepos[3]; 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. // 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, // 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 // 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 // I've seen DATA *twice* on a creature record, and with the exact same content too! weird
// alarmvoi0000.ess // alarmvoi0000.ess
esm.getHNOT(mPos, "DATA", 24); esm.getHNOTSized<24>(mPos, "DATA");
esm.getHNOT(mPos, "DATA", 24); esm.getHNOTSized<24>(mPos, "DATA");
mDeleted = 0; mDeleted = 0;
if (esm.isNextSub("DELE")) if (esm.isNextSub("DELE"))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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