[Client] Allow unilateral scripted container changes not from console

This prevents infinite loops in certain client scripts from mods that use while loops to determine that all items of a certain type have been removed from a container, such as in the script BCSwap2Arg from  Better_Clothes.
experimental-mono
David Cernat 6 years ago
parent 99f8ef88a5
commit a8cf1e02c4

@ -80,18 +80,24 @@ namespace MWScript
/* /*
Start of tes3mp change (major) Start of tes3mp change (major)
Disable unilateral item addition on this client and expect the server's reply to our Allow unilateral item removal on this client from client scripts and dialogue (but not console commands)
packet to do it instead, except for changes to player inventories which still require to prevent infinite loops in certain mods. Otherwise, expect the server's reply to our packet to do the
the PlayerInventory to be reworked removal instead, except for changes to player inventories which still require the PlayerInventory to be
reworked.
*/ */
// Spawn a messagebox (only for items added to player's inventory and if player is talking to someone) unsigned char packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType());
if (ptr == MWBase::Environment::get().getWorld ()->getPlayerPtr() )
{ MWWorld::Ptr itemPtr;
MWWorld::Ptr itemPtr = *ptr.getClass().getContainerStore(ptr).add(item, count, ptr);
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr() || packetOrigin != mwmp::CLIENT_CONSOLE)
itemPtr = *ptr.getClass().getContainerStore(ptr).add(item, count, ptr);
/* /*
End of tes3mp change (major) End of tes3mp change (major)
*/ */
// Spawn a messagebox (only for items added to player's inventory and if player is talking to someone)
if (ptr == MWBase::Environment::get().getWorld()->getPlayerPtr())
{
// The two GMST entries below expand to strings informing the player of what, and how many of it has been added to their inventory // The two GMST entries below expand to strings informing the player of what, and how many of it has been added to their inventory
std::string msgBox; std::string msgBox;
std::string itemName = itemPtr.getClass().getName(itemPtr); std::string itemName = itemPtr.getClass().getName(itemPtr);
@ -118,7 +124,7 @@ namespace MWScript
{ {
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset(); objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); objectList->packetOrigin = packetOrigin;
objectList->cell = *ptr.getCell()->getCell(); objectList->cell = *ptr.getCell()->getCell();
objectList->action = mwmp::BaseObjectList::ADD; objectList->action = mwmp::BaseObjectList::ADD;
objectList->containerSubAction = mwmp::BaseObjectList::NONE; objectList->containerSubAction = mwmp::BaseObjectList::NONE;
@ -203,13 +209,15 @@ namespace MWScript
/* /*
Start of tes3mp change (major) Start of tes3mp change (major)
Disable unilateral item removal on this client and expect the server's reply to our Allow unilateral item removal on this client from client scripts and dialogue (but not console commands)
packet to do it instead, except for changes to player inventories which still require to prevent infinite loops in certain mods. Otherwise, expect the server's reply to our packet to do the
the PlayerInventory to be reworked removal instead, except for changes to player inventories which still require the PlayerInventory to be
reworked.
*/ */
unsigned char packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType());
int numRemoved = 0; int numRemoved = 0;
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer() || packetOrigin != mwmp::CLIENT_CONSOLE)
numRemoved = store.remove(item, count, ptr); numRemoved = store.remove(item, count, ptr);
// Spawn a messagebox (only for items removed from player's inventory) // Spawn a messagebox (only for items removed from player's inventory)
@ -246,7 +254,7 @@ namespace MWScript
{ {
mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList(); mwmp::ObjectList *objectList = mwmp::Main::get().getNetworking()->getObjectList();
objectList->reset(); objectList->reset();
objectList->packetOrigin = ScriptController::getPacketOriginFromContextType(runtime.getContext().getContextType()); objectList->packetOrigin = packetOrigin;
objectList->cell = *ptr.getCell()->getCell(); objectList->cell = *ptr.getCell()->getCell();
objectList->action = mwmp::BaseObjectList::REMOVE; objectList->action = mwmp::BaseObjectList::REMOVE;
objectList->containerSubAction = mwmp::BaseObjectList::NONE; objectList->containerSubAction = mwmp::BaseObjectList::NONE;

Loading…
Cancel
Save