diff --git a/apps/openmw/mwworld/esmstore.cpp b/apps/openmw/mwworld/esmstore.cpp index d366a5a68..1f6ed5102 100644 --- a/apps/openmw/mwworld/esmstore.cpp +++ b/apps/openmw/mwworld/esmstore.cpp @@ -45,7 +45,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) const std::vector &masters = esm.getGameFiles(); std::vector *allPlugins = esm.getGlobalReaderList(); for (size_t j = 0; j < masters.size(); j++) { - ESM::Header::MasterData &mast = const_cast(masters[j]); + const ESM::Header::MasterData &mast = masters[j]; std::string fname = mast.name; int index = ~0; for (int i = 0; i < esm.getIndex(); i++) { @@ -63,7 +63,7 @@ void ESMStore::load(ESM::ESMReader &esm, Loading::Listener* listener) + ", but it has not been loaded yet. Please check your load order."; esm.fail(fstring); } - mast.index = index; + esm.addParentFileIndex(index); } // Loop through all records diff --git a/components/esm/esmcommon.hpp b/components/esm/esmcommon.hpp index 97ce88556..f7a8bf126 100644 --- a/components/esm/esmcommon.hpp +++ b/components/esm/esmcommon.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -126,6 +127,7 @@ struct ESM_Context // actually contribute to a specific cell. Therefore, we need to store the index // of the file belonging to this contest. See CellStore::(list/load)refs for details. int index; + std::vector parentFileIndices; // True if subName has been read but not used. bool subCached; diff --git a/components/esm/esmreader.cpp b/components/esm/esmreader.cpp index 92dbba167..1b6eca734 100644 --- a/components/esm/esmreader.cpp +++ b/components/esm/esmreader.cpp @@ -20,8 +20,7 @@ ESM_Context ESMReader::getContext() } ESMReader::ESMReader() - : mIdx(0) - , mRecordFlags(0) + : mRecordFlags(0) , mBuffer(50*1024) , mGlobalReaderList(nullptr) , mEncoder(nullptr) diff --git a/components/esm/esmreader.hpp b/components/esm/esmreader.hpp index 72a7b4790..761756e8f 100644 --- a/components/esm/esmreader.hpp +++ b/components/esm/esmreader.hpp @@ -79,13 +79,15 @@ public: // terrain palette, but ESMReader does not pass a reference to the correct plugin // to the individual load() methods. This hack allows to pass this reference // indirectly to the load() method. - int mIdx; - void setIndex(const int index) {mIdx = index; mCtx.index = index;} - int getIndex() {return mIdx;} + void setIndex(const int index) { mCtx.index = index;} + int getIndex() {return mCtx.index;} void setGlobalReaderList(std::vector *list) {mGlobalReaderList = list;} std::vector *getGlobalReaderList() {return mGlobalReaderList;} + void addParentFileIndex(int index) { mCtx.parentFileIndices.push_back(index); } + const std::vector& getParentFileIndices() const { return mCtx.parentFileIndices; } + /************************************************************************* * * Medium-level reading shortcuts diff --git a/components/esm/loadcell.cpp b/components/esm/loadcell.cpp index 5b259acef..f92a752a4 100644 --- a/components/esm/loadcell.cpp +++ b/components/esm/loadcell.cpp @@ -21,12 +21,12 @@ namespace // If we have an index value that does not make sense, assume that it was an addition // by the present plugin (but a faulty one) - if (local && local <= reader.getGameFiles().size()) + if (local && local <= reader.getParentFileIndices().size()) { // If the most significant 8 bits are used, then this reference already exists. // In this case, do not spawn a new reference, but overwrite the old one. refNum.mIndex &= 0x00ffffff; // delete old plugin ID - refNum.mContentFile = reader.getGameFiles()[local-1].index; + refNum.mContentFile = reader.getParentFileIndices()[local-1]; } else {