diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 31c73f8461..0f5009400d 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -766,21 +766,22 @@ namespace MWWorld { auto stream = Files::openBinaryInputFileStream(cell.mReaderContext.filename); const ESM::Format format = ESM::readFormat(*stream); - assert(format == ESM::Tes4); + assert(format == ESM::Format::Tes4); stream->seekg(0); ESM4::Reader readerESM4( std::move(stream), cell.mReaderContext.filename, MWBase::Environment::get().getResourceSystem()->getVFS()); readerESM4.setEncoder(readers.getStatelessEncoder()); - bool contextValid = cell.mReaderContext.filePos != -1; + bool contextValid = cell.mReaderContext.filePos != std::numeric_limits::max(); if (contextValid) readerESM4.restoreContext(cell.mReaderContext); while ((ESM::RefId::formIdRefId(readerESM4.getContext().currCell) == cell.mId || !contextValid) && readerESM4.hasMoreRecs()) { - readerESM4.exitGroupCheck(); + if (!contextValid) + readerESM4.exitGroupCheck(); if (!ESM4::ReaderUtils::readItem( readerESM4, [&](ESM4::Reader& reader) { @@ -788,6 +789,7 @@ namespace MWWorld ESM::RecNameInts esm4RecName = static_cast(ESM::esm4Recname(recordType)); if (esm4RecName == ESM::RecNameInts::REC_REFR4 && contextValid) { + reader.getRecordData(); ESM4::Reference ref; ref.load(reader); invocable(ref); @@ -795,6 +797,7 @@ namespace MWWorld } else if (esm4RecName == ESM::RecNameInts::REC_CELL4) { + reader.getRecordData(); ESM4::Cell cellToLoad; cellToLoad.load(reader); // This is necessary to exit or to find the correct cell if (cellToLoad.mId == cell.mId) diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index d6168efdae..e599034c8f 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -134,7 +134,7 @@ namespace ESM4 ReaderContext Reader::getContext() { mCtx.filePos = mStream->tellg(); - if (mCtx.filePos == -1) + if (mCtx.filePos == std::numeric_limits::max()) return mCtx; mCtx.filePos -= mCtx.recHeaderSize; // update file position return mCtx;