From 8a8ecce1e550efe9c94696b881024fd6ee10a57e Mon Sep 17 00:00:00 2001 From: scrawl Date: Wed, 25 Jun 2014 00:11:25 +0200 Subject: [PATCH] Fix some uninitialized data written to savegames --- apps/openmw/mwstate/statemanagerimp.cpp | 7 +++++++ components/esm/cellref.cpp | 9 +++++---- components/esm/esmwriter.cpp | 5 +++++ components/esm/esmwriter.hpp | 5 +++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwstate/statemanagerimp.cpp b/apps/openmw/mwstate/statemanagerimp.cpp index a459c87bb..a3604cc66 100644 --- a/apps/openmw/mwstate/statemanagerimp.cpp +++ b/apps/openmw/mwstate/statemanagerimp.cpp @@ -201,6 +201,13 @@ void MWState::StateManager::saveGame (const std::string& description, const Slot writer.addMaster (*iter, 0); // not using the size information anyway -> use value of 0 writer.setFormat (ESM::Header::CurrentFormat); + + // all unused + writer.setVersion(0); + writer.setType(0); + writer.setAuthor(""); + writer.setDescription(""); + int recordCount = 1 // saved game header +MWBase::Environment::get().getJournal()->countSavedGameRecords() +MWBase::Environment::get().getWorld()->countSavedGameRecords() diff --git a/components/esm/cellref.cpp b/components/esm/cellref.cpp index d785fb2b6..84c638d9c 100644 --- a/components/esm/cellref.cpp +++ b/components/esm/cellref.cpp @@ -108,13 +108,13 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons esm.writeHNT("NAM9", mGoldValue); } - if (mTeleport && !inInventory) + if (!inInventory && mTeleport) { esm.writeHNT("DODT", mDoorDest); esm.writeHNOCString("DNAM", mDestCell); } - if (mLockLevel != 0 && !inInventory) { + if (!inInventory && mLockLevel != 0) { esm.writeHNT("FLTV", mLockLevel); } @@ -127,13 +127,13 @@ void ESM::CellRef::save (ESMWriter &esm, bool wideRefNum, bool inInventory) cons if (mReferenceBlocked != -1) esm.writeHNT("UNAM", mReferenceBlocked); - if (mFltv != 0 && !inInventory) + if (!inInventory && mFltv != 0) esm.writeHNT("FLTV", mFltv); if (!inInventory) esm.writeHNT("DATA", mPos, 24); - if (mNam0 != 0 && !inInventory) + if (!inInventory && mNam0 != 0) esm.writeHNT("NAM0", mNam0); } @@ -158,6 +158,7 @@ void ESM::CellRef::blank() mReferenceBlocked = 0; mFltv = 0; mNam0 = 0; + mTeleport = false; for (int i=0; i<3; ++i) { diff --git a/components/esm/esmwriter.cpp b/components/esm/esmwriter.cpp index 9d8d943d9..06572ce8f 100644 --- a/components/esm/esmwriter.cpp +++ b/components/esm/esmwriter.cpp @@ -18,6 +18,11 @@ namespace ESM mHeader.mData.version = ver; } + void ESMWriter::setType(int type) + { + mHeader.mData.type = type; + } + void ESMWriter::setAuthor(const std::string& auth) { mHeader.mData.author.assign (auth); diff --git a/components/esm/esmwriter.hpp b/components/esm/esmwriter.hpp index ca4f42217..e57c6e45d 100644 --- a/components/esm/esmwriter.hpp +++ b/components/esm/esmwriter.hpp @@ -25,10 +25,15 @@ class ESMWriter ESMWriter(); unsigned int getVersion() const; + + // Set various header data (ESM::Header::Data). All of the below functions must be called before writing, + // otherwise this data will be left uninitialized. void setVersion(unsigned int ver = 0x3fa66666); + void setType(int type); void setEncoder(ToUTF8::Utf8Encoder *encoding); void setAuthor(const std::string& author); void setDescription(const std::string& desc); + // Set the record count for writing it in the file header void setRecordCount (int count); // Counts how many records we have actually written.