From 57e7bf3748c5a740e66b591934c1ce1f349baeae Mon Sep 17 00:00:00 2001 From: cykoder <2380691-cykoder@users.noreply.gitlab.com> Date: Mon, 24 Jun 2024 18:03:59 +0000 Subject: [PATCH] OpenMW-CS verify duplicate RefNums --- apps/opencs/model/tools/referencecheck.cpp | 11 +++++++++++ apps/opencs/model/tools/referencecheck.hpp | 1 + 2 files changed, 12 insertions(+) diff --git a/apps/opencs/model/tools/referencecheck.cpp b/apps/opencs/model/tools/referencecheck.cpp index 33c2168ef3..306094f2f5 100644 --- a/apps/opencs/model/tools/referencecheck.cpp +++ b/apps/opencs/model/tools/referencecheck.cpp @@ -45,6 +45,16 @@ void CSMTools::ReferenceCheckStage::perform(int stage, CSMDoc::Messages& message const CSMWorld::CellRef& cellRef = record.get(); const CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Reference, cellRef.mId); + // Check RefNum is unique per content file, otherwise can cause load issues + const auto refNum = cellRef.mRefNum; + const auto insertResult = mUsedReferenceIDs.emplace(refNum, cellRef.mId); + if (!insertResult.second) + messages.add(id, + "Duplicate RefNum: " + std::to_string(refNum.mContentFile) + std::string("-") + + std::to_string(refNum.mIndex) + " shared with cell reference " + + insertResult.first->second.toString(), + "", CSMDoc::Message::Severity_Error); + // Check reference id if (cellRef.mRefID.empty()) messages.add(id, "Instance is not based on an object", "", CSMDoc::Message::Severity_Error); @@ -109,6 +119,7 @@ void CSMTools::ReferenceCheckStage::perform(int stage, CSMDoc::Messages& message int CSMTools::ReferenceCheckStage::setup() { mIgnoreBaseRecords = CSMPrefs::get()["Reports"]["ignore-base-records"].isTrue(); + mUsedReferenceIDs.clear(); return mReferences.getSize(); } diff --git a/apps/opencs/model/tools/referencecheck.hpp b/apps/opencs/model/tools/referencecheck.hpp index 5f5004b912..58fb4e4170 100644 --- a/apps/opencs/model/tools/referencecheck.hpp +++ b/apps/opencs/model/tools/referencecheck.hpp @@ -43,6 +43,7 @@ namespace CSMTools const CSMWorld::IdCollection& mCells; const CSMWorld::IdCollection& mFactions; const CSMWorld::IdCollection& mBodyParts; + std::unordered_map mUsedReferenceIDs; bool mIgnoreBaseRecords; }; }