From a95099cd03c1c6d21ab8bd450c536ec67d193f57 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Mon, 28 Feb 2022 18:20:47 +0200 Subject: [PATCH] [Client] Use item model's items for Container packet sent from Take All Previously, a Container packet sent when using the Take All button included all the items in the container, not just all the items in the container window seen on the client. This was a problem when stealing from actors, as the container window does not give access to all of their items. --- apps/openmw/mwgui/container.cpp | 30 ++++++++++++++++++------------ apps/openmw/mwmp/ObjectList.cpp | 16 ++++++++++++++++ apps/openmw/mwmp/ObjectList.hpp | 2 ++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/apps/openmw/mwgui/container.cpp b/apps/openmw/mwgui/container.cpp index af0742d23..25f8900f7 100644 --- a/apps/openmw/mwgui/container.cpp +++ b/apps/openmw/mwgui/container.cpp @@ -297,27 +297,33 @@ namespace MWGui /* Start of tes3mp addition - Trigger crimes related to the attempted taking of these items, if applicable - Send an ID_CONTAINER packet every time the Take All button is used on a container */ - for (size_t i = 0; i < mModel->getItemCount(); ++i) - { - const ItemStack& item = mModel->getItem(i); - - if (!onTakeItem(item, item.mCount)) - break; - } - mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); objectList->reset(); objectList->packetOrigin = mwmp::CLIENT_GAMEPLAY; objectList->cell = *mPtr.getCell()->getCell(); objectList->action = mwmp::BaseObjectList::REMOVE; objectList->containerSubAction = mwmp::BaseObjectList::TAKE_ALL; - objectList->addEntireContainer(mPtr); - objectList->sendContainer(); + mwmp::BaseObject baseObject = objectList->getBaseObjectFromPtr(mPtr); + + for (size_t i = 0; i < mModel->getItemCount(); ++i) + { + const ItemStack& item = mModel->getItem(i); + + // Trigger crimes related to the attempted taking of these items, if applicable + if (!onTakeItem(item, item.mCount)) + break; + + objectList->addContainerItem(baseObject, item, item.mCount, item.mCount); + } + + if (baseObject.containerItems.size() > 0) + { + objectList->addBaseObject(baseObject); + objectList->sendContainer(); + } /* End of tes3mp addition */ diff --git a/apps/openmw/mwmp/ObjectList.cpp b/apps/openmw/mwmp/ObjectList.cpp index edbb6af62..29c0f512b 100644 --- a/apps/openmw/mwmp/ObjectList.cpp +++ b/apps/openmw/mwmp/ObjectList.cpp @@ -112,6 +112,22 @@ void ObjectList::addContainerItem(mwmp::BaseObject& baseObject, const MWWorld::P baseObject.containerItems.push_back(containerItem); } +void ObjectList::addContainerItem(mwmp::BaseObject& baseObject, const MWGui::ItemStack& itemStack, int itemCount, int actionCount) +{ + mwmp::ContainerItem containerItem; + containerItem.refId = itemStack.mBase.getCellRef().getRefId(); + containerItem.count = itemCount; + containerItem.charge = itemStack.mBase.getCellRef().getCharge(); + containerItem.enchantmentCharge = itemStack.mBase.getCellRef().getEnchantmentCharge(); + containerItem.soul = itemStack.mBase.getCellRef().getSoul(); + containerItem.actionCount = actionCount; + + LOG_APPEND(TimedLog::LOG_VERBOSE, "--- Adding container item %s to packet with count %i and actionCount %i", + containerItem.refId.c_str(), itemCount, actionCount); + + baseObject.containerItems.push_back(containerItem); +} + void ObjectList::addContainerItem(mwmp::BaseObject& baseObject, const std::string itemId, int itemCount, int actionCount) { mwmp::ContainerItem containerItem; diff --git a/apps/openmw/mwmp/ObjectList.hpp b/apps/openmw/mwmp/ObjectList.hpp index 8ccf1be88..8fceed8cb 100644 --- a/apps/openmw/mwmp/ObjectList.hpp +++ b/apps/openmw/mwmp/ObjectList.hpp @@ -2,6 +2,7 @@ #define OPENMW_OBJECTLIST_HPP #include +#include "../mwgui/itemmodel.hpp" #include "../mwworld/worldimp.hpp" #include @@ -20,6 +21,7 @@ namespace mwmp void addBaseObject(BaseObject baseObject); mwmp::BaseObject getBaseObjectFromPtr(const MWWorld::Ptr& ptr); void addContainerItem(mwmp::BaseObject& baseObject, const MWWorld::Ptr& itemPtr, int itemCount, int actionCount); + void addContainerItem(mwmp::BaseObject& baseObject, const MWGui::ItemStack& itemStack, int itemCount, int actionCount); void addContainerItem(mwmp::BaseObject& baseObject, const std::string itemId, int itemCount, int actionCount); void addEntireContainer(const MWWorld::Ptr& ptr);