From 343dd8b5ea043ac7ae4ec33558e07453939b4f8c Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 26 Dec 2018 13:41:19 +0200 Subject: [PATCH] [Client] Fix addition of items to player inventories Previously, multiple stacks of the same item ID could overwrite data in each other because of how the logic in ContainerStore::add() works. For example, a stack of 5 grand soul gems with no souls would get added to the player, then the attempt to add a grand soul gem with a particular soul would retrieve the previous stack first before setting all of it to that soul, resulting in 6 grand soul gems with that soul. --- apps/openmw/mwmp/LocalPlayer.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 027786852..1d7c3899e 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -675,6 +675,7 @@ void LocalPlayer::updateAnimFlags(bool forceUpdate) void LocalPlayer::addItems() { MWWorld::Ptr ptrPlayer = getPlayerPtr(); + const MWWorld::ESMStore &esmStore = MWBase::Environment::get().getWorld()->getStore(); MWWorld::ContainerStore &ptrStore = ptrPlayer.getClass().getContainerStore(ptrPlayer); for (const auto &item : inventoryChanges.items) @@ -685,7 +686,9 @@ void LocalPlayer::addItems() try { - MWWorld::Ptr itemPtr = *ptrStore.add(item.refId, item.count, ptrPlayer); + MWWorld::ManualRef itemRef(esmStore, item.refId, item.count); + MWWorld::Ptr itemPtr = itemRef.getPtr(); + if (item.charge != -1) itemPtr.getCellRef().setCharge(item.charge); @@ -694,6 +697,8 @@ void LocalPlayer::addItems() if (!item.soul.empty()) itemPtr.getCellRef().setSoul(item.soul); + + ptrStore.add(itemPtr, item.count, ptrPlayer); } catch (std::exception&) {