From aa92128cf2e3017de054713c7fbfc6ed6d82507d Mon Sep 17 00:00:00 2001 From: David Cernat Date: Sat, 16 Apr 2022 01:30:51 +0300 Subject: [PATCH] [Client] Fix logic for sending ObjectState packets The previous logic was meant to prevent packet spam from local scripts, but inadvertently prevented objects from being enabled or disabled correctly from dialogue in certain quests. Enabling and disabling objects from dialogue and the console is now always allowed to go through. --- apps/openmw/mwscript/miscextensions.cpp | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index d26c54ab6..5c6b2c8ea 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -195,21 +195,23 @@ namespace MWScript /* Start of tes3mp addition - Send an ID_OBJECT_STATE packet whenever an object is enabled, as long as - the player is logged in on the server, the object is still disabled, and our last - packet regarding its state did not already attempt to enable it (to prevent + Send an ID_OBJECT_STATE packet whenever an object should be enabled, as long as the + player is logged in on the server and — if triggered from a clientside script — our + last packet regarding its state did not already attempt to enable it (to prevent packet spam) */ if (mwmp::Main::get().getLocalPlayer()->isLoggedIn()) { - if (ptr.isInCell() && !ptr.getRefData().isEnabled() && - ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Enabled) + unsigned char packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); + + if (packetOrigin == Interpreter::Context::CONSOLE || packetOrigin == Interpreter::Context::DIALOGUE || + (ptr.isInCell() && ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Enabled)) { ptr.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Enabled); mwmp::ObjectList* objectList = mwmp::Main::get().getNetworking()->getObjectList(); objectList->reset(); - objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); + objectList->packetOrigin = packetOrigin; objectList->originClientScript = runtime.getContext().getCurrentScriptName(); objectList->addObjectState(ptr, true); objectList->sendObjectState(); @@ -244,21 +246,23 @@ namespace MWScript /* Start of tes3mp addition - Send an ID_OBJECT_STATE packet whenever an object should be disabled, as long as - the player is logged in on the server, the object is still enabled, and our last - packet regarding its state did not already attempt to disable it (to prevent + Send an ID_OBJECT_STATE packet whenever an object should be disabled, as long as the + player is logged in on the server and — if triggered from a clientside script — our + last packet regarding its state did not already attempt to disable it (to prevent packet spam) */ if (mwmp::Main::get().getLocalPlayer()->isLoggedIn()) { - if (ptr.isInCell() && ptr.getRefData().isEnabled() && - ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Disabled) + unsigned char packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); + + if (packetOrigin == Interpreter::Context::CONSOLE || packetOrigin == Interpreter::Context::DIALOGUE || + (ptr.isInCell() && ptr.getRefData().getLastCommunicatedState() != MWWorld::RefData::StateCommunication::Disabled)) { ptr.getRefData().setLastCommunicatedState(MWWorld::RefData::StateCommunication::Disabled); mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); objectList->reset(); - objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); + objectList->packetOrigin = packetOrigin; objectList->originClientScript = runtime.getContext().getCurrentScriptName(); objectList->addObjectState(ptr, false); objectList->sendObjectState();