diff --git a/README.md b/README.md index ed0c36a9..ac3d0df7 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Quick index: | Namespace | Calls | |-----------|-------| -| Spell | `GetSpellInfo` (with `(slot, bookType)` overload), `C_Spell.GetSpellInfo`, `GameTooltip:SetSpellByID`, `C_Spell.GetSpellDescription` | +| Spell | `GetSpellInfo` (with `(slot, bookType)` overload), `C_Spell.GetSpellInfo`, `C_Spell.GetSpellName`, `C_Spell.GetSpellTexture`, `GameTooltip:SetSpellByID`, `C_Spell.GetSpellDescription` | | Quest | `GetQuestIDFromLogIndex`, `C_QuestLog.RequestLoadQuestByID` (+ `QUEST_DATA_LOAD_RESULT` event), `C_QuestLog.GetTitleForQuestID` | | Faction | `GetFactionIDByIndex`, `GetFactionInfoByID` | | Item | `C_Item.IsBound`, `C_Item.GetItemID`, `C_Item.GetItemInfoInstant`, `C_Item.IsItemDataCached(ByID)`, `C_Item.RequestLoadItemData(ByID)` (+ `ITEM_DATA_LOAD_RESULT` event) | diff --git a/docs/API.md b/docs/API.md index 843eb489..0fab88c5 100644 --- a/docs/API.md +++ b/docs/API.md @@ -9,6 +9,8 @@ build instructions. - [Spell](#spell) - [`GetSpellInfo(spellID)` / `GetSpellInfo(slot, bookType)`](#getspellinfospellid--getspellinfoslot-booktype) - [`C_Spell.GetSpellInfo(spellID)`](#c_spellgetspellinfospellid) + - [`C_Spell.GetSpellName(spellID)`](#c_spellgetspellnamespellid) + - [`C_Spell.GetSpellTexture(spellID)`](#c_spellgetspelltexturespellid) - [`GameTooltip:SetSpellByID(spellID)`](#gametooltipsetspellbyidspellid) - [`C_Spell.GetSpellDescription(spellID)`](#c_spellgetspelldescriptionspellid) - [Quest](#quest) @@ -115,6 +117,38 @@ local info = C_Spell.GetSpellInfo(133) Equivalent to the function of the same name introduced in 4.0. +### `C_Spell.GetSpellName(spellID)` + +Returns the localized name of `spellID`, or `nil` if the spell ID is out +of range or has no name in the current locale. Convenience accessor for +the `name` field of [`C_Spell.GetSpellInfo`](#c_spellgetspellinfospellid) +when that's all you need — single field read, no DBC indirection beyond +the locale lookup. + +```lua +local name = C_Spell.GetSpellName(133) -- "Fireball" +``` + +Equivalent to the function of the same name introduced in 10.0. + +### `C_Spell.GetSpellTexture(spellID)` + +Returns the icon path string for `spellID` (read from `SpellIcon.dbc` +via the spell's `SpellIconID` field), or `nil` if the spell ID is out +of range or the icon record is empty. + +> **Path string, not fileID.** Modern WoW returns this as a +> `fileID:number`. Vanilla 1.12 has no fileID system — see the same +> note on [`C_Spell.GetSpellInfo`](#c_spellgetspellinfospellid)'s +> `iconID` field. Pass directly to `texture:SetTexture(...)`. + +```lua +local path = C_Spell.GetSpellTexture(133) +-- path = "Interface\\Icons\\Spell_Fire_FlameBolt" +``` + +Equivalent to the function of the same name introduced in 10.0. + ### `GameTooltip:SetSpellByID(spellID)` Renders a spell tooltip for any `spellID`, including spells the player has diff --git a/src/spell/Info.cpp b/src/spell/Info.cpp index 5d6c3bef..09484996 100644 --- a/src/spell/Info.cpp +++ b/src/spell/Info.cpp @@ -218,9 +218,51 @@ static int __fastcall Script_C_GetSpellInfo(void *L) { return 1; } +static int __fastcall Script_C_GetSpellName(void *L) { + if (!Game::Lua::IsNumber(L, 1)) { + Game::Lua::Error(L, "Usage: C_Spell.GetSpellName(spellID)"); + return 0; + } + const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); + const uint8_t *record = Spell::Lookup::RecordForID(spellID); + if (record == nullptr) + return 0; // nil for unknown spellID + + const int locale = ReadGlobal(Offsets::VAR_LOCALE_INDEX); + const char *name = *reinterpret_cast(record + OFF_NAME + locale * 4); + if (name == nullptr || *name == '\0') + return 0; // empty / no name in current locale → nil + Game::Lua::PushString(L, name); + return 1; +} + +static int __fastcall Script_C_GetSpellTexture(void *L) { + if (!Game::Lua::IsNumber(L, 1)) { + Game::Lua::Error(L, "Usage: C_Spell.GetSpellTexture(spellID)"); + return 0; + } + const int spellID = static_cast(Game::Lua::ToNumber(L, 1)); + const uint8_t *record = Spell::Lookup::RecordForID(spellID); + if (record == nullptr) + return 0; + + const int iconID = *reinterpret_cast(record + OFF_ICON_ID); + auto *iconRec = LookupSubRecord(Offsets::VAR_SPELL_ICON_RECORDS, + Offsets::VAR_SPELL_ICON_COUNT, iconID); + if (iconRec == nullptr) + return 0; + const char *path = *reinterpret_cast(iconRec + 4); + if (path == nullptr || *path == '\0') + return 0; + Game::Lua::PushString(L, path); + return 1; +} + static void RegisterLuaFunctions() { Game::Lua::RegisterGlobalFunction("GetSpellInfo", &Script_GetSpellInfo); Game::Lua::RegisterTableFunction("C_Spell", "GetSpellInfo", &Script_C_GetSpellInfo); + Game::Lua::RegisterTableFunction("C_Spell", "GetSpellName", &Script_C_GetSpellName); + Game::Lua::RegisterTableFunction("C_Spell", "GetSpellTexture", &Script_C_GetSpellTexture); } static const Game::ModuleAutoRegister _autoreg{&RegisterLuaFunctions};