Skip to content

Commit

Permalink
[Fix] Item name register from appearances protobuf #376
Browse files Browse the repository at this point in the history
It was missing the item name register on the function void Items::loadFromProtobuf() on the Items map. This map is used to identify a item by it's name instead of ID. This is largely used on the SRC and LUA environments.

This wrong behavior on the items name register was affecting only items who had their names on the appearances.dat protobuf file but was not registered on the items.xml file.
  • Loading branch information
marcosvf132 committed May 4, 2022
1 parent 44c8e82 commit a4073d7
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/items/items.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ void Items::loadFromProtobuf()
iType.lookThrough = object.flags().ignore_look();
iType.stackable = object.flags().cumulative();
iType.isPodium = object.flags().show_off_socket();

if (!iType.name.empty()) {
nameToItems.insert({
asLowerCaseString(iType.name),
iType.id
});
}
}

items.shrink_to_fit();
Expand Down Expand Up @@ -259,13 +266,24 @@ void Items::parseItemNode(const pugi::xml_node & itemNode, uint16_t id) {
return;
}

bool isNameRegistered = !itemType.name.empty();
if (isNameRegistered && itemType.name != itemNode.attribute("name").as_string()) {
if (auto result = nameToItems.find(asLowerCaseString(itemType.name));
result != nameToItems.end()) {
nameToItems.erase(result);
isNameRegistered = false;
}
}

itemType.loaded = true;
itemType.name = itemNode.attribute("name").as_string();

nameToItems.insert({
asLowerCaseString(itemType.name),
id
});
if (!isNameRegistered) {
nameToItems.insert({
asLowerCaseString(itemType.name),
id
});
}

pugi::xml_attribute articleAttribute = itemNode.attribute("article");
if (articleAttribute) {
Expand Down Expand Up @@ -336,4 +354,4 @@ bool Items::hasItemType(size_t hasId) const
return true;
}
return false;
}
}

0 comments on commit a4073d7

Please sign in to comment.