From 4b3e377addadfc84df4f5f23236cf4cdb1a8e53e Mon Sep 17 00:00:00 2001 From: Kelsi Date: Fri, 20 Mar 2026 19:18:30 -0700 Subject: [PATCH] feat: resolve random property/suffix names for item display Load ItemRandomProperties.dbc and ItemRandomSuffix.dbc lazily to resolve suffix names like "of the Eagle", "of the Monkey" etc. Add getRandomPropertyName(id) callback on GameHandler wired through Application. Append suffix to item names in SMSG_ITEM_PUSH_RESULT loot notifications so items display as "Leggings of the Eagle" instead of just "Leggings". --- include/game/game_handler.hpp | 9 +++++++++ src/core/application.cpp | 32 ++++++++++++++++++++++++++++++++ src/game/game_handler.cpp | 7 ++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/include/game/game_handler.hpp b/include/game/game_handler.hpp index 5da300cc..7c4e0918 100644 --- a/include/game/game_handler.hpp +++ b/include/game/game_handler.hpp @@ -294,6 +294,14 @@ public: return spellIconPathResolver_ ? spellIconPathResolver_(spellId) : std::string{}; } + // Random property/suffix name resolver: randomPropertyId -> suffix name (e.g., "of the Eagle") + // Positive IDs → ItemRandomProperties.dbc; negative IDs → ItemRandomSuffix.dbc (abs value) + using RandomPropertyNameResolver = std::function; + void setRandomPropertyNameResolver(RandomPropertyNameResolver r) { randomPropertyNameResolver_ = std::move(r); } + std::string getRandomPropertyName(int32_t id) const { + return randomPropertyNameResolver_ ? randomPropertyNameResolver_(id) : std::string{}; + } + // Emote animation callback: (entityGuid, animationId) using EmoteAnimCallback = std::function; void setEmoteAnimCallback(EmoteAnimCallback cb) { emoteAnimCallback_ = std::move(cb); } @@ -2654,6 +2662,7 @@ private: AddonChatCallback addonChatCallback_; AddonEventCallback addonEventCallback_; SpellIconPathResolver spellIconPathResolver_; + RandomPropertyNameResolver randomPropertyNameResolver_; EmoteAnimCallback emoteAnimCallback_; // Targeting diff --git a/src/core/application.cpp b/src/core/application.cpp index 2826470a..8b4aeeb0 100644 --- a/src/core/application.cpp +++ b/src/core/application.cpp @@ -413,6 +413,38 @@ bool Application::initialize() { return pit->second; }); } + // Wire random property/suffix name resolver for item display + { + auto propNames = std::make_shared>(); + auto propLoaded = std::make_shared(false); + auto* amPtr = assetManager.get(); + gameHandler->setRandomPropertyNameResolver([propNames, propLoaded, amPtr](int32_t id) -> std::string { + if (!amPtr || id == 0) return {}; + if (!*propLoaded) { + *propLoaded = true; + // ItemRandomProperties.dbc: ID=0, Name=4 (string) + if (auto dbc = amPtr->loadDBC("ItemRandomProperties.dbc"); dbc && dbc->isLoaded()) { + uint32_t nameField = (dbc->getFieldCount() > 4) ? 4 : 1; + for (uint32_t r = 0; r < dbc->getRecordCount(); ++r) { + int32_t rid = static_cast(dbc->getUInt32(r, 0)); + std::string name = dbc->getString(r, nameField); + if (!name.empty() && rid > 0) (*propNames)[rid] = name; + } + } + // ItemRandomSuffix.dbc: ID=0, Name=4 (string) — stored as negative IDs + if (auto dbc = amPtr->loadDBC("ItemRandomSuffix.dbc"); dbc && dbc->isLoaded()) { + uint32_t nameField = (dbc->getFieldCount() > 4) ? 4 : 1; + for (uint32_t r = 0; r < dbc->getRecordCount(); ++r) { + int32_t rid = static_cast(dbc->getUInt32(r, 0)); + std::string name = dbc->getString(r, nameField); + if (!name.empty() && rid > 0) (*propNames)[-rid] = name; + } + } + } + auto it = propNames->find(id); + return (it != propNames->end()) ? it->second : std::string{}; + }); + } LOG_INFO("Addon system initialized, found ", addonManager_->getAddons().size(), " addon(s)"); } else { LOG_WARNING("Failed to initialize addon system"); diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index e42704e3..ce4098e1 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -1978,7 +1978,7 @@ void GameHandler::handlePacket(network::Packet& packet) { /*uint32_t itemSlot =*/ packet.readUInt32(); uint32_t itemId = packet.readUInt32(); /*uint32_t suffixFactor =*/ packet.readUInt32(); - /*int32_t randomProp =*/ static_cast(packet.readUInt32()); + int32_t randomProp = static_cast(packet.readUInt32()); uint32_t count = packet.readUInt32(); /*uint32_t totalCount =*/ packet.readUInt32(); @@ -1987,6 +1987,11 @@ void GameHandler::handlePacket(network::Packet& packet) { if (const ItemQueryResponseData* info = getItemInfo(itemId)) { // Item info already cached — emit immediately. std::string itemName = info->name.empty() ? ("item #" + std::to_string(itemId)) : info->name; + // Append random suffix name (e.g., "of the Eagle") if present + if (randomProp != 0) { + std::string suffix = getRandomPropertyName(randomProp); + if (!suffix.empty()) itemName += " " + suffix; + } uint32_t quality = info->quality; std::string link = buildItemLink(itemId, quality, itemName); std::string msg = "Received: " + link;