From 1c17260d875ddc04d89bf21d6ae12a212382e060 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 17 Oct 2022 09:35:43 +0200 Subject: [PATCH 1/3] Don't use potentially invalid cache entry --- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 690f05d51f..4deab10647 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -293,8 +293,7 @@ namespace MWDialogue const ESM::Dialogue& dialogue = *dialogues.find(topic); - const ESM::DialInfo* info = mChoice == -1 && mActorKnownTopics.count(topic) ? mActorKnownTopics[topic].mInfo - : filter.search(dialogue, true); + const ESM::DialInfo* info = filter.search(dialogue, true); if (info) { From 81f138cea024497c11fc27525c03f4ff7b8c17cb Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 17 Oct 2022 09:37:56 +0200 Subject: [PATCH 2/3] Prevent potentially returning garbage flags --- apps/openmw/mwbase/dialoguemanager.hpp | 2 +- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 7 +++++-- apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index 889da6de71..b84aa17ec1 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -89,7 +89,7 @@ namespace MWBase }; virtual std::list getAvailableTopics() = 0; - virtual int getTopicFlag(const std::string&) = 0; + virtual int getTopicFlag(const std::string&) const = 0; virtual bool checkServiceRefused(ResponseCallback* callback, ServiceType service = ServiceType::Any) = 0; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 4deab10647..c12da74c4d 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -424,9 +424,12 @@ namespace MWDialogue return keywordList; } - int DialogueManager::getTopicFlag(const std::string& topicId) + int DialogueManager::getTopicFlag(const std::string& topicId) const { - return mActorKnownTopics[topicId].mFlags; + auto known = mActorKnownTopics.find(topicId); + if (known != mActorKnownTopics.end()) + return known->second.mFlags; + return 0; } void DialogueManager::keywordSelected(const std::string& keyword, ResponseCallback* callback) diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index ae6824c57c..c4599e7550 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -82,7 +82,7 @@ namespace MWDialogue bool startDialogue(const MWWorld::Ptr& actor, ResponseCallback* callback) override; std::list getAvailableTopics() override; - int getTopicFlag(const std::string& topicId) override; + int getTopicFlag(const std::string& topicId) const override; bool inJournal(const std::string& topicId, const std::string& infoId) override; From a24e9e4c0a7dc40bc3cf5be0b9ef763af86a5440 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Mon, 17 Oct 2022 09:43:20 +0200 Subject: [PATCH 3/3] Mark constant methods const --- apps/openmw/mwbase/dialoguemanager.hpp | 6 +++--- apps/openmw/mwdialogue/dialoguemanagerimp.cpp | 6 +++--- apps/openmw/mwdialogue/dialoguemanagerimp.hpp | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index b84aa17ec1..94b85cbe88 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -53,14 +53,14 @@ namespace MWBase virtual bool startDialogue(const MWWorld::Ptr& actor, ResponseCallback* callback) = 0; - virtual bool inJournal(const std::string& topicId, const std::string& infoId) = 0; + virtual bool inJournal(const std::string& topicId, const std::string& infoId) const = 0; virtual void addTopic(std::string_view topic) = 0; virtual void addChoice(std::string_view text, int choice) = 0; - virtual const std::vector>& getChoices() = 0; + virtual const std::vector>& getChoices() const = 0; - virtual bool isGoodbye() = 0; + virtual bool isGoodbye() const = 0; virtual void goodbye() = 0; diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index c12da74c4d..26e68350de 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -260,7 +260,7 @@ namespace MWDialogue } } - bool DialogueManager::inJournal(const std::string& topicId, const std::string& infoId) + bool DialogueManager::inJournal(const std::string& topicId, const std::string& infoId) const { const MWDialogue::Topic* topicHistory = nullptr; MWBase::Journal* journal = MWBase::Environment::get().getJournal(); @@ -528,12 +528,12 @@ namespace MWDialogue mChoices.emplace_back(text, choice); } - const std::vector>& DialogueManager::getChoices() + const std::vector>& DialogueManager::getChoices() const { return mChoices; } - bool DialogueManager::isGoodbye() + bool DialogueManager::isGoodbye() const { return mGoodbye; } diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index c4599e7550..d75a682768 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -84,14 +84,14 @@ namespace MWDialogue std::list getAvailableTopics() override; int getTopicFlag(const std::string& topicId) const override; - bool inJournal(const std::string& topicId, const std::string& infoId) override; + bool inJournal(const std::string& topicId, const std::string& infoId) const override; void addTopic(std::string_view topic) override; void addChoice(std::string_view text, int choice) override; - const std::vector>& getChoices() override; + const std::vector>& getChoices() const override; - bool isGoodbye() override; + bool isGoodbye() const override; void goodbye() override;