Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GetItemLink crash #114

Merged
merged 3 commits into from
Apr 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/LuaEngine/ItemMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,9 @@ namespace LuaItem
const ItemTemplate* temp = item->GetTemplate();
std::string name = temp->Name1;
if (ItemLocale const* il = eObjectMgr->GetItemLocale(temp->ItemId))
{
ObjectMgr::GetLocaleString(il->Name, static_cast<LocaleConstant>(locale), name);
}

#ifndef CLASSIC
if (int32 itemRandPropId = item->GetItemRandomPropertyId())
Expand All @@ -284,34 +286,43 @@ namespace LuaItem
{
const ItemRandomSuffixEntry* itemRandEntry = sItemRandomSuffixStore.LookupEntry(-item->GetItemRandomPropertyId());
if (itemRandEntry)
{
#if TRINITY || AZEROTHCORE
suffix = &itemRandEntry->Name;
#else
suffix = itemRandEntry->nameSuffix;
#endif
}
}
else
{
const ItemRandomPropertiesEntry* itemRandEntry = sItemRandomPropertiesStore.LookupEntry(item->GetItemRandomPropertyId());
if (itemRandEntry)
{
#if TRINITY || AZEROTHCORE
suffix = &itemRandEntry->Name;
#else
suffix = itemRandEntry->nameSuffix;
#endif
}
}
if (suffix)
{
name += ' ';
#if TRINITY || AZEROTHCORE
name += (*suffix)[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)];
const char* suffixName = (*suffix)[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)];
#else
name += suffix[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)];
const char* suffixName = suffix[(name != temp->Name1) ? locale : uint8(DEFAULT_LOCALE)];
#endif
if (strcmp(suffixName, "") != 0)
{
name += ' ';
name += suffixName;
}
}
}
#endif

Player* owner = item->GetOwner();
std::ostringstream oss;
oss << "|c" << std::hex << ItemQualityColors[temp->Quality] << std::dec <<
"|Hitem:" << temp->ItemId << ":" <<
Expand All @@ -323,11 +334,7 @@ namespace LuaItem
item->GetEnchantmentId(BONUS_ENCHANTMENT_SLOT) << ":" <<
#endif
item->GetItemRandomPropertyId() << ":" << item->GetItemSuffixFactor() << ":" <<
#ifdef TRINITY
(uint32)item->GetOwner()->GetLevel() << "|h[" << name << "]|h|r";
#else
(uint32)item->GetOwner()->getLevel() << "|h[" << name << "]|h|r";
#endif
(uint32)(owner ? owner->GetLevel() : 0) << "|h[" << name << "]|h|r";

Eluna::Push(L, oss.str());
return 1;
Expand Down