diff --git a/WoW/Source/DB/DBClient/DBCache.cpp b/WoW/Source/DB/DBClient/DBCache.cpp index 6b568cc..37a6bf9 100644 --- a/WoW/Source/DB/DBClient/DBCache.cpp +++ b/WoW/Source/DB/DBClient/DBCache.cpp @@ -69,16 +69,6 @@ bool DBCacheIsNullKey(const CWardenKey& key) { return true; } -// INLINED -uint32_t DBCacheHashKey(int32_t key) { - return key; -} - -// INLINED -uint32_t DBCacheHashKey(uint64_t key) { - return static_cast(key); -} - // INLINED uint32_t DBCacheHashKey(const CWardenKey& key) { return key.Hash(); diff --git a/WoW/Source/DB/DBClient/DBCache.h b/WoW/Source/DB/DBClient/DBCache.h index 3f4d72f..be6719e 100644 --- a/WoW/Source/DB/DBClient/DBCache.h +++ b/WoW/Source/DB/DBClient/DBCache.h @@ -43,8 +43,8 @@ class DBCache : public Blizzard::Using::GlobalUse { TSLink m_pendingLink; }; - struct REVERSEENTRY : public TSHashObject { - TKey m_id; + struct REVERSEENTRY : public TSHashObject { + T* m_record; }; /* 0008 */ TSHashTable m_entries; @@ -60,14 +60,14 @@ class DBCache : public Blizzard::Using::GlobalUse { /* 004C */ uint32_t m_queriesSent; /* 0050 */ uint32_t m_nextQueryTime; /* 0054 */ TSExplicitList m_pending; - /* 0060 */ TSHashTable m_reverse; + /* 0060 */ TSHashTable m_reverse; virtual void InvalidateIntKey(int32_t key); DBCache(uint32_t signature, const char* fileName, uint32_t queryOpcode, uint32_t multipleQueryOpcode, bool sendRequester, bool enabled, uint32_t queriesPerMinute); ~DBCache(); void AddItem(T* item, TKey key); - void AddItems(CDataStore* msg, bool notify); + void AddItems(CDataStore* msg, bool single); void CancelCallback(TKey key, void (*callback)(int32_t id, const WOWGUID& guid, void* param, bool success), void* param); void Clear(); void ClearPending(); @@ -75,6 +75,9 @@ class DBCache : public Blizzard::Using::GlobalUse { T* GetRecord(TKey key, const WOWGUID& guid, void (*callback)(int32_t id, const WOWGUID& guid, void* param, bool success), void* param, bool unique); void Destroy(); void Invalidate(TKey key); + REVERSEENTRY* FindReverseEntry(const char* name); + T* GetRecordByName(const char* name); + void RemoveReverseEntry(const char* name); void ItemAdded(T* item); void Load(); void RetryItem(TKey key); @@ -93,11 +96,19 @@ void DBCacheWriteKey(CDataStore& msg, const CWardenKey& key); bool DBCacheIsNullKey(int32_t key); bool DBCacheIsNullKey(uint64_t key); bool DBCacheIsNullKey(const CWardenKey& key); -uint32_t DBCacheHashKey(int32_t key); -uint32_t DBCacheHashKey(uint64_t key); uint32_t DBCacheHashKey(const CWardenKey& key); void GetCacheDirectory(char* path); +// INLINED +inline uint32_t DBCacheHashKey(int32_t key) { + return key; +} + +// INLINED +inline uint32_t DBCacheHashKey(uint64_t key) { + return static_cast(key); +} + // VERIFY: 8997838f auto // OFFSET: [0x00675C80, 0x00675DB0, 0x00675EE0, 0x00676010, 0x00676140, 0x00676270, 0x006763A0, 0x006764D0, 0x00676600, 0x00676730, 0x00676860, 0x00676990, 0x00676AC0, 0x00676BF0, 0x00676D20] template @@ -473,4 +484,115 @@ void DBCache::VerifyAndUpdateVersion(uint32_t version) { this->m_version = version; } +// VERIFY: 27b57ae6 manual +// OFFSET: [0x0067CBD0] +template +void DBCache::AddItems(CDataStore* msg, bool single) { + uint8_t count; + + if (single) { + count = 1; + } else { + msg->Get(count); + + if (!count) { + return; + } + } + + do { + bool denied = false; + uint32_t id; + msg->Get(id); + + if (static_cast(id) < 0) { + id &= 0x7FFFFFFF; + denied = true; + } + + TKey key = id; + + DBCACHEHASH* hash = this->m_entries.Ptr(DBCacheHashKey(key), key); + + if (denied) { + if (hash) { + hash->m_dispatching = true; + + for (DBCACHECALLBACK* node = hash->m_callbacks.Head(); node;) { + DBCACHECALLBACK* next = hash->m_callbacks.Next(node); + node->m_callback(key, node->m_guid, node->m_param, false); + node = next; + } + + hash->m_dispatching = false; + this->m_entries.Delete(hash); + } + } else { + if (!hash) { + hash = this->m_entries.New(DBCacheHashKey(key), key, 0, 0); + } + + hash->m_dispatching = true; + hash->m_record.Unpack(msg); + hash->m_loaded = true; + hash->m_id = key; + + for (DBCACHECALLBACK* node = hash->m_callbacks.Head(); node;) { + DBCACHECALLBACK* next = hash->m_callbacks.Next(node); + node->m_callback(key, node->m_guid, node->m_param, true); + node = next; + } + + hash->m_callbacks.Clear(); + bool invalidate = hash->m_invalidatePending; + hash->m_dispatching = false; + + if (invalidate) { + this->Invalidate(key); + } + } + } while (--count); +} + +// VERIFY: e5e95050 manual +// OFFSET: [0x0067A070] +template +void DBCache::DenyItem(TKey key) { + DBCACHEHASH* hash = this->m_entries.Ptr(DBCacheHashKey(key), key); + + if (!hash) { + return; + } + + hash->m_dispatching = true; + + for (DBCACHECALLBACK* node = hash->m_callbacks.Head(); node;) { + DBCACHECALLBACK* next = hash->m_callbacks.Next(node); + node->m_callback(static_cast(key), node->m_guid, node->m_param, false); + node = next; + } + + hash->m_dispatching = false; + this->m_entries.Delete(hash); +} + +// VERIFY: 80ad7a9d auto +// OFFSET: [0x0067A170] +template +void DBCache::Invalidate(TKey key) { + DBCACHEHASH* hash = this->m_entries.Ptr(DBCacheHashKey(key), key); + + if (!hash) { + return; + } + + if (!hash->m_loaded) { + this->DenyItem(key); + } else if (hash->m_dispatching) { + hash->m_invalidatePending = true; + } else { + this->m_entries.Delete(hash); + } +} + #endif diff --git a/WoW/Source/DB/DBClient/DBCacheInstances.cpp b/WoW/Source/DB/DBClient/DBCacheInstances.cpp index dcd9986..0f67125 100644 --- a/WoW/Source/DB/DBClient/DBCacheInstances.cpp +++ b/WoW/Source/DB/DBClient/DBCacheInstances.cpp @@ -517,3 +517,111 @@ void DBCache_ClearTemporaryCaches() { g_danceCache.Clear(); } } + +// VERIFY: db411930 manual +// OFFSET: 0x0066FFE0 +template <> +DBCache::REVERSEENTRY* DBCache::FindReverseEntry(const char* name) { + if (this->m_reverse.m_slotmask == 0xFFFFFFFF) { + return nullptr; + } + + uint32_t hashval = SStrHashHT(name); + TSExplicitList& list = this->m_reverse.m_slotlistarray[hashval & this->m_reverse.m_slotmask]; + + for (REVERSEENTRY* entry = list.Head(); entry; entry = list.Next(entry)) { + if (entry->m_hashval == hashval && (entry->m_key.m_str == name || !SStrCmpUTF8I(entry->m_key.m_str, name, STORM_MAX_STR))) { + return entry; + } + } + + return nullptr; +} + +// VERIFY: 4c9eb627 auto +// OFFSET: 0x006701F0 +template <> +NameCache* DBCache::GetRecordByName(const char* name) { + REVERSEENTRY* entry = this->FindReverseEntry(name); + return entry ? entry->m_record : nullptr; +} + +// VERIFY: fd608d3a manual +// OFFSET: 0x00678F20 +template <> +void DBCache::RemoveReverseEntry(const char* name) { + REVERSEENTRY* entry = this->FindReverseEntry(name); + + if (!entry) { + SErrSetLastError(87); + return; + } + + this->m_reverse.Delete(entry); +} + +// VERIFY: a4de3f42 auto +// OFFSET: 0x00680C20 +template <> +void DBCache::ItemAdded(NameCache* item) { + if (this->FindReverseEntry(item->m_name)) { + return; + } + + uint32_t hashval = SStrHashHT(item->m_name); + REVERSEENTRY* entry = this->m_reverse.InternalNewNode(hashval, 0, 0); + entry->m_hashval = hashval; + entry->m_key.m_str = item->m_name; + entry->m_record = item; +} + +// VERIFY: 499cc0d7 auto +// OFFSET: 0x0067A430 +template <> +void DBCache::Invalidate(uint64_t key) { + DBCACHEHASH* hash = this->m_entries.Ptr(DBCacheHashKey(key), key); + + if (!hash) { + return; + } + + if (!hash->m_loaded) { + this->DenyItem(key); + } else if (hash->m_dispatching) { + hash->m_invalidatePending = true; + } else { + this->RemoveReverseEntry(hash->m_record.m_name); + this->m_entries.Delete(hash); + } +} + +// VERIFY: dcddca51 auto +// OFFSET: 0x00680C60 +template <> +void DBCache::AddItem(NameCache* item, uint64_t key) { + DBCACHEHASH* hash = this->m_entries.Ptr(DBCacheHashKey(key), key); + + if (!hash) { + hash = this->m_entries.New(DBCacheHashKey(key), key, 0, 0); + } + + hash->m_dispatching = true; + hash->m_record.Copy(*item); + hash->m_loaded = true; + hash->m_id = key; + this->ItemAdded(&hash->m_record); + + for (DBCACHECALLBACK* node = hash->m_callbacks.Head(); node;) { + DBCACHECALLBACK* next = hash->m_callbacks.Next(node); + node->m_callback(static_cast(key), node->m_guid, node->m_param, true); + node = next; + } + + hash->m_callbacks.Clear(); + bool invalidate = hash->m_invalidatePending; + hash->m_dispatching = false; + + if (invalidate) { + this->Invalidate(key); + } +} diff --git a/WoW/Source/DB/DBClient/DBCacheInstances.h b/WoW/Source/DB/DBClient/DBCacheInstances.h index 7366633..476deb5 100644 --- a/WoW/Source/DB/DBClient/DBCacheInstances.h +++ b/WoW/Source/DB/DBClient/DBCacheInstances.h @@ -40,6 +40,21 @@ extern DBCache g_danceCache; template <> void DBCache::ItemAdded(NameCache* item); +template <> +void DBCache::Invalidate(uint64_t key); + +template <> +DBCache::REVERSEENTRY* DBCache::FindReverseEntry(const char* name); + +template <> +NameCache* DBCache::GetRecordByName(const char* name); + +template <> +void DBCache::RemoveReverseEntry(const char* name); + +template <> +void DBCache::AddItem(NameCache* item, uint64_t key); + void DBCache_ClearHandlers(); void DBCache_Destroy(); void DBCache_Idle(); diff --git a/WoW/Source/DB/WowClientDB.h b/WoW/Source/DB/WowClientDB.h index f48bef5..c56f954 100644 --- a/WoW/Source/DB/WowClientDB.h +++ b/WoW/Source/DB/WowClientDB.h @@ -62,6 +62,7 @@ class WowClientDB : public WowClientDB_Common, public IDatabase { T* GetRecord(int32_t id) const override; WowClientDB(); + T* GetRecordByIndex(int32_t index) const; }; template @@ -450,4 +451,15 @@ int32_t WowClientDB_RLE::GetRecord(int32_t id, T* rec) const { return 1; } +// VERIFY: 040a5e1f auto +// OFFSET: [0x004D8580, 0x00514030] +template +T* WowClientDB::GetRecordByIndex(int32_t index) const { + if (index < 0 || index >= this->m_numRecords) { + return nullptr; + } + + return &this->m_records[index]; +} + #endif diff --git a/WoW/Source/Game/GameClient/NameCache.cpp b/WoW/Source/Game/GameClient/NameCache.cpp index 2f7b335..5239bf0 100644 --- a/WoW/Source/Game/GameClient/NameCache.cpp +++ b/WoW/Source/Game/GameClient/NameCache.cpp @@ -37,6 +37,29 @@ void NameCache::Pack(CDataStore* msg) { msg->Put(this->m_class); } +// VERIFY: c6bdf007 manual +// OFFSET: 0x006680C0 +NameCache& NameCache::Copy(const NameCache& other) { + this->m_guid = other.m_guid; + SStrCopy(this->m_name, other.m_name, sizeof(this->m_name)); + + if (other.m_declinedNames) { + if (!this->m_declinedNames) { + this->m_declinedNames = static_cast(SMemAlloc(sizeof(NameCache::DeclinedNames), __FILE__, __LINE__, 0)); + } + + for (uint32_t i = 0; i < sizeof(this->m_declinedNames->m_names) / sizeof(this->m_declinedNames->m_names[0]); i++) { + SStrCopy(this->m_declinedNames->m_names[i], other.m_declinedNames->m_names[i], sizeof(this->m_declinedNames->m_names[i])); + } + } + + SStrCopy(this->m_realmName, other.m_realmName, sizeof(this->m_realmName)); + this->m_race = other.m_race; + this->m_sex = other.m_sex; + this->m_class = other.m_class; + return *this; +} + // VERIFY: d7e9cfe1 manual // OFFSET: 0x007F74A0 void NameCache::Unpack(CDataStore* msg) { diff --git a/WoW/Source/Game/GameClient/NameCache.h b/WoW/Source/Game/GameClient/NameCache.h index ccccef2..41b513c 100644 --- a/WoW/Source/Game/GameClient/NameCache.h +++ b/WoW/Source/Game/GameClient/NameCache.h @@ -26,6 +26,7 @@ class NameCache { NameCache(); ~NameCache(); + NameCache& Copy(const NameCache& other); void Pack(CDataStore* msg); void Unpack(CDataStore* msg); char* FullName(char* buffer, uint32_t size); diff --git a/WoW/Source/Magic/MagicClient/Spell_C.cpp b/WoW/Source/Magic/MagicClient/Spell_C.cpp index be7561b..6237e62 100644 --- a/WoW/Source/Magic/MagicClient/Spell_C.cpp +++ b/WoW/Source/Magic/MagicClient/Spell_C.cpp @@ -3404,3 +3404,19 @@ int32_t Spell_C_GetMinMaxPoints(const SpellRec* spell, uint32_t effectIndex, int *maxPoints = CMath::ftrunc(high); return 0; } + +// VERIFY: 3cc995d6 auto +// OFFSET: 0x007FD630 +int32_t Spell_C_GetTargetingSpell() { + return s_targetingSpell ? s_targetingSpell->m_data.m_spellId : 0; +} + +// VERIFY: 8d996461 auto +// OFFSET: 0x008090C0 +bool Spell_C_GetItemCooldown(CGItem_C* item, uint32_t* duration, uint32_t* start, uint32_t* enable) { + if (!item) { + return false; + } + + return s_spellHistory[0].GetSpellCooldown(item->GetEnchantmentSpell(0), item->m_obj->m_entryID, duration, start, enable); +} diff --git a/WoW/Source/Magic/MagicClient/Spell_C.h b/WoW/Source/Magic/MagicClient/Spell_C.h index 671f28f..c4a19be 100644 --- a/WoW/Source/Magic/MagicClient/Spell_C.h +++ b/WoW/Source/Magic/MagicClient/Spell_C.h @@ -215,6 +215,8 @@ void Spell_C_GetMinMaxPoints(const SpellRec* spell, uint32_t effectIndex, float* void Spell_C_GetMinMaxRange(CGUnit_C* caster, const SpellRec* spell, float* minRange, float* maxRange, int32_t friendly, CGObject_C* target); int32_t Spell_C_GetDuration(const SpellRec* spell, int32_t isPet, int32_t isUnit, int32_t noModifiers, int32_t applyHaste); bool Spell_C_HasNoReagentCost(CGPlayer_C* player, const SpellRec* spell); +int32_t Spell_C_GetTargetingSpell(); +bool Spell_C_GetItemCooldown(CGItem_C* item, uint32_t* duration, uint32_t* start, uint32_t* enable); void Spell_C_SpellFailed(PendingSpellCast* cast, const SpellRec* spell, int32_t reason, int32_t a4, int32_t a5, bool a6); int32_t Spell_C_CastSpell(CGUnit_C* caster, int32_t spellId, const CGItem_C* item, WOWGUID target, PendingSpellCast* cast, bool a6); void UnitCombatLogCastStart(const WOWGUID& caster, const WOWGUID& target, int32_t spellId); diff --git a/WoW/Source/Object/Item.h b/WoW/Source/Object/Item.h index 2da27e2..e1e6fb4 100644 --- a/WoW/Source/Object/Item.h +++ b/WoW/Source/Object/Item.h @@ -21,6 +21,9 @@ class CGItem { virtual uint32_t GetItemStaticFlags(int32_t a1) = 0; int32_t IsUsable() const; + uint32_t GetDurability() const; + uint32_t GetMaxDurability() const; + int32_t GetPetitionSignatures(); }; struct ItemEnchantment { diff --git a/WoW/Source/Object/ObjectClient/Item_C.cpp b/WoW/Source/Object/ObjectClient/Item_C.cpp index 5ffe20d..5194833 100644 --- a/WoW/Source/Object/ObjectClient/Item_C.cpp +++ b/WoW/Source/Object/ObjectClient/Item_C.cpp @@ -7,6 +7,7 @@ #include "Engine/Source/Tempest/CImVector.h" #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/Tempest/CMath.h" #include "WoW/Source/DB/DBClient/DBCacheInstances.h" #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/DB/Rec/ItemRandomPropertiesRec.h" @@ -19,6 +20,11 @@ #include "WoW/Source/Object/ItemStats.h" #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Common/ComponentCore/CharacterComponent.h" +#include "WoW/Source/DB/Rec/DurabilityCostsRec.h" +#include "WoW/Source/DB/Rec/DurabilityQualityRec.h" +#include "WoW/Source/DB/Rec/LockRec.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/Magic/MagicClient/Spell_C.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/Object/ObjectClient/Unit_C.h" #include "WoW/Source/Ui/ActionBarFrame.h" @@ -28,6 +34,7 @@ #include "WoW/Source/Ui/PaperDollInfoFrame.h" #include "WoW/Source/Ui/QuestLog.h" #include "WoW/Source/Ui/ScriptEvents.h" +#include "WoW/Source/Ui/SpellBookFrame.h" #include "WoW/Source/Ui/TradeFrame.h" #include "WoW/Source/Ui/TradeSkillFrame.h" #include "WoW/Source/WorldClient/FrameTime.h" @@ -1095,3 +1102,276 @@ const char* CGItem_C::GetInventoryArt() const { return CGItem_C::GetInventoryArt(0); } + +// VERIFY: 61c58006 manual +// OFFSET: 0x00584AC0 +uint32_t CGItem::GetDurability() const { + if (this->m_item->m_itemFieldFlags & 8) { + return 0; + } + + return this->m_item->m_itemFieldDurability; +} + +// VERIFY: e00bdbda manual +// OFFSET: 0x00584AE0 +uint32_t CGItem::GetMaxDurability() const { + if (this->m_item->m_itemFieldFlags & 8) { + return 0; + } + + return this->m_item->m_itemFieldMaxdurability; +} + +// VERIFY: d3247ea5 manual +// OFFSET: 0x0061DC90 +int32_t CGItem::GetPetitionSignatures() { + if (this->GetItemStaticFlags(0) & 0x2000) { + return this->m_item->m_itemFieldEnchantment[0].m_duration; + } + + return 0; +} + +// VERIFY: 5cea77df manual +// OFFSET: 0x00707650 +int32_t CGItem_C::GetRandomPropertyValue(int32_t slot, int32_t randomPropertiesId, int32_t points) { + float value = 0.0f; + + if (randomPropertiesId < 0) { + ItemRandomSuffixRec* suffix = g_itemRandomSuffixDB.GetRecord(-randomPropertiesId); + uint32_t index = slot - 7; + + if (suffix && static_cast(index) >= 0 && index < 5) { + value = suffix->m_allocationPct[index] * 0.0001f * points; + } + } + + return CMath::ftrunc(value); +} + +// VERIFY: bf61ad32 manual +// OFFSET: 0x00707C60 +int32_t CGItem_C::GetEnchantmentSpell(int32_t effect) { + SpellRec spell; + int32_t spellId = 0; + ItemStats_C* stats = g_itemDBCache.GetRecord(this->m_obj->m_entryID, WOWGUID{ 0 }, nullptr, nullptr, false); + + if (!stats) { + return 0; + } + + for (uint32_t i = 0; i < 5; i++) { + if (!stats->m_spellId[i] || stats->m_spellTrigger[i]) { + continue; + } + + bool match = !effect; + + if (!match && g_spellDB.GetRecord(stats->m_spellId[i], &spell)) { + for (uint32_t j = 0; j < 3; j++) { + if (spell.m_effect[j] == effect) { + match = true; + break; + } + } + } + + if (match) { + spellId = stats->m_spellId[i]; + + if (spellId) { + return spellId; + } + + break; + } + } + + for (uint32_t slot = 0; slot < 12; slot++) { + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(this->m_item->m_itemFieldEnchantment[slot].m_id); + + if (enchant) { + for (uint32_t i = 0; i < 3; i++) { + if (enchant->m_effect[i] == 7) { + spellId = enchant->m_effectArg[i]; + break; + } + } + } + + if (spellId) { + break; + } + } + + return spellId; +} + +// VERIFY: 24e20657 manual +// OFFSET: 0x00708540 +int32_t CGItem_C::GetRepairCost() { + ItemStats_C* stats = g_itemDBCache.GetRecord(this->m_obj->m_entryID, WOWGUID{ 0 }, nullptr, nullptr, false); + + if (!stats) { + return 0; + } + + CGItemData* item = this->m_item; + + if ((item->m_itemFieldFlags & 8) || !item->m_itemFieldMaxdurability) { + return 0; + } + + uint32_t durability = (item->m_itemFieldFlags & 8) ? 0 : item->m_itemFieldDurability; + + if ((item->m_itemFieldFlags & 8) || durability >= item->m_itemFieldMaxdurability) { + return 0; + } + + DurabilityCostsRec* costs = g_durabilityCostsDB.GetRecord(stats->m_itemLevel); + + if (!costs) { + return 0; + } + + uint32_t itemClass = this->GetClassID(); + + if (itemClass != 2 && itemClass != 4) { + return 0; + } + + uint32_t subClass = this->GetSubtypeID(); + int32_t cost; + + if (itemClass == 2) { + if (subClass > 21) { + return 0; + } + + cost = costs->m_weaponSubClassCost[subClass]; + } else { + if (itemClass != 4 || subClass > 8) { + return 0; + } + + cost = costs->m_armorSubClassCost[subClass]; + } + + DurabilityQualityRec* quality = g_durabilityQualityDB.GetRecordByIndex(2 * stats->m_quality + 1); + + if (!quality) { + return 0; + } + + int32_t lost = this->GetMaxDurability() - this->GetDurability(); + int32_t result = CMath::fint_n(lost * quality->m_data * cost); + return result ? result : 1; +} + +// VERIFY: 84e69779 manual +// OFFSET: 0x007086B0 +int32_t CGItem_C::IsLocked(const LockRec* lock, int32_t itemLevel, int32_t* spellId, int32_t* skillValue, int32_t* requiredSkill, int32_t* lockIndex, CGItem_C** key, int32_t* entry) { + int32_t locked = 0; + SpellRec spell; + + for (int32_t i = 0; i < 8; i++) { + int32_t type = lock->m_type[i]; + + if (!type) { + continue; + } + + if (type == 2) { + locked = 1; + + for (uint32_t j = 0; j < s_openLockSpells.m_count; j++) { + g_spellDB.GetRecord(s_openLockSpells.m_data[j], &spell); + + for (uint32_t effect = 0; effect < 3; effect++) { + if (spell.m_effect[effect] != 33 || spell.m_effectMiscValue[effect] != lock->m_index[i]) { + continue; + } + + int32_t required = lock->m_skill[i] ? lock->m_skill[i] : 5 * itemLevel; + int32_t minPoints; + int32_t maxPoints; + Spell_C_GetMinMaxPoints(&spell, effect, &minPoints, &maxPoints, 0, 0, 0, 0); + + if (spellId) { + *spellId = s_openLockSpells.m_data[j]; + } + + if (skillValue) { + *skillValue = minPoints; + } + + if (requiredSkill) { + *requiredSkill = required; + } + + if (lockIndex) { + *lockIndex = lock->m_index[i]; + } + + if (minPoints >= required) { + if (entry) { + *entry = i; + } + + return 0; + } + } + } + } else if (type == 3) { + locked = 1; + + g_spellDB.GetRecord(lock->m_index[i], &spell); + + for (uint32_t effect = 0; effect < 3; effect++) { + if (spell.m_effect[effect] == 33) { + if (spellId) { + *spellId = spell.m_id; + } + + if (entry) { + *entry = i; + } + + return 0; + } + } + } else if (type == 1) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + locked = 1; + CGItem_C* item = player->m_bag.FindItemOfType(lock->m_index[i], 0); + + if (item) { + if (spellId) { + *spellId = item->GetEnchantmentSpell(0); + } + + if (key) { + *key = item; + } + + if (entry) { + *entry = i; + } + + return 0; + } + } + } + } + + return locked; +} + +// VERIFY: bb164cd0 auto +// OFFSET: 0x007089B0 +int32_t CGItem_C::GetRandomPropertyValue(int32_t slot) { + return CGItem_C::GetRandomPropertyValue(slot, this->m_item->m_itemFieldRandomPropertiesId, this->GetRandomPropertyPoints()); +} diff --git a/WoW/Source/Object/ObjectClient/Item_C.h b/WoW/Source/Object/ObjectClient/Item_C.h index c1e826c..3face8d 100644 --- a/WoW/Source/Object/ObjectClient/Item_C.h +++ b/WoW/Source/Object/ObjectClient/Item_C.h @@ -11,6 +11,7 @@ class CClientObjCreate; class CImVector; class ItemStats_C; +class LockRec; struct INVENTORYART : public TSHashObject { /* 0018 */ char* m_texture; @@ -84,6 +85,10 @@ class CGItem_C : public CGObject_C, public CGItem { bool IsBound(); void Unlock(); static int32_t GetUseSpell(int32_t itemId); + static int32_t GetRandomPropertyValue(int32_t slot, int32_t randomPropertiesId, int32_t points); + static int32_t IsLocked(const LockRec* lock, int32_t itemLevel, int32_t* spellId, int32_t* skillValue, int32_t* requiredSkill, int32_t* lockIndex, CGItem_C** key, int32_t* entry); + int32_t GetRandomPropertyValue(int32_t slot); + int32_t GetRepairCost(); int32_t GetEnchantmentSpell(int32_t a1); void GetSpellCooldownInfo(uint32_t& cooldown, uint32_t& categoryCooldown, uint32_t& category); bool IsBoundForTrade(); diff --git a/WoW/Source/Object/ObjectClient/Player_C.cpp b/WoW/Source/Object/ObjectClient/Player_C.cpp index 29c5260..e4a54b5 100644 --- a/WoW/Source/Object/ObjectClient/Player_C.cpp +++ b/WoW/Source/Object/ObjectClient/Player_C.cpp @@ -45,6 +45,8 @@ #include "WoW/Source/Ui/ActionBarFrame.h" #include "WoW/Source/Ui/BarberShop.h" #include "Engine/Source/Os/TimeManager.h" +#include "WoW/Source/DB/Rec/GemPropertiesRec.h" +#include "WoW/Source/DB/Rec/ItemSetRec.h" #include "WoW/Source/Ui/ClassTrainerFrame.h" #include "WoW/Source/Ui/CommentatorFrame.h" #include "WoW/Source/Ui/GuildBankFrame.h" @@ -68,6 +70,7 @@ #include #include "WoW/Source/Object/GameObject.h" #include "WoW/Source/DB/Rec/LockRec.h" +#include "WoW/Source/DB/Rec/SpellItemEnchantmentRec.h" #include "WoW/Source/WowSvcs/WowSvcsClient/FriendList.h" #include "_Triage/AreaList.h" @@ -82,10 +85,6 @@ struct InitialSpellStruct { /* 0006 */ uint16_t unk_0006; }; -struct InspectData { - /* 0000 */ uint8_t unk_0000[1368]; -}; - // STATIC: 0x00C9D33C static int32_t s_unk_C9D33C; @@ -143,6 +142,9 @@ static WOWGUID s_giftWrapItem; // STATIC: 0x00C9EAE0 static InspectData* s_inspectData; +// STATIC: 0x00C9EC78 +static InspectItem s_emptyInspectItem; + // STATIC: 0x00C9EAE4 uint32_t CGPlayer_C::s_lastUpdatePVPSequence; @@ -1098,6 +1100,12 @@ int32_t Packet_SMSG_SET_PROFICIENCY(void* param, NETMESSAGE msgId, uint32_t time return 1; } +// VERIFY: dfb6fe0a manual +// OFFSET: 0x006CEB00 +bool CGPlayer_C::CanDualWield() { + return s_dualWieldSpell != 0; +} + // VERIFY: 37ec0ce6 auto // OFFSET: 0x006CED80 int32_t __stdcall CGPlayer_C::OnLootItemNotify(CDataStore* msg) { @@ -2456,7 +2464,7 @@ void __stdcall CGPlayer_C::ClearAFK(int32_t force) { ClientServices::Send2(&msg); } -// VERIFY: 113486d4 manual +// VERIFY: f4bf6af2 manual // OFFSET: 0x006E6B40 CGPlayer_C::CGPlayer_C(uint32_t time, const CClientObjCreate& create) : CGUnit_C(time, create), @@ -2492,10 +2500,10 @@ CGPlayer_C::CGPlayer_C(uint32_t time, const CClientObjCreate& create) this->m_combatModeTime = FrameTime::s_curTimeMs - 500; this->m_pvpCooldownTimestamp = 0; - this->unk_1924[0] = 0; - this->unk_1924[1] = 0; - this->unk_1924[2] = 0; - this->unk_1924[3] = 0; + this->m_gemCounts[0] = 0; + this->m_gemCounts[1] = 0; + this->m_gemCounts[2] = 0; + this->m_gemCounts[3] = 0; this->unk_1944 = 0; this->unk_1948 = 0; @@ -4525,3 +4533,140 @@ float CGPlayer_C::GetModDamageDonePct(int32_t school) const { return 0.0f; } + +// VERIFY: 68b495c6 manual +// OFFSET: 0x006DC550 +bool CGPlayer_C::MeetsItemSetSkill(const ItemSetRec* set) const { + if (set->m_requiredSkill) { + int32_t index = this->GetSkillIndex(set->m_requiredSkill); + + if (index < 0 || static_cast(this->GetSkillValue(index)) < set->m_requiredSkillRank) { + return false; + } + } + + return true; +} + +// VERIFY: 95312415 manual +// OFFSET: 0x006DE360 +InspectItem* CGPlayer_C::GetInspectedItem(int32_t slot) { + if (s_inspectData && s_inspectData->m_guid == this->m_obj->m_guid) { + if (slot < 0) { + return nullptr; + } + + if (static_cast(slot) < 19) { + return &s_inspectData->m_items[slot]; + } + } + + if (slot < 0 || static_cast(slot) >= 19) { + return nullptr; + } + + VisibleItem_C* visible = &this->m_player->m_playerVisibleItems[slot]; + + if (!visible) { + return nullptr; + } + + memset(&s_emptyInspectItem, 0, sizeof(s_emptyInspectItem)); + s_emptyInspectItem.m_itemId = abs(visible->m_itemId); + s_emptyInspectItem.m_enchants[0] = visible->m_enchantment[0]; + s_emptyInspectItem.m_enchants[1] = visible->m_enchantment[1]; + + if (visible->m_itemId <= 0) { + s_emptyInspectItem.m_flags |= 1; + } + + return &s_emptyInspectItem; +} + +// VERIFY: bd15a857 manual +// OFFSET: 0x006DE490 +static void CountGemsItemCacheCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (!success) { + return; + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player) { + player->CountEquippedGems(); + } +} + +// VERIFY: 456c3dda manual +// OFFSET: 0x006DE4D0 +void CGPlayer_C::CountEquippedGems() { + this->m_gemCounts[0] = 0; + this->m_gemCounts[1] = 0; + this->m_gemCounts[2] = 0; + this->m_gemCounts[3] = 0; + + for (uint32_t slot = 0; slot <= 18; slot++) { + CGItem_C* item = nullptr; + InspectItem* inspect = nullptr; + + if (ClntObjMgrGetActivePlayer() == this->m_obj->m_guid) { + item = this->m_bag.GetItemPointer(slot); + + if (!item || !item->IsUsable()) { + continue; + } + } else { + inspect = this->GetInspectedItem(slot); + + if (!inspect || !(inspect->m_flags & 1)) { + continue; + } + } + + for (uint32_t socket = 2; socket <= 4; socket++) { + int32_t enchantId; + + if (ClntObjMgrGetActivePlayer() == this->m_obj->m_guid) { + enchantId = (item->GetItemStaticFlags(0) & 0x2000) ? 0 : item->m_item->m_itemFieldEnchantment[socket].m_id; + } else if (socket <= 11) { + enchantId = inspect->m_enchants[socket]; + } else { + enchantId = 0; + } + + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(enchantId); + + if (!enchant || !enchant->m_srcItemID) { + continue; + } + + ItemStats_C* gem = g_itemDBCache.GetRecord(enchant->m_srcItemID, WOWGUID{ 0 }, &CountGemsItemCacheCallback, nullptr, false); + + if (!gem) { + continue; + } + + GemPropertiesRec* properties = g_gemPropertiesDB.GetRecord(gem->m_gemProperties); + + if (!properties || !properties->m_type) { + continue; + } + + if (properties->m_type & 1) { + this->m_gemCounts[0]++; + } + + if (properties->m_type & 2) { + this->m_gemCounts[1]++; + } + + if (properties->m_type & 4) { + this->m_gemCounts[2]++; + } + + if (properties->m_type & 8) { + this->m_gemCounts[3]++; + } + } + } +} diff --git a/WoW/Source/Object/ObjectClient/Player_C.h b/WoW/Source/Object/ObjectClient/Player_C.h index 83fa61c..aa6b984 100644 --- a/WoW/Source/Object/ObjectClient/Player_C.h +++ b/WoW/Source/Object/ObjectClient/Player_C.h @@ -23,6 +23,23 @@ class CreatureModelDataRec; class SpellRec; class SpellVisualKitRec; +struct InspectItem { + /* 0000 */ WOWGUID m_creator; + /* 0008 */ int32_t m_itemId; + /* 000C */ int32_t m_enchants [12]; + /* 003C */ int16_t m_randomPropertiesId; + /* 003E */ uint16_t m_flags; + /* 0040 */ uint32_t m_propertySeed; + /* 0044 */ uint32_t unk_0044; +}; + +struct InspectData { + /* 0000 */ WOWGUID m_guid; + /* 0008 */ InspectItem m_items [19]; +}; + +class ItemSetRec; + struct ITEMSWAP { /* 0000 */ WOWGUID m_guid; /* 0008 */ uint32_t unk_0008 [6]; @@ -85,6 +102,7 @@ class CGPlayer_C : public CGUnit_C, public CGPlayer { static const char* GetHairCustomizationName(); static uint32_t GetPendingMovie(); static uint32_t GetProficiency(uint8_t itemClass); + static bool CanDualWield(); static void __stdcall GetQuestReward(const WOWGUID& questGiver, int32_t questId, int32_t reward); static void __stdcall GiveQuestItems(const WOWGUID& questGiver, int32_t questId); static int32_t IsGiftWrapping(); @@ -163,7 +181,7 @@ class CGPlayer_C : public CGUnit_C, public CGPlayer { /* 18F0 */ CGBag_C m_bag; /* 1908 */ uint32_t unk_1908 [6]; /* 1920 */ uint32_t m_clientStandState; - /* 1924 */ uint32_t unk_1924 [4]; + /* 1924 */ int32_t m_gemCounts [4]; /* 1934 */ uint32_t m_combatModeTime; /* 1938 */ WOWGUID m_combatTarget; /* 1940 */ uint32_t m_pvpCooldownTimestamp; @@ -218,6 +236,8 @@ class CGPlayer_C : public CGUnit_C, public CGPlayer { uint32_t GetSkillValue(int32_t index) const; const VisibleItem_C* GetVisibleItem(int32_t slot) const; int32_t GetModDamageDonePos(int32_t school) const; + bool MeetsItemSetSkill(const ItemSetRec* set) const; + InspectItem* GetInspectedItem(int32_t slot); int32_t GetModDamageDoneNeg(int32_t school) const; float GetModDamageDonePct(int32_t school) const; const CGItem_C* EquippedItemMeetSpellRequirements(const SpellRec* spell, uint32_t slotMask); diff --git a/WoW/Source/Object/ObjectClient/Unit_C.cpp b/WoW/Source/Object/ObjectClient/Unit_C.cpp index 7d3283b..0e86352 100644 --- a/WoW/Source/Object/ObjectClient/Unit_C.cpp +++ b/WoW/Source/Object/ObjectClient/Unit_C.cpp @@ -15,6 +15,7 @@ #include "WoW/Source/DB/Rec/VehicleSeatRec.h" #include "WoW/Source/DB/Rec/CreatureMovementInfoRec.h" #include "WoW/Source/DB/Rec/ItemDisplayInfoRec.h" +#include "WoW/Source/DB/Rec/FactionRec.h" #include "WoW/Source/DB/Rec/FactionTemplateRec.h" #include "WoW/Source/DB/Rec/AreaTableRec.h" #include "WoW/Source/DB/Rec/AreaGroupRec.h" @@ -2957,6 +2958,39 @@ int32_t CGUnit_C::UnitReaction(const CGUnit_C* unit) const { return reaction; } +// VERIFY: 5eefb777 auto +// OFFSET: 0x007279A0 +float CGUnit_C::GetPlayerDiscount(const CGUnit_C* unit) const { + FactionTemplateRec* factionTemplate = g_factionTemplateDB.GetRecord(this->m_unit->m_unitFieldFactiontemplate); + + if (!factionTemplate) { + return 0.0f; + } + + FactionRec* faction = g_factionDB.GetRecord(factionTemplate->m_faction); + + if (!faction || faction->m_reputationIndex < 0) { + return 0.0f; + } + + switch (this->UnitReaction(unit)) { + case 4: + return 0.05f; + + case 5: + return 0.1f; + + case 6: + return 0.15f; + + case 7: + return 0.2f; + + default: + return 0.0f; + } +} + // VERIFY: 7c461897 auto // OFFSET: 0x00514050 bool CGUnit_C::IsFriendly(const CGUnit_C* unit) const { diff --git a/WoW/Source/Object/ObjectClient/Unit_C.h b/WoW/Source/Object/ObjectClient/Unit_C.h index b5fe271..b036df5 100644 --- a/WoW/Source/Object/ObjectClient/Unit_C.h +++ b/WoW/Source/Object/ObjectClient/Unit_C.h @@ -798,6 +798,7 @@ class CGUnit_C : public CGObject_C, public CGUnit { void UpdatePartyMemberPetState(); void ExecuteClientControlUpdate(WOWGUID guid, uint8_t state); int32_t UnitReaction(const CGUnit_C* unit) const; + float GetPlayerDiscount(const CGUnit_C* unit) const; void SetAttacking(WOWGUID guid); void UpdateObjectEffectMovementStates(); void DestroyUnitMount(int32_t a2); diff --git a/WoW/Source/UIUtil/Tooltip.cpp b/WoW/Source/UIUtil/Tooltip.cpp index 43fd85a..514020f 100644 --- a/WoW/Source/UIUtil/Tooltip.cpp +++ b/WoW/Source/UIUtil/Tooltip.cpp @@ -24,16 +24,23 @@ #include "Engine/Source/FrameScript/FrameScript.h" #include "Engine/Source/Tempest/CAaRect.h" #include "Engine/Source/Tempest/CMath.h" +#include "Engine/Source/Tempest/CRect.h" #include "WoW/Source/DB/DBClient/DBCacheInstances.h" #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/DB/Rec/CreatureTypeRec.h" #include "WoW/Source/DB/Rec/FactionRec.h" #include "WoW/Source/DB/Rec/FactionTemplateRec.h" +#include "WoW/Source/DB/Rec/GemPropertiesRec.h" +#include "WoW/Source/DB/Rec/ItemSetRec.h" #include "WoW/Source/DB/Rec/ItemSubClassMaskRec.h" #include "WoW/Source/DB/Rec/ItemSubClassRec.h" #include "WoW/Source/DB/Rec/PowerDisplayRec.h" +#include "WoW/Source/DB/Rec/ScalingStatDistributionRec.h" +#include "WoW/Source/DB/Rec/ScalingStatValuesRec.h" #include "WoW/Source/DB/Rec/SkillLineAbilityRec.h" #include "WoW/Source/DB/Rec/SkillLineRec.h" +#include "WoW/Source/DB/Rec/SpellItemEnchantmentConditionRec.h" +#include "WoW/Source/DB/Rec/SpellItemEnchantmentRec.h" #include "WoW/Source/DB/Rec/SpellRec.h" #include "WoW/Source/DB/Rec/SpellRuneCostRec.h" #include "WoW/Source/DB/Rec/SpellShapeshiftFormRec.h" @@ -46,6 +53,7 @@ #include "WoW/Source/Magic/MagicClient/Spell_C.h" #include "WoW/Source/Object/CreatureStats.h" #include "WoW/Source/Object/Item.h" +#include "WoW/Source/Object/ItemNameCache.h" #include "WoW/Source/Object/ItemStats.h" #include "WoW/Source/Object/QuestCache.h" #include "WoW/Source/Object/ObjectClient/AuraData.h" @@ -55,6 +63,7 @@ #include "WoW/Source/Object/ObjectClient/Item_C.h" #include "WoW/Source/Object/ObjectClient/Player_C.h" #include "WoW/Source/Ui/GameUI.h" +#include "WoW/Source/Ui/MerchantFrame.h" #include "WoW/Source/Ui/PaperDollInfoFrame.h" #include "WoW/Source/Ui/PartyFrame.h" #include "WoW/Source/Ui/PetInfo.h" @@ -64,6 +73,29 @@ #include "WoW/Source/Ui/ReputationInfo.h" #include "WoW/Source/Ui/TalentInfo.h" #include "_Triage/AreaList.h" +#include +#include +#include "WoW/Source/DB/Rec/AreaTableRec.h" +#include "WoW/Source/DB/Rec/ChrClassesRec.h" +#include "WoW/Source/DB/Rec/ChrRacesRec.h" +#include "WoW/Source/DB/Rec/GlyphPropertiesRec.h" +#include "WoW/Source/DB/Rec/ItemClassRec.h" +#include "WoW/Source/DB/Rec/ItemExtendedCostRec.h" +#include "WoW/Source/DB/Rec/ItemLimitCategoryRec.h" +#include "WoW/Source/DB/Rec/ItemPurchaseGroupRec.h" +#include "WoW/Source/DB/Rec/ItemRandomPropertiesRec.h" +#include "WoW/Source/DB/Rec/ItemRandomSuffixRec.h" +#include "WoW/Source/DB/Rec/LockRec.h" +#include "WoW/Source/DB/Rec/LockTypeRec.h" +#include "WoW/Source/DB/Rec/MapRec.h" +#include "WoW/Source/Object/CGPetition.h" +#include "WoW/Source/Object/ObjectClient/VisibleItem_C.h" +#include "WoW/Source/Ui/ArenaTeamInfo.h" +#include "WoW/Source/Ui/Calendar.h" +#include "WoW/Source/Ui/EquipmentManager.h" +#include "WoW/Source/Ui/ItemSocketInfo.h" +#include "WoW/Source/Ui/LootFrame.h" +#include "WoW/Source/UIUtil/Cursor.h" // STATIC: 0x00C5CF4C int32_t CGTooltip::s_objectType; @@ -113,6 +145,60 @@ static const char* s_questDifficultyColorStrings[5] = { "|cff808080", }; +// STATIC: 0x00AD2D48 +static uint32_t s_tooltipBrightRedColor = 0xFFFF0000; + +// STATIC: 0x00AD2D50 +static uint32_t s_tooltipItemSetColor = 0xFFFFFF97; + +// STATIC: 0x00AD2D54 +static uint32_t s_skillColors[5] = { 0xFF808080, 0xFF40C040, 0xFFFFFF00, 0xFFFF8040, 0xFFFF2020 }; + +// STATIC: 0x00AD2DA4 +static uint32_t s_tooltipGlyphColor = 0xFF66BBFF; + +// STATIC: 0x00AD2DA8 +static uint32_t s_tooltipRefundColor = 0xFF00CCFF; + +// STATIC: 0x00AD2DAC +static uint32_t s_tooltipTradeColor = 0xFF00CCFF; + +// STATIC: 0x00AD2D3C +static uint32_t s_tooltipDisenchantColor = 0xFF88AAFF; + +// STATIC: 0x00AD2AC8 +static const char* s_colorblindSuffixes[5] = { "", "[+] ", "[++] ", "[+++] ", "[-] " }; + +// STATIC: 0x00AD2A54 +static const char* s_colorStrings[4] = { "|cffffffff", "|cff808080", "|cffff2020", "|cff00ff00" }; + +// STATIC: 0x00AC7FD8 +static const char* s_inventoryTypeTokens[29] = { "", "INVTYPE_HEAD", "INVTYPE_NECK", "INVTYPE_SHOULDER", "INVTYPE_BODY", "INVTYPE_CHEST", "INVTYPE_WAIST", "INVTYPE_LEGS", "INVTYPE_FEET", "INVTYPE_WRIST", "INVTYPE_HAND", "INVTYPE_FINGER", "INVTYPE_TRINKET", "INVTYPE_WEAPON", "INVTYPE_SHIELD", "INVTYPE_RANGED", "INVTYPE_CLOAK", "INVTYPE_2HWEAPON", "INVTYPE_BAG", "INVTYPE_TABARD", "INVTYPE_ROBE", "INVTYPE_WEAPONMAINHAND", "INVTYPE_WEAPONOFFHAND", "INVTYPE_HOLDABLE", "INVTYPE_AMMO", "INVTYPE_THROWN", "INVTYPE_RANGEDRIGHT", "INVTYPE_QUIVER", "INVTYPE_RELIC" }; + +// STATIC: 0x00AD6640 +static const char* s_itemModTokens[49] = { "ITEM_MOD_MANA", "ITEM_MOD_HEALTH", "", "ITEM_MOD_AGILITY", "ITEM_MOD_STRENGTH", "ITEM_MOD_INTELLECT", "ITEM_MOD_SPIRIT", "ITEM_MOD_STAMINA", "", "", "", "", "ITEM_MOD_DEFENSE_SKILL_RATING", "ITEM_MOD_DODGE_RATING", "ITEM_MOD_PARRY_RATING", "ITEM_MOD_BLOCK_RATING", "ITEM_MOD_HIT_MELEE_RATING", "ITEM_MOD_HIT_RANGED_RATING", "ITEM_MOD_HIT_SPELL_RATING", "ITEM_MOD_CRIT_MELEE_RATING", "ITEM_MOD_CRIT_RANGED_RATING", "ITEM_MOD_CRIT_SPELL_RATING", "ITEM_MOD_HIT_TAKEN_MELEE_RATING", "ITEM_MOD_HIT_TAKEN_RANGED_RATING", "ITEM_MOD_HIT_TAKEN_SPELL_RATING", "ITEM_MOD_CRIT_TAKEN_MELEE_RATING", "ITEM_MOD_CRIT_TAKEN_RANGED_RATING", "ITEM_MOD_CRIT_TAKEN_SPELL_RATING", "ITEM_MOD_HASTE_MELEE_RATING", "ITEM_MOD_HASTE_RANGED_RATING", "ITEM_MOD_HASTE_SPELL_RATING", "ITEM_MOD_HIT_RATING", "ITEM_MOD_CRIT_RATING", "ITEM_MOD_HIT_TAKEN_RATING", "ITEM_MOD_CRIT_TAKEN_RATING", "ITEM_MOD_RESILIENCE_RATING", "ITEM_MOD_HASTE_RATING", "ITEM_MOD_EXPERTISE_RATING", "ITEM_MOD_ATTACK_POWER", "ITEM_MOD_RANGED_ATTACK_POWER", "", "ITEM_MOD_SPELL_HEALING_DONE", "ITEM_MOD_SPELL_DAMAGE_DONE", "ITEM_MOD_MANA_REGENERATION", "ITEM_MOD_ARMOR_PENETRATION_RATING", "ITEM_MOD_SPELL_POWER", "ITEM_MOD_HEALTH_REGEN", "ITEM_MOD_SPELL_PENETRATION", "ITEM_MOD_BLOCK_VALUE" }; + +// STATIC: 0x00AD6704 +static const char* s_socketColorNames[5] = { "Meta", "Red", "Yellow", "Blue", "Major" }; + +// STATIC: 0x00A262F0 +static const int32_t s_primaryStatOrder[11] = { 4, 3, 7, 5, 6, 1, 0, 8, 9, 2, 10 }; + +// STATIC: 0x00A25F78 +static const int32_t s_spellStatOrder[37] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 41, 43, 44, 45, 46, 47, 48 }; + +// STATIC: 0x00C5CF48 +static const ItemSetRec* s_sortItemSet; + +// STATIC: 0x00AD2AB4 +static const char* s_gemColorTokens[5] = { nullptr, "META_GEM", "RED_GEM", "YELLOW_GEM", "BLUE_GEM" }; + +// STATIC: 0x00A246E0 +static const int32_t s_gemColorIndices[5] = { -1, 0, 1, 2, 3 }; + +// STATIC: 0x00A2D288 +static const uint32_t s_inventoryTypeSlots[29] = { 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 3072, 12288, 98304, 65536, 131072, 16384, 98304, 7864320, 262144, 16, 98304, 98304, 65536, 0, 131072, 131072, 0, 131072 }; + // STATIC: 0x00AD2A5C static const char* s_tooltipRedColorString = "|cffff2020"; @@ -167,29 +253,105 @@ int32_t CGTooltip::GetObjectType() { return CGTooltip::s_objectType; } -// VERIFY: 620233cc auto +// VERIFY: 4591e9ef auto // OFFSET: 0x0050F590 void ItemLinkInfo::Clear() { this->m_itemId = 0; memset(this->m_enchants, 0, sizeof(this->m_enchants)); - memset(this->m_gems, 0, sizeof(this->m_gems)); - memset(this->m_gemEnchants, 0, sizeof(this->m_gemEnchants)); - this->unk_0094 = 0; - this->unk_0098 = 0; - this->unk_00A0 = 0; - this->unk_00A4 = 0; - this->unk_00A8 = 0; - this->unk_00AC = 0; - this->unk_00B0 = 0; - this->unk_00B4 = 0; - this->unk_00BC = 0; - this->unk_00C0 = 0; - this->unk_00C4 = 0; - this->unk_00C8 = 0; - this->unk_00CC = 0; - this->unk_00B8 = -1; - this->unk_00D0 = 1; - this->unk_00D4 = -1; + memset(this->m_enchantDurations, 0, sizeof(this->m_enchantDurations)); + memset(this->m_enchantCharges, 0, sizeof(this->m_enchantCharges)); + this->m_cooldown = 0; + this->m_proposedEnchant = 0; + this->m_creator = WOWGUID{ 0 }; + this->m_giftCreator = WOWGUID{ 0 }; + this->m_propertySeed = 0; + this->m_randomPropertiesId = 0; + this->m_wrapped = 0; + this->m_lockId = 0; + this->m_maxDurability = 0; + this->m_durability = 0; + this->m_level = 0; + this->m_spellCharges = -1; + this->m_stackCount = 1; + this->m_maxStackCount = -1; +} + +// VERIFY: 280704e6 auto +// OFFSET: 0x0050F630 +int32_t ItemLinkInfo::GetItemIdFromLink(const char* link) { + this->Clear(); + const char* cursor = SStrStr(link, "item:"); + + if (!cursor) { + return 0; + } + + cursor += 5; + this->m_itemId = SStrToInt(cursor); + + if (static_cast(this->m_itemId) <= 0) { + return 0; + } + + while (*cursor && *cursor != ':') { + cursor++; + } + + if (*cursor) { + this->m_enchants[0] = SStrToInt(++cursor); + } + + for (uint32_t i = 2; i < 5; i++) { + while (*cursor && *cursor != ':') { + cursor++; + } + + if (*cursor) { + this->m_enchants[i] = SStrToInt(++cursor); + } + } + + while (*cursor && *cursor != ':') { + cursor++; + } + + if (!*cursor) { + return this->m_itemId; + } + + this->m_enchants[5] = SStrToInt(++cursor); + + while (*cursor && *cursor != ':') { + cursor++; + } + + if (!*cursor) { + return this->m_itemId; + } + + this->m_randomPropertiesId = SStrToInt(++cursor); + + while (*cursor && *cursor != ':') { + cursor++; + } + + if (!*cursor) { + return this->m_itemId; + } + + this->m_propertySeed = SStrToInt(++cursor); + + while (*cursor && *cursor != ':') { + cursor++; + } + + if (!*cursor) { + return this->m_itemId; + } + + this->m_level = SStrToInt(++cursor); + + return this->m_itemId; } // VERIFY: bd6b1c11 auto @@ -403,7 +565,7 @@ void CGTooltip::OnLayerUpdate(float elapsedSec) { } } -// VERIFY: 5a252c7f manual +// VERIFY: 85be993a manual // OFFSET: 0x0061C620 void CGTooltip::ClearTooltip() { if (this->m_healthGuid != WOWGUID()) { @@ -424,7 +586,7 @@ void CGTooltip::ClearTooltip() { this->unk_0348 = 0; this->unk_034C = 0; this->m_healthGuid = WOWGUID(); - this->unk_0360 = 0; + this->m_itemId = 0; this->m_spellId = 0; this->unk_0368 = 0; this->unk_036C = 0; @@ -613,7 +775,7 @@ int32_t CGTooltip::ShowThis() { return CSimpleFrame::ShowThis(); } -// VERIFY: 4aa6f7f3 manual +// VERIFY: 306254b7 manual // OFFSET: 0x0061DEE0 CGTooltip::CGTooltip(CSimpleFrame* parent) : CSimpleFrame(parent) { this->m_itemLinkInfo.Clear(); @@ -634,22 +796,21 @@ CGTooltip::CGTooltip(CSimpleFrame* parent) : CSimpleFrame(parent) { this->unk_0348 = 0; this->unk_034C = 0; this->m_healthGuid = WOWGUID(); - this->unk_0360 = 0; + this->m_itemId = 0; this->m_spellId = 0; this->unk_0368 = 0; this->unk_036C = 0; this->unk_0370 = 0; - this->unk_03B4 = 0; - this->unk_03B8 = 0; - this->unk_03BC = 0; - this->unk_03C0 = 0; - this->unk_03C4 = 0; + this->m_itemNameOnly = 0; + this->m_itemSocketPreview = 0; + this->m_itemCompare = 0; + this->m_itemOwner = WOWGUID{ 0 }; this->m_pendingQueries = 0; this->m_fading = 0; this->m_minimumWidthForce = 0; - this->unk_04C8 = 0; - this->unk_04D0 = 0; - this->unk_04CC = 0; + this->m_itemMinimumLevel = 0; + this->m_itemDisplayedLevel = 0; + this->m_itemSkipSellPrice = 0; this->m_statusBar = nullptr; } @@ -1633,7 +1794,7 @@ void CGTooltip::GetFloatDurationString(char* buffer, uint32_t size, float time, } } -// VERIFY: 21c050c5 auto +// VERIFY: 74ea258e auto // OFFSET: 0x0061DD60 void TooltipSpellCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { if (!success) { @@ -1647,7 +1808,7 @@ void TooltipSpellCallback(int32_t id, const WOWGUID& guid, void* param, bool suc } if (tooltip->m_pendingQueries <= 0 && tooltip->m_spellId) { - tooltip->SetSpell(tooltip->m_spellId, 0, 0, 0, 0, 0, 0, nullptr, nullptr, 0, 0, 0, -1, -1, 0); + tooltip->SetSpell(tooltip->m_spellId, 0, 0, 0, 0, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); tooltip->CalculateSize(); } } @@ -2288,7 +2449,7 @@ static void AddSpellUseAllPowerLine(CGTooltip* tooltip, const SpellRec* spell, c tooltip->AddLine(text, nullptr, textColor, textColor, 0); } -// VERIFY: 0360572e manual +// VERIFY: 8edeac88 manual // OFFSET: 0x006238A0 int32_t CGTooltip::SetSpell(int32_t spellId, int32_t brief, uint32_t cooldown, int32_t isPet, int32_t showRank, int32_t isInspect, int32_t a8, const TalentRec* talent, CGTalentGroup_C* talentGroup, int32_t append, int32_t usePreview, int32_t a13, int32_t rank, int32_t maxRank, int32_t showLearn) { const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); @@ -2455,9 +2616,9 @@ int32_t CGTooltip::SetSpell(int32_t spellId, int32_t brief, uint32_t cooldown, i if (createsItem && spell.m_effectItemType[0]) { this->m_itemLinkInfo.Clear(); - int32_t itemParams[2] = { 0, 0 }; + WOWGUID requester = { 0 }; WOWGUID itemGuid = { 0 }; - this->SetItem(spell.m_effectItemType[0], itemParams, &itemGuid, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1); + this->SetItem(spell.m_effectItemType[0], &requester, &itemGuid, 0, 0, 0, 1, WOWGUID{ 0 }, 0, nullptr, 0, nullptr, 0, 0, 1); } } @@ -2469,3 +2630,3204 @@ int32_t CGTooltip::SetSpell(int32_t spellId, int32_t brief, uint32_t cooldown, i this->CalculateSize(); return result; } + +// VERIFY: 16a2d627 auto +// OFFSET: 0x0061A0D0 +void CGTooltip::AddMoney(int32_t money, int32_t maxMoney) { + if (!this->m_onTooltipAddMoney.m_luaRef) { + return; + } + + lua_State* L = FrameScript_GetContext(); + lua_pushnumber(L, money); + + if (maxMoney <= 0) { + lua_pushnil(L); + } else { + lua_pushnumber(L, maxMoney); + } + + this->RunScript(this->m_onTooltipAddMoney, 2, nullptr); +} + +// VERIFY: 37e7fe43 auto +// OFFSET: 0x0061A1C0 +static const char* GetColorblindSuffix(int32_t index) { + CVar* colorblindMode = CVar::Lookup("colorblindMode"); + + if (colorblindMode && colorblindMode->m_intValue) { + return s_colorblindSuffixes[index]; + } + + return ""; +} + +// VERIFY: 3cef9206 auto +// OFFSET: 0x0061A1F0 +static const CImVector* GetSkillColor(int32_t required, int32_t current, const char** suffix) { + int32_t index = 4; + + if (current >= required + 100) { + index = 0; + } else if (current >= required + 50) { + index = 1; + } else if (current >= required + 25) { + index = 2; + } else if (current >= required) { + index = 3; + } + + CVar* colorblindMode = CVar::Lookup("colorblindMode"); + + if (colorblindMode && colorblindMode->m_intValue) { + *suffix = s_colorblindSuffixes[index]; + } else { + *suffix = ""; + } + + return reinterpret_cast(&s_skillColors[index]); +} + +// VERIFY: c9abb8d7 auto +// OFFSET: 0x0061A600 +static int32_t SortItemSetBonuses(const void* a, const void* b) { + uint8_t first = *static_cast(a); + uint8_t second = *static_cast(b); + int32_t firstThreshold = s_sortItemSet->m_setThreshold[first]; + int32_t secondThreshold = s_sortItemSet->m_setThreshold[second]; + + if (firstThreshold > secondThreshold) { + return 1; + } + + if (firstThreshold < secondThreshold) { + return -1; + } + + return first < second ? -1 : 1; +} + +// VERIFY: 3d9b5b4c auto +// OFFSET: 0x0061A650 +int32_t GetScalingStatBudget(const ScalingStatValuesRec* values, uint32_t flags) { + if (!values) { + return 0; + } + + switch (flags & 0x4001F) { + case 0x1: + return values->m_shoulderBudget; + + case 0x2: + return values->m_trinketBudget; + + case 0x4: + return values->m_weaponBudget1h; + + case 0x8: + return values->m_primaryBudget; + + case 0x10: + return values->m_rangedBudget; + + case 0x40000: + return values->m_tertiaryBudget; + } + + return 0; +} + +// VERIFY: 68b9f580 manual +// OFFSET: 0x0061A6B0 +int32_t GetScalingStatArmor(const ScalingStatValuesRec* values, uint32_t flags) { + if (!values) { + return 0; + } + + switch (flags & 0xF801E0) { + case 0x20: + return values->m_clothShoulderArmor; + + case 0x40: + return values->m_leatherShoulderArmor; + + case 0x80: + return values->m_mailShoulderArmor; + + case 0x100: + return values->m_plateShoulderArmor; + + case 0x80000: + return values->m_clothCloakArmor; + + case 0x100000: + return values->m_clothChestArmor; + + case 0x200000: + return values->m_leatherChestArmor; + + case 0x400000: + return values->m_mailChestArmor; + + case 0x800000: + return values->m_plateChestArmor; + } + + return 0; +} + +// VERIFY: 716dc312 auto +// OFFSET: 0x0061A830 +void GetScalingStatDamage(const ScalingStatValuesRec* values, uint32_t flags, float* minDamage, float* maxDamage) { + float dps = 0.0f; + + if (minDamage) { + *minDamage = 0.0f; + } + + if (maxDamage) { + *maxDamage = 0.0f; + } + + if (!minDamage || !maxDamage || !values) { + return; + } + + float variance = 0.3f; + + switch (flags & 0x7E00) { + case 0x200: + dps = static_cast(values->m_weaponDps1h); + break; + + case 0x400: + dps = static_cast(values->m_weaponDps2h); + variance = 0.2f; + break; + + case 0x800: + dps = static_cast(values->m_spellcasterDps1h); + break; + + case 0x1000: + dps = static_cast(values->m_spellcasterDps2h); + variance = 0.2f; + break; + + case 0x2000: + dps = static_cast(values->m_rangedDps); + break; + + case 0x4000: + dps = static_cast(values->m_wandDps); + break; + } + + *minDamage = dps - dps * variance; + *maxDamage = dps * (variance + 1.0f); +} + +// VERIFY: 64b947f2 manual +// OFFSET: 0x0061A8F0 +int32_t GetFeralAttackPower(const ItemStats_C* stats, float damage) { + if (stats->m_class == 2 && (s_inventoryTypeSlots[stats->m_inventoryType] & 0x8000)) { + double dps = damage / (stats->m_delay * 0.001f); + + if (dps > 54.810001) { + return static_cast(floor((dps - 54.810001) * 14.0 + 0.5)); + } + } + + return 0; +} + +// VERIFY: 7d08691d manual +// OFFSET: 0x0061ABF0 +void CGTooltip::GetItemDurationString(char* buffer, uint32_t size, uint64_t time, const char* token) { + if (!buffer || !token) { + return; + } + + int32_t units = 0; + *buffer = '\0'; + char part[256] = { 0 }; + char text[1024] = { 0 }; + + if (time >= 86400000) { + SStrPrintf(part, sizeof(part), FrameScript_GetText("DAYS_ABBR", -1, GENDER_NOT_APPLICABLE), static_cast(time) / 86400000); + SStrPack(text, part, sizeof(text)); + time -= time / 86400000 * 86400000; + units = 1; + } + + if (time >= 3600000) { + if (text[0]) { + SStrPack(text, FrameScript_GetText("TIME_UNIT_DELIMITER", -1, GENDER_NOT_APPLICABLE), sizeof(text)); + } + + SStrPrintf(part, sizeof(part), FrameScript_GetText("HOURS_ABBR", -1, GENDER_NOT_APPLICABLE), static_cast(time) / 3600000); + SStrPack(text, part, sizeof(text)); + time -= time / 3600000 * 3600000; + units++; + } + + if (units < 2) { + if (time >= 60000) { + if (text[0]) { + SStrPack(text, FrameScript_GetText("TIME_UNIT_DELIMITER", -1, GENDER_NOT_APPLICABLE), sizeof(text)); + } + + SStrPrintf(part, sizeof(part), FrameScript_GetText("MINUTES_ABBR", -1, GENDER_NOT_APPLICABLE), static_cast(time) / 60000); + SStrPack(text, part, sizeof(text)); + time -= time / 60000 * 60000; + units++; + } + + if (units < 2 && time) { + if (text[0]) { + SStrPack(text, FrameScript_GetText("TIME_UNIT_DELIMITER", -1, GENDER_NOT_APPLICABLE), sizeof(text)); + } + + SStrPrintf(part, sizeof(part), FrameScript_GetText("SECONDS_ABBR", -1, GENDER_NOT_APPLICABLE), static_cast(time / 1000)); + SStrPack(text, part, sizeof(text)); + } + } + + SStrPrintf(buffer, size, FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), text); +} + +// VERIFY: 5b4cf4a8 manual +// OFFSET: 0x0061B4F0 +void __stdcall CGTooltip::FormatStringForXML(const char* text, char* buffer) { + int32_t length = strlen(text); + const char* processed = LanguageProcess(text); + int32_t out = 0; + + for (int32_t i = 0; i < length; i++) { + char c = processed[i]; + + if (c == '<') { + buffer[out++] = '&'; + buffer[out++] = 'l'; + buffer[out++] = 't'; + buffer[out++] = ';'; + i++; + } else if (c == '>') { + buffer[out++] = '&'; + buffer[out++] = 'g'; + buffer[out++] = 't'; + buffer[out++] = ';'; + i++; + } else if (c == '&') { + buffer[out++] = '&'; + buffer[out++] = 'a'; + buffer[out++] = 'm'; + buffer[out++] = 'p'; + buffer[out++] = ';'; + i++; + } + + buffer[out++] = processed[i]; + } + + buffer[out] = '\0'; +} + +// VERIFY: 2fdbd3e2 manual +// OFFSET: 0x0061C0B0 +int32_t GetEnchantmentConditionText(CGPlayer_C* player, const SpellItemEnchantmentRec* enchant, char* buffer, uint32_t size, int32_t newline) { + *buffer = '\0'; + + if (!enchant || !enchant->m_srcItemID || !enchant->m_conditionID || !player) { + return 1; + } + + SpellItemEnchantmentConditionRec* condition = g_spellItemEnchantmentConditionDB.GetRecord(enchant->m_conditionID); + + if (!condition) { + return 1; + } + + int32_t allMet = 1; + + for (uint32_t i = 0; i < 5; i++) { + char line[1024]; + char rightName[1024]; + char text[1024]; + char leftName[1024]; + int32_t met = 1; + const char* color; + + if (newline || *buffer) { + SStrPack(buffer, "\n", size); + } + + uint8_t leftType = condition->m_ltOperandType[i]; + uint8_t rightType = condition->m_rtOperandType[i]; + uint32_t leftIndex = s_gemColorIndices[leftType]; + int32_t left = leftIndex >= 4 ? 0 : player->m_gemCounts[leftIndex]; + + if (leftType >= 5) { + SStrCopy(leftName, FrameScript_GetText("UNKNOWN", -1, GENDER_NOT_APPLICABLE), sizeof(leftName)); + } else { + FormatString(s_gemColorTokens[leftType], -1, GENDER_NOT_APPLICABLE, leftName, sizeof(leftName)); + } + + if (rightType) { + uint32_t rightIndex = s_gemColorIndices[rightType]; + int32_t right = rightIndex >= 4 ? 0 : player->m_gemCounts[rightIndex]; + + if (rightType >= 5) { + SStrCopy(rightName, FrameScript_GetText("UNKNOWN", -1, GENDER_NOT_APPLICABLE), sizeof(rightName)); + } else { + FormatString(s_gemColorTokens[rightType], -1, GENDER_NOT_APPLICABLE, rightName, sizeof(rightName)); + } + + switch (condition->m_operator[i]) { + case 0: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_EQUAL_COMPARE", -1, GENDER_NOT_APPLICABLE), leftName, rightName); + met = left == right; + break; + + case 1: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_NOT_EQUAL_COMPARE", -1, GENDER_NOT_APPLICABLE), leftName, rightName); + met = left != right; + break; + + case 2: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_MORE_COMPARE", -1, GENDER_NOT_APPLICABLE), rightName, leftName); + met = right > left; + break; + + case 3: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_MORE_COMPARE", -1, GENDER_NOT_APPLICABLE), leftName, rightName); + met = left > right; + break; + + case 4: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_MORE_EQUAL_COMPARE", -1, GENDER_NOT_APPLICABLE), rightName, leftName); + met = right >= left; + break; + + case 5: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_MORE_EQUAL_COMPARE", -1, GENDER_NOT_APPLICABLE), leftName, rightName); + met = left >= right; + break; + } + } else { + int32_t value = condition->m_rtOperand[i]; + + switch (condition->m_operator[i]) { + case 0: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_EQUAL_VALUE", -1, GENDER_NOT_APPLICABLE), value, leftName); + met = left == value; + break; + + case 1: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_NOT_EQUAL_VALUE", -1, GENDER_NOT_APPLICABLE), value, leftName); + met = left != value; + break; + + case 2: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_LESS_VALUE", -1, GENDER_NOT_APPLICABLE), value, leftName); + met = left < value; + break; + + case 3: + value++; + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_MORE_VALUE", -1, GENDER_NOT_APPLICABLE), value, leftName); + met = left >= value; + break; + + case 4: + value++; + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_LESS_VALUE", -1, GENDER_NOT_APPLICABLE), value, leftName); + met = left < value; + break; + + case 5: + SStrPrintf(text, sizeof(text), FrameScript_GetText("ENCHANT_CONDITION_MORE_VALUE", -1, GENDER_NOT_APPLICABLE), value, leftName); + met = left >= value; + break; + } + } + + color = met ? s_colorStrings[0] : s_colorStrings[1]; + SStrPrintf(line, sizeof(line), " %s%s%s%s", color, FrameScript_GetText("ENCHANT_CONDITION_REQUIRES", -1, GENDER_NOT_APPLICABLE), text, "|r"); + SStrPack(buffer, line, size); + + if (!met || !allMet) { + allMet = 0; + } + + if (!condition->m_logic[i]) { + break; + } + } + + return allMet; +} + +// VERIFY: 05aca7fe manual +// OFFSET: 0x0061C8B0 +void CGTooltip::AddTexture(const char* texture, const CAaRect& coords, const CImVector& color) { + uint32_t index = this->m_numTextures; + + if (index >= 10 || !this->m_textures[index]) { + return; + } + + uint32_t lines = this->m_numLines; + + if (lines < 2) { + return; + } + + uint32_t line = lines - 1; + float offset; + + if (index && this->m_textureLines[index - 1] == lines - 2) { + offset = 0.0f; + } else { + offset = this->m_textures[index]->GetWidth() + 0.0049999999f; + } + + CSimpleFontString** strings = &this->m_leftStrings.m_data[line]; + strings[0]->SetPoint(FRAMEPOINT_TOPLEFT, strings[-1], FRAMEPOINT_BOTTOMLEFT, offset, NDCToDDCWidth(-2.0f / (CoordinateGetAspectCompensation() * 1024.0f)), 1); + this->m_textures[this->m_numTextures]->MarkFramePointsUnused(); + this->m_textures[this->m_numTextures]->SetPoint(FRAMEPOINT_TOPRIGHT, this->m_leftStrings.m_data[line], FRAMEPOINT_TOPLEFT, -0.0049999999f, 0.0f, 1); + + if (line < this->m_maxLines - 1) { + CSimpleFontString** next = &this->m_leftStrings.m_data[line]; + + if (next[1]) { + CSimpleTexture* current = this->m_textures[this->m_numTextures]; + float y = NDCToDDCWidth(-2.0f / (CoordinateGetAspectCompensation() * 1024.0f)); + next[1]->SetPoint(FRAMEPOINT_TOPLEFT, next[0], FRAMEPOINT_BOTTOMLEFT, -(current->GetWidth() + 0.0049999999f), y, 1); + } + } + + this->m_textures[this->m_numTextures]->SetTexture(texture, 0, 0, CSimpleTexture::s_textureFilterMode, ImageMode_Normal); + this->m_textures[this->m_numTextures]->SetTexCoord(reinterpret_cast(coords)); + this->m_textures[this->m_numTextures]->SetVertexColor(color); + CSimpleTexture* shown = this->m_textures[this->m_numTextures]; + shown->m_shown = 1; + shown->ShowThis(); + this->m_textureLines[this->m_numTextures++] = line; +} + +// VERIFY: c9ca1286 manual +// OFFSET: 0x0061E740 +int32_t CGTooltip::GetDisplayedScalingItemLevel(const ItemStats_C* stats, const ItemLinkInfo* link, WOWGUID target, int32_t minimumLevel) { + ScalingStatDistributionRec* distribution = g_scalingStatDistributionDB.GetRecord(stats->m_scalingStatDistribution); + int32_t level = 0; + + if (minimumLevel) { + level = 1; + } else if ((!link || !(level = link->m_level)) && target != CGMerchantInfo::m_merchant) { + CGUnit_C* unit = static_cast(ClntObjMgrObjectPtr(target, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (unit) { + level = unit->m_unit->m_unitFieldLevel; + } + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player && !level) { + level = player->m_unit->m_unitFieldLevel; + } + + if (distribution) { + int32_t required = stats->m_requiredLevel; + int32_t highest = required <= level ? level : required; + + if (highest >= distribution->m_maxlevel) { + level = distribution->m_maxlevel; + } else if (required > level) { + level = stats->m_requiredLevel; + } + } + + return level > 1 ? level : 1; +} + +// VERIFY: 12a957b9 manual +// OFFSET: 0x00623590 +void CGTooltip::AddSpellReagents(const SpellRec* spell, const char* token, void (*callback)(int32_t id, const WOWGUID& guid, void* param, bool success)) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + char line[4096]; + char text[4096]; + char reagent[1024]; + int32_t first = 1; + + for (uint32_t i = 0; i < 8; i++) { + int32_t itemId = spell->m_reagent[i]; + + if (itemId <= 0) { + continue; + } + + WOWGUID guid = { (static_cast(0x1FE00000) << 32) | static_cast(spell->m_id) }; + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, guid, callback, this, true); + + if (!stats) { + continue; + } + + if (first) { + first = 0; + text[0] = '\0'; + } else { + SStrPack(text, ", ", sizeof(text)); + } + + const char* name = stats->m_name[0]; + + if (spell->m_reagentCount[i] <= 1) { + SStrCopy(reagent, name, sizeof(reagent)); + } else { + SStrPrintf(reagent, sizeof(reagent), "%s (%d)", name, spell->m_reagentCount[i]); + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (player && player->m_bag.GetItemTypeCount(spell->m_reagent[i], 0) >= spell->m_reagentCount[i]) { + SStrPack(text, reagent, sizeof(text)); + } else { + SStrPack(text, s_tooltipRedColorString, sizeof(text)); + SStrPack(text, reagent, sizeof(text)); + SStrPack(text, "|r", sizeof(text)); + } + } + + if (!first) { + SStrPrintf(line, sizeof(line), FrameScript_GetText(token, -1, GENDER_NOT_APPLICABLE), text); + this->AddLine(line, nullptr, textColor, textColor, 1); + } +} + +// VERIFY: c31b22a0 auto +// OFFSET: 0x00623760 +int32_t CGTooltip::SetItemNoStats() { + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + this->AddLine(FrameScript_GetText("RETRIEVING_ITEM_INFO", -1, GENDER_NOT_APPLICABLE), nullptr, redColor, redColor, 0); + + if (this->m_onTooltipSetItem.m_luaRef) { + this->RunScript(this->m_onTooltipSetItem, 0, nullptr); + } + + this->Show(); + this->CalculateSize(); + return 0; +} + +// VERIFY: 38b9e6db auto +// OFFSET: 0x00626650 +void TooltipItemCallback(int32_t id, const WOWGUID& guid, void* param, bool success) { + if (!success) { + return; + } + + CGTooltip* tooltip = static_cast(param); + + if (tooltip->m_spellId) { + tooltip->SetSpell(tooltip->m_spellId, 0, 0, 0, 0, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + tooltip->CalculateSize(); + } else if (tooltip->m_itemId) { + WOWGUID itemGuid = tooltip->m_itemGuid; + WOWGUID requester = { 0 }; + tooltip->SetItem(tooltip->m_itemId, &requester, &itemGuid, tooltip->m_itemNameOnly, tooltip->m_itemCompare, tooltip->m_itemUseLinkInfo, 0, tooltip->m_itemOwner, tooltip->m_itemSocketPreview, nullptr, tooltip->m_itemHideCharges, nullptr, tooltip->m_itemMinimumLevel, tooltip->m_itemSkipSellPrice, 0); + tooltip->CalculateSize(); + } +} + +// VERIFY: b16ac8ce auto +// OFFSET: 0x006276E0 +bool ResolveItemSetItem(ItemSetTooltipData* data, int32_t pass, int32_t itemId, int32_t slot) { + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, WOWGUID{ 0 }, &TooltipItemCallback, data->m_tooltip, true); + + if (!stats || static_cast(stats->m_itemSet) != data->m_set->m_id) { + return false; + } + + if (!pass) { + for (uint32_t i = 0; i < 17; i++) { + if (!data->m_equipped[i] && itemId == data->m_set->m_itemID[i]) { + data->m_equipped[i] = itemId; + data->m_slotUsed[slot] = 1; + return true; + } + } + + return false; + } + + if (data->m_slotUsed[slot]) { + return false; + } + + for (uint32_t i = 0; i < 17; i++) { + if (data->m_equipped[i] || !data->m_items[i]) { + continue; + } + + uint32_t type = stats->m_inventoryType; + uint32_t setType = data->m_items[i]->m_inventoryType; + + if (type == setType || (type == 5 && setType == 20) || (type == 20 && setType == 5)) { + data->m_equipped[i] = itemId; + return true; + } + } + + return true; +} + +// INLINED +static void AddItemNameLines(CGTooltip* tooltip, const ItemStats_C* stats, int32_t itemId, int32_t randomPropertiesId, int32_t nameOnly, int32_t append, int32_t destroyGem) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& grayColor = *reinterpret_cast(&s_tooltipGrayColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char name[1024]; + char format[1024]; + CGItem_C::BuildItemName(name, sizeof(name), itemId, randomPropertiesId); + + if (append) { + SStrCopy(format, name, sizeof(format)); + SStrPrintf(name, sizeof(name), "\n%s", format); + } + + if (nameOnly) { + tooltip->AddLine(name, nullptr, textColor, textColor, 0); + return; + } + + const CImVector* nameColor = destroyGem ? &grayColor : reinterpret_cast(&s_itemQualityColors[stats->m_quality]); + tooltip->AddLine(name, nullptr, *nameColor, *nameColor, 0); + CVar* colorblindMode = CVar::Lookup("colorblindMode"); + + if (colorblindMode && colorblindMode->m_intValue) { + if (stats->m_flags[0] & 8) { + tooltip->AddLine(FrameScript_GetText("ITEM_HEROIC_EPIC", -1, GENDER_NOT_APPLICABLE), nullptr, textColor, textColor, 0); + } else { + SStrPrintf(format, sizeof(format), "ITEM_QUALITY%d_DESC", destroyGem ? 0 : stats->m_quality); + tooltip->AddLine(FrameScript_GetText(format, -1, GENDER_NOT_APPLICABLE), nullptr, textColor, textColor, 0); + } + } else if (stats->m_flags[0] & 8) { + tooltip->AddLine(FrameScript_GetText("ITEM_HEROIC", -1, GENDER_NOT_APPLICABLE), nullptr, greenColor, greenColor, 0); + } +} + +// INLINED +static bool AddItemPetitionLines(CGTooltip* tooltip, CGItem_C* item, const WOWGUID* itemGuid) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + char text[4096]; + + if (!(item->GetItemStaticFlags(0) & 0x2000)) { + return true; + } + + int32_t petitionId = (item->GetItemStaticFlags(0) & 0x2000) ? item->m_item->m_itemFieldEnchantment[0].m_id : 0; + CGPetition* petition = g_petitionCache.GetRecord(petitionId, *itemGuid, TooltipItemCallback, tooltip, true); + + if (!petition) { + return false; + } + + if (petition->m_staticType) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("PETITION_TITLE", -1, GENDER_NOT_APPLICABLE), petition->m_title); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("GUILD_CHARTER_TITLE", -1, GENDER_NOT_APPLICABLE), petition->m_title); + } + + tooltip->AddLine(text, nullptr, textColor, textColor, 1); + NameCache* owner = g_nameDBCache.GetRecord(petition->m_ownerGuid.m_guid, petition->m_ownerGuid, TooltipItemCallback, tooltip, true); + + if (owner) { + const char* token = petition->m_staticType ? FrameScript_GetText("PETITION_CREATOR", -1, GENDER_NOT_APPLICABLE) : FrameScript_GetText("GUILD_CHARTER_CREATOR", -1, GENDER_NOT_APPLICABLE); + SStrPrintf(text, sizeof(text), token, owner->m_name); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + int32_t signatures = item->GetPetitionSignatures(); + + if (signatures) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("PETITION_NUM_SIGNATURES", signatures, GENDER_NOT_APPLICABLE), signatures); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + return true; +} + +// INLINED +static void AddItemLockLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, const LockRec* lock) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + char text[4096]; + int32_t spellId = 0; + int32_t skillValue = 0; + int32_t requiredSkill = 0; + int32_t lockIndex = 0; + const char* suffix = ""; + CImVector lockColor; + CGItem_C::IsLocked(lock, stats->m_itemLevel, &spellId, &skillValue, &requiredSkill, &lockIndex, nullptr, nullptr); + + if (spellId) { + lockColor = *GetSkillColor(requiredSkill, skillValue, &suffix); + } else { + lockColor = *reinterpret_cast(&s_skillColors[1]); + suffix = GetColorblindSuffix(1); + } + + bool encrypted = false; + + if (lockIndex) { + encrypted = lockIndex == 20; + } else { + for (uint32_t i = 0; i < 8; i++) { + if (lock->m_index[i] == 20) { + encrypted = true; + break; + } + } + } + + if (encrypted) { + SStrPrintf(text, sizeof(text), "%s%s", suffix, FrameScript_GetText("ENCRYPTED", -1, GENDER_NOT_APPLICABLE)); + } else { + SStrPrintf(text, sizeof(text), "%s%s", suffix, FrameScript_GetText("LOCKED", -1, GENDER_NOT_APPLICABLE)); + } + + tooltip->AddLine(text, nullptr, lockColor, lockColor, 0); + + for (uint32_t i = 0; i < 8; i++) { + int32_t type = lock->m_type[i]; + + if (type == 2) { + int32_t skillSpell = 0; + int32_t skillCurrent = 0; + int32_t skillRequired = 0; + const char* skillSuffix; + CImVector skillColor = textColor; + CGItem_C::IsLocked(lock, stats->m_itemLevel, &skillSpell, &skillCurrent, &skillRequired, nullptr, nullptr, nullptr); + + if (skillSpell) { + char format[128]; + skillColor = *GetSkillColor(skillRequired, skillCurrent, &skillSuffix); + SStrCopy(format, FrameScript_GetText("ITEM_MIN_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + LockTypeRec* lockType = g_lockTypeDB.GetRecord(lock->m_index[i]); + SStrPrintf(text, sizeof(text), format, lockType ? lockType->m_name : "UNKNOWN", lock->m_skill[i]); + tooltip->AddLine(text, nullptr, skillColor, skillColor, 0); + } + + return; + } + + if (type == 3) { + SpellRec spell; + + if (g_spellDB.GetRecord(lock->m_index[i], &spell)) { + tooltip->AddSpellReagents(&spell, "LOCKED_WITH_SPELL", TooltipItemCallback); + } + + return; + } + + if (type == 1) { + WOWGUID key = item ? item->m_obj->m_guid : WOWGUID{ 0 }; + ItemStats_C* keyStats = g_itemDBCache.GetRecord(lock->m_index[i], key, TooltipItemCallback, tooltip, true); + + if (keyStats) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("LOCKED_WITH_ITEM", -1, GENDER_NOT_APPLICABLE), keyStats->GetName(0)); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + return; + } + } +} + +// INLINED +static const LockRec* AddItemBindLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, const WOWGUID* requester, int32_t skipLock) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + char text[4096]; + char format[1024]; + + if (stats->m_area) { + AreaTableRec* area = g_areaTableDB.GetRecord(stats->m_area); + + if (area) { + tooltip->AddLine(area->m_areaName, nullptr, textColor, textColor, 0); + } + } + + if (stats->m_map) { + MapRec* map = g_mapDB.GetRecord(stats->m_map); + + if (map) { + tooltip->AddLine(map->m_mapName, nullptr, textColor, textColor, 0); + } + } + + if (stats->m_flags[0] & 2) { + FormatString("ITEM_CONJURED", -1, GENDER_NOT_APPLICABLE, format, sizeof(format)); + tooltip->AddLine(format, nullptr, textColor, textColor, 0); + } + + text[0] = '\0'; + + if (item && item->IsBound()) { + if (stats->m_bonding == 4) { + FormatString("ITEM_BIND_QUEST", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + } else if (stats->m_class != 10) { + if (stats->m_flags[0] & 0x8000000) { + FormatString("ITEM_ACCOUNTBOUND", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + } else { + FormatString("ITEM_SOULBOUND", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + } + } + } + + if (stats->m_bonding && !text[0] && (stats->m_class != 10 || *requester == CGLootInfo::m_lootObj)) { + if (stats->m_flags[0] & 0x8000000) { + FormatString("ITEM_BIND_TO_ACCOUNT", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + } else { + switch (stats->m_bonding) { + case 1: + FormatString("ITEM_BIND_ON_PICKUP", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + break; + + case 2: + FormatString("ITEM_BIND_ON_EQUIP", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + break; + + case 3: + FormatString("ITEM_BIND_ON_USE", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + break; + + case 4: + FormatString("ITEM_BIND_QUEST", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + break; + } + } + } + + if (text[0]) { + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + if (stats->m_class != 10) { + if (stats->m_flags[0] & 0x80000) { + FormatString("ITEM_UNIQUE_EQUIPPABLE", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } else if (static_cast(stats->m_maxCount) > 0) { + if (stats->m_maxCount == 1) { + FormatString("ITEM_UNIQUE", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + } else { + FormatString("ITEM_UNIQUE_MULTIPLE", -1, GENDER_NOT_APPLICABLE, format, sizeof(format)); + SStrPrintf(text, sizeof(text), format, stats->m_maxCount); + } + + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } else if (stats->m_itemLimitCategory) { + ItemLimitCategoryRec* category = g_itemLimitCategoryDB.GetRecord(stats->m_itemLimitCategory); + + if (category->m_flags & 1) { + FormatString("ITEM_LIMIT_CATEGORY_MULTIPLE", -1, GENDER_NOT_APPLICABLE, format, sizeof(format)); + } else { + FormatString("ITEM_LIMIT_CATEGORY", -1, GENDER_NOT_APPLICABLE, format, sizeof(format)); + } + + SStrPrintf(text, sizeof(text), format, category->m_name, category->m_quantity); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + } + + if (stats->m_startQuest) { + FormatString("ITEM_STARTS_QUEST", -1, GENDER_NOT_APPLICABLE, text, sizeof(text)); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + if (skipLock) { + return nullptr; + } + + LockRec* lock = g_lockDB.GetRecord(stats->m_lockId); + + if (!lock) { + if (!tooltip->m_itemUseLinkInfo || !tooltip->m_itemLinkInfo.m_lockId) { + return nullptr; + } + + lock = g_lockDB.GetRecord(tooltip->m_itemLinkInfo.m_lockId); + + if (!lock) { + return nullptr; + } + } + + if (item && (item->m_item->m_itemFieldFlags & 4)) { + return nullptr; + } + + return lock; +} + +// INLINED +static void AddItemTypeLines(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player, const ScalingStatValuesRec* values, const ScalingStatDistributionRec* distribution) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& glyphColor = *reinterpret_cast(&s_tooltipGlyphColor); + char slot[1024]; + char format[1024]; + char subClassName[1024]; + ItemSubClassRec* subClass = nullptr; + subClassName[0] = '\0'; + + for (int32_t i = 0; i < g_itemSubClassDB.m_numRecords; i++) { + ItemSubClassRec* rec = g_itemSubClassDB.GetRecordByIndex(i); + + if (rec && rec->m_classID == static_cast(stats->m_class) && rec->m_subClassID == static_cast(stats->m_subClass)) { + subClass = rec; + break; + } + } + + if (stats->m_inventoryType == 18) { + if (subClass && subClass->m_displayName && *subClass->m_displayName) { + SStrCopy(format, FrameScript_GetText("CONTAINER_SLOTS", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(slot, sizeof(slot), format, stats->m_containerSlots, subClass->m_displayName); + tooltip->AddLine(slot, nullptr, textColor, textColor, 0); + } + + return; + } + + if (stats->m_class == 16) { + for (uint32_t i = 0; i < 5; i++) { + SpellRec spell; + + if (g_spellDB.GetRecord(stats->m_spellId[i], &spell)) { + for (uint32_t j = 0; j < 3; j++) { + if (spell.m_effect[j] != 74) { + continue; + } + + GlyphPropertiesRec* glyph = g_glyphPropertiesDB.GetRecord(spell.m_effectMiscValue[j]); + + if (glyph) { + const char* text = glyph->m_glyphSlotFlags ? FrameScript_GetText("MINOR_GLYPH", -1, GENDER_NOT_APPLICABLE) : FrameScript_GetText("MAJOR_GLYPH", -1, GENDER_NOT_APPLICABLE); + tooltip->AddLine(text, nullptr, glyphColor, glyphColor, 0); + } + } + } + } + + return; + } + + if (subClass && stats->m_inventoryType != 16 && !(subClass->m_flags & 1) && subClass->m_displayName && *subClass->m_displayName) { + SStrCopy(subClassName, subClass->m_displayName, sizeof(subClassName)); + } + + if (stats->m_class != 6) { + const char* text = FrameScript_GetText(s_inventoryTypeTokens[stats->m_inventoryType], -1, GENDER_NOT_APPLICABLE); + SStrCopy(slot, text, sizeof(slot)); + + if (!*text) { + slot[0] = '\0'; + } + } else { + ItemClassRec* itemClass = g_itemClassDB.GetRecord(6); + + if (itemClass && itemClass->m_className && *itemClass->m_className) { + SStrCopy(slot, itemClass->m_className, sizeof(slot)); + } else { + slot[0] = '\0'; + } + } + + int32_t subClassRed = 0; + int32_t slotRed = 0; + uint32_t proficiency = CGPlayer_C::GetProficiency(stats->m_class); + + if (proficiency && !((1 << stats->m_subClass) & proficiency)) { + if (stats->m_class == 2) { + int32_t prerequisite = subClass->m_prerequisiteProficiency; + + if (prerequisite != -1) { + if ((1 << prerequisite) & proficiency) { + slotRed = 1; + } else { + subClassRed = 1; + } + } else { + int32_t postrequisite = subClass->m_postrequisiteProficiency; + + if (postrequisite == -1 || !((1 << postrequisite) & proficiency)) { + subClassRed = 1; + } else { + slotRed = 1; + } + } + } else { + int32_t alternate = -1; + + if (values && distribution && stats->m_class == 4 && (stats->m_subClass == 4 || stats->m_subClass == 3)) { + ChrClassesRec* playerClass = g_chrClassesDB.GetRecord(player->m_unit->m_unitFieldBytes0[1]); + + if (playerClass) { + if (stats->m_subClass == 4 && (playerClass->m_flags & 0x20)) { + alternate = ((proficiency & 8) | 0x10) >> 3; + } else if (stats->m_subClass == 3 && (playerClass->m_flags & 0x10) && (proficiency & 4)) { + alternate = stats->m_subClass - 1; + } + } + } + + if (alternate == -1) { + subClassRed = 1; + } else { + for (int32_t i = 0; i < g_itemSubClassDB.m_numRecords; i++) { + ItemSubClassRec* rec = g_itemSubClassDB.GetRecordByIndex(i); + + if (rec && rec->m_classID == 4 && rec->m_subClassID == alternate) { + if (rec->m_displayName && *rec->m_displayName) { + SStrCopy(subClassName, rec->m_displayName, sizeof(subClassName)); + } + + break; + } + } + } + } + } + + if (stats->m_inventoryType == 22 && !CGPlayer_C::CanDualWield()) { + slotRed = 1; + } + + if (slot[0]) { + const CImVector& rightColor = subClassRed ? redColor : textColor; + const CImVector& leftColor = slotRed ? redColor : textColor; + tooltip->AddLine(slot, subClassName[0] ? subClassName : nullptr, leftColor, rightColor, 0); + } else if (subClassName[0]) { + const CImVector& color = subClassRed ? redColor : textColor; + tooltip->AddLine(subClassName, nullptr, color, color, 0); + } +} + +// INLINED +static float AddItemDamageLines(CGTooltip* tooltip, const ItemStats_C* stats, const ScalingStatValuesRec* values) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + char text[1024]; + char format[1024]; + char speed[1024]; + char school[4096]; + float average = 0.0f; + int32_t first = 1; + + if ((stats->m_scalingStatValue & 0x7E00) && values) { + float minDamage; + float maxDamage; + GetScalingStatDamage(values, stats->m_scalingStatValue, &minDamage, &maxDamage); + + if (stats->m_delay) { + float delay = static_cast(static_cast(stats->m_delay)); + minDamage = minDamage * delay * 0.001f; + maxDamage = 0.001f * (delay * maxDamage); + } + + average = (minDamage + maxDamage) * 0.5f; + SStrCopy(format, FrameScript_GetText("DAMAGE_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, static_cast(minDamage), static_cast(maxDamage)); + SStrCopy(format, FrameScript_GetText("SPEED", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(speed, sizeof(speed), "%s %.2f", format, static_cast(static_cast(static_cast(stats->m_delay)) * 0.001f)); + tooltip->AddLine(text, speed, textColor, textColor, 0); + first = 0; + } else { + for (uint32_t i = 0; i < 2; i++) { + float minValue = stats->m_damageMin[i]; + float maxValue = stats->m_damageMax[i]; + int32_t minDamage = static_cast(minValue <= 0.0f ? minValue - 0.99995f : minValue); + int32_t maxDamage = static_cast(maxValue > 0.0f ? maxValue + 0.99995f : maxValue); + + if (!minDamage && !maxDamage) { + continue; + } + + if (stats->m_damageType[i]) { + SStrPrintf(format, sizeof(format), "SPELL_SCHOOL%d_CAP", stats->m_damageType[i]); + SStrCopy(school, FrameScript_GetText(format, -1, GENDER_NOT_APPLICABLE), sizeof(school)); + + if (stats->m_class == 6) { + float ammo = (minDamage + maxDamage) * 0.5f; + SStrCopy(format, FrameScript_GetText(first ? "AMMO_SCHOOL_DAMAGE_TEMPLATE" : "PLUS_AMMO_SCHOOL_DAMAGE_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, static_cast(ammo), school); + } else if (minDamage == maxDamage) { + SStrCopy(format, FrameScript_GetText(first ? "SINGLE_DAMAGE_TEMPLATE_WITH_SCHOOL" : "PLUS_SINGLE_DAMAGE_TEMPLATE_WITH_SCHOOL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, minDamage, school); + } else { + SStrCopy(format, FrameScript_GetText(first ? "DAMAGE_TEMPLATE_WITH_SCHOOL" : "PLUS_DAMAGE_TEMPLATE_WITH_SCHOOL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, minDamage, maxDamage, school); + } + } else { + if (stats->m_class == 6) { + float ammo = 0.5f * (minDamage + maxDamage); + SStrCopy(format, FrameScript_GetText(first ? "AMMO_DAMAGE_TEMPLATE" : "PLUS_AMMO_DAMAGE_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, static_cast(ammo)); + } else if (minDamage == maxDamage) { + SStrCopy(format, FrameScript_GetText(first ? "SINGLE_DAMAGE_TEMPLATE" : "PLUS_SINGLE_DAMAGE_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, minDamage); + } else { + SStrCopy(format, FrameScript_GetText(first ? "DAMAGE_TEMPLATE" : "PLUS_DAMAGE_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, minDamage, maxDamage); + } + } + + if (!first || stats->m_class != 2) { + speed[0] = '\0'; + } else { + SStrCopy(format, FrameScript_GetText("SPEED", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(speed, sizeof(speed), "%s %.2f", format, static_cast(static_cast(static_cast(stats->m_delay)) * 0.001f)); + } + + tooltip->AddLine(text, speed, textColor, textColor, 0); + first = 0; + average = (stats->m_damageMin[i] + stats->m_damageMax[i]) * 0.5f + average; + } + } + + if (!first && stats->m_class == 2) { + SStrCopy(format, FrameScript_GetText("DPS_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, static_cast(average / (static_cast(static_cast(stats->m_delay)) * 0.001f))); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + return average; +} + +// INLINED +static void AddItemArmorAndStatLines(CGTooltip* tooltip, const ItemStats_C* stats, const ScalingStatValuesRec* values, const ScalingStatDistributionRec* distribution) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char format[1024]; + char text[4096]; + char school[32]; + + if (stats->m_scalingStatValue & 0xF801E0) { + int32_t armor = GetScalingStatArmor(values, stats->m_scalingStatValue); + SStrCopy(format, FrameScript_GetText("ARMOR_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, armor); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } else if (static_cast(stats->m_resistances[0]) > 0) { + SStrCopy(format, FrameScript_GetText("ARMOR_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, stats->m_resistances[0]); + + if (stats->m_armorDamageModifier <= 0.0f) { + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } else { + tooltip->AddLine(text, nullptr, greenColor, greenColor, 0); + } + } + + if (static_cast(stats->m_block) > 0) { + SStrCopy(format, FrameScript_GetText("SHIELD_BLOCK_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, stats->m_block); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + if (!stats->m_scalingStatValue) { + for (uint32_t i = 0; i < 11; i++) { + uint32_t j = 0; + + for (; j < 10; j++) { + if (stats->m_statValue[j] && stats->m_statType[j] != static_cast(-1) && stats->m_statType[j] == s_primaryStatOrder[i]) { + break; + } + } + + if (j == 10) { + continue; + } + + format[0] = '\0'; + SStrCopy(format, FrameScript_GetText(s_itemModTokens[s_primaryStatOrder[i]], -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (format[0]) { + int32_t value = stats->m_statValue[j]; + SStrPrintf(text, sizeof(text), format, 2 * (value <= 0) + '+', abs(value)); + tooltip->AddLine(text, nullptr, textColor, textColor, 1); + } + } + } else if (distribution) { + int32_t budget = values ? GetScalingStatBudget(values, stats->m_scalingStatValue) : 0; + + for (uint32_t i = 0; i < 11; i++) { + int32_t value = 0; + uint32_t j = 0; + + for (; j < 10; j++) { + if (distribution->m_bonus[j] && (value = budget * distribution->m_bonus[j] / 10000) != 0 && distribution->m_statID[j] == s_primaryStatOrder[i]) { + break; + } + } + + if (j == 10) { + continue; + } + + format[0] = '\0'; + SStrCopy(format, FrameScript_GetText(s_itemModTokens[s_primaryStatOrder[i]], -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (format[0]) { + SStrPrintf(text, sizeof(text), format, 2 * (value <= 0) + '+', abs(value)); + tooltip->AddLine(text, nullptr, textColor, textColor, 1); + } + } + } + + int32_t resistance = stats->m_resistances[1]; + bool allEqual = true; + + for (uint32_t i = 2; i < 7; i++) { + if (static_cast(stats->m_resistances[i]) != resistance) { + allEqual = false; + break; + } + } + + if (allEqual) { + if (resistance) { + SStrCopy(format, FrameScript_GetText("ITEM_RESIST_ALL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, 2 * (static_cast(stats->m_resistances[1]) <= 0) + '+', abs(static_cast(stats->m_resistances[1]))); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + return; + } + + for (int32_t i = 2; i <= 6; i++) { + int32_t value = stats->m_resistances[i]; + + if (value) { + SStrPrintf(format, sizeof(format), "SPELL_SCHOOL%d_CAP", i); + SStrCopy(school, FrameScript_GetText(format, -1, GENDER_NOT_APPLICABLE), sizeof(school)); + SStrCopy(format, FrameScript_GetText("ITEM_RESIST_SINGLE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, 2 * (value <= 0) + '+', abs(value), school); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + } +} + +// INLINED +static int32_t AddItemSocketLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, CGPlayer_C* player, CGPlayer_C* ownerPlayer, WOWGUID owner, int32_t socketPreview, int32_t numSockets, int32_t* useSpell, int32_t* useCharges, const SpellItemEnchantmentRec** useEnchant) { + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& grayColor = *reinterpret_cast(&s_tooltipGrayColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + const CImVector& brightRedColor = *reinterpret_cast(&s_tooltipBrightRedColor); + char format[1024]; + char text[4096]; + char conditions[1024]; + char charges[64]; + char name[32]; + int32_t needsUpdate = 0; + int32_t allGemsMatch = 1; + + for (int32_t slot = 0; slot < 12; slot++) { + int32_t enchantId; + + if (item) { + enchantId = (item->GetItemStaticFlags(0) & 0x2000) ? 0 : item->m_item->m_itemFieldEnchantment[slot].m_id; + } else { + enchantId = tooltip->m_itemLinkInfo.m_enchants[slot]; + } + + uint32_t socket = slot - 2; + int32_t isSocket = socket <= 2 && static_cast(socket) < numSockets; + + if (socket <= 2 && socketPreview) { + WOWGUID gemGuid = socket < 3 ? CGItemSocketInfo::m_gemItems[socket] : WOWGUID{ 0 }; + CGItem_C* gemItem = static_cast(ClntObjMgrObjectPtr(gemGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + SpellItemEnchantmentRec* current = g_spellItemEnchantmentDB.GetRecord(abs(enchantId)); + + if (gemItem) { + WOWGUID requester = { 0 }; + ItemStats_C* gemStats = g_itemDBCache.GetRecord(gemItem->m_obj->m_entryID, requester, TooltipItemCallback, tooltip, true); + + if (gemStats) { + GemPropertiesRec* properties = g_gemPropertiesDB.GetRecord(gemStats->m_gemProperties); + + if (properties) { + enchantId = properties->m_enchantID; + } + + if (!CGItemSocketInfo::GemMatchesSocket(stats, gemStats, socket)) { + allGemsMatch = 0; + } + } + } else if (!current && stats->m_socketColor[socket]) { + allGemsMatch = 0; + } + } + + if (!enchantId) { + if (socket > 2 || !isSocket || socketPreview) { + continue; + } + + uint32_t color = stats->m_socketColor[socket]; + + if (color) { + allGemsMatch = 0; + + for (uint32_t i = 0; i < 4; i++) { + if (!((1 << i) & color)) { + continue; + } + + SStrCopy(name, s_socketColorNames[i], STORM_MAX_STR); + SStrUpper(name); + SStrPrintf(format, sizeof(format), "%s%s", "EMPTY_SOCKET_", name); + SStrPrintf(text, sizeof(text), FrameScript_GetText(format, -1, GENDER_NOT_APPLICABLE)); + tooltip->AddLine(text, nullptr, grayColor, grayColor, 0); + SStrPrintf(text, sizeof(text), "Interface\\ItemSocketingFrame\\UI-EmptySocket-%s.blp", s_socketColorNames[i]); + CAaRect coords = { 0.0f, 0.0f, 1.0f, 1.0f }; + uint32_t textureColor = 0xFFFFFFFF; + tooltip->AddTexture(text, coords, *reinterpret_cast(&textureColor)); + break; + } + + continue; + } + + int32_t prismaticId = 0; + + if (item) { + prismaticId = (item->GetItemStaticFlags(0) & 0x2000) ? 0 : item->m_item->m_itemFieldEnchantment[6].m_id; + } else if (tooltip->m_itemUseLinkInfo) { + prismaticId = tooltip->m_itemLinkInfo.m_enchants[6]; + } + + SpellItemEnchantmentRec* prismatic = g_spellItemEnchantmentDB.GetRecord(prismaticId); + + if (prismaticId && prismatic && prismatic->m_requiredSkillID) { + int32_t index = player->GetSkillIndex(prismatic->m_requiredSkillID); + bool skillOk = index >= 0 && static_cast(player->GetSkillValue(index)) >= prismatic->m_requiredSkillRank; + bool levelOk = prismatic->m_minLevel <= static_cast(player->m_unit->m_unitFieldLevel); + const CImVector& color = skillOk && levelOk ? grayColor : redColor; + tooltip->AddLine(FrameScript_GetText("EMPTY_SOCKET_NO_COLOR", -1, GENDER_NOT_APPLICABLE), nullptr, color, color, 0); + CAaRect coords = { 0.0f, 0.0f, 1.0f, 1.0f }; + uint32_t textureColor = 0xFFFFFFFF; + tooltip->AddTexture("Interface\\ItemSocketingFrame\\UI-EmptySocket.blp", coords, *reinterpret_cast(&textureColor)); + + if (!skillOk) { + SkillLineRec* skill = g_skillLineDB.GetRecord(prismatic->m_requiredSkillID); + SStrCopy(format, FrameScript_GetText(prismatic->m_requiredSkillRank ? "SOCKET_ITEM_MIN_SKILL" : "SOCKET_ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (prismatic->m_requiredSkillRank) { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN", prismatic->m_requiredSkillRank); + } else { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN"); + } + + tooltip->AddLine(text, nullptr, redColor, redColor, 0); + } + + if (!levelOk) { + SStrCopy(format, FrameScript_GetText("SOCKET_ITEM_REQ_LEVEL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, prismatic->m_minLevel); + } + + continue; + } + + tooltip->AddLine(FrameScript_GetText("EMPTY_SOCKET_NO_COLOR", -1, GENDER_NOT_APPLICABLE), nullptr, grayColor, grayColor, 0); + CAaRect coords = { 0.0f, 0.0f, 1.0f, 1.0f }; + uint32_t textureColor = 0xFFFFFFFF; + tooltip->AddTexture("Interface\\ItemSocketingFrame\\UI-EmptySocket.blp", coords, *reinterpret_cast(&textureColor)); + continue; + } + + if (slot == 6 || (stats->m_socketBonus && static_cast(stats->m_socketBonus) == enchantId)) { + continue; + } + + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(abs(enchantId)); + + if (!enchant) { + continue; + } + + if (enchant->m_effect[0] == 7) { + *useSpell = enchant->m_effectArg[0]; + + if (item) { + *useCharges = (item->GetItemStaticFlags(0) & 0x2000) ? 0 : item->m_item->m_itemFieldEnchantment[slot].m_charges; + } else { + *useCharges = tooltip->m_itemLinkInfo.m_enchantCharges[slot]; + } + + *useEnchant = enchant; + continue; + } + + if (enchant->m_effect[0] == 3 && owner == ClntObjMgrGetActivePlayer()) { + SpellRec spell; + + if (g_spellDB.GetRecord(enchant->m_effectArg[0], &spell) && ownerPlayer && !CGUnit_C::IsSpellAllowedInArena(&spell)) { + continue; + } + } + + CImVector color = *reinterpret_cast(&s_tooltipTextColor); + + if (socket > 2 && slot < 7) { + color = *reinterpret_cast(enchantId > 0 ? &s_tooltipGreenColor : &s_tooltipBrightRedColor); + } + + int32_t value = item ? item->GetRandomPropertyValue(slot) : CGItem_C::GetRandomPropertyValue(slot, tooltip->m_itemLinkInfo.m_randomPropertiesId, static_cast(tooltip->m_itemLinkInfo.m_propertySeed)); + SpellItemEnchantmentParseText(enchant, format, sizeof(format), value); + uint32_t timeLeft; + + if (item && (timeLeft = item->GetEnchantmentTimeLeft(slot)) != 0) { + CGTooltip::GetDurationString(text, sizeof(text), static_cast(timeLeft), "ITEM_ENCHANT_TIME_LEFT", format, 1, 0); + needsUpdate = 1; + } else { + SStrCopy(text, format, sizeof(text)); + } + + if (!item || !(item->GetItemStaticFlags(0) & 0x2000)) { + int32_t hasCharges = item ? item->m_item->m_itemFieldEnchantment[slot].m_charges : tooltip->m_itemLinkInfo.m_enchantCharges[slot]; + + if (hasCharges) { + int32_t count; + + if (item) { + count = (item->GetItemStaticFlags(0) & 0x2000) ? 0 : item->m_item->m_itemFieldEnchantment[slot].m_charges; + } else { + count = tooltip->m_itemLinkInfo.m_enchantCharges[slot]; + } + + if (item && (item->m_item->m_itemFieldEnchantment[slot].unk_000A & 0xF)) { + color = grayColor; + } else { + SStrPrintf(charges, sizeof(charges), FrameScript_GetText("ITEM_SPELL_CHARGES", -1, GENDER_NOT_APPLICABLE), count); + SStrPrintf(format, sizeof(format), " (%s)", charges); + SStrPack(text, format, sizeof(text)); + } + } + } + + conditions[0] = '\0'; + bool skillOk = true; + bool levelOk = true; + + if (enchant->m_requiredSkillID) { + int32_t index = player->GetSkillIndex(enchant->m_requiredSkillID); + + if (index < 0 || static_cast(player->GetSkillValue(index)) < enchant->m_requiredSkillRank) { + skillOk = false; + } + } + + if (enchant->m_minLevel > static_cast(player->m_unit->m_unitFieldLevel)) { + levelOk = false; + } + + int32_t socketEnchantId = 0; + bool socketOk = true; + bool prismaticEmpty; + + if (item) { + prismaticEmpty = (item->GetItemStaticFlags(0) & 0x2000) || !item->m_item->m_itemFieldEnchantment[6].m_id; + } else { + prismaticEmpty = !tooltip->m_itemLinkInfo.m_enchants[6]; + } + + bool conditionLine = true; + + if (slot < 2 || slot > 4) { + if (slot < 7) { + const CImVector& lineColor = skillOk && levelOk ? color : redColor; + tooltip->AddLine(text, nullptr, lineColor, lineColor, 0); + conditionLine = false; + } else if (slot > 11) { + conditionLine = false; + } + } else if (!stats->m_socketColor[socket] || !prismaticEmpty) { + if (item) { + if (!(item->GetItemStaticFlags(0) & 0x2000)) { + socketEnchantId = item->m_item->m_itemFieldEnchantment[slot].m_id; + } + } else if (tooltip->m_itemUseLinkInfo) { + socketEnchantId = tooltip->m_itemLinkInfo.m_enchants[slot]; + } + + if (socketEnchantId) { + SpellItemEnchantmentRec* socketEnchant = g_spellItemEnchantmentDB.GetRecord(socketEnchantId); + + if (socketEnchant && socketEnchant->m_requiredSkillID) { + int32_t index = player->GetSkillIndex(socketEnchant->m_requiredSkillID); + + if (index < 0 || static_cast(player->GetSkillValue(index)) < socketEnchant->m_requiredSkillRank || enchant->m_minLevel > static_cast(player->m_unit->m_unitFieldLevel)) { + socketOk = false; + } + } + } + } + + if (conditionLine) { + CGPlayer_C* gemOwner = static_cast(ClntObjMgrObjectPtr(owner, TYPEMASK_PLAYER, __FILE__, __LINE__)); + int32_t conditionsMet; + + if (gemOwner) { + gemOwner->CountEquippedGems(); + conditionsMet = GetEnchantmentConditionText(gemOwner, enchant, conditions, sizeof(conditions), 1); + } else { + conditionsMet = GetEnchantmentConditionText(player, enchant, conditions, sizeof(conditions), 1); + } + + const char* colorString; + + if (socketOk && skillOk && levelOk) { + colorString = conditionsMet ? s_colorStrings[0] : s_colorStrings[1]; + } else { + colorString = s_colorStrings[2]; + } + + SStrPrintf(format, sizeof(format), "%s%s%s", colorString, text, "|r"); + SStrPack(format, conditions, sizeof(text)); + tooltip->AddLine(format, nullptr, titleColor, titleColor, 0); + } + + if (enchant->m_srcItemID) { + WOWGUID requester = { 0 }; + ItemStats_C* gem = g_itemDBCache.GetRecord(enchant->m_srcItemID, requester, TooltipItemCallback, tooltip, true); + + if (gem) { + if (!CGItemSocketInfo::GemMatchesSocket(stats, gem, socket)) { + allGemsMatch = 0; + } + + char texture[260]; + const char* path = ClientDBStringLookup(3); + SStrPrintf(texture, sizeof(texture), "%s%s%s", path, *path ? "\\" : "", CGItem_C::GetInventoryArt(gem->m_displayId)); + CAaRect coords = { 0.0f, 0.0f, 1.0f, 1.0f }; + uint32_t textureColor = 0xFFFFFFFF; + tooltip->AddTexture(texture, coords, *reinterpret_cast(&textureColor)); + } + } + + if (!skillOk && enchant->m_requiredSkillID) { + SkillLineRec* skill = g_skillLineDB.GetRecord(enchant->m_requiredSkillID); + SStrCopy(format, FrameScript_GetText(enchant->m_requiredSkillRank ? "ENCHANT_ITEM_MIN_SKILL" : "ENCHANT_ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (enchant->m_requiredSkillRank) { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN", enchant->m_requiredSkillRank); + } else { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN"); + } + + tooltip->AddLine(text, nullptr, redColor, redColor, 0); + } + + if (!levelOk) { + SStrCopy(format, FrameScript_GetText("ENCHANT_ITEM_REQ_LEVEL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, enchant->m_minLevel); + tooltip->AddLine(text, nullptr, redColor, redColor, 0); + } + + if (!socketOk && socketEnchantId) { + SpellItemEnchantmentRec* socketEnchant = g_spellItemEnchantmentDB.GetRecord(socketEnchantId); + + if (socketEnchant && socketEnchant->m_requiredSkillID) { + SkillLineRec* skill = g_skillLineDB.GetRecord(socketEnchant->m_requiredSkillID); + SStrCopy(format, FrameScript_GetText(socketEnchant->m_requiredSkillRank ? "SOCKET_ITEM_MIN_SKILL" : "SOCKET_ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (socketEnchant->m_requiredSkillRank) { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN", socketEnchant->m_requiredSkillRank); + } else { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN"); + } + + tooltip->AddLine(text, nullptr, redColor, redColor, 0); + } + } + } + + if (tooltip->m_itemUseLinkInfo && tooltip->m_itemLinkInfo.m_proposedEnchant) { + SpellRec spell; + + if (g_spellDB.GetRecord(tooltip->m_itemLinkInfo.m_proposedEnchant, &spell)) { + SStrCopy(format, FrameScript_GetText("ITEM_PROPOSED_ENCHANT", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, spell.m_name); + tooltip->AddLine(text, nullptr, greenColor, greenColor, 0); + tooltip->AddLine(FrameScript_GetText("ITEM_ENCHANT_DISCLAIMER", -1, GENDER_NOT_APPLICABLE), nullptr, brightRedColor, brightRedColor, 0); + } + } + + if (stats->m_socketBonus) { + SpellItemEnchantmentRec* bonus = g_spellItemEnchantmentDB.GetRecord(abs(static_cast(stats->m_socketBonus))); + + if (bonus) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_SOCKET_BONUS", -1, GENDER_NOT_APPLICABLE), bonus->m_name); + CImVector color = allGemsMatch ? greenColor : grayColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + } + + return needsUpdate; +} + +// INLINED +static void AddItemStaticSocketLines(CGTooltip* tooltip, const ItemStats_C* stats) { + const CImVector& grayColor = *reinterpret_cast(&s_tooltipGrayColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char name[32]; + char format[1024]; + char text[4096]; + + for (uint32_t slot = 0; slot < 12; slot++) { + uint32_t socket = slot - 2; + + if (socket > 2 || !stats->m_socketColor[socket]) { + continue; + } + + uint32_t color = stats->m_socketColor[socket]; + + for (uint32_t i = 0; i < 4; i++) { + if (!((1 << i) & color)) { + continue; + } + + SStrCopy(name, s_socketColorNames[i], STORM_MAX_STR); + SStrUpper(name); + SStrPrintf(format, sizeof(format), "%s%s", "EMPTY_SOCKET_", name); + SStrPrintf(text, sizeof(text), FrameScript_GetText(format, -1, GENDER_NOT_APPLICABLE)); + tooltip->AddLine(text, nullptr, grayColor, grayColor, 0); + SStrPrintf(text, sizeof(text), "Interface\\ItemSocketingFrame\\UI-EmptySocket-%s.blp", s_socketColorNames[i]); + CAaRect coords = { 0.0f, 0.0f, 1.0f, 1.0f }; + uint32_t textureColor = 0xFFFFFFFF; + tooltip->AddTexture(text, coords, *reinterpret_cast(&textureColor)); + break; + } + } + + if (stats->m_socketBonus) { + SpellItemEnchantmentRec* bonus = g_spellItemEnchantmentDB.GetRecord(abs(static_cast(stats->m_socketBonus))); + + if (bonus) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_SOCKET_BONUS", -1, GENDER_NOT_APPLICABLE), bonus->m_name); + CImVector color = grayColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + } + + if (stats->m_randomProperty || stats->m_randomSuffix) { + tooltip->AddLine(FrameScript_GetText("ITEM_RANDOM_ENCHANT", -1, GENDER_NOT_APPLICABLE), nullptr, greenColor, greenColor, 0); + } +} + +// INLINED +static void AddItemGemLines(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player, int32_t destroyGem) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& grayColor = *reinterpret_cast(&s_tooltipGrayColor); + char text[4096]; + GemPropertiesRec* properties = g_gemPropertiesDB.GetRecord(stats->m_gemProperties); + + if (!properties) { + return; + } + + SpellItemEnchantmentRec* enchant = g_spellItemEnchantmentDB.GetRecord(abs(properties->m_enchantID)); + + if (!enchant) { + return; + } + + int32_t skillOk = 1; + + if (stats->m_requiredSkill) { + int32_t index = player->GetSkillIndex(stats->m_requiredSkill); + skillOk = index >= 0 && player->GetSkillValue(index) >= stats->m_requiredSkillRank; + } + + const CImVector* color; + + if (destroyGem) { + color = &grayColor; + } else { + color = skillOk ? &textColor : &redColor; + } + + tooltip->AddLine(enchant->m_name, nullptr, *color, *color, 0); + GetEnchantmentConditionText(player, enchant, text, sizeof(text), 0); + + if (text[0]) { + tooltip->AddLine(text, nullptr, textColor, textColor, 1); + } +} + +// INLINED +static int32_t AddItemDurabilityLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, int32_t wrapped, int32_t socketPreview) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + char format[1024]; + char text[4096]; + int32_t needsUpdate = 0; + ItemLinkInfo& link = tooltip->m_itemLinkInfo; + + if (!wrapped && !socketPreview) { + int32_t useLinkInfo = tooltip->m_itemUseLinkInfo; + + if (useLinkInfo && link.m_maxDurability == static_cast(-1)) { + link.m_maxDurability = stats->m_maxDurability; + } + + if ((item && !(item->m_item->m_itemFieldFlags & 8) && item->m_item->m_itemFieldMaxdurability) || (useLinkInfo && link.m_maxDurability)) { + SStrCopy(format, FrameScript_GetText("DURABILITY_TEMPLATE", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + uint32_t durability; + uint32_t maxDurability; + + if (item && !(item->m_item->m_itemFieldFlags & 8) && item->m_item->m_itemFieldMaxdurability) { + durability = (item->m_item->m_itemFieldFlags & 8) ? 0 : item->m_item->m_itemFieldDurability; + } else if (tooltip->m_itemUseLinkInfo && link.m_maxDurability) { + durability = link.m_durability; + } else { + durability = stats->m_maxDurability; + } + + if (item && !(item->m_item->m_itemFieldFlags & 8) && item->m_item->m_itemFieldMaxdurability) { + maxDurability = (item->m_item->m_itemFieldFlags & 8) ? 0 : item->m_item->m_itemFieldMaxdurability; + } else if (!tooltip->m_itemUseLinkInfo || (maxDurability = link.m_maxDurability) == 0) { + maxDurability = stats->m_maxDurability; + } + + if (durability >= maxDurability) { + durability = maxDurability; + } + + SStrPrintf(text, sizeof(text), format, durability, maxDurability); + const CImVector& color = durability ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + } + + int32_t timeLeft = stats->m_duration; + + if (timeLeft > 0) { + if (item) { + timeLeft = item->GetExpirationTimeLeft(); + } + + if (timeLeft >= 0 && !socketPreview) { + CGTooltip::GetDurationString(text, sizeof(text), timeLeft, "ITEM_DURATION", nullptr, 1, 1); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + needsUpdate = 1; + } + } + + if (stats->m_holidayId) { + const char* holiday = GetHolidayName(stats->m_holidayId); + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), holiday); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + + return needsUpdate; +} + +// INLINED +static void AddItemRaceClassLines(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + char format[1024]; + char text[4096]; + char line[512]; + char list[512]; + int32_t allowed = 1; + text[0] = '\0'; + + if (((stats->m_allowableRace - 1) & stats->m_allowableRace) || ((stats->m_allowableClass - 1) & stats->m_allowableClass)) { + int32_t allRaces = 1; + int32_t allClasses = 1; + + for (int32_t i = 0; i < g_chrRacesDB.m_numRecords; i++) { + ChrRacesRec* race = g_chrRacesDB.GetRecordByIndex(i); + + if (race && !(race->m_flags & 1) && !((1 << (race->m_id - 1)) & stats->m_allowableRace)) { + allRaces = 0; + break; + } + } + + for (int32_t i = 0; i < g_chrClassesDB.m_numRecords; i++) { + ChrClassesRec* playerClass = g_chrClassesDB.GetRecordByIndex(i); + + if (playerClass && !((1 << (playerClass->m_id - 1)) & stats->m_allowableClass)) { + allClasses = 0; + break; + } + } + + if (!allRaces) { + list[0] = '\0'; + int32_t first = 1; + allowed = 0; + + for (int32_t i = 0; i < g_chrRacesDB.m_numRecords; i++) { + ChrRacesRec* race = g_chrRacesDB.GetRecordByIndex(i); + + if (!(race->m_flags & 1) && race->m_name && ((1 << (race->m_id - 1)) & stats->m_allowableRace)) { + if (!first) { + SStrPack(list, ", ", sizeof(list)); + } + + SStrPack(list, race->m_name, sizeof(list)); + first = 0; + + if (player->m_unit->m_unitFieldBytes0[0] == race->m_id) { + allowed = 1; + } + } + } + + if (list[0]) { + SStrCopy(format, FrameScript_GetText("ITEM_RACES_ALLOWED", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(line, sizeof(line), format, list); + const CImVector& color = allowed ? textColor : redColor; + tooltip->AddLine(line, nullptr, color, color, 0); + } + } + + if (!allClasses) { + list[0] = '\0'; + int32_t first = 1; + allowed = 0; + + for (int32_t i = 0; i < g_chrClassesDB.m_numRecords; i++) { + ChrClassesRec* playerClass = g_chrClassesDB.GetRecordByIndex(i); + + if (playerClass && playerClass->m_name && ((1 << (playerClass->m_id - 1)) & stats->m_allowableClass)) { + if (!first) { + SStrPack(list, ", ", sizeof(list)); + } + + SStrPack(list, playerClass->m_name, sizeof(list)); + first = 0; + + if (player->m_unit->m_unitFieldBytes0[1] == playerClass->m_id) { + allowed = 1; + } + } + } + + if (list[0]) { + SStrCopy(format, FrameScript_GetText("ITEM_CLASSES_ALLOWED", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(line, sizeof(line), format, list); + const CImVector& color = allowed ? textColor : redColor; + tooltip->AddLine(line, nullptr, color, color, 0); + } + } + + return; + } + + for (int32_t i = 0; i < g_chrRacesDB.m_numRecords; i++) { + ChrRacesRec* race = g_chrRacesDB.GetRecordByIndex(i); + + if (!(race->m_flags & 1) && race->m_name && ((1 << (race->m_id - 1)) & stats->m_allowableRace)) { + SStrPrintf(text, sizeof(text), "%s ", race->m_name); + + if (player->m_unit->m_unitFieldBytes0[0] != race->m_id) { + allowed = 0; + } + + break; + } + } + + for (int32_t i = 0; i < g_chrClassesDB.m_numRecords; i++) { + ChrClassesRec* playerClass = g_chrClassesDB.GetRecordByIndex(i); + + if (playerClass && playerClass->m_name && ((1 << (playerClass->m_id - 1)) & stats->m_allowableClass)) { + SStrPack(text, playerClass->m_name, sizeof(text)); + + if (player->m_unit->m_unitFieldBytes0[1] != playerClass->m_id) { + allowed = 0; + } + + break; + } + } + + if (text[0]) { + char classOnly[128]; + SStrCopy(format, FrameScript_GetText("RACE_CLASS_ONLY", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(classOnly, sizeof(classOnly), format, text); + const CImVector& color = allowed ? textColor : redColor; + tooltip->AddLine(classOnly, nullptr, color, color, 0); + } +} + +// INLINED +static void AddItemLevelLines(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player, const ScalingStatDistributionRec* distribution, int32_t displayedLevel) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + char format[1024]; + char text[4096]; + int32_t requiredLevel = stats->m_requiredLevel; + + if (distribution) { + SStrCopy(format, FrameScript_GetText("ITEM_LEVEL_RANGE_CURRENT", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, requiredLevel <= 0 ? 1 : requiredLevel, distribution->m_maxlevel, displayedLevel); + int32_t level = player->m_unit->m_unitFieldLevel; + const CImVector& color = level < requiredLevel || level > distribution->m_maxlevel ? redColor : textColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } else if (requiredLevel > 1) { + SStrCopy(format, FrameScript_GetText("ITEM_MIN_LEVEL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, requiredLevel); + const CImVector& color = requiredLevel <= static_cast(player->m_unit->m_unitFieldLevel) ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + + CVar* showItemLevel = CVar::Lookup("showItemLevel"); + + if (showItemLevel && showItemLevel->m_intValue) { + uint32_t itemClass = stats->m_class; + + if (itemClass == 2 || itemClass == 4 || itemClass == 5 || itemClass == 6) { + SStrCopy(format, FrameScript_GetText("ITEM_LEVEL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, stats->m_itemLevel); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + } +} + +// INLINED +static void AddItemRequirementLines(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player, int32_t itemId, const WOWGUID* requester) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + char format[1024]; + char text[4096]; + + if (stats->m_requiredSkill) { + SkillLineRec* skill = g_skillLineDB.GetRecord(stats->m_requiredSkill); + int32_t index = player->GetSkillIndex(stats->m_requiredSkill); + bool skillOk = index >= 0 && player->GetSkillValue(index) >= stats->m_requiredSkillRank; + + if (stats->m_flags[0] & 0x40000) { + if (index >= 0 && static_cast(player->GetSkillValue(index)) > 0) { + const CImVector& color = skillOk ? textColor : redColor; + tooltip->AddLine(FrameScript_GetText("ITEM_PROSPECTABLE", -1, GENDER_NOT_APPLICABLE), nullptr, color, color, 0); + } + } else if (stats->m_flags[0] & 0x20000000) { + if (index >= 0 && static_cast(player->GetSkillValue(index)) > 0) { + const CImVector& color = skillOk ? textColor : redColor; + tooltip->AddLine(FrameScript_GetText("ITEM_MILLABLE", -1, GENDER_NOT_APPLICABLE), nullptr, color, color, 0); + } + } else { + SStrCopy(format, FrameScript_GetText(stats->m_requiredSkillRank ? "ITEM_MIN_SKILL" : "ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (stats->m_requiredSkillRank) { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN", stats->m_requiredSkillRank); + } else { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN"); + } + + const CImVector& color = skillOk ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + } + + SpellRec spell; + + if (g_spellDB.GetRecord(stats->m_spellId[0], &spell) && spell.m_effect[0] == 36) { + int32_t taughtSpell = spell.m_effectTriggerSpell[0]; + + if (!taughtSpell) { + for (uint32_t i = 0; i < 5; i++) { + if (stats->m_spellTrigger[i] == 6) { + taughtSpell = stats->m_spellId[i]; + break; + } + } + } + + CGUnit_C* learner; + + if (spell.m_implicitTargetA[0] == 5 || spell.m_implicitTargetB[0] == 5) { + CGUnitData* unit = player->m_unit; + learner = static_cast(ClntObjMgrObjectPtr(unit->m_unitFieldCharm ? unit->m_unitFieldCharm : unit->m_unitFieldSummon, TYPEMASK_UNIT, __FILE__, __LINE__)); + } else { + learner = player; + } + + if (learner && (learner->IsSpellKnown(taughtSpell) || learner->IsSpellSuperceded(taughtSpell))) { + tooltip->AddLine(FrameScript_GetText("ITEM_SPELL_KNOWN", -1, GENDER_NOT_APPLICABLE), nullptr, redColor, redColor, 0); + } + } + + if (stats->m_requiredSpell && g_spellDB.GetRecord(stats->m_requiredSpell, &spell)) { + bool known = player->IsSpellKnown(stats->m_requiredSpell) || player->IsSpellSuperceded(stats->m_requiredSpell); + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), spell.m_name); + const CImVector& color = known ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + + if (stats->m_requiredHonorRank) { + bool ranked = player->m_player->m_playerFieldBytes[3] >= stats->m_requiredHonorRank; + const char* rank = player->GetPVPRankString(stats->m_requiredHonorRank); + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), rank); + const CImVector& color = ranked ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + + if (*requester == CGMerchantInfo::m_merchant) { + MerchantItem* merchantItem = CGMerchantInfo::FindItemById(itemId); + + if (merchantItem) { + ItemExtendedCostRec* cost = g_itemExtendedCostDB.GetRecord(merchantItem->m_extendedCostID); + + if (cost) { + if (cost->m_requiredArenaRating > 0) { + int32_t bracket = cost->m_arenaBracket; + + if (bracket > 3) { + bracket = 3; + } else if (bracket < 0) { + bracket = 0; + } + + bool rated = CGArenaTeamInfo::CheckPersonalAndTeamRating(cost->m_requiredArenaRating, bracket); + + if (bracket == 2) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_ARENA_RATING_5V5", -1, GENDER_NOT_APPLICABLE), cost->m_requiredArenaRating); + } else if (bracket == 1) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_ARENA_RATING_3V3", -1, GENDER_NOT_APPLICABLE), cost->m_requiredArenaRating); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_ARENA_RATING", -1, GENDER_NOT_APPLICABLE), cost->m_requiredArenaRating); + } + + const CImVector& color = rated ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + + if (cost->m_itemPurchaseGroup) { + ItemPurchaseGroupRec* group = g_itemPurchaseGroupDB.GetRecord(cost->m_itemPurchaseGroup); + + if (group) { + bool owned = false; + + for (uint32_t i = 0; i < 8; i++) { + if (group->m_itemID[i] && player->m_bag.FindItemOfType(group->m_itemID[i], 8)) { + owned = true; + break; + } + } + + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_PURCHASE_GROUP", -1, GENDER_NOT_APPLICABLE), group->m_name); + const CImVector& color = owned ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + } + } + } + } + + if (stats->m_requiredCityRank) { + bool hasMedal = ((1 << (stats->m_requiredCityRank - 1)) & player->m_player->m_playerFieldPvpMedals) != 0; + SStrPrintf(format, sizeof(format), "PVP_MEDAL%d", stats->m_requiredCityRank); + const char* medal = FrameScript_GetText(format, -1, GENDER_NOT_APPLICABLE); + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), medal); + const CImVector& color = hasMedal ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + + if (stats->m_requiredReputationFaction) { + int32_t rank = stats->m_requiredReputationRank; + bool reached = GetRepListRepValue(stats->m_requiredReputationFaction) >= CGReputationInfo::m_reactionThresholds[rank]; + FactionRec* faction = g_factionDB.GetRecord(stats->m_requiredReputationFaction); + SStrPrintf(format, sizeof(format), "FACTION_STANDING_LABEL%d", rank + 1); + const char* name = faction ? faction->m_name : "UNKNOWN"; + const char* standing = player->GetFrameScriptText(format, -1); + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_REQ_REPUTATION", -1, GENDER_NOT_APPLICABLE), name, standing); + const CImVector& color = reached ? textColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } +} + +// INLINED +static int32_t CollectItemSetData(CGTooltip* tooltip, const ItemSetRec* set, CGPlayer_C* player, CGPlayer_C* ownerPlayer, int32_t* equipped, int32_t* numItems, int32_t* numEquipped) { + ItemSetTooltipData data; + data.m_tooltip = tooltip; + data.m_set = set; + data.m_equipped = equipped; + memset(data.m_slotUsed, 0, sizeof(data.m_slotUsed)); + + for (uint32_t i = 0; i < 17; i++) { + if (!set->m_itemID[i]) { + data.m_items[i] = nullptr; + continue; + } + + WOWGUID requester = { 0 }; + ItemNameCache_C* item = g_itemNameDBCache.GetRecord(set->m_itemID[i], requester, TooltipItemCallback, tooltip, true); + data.m_items[i] = item; + + if (!item) { + continue; + } + + uint32_t j = 0; + + for (; j < i; j++) { + ItemNameCache_C* previous = data.m_items[j]; + + if (!previous) { + break; + } + + uint32_t type = item->m_inventoryType; + uint32_t previousType = previous->m_inventoryType; + + if (type == previousType && type != 11 && type != 12 && type != 13) { + break; + } + + if (type == 5 ? previousType == 20 : type == 20 && previousType == 5) { + break; + } + } + + if (j == i) { + (*numItems)++; + } + } + + for (int32_t pass = 0; pass < 2; pass++) { + if (ownerPlayer) { + for (int32_t slot = 0; slot < 19; slot++) { + const VisibleItem_C* visible = ownerPlayer->GetVisibleItem(slot); + + if (visible) { + int32_t itemId = abs(visible->m_itemId); + + if (itemId && ResolveItemSetItem(&data, pass, itemId, slot)) { + (*numEquipped)++; + } + } + } + } else { + for (int32_t slot = 0; slot < 19; slot++) { + const CGItem_C* item = player->m_bag.GetItemPointer(slot); + + if (item && ResolveItemSetItem(&data, pass, item->m_obj->m_entryID, slot)) { + (*numEquipped)++; + } + } + } + } + + return player->MeetsItemSetSkill(set); +} + +// INLINED +static void AddItemSpellStatLines(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player, const ScalingStatValuesRec* values, const ScalingStatDistributionRec* distribution, float averageDamage) { + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char format[1024]; + char bonus[4096]; + char text[4096]; + + if (player->m_unit->m_unitFieldBytes0[1] == 11) { + int32_t attackPower = GetFeralAttackPower(stats, averageDamage); + + if (attackPower > 0) { + SStrCopy(format, FrameScript_GetText("FERAL_DRUID_ITEM_AP", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(bonus, 1024, format, attackPower); + tooltip->AddLine(bonus, nullptr, greenColor, greenColor, 1); + } + } + + if (!stats->m_scalingStatValue) { + for (uint32_t i = 0; i < 10; i++) { + int32_t value = stats->m_statValue[i]; + + if (!value || stats->m_statType[i] == static_cast(-1)) { + continue; + } + + uint32_t j = 0; + + for (; j < sizeof(s_spellStatOrder) / sizeof(s_spellStatOrder[0]); j++) { + if (static_cast(stats->m_statType[i]) == s_spellStatOrder[j]) { + break; + } + } + + if (j == sizeof(s_spellStatOrder) / sizeof(s_spellStatOrder[0])) { + continue; + } + + format[0] = '\0'; + SStrCopy(format, FrameScript_GetText(s_itemModTokens[s_spellStatOrder[j]], -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (format[0]) { + if (SStrStr(format, "%c")) { + SStrPrintf(bonus, sizeof(bonus), format, 2 * (value <= 0) + '+', abs(value)); + } else { + SStrPrintf(bonus, sizeof(bonus), format, value); + } + + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONEQUIP", -1, GENDER_NOT_APPLICABLE), bonus); + tooltip->AddLine(text, nullptr, greenColor, greenColor, 0); + } + } + + return; + } + + if (distribution) { + int32_t budget = GetScalingStatBudget(values, stats->m_scalingStatValue); + + if (budget) { + for (uint32_t i = 0; i < 10; i++) { + int32_t value; + + if (!distribution->m_bonus[i] || (value = distribution->m_bonus[i] * budget / 10000) == 0) { + continue; + } + + uint32_t j = 0; + + for (; j < sizeof(s_spellStatOrder) / sizeof(s_spellStatOrder[0]); j++) { + if (distribution->m_statID[i] == s_spellStatOrder[j]) { + break; + } + } + + if (j == sizeof(s_spellStatOrder) / sizeof(s_spellStatOrder[0])) { + continue; + } + + format[0] = '\0'; + SStrCopy(format, FrameScript_GetText(s_itemModTokens[s_spellStatOrder[j]], -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (format[0]) { + if (SStrStr(format, "%c")) { + SStrPrintf(bonus, sizeof(bonus), format, 2 * (value <= 0) + '+', abs(value)); + } else { + SStrPrintf(bonus, sizeof(bonus), format, value); + } + + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONEQUIP", -1, GENDER_NOT_APPLICABLE), bonus); + tooltip->AddLine(text, nullptr, greenColor, greenColor, 1); + } + } + } + } + + if ((stats->m_scalingStatValue & 0x8000) && values && values->m_spellPower) { + SStrCopy(format, FrameScript_GetText(s_itemModTokens[45], -1, GENDER_NOT_APPLICABLE), sizeof(format)); + + if (format[0]) { + SStrPrintf(bonus, sizeof(bonus), format, values->m_spellPower); + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONEQUIP", -1, GENDER_NOT_APPLICABLE), bonus); + tooltip->AddLine(text, nullptr, greenColor, greenColor, 1); + } + } +} + +// INLINED +static int32_t AddItemSpellTriggerLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, int32_t hideCharges, FILE* stream) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char format[1024]; + char cooldown[1024]; + char text[4096]; + char line[1024]; + char buffer[4096]; + int32_t isRecipe = 0; + + for (int32_t i = 0; i < 5; i++) { + if (stream) { + sprintf(buffer, "\t\t\t", i); + fputs(buffer, stream); + } + + if (static_cast(stats->m_spellId[i]) <= 0) { + if (stream) { + sprintf(buffer, "\n", i); + fputs(buffer, stream); + } + + continue; + } + + SpellRec spell; + + if (!g_spellDB.GetRecord(stats->m_spellId[i], &spell)) { + if (stream) { + sprintf(buffer, "\n", i); + fputs(buffer, stream); + } + + continue; + } + + SpellParserParseText(&spell, format, sizeof(format), 0, 0, 0, 0, 1, 0); + + if (!format[0] && stats->m_spellTrigger[i] != 6) { + if (stream) { + sprintf(buffer, "\n", i); + fputs(buffer, stream); + } + + continue; + } + + switch (stats->m_spellTrigger[i]) { + case 0: { + int32_t spellCooldown = stats->m_spellCooldown[i]; + + if (spellCooldown < 0) { + if (static_cast(stats->m_spellCategoryCooldown[i]) >= 0) { + spellCooldown = 0; + } else { + int32_t recoveryTime = spell.m_recoveryTime; + int32_t categoryRecoveryTime = spell.m_categoryRecoveryTime; + Spell_C_ModifySpellValue(&spell, recoveryTime, 11); + + if (spell.m_attributesExF >= 0) { + Spell_C_ModifySpellValue(&spell, categoryRecoveryTime, 11); + } + + spellCooldown = recoveryTime <= categoryRecoveryTime ? categoryRecoveryTime : recoveryTime; + } + } + + if (spellCooldown <= 0) { + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONUSE", -1, GENDER_NOT_APPLICABLE), format); + } else { + CGTooltip::GetItemDurationString(cooldown, sizeof(cooldown), spellCooldown, "ITEM_COOLDOWN_TOTAL"); + SStrPrintf(text, sizeof(text), "%s %s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONUSE", -1, GENDER_NOT_APPLICABLE), format, cooldown); + } + + break; + } + + case 1: + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONEQUIP", -1, GENDER_NOT_APPLICABLE), format); + break; + + case 2: + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONPROC", -1, GENDER_NOT_APPLICABLE), format); + break; + + case 6: + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONUSE", -1, GENDER_NOT_APPLICABLE), stats->m_description); + isRecipe = 1; + break; + + default: + SStrCopy(text, format, sizeof(text)); + break; + } + + SpellRec created; + int32_t hasCreated = 0; + int32_t createsItem = 0; + + if (stats->m_spellTrigger[i] == 6) { + hasCreated = 1; + created = spell; + } else if (spell.m_effect[0] == 36) { + hasCreated = g_spellDB.GetRecord(spell.m_effectTriggerSpell[0], &created); + } + + if (hasCreated && (created.m_effect[0] == 24 || created.m_effect[0] == 157 || created.m_effect[0] == 59) && created.m_effectItemType[0]) { + createsItem = 1; + } + + if (stream) { + CGTooltip::FormatStringForXML(format, buffer); + fputs(buffer, stream); + } + + const CImVector& color = createsItem ? textColor : greenColor; + tooltip->AddLine(text, nullptr, color, color, 1); + + if (!hideCharges) { + int32_t charges; + + if (tooltip->m_itemUseLinkInfo) { + charges = tooltip->m_itemLinkInfo.m_spellCharges; + } else { + charges = item ? item->m_item->m_itemFieldSpellCharges[i] : stats->m_spellCharges[i]; + } + + if (stats->m_spellCharges[i] && stats->m_spellCharges[i] != -1) { + int32_t count = abs(charges); + + if (count) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_SPELL_CHARGES", -1, GENDER_NOT_APPLICABLE), count); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_SPELL_CHARGES_NONE", -1, GENDER_NOT_APPLICABLE)); + } + + if (stream) { + CGTooltip::FormatStringForXML(text, buffer); + fputs(buffer, stream); + } + + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + } + + if (hasCreated && createsItem) { + WOWGUID requester = { 0 }; + WOWGUID itemGuid = { 0 }; + tooltip->SetItem(created.m_effectItemType[0], &requester, &itemGuid, 0, 0, 0, 1, WOWGUID{ 0 }, 0, nullptr, hideCharges, nullptr, 0, 0, 1); + int32_t first = 1; + int32_t missing = 0; + text[0] = '\0'; + + for (uint32_t j = 0; j < 8; j++) { + int32_t reagent = created.m_reagent[j]; + + if (reagent <= 0) { + continue; + } + + WOWGUID query; + query.m_guid = static_cast(static_cast(created.m_id)) | 0x1FE0000000000000ULL; + ItemStats_C* reagentStats = g_itemDBCache.GetRecord(reagent, query, TooltipItemCallback, tooltip, true); + + if (!reagentStats) { + missing = 1; + continue; + } + + if (first) { + first = 0; + } else { + SStrPack(text, ", ", sizeof(text)); + } + + if (created.m_reagentCount[j] <= 1) { + SStrCopy(format, reagentStats->m_name[0], sizeof(format)); + } else { + SStrPrintf(format, sizeof(format), "%s (%d)", reagentStats->m_name[0], created.m_reagentCount[j]); + } + + SStrPack(text, format, sizeof(text)); + } + + if (!first && !missing) { + SStrPrintf(format, sizeof(format), FrameScript_GetText("ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), text); + SStrPrintf(line, sizeof(line), "\n%s", format); + + if (stream) { + CGTooltip::FormatStringForXML(line, buffer); + fputs(buffer, stream); + } + + tooltip->AddLine(line, nullptr, textColor, textColor, 1); + } + } + + if (stream) { + sprintf(buffer, "\n", i); + fputs(buffer, stream); + } + } + + return isRecipe; +} + +// INLINED +static void AddItemSetLines(CGTooltip* tooltip, const ItemSetRec* set, CGPlayer_C* player, const int32_t* equipped, int32_t numItems, int32_t numEquipped, int32_t skillOk, FILE* stream) { + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& grayColor = *reinterpret_cast(&s_tooltipGrayColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + const CImVector& itemSetColor = *reinterpret_cast(&s_tooltipItemSetColor); + char format[1024]; + char text[4096]; + char buffer[4096]; + tooltip->AddLine(" ", nullptr, titleColor, titleColor, 1); + SStrCopy(format, FrameScript_GetText("ITEM_SET_NAME", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SStrPrintf(text, sizeof(text), format, set->m_name, numEquipped, numItems); + tooltip->AddLine(text, nullptr, titleColor, titleColor, 0); + + if (set->m_requiredSkill) { + SStrCopy(format, FrameScript_GetText(set->m_requiredSkillRank ? "ITEM_MIN_SKILL" : "ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(format)); + SkillLineRec* skill = g_skillLineDB.GetRecord(set->m_requiredSkill); + + if (set->m_requiredSkillRank) { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN", set->m_requiredSkillRank); + } else { + SStrPrintf(text, sizeof(text), format, skill ? skill->m_displayName : "UNKNOWN"); + } + + int32_t index = player->GetSkillIndex(set->m_requiredSkill); + const CImVector& color = index < 0 || static_cast(player->GetSkillValue(index)) < set->m_requiredSkillRank ? redColor : textColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + + for (uint32_t i = 0; i < 17; i++) { + if (!set->m_itemID[i]) { + continue; + } + + const char* name; + + if (equipped[i]) { + WOWGUID requester = { 0 }; + ItemStats_C* stats = g_itemDBCache.GetRecord(equipped[i], requester, nullptr, nullptr, false); + + if (!stats) { + continue; + } + + name = stats->m_name[0]; + } else { + WOWGUID requester = { 0 }; + ItemNameCache_C* item = g_itemNameDBCache.GetRecord(set->m_itemID[i], requester, nullptr, nullptr, false); + + if (!item) { + continue; + } + + name = item->m_name; + } + + if (name) { + SStrPrintf(text, sizeof(text), " %s", name); + const CImVector& color = equipped[i] ? itemSetColor : grayColor; + tooltip->AddLine(text, nullptr, color, color, 0); + } + } + + tooltip->AddLine(" ", nullptr, titleColor, titleColor, 1); + uint8_t order[8]; + + for (uint32_t i = 0; i < 8; i++) { + order[i] = i; + } + + s_sortItemSet = set; + qsort(order, 8, sizeof(order[0]), SortItemSetBonuses); + + for (int32_t i = 0; i < 8; i++) { + uint8_t index = order[i]; + + if (stream) { + sprintf(buffer, "\t\t\t", i); + fputs(buffer, stream); + } + + if (set->m_setSpellID[index]) { + SpellRec spell; + + if (g_spellDB.GetRecord(set->m_setSpellID[index], &spell)) { + SpellParserParseText(&spell, format, sizeof(format), 0, 0, 0, 0, 1, 0); + + if (skillOk && numEquipped >= set->m_setThreshold[index]) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_SET_BONUS", -1, GENDER_NOT_APPLICABLE), format); + tooltip->AddLine(text, nullptr, greenColor, greenColor, 1); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_SET_BONUS_GRAY", -1, GENDER_NOT_APPLICABLE), set->m_setThreshold[index], format); + tooltip->AddLine(text, nullptr, grayColor, grayColor, 1); + } + + if (stream) { + CGTooltip::FormatStringForXML(format, buffer); + fputs(buffer, stream); + } + } + } + + if (stream) { + sprintf(buffer, "\n", i); + fputs(buffer, stream); + } + } +} + +// INLINED +static void AddItemUseEnchantLine(CGTooltip* tooltip, CGPlayer_C* player, int32_t useSpell, int32_t useCharges, const SpellItemEnchantmentRec* enchant) { + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char format[1024]; + char cooldown[1024]; + char text[4096]; + char charges[64]; + char token[256]; + SpellRec spell; + + if (!g_spellDB.GetRecord(useSpell, &spell)) { + return; + } + + SpellParserParseText(&spell, format, sizeof(format), 0, 0, 0, 0, 1, 0); + int32_t skillOk = 1; + bool levelOk = true; + + if (enchant->m_requiredSkillID) { + int32_t index = player->GetSkillIndex(enchant->m_requiredSkillID); + + if (index < 0 || static_cast(player->GetSkillValue(index)) < enchant->m_requiredSkillRank) { + skillOk = 0; + } + } + + if (enchant->m_minLevel > static_cast(player->m_unit->m_unitFieldLevel)) { + levelOk = false; + } + + int32_t recoveryTime = spell.m_recoveryTime; + int32_t categoryRecoveryTime = spell.m_categoryRecoveryTime; + Spell_C_ModifySpellValue(&spell, recoveryTime, 11); + + if (spell.m_attributesExF >= 0) { + Spell_C_ModifySpellValue(&spell, categoryRecoveryTime, 11); + } + + int32_t spellCooldown = recoveryTime <= categoryRecoveryTime ? categoryRecoveryTime : recoveryTime; + + if (spellCooldown <= 0) { + SStrPrintf(text, sizeof(text), "%s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONUSE", -1, GENDER_NOT_APPLICABLE), format); + } else { + CGTooltip::GetItemDurationString(cooldown, sizeof(cooldown), spellCooldown, "ITEM_COOLDOWN_TOTAL"); + SStrPrintf(text, sizeof(text), "%s %s %s", FrameScript_GetText("ITEM_SPELL_TRIGGER_ONUSE", -1, GENDER_NOT_APPLICABLE), format, cooldown); + } + + if (useCharges && useCharges != -1) { + SStrPrintf(charges, sizeof(charges), FrameScript_GetText("ITEM_SPELL_CHARGES", abs(useCharges), GENDER_NOT_APPLICABLE)); + SStrPrintf(format, sizeof(format), " (%s)", charges); + SStrPack(text, format, sizeof(text)); + } + + const CImVector& color = skillOk && levelOk ? greenColor : redColor; + tooltip->AddLine(text, nullptr, color, color, 1); + + if (!skillOk && enchant->m_requiredSkillID) { + SkillLineRec* skill = g_skillLineDB.GetRecord(enchant->m_requiredSkillID); + SStrCopy(token, FrameScript_GetText(enchant->m_requiredSkillRank ? "ENCHANT_ITEM_MIN_SKILL" : "ENCHANT_ITEM_REQ_SKILL", -1, GENDER_NOT_APPLICABLE), sizeof(token)); + + if (enchant->m_requiredSkillRank) { + SStrPrintf(text, sizeof(text), token, skill ? skill->m_displayName : "UNKNOWN", enchant->m_requiredSkillRank); + } else { + SStrPrintf(text, sizeof(text), token, skill ? skill->m_displayName : "UNKNOWN"); + } + + tooltip->AddLine(text, nullptr, redColor, redColor, 0); + } + + if (!levelOk) { + SStrCopy(token, FrameScript_GetText("ENCHANT_ITEM_REQ_LEVEL", -1, GENDER_NOT_APPLICABLE), sizeof(token)); + SStrPrintf(text, sizeof(text), token, enchant->m_minLevel); + tooltip->AddLine(text, nullptr, redColor, redColor, 0); + } +} + +// INLINED +static void AddItemCreatorLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, int32_t wrapped) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + char text[4096]; + WOWGUID guid; + + if (wrapped) { + if (item) { + guid = item->m_item->m_itemFieldGiftcreator; + } else { + if (!tooltip->m_itemUseLinkInfo) { + return; + } + + guid = tooltip->m_itemLinkInfo.m_giftCreator; + } + + if (guid) { + NameCache* name = g_nameDBCache.GetRecord(guid.m_guid, guid, TooltipItemCallback, tooltip, true); + + if (name) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_WRAPPED_BY", -1, GENDER_NOT_APPLICABLE), name->m_name); + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + } + } else { + if (item) { + guid = item->m_item->m_itemFieldCreator; + } else { + if (!tooltip->m_itemUseLinkInfo) { + return; + } + + guid = tooltip->m_itemLinkInfo.m_creator; + } + + if (guid) { + NameCache* name = g_nameDBCache.GetRecord(guid.m_guid, guid, TooltipItemCallback, tooltip, true); + + if (name) { + if (item && (item->m_item->m_itemFieldFlags & 0x200)) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_WRITTEN_BY", -1, GENDER_NOT_APPLICABLE), name->m_name); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_CREATED_BY", -1, GENDER_NOT_APPLICABLE), name->m_name); + } + + tooltip->AddLine(text, nullptr, textColor, textColor, 0); + } + } + } + + if (!item) { + return; + } + + uint32_t flags = stats->m_flags[0]; + + if (!tooltip->m_itemUseLinkInfo && (((flags & 4) && (!stats->m_lockId || (item->m_item->m_itemFieldFlags & 4))) || ((flags & 0x200) && (item->m_item->m_itemFieldFlags & 8)))) { + tooltip->AddLine(FrameScript_GetText("ITEM_OPENABLE", -1, GENDER_NOT_APPLICABLE), nullptr, greenColor, greenColor, 0); + } else if (item->GetPageTextID(nullptr) || (item->m_item->m_itemFieldFlags & 0x200)) { + tooltip->AddLine(FrameScript_GetText("ITEM_READABLE", -1, GENDER_NOT_APPLICABLE), nullptr, greenColor, greenColor, 0); + } + + if (item->GetNumSockets()) { + tooltip->AddLine(FrameScript_GetText("ITEM_SOCKETABLE", -1, GENDER_NOT_APPLICABLE), nullptr, greenColor, greenColor, 0); + } +} + +// INLINED +static void AddItemDisenchantLine(CGTooltip* tooltip, const ItemStats_C* stats, CGPlayer_C* player) { + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& disenchantColor = *reinterpret_cast(&s_tooltipDisenchantColor); + char text[4096]; + SkillLineAbilityRec* ability = SpellTableLookupAbility(player->m_unit->m_unitFieldBytes0[0], player->m_unit->m_unitFieldBytes0[1], Spell_C_GetTargetingSpell()); + SkillLineRec* skill = g_skillLineDB.GetRecord(ability ? ability->m_skillLine : -1); + SpellRec spell; + + if (!skill || !ability || !g_spellDB.GetRecord(Spell_C_GetTargetingSpell(), &spell) || spell.m_effect[0] != 99) { + return; + } + + int32_t rank = player->GetSkillRank(ability->m_skillLine); + int32_t required = stats->m_requiredDisenchantSkill; + const CImVector* color; + + if (required > 0) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_DISENCHANT_MIN_SKILL", -1, GENDER_NOT_APPLICABLE), skill->m_displayName, required); + color = rank >= static_cast(stats->m_requiredDisenchantSkill) ? &disenchantColor : &redColor; + } else if (!required) { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_DISENCHANT_ANY_SKILL", -1, GENDER_NOT_APPLICABLE)); + color = &disenchantColor; + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("ITEM_DISENCHANT_NOT_DISENCHANTABLE", -1, GENDER_NOT_APPLICABLE)); + color = &redColor; + } + + tooltip->AddLine(text, nullptr, *color, *color, 0); +} + +// INLINED +static int32_t AddItemTradeLines(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, CGPlayer_C* player) { + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + const CImVector& refundColor = *reinterpret_cast(&s_tooltipRefundColor); + const CImVector& tradeColor = *reinterpret_cast(&s_tooltipTradeColor); + char format[1024]; + char text[4096]; + char minutes[256]; + int32_t refundable = 0; + CGItem_C::ItemPurchaseData* purchase = item->m_itemPurchaseData; + + if (purchase) { + int32_t timeLeft = purchase->m_refundTimeLeft - player->GetPlayedTime() + 7200; + + if (timeLeft > 0 && !item->HasEnchantments()) { + if (static_cast(timeLeft - 3660) > 3539) { + CGTooltip::GetDurationString(format, sizeof(format), timeLeft, "INT_SPELL_DURATION", nullptr, 0, 1); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("INT_SPELL_DURATION_HOURS", 1, GENDER_NOT_APPLICABLE), 1); + int32_t count = (timeLeft - 3600) / 60; + SStrPrintf(minutes, sizeof(minutes), FrameScript_GetText("INT_SPELL_DURATION_MIN", count, GENDER_NOT_APPLICABLE), count); + SStrPrintf(format, sizeof(format), "%s%s%s", text, FrameScript_GetText("TIME_UNIT_DELIMITER", -1, GENDER_NOT_APPLICABLE), minutes); + } + SStrPrintf(text, sizeof(text), FrameScript_GetText("REFUND_TIME_REMAINING", -1, GENDER_NOT_APPLICABLE), format); + tooltip->AddLine(" ", nullptr, titleColor, titleColor, 0); + tooltip->AddLine(text, nullptr, refundColor, refundColor, 1); + refundable = 1; + } + } else if ((stats->m_flags[0] & 0x1000) && !(item->m_itemFlags & 4)) { + item->RequestItemPurchaseData(); + refundable = 1; + } + + if (item->IsBound() && !item->IsPermanentlyBoundForTrade()) { + int32_t timeLeft = item->m_item->m_itemFieldCreatePlayedTime - player->GetPlayedTime() + 7200; + + if (timeLeft > 0) { + if (static_cast(timeLeft - 3660) > 3539) { + CGTooltip::GetDurationString(format, sizeof(format), timeLeft, "INT_SPELL_DURATION", nullptr, 0, 1); + } else { + SStrPrintf(text, sizeof(text), FrameScript_GetText("INT_SPELL_DURATION_HOURS", 1, GENDER_NOT_APPLICABLE), 1); + int32_t count = (timeLeft - 3600) / 60; + SStrPrintf(minutes, sizeof(minutes), FrameScript_GetText("INT_SPELL_DURATION_MIN", count, GENDER_NOT_APPLICABLE), count); + SStrPrintf(format, sizeof(format), "%s%s%s", text, FrameScript_GetText("TIME_UNIT_DELIMITER", -1, GENDER_NOT_APPLICABLE), minutes); + } + SStrPrintf(text, sizeof(text), FrameScript_GetText("BIND_TRADE_TIME_REMAINING", -1, GENDER_NOT_APPLICABLE), format); + tooltip->AddLine(" ", nullptr, titleColor, titleColor, 0); + tooltip->AddLine(text, nullptr, tradeColor, tradeColor, 1); + } + } + + return refundable; +} + +// INLINED +static void AddItemSellPrice(CGTooltip* tooltip, const ItemStats_C* stats, CGItem_C* item, CGPlayer_C* player) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + int32_t price = stats->m_sellPrice; + int32_t maxPrice = -1; + + if (!price) { + if (!CGMerchantInfo::m_merchant || !item) { + return; + } + + if (item->m_item->m_itemFieldContained == player->m_obj->m_guid) { + WOWGUID guid = item->m_obj->m_guid; + uint32_t slot = 0; + + for (; slot < player->m_bag.m_numSlots; slot++) { + if (player->m_bag.m_slots[slot] == guid) { + break; + } + } + + if (slot >= player->m_bag.m_numSlots || slot < 23) { + return; + } + } + + tooltip->AddLine(FrameScript_GetText("ITEM_UNSELLABLE", -1, GENDER_NOT_APPLICABLE), nullptr, textColor, textColor, 0); + return; + } + + if (!item) { + if (tooltip->m_itemUseLinkInfo) { + uint32_t stackCount = tooltip->m_itemLinkInfo.m_stackCount; + int32_t maxStackCount = tooltip->m_itemLinkInfo.m_maxStackCount; + int32_t sellPrice = price; + price = stackCount * sellPrice; + + if (maxStackCount > static_cast(stackCount)) { + maxPrice = sellPrice * maxStackCount; + } + } + + tooltip->AddMoney(price, maxPrice); + return; + } + + if (item->GetEnchantmentSpell(0) && !item->HasOnUseEnchant() && item->GetUsableSpellCharges() < -1) { + price = price * item->GetCurrentSpellCharges() / item->GetUsableSpellCharges(); + } + + int32_t repairCost = item->GetRepairCost(); + + if (repairCost < price) { + if (repairCost) { + price -= repairCost; + } + } else { + price = 1; + } + + int32_t stackCount = item->m_item->m_itemFieldStackCount; + + if (stackCount <= 1) { + tooltip->AddMoney(price, maxPrice); + } else { + tooltip->AddMoney(stackCount * price, maxPrice); + } +} + +// VERIFY: 3c6e8093 manual +// OFFSET: 0x006277F0 +int32_t CGTooltip::SetItem(int32_t itemId, const WOWGUID* requester, const WOWGUID* itemGuid, int32_t nameOnly, int32_t compare, int32_t useLinkInfo, int32_t append, WOWGUID owner, int32_t socketPreview, FILE* stream, int32_t hideCharges, const ItemLinkInfo* link, int32_t minimumLevel, int32_t skipLock, int32_t skipSellPrice) { + const CImVector& textColor = *reinterpret_cast(&s_tooltipTextColor); + const CImVector& titleColor = *reinterpret_cast(&s_tooltipTitleColor); + const CImVector& redColor = *reinterpret_cast(&s_tooltipRedColor); + const CImVector& grayColor = *reinterpret_cast(&s_tooltipGrayColor); + char text[4096]; + + if (!append) { + this->ClearTooltip(); + } + + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + this->Hide(); + return 0; + } + + CGPlayer_C* ownerPlayer = nullptr; + + if (owner) { + ownerPlayer = static_cast(ClntObjMgrObjectPtr(owner, TYPEMASK_PLAYER, __FILE__, __LINE__)); + } + + if (!append) { + this->m_itemGuid = *itemGuid; + this->m_itemId = itemId; + this->m_itemUseLinkInfo = useLinkInfo; + this->m_itemNameOnly = nameOnly; + this->m_itemSocketPreview = socketPreview; + this->m_itemCompare = compare; + this->m_itemOwner = owner; + this->m_itemHideCharges = hideCharges; + this->m_itemMinimumLevel = minimumLevel; + this->m_itemSkipSellPrice = skipSellPrice; + } + + ItemStats_C* stats = g_itemDBCache.GetRecord(itemId, *requester, TooltipItemCallback, this, true); + + if (!stats) { + return this->SetItemNoStats(); + } + + CGItem_C* item = static_cast(ClntObjMgrObjectPtr(*itemGuid, TYPEMASK_ITEM, __FILE__, __LINE__)); + int32_t needsUpdate = 0; + int32_t wrapped = (item && (item->m_item->m_itemFieldFlags & 8)) || (this->m_itemUseLinkInfo && this->m_itemLinkInfo.m_wrapped); + int32_t randomPropertiesId = 0; + int32_t useSpell = 0; + int32_t useCharges = 0; + const SpellItemEnchantmentRec* useEnchant = nullptr; + + if (!wrapped) { + if (this->m_itemUseLinkInfo && this->m_itemLinkInfo.m_randomPropertiesId) { + randomPropertiesId = this->m_itemLinkInfo.m_randomPropertiesId; + + if (randomPropertiesId > 0) { + ItemRandomPropertiesRec* properties = g_itemRandomPropertiesDB.GetRecord(randomPropertiesId); + + if (properties) { + for (uint32_t i = 0; i < 5; i++) { + this->m_itemLinkInfo.m_enchants[i + 7] = properties->m_enchantment[i]; + } + } + } else { + ItemRandomSuffixRec* suffix = g_itemRandomSuffixDB.GetRecord(-randomPropertiesId); + + if (suffix) { + for (uint32_t i = 0; i < 5; i++) { + this->m_itemLinkInfo.m_enchants[i + 7] = i < 5 ? suffix->m_enchantment[i] : 0; + } + } + } + } else if (item) { + randomPropertiesId = item->m_item->m_itemFieldRandomPropertiesId; + } + } + + int32_t destroyGem = 0; + + if (compare) { + if (stats->m_gemProperties) { + this->AddLine(FrameScript_GetText("DESTROY_GEM", -1, GENDER_NOT_APPLICABLE), nullptr, redColor, redColor, 0); + destroyGem = 1; + } else { + this->AddLine(FrameScript_GetText("CURRENTLY_EQUIPPED", -1, GENDER_NOT_APPLICABLE), nullptr, grayColor, grayColor, 0); + } + } + + AddItemNameLines(this, stats, itemId, randomPropertiesId, nameOnly, append, destroyGem); + + if (item && !AddItemPetitionLines(this, item, itemGuid)) { + return 0; + } + + if (stats->m_flags[0] & 0x2000) { + const CImVector& greenColor = *reinterpret_cast(&s_tooltipGreenColor); + this->AddLine(FrameScript_GetText("ITEM_SIGNABLE", -1, GENDER_NOT_APPLICABLE), nullptr, greenColor, greenColor, 0); + } + + if (!nameOnly && !socketPreview) { + const LockRec* lock = AddItemBindLines(this, stats, item, requester, skipLock); + + if (lock) { + AddItemLockLines(this, stats, item, lock); + needsUpdate = 1; + } + } + + const ScalingStatDistributionRec* distribution = nullptr; + const ScalingStatValuesRec* values = nullptr; + int32_t displayedLevel = 0; + + if (stats->m_scalingStatValue) { + distribution = g_scalingStatDistributionDB.GetRecord(stats->m_scalingStatDistribution); + displayedLevel = CGTooltip::GetDisplayedScalingItemLevel(stats, link, *requester, minimumLevel); + this->m_itemDisplayedLevel = displayedLevel; + values = g_scalingStatValuesDB.GetRecordByIndex(displayedLevel - 1); + } + + AddItemTypeLines(this, stats, player, values, distribution); + float averageDamage = 0.0f; + + if (!nameOnly) { + averageDamage = AddItemDamageLines(this, stats, values); + AddItemArmorAndStatLines(this, stats, values, distribution); + int32_t numSockets = 0; + + if (item) { + numSockets = item->GetNumSockets(); + } else { + for (uint32_t i = 0; i < 3; i++) { + if (stats->m_socketColor[i]) { + numSockets++; + } + } + + if (this->m_itemUseLinkInfo && this->m_itemLinkInfo.m_enchants[6]) { + SpellItemEnchantmentRec* prismatic = g_spellItemEnchantmentDB.GetRecord(this->m_itemLinkInfo.m_enchants[6]); + + if (prismatic) { + for (uint32_t i = 0; i < 3; i++) { + if (prismatic->m_effect[i] == 8) { + numSockets += prismatic->m_effectPointsMin[i]; + break; + } + } + } + } + } + + if (!wrapped) { + if (item || this->m_itemUseLinkInfo) { + if (AddItemSocketLines(this, stats, item, player, ownerPlayer, owner, socketPreview, numSockets, &useSpell, &useCharges, &useEnchant)) { + needsUpdate = 1; + } + } else { + AddItemStaticSocketLines(this, stats); + } + } + + if (stats->m_gemProperties && !socketPreview) { + AddItemGemLines(this, stats, player, destroyGem); + } + } + + if (AddItemDurabilityLines(this, stats, item, wrapped, socketPreview)) { + needsUpdate = 1; + } + + if (!socketPreview) { + AddItemRaceClassLines(this, stats, player); + } + + AddItemLevelLines(this, stats, player, distribution, displayedLevel); + + if (!socketPreview) { + AddItemRequirementLines(this, stats, player, itemId, requester); + } + + ItemSetRec* set = nullptr; + int32_t skillOk = 0; + int32_t numItems = 0; + int32_t numEquipped = 0; + int32_t equipped[17]; + memset(equipped, 0, sizeof(equipped)); + + if (stats->m_itemSet) { + set = g_itemSetDB.GetRecord(stats->m_itemSet); + + if (set && !socketPreview) { + skillOk = CollectItemSetData(this, set, player, ownerPlayer, equipped, &numItems, &numEquipped); + } + } + + AddItemSpellStatLines(this, stats, player, values, distribution, averageDamage); + int32_t isRecipe = AddItemSpellTriggerLines(this, stats, item, hideCharges, stream); + + if (useSpell) { + AddItemUseEnchantLine(this, player, useSpell, useCharges, useEnchant); + } + + if (set && !socketPreview) { + AddItemSetLines(this, set, player, equipped, numItems, numEquipped, skillOk, stream); + } else if (stream) { + for (int32_t i = 0; i < 8; i++) { + char buffer[260]; + sprintf(buffer, "\t\t\t\n", i, i); + fputs(buffer, stream); + } + } + + if (this->m_itemUseLinkInfo && this->m_itemLinkInfo.m_cooldown && !socketPreview) { + CGTooltip::GetItemDurationString(text, sizeof(text), this->m_itemLinkInfo.m_cooldown, "ITEM_COOLDOWN_TIME"); + this->AddLine(text, nullptr, textColor, textColor, 0); + needsUpdate = 1; + } else { + uint32_t duration = 0; + uint32_t enable = 0; + Spell_C_GetItemCooldown(item, &duration, nullptr, &enable); + + if (duration && !enable) { + this->AddLine(FrameScript_GetText("COOLDOWN_ON_LEAVE_COMBAT", -1, GENDER_NOT_APPLICABLE), nullptr, textColor, textColor, 0); + needsUpdate = 1; + } + } + + if (!nameOnly) { + if (!isRecipe && stats->m_description && *stats->m_description) { + SStrPrintf(text, sizeof(text), "\"%s\"", stats->m_description); + this->AddLine(text, nullptr, titleColor, titleColor, 1); + } + + if (!socketPreview) { + AddItemCreatorLines(this, stats, item, wrapped); + + if (!append && Spell_C_IsTargeting()) { + AddItemDisenchantLine(this, stats, player); + } + } + + if (*itemGuid) { + CVar* equipmentManager = CVar::Lookup("equipmentManager"); + CVar* dontShowEquipmentSets = CVar::Lookup("dontShowEquipmentSetsOnItems"); + + if (equipmentManager && equipmentManager->m_intValue && (!dontShowEquipmentSets || !dontShowEquipmentSets->m_intValue)) { + const char* token = FrameScript_GetText("EQUIPMENT_SETS", -1, GENDER_NOT_APPLICABLE); + char sets[1024]; + + if (token && CGEquipmentManager::GetSetList(sets, sizeof(sets), itemGuid)) { + SStrPrintf(text, sizeof(text), token, sets); + this->AddLine(text, nullptr, titleColor, titleColor, 1); + } + } + } + + int32_t refundable = item ? AddItemTradeLines(this, stats, item, player) : 0; + + if (CursorGetResetMode() != 17 && !refundable && !this->m_itemSkipSellPrice && !skipSellPrice) { + AddItemSellPrice(this, stats, item, player); + } + } + + if (this->m_onTooltipSetItem.m_luaRef) { + this->RunScript(this->m_onTooltipSetItem, 0, nullptr); + } + + this->Show(); + this->CalculateSize(); + return needsUpdate; +} diff --git a/WoW/Source/UIUtil/Tooltip.h b/WoW/Source/UIUtil/Tooltip.h index ee55313..99bd237 100644 --- a/WoW/Source/UIUtil/Tooltip.h +++ b/WoW/Source/UIUtil/Tooltip.h @@ -3,6 +3,7 @@ #include #include +#include #include "Engine/Source/Base/CDataAllocator.h" #include "Engine/Source/Frame/CSimpleFrame.h" #include "Engine/Source/FrameScript/FrameScript_Object.h" @@ -24,27 +25,26 @@ class ItemLinkInfo { public: /* 0000 */ uint32_t m_itemId; /* 0004 */ uint32_t m_enchants [12]; - /* 0034 */ uint32_t m_gems [12]; - /* 0064 */ uint32_t m_gemEnchants [12]; - /* 0094 */ uint32_t unk_0094; - /* 0098 */ uint32_t unk_0098; + /* 0034 */ uint32_t m_enchantDurations [12]; + /* 0064 */ int32_t m_enchantCharges [12]; + /* 0094 */ uint32_t m_cooldown; + /* 0098 */ int32_t m_proposedEnchant; /* 009C */ uint32_t unk_009C; - /* 00A0 */ uint32_t unk_00A0; - /* 00A4 */ uint32_t unk_00A4; - /* 00A8 */ uint32_t unk_00A8; - /* 00AC */ uint32_t unk_00AC; - /* 00B0 */ uint32_t unk_00B0; - /* 00B4 */ uint32_t unk_00B4; - /* 00B8 */ int32_t unk_00B8; - /* 00BC */ uint32_t unk_00BC; - /* 00C0 */ uint32_t unk_00C0; - /* 00C4 */ uint32_t unk_00C4; - /* 00C8 */ uint32_t unk_00C8; - /* 00CC */ uint32_t unk_00CC; - /* 00D0 */ uint32_t unk_00D0; - /* 00D4 */ int32_t unk_00D4; + /* 00A0 */ WOWGUID m_creator; + /* 00A8 */ WOWGUID m_giftCreator; + /* 00B0 */ uint32_t m_propertySeed; + /* 00B4 */ int32_t m_randomPropertiesId; + /* 00B8 */ int32_t m_spellCharges; + /* 00BC */ uint32_t m_wrapped; + /* 00C0 */ uint32_t m_lockId; + /* 00C4 */ uint32_t m_maxDurability; + /* 00C8 */ uint32_t m_durability; + /* 00CC */ int32_t m_level; + /* 00D0 */ uint32_t m_stackCount; + /* 00D4 */ int32_t m_maxStackCount; void Clear(); + int32_t GetItemIdFromLink(const char* link); }; class CGTalentGroup_C; @@ -56,6 +56,29 @@ class CGUnit_C; class CImVector; class CSimpleFontString; +class CGPlayer_C; +class ItemNameCache_C; +class ItemSetRec; +class ItemStats_C; +class ScalingStatValuesRec; +class SpellItemEnchantmentRec; +class SpellRec; + +struct ItemSetTooltipData { + /* 0000 */ CGTooltip* m_tooltip; + /* 0004 */ const ItemSetRec* m_set; + /* 0008 */ ItemNameCache_C* m_items [17]; + /* 004C */ int32_t* m_equipped; + /* 0050 */ uint8_t m_slotUsed [19]; +}; + +void TooltipItemCallback(int32_t id, const WOWGUID& guid, void* param, bool success); +int32_t GetScalingStatBudget(const ScalingStatValuesRec* values, uint32_t flags); +int32_t GetScalingStatArmor(const ScalingStatValuesRec* values, uint32_t flags); +void GetScalingStatDamage(const ScalingStatValuesRec* values, uint32_t flags, float* minDamage, float* maxDamage); +int32_t GetFeralAttackPower(const ItemStats_C* stats, float damage); +int32_t GetEnchantmentConditionText(CGPlayer_C* player, const SpellItemEnchantmentRec* enchant, char* buffer, uint32_t size, int32_t newline); +bool ResolveItemSetItem(ItemSetTooltipData* data, int32_t pass, int32_t itemId, int32_t slot); void TooltipUnitNameCallback(int32_t id, const WOWGUID& guid, void* param, bool success); void TooltipCorpseCallback(int32_t id, const WOWGUID& guid, void* param, bool success); void TooltipSpellCallback(int32_t id, const WOWGUID& guid, void* param, bool success); @@ -103,7 +126,7 @@ class CGTooltip : public CSimpleFrame { /* 0350 */ uint32_t unk_0350; /* 0354 */ uint32_t unk_0354; /* 0358 */ WOWGUID m_healthGuid; - /* 0360 */ uint32_t unk_0360; + /* 0360 */ int32_t m_itemId; /* 0364 */ int32_t m_spellId; /* 0368 */ uint32_t unk_0368; /* 036C */ uint32_t unk_036C; @@ -111,11 +134,10 @@ class CGTooltip : public CSimpleFrame { /* 0374 */ uint32_t unk_0374 [4]; /* 0384 */ WowTime m_time; /* 03A4 */ uint32_t unk_03A4 [4]; - /* 03B4 */ uint32_t unk_03B4; - /* 03B8 */ uint32_t unk_03B8; - /* 03BC */ uint32_t unk_03BC; - /* 03C0 */ uint32_t unk_03C0; - /* 03C4 */ uint32_t unk_03C4; + /* 03B4 */ int32_t m_itemNameOnly; + /* 03B8 */ int32_t m_itemSocketPreview; + /* 03BC */ int32_t m_itemCompare; + /* 03C0 */ WOWGUID m_itemOwner; /* 03C8 */ int32_t m_pendingQueries; /* 03CC */ uint32_t m_fading; /* 03D0 */ float m_fadeTime; @@ -125,11 +147,11 @@ class CGTooltip : public CSimpleFrame { /* 03E0 */ float m_offsetX; /* 03E4 */ float m_offsetY; /* 03E8 */ ItemLinkInfo m_itemLinkInfo; - /* 04C0 */ uint32_t unk_04C0; - /* 04C4 */ uint32_t unk_04C4; - /* 04C8 */ uint32_t unk_04C8; - /* 04CC */ uint32_t unk_04CC; - /* 04D0 */ uint32_t unk_04D0; + /* 04C0 */ int32_t m_itemUseLinkInfo; + /* 04C4 */ int32_t m_itemHideCharges; + /* 04C8 */ int32_t m_itemMinimumLevel; + /* 04CC */ int32_t m_itemSkipSellPrice; + /* 04D0 */ int32_t m_itemDisplayedLevel; /* 04D4 */ FrameScript_Object::ScriptIx m_onTooltipSetDefaultAnchor; /* 04DC */ FrameScript_Object::ScriptIx m_onTooltipCleared; /* 04E4 */ FrameScript_Object::ScriptIx m_onTooltipAddMoney; @@ -172,11 +194,21 @@ class CGTooltip : public CSimpleFrame { void AddSkinnableText(CGUnit_C* unit, char* buffer, uint32_t size); static void GetSummonedByString(CGUnit_C* unit, char* buffer, uint32_t size); static void GetDurationString(char* buffer, uint32_t size, uint64_t time, const char* token, const char* prefix, int32_t roundUp, int32_t seconds); + static void GetItemDurationString(char* buffer, uint32_t size, uint64_t time, const char* token); + static void __stdcall FormatStringForXML(const char* text, char* buffer); + static int32_t GetDisplayedScalingItemLevel(const ItemStats_C* stats, const ItemLinkInfo* link, WOWGUID target, int32_t minimumLevel); + void AddMoney(int32_t money, int32_t maxMoney); + void AddSpellReagents(const SpellRec* spell, const char* token, void (*callback)(int32_t id, const WOWGUID& guid, void* param, bool success)); + int32_t SetItemNoStats(); static void GetFloatDurationString(char* buffer, uint32_t size, float time, const char* token, const char* prefix); int32_t AddTalentPrereqs(const TalentRec* talent, CGTalentGroup_C* group, int32_t isInspect, int32_t isPet, int32_t usePreview); void AddTalentLearnText(const TalentRec* talent, CGTalentGroup_C* group, int32_t prereqsMet, int32_t rank, int32_t maxRank, int32_t a7, int32_t a8, int32_t isPet, int32_t usePreview); + int32_t SetQuest(int32_t questId); + void SetGlyph(int32_t glyphId, int32_t spellId, int32_t a3, int32_t a4, int32_t a5); + void SetTalent(const TalentRec* talent, CGTalentGroup_C* group, int32_t a3, int32_t a4, int32_t rank, int32_t a6, int32_t a7); + int32_t SetAchievement(int32_t achievementId, uint64_t guid, bool completed, WowTime time, uint32_t criteria1, uint32_t criteria2, uint32_t criteria3, uint32_t criteria4, int32_t a10); int32_t SetSpell(int32_t spellId, int32_t brief, uint32_t cooldown, int32_t isPet, int32_t showRank, int32_t isInspect, int32_t a8, const TalentRec* talent, CGTalentGroup_C* talentGroup, int32_t append, int32_t usePreview, int32_t a13, int32_t rank, int32_t maxRank, int32_t showLearn); - int32_t SetItem(int32_t itemId, int32_t* a2, WOWGUID* a3, int32_t a4, int32_t a5, int32_t a6, int32_t a7, uint64_t a8, int32_t a9, int32_t a10, int32_t a11, int32_t a12, int32_t a13, int32_t a14, int32_t a15); + int32_t SetItem(int32_t itemId, const WOWGUID* requester, const WOWGUID* itemGuid, int32_t nameOnly, int32_t compare, int32_t useLinkInfo, int32_t append, WOWGUID owner, int32_t socketPreview, FILE* stream, int32_t hideCharges, const ItemLinkInfo* link, int32_t minimumLevel, int32_t skipLock, int32_t skipSellPrice); }; class CGItemStatsSummary { diff --git a/WoW/Source/UIUtil/Tooltip_Scripts.cpp b/WoW/Source/UIUtil/Tooltip_Scripts.cpp index 7dfa6a6..c876e63 100644 --- a/WoW/Source/UIUtil/Tooltip_Scripts.cpp +++ b/WoW/Source/UIUtil/Tooltip_Scripts.cpp @@ -15,19 +15,30 @@ #include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" #include "WoW/Source/UIUtil/Types.h" #include "WoW/Source/Ui/SpellBookFrame.h" +#include "WoW/Source/DB/DBClient/DBCacheInstances.h" +#include "WoW/Source/Object/ObjectClient/Container_C.h" +#include "WoW/Source/Ui/ContainerFrame.h" +#include "WoW/Source/Ui/MerchantFrame.h" +#include "WoW/Source/Ui/PaperDollInfoFrame.h" +#include "WoW/Source/Ui/ScriptEvents.h" +#include +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/SpellRec.h" +#include "WoW/Source/DB/Rec/TalentRec.h" +#include "WoW/Source/Object/ObjectClient/UnitCombatLog_C.h" +#include "WoW/Source/Ui/DanceStudio.h" +#include "WoW/Source/Ui/TradeSkillFrame.h" int32_t Script_AddFontStrings(lua_State* L); int32_t Script_GetAnchorType(lua_State* L); int32_t Script_SetAnchorType(lua_State* L); int32_t Script_AddTexture(lua_State* L); -int32_t Script_SetHyperlink(lua_State* L); int32_t Script_SetAction(lua_State* L); int32_t Script_SetPetAction(lua_State* L); int32_t Script_SetShapeshift(lua_State* L); int32_t Script_SetPossession(lua_State* L); int32_t Script_TooltipSetTracking(lua_State* L); int32_t Script_SetGlyph(lua_State* L); -int32_t Script_SetInventoryItem(lua_State* L); int32_t Script_SetLootItem(lua_State* L); int32_t Script_SetQuestItem(lua_State* L); int32_t Script_SetQuestLogItem(lua_State* L); @@ -37,7 +48,6 @@ int32_t Script_SetMerchantItem(lua_State* L); int32_t Script_SetMerchantCostItem(lua_State* L); int32_t Script_SetTradePlayerItem(lua_State* L); int32_t Script_SetTradeTargetItem(lua_State* L); -int32_t Script_SetBagItem(lua_State* L); int32_t Script_SetUnit(lua_State* L); int32_t Script_SetUnitBuff(lua_State* L); int32_t Script_SetUnitDebuff(lua_State* L); @@ -406,7 +416,7 @@ static int32_t Script_AppendText(lua_State* L) { return 0; } -// VERIFY: 75c058fe manual +// VERIFY: 2fd5996e manual // OFFSET: 0x006259E0 static int32_t Script_SetSpell(lua_State* L) { CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); @@ -432,7 +442,7 @@ static int32_t Script_SetSpell(lua_State* L) { Spell_C_GetSpellCooldown(spellId, petSpell, &duration, &start, &enable); uint32_t cooldown = !enable || !start || !duration ? 0 : start + duration - OsGetAsyncTimeMs(); - if (tooltip->SetSpell(spellId, 0, cooldown, petSpell, 0, 0, 0, nullptr, nullptr, 0, 0, 0, -1, -1, 0)) { + if (tooltip->SetSpell(spellId, 0, cooldown, petSpell, 0, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0)) { lua_pushnumber(L, 1.0); return 1; } @@ -442,7 +452,7 @@ static int32_t Script_SetSpell(lua_State* L) { return 1; } -// VERIFY: 6cc3f923 manual +// VERIFY: ed4d980b manual // OFFSET: 0x00625B90 static int32_t Script_SetSpellByID(lua_State* L) { CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); @@ -463,7 +473,7 @@ static int32_t Script_SetSpellByID(lua_State* L) { Spell_C_GetSpellCooldown(spellId, petSpell, &duration, &start, &enable); uint32_t cooldown = !enable || !start || !duration ? 0 : start + duration - OsGetAsyncTimeMs(); - if (tooltip->SetSpell(spellId, 0, cooldown, petSpell, showRank, 0, 0, nullptr, nullptr, 0, 0, 0, -1, -1, 0)) { + if (tooltip->SetSpell(spellId, 0, cooldown, petSpell, showRank, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0)) { lua_pushnumber(L, 1.0); return 1; } @@ -473,6 +483,405 @@ static int32_t Script_SetSpellByID(lua_State* L) { return 1; } +// VERIFY: 6f832080 manual +// OFFSET: 0x0062DAE0 +static int32_t Script_SetHyperlink(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isstring(L, 2)) { + const char* name = tooltip->GetName(); + luaL_error(L, "Usage: %s:SetHyperlink(link)", name ? name : ""); + return 0; + } + + const char* link = lua_tolstring(L, 2, nullptr); + const char* cursor; + + if ((cursor = SStrStr(link, "item:")) != nullptr) { + int32_t itemId = SStrToInt(cursor + 5); + + if (tooltip->m_isShown && itemId == tooltip->m_itemId) { + tooltip->Hide(); + return 0; + } + + if (itemId > 0) { + tooltip->m_itemLinkInfo.Clear(); + tooltip->m_itemLinkInfo.GetItemIdFromLink(link); + WOWGUID requester = { 0 }; + WOWGUID itemGuid = { 0 }; + tooltip->SetItem(itemId, &requester, &itemGuid, 0, 0, 1, 0, WOWGUID{ 0 }, 0, nullptr, 1, &tooltip->m_itemLinkInfo, 0, 0, 0); + } + + return 0; + } + + if ((cursor = SStrStr(link, "enchant:")) != nullptr) { + int32_t spellId = SStrToInt(cursor + 8); + + if (tooltip->m_isShown && spellId == tooltip->m_spellId) { + tooltip->Hide(); + return 0; + } + + SpellRec spell; + + if (g_spellDB.GetRecord(spellId, &spell) && (spell.m_attributes & 0x20)) { + tooltip->SetSpell(spellId, 0, 0, 0, 0, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + } + + return 0; + } + + if ((cursor = SStrStr(link, "dance:")) != nullptr) { + CGDanceStudio::LoadDance(SStrToInt(cursor + 6)); + return 0; + } + + if ((cursor = SStrStr(link, "spell:")) != nullptr) { + int32_t spellId = SStrToInt(cursor + 6); + + if (tooltip->m_isShown && spellId == tooltip->m_spellId) { + tooltip->Hide(); + return 0; + } + + tooltip->SetSpell(spellId, 0, 0, 0, 0, 0, 0, nullptr, nullptr, 0, 0, -1, -1, 0, 0); + return 0; + } + + if ((cursor = SStrStr(link, "unit:")) != nullptr) { + WOWGUID guid = StringToGuid(cursor + 5); + + if (tooltip->m_isShown && guid == tooltip->m_unitGuid) { + tooltip->Hide(); + return 0; + } + + WOWGUID healthGuid = { 0 }; + tooltip->SetUnit(guid, 0, healthGuid, 0); + return 0; + } + + if ((cursor = SStrStr(link, "quest:")) != nullptr) { + int32_t questId = SStrToInt(cursor + 6); + + if (tooltip->m_isShown && questId == static_cast(tooltip->unk_0368)) { + tooltip->Hide(); + return 0; + } + + tooltip->SetQuest(questId); + return 0; + } + + if ((cursor = SStrStr(link, "talent:")) != nullptr) { + cursor += 7; + TalentRec* talent = g_talentDB.GetRecord(SStrToInt(cursor)); + + if (!talent) { + return 0; + } + + int32_t rank = -1; + const char* separator = SStrChr(cursor, ':'); + + if (separator) { + rank = SStrToInt(separator + 1); + } + + tooltip->SetTalent(talent, nullptr, 0, 1, rank, 0, 0); + return 0; + } + + if ((cursor = SStrStr(link, "trade:")) != nullptr) { + CGTradeSkillInfo::SetLink(cursor + 6); + return 0; + } + + if ((cursor = SStrStr(link, "achievement:")) != nullptr) { + cursor += 12; + int32_t achievementId = SStrToInt(cursor); + + if (tooltip->m_isShown && achievementId == static_cast(tooltip->unk_036C)) { + tooltip->Hide(); + return 0; + } + + uint64_t guid = 0; + WowTime time; + int32_t completed = 0; + uint32_t criteria1 = 0; + uint32_t criteria2 = 0; + uint32_t criteria3 = 0; + uint32_t criteria4 = 0; + const char* field = SStrChr(cursor, ':'); + + if (field) { + field++; + sscanf(field, "%I64X:", &guid); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + completed = SStrToInt(++field); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + time.m_month = SStrToInt(++field); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + time.m_monthDay = SStrToInt(++field); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + time.m_year = SStrToInt(++field); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + criteria1 = SStrToUnsigned(++field); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + criteria2 = SStrToUnsigned(++field); + } + + if ((field = SStrChr(field, ':')) != nullptr) { + criteria3 = SStrToUnsigned(++field); + } + + const char* last = SStrChr(field, ':'); + + if (last) { + criteria4 = SStrToUnsigned(last + 1); + } + + tooltip->SetAchievement(achievementId, guid, completed != 0, time, criteria1, criteria2, criteria3, criteria4, 0); + return 0; + } + + if ((cursor = SStrStr(link, "glyph:")) != nullptr) { + cursor += 6; + int32_t glyphId = SStrToInt(cursor); + const char* separator = SStrChr(cursor, ':'); + + if (separator) { + tooltip->SetGlyph(glyphId, SStrToInt(separator + 1), 1, 1, 0); + } + + return 0; + } + + luaL_error(L, "%s:SetHyperlink(): Unknown link type", tooltip->GetDisplayName()); + return 0; +} + +// VERIFY: d3c4ca9b manual +// OFFSET: 0x0062E050 +static int32_t Script_SetInventoryItem(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + + if (!lua_isstring(L, 2)) { + const char* name = tooltip->GetName(); + luaL_error(L, "Usage: %s:SetInventoryItem(unit, slot [, nameOnly])", name ? name : ""); + return 0; + } + + int32_t slot; + + if (!lua_isnumber(L, 3) || ((slot = static_cast(lua_tonumber(L, 3) - 1.0)) < 0 || slot > 22) && (slot < 39 || slot > 66) && (slot < 67 || slot > 73) && (slot < 86 || slot > 117) && (slot < 118 || slot > 149) && slot != -1) { + luaL_error(L, "Invalid inventory slot in SetInventoryItem"); + return 0; + } + + int32_t nameOnly = StringToBOOL(L, 4, 0); + CGPlayer_C* unit = static_cast(GetUnitFromName(lua_tolstring(L, 2, nullptr))); + + if (!CGCharacterInfo::CanInspect(unit)) { + lua_pushnil(L); + lua_pushnil(L); + lua_pushnumber(L, 0.0); + return 3; + } + + if (slot == -1) { + int32_t ammoId = CGCharacterInfo::GetActivePlayerAmmoID(unit); + CGItem_C* ammo; + + if (ammoId && (ammo = unit->GetBag()->FindItemOfType(ammoId, 0)) != nullptr) { + WOWGUID itemGuid = ammo->m_obj->m_guid; + WOWGUID requester = unit->m_obj->m_guid; + tooltip->SetItem(ammoId, &requester, &itemGuid, 0, 0, 0, 0, WOWGUID{ 0 }, 0, nullptr, 0, nullptr, 0, 0, 0); + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnil(L); + return 2; + } + + CGItem_C* item = unit->m_bag.GetItemPointer(slot); + + if (!item) { + InspectItem* inspected = unit->GetInspectedItem(slot); + + if (!inspected || !inspected->m_itemId) { + lua_pushnil(L); + lua_pushnil(L); + lua_pushnumber(L, 0.0); + return 3; + } + + WOWGUID query = { 0 }; + g_itemDBCache.GetRecord(inspected->m_itemId, query, TooltipItemCallback, tooltip, false); + ItemLinkInfo& link = tooltip->m_itemLinkInfo; + link.Clear(); + link.m_randomPropertiesId = inspected->m_randomPropertiesId; + + for (uint32_t i = 0; i < 12; i++) { + link.m_enchants[i] = inspected->m_enchants[i]; + link.m_enchantDurations[i] = 0; + link.m_enchantCharges[i] = 0; + } + + link.m_propertySeed = inspected->m_propertySeed; + link.m_creator = inspected->m_creator; + WOWGUID itemGuid = { 0 }; + WOWGUID requester = unit->m_obj->m_guid; + tooltip->SetItem(inspected->m_itemId, &requester, &itemGuid, nameOnly, 0, 1, 0, unit->m_obj->m_guid, 0, nullptr, 0, nullptr, 0, 0, 0); + lua_pushnumber(L, 1.0); + lua_pushnil(L); + lua_pushnumber(L, 0.0); + return 3; + } + + int32_t result; + + if (item->GetUsableSpellCharges() && !item->GetCurrentSpellCharges()) { + WOWGUID requester = unit->m_obj->m_guid; + WOWGUID itemGuid = item->m_obj->m_guid; + result = tooltip->SetItem(item->m_obj->m_entryID, &requester, &itemGuid, nameOnly, 0, 0, 0, unit->m_obj->m_guid, 0, nullptr, 0, nullptr, 0, 0, 0); + } else { + uint32_t duration = 0; + uint32_t start = 0; + uint32_t enable = 0; + Spell_C_GetItemCooldown(item, &duration, &start, &enable); + + if (enable && duration && start) { + tooltip->m_itemLinkInfo.Clear(); + tooltip->m_itemLinkInfo.m_cooldown = start + duration - OsGetAsyncTimeMs(); + tooltip->m_itemLinkInfo.m_spellCharges = item->GetCurrentSpellCharges(); + WOWGUID requester = unit->m_obj->m_guid; + WOWGUID itemGuid = item->m_obj->m_guid; + result = tooltip->SetItem(item->m_obj->m_entryID, &requester, &itemGuid, nameOnly, 0, 1, 0, unit->m_obj->m_guid, 0, nullptr, 0, nullptr, 0, 0, 0); + } else { + WOWGUID requester = unit->m_obj->m_guid; + WOWGUID itemGuid = item->m_obj->m_guid; + result = tooltip->SetItem(item->m_obj->m_entryID, &requester, &itemGuid, nameOnly, 0, 0, 0, unit->m_obj->m_guid, 0, nullptr, 0, nullptr, 0, 0, 0); + } + } + + lua_pushnumber(L, 1.0); + + if (result) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, static_cast(CGMerchantInfo::GetRepairCost(item))); + return 3; +} + +// VERIFY: eb0546cd manual +// OFFSET: 0x0062F420 +static int32_t Script_SetBagItem(lua_State* L) { + CGTooltip* tooltip = static_cast(FrameScript_GetObjectThis(L, CGTooltip::GetObjectType())); + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player || !lua_isnumber(L, 2) || !lua_isnumber(L, 3)) { + return 0; + } + + int32_t index = static_cast(lua_tonumber(L, 2)) - 1; + CGBag_C* bag; + + if (index == -1) { + bag = &player->m_bag; + } else { + if (static_cast(index) > 10) { + return 0; + } + + CGObject_C* container = ClntObjMgrObjectPtr(GetBagAtIndex(index), TYPEMASK_CONTAINER, __FILE__, __LINE__); + + if (!container) { + return 0; + } + + bag = container->GetBag(); + } + + if (!bag) { + return 0; + } + + int32_t slot = static_cast(lua_tonumber(L, 3)) - 1; + + if (bag == &player->m_bag) { + slot += 23; + } + + CGItem_C* item; + + if (slot < 0 || slot >= bag->m_numSlots || (item = bag->GetItemPointer(slot)) == nullptr) { + lua_pushnil(L); + return 1; + } + + int32_t result; + uint32_t duration; + uint32_t start; + uint32_t enable; + + if ((item->GetUsableSpellCharges() && !item->GetCurrentSpellCharges()) || (duration = 0, start = 0, enable = 0, Spell_C_GetItemCooldown(item, &duration, &start, &enable), !enable || !duration || !start)) { + WOWGUID requester = item->m_obj->m_guid; + WOWGUID itemGuid = item->m_obj->m_guid; + result = tooltip->SetItem(item->m_obj->m_entryID, &requester, &itemGuid, 0, 0, 0, 0, WOWGUID{ 0 }, 0, nullptr, 0, nullptr, 0, 0, 0); + } else { + ItemLinkInfo& link = tooltip->m_itemLinkInfo; + link.Clear(); + + for (uint32_t i = 0; i < 12; i++) { + link.m_enchants[i] = 0; + link.m_enchantDurations[i] = 0; + link.m_enchantCharges[i] = 0; + } + + link.m_cooldown = duration + start - OsGetAsyncTimeMs(); + link.m_proposedEnchant = 0; + link.m_creator = item->m_item->m_itemFieldCreator; + link.m_wrapped = (item->m_item->m_itemFieldFlags >> 3) & 1; + link.m_giftCreator = item->m_item->m_itemFieldGiftcreator; + link.m_spellCharges = item->GetCurrentSpellCharges(); + WOWGUID requester = item->m_obj->m_guid; + WOWGUID itemGuid = item->m_obj->m_guid; + result = tooltip->SetItem(item->m_obj->m_entryID, &requester, &itemGuid, 0, 0, 1, 0, WOWGUID{ 0 }, 0, nullptr, 0, nullptr, 0, 0, 0); + } + + int32_t repairCost = CGMerchantInfo::GetRepairCost(item); + + if (result) { + lua_pushnumber(L, 1.0); + } else { + lua_pushnil(L); + } + + lua_pushnumber(L, repairCost); + return 2; +} + // STATIC: 0x00AD2AE0 static FrameScript_Method s_ScriptMethods[] = { { "AddFontStrings", &Script_AddFontStrings }, diff --git a/WoW/Source/Ui/ArenaTeamInfo.cpp b/WoW/Source/Ui/ArenaTeamInfo.cpp index d0669a7..b01a38d 100644 --- a/WoW/Source/Ui/ArenaTeamInfo.cpp +++ b/WoW/Source/Ui/ArenaTeamInfo.cpp @@ -4,6 +4,12 @@ #include "WoW/Source/Ui/Types.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" #include "WoW/Source/Net/Types.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/Player.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" + +// STATIC: 0x00A15ABC +static const int32_t s_arenaBracketTypes[3] = { 2, 3, 5 }; // STATIC: 0x00ACF834 int32_t CGArenaTeamInfo::m_showOffline = 1; @@ -92,3 +98,37 @@ void CGArenaTeamInfo::InitializeGame() { CGArenaTeamInfo::m_sortOrder[i].m_column = i; } } + +// VERIFY: 04a71da4 manual +// OFFSET: 0x005A37B0 +bool CGArenaTeamInfo::CheckPersonalAndTeamRating(uint32_t rating, int32_t bracket) { + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + + if (!player) { + return false; + } + + for (uint32_t i = 0; i < 3; i++) { + uint32_t* info = &player->m_player->m_playerFieldArenaTeamInfo11[i * 7]; + + if (!info) { + continue; + } + + int32_t type = info[1]; + + if (type < s_arenaBracketTypes[bracket] || info[6] < rating) { + continue; + } + + for (uint32_t j = 0; j < 3; j++) { + ArenaTeam* team = &CGArenaTeamInfo::m_arenaTeams[j]; + + if (team && team->m_type == static_cast(type) && team->m_rating >= rating) { + return true; + } + } + } + + return false; +} diff --git a/WoW/Source/Ui/ArenaTeamInfo.h b/WoW/Source/Ui/ArenaTeamInfo.h index b28521b..161eaef 100644 --- a/WoW/Source/Ui/ArenaTeamInfo.h +++ b/WoW/Source/Ui/ArenaTeamInfo.h @@ -56,6 +56,7 @@ class CGArenaTeamInfo { static WOWGUID m_selectedMember; static void EnterWorld(); static void InitializeGame(); + static bool CheckPersonalAndTeamRating(uint32_t rating, int32_t bracket); }; int32_t Script_GetArenaTeamRosterInfo(lua_State* L); diff --git a/WoW/Source/Ui/Calendar.cpp b/WoW/Source/Ui/Calendar.cpp index 60c0553..700b575 100644 --- a/WoW/Source/Ui/Calendar.cpp +++ b/WoW/Source/Ui/Calendar.cpp @@ -1,4 +1,7 @@ #include "Calendar.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/HolidayNamesRec.h" +#include "WoW/Source/DB/Rec/HolidaysRec.h" #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" // STATIC: 0x00C207EC @@ -49,3 +52,16 @@ void CGCalendar::InitializeGame() { ClientServices::SetMessageHandler(SMSG_CALENDAR_SEND_NUM_PENDING, PH_CALENDAR_GROUP, nullptr); ClientServices::SetMessageHandler(SMSG_CALENDAR_CLEAR_PENDING_ACTION, PH_CALENDAR_GROUP, nullptr); } + +// VERIFY: d8756e5f auto +// OFFSET: 0x005B9430 +const char* GetHolidayName(int32_t holidayId) { + HolidaysRec* holiday = g_holidaysDB.GetRecord(holidayId); + + if (!holiday) { + return nullptr; + } + + HolidayNamesRec* name = g_holidayNamesDB.GetRecord(holiday->m_holidayNameID); + return name ? name->m_name : nullptr; +} diff --git a/WoW/Source/Ui/Calendar.h b/WoW/Source/Ui/Calendar.h index 02d5ca1..69da82c 100644 --- a/WoW/Source/Ui/Calendar.h +++ b/WoW/Source/Ui/Calendar.h @@ -116,5 +116,6 @@ int32_t Script_CalendarCanSendInvite(lua_State* L); int32_t Script_CalendarCanAddEvent(lua_State* L); int32_t Script_OpenCalendar(lua_State* L); void CalendarRegisterScriptFunctions(); +const char* GetHolidayName(int32_t holidayId); #endif diff --git a/WoW/Source/Ui/DanceStudio.h b/WoW/Source/Ui/DanceStudio.h index e9104df..939c092 100644 --- a/WoW/Source/Ui/DanceStudio.h +++ b/WoW/Source/Ui/DanceStudio.h @@ -16,6 +16,7 @@ int32_t Packet_SMSG_LEARNED_DANCE_MOVES(void* param, NETMESSAGE msgId, uint32_t class CGDanceStudio { public: static void InitializeGame(); + static void LoadDance(int32_t danceId); static void RegisterScriptFunctions(); }; diff --git a/WoW/Source/Ui/EquipmentManager.cpp b/WoW/Source/Ui/EquipmentManager.cpp index 2fc7db8..141313e 100644 --- a/WoW/Source/Ui/EquipmentManager.cpp +++ b/WoW/Source/Ui/EquipmentManager.cpp @@ -4,6 +4,8 @@ #include #include "Engine/Source/Base/ObjectAlloc.h" #include "Engine/Source/Storm/H/storm.h" +#include "Engine/Source/FrameScript/FrameScript.h" +#include #include "WoW/Source/WowSvcs/WowSvcsClient/ClientServices.h" // STATIC: 0x00C1E95C @@ -21,6 +23,9 @@ int32_t CGEquipmentManager::m_pendingSetID; // STATIC: 0x00C1E908 int32_t CGEquipmentManager::m_ignoredSlots[19]; +// STATIC: 0x00ACFC00 +TSList CGEquipmentManager::s_equipmentSets; + // VERIFY: 36e16d6a auto // OFFSET: 0x005AD690 void CGEquipmentManager::EnterWorld() { @@ -64,3 +69,51 @@ void CGEquipmentManager::InitializeGame() { CGEquipmentManager::s_equipmentSetHeap = new (SMemAlloc(sizeof(uint32_t), __FILE__, __LINE__, 0)) uint32_t(ObjectAllocAddHeap(sizeof(EQUIPMENT_SET), 128, "EQUIPMENTSET", true)); } } + +// VERIFY: ecc66233 manual +// OFFSET: 0x005AE380 +int32_t CGEquipmentManager::GetSetList(char* buffer, uint32_t size, const WOWGUID* item) { + uint32_t remaining = size - 1; + char* out = buffer; + const char* separator = ""; + const char* delimiter = FrameScript_GetText("PLAYER_LIST_DELIMITER", -1, GENDER_NOT_APPLICABLE); + + for (EQUIPMENT_SET_NODE* node = CGEquipmentManager::s_equipmentSets.Head(); node; node = CGEquipmentManager::s_equipmentSets.Next(node)) { + EQUIPMENT_SET* set = node->m_set; + + for (uint32_t i = 0; i < sizeof(set->m_items) / sizeof(set->m_items[0]); i++) { + if (set->m_items[i] != *item) { + continue; + } + + size_t nameLength = SStrLen(set->m_name); + size_t separatorLength = SStrLen(separator); + + if (separatorLength + nameLength > remaining) { + break; + } + + memcpy(out, separator, separatorLength); + out += separatorLength; + memcpy(out, set->m_name, nameLength); + out += nameLength; + remaining -= nameLength + separatorLength; + separator = delimiter; + } + } + + *out = '\0'; + return buffer != out; +} + +// VERIFY: b88be2b9 manual +// OFFSET: 0x005AE5C0 +const EQUIPMENT_SET* CGEquipmentManager::GetSetByID(int32_t id) { + for (EQUIPMENT_SET_NODE* node = CGEquipmentManager::s_equipmentSets.Head(); node; node = CGEquipmentManager::s_equipmentSets.Next(node)) { + if (node->m_set->m_id == id) { + return node->m_set; + } + } + + return nullptr; +} diff --git a/WoW/Source/Ui/EquipmentManager.h b/WoW/Source/Ui/EquipmentManager.h index 630fdab..c84f8a3 100644 --- a/WoW/Source/Ui/EquipmentManager.h +++ b/WoW/Source/Ui/EquipmentManager.h @@ -4,6 +4,7 @@ #include #include "WoW/Source/Object/WGUID.h" #include "WoW/Source/Net/Types.h" +#include "Engine/Source/Storm/H/stpl.h" class CDataStore; struct lua_State; @@ -19,6 +20,10 @@ struct EQUIPMENT_SET { /* 0230 */ uint32_t unk_0230; }; +struct EQUIPMENT_SET_NODE : public TSLinkedNode { + /* 0008 */ EQUIPMENT_SET* m_set; +}; + int32_t Packet_SMSG_EQUIPMENT_SET_LIST(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t Packet_SMSG_EQUIPMENT_SET_SAVED(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); int32_t Packet_SMSG_EQUIPMENT_SET_USE_RESULT(void* param, NETMESSAGE msgId, uint32_t time, CDataStore* msg); @@ -26,6 +31,7 @@ int32_t Packet_SMSG_EQUIPMENT_SET_USE_RESULT(void* param, NETMESSAGE msgId, uint class CGEquipmentManager { public: static uint32_t* s_equipmentSetHeap; + static TSList s_equipmentSets; static void EnterWorld(); static uint8_t m_lastCanUseEquipmentSetsValue; static uint8_t m_swapPending; @@ -38,6 +44,7 @@ class CGEquipmentManager { static void InitializeGame(); static void EquipSet(int32_t id); static void GetFullIconPath(int32_t id, char* buffer, uint32_t size); + static int32_t GetSetList(char* buffer, uint32_t size, const WOWGUID* item); }; int32_t Script_SaveEquipmentSet(lua_State* L); diff --git a/WoW/Source/Ui/ItemSocketInfo.cpp b/WoW/Source/Ui/ItemSocketInfo.cpp index 2f40c8b..6143fea 100644 --- a/WoW/Source/Ui/ItemSocketInfo.cpp +++ b/WoW/Source/Ui/ItemSocketInfo.cpp @@ -1 +1,48 @@ #include "ItemSocketInfo.h" +#include "WoW/Source/DB/DBClient/DBClient.h" +#include "WoW/Source/DB/Rec/GemPropertiesRec.h" +#include "WoW/Source/Object/ItemStats.h" + +// STATIC: 0x00C20FC8 +WOWGUID CGItemSocketInfo::m_gemItems[3]; + +// VERIFY: c7291b92 manual +// OFFSET: 0x005C48D0 +int32_t CGItemSocketInfo::GemMatchesSocket(const ItemStats_C* item, const ItemStats_C* gem, int32_t socket) { + if (!item || !gem) { + return 0; + } + + uint32_t color = item->m_socketColor[socket]; + + if (!color) { + return 1; + } + + GemPropertiesRec* properties = g_gemPropertiesDB.GetRecord(gem->m_gemProperties); + + if (!properties) { + return 0; + } + + int32_t type = properties->m_type; + int32_t match = 0; + + if ((type & 1) && (color & 1)) { + match = 1; + } + + if ((type & 2) && (color & 2)) { + match = 1; + } + + if ((type & 4) && (color & 4)) { + match = 1; + } + + if ((type & 8) && (color & 8)) { + return 1; + } + + return match; +} diff --git a/WoW/Source/Ui/ItemSocketInfo.h b/WoW/Source/Ui/ItemSocketInfo.h index 5ac9c89..f3bbce1 100644 --- a/WoW/Source/Ui/ItemSocketInfo.h +++ b/WoW/Source/Ui/ItemSocketInfo.h @@ -2,6 +2,7 @@ #define WOW_SOURCE_UI_ITEMSOCKETINFO_H #include +#include "WoW/Source/Object/WGUID.h" struct lua_State; @@ -19,9 +20,14 @@ int32_t Script_GetSocketItemRefundable(lua_State* L); int32_t Script_GetSocketItemBoundTradeable(lua_State* L); void ItemSocketInfoRegisterScriptFunctions(); +class ItemStats_C; + class CGItemSocketInfo { public: + static WOWGUID m_gemItems[3]; + static void EnterWorld(); + static int32_t GemMatchesSocket(const ItemStats_C* item, const ItemStats_C* gem, int32_t socket); }; #endif diff --git a/WoW/Source/Ui/MerchantFrame.cpp b/WoW/Source/Ui/MerchantFrame.cpp index 724ec66..51800c5 100644 --- a/WoW/Source/Ui/MerchantFrame.cpp +++ b/WoW/Source/Ui/MerchantFrame.cpp @@ -1,4 +1,9 @@ #include "MerchantFrame.h" +#include "Engine/Source/Tempest/CMath.h" +#include "WoW/Source/Object/ObjectClient/Item_C.h" +#include "WoW/Source/Object/ObjectClient/Player_C.h" +#include "WoW/Source/Object/ObjectClient/Unit_C.h" +#include "WoW/Source/ObjectMgrClient/ObjectMgrClient.h" // STATIC: 0x00BFA3F0 int32_t CGMerchantInfo::m_numMerchantItems; @@ -8,3 +13,33 @@ uint32_t CGMerchantInfo::m_numBuybackItems; // STATIC: 0x00BF9128 MerchantItem CGMerchantInfo::m_items[150]; + +// VERIFY: 4b63a9a7 manual +// OFFSET: 0x00584150 +MerchantItem* CGMerchantInfo::FindItemById(int32_t itemId) { + if (!CGMerchantInfo::m_merchant || !CGMerchantInfo::m_numMerchantItems) { + return nullptr; + } + + for (uint32_t i = 0; i < sizeof(CGMerchantInfo::m_items) / sizeof(CGMerchantInfo::m_items[0]); i++) { + if (CGMerchantInfo::m_items[i].m_itemID == itemId) { + return &CGMerchantInfo::m_items[i]; + } + } + + return nullptr; +} + +// VERIFY: 7160c52f manual +// OFFSET: 0x00584B20 +int32_t CGMerchantInfo::GetRepairCost(CGItem_C* item) { + float multiplier = 1.0f; + CGPlayer_C* player = static_cast(ClntObjMgrObjectPtr(ClntObjMgrGetActivePlayer(), TYPEMASK_PLAYER, __FILE__, __LINE__)); + CGUnit_C* merchant = static_cast(ClntObjMgrObjectPtr(CGMerchantInfo::m_merchant, TYPEMASK_UNIT, __FILE__, __LINE__)); + + if (player && merchant) { + multiplier = 1.0f - merchant->GetPlayerDiscount(player); + } + + return CMath::fint_(static_cast(static_cast(item->GetRepairCost())) * multiplier); +} diff --git a/WoW/Source/Ui/MerchantFrame.h b/WoW/Source/Ui/MerchantFrame.h index 2914f6e..1dbd97c 100644 --- a/WoW/Source/Ui/MerchantFrame.h +++ b/WoW/Source/Ui/MerchantFrame.h @@ -4,6 +4,8 @@ #include #include "WoW/Source/Object/WGUID.h" +class CGItem_C; + struct lua_State; struct MerchantItem { @@ -20,6 +22,8 @@ struct MerchantItem { class CGMerchantInfo { public: static void EnterWorld(); + static MerchantItem* FindItemById(int32_t itemId); + static int32_t GetRepairCost(CGItem_C* item); static MerchantItem m_items[150]; static WOWGUID m_merchant; static int32_t m_numMerchantItems; diff --git a/WoW/Source/Ui/QuestTextParser.cpp b/WoW/Source/Ui/QuestTextParser.cpp index 1662126..6dd5de6 100644 --- a/WoW/Source/Ui/QuestTextParser.cpp +++ b/WoW/Source/Ui/QuestTextParser.cpp @@ -6,6 +6,7 @@ #include "WoW/Source/DB/DBClient/DBClient.h" #include "WoW/Source/DB/Rec/AreaTableRec.h" #include "WoW/Source/DB/Rec/SpellDescriptionVariablesRec.h" +#include "WoW/Source/DB/Rec/SpellItemEnchantmentRec.h" #include "WoW/Source/DB/Rec/SpellRadiusRec.h" #include "WoW/Source/DB/Rec/SpellRangeRec.h" #include "WoW/Source/DB/Rec/SpellRec.h" @@ -263,6 +264,47 @@ static int32_t SpellParserVariable(char* buffer, uint32_t size, const char** cur return 0; } +// VERIFY: 4b6e8371 manual +// OFFSET: 0x00577260 +int32_t SpellItemEnchantmentParseText(const SpellItemEnchantmentRec* enchant, char* buffer, uint32_t size, int32_t value) { + int32_t failed = 0; + *buffer = '\0'; + const char* text = enchant->m_name; + + for (const char* dollar = SStrChr(text, '$'); dollar && *dollar; dollar = SStrChr(text, '$')) { + int32_t length = dollar - text; + + if (dollar != text) { + uint32_t bufferLength = SStrLen(buffer); + SStrPack(buffer, text, size); + + if (bufferLength + length < size) { + buffer[bufferLength + length] = '\0'; + } + } + + const char* cursor = dollar + 1; + + if (*cursor == 'i') { + char number[32]; + SStrPrintf(number, sizeof(number), "%d", value); + SStrPack(buffer, number, size); + + if (*cursor) { + cursor++; + } + } else { + SStrPack(buffer, "$", size); + failed = 1; + } + + text = cursor; + } + + SStrPack(buffer, text, size); + return failed == 0; +} + // VERIFY: f4c9dae8 manual // OFFSET: 0x005796C0 static bool SpellParserGetCondition(const char** cursor) { diff --git a/WoW/Source/Ui/QuestTextParser.h b/WoW/Source/Ui/QuestTextParser.h index 7e4cb22..4de980b 100644 --- a/WoW/Source/Ui/QuestTextParser.h +++ b/WoW/Source/Ui/QuestTextParser.h @@ -7,6 +7,7 @@ class CGUnit_C; class NameCache; +class SpellItemEnchantmentRec; class SpellRec; struct SpellVariable { @@ -25,5 +26,6 @@ extern TSGrowableArray s_spellVariables; void GenderConditional(char* buffer, uint32_t size, int32_t gender, const CGUnit_C* unit, const NameCache* name, const char** cursor); int32_t SpellParserParseText(const SpellRec* spell, char* buffer, uint32_t size, int32_t parsePet, int32_t parseUnit, int32_t spellLevel, int32_t useAuraDescription, int32_t scale, int32_t noModifiers); +int32_t SpellItemEnchantmentParseText(const SpellItemEnchantmentRec* enchant, char* buffer, uint32_t size, int32_t value); #endif diff --git a/WoW/Source/Ui/SpellBookFrame.h b/WoW/Source/Ui/SpellBookFrame.h index eabf18d..ffee7dc 100644 --- a/WoW/Source/Ui/SpellBookFrame.h +++ b/WoW/Source/Ui/SpellBookFrame.h @@ -134,5 +134,6 @@ int32_t FindSpellSlotByName(const char* name, const char* subtext, int32_t* petS int32_t GetSpellIdByName(const char* name, int32_t* petSpell); bool GetSlotFromLua(lua_State* L, uint32_t* slot, int32_t* petSpell, int32_t* type, int32_t allowName); bool HasPetSpell(int32_t spellId); +extern TSGrowableArray s_openLockSpells; #endif diff --git a/WoW/Source/Ui/TradeSkillFrame.h b/WoW/Source/Ui/TradeSkillFrame.h index d8aa5df..80819af 100644 --- a/WoW/Source/Ui/TradeSkillFrame.h +++ b/WoW/Source/Ui/TradeSkillFrame.h @@ -20,6 +20,7 @@ class CGTradeSkillInfo { static uint32_t m_recastTimes; static uint32_t m_pendingRecastTimes; static void RefreshList(int32_t a1); + static void SetLink(const char* link); static void CommitPendingRecast(int32_t spellId); static void DoRecast(int32_t spellId); };