From 301b1259ee57e8bc1d8f8c6542ea8d177ad14ef4 Mon Sep 17 00:00:00 2001 From: John Coffey Date: Sun, 15 Nov 2026 00:50:40 -0700 Subject: [PATCH] Read talents through C_SpecializationInfo when the client has it --- Core.lua | 71 +++++++++++++++++++++++++++++++++++++++++++---- tools/harness.lua | 12 ++++++++ 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/Core.lua b/Core.lua index 1878201..94d5a6f 100644 --- a/Core.lua +++ b/Core.lua @@ -226,17 +226,53 @@ local function TabInfo(t) return a, b, c -- name, icon, pointsSpent end +local function TalentGroup() + if C_SpecializationInfo and C_SpecializationInfo.GetActiveSpecGroup then + local ok, g = pcall(C_SpecializationInfo.GetActiveSpecGroup); if ok and g then return g end + end + if GetActiveTalentGroup then + local ok, g = pcall(GetActiveTalentGroup); if ok and g then return g end + end + return 1 +end + +-- One talent: name, icon, tier, column, rank, maxRank. Newer clients (WoW Forever included) use +-- C_SpecializationInfo.GetTalentInfo(query), which returns a table; older ones use the global +-- GetTalentInfo(tab, index), which some builds return with a talent ID in front. +local function TalentInfo(t, i, group) + if C_SpecializationInfo and C_SpecializationInfo.GetTalentInfo then + local ok, x = pcall(C_SpecializationInfo.GetTalentInfo, + { specializationIndex = t, talentIndex = i, isInspect = false, isPet = false, groupIndex = group }) + if ok and type(x) == "table" and x.name then + return x.name, x.icon, x.tier, x.column, x.rank, x.maxRank, "C_SpecializationInfo" + end + end + if GetTalentInfo then + local ok, a, b, c, d, e, f, g = pcall(GetTalentInfo, t, i) + if ok and type(a) == "string" then return a, b, c, d, e, f, "GetTalentInfo" end + if ok and type(a) == "number" and type(b) == "string" then return b, c, d, e, f, g, "GetTalentInfo(id)" end + end +end + +local MAX_TALENTS = 40 +ns.talentSource = nil + function ns.ScanTalents() local T = ns.talents wipe(T.byName); wipe(T.tabs); T.total = 0 - if not GetNumTalentTabs then return end - for t = 1, GetNumTalentTabs() do - local name, icon, points = TabInfo(t) + local numTabs = GetNumTalentTabs and GetNumTalentTabs() or 3 + local group = TalentGroup() + for t = 1, numTabs do + local ok, name, icon, points = pcall(TabInfo, t) + if not ok then name, icon, points = nil, nil, 0 end T.tabs[t] = { name = name, icon = icon, points = points or 0 } T.total = T.total + (points or 0) - for i = 1, (GetNumTalents(t) or 0) do - local tname, ticon, tier, column, rank, maxRank = GetTalentInfo(t, i) + local count = GetNumTalents and GetNumTalents(t) or MAX_TALENTS + if not count or count == 0 then count = MAX_TALENTS end + for i = 1, count do + local tname, ticon, tier, column, rank, maxRank, source = TalentInfo(t, i, group) if tname then + ns.talentSource = source T.byName[tname] = { tab = t, index = i, icon = ticon, rank = rank or 0, maxRank = maxRank or 1, tier = tier, column = column, tabName = name } end @@ -244,6 +280,30 @@ function ns.ScanTalents() end end +-- /fg talentdebug: what the client's talent API returns, for bug reports. +function ns.TalentDebug() + ns.ScanTalents() + local n = 0; for _ in pairs(ns.talents.byName) do n = n + 1 end + ns.Print(("talents found: %d, points spent: %d, source: %s"):format(n, ns.talents.total, tostring(ns.talentSource))) + ns.Print(("API: GetTalentInfo=%s, C_SpecializationInfo.GetTalentInfo=%s, GetNumTalents=%s, GetNumTalentTabs=%s"):format( + tostring(GetTalentInfo ~= nil), tostring(C_SpecializationInfo ~= nil and C_SpecializationInfo.GetTalentInfo ~= nil), + tostring(GetNumTalents ~= nil), tostring(GetNumTalentTabs ~= nil))) + for t, tab in ipairs(ns.talents.tabs) do ns.Print(("tab %d: %s (%d points)"):format(t, tostring(tab.name), tab.points)) end + if GetTalentInfo then + local ok, a, b, c, d, e, f = pcall(GetTalentInfo, 1, 1) + ns.Print("GetTalentInfo(1,1) -> " .. (ok and table.concat({ tostring(a), tostring(b), tostring(c), tostring(d), tostring(e), tostring(f) }, ", ") or ("error: " .. tostring(a)))) + end + local build = ns.GetActiveBuild() + if build and build.talents then + local missing = {} + for _, p in pairs(build.talents) do if not ns.talents.byName[p[1]] then missing[p[1]] = true end end + local list = {}; for k in pairs(missing) do list[#list + 1] = k end + table.sort(list) + ns.Print(("build %s: %d talent names not in your tree%s"):format(build.name or build.key or "?", #list, + #list > 0 and (": " .. table.concat(list, ", ", 1, math.min(#list, 8))) or "")) + end +end + function ns.TabIndexByName(name) for t, info in ipairs(ns.talents.tabs) do if info.name == name then return t end end end @@ -473,6 +533,7 @@ SlashCmdList.FOREVERGUIDE = function(msg) Print("progress reset."); ns.Fire("Refresh") elseif msg == "resetpos" then ns.char.pos = nil; ns.Fire("ResetPosition") + elseif msg == "talentdebug" then ns.TalentDebug() elseif msg == "support" or msg == "donate" then Print("ForeverGuide is free. To support Coffey Labs: " .. ns.SUPPORT); ns.ShowLink(ns.SUPPORT) else diff --git a/tools/harness.lua b/tools/harness.lua index 53ccde5..81274d8 100644 --- a/tools/harness.lua +++ b/tools/harness.lua @@ -98,6 +98,17 @@ function GetNumTalentTabs() return #tabs end function GetTalentTabInfo(t) return 100 + t, tabs[t], "", 1, 3 end function GetNumTalents(t) return #(talentsByTab[t] or {}) end function GetTalentInfo(t, i) local x = talentsByTab[t][i]; return x[1], 1, 1, 1, x[2], x[3] end +-- TALENT_API=new: only C_SpecializationInfo.GetTalentInfo (table); TALENT_API=id: talent ID first. +if os.getenv("TALENT_API") == "new" then + GetTalentInfo = nil + C_SpecializationInfo = C_SpecializationInfo or {} + C_SpecializationInfo.GetTalentInfo = function(q) + local x = talentsByTab[q.specializationIndex] and talentsByTab[q.specializationIndex][q.talentIndex] + if x then return { name = x[1], icon = 1, tier = 1, column = 1, rank = x[2], maxRank = x[3], talentID = 7 } end + end +elseif os.getenv("TALENT_API") == "id" then + function GetTalentInfo(t, i) local x = talentsByTab[t][i]; return 7, x[1], 1, 1, 1, x[2], x[3] end +end function GetNumSkillLines() return 2 end function GetSkillLineInfo(i) if i == 1 then return "Professions", true end @@ -166,6 +177,7 @@ local b = ns.GetActiveBuild() print("build:", b and b.name, "spec:", ns.ActiveSpec()) local L, plan = ns.PendingTalent() print("pending talent:", L, plan and ns.TalentText(plan)) +ns.TalentDebug() for _, tab in ipairs({ "quests", "route", "talents", "spec", "gear", "professions", "extras", "dungeons", "settings" }) do SlashCmdList.FOREVERGUIDE(tab == "route" and "guide" or tab) -- 2.54.0