mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-04 03:40:14 +00:00
Merge branch 'esmcleanup' into 'master'
More ESM cleanup See merge request OpenMW/openmw!903
This commit is contained in:
commit
a6b695e15b
@ -119,13 +119,13 @@ std::string ESMReader::getHString()
|
||||
// them. For some reason, they break the rules, and contain a byte
|
||||
// (value 0) even if the header says there is no data. If
|
||||
// Morrowind accepts it, so should we.
|
||||
if (mCtx.leftSub == 0 && !mEsm->peek())
|
||||
if (mCtx.leftSub == 0 && hasMoreSubs() && !mEsm->peek())
|
||||
{
|
||||
// Skip the following zero byte
|
||||
mCtx.leftRec--;
|
||||
char c;
|
||||
getExact(&c, 1);
|
||||
return "";
|
||||
getT(c);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
return getString(mCtx.leftSub);
|
||||
@ -152,14 +152,12 @@ void ESMReader::getSubNameIs(const char* name)
|
||||
{
|
||||
getSubName();
|
||||
if (mCtx.subName != name)
|
||||
fail(
|
||||
"Expected subrecord " + std::string(name) + " but got "
|
||||
+ mCtx.subName.toString());
|
||||
fail("Expected subrecord " + std::string(name) + " but got " + mCtx.subName.toString());
|
||||
}
|
||||
|
||||
bool ESMReader::isNextSub(const char* name)
|
||||
{
|
||||
if (!mCtx.leftRec)
|
||||
if (!hasMoreSubs())
|
||||
return false;
|
||||
|
||||
getSubName();
|
||||
@ -174,7 +172,7 @@ bool ESMReader::isNextSub(const char* name)
|
||||
|
||||
bool ESMReader::peekNextSub(const char *name)
|
||||
{
|
||||
if (!mCtx.leftRec)
|
||||
if (!hasMoreSubs())
|
||||
return false;
|
||||
|
||||
getSubName();
|
||||
@ -231,21 +229,17 @@ void ESMReader::skipHSubUntil(const char *name)
|
||||
|
||||
void ESMReader::getSubHeader()
|
||||
{
|
||||
if (mCtx.leftRec < 4)
|
||||
if (mCtx.leftRec < sizeof(mCtx.leftSub))
|
||||
fail("End of record while reading sub-record header");
|
||||
|
||||
// Get subrecord size
|
||||
getT(mCtx.leftSub);
|
||||
mCtx.leftRec -= sizeof(mCtx.leftSub);
|
||||
|
||||
// Adjust number of record bytes left
|
||||
mCtx.leftRec -= mCtx.leftSub + 4;
|
||||
}
|
||||
|
||||
void ESMReader::getSubHeaderIs(int size)
|
||||
{
|
||||
getSubHeader();
|
||||
if (size != static_cast<int> (mCtx.leftSub))
|
||||
fail("getSubHeaderIs(): Sub header mismatch");
|
||||
if (mCtx.leftRec < mCtx.leftSub)
|
||||
fail("Record size is larger than rest of file");
|
||||
mCtx.leftRec -= mCtx.leftSub;
|
||||
}
|
||||
|
||||
NAME ESMReader::getRecName()
|
||||
@ -273,7 +267,7 @@ void ESMReader::skipRecord()
|
||||
void ESMReader::getRecHeader(uint32_t &flags)
|
||||
{
|
||||
// General error checking
|
||||
if (mCtx.leftFile < 12)
|
||||
if (mCtx.leftFile < 3 * sizeof(uint32_t))
|
||||
fail("End of file while reading record header");
|
||||
if (mCtx.leftRec)
|
||||
fail("Previous record contains unread bytes");
|
||||
@ -281,7 +275,7 @@ void ESMReader::getRecHeader(uint32_t &flags)
|
||||
getUint(mCtx.leftRec);
|
||||
getUint(flags);// This header entry is always zero
|
||||
getUint(flags);
|
||||
mCtx.leftFile -= 12;
|
||||
mCtx.leftFile -= 3 * sizeof(uint32_t);
|
||||
|
||||
// Check that sizes add up
|
||||
if (mCtx.leftFile < mCtx.leftRec)
|
||||
|
@ -206,10 +206,6 @@ public:
|
||||
*/
|
||||
void getSubHeader();
|
||||
|
||||
/** Get sub header and check the size
|
||||
*/
|
||||
void getSubHeaderIs(int size);
|
||||
|
||||
/*************************************************************************
|
||||
*
|
||||
* Low level record methods
|
||||
|
@ -50,7 +50,9 @@ namespace ESM
|
||||
switch (esm.retSubName().intval)
|
||||
{
|
||||
case ESM::FourCC<'I','N','T','V'>::value:
|
||||
esm.getSubHeaderIs(8);
|
||||
esm.getSubHeader();
|
||||
if (esm.getSubSize() != 8)
|
||||
esm.fail("Subrecord size is not equal to 8");
|
||||
esm.getT<int>(mX);
|
||||
esm.getT<int>(mY);
|
||||
hasLocation = true;
|
||||
|
@ -39,7 +39,7 @@ namespace ESM
|
||||
// May include the additional two bytes (but not necessarily)
|
||||
if (esm.getSubSize() == sizeof(mData))
|
||||
{
|
||||
esm.getExact(&mData, sizeof(mData));
|
||||
esm.getT(mData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user