From 382d458f9ce395e3f5f0358ad3a0caea5db4ca2f Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 13 Feb 2021 20:54:31 +0100 Subject: [PATCH 1/5] Ignore wrong reference class for SetHello --- apps/openmw/mwscript/aiextensions.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index 223ae3a152..d4de8ded5d 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -275,9 +275,11 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); Interpreter::Type_Integer value = runtime[0].mInteger; runtime.pop(); - - ptr.getClass().getCreatureStats(ptr).setAiSetting(mIndex, value); - ptr.getClass().setBaseAISetting(ptr.getCellRef().getRefId(), mIndex, value); + if(ptr.getClass().isActor()) + { + ptr.getClass().getCreatureStats(ptr).setAiSetting(mIndex, value); + ptr.getClass().setBaseAISetting(ptr.getCellRef().getRefId(), mIndex, value); + } } }; From 879e66a0439aa27a4d2af4341028334d4792bdfc Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 13 Feb 2021 20:55:24 +0100 Subject: [PATCH 2/5] Don't autoequip items when implicitely adding an item using equip --- apps/openmw/mwscript/containerextensions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 375242f17c..7eeb3bfaba 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -308,7 +308,8 @@ namespace MWScript } if (it == invStore.end()) { - it = ptr.getClass().getContainerStore (ptr).add (item, 1, ptr); + MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), item, 1); + it = ptr.getClass().getContainerStore (ptr).add (ref.getPtr(), 1, ptr, false); Log(Debug::Warning) << "Implicitly adding one " << item << " to the inventory store of " << ptr.getCellRef().getRefId() << " to fulfill the requirements of Equip instruction"; From 67c8d73fe01a31932adb437054805440857f0d71 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sun, 14 Feb 2021 16:25:38 +0100 Subject: [PATCH 3/5] Allow scripts to fail per target --- apps/openmw/mwscript/interpretercontext.cpp | 10 +++++++++- apps/openmw/mwscript/interpretercontext.hpp | 4 +++- apps/openmw/mwscript/scriptmanagerimp.cpp | 7 ++++--- apps/openmw/mwscript/scriptmanagerimp.hpp | 4 ++-- components/interpreter/context.hpp | 2 ++ 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index d8fd287d72..270b0ea549 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -129,6 +129,14 @@ namespace MWScript mGlobalScriptDesc = globalScriptDesc; } + std::string InterpreterContext::getTarget() const + { + auto ptr = getReference(false); + if(!ptr.isEmpty()) + return ptr.mRef->mRef.getRefId(); + return {}; + } + int InterpreterContext::getLocalShort (int index) const { if (!mLocals) @@ -474,7 +482,7 @@ namespace MWScript locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')] = value; } - MWWorld::Ptr InterpreterContext::getReference(bool required) + MWWorld::Ptr InterpreterContext::getReference(bool required) const { return getReferenceImp ("", true, required); } diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index 298454bcd2..84982f6356 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -47,6 +47,8 @@ namespace MWScript InterpreterContext (MWScript::Locals *locals, const MWWorld::Ptr& reference); ///< The ownership of \a locals is not transferred. 0-pointer allowed. + std::string getTarget() const override; + int getLocalShort (int index) const override; int getLocalLong (int index) const override; @@ -124,7 +126,7 @@ namespace MWScript void setMemberFloat (const std::string& id, const std::string& name, float value, bool global) override; - MWWorld::Ptr getReference(bool required=true); + MWWorld::Ptr getReference(bool required=true) const; ///< Reference, that the script is running from (can be empty) void updatePtr(const MWWorld::Ptr& base, const MWWorld::Ptr& updated); diff --git a/apps/openmw/mwscript/scriptmanagerimp.cpp b/apps/openmw/mwscript/scriptmanagerimp.cpp index e1652b311c..15b416fd04 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.cpp +++ b/apps/openmw/mwscript/scriptmanagerimp.cpp @@ -109,7 +109,8 @@ namespace MWScript } // execute script - if (!iter->second.mByteCode.empty() && iter->second.mActive) + std::string target = Misc::StringUtils::lowerCase(interpreterContext.getTarget()); + if (!iter->second.mByteCode.empty() && iter->second.mInactive.find(target) == iter->second.mInactive.end()) try { if (!mOpcodesInstalled) @@ -129,7 +130,7 @@ namespace MWScript { Log(Debug::Error) << "Execution of script " << name << " failed: " << e.what(); - iter->second.mActive = false; // don't execute again. + iter->second.mInactive.insert(target); // don't execute again. } return false; } @@ -138,7 +139,7 @@ namespace MWScript { for (auto& script : mScripts) { - script.second.mActive = true; + script.second.mInactive.clear(); } mGlobalScripts.clear(); diff --git a/apps/openmw/mwscript/scriptmanagerimp.hpp b/apps/openmw/mwscript/scriptmanagerimp.hpp index 7ddcd2489d..04693eea6a 100644 --- a/apps/openmw/mwscript/scriptmanagerimp.hpp +++ b/apps/openmw/mwscript/scriptmanagerimp.hpp @@ -2,6 +2,7 @@ #define GAME_SCRIPT_SCRIPTMANAGER_H #include +#include #include #include @@ -45,13 +46,12 @@ namespace MWScript { std::vector mByteCode; Compiler::Locals mLocals; - bool mActive; + std::set mInactive; CompiledScript(const std::vector& code, const Compiler::Locals& locals) { mByteCode = code; mLocals = locals; - mActive = true; } }; diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 862018bdc0..18d36ffee9 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -12,6 +12,8 @@ namespace Interpreter virtual ~Context() {} + virtual std::string getTarget() const = 0; + virtual int getLocalShort (int index) const = 0; virtual int getLocalLong (int index) const = 0; From 690e5ef7574f6eb0e8038ab9f1c6b4b61b724fd5 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Thu, 11 Mar 2021 20:47:26 +0100 Subject: [PATCH 4/5] Don't resolve a script's target just to get the ID --- apps/openmw/mwscript/globalscripts.cpp | 20 ++++++++++++++++++++ apps/openmw/mwscript/globalscripts.hpp | 2 ++ apps/openmw/mwscript/interpretercontext.cpp | 7 ++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index b287d33b3d..9de08fbce3 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -92,6 +92,21 @@ namespace return false; } }; + + struct IdGettingVisitor : public boost::static_visitor + { + std::string operator()(const MWWorld::Ptr& ptr) const + { + if(ptr.isEmpty()) + return {}; + return ptr.mRef->mRef.getRefId(); + } + + std::string operator()(const std::pair& pair) const + { + return pair.second; + } + }; } namespace MWScript @@ -110,6 +125,11 @@ namespace MWScript return ptr; } + std::string GlobalScriptDesc::getId() const + { + return boost::apply_visitor(IdGettingVisitor(), mTarget); + } + GlobalScripts::GlobalScripts (const MWWorld::ESMStore& store) : mStore (store) diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 049e78804a..cd70f4e667 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -44,6 +44,8 @@ namespace MWScript const MWWorld::Ptr* getPtrIfPresent() const; // Returns a Ptr if one has been resolved MWWorld::Ptr getPtr(); // Resolves mTarget to a Ptr and caches the (potentially empty) result + + std::string getId() const; // Returns the target's ID -- if any }; class GlobalScripts diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 270b0ea549..2e8f72e629 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -131,9 +131,10 @@ namespace MWScript std::string InterpreterContext::getTarget() const { - auto ptr = getReference(false); - if(!ptr.isEmpty()) - return ptr.mRef->mRef.getRefId(); + if(!mReference.isEmpty()) + return mReference.mRef->mRef.getRefId(); + else if(mGlobalScriptDesc) + return mGlobalScriptDesc->getId(); return {}; } From 2db7495d438b2321dece049b6e52b2b921e069d5 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Sat, 19 Jun 2021 19:27:32 +0200 Subject: [PATCH 5/5] add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 110eaf21d4..0e4a5e9024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.48.0 ------ + Bug #3737: Scripts from The Underground 2 .esp do not play (all patched versions) Bug #3846: Strings starting with "-" fail to compile if not enclosed in quotes 0.47.0