From b9a1b0244ba5838770b42b0cff605d586e9d7129 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 22 Mar 2026 21:53:58 -0700 Subject: [PATCH] feat: add GetEnchantInfo for enchantment name resolution GetEnchantInfo(enchantId) looks up the enchantment name from SpellItemEnchantment.dbc (field 14). Returns the display name like "Crusader", "+22 Intellect", or "Mongoose" for a given enchant ID. Used by equipment comparison addons and tooltip addons to display enchantment names on equipped gear. The enchant ID comes from the item's ITEM_FIELD_ENCHANTMENT update field. Also adds getEnchantName() to GameHandler for C++ access. --- include/game/game_handler.hpp | 1 + src/addons/lua_engine.cpp | 12 ++++++++++++ src/game/game_handler.cpp | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/include/game/game_handler.hpp b/include/game/game_handler.hpp index c8971854..523c6561 100644 --- a/include/game/game_handler.hpp +++ b/include/game/game_handler.hpp @@ -2243,6 +2243,7 @@ public: const std::string& getSpellRank(uint32_t spellId) const; /// Returns the tooltip/description text from Spell.dbc (empty if unknown or has no text). const std::string& getSpellDescription(uint32_t spellId) const; + std::string getEnchantName(uint32_t enchantId) const; const std::string& getSkillLineName(uint32_t spellId) const; /// Returns the DispelType for a spell (0=none,1=magic,2=curse,3=disease,4=poison,5+=other) uint8_t getSpellDispelType(uint32_t spellId) const; diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 3cb35c1f..99fe2a18 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -1687,6 +1687,17 @@ static int lua_GetSpellDescription(lua_State* L) { return 1; } +// GetEnchantInfo(enchantId) → name or nil +static int lua_GetEnchantInfo(lua_State* L) { + auto* gh = getGameHandler(L); + if (!gh) { lua_pushnil(L); return 1; } + uint32_t enchantId = static_cast(luaL_checknumber(L, 1)); + std::string name = gh->getEnchantName(enchantId); + if (name.empty()) { lua_pushnil(L); return 1; } + lua_pushstring(L, name.c_str()); + return 1; +} + static int lua_GetSpellCooldown(lua_State* L) { auto* gh = getGameHandler(L); if (!gh) { lua_pushnumber(L, 0); lua_pushnumber(L, 0); return 2; } @@ -5049,6 +5060,7 @@ void LuaEngine::registerCoreAPI() { {"GetSpellCooldown", lua_GetSpellCooldown}, {"GetSpellPowerCost", lua_GetSpellPowerCost}, {"GetSpellDescription", lua_GetSpellDescription}, + {"GetEnchantInfo", lua_GetEnchantInfo}, {"IsSpellInRange", lua_IsSpellInRange}, {"UnitDistanceSquared", lua_UnitDistanceSquared}, {"CheckInteractDistance", lua_CheckInteractDistance}, diff --git a/src/game/game_handler.cpp b/src/game/game_handler.cpp index 1064eadd..e38dbfab 100644 --- a/src/game/game_handler.cpp +++ b/src/game/game_handler.cpp @@ -23431,6 +23431,21 @@ const std::string& GameHandler::getSpellDescription(uint32_t spellId) const { return (it != spellNameCache_.end()) ? it->second.description : EMPTY_STRING; } +std::string GameHandler::getEnchantName(uint32_t enchantId) const { + if (enchantId == 0) return {}; + auto* am = core::Application::getInstance().getAssetManager(); + if (!am || !am->isInitialized()) return {}; + auto dbc = am->loadDBC("SpellItemEnchantment.dbc"); + if (!dbc || !dbc->isLoaded()) return {}; + // Name is at field 14 (consistent across Classic/TBC/WotLK) + for (uint32_t i = 0; i < dbc->getRecordCount(); ++i) { + if (dbc->getUInt32(i, 0) == enchantId) { + return dbc->getString(i, 14); + } + } + return {}; +} + uint8_t GameHandler::getSpellDispelType(uint32_t spellId) const { const_cast(this)->loadSpellNameCache(); auto it = spellNameCache_.find(spellId);