mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-20 15:40:32 +00:00
Initial changes to detect when context isn't usable
This commit is contained in:
parent
ba1f91661f
commit
34dd24b261
@ -6,6 +6,7 @@
|
||||
|
||||
#include <components/debug/debuglog.hpp>
|
||||
|
||||
#include <components/esm/format.hpp>
|
||||
#include <components/esm3/cellid.hpp>
|
||||
#include <components/esm3/cellref.hpp>
|
||||
#include <components/esm3/cellstate.hpp>
|
||||
@ -764,35 +765,49 @@ namespace MWWorld
|
||||
static void visitCell4References(const ESM4::Cell& cell, ESM::ReadersCache& readers, ReferenceInvocable&& invocable)
|
||||
{
|
||||
auto stream = Files::openBinaryInputFileStream(cell.mReaderContext.filename);
|
||||
const ESM::Format format = ESM::readFormat(*stream);
|
||||
assert(format == ESM::Tes4);
|
||||
stream->seekg(0);
|
||||
|
||||
ESM4::Reader readerESM4(
|
||||
std::move(stream), cell.mReaderContext.filename, MWBase::Environment::get().getResourceSystem()->getVFS());
|
||||
|
||||
readerESM4.setEncoder(readers.getStatelessEncoder());
|
||||
readerESM4.restoreContext(cell.mReaderContext);
|
||||
bool continueRead = true;
|
||||
while (ESM::RefId::formIdRefId(readerESM4.getContext().currCell) == cell.mId && readerESM4.hasMoreRecs()
|
||||
&& continueRead)
|
||||
bool contextValid = cell.mReaderContext.filePos != -1;
|
||||
if (contextValid)
|
||||
readerESM4.restoreContext(cell.mReaderContext);
|
||||
|
||||
while ((ESM::RefId::formIdRefId(readerESM4.getContext().currCell) == cell.mId || !contextValid)
|
||||
&& readerESM4.hasMoreRecs())
|
||||
{
|
||||
continueRead = ESM4::ReaderUtils::readItem(
|
||||
readerESM4,
|
||||
[&](ESM4::Reader& reader) {
|
||||
auto recordType = static_cast<ESM4::RecordTypes>(reader.hdr().record.typeId);
|
||||
ESM::RecNameInts esm4RecName = static_cast<ESM::RecNameInts>(ESM::esm4Recname(recordType));
|
||||
if (esm4RecName == ESM::RecNameInts::REC_REFR4)
|
||||
{
|
||||
ESM4::Reference ref;
|
||||
ref.load(reader);
|
||||
invocable(ref);
|
||||
return true;
|
||||
}
|
||||
else if (esm4RecName == ESM::RecNameInts::REC_CELL4)
|
||||
{
|
||||
ESM4::Cell cellToLoad;
|
||||
cellToLoad.load(reader); // This is necessary to exit
|
||||
}
|
||||
return false;
|
||||
},
|
||||
[&](ESM4::Reader& reader) {});
|
||||
readerESM4.exitGroupCheck();
|
||||
if (!ESM4::ReaderUtils::readItem(
|
||||
readerESM4,
|
||||
[&](ESM4::Reader& reader) {
|
||||
auto recordType = static_cast<ESM4::RecordTypes>(reader.hdr().record.typeId);
|
||||
ESM::RecNameInts esm4RecName = static_cast<ESM::RecNameInts>(ESM::esm4Recname(recordType));
|
||||
if (esm4RecName == ESM::RecNameInts::REC_REFR4 && contextValid)
|
||||
{
|
||||
ESM4::Reference ref;
|
||||
ref.load(reader);
|
||||
invocable(ref);
|
||||
return true;
|
||||
}
|
||||
else if (esm4RecName == ESM::RecNameInts::REC_CELL4)
|
||||
{
|
||||
ESM4::Cell cellToLoad;
|
||||
cellToLoad.load(reader); // This is necessary to exit or to find the correct cell
|
||||
if (cellToLoad.mId == cell.mId)
|
||||
contextValid = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
[&](ESM4::Reader& reader) {}))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,8 @@ namespace ESM4
|
||||
ReaderContext Reader::getContext()
|
||||
{
|
||||
mCtx.filePos = mStream->tellg();
|
||||
if (mCtx.filePos == -1)
|
||||
return mCtx;
|
||||
mCtx.filePos -= mCtx.recHeaderSize; // update file position
|
||||
return mCtx;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user