aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-09-01 22:02:22 +0200
committerGitHub <noreply@github.com>2020-09-01 22:02:22 +0200
commitd0b91f69279a823be159590c09945bc426f50d3e (patch)
tree1545fbeca0c4e86c3b3db22fe8a46f4b466afcde /src
parent3fbbe7cfbe1bc51db12bdc1ec7b21c16d1716366 (diff)
Core/Misc: More DBC std::array refactors, stricter |Hitem checks, and more hyperlink unit tests
Diffstat (limited to 'src')
-rw-r--r--src/server/game/AuctionHouse/AuctionHouseMgr.cpp8
-rw-r--r--src/server/game/Chat/HyperlinkTags.cpp44
-rw-r--r--src/server/game/Chat/Hyperlinks.cpp23
-rw-r--r--src/server/game/Chat/Hyperlinks.h7
-rw-r--r--src/server/shared/DataStores/DBCStructure.h28
5 files changed, 71 insertions, 39 deletions
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
index 93fcedf17bb..86efd1a63a1 100644
--- a/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
+++ b/src/server/game/AuctionHouse/AuctionHouseMgr.cpp
@@ -796,19 +796,19 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
// These are found in ItemRandomSuffix.dbc and ItemRandomProperties.dbc
// even though the DBC names seem misleading
- char const* const* suffix = nullptr;
+ std::array<char const*, 16> const* suffix = nullptr;
if (propRefID < 0)
{
ItemRandomSuffixEntry const* itemRandSuffix = sItemRandomSuffixStore.LookupEntry(-propRefID);
if (itemRandSuffix)
- suffix = itemRandSuffix->Name;
+ suffix = &itemRandSuffix->Name;
}
else
{
ItemRandomPropertiesEntry const* itemRandProp = sItemRandomPropertiesStore.LookupEntry(propRefID);
if (itemRandProp)
- suffix = itemRandProp->Name;
+ suffix = &itemRandProp->Name;
}
// dbc local name
@@ -817,7 +817,7 @@ void AuctionHouseObject::BuildListAuctionItems(WorldPacket& data, Player* player
// Append the suffix (ie: of the Monkey) to the name using localization
// or default enUS if localization is invalid
name += ' ';
- name += suffix[locdbc_idx >= 0 ? locdbc_idx : LOCALE_enUS];
+ name += (*suffix)[locdbc_idx >= 0 ? locdbc_idx : LOCALE_enUS];
}
}
diff --git a/src/server/game/Chat/HyperlinkTags.cpp b/src/server/game/Chat/HyperlinkTags.cpp
index d511265c537..35c47c04c0d 100644
--- a/src/server/game/Chat/HyperlinkTags.cpp
+++ b/src/server/game/Chat/HyperlinkTags.cpp
@@ -113,9 +113,47 @@ bool Trinity::Hyperlinks::LinkTags::item::StoreTo(ItemLinkData& val, std::string
if (!t.TryConsumeTo(itemId))
return false;
val.Item = sObjectMgr->GetItemTemplate(itemId);
- return val.Item && t.TryConsumeTo(val.EnchantId) && t.TryConsumeTo(val.GemEnchantId[0]) && t.TryConsumeTo(val.GemEnchantId[1]) &&
- t.TryConsumeTo(val.GemEnchantId[2]) && t.TryConsumeTo(dummy) && t.TryConsumeTo(val.RandomPropertyId) && t.TryConsumeTo(val.RandomPropertySeed) &&
- t.TryConsumeTo(val.RenderLevel) && t.IsEmpty() && !dummy;
+
+ int randomPropertyId;
+ if (!(val.Item && t.TryConsumeTo(val.EnchantId) && t.TryConsumeTo(val.GemEnchantId[0]) && t.TryConsumeTo(val.GemEnchantId[1]) &&
+ t.TryConsumeTo(val.GemEnchantId[2]) && t.TryConsumeTo(dummy) && t.TryConsumeTo(randomPropertyId) && t.TryConsumeTo(val.RandomSuffixBaseAmount) &&
+ t.TryConsumeTo(val.RenderLevel) && t.IsEmpty() && !dummy))
+ return false;
+
+ if (randomPropertyId < 0)
+ {
+ if (!val.Item->RandomSuffix)
+ return false;
+ if (ItemRandomSuffixEntry const* suffixEntry = sItemRandomSuffixStore.LookupEntry(-randomPropertyId))
+ {
+ val.RandomSuffix = suffixEntry;
+ val.RandomProperty = nullptr;
+ }
+ else
+ return false;
+ }
+ else if (randomPropertyId > 0)
+ {
+ if (!val.Item->RandomProperty)
+ return false;
+ if (ItemRandomPropertiesEntry const* propEntry = sItemRandomPropertiesStore.LookupEntry(randomPropertyId))
+ {
+ val.RandomSuffix = nullptr;
+ val.RandomProperty = propEntry;
+ }
+ else
+ return false;
+ }
+ else
+ {
+ val.RandomSuffix = nullptr;
+ val.RandomProperty = nullptr;
+ }
+
+ if ((val.RandomSuffix && !val.RandomSuffixBaseAmount) || (val.RandomSuffixBaseAmount && !val.RandomSuffix))
+ return false;
+
+ return true;
}
bool Trinity::Hyperlinks::LinkTags::quest::StoreTo(QuestLinkData& val, std::string_view text)
diff --git a/src/server/game/Chat/Hyperlinks.cpp b/src/server/game/Chat/Hyperlinks.cpp
index 308ec33d46d..8b82cb1e38c 100644
--- a/src/server/game/Chat/Hyperlinks.cpp
+++ b/src/server/game/Chat/Hyperlinks.cpp
@@ -132,21 +132,11 @@ struct LinkValidator<LinkTags::item>
{
ItemLocale const* locale = sObjectMgr->GetItemLocale(data.Item->ItemId);
- char const* const* randomSuffixes = nullptr; // this is a c-style array of c strings (and i don't want to touch DBCStructure.h right now)
- if (data.RandomPropertyId < 0)
- {
- if (ItemRandomSuffixEntry const* suffixEntry = sItemRandomSuffixStore.LookupEntry(-data.RandomPropertyId))
- randomSuffixes = suffixEntry->Name;
- else
- return false;
- }
- else if (data.RandomPropertyId > 0)
- {
- if (ItemRandomPropertiesEntry const* propEntry = sItemRandomPropertiesStore.LookupEntry(data.RandomPropertyId))
- randomSuffixes = propEntry->Name;
- else
- return false;
- }
+ std::array<char const*, 16> const* randomSuffixes = nullptr;
+ if (data.RandomProperty)
+ randomSuffixes = &data.RandomProperty->Name;
+ else if (data.RandomSuffix)
+ randomSuffixes = &data.RandomSuffix->Name;
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
@@ -157,8 +147,9 @@ struct LinkValidator<LinkTags::item>
continue;
if (randomSuffixes)
{
- std::string_view randomSuffix(randomSuffixes[i]);
+ std::string_view randomSuffix((*randomSuffixes)[i]);
if (
+ (!randomSuffix.empty()) &&
(text.length() == (name.length() + 1 + randomSuffix.length())) &&
(text.substr(0, name.length()) == name) &&
(text[name.length()] == ' ') &&
diff --git a/src/server/game/Chat/Hyperlinks.h b/src/server/game/Chat/Hyperlinks.h
index 69bfdb28ff0..4a263df4a01 100644
--- a/src/server/game/Chat/Hyperlinks.h
+++ b/src/server/game/Chat/Hyperlinks.h
@@ -29,6 +29,8 @@
struct AchievementEntry;
struct GlyphPropertiesEntry;
struct GlyphSlotEntry;
+struct ItemRandomPropertiesEntry;
+struct ItemRandomSuffixEntry;
struct ItemTemplate;
class SpellInfo;
class Quest;
@@ -59,8 +61,9 @@ namespace Trinity::Hyperlinks
ItemTemplate const* Item;
uint32 EnchantId;
std::array<uint32, 3> GemEnchantId;
- int32 RandomPropertyId;
- int32 RandomPropertySeed;
+ ItemRandomPropertiesEntry const* RandomProperty;
+ ItemRandomSuffixEntry const* RandomSuffix;
+ uint32 RandomSuffixBaseAmount;
uint8 RenderLevel;
};
diff --git a/src/server/shared/DataStores/DBCStructure.h b/src/server/shared/DataStores/DBCStructure.h
index e3b67d43703..753067043b6 100644
--- a/src/server/shared/DataStores/DBCStructure.h
+++ b/src/server/shared/DataStores/DBCStructure.h
@@ -951,24 +951,24 @@ struct ItemLimitCategoryEntry
struct ItemRandomPropertiesEntry
{
- uint32 ID; // 0
- //char const* InternalName; // 1
- uint32 Enchantment[MAX_ITEM_ENCHANTMENT_EFFECTS]; // 2-4
- //uint32 UnusedEnchantment[2]; // 5-6
- char const* Name[16]; // 7-22
- //uint32 Name_lang_mask; // 23
+ uint32 ID; // 0
+ //char const* InternalName; // 1
+ std::array<uint32, MAX_ITEM_ENCHANTMENT_EFFECTS> Enchantment; // 2-4
+ //std::array<uint32, 2> UnusedEnchantment; // 5-6
+ std::array<char const*, 16> Name; // 7-22
+ //uint32 Name_lang_mask; // 23
};
struct ItemRandomSuffixEntry
{
- uint32 ID; // 0
- char const* Name[16]; // 1-16
- //uint32 Name_lang_mask; // 17
- //char const* InternalName; // 18
- uint32 Enchantment[MAX_ITEM_ENCHANTMENT_EFFECTS]; // 19-21
- //uint32 UnusedEnchantment[2] // 22-23
- uint32 AllocationPct[MAX_ITEM_ENCHANTMENT_EFFECTS]; // 24-26
- //uint32 UnusedAllocationPct[2] // 27-28
+ uint32 ID; // 0
+ std::array<char const*, 16> Name; // 1-16
+ //uint32 Name_lang_mask; // 17
+ //char const* InternalName; // 18
+ std::array<uint32, MAX_ITEM_ENCHANTMENT_EFFECTS> Enchantment; // 19-21
+ //std::array<uint32, 2> UnusedEnchantment; // 22-23
+ std::array<uint32, MAX_ITEM_ENCHANTMENT_EFFECTS> AllocationPct; // 24-26
+ //std::array<uint32, 2> UnusedAllocationPct; // 27-28
};
#define MAX_ITEM_SET_ITEMS 10