fix(inventory): inventory groups keep their locked flag, as the client

LWOInventoryComponent_Common::msgUpdateInventoryGroup (0x00c955b0) stores
the ADD's locked flag in the group; locked groups don't count toward the
50 user groups (msgGetInventoryGroupCount 0x00bde4b0 counts only unlocked
ones) and msgUpdateInventoryGroupContents (0x00ce1f50) applies the
1000-LOT cap only to unlocked groups. LoadFromSaveData (0x00d1ec40) reads
it from the grp element's u attribute. The server dropped the flag and
always saved u="0"; saves without u load as unlocked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-10-02 10:31:56 -05:00
parent 841004e6a4
commit 0b5a79cf96
3 changed files with 49 additions and 4 deletions

View File

@@ -2008,7 +2008,8 @@ void InventoryComponent::UpdateGroup(const GroupUpdate& groupUpdate) {
return;
}
if (groupUpdate.command == GroupUpdateCommand::ADD && groups.size() >= MaximumGroupCount) {
const auto unlockedGroups = std::ranges::count_if(groups, [](const Group& group) { return !group.locked; });
if (groupUpdate.command == GroupUpdateCommand::ADD && !groupUpdate.locked && unlockedGroups >= MaximumGroupCount) {
LOG("Cannot add group to inventory %s. Maximum group count reached.", StringifiedEnum::ToString(groupUpdate.inventory).data());
return;
}
@@ -2018,11 +2019,12 @@ void InventoryComponent::UpdateGroup(const GroupUpdate& groupUpdate) {
auto& group = groups.emplace_back();
group.groupId = groupUpdate.groupId;
group.groupName = groupUpdate.groupName;
group.locked = groupUpdate.locked;
break;
}
case GroupUpdateCommand::ADD_LOT: {
// msgUpdateInventoryGroupContents (0x00ce1f50): a group holds at most 1000 LOTs
if (groupItr->lots.size() >= MaximumGroupLotCount) break;
// msgUpdateInventoryGroupContents (0x00ce1f50): an unlocked group holds at most 1000 LOTs
if (!groupItr->locked && groupItr->lots.size() >= MaximumGroupLotCount) break;
groupItr->lots.insert(groupUpdate.lot);
break;
}
@@ -2057,7 +2059,7 @@ void InventoryComponent::UpdateGroupXml(tinyxml2::XMLElement& groups) const {
groupElement->SetAttribute("id", group.groupId.c_str());
groupElement->SetAttribute("n", group.groupName.c_str());
groupElement->SetAttribute("t", static_cast<uint32_t>(inventory));
groupElement->SetAttribute("u", 0);
groupElement->SetAttribute("u", group.locked ? 1 : 0);
std::ostringstream lots;
bool first = true;
for (const auto lot : group.lots) {
@@ -2084,6 +2086,8 @@ void InventoryComponent::LoadGroupXml(const tinyxml2::XMLElement& groups) {
groupElement->QueryStringAttribute("n", &groupName);
groupElement->QueryStringAttribute("l", &lots);
groupElement->QueryAttribute("t", &inventory);
bool locked = false;
groupElement->QueryBoolAttribute("u", &locked);
if (!groupId || !groupName || !lots) {
LOG("Failed to load group from xml id %i name %i lots %i",
@@ -2092,6 +2096,7 @@ void InventoryComponent::LoadGroupXml(const tinyxml2::XMLElement& groups) {
auto& group = m_Groups[static_cast<eInventoryType>(inventory)].emplace_back();
group.groupId = groupId;
group.groupName = groupName;
group.locked = locked;
for (const auto& lotStr : GeneralUtils::SplitString(lots, ' ')) {
auto lot = GeneralUtils::TryParse<LOT>(lotStr);
@@ -2409,6 +2414,7 @@ void InventoryComponent::OnUpdateInventoryGroup(const GameMessages::UpdateInvent
groupUpdate.inventory = msg.inventoryType;
// msgUpdateInventoryGroup (0x00c955b0) cuts names to 64 characters
groupUpdate.groupName = GeneralUtils::UTF16ToWTF8(msg.groupName.substr(0, MaximumGroupNameLength));
groupUpdate.locked = msg.locked;
if (msg.action == "ADD") groupUpdate.command = GroupUpdateCommand::ADD;
else if (msg.action == "MODIFY") groupUpdate.command = GroupUpdateCommand::MODIFY;

View File

@@ -78,6 +78,8 @@ public:
std::string groupName;
// All the lots the user has in the group.
std::set<LOT> lots;
// Locked groups don't count toward MaximumGroupCount and have no LOT cap (saved as u)
bool locked = false;
};
enum class GroupUpdateCommand {
@@ -97,6 +99,7 @@ public:
LOT lot;
eInventoryType inventory;
GroupUpdateCommand command;
bool locked = false;
};
static constexpr uint32_t MaximumGroupCount = 50;

View File

@@ -7,6 +7,7 @@
#include "InventoryMessages.h"
#include <gtest/gtest.h>
#include <tinyxml2.h>
// Inventory groups as LWOInventoryComponent_Common::msgUpdateInventoryGroup (0x00c955b0) and
// msgUpdateInventoryGroupContents (0x00ce1f50) keep them.
@@ -96,3 +97,38 @@ TEST_F(InventoryGroupTests, AGroupHoldsAtMost1000Lots) {
EXPECT_EQ(Groups()[0].lots.size(), 1000u);
EXPECT_FALSE(Groups()[0].lots.contains(1001));
}
TEST_F(InventoryGroupTests, LockedGroupsHaveNoLimits) {
for (uint32_t i = 0; i < InventoryComponent::MaximumGroupCount; i++) Group("ADD", "user_group" + std::to_string(i), u"g");
Group("ADD", "over", u"g");
EXPECT_EQ(Groups().size(), InventoryComponent::MaximumGroupCount);
Group("ADD", "locked", u"g", eInventoryType::BRICKS, true);
ASSERT_EQ(Groups().size(), InventoryComponent::MaximumGroupCount + 1);
EXPECT_TRUE(Groups().back().locked);
for (LOT lot = 1; lot <= 1001; lot++) Contents("ADD", "locked", lot);
EXPECT_EQ(Groups().back().lots.size(), 1001u);
}
TEST_F(InventoryGroupTests, TheLockedFlagIsSavedAndLoaded) {
Group("ADD", "locked", u"a", eInventoryType::BRICKS, true);
Group("ADD", "unlocked", u"b");
tinyxml2::XMLDocument doc;
doc.Parse("<obj><inv><bag/><items/></inv></obj>");
inventory->WriteSaveData(doc);
auto* const grp = doc.FirstChildElement("obj")->FirstChildElement("inv")->FirstChildElement("grps")->FirstChildElement("grp");
ASSERT_NE(grp, nullptr);
EXPECT_STREQ(grp->Attribute("u"), "1");
EXPECT_STREQ(grp->NextSiblingElement("grp")->Attribute("u"), "0");
// Saves from before have u="0" or no u
grp->NextSiblingElement("grp")->DeleteAttribute("u");
auto loaded = std::make_unique<Entity>(2, info);
auto* const loadedInventory = loaded->AddComponent<InventoryComponent>(-1);
loadedInventory->LoadXml(doc);
const auto& groups = loadedInventory->GetGroups().at(eInventoryType::BRICKS);
ASSERT_EQ(groups.size(), 2u);
EXPECT_TRUE(groups[0].locked);
EXPECT_FALSE(groups[1].locked);
}