fix $item with names that are also specials

This commit is contained in:
Martin Michelsen
2023-06-19 15:32:27 -07:00
parent e8fcf2884a
commit 6468af6eb7
2 changed files with 38 additions and 27 deletions
+13 -2
View File
@@ -1409,7 +1409,7 @@ const unordered_map<uint32_t, ItemNameInfo> name_info_for_primary_identifier({
{0x031903, "Team Points 10000"}, {0x031903, "Team Points 10000"},
}); });
ItemData::ItemData(const string& orig_description) { ItemData::ItemData(const string& orig_description, bool skip_special) {
this->data1d.clear(0); this->data1d.clear(0);
this->id = 0xFFFFFFFF; this->id = 0xFFFFFFFF;
this->data2d = 0; this->data2d = 0;
@@ -1444,6 +1444,7 @@ ItemData::ItemData(const string& orig_description) {
} }
uint8_t weapon_special = 0; uint8_t weapon_special = 0;
if (!skip_special) {
for (const auto& it : name_for_weapon_special) { for (const auto& it : name_for_weapon_special) {
if (!it.second) { if (!it.second) {
continue; continue;
@@ -1456,6 +1457,7 @@ ItemData::ItemData(const string& orig_description) {
break; break;
} }
} }
}
static map<string, uint32_t> primary_identifier_for_name; static map<string, uint32_t> primary_identifier_for_name;
if (primary_identifier_for_name.empty()) { if (primary_identifier_for_name.empty()) {
@@ -1865,13 +1867,23 @@ ItemData item_for_string(const string& desc) {
try { try {
return ItemData(desc); return ItemData(desc);
} catch (const exception&) { } catch (const exception&) {
}
try {
return ItemData(desc, true);
} catch (const exception&) {
}
string data = parse_data_string(desc); string data = parse_data_string(desc);
if (data.size() < 2) { if (data.size() < 2) {
throw runtime_error("item code too short"); throw runtime_error("item code too short");
} }
if (data[0] > 4) {
throw runtime_error("invalid item class");
}
if (data.size() > 16) { if (data.size() > 16) {
throw runtime_error("item code too long"); throw runtime_error("item code too long");
} }
ItemData ret; ItemData ret;
if (data.size() <= 12) { if (data.size() <= 12) {
memcpy(ret.data1.data(), data.data(), data.size()); memcpy(ret.data1.data(), data.data(), data.size());
@@ -1881,4 +1893,3 @@ ItemData item_for_string(const string& desc) {
} }
return ret; return ret;
} }
}
+1 -1
View File
@@ -96,7 +96,7 @@ struct ItemData { // 0x14 bytes
} __attribute__((packed)); } __attribute__((packed));
ItemData(); ItemData();
explicit ItemData(const std::string& orig_description); explicit ItemData(const std::string& orig_description, bool skip_special = false);
ItemData(const ItemData& other); ItemData(const ItemData& other);
ItemData& operator=(const ItemData& other); ItemData& operator=(const ItemData& other);