diff --git a/ComboPointTracker.lua b/ComboPointTracker.lua index 50b0b12..7254337 100644 --- a/ComboPointTracker.lua +++ b/ComboPointTracker.lua @@ -422,11 +422,10 @@ function Extension.OnLoad() if _G.CastSpell then local originalCastSpell = _G.CastSpell _G.CastSpell = function(id, bookType) - -- Get spell name before casting - local spellName = GetSpellName(id, bookType) + -- Safely try to track combo points without breaking the cast + local success, spellName = pcall(GetSpellName, id, bookType) - -- Capture combo points BEFORE casting if it's a combo scaling spell - if spellName and CleveRoids.IsComboScalingSpell(spellName) then + if success and spellName and CleveRoids.IsComboScalingSpell(spellName) then local currentCP = CleveRoids.GetComboPoints() if currentCP and currentCP > 0 then CleveRoids.lastComboPoints = currentCP @@ -439,65 +438,78 @@ function Extension.OnLoad() end end - -- Call original to cast the spell - originalCastSpell(id, bookType) + -- Call original to cast the spell (and capture return value) + local result1, result2, result3 = originalCastSpell(id, bookType) - -- Track combo points after casting - if spellName and CleveRoids.IsComboScalingSpell(spellName) then - CleveRoids.TrackComboPointCast(spellName) - - -- Confirm the tracking - if CleveRoids.ComboPointTracking[spellName] then - CleveRoids.ComboPointTracking[spellName].confirmed = true - end + -- Track combo points after casting (with error protection) + if success and spellName and CleveRoids.IsComboScalingSpell(spellName) then + pcall(function() + CleveRoids.TrackComboPointCast(spellName) + if CleveRoids.ComboPointTracking[spellName] then + CleveRoids.ComboPointTracking[spellName].confirmed = true + end + end) end + + return result1, result2, result3 end end if _G.UseAction then local originalUseAction = _G.UseAction _G.UseAction = function(slot, target, button) - -- Try to determine spell name from action slot BEFORE casting + -- Safely try to determine spell name without breaking action bar local spellName = nil - local actionText = GetActionText(slot) + pcall(function() + local actionText = GetActionText(slot) - -- If no action text, it's likely a spell (not a macro) - if not actionText then - -- Try to get from tooltip - GameTooltip:SetOwner(UIParent, "ANCHOR_NONE") - GameTooltip:SetAction(slot) - if GameTooltipTextLeft1 then - spellName = GameTooltipTextLeft1:GetText() - end - GameTooltip:Hide() - end + -- If no action text, it's likely a spell (not a macro) + if not actionText then + -- Try to get spell name from tooltip + -- Use a temporary hidden tooltip to avoid UI interference + local tooltip = getglobal("CleveRoidsComboTooltip") + if not tooltip then + tooltip = CreateFrame("GameTooltip", "CleveRoidsComboTooltip", nil, "GameTooltipTemplate") + tooltip:SetOwner(WorldFrame, "ANCHOR_NONE") + end - -- Capture combo points BEFORE casting if it's a combo scaling spell - if spellName and CleveRoids.IsComboScalingSpell(spellName) then - local currentCP = CleveRoids.GetComboPoints() - if currentCP and currentCP > 0 then - CleveRoids.lastComboPoints = currentCP - if CleveRoids.debug then - DEFAULT_CHAT_FRAME:AddMessage( - string.format("|cffaaaaff[UseAction]|r Captured %d combo points before casting %s", - currentCP, spellName) - ) + tooltip:ClearLines() + tooltip:SetAction(slot) + local text = getglobal("CleveRoidsComboTooltipTextLeft1") + if text then + spellName = text:GetText() end end - end - -- Call original to execute the action - originalUseAction(slot, target, button) - - -- Track combo points after casting - if spellName and CleveRoids.IsComboScalingSpell(spellName) then - CleveRoids.TrackComboPointCast(spellName) - - -- Confirm the tracking - if CleveRoids.ComboPointTracking[spellName] then - CleveRoids.ComboPointTracking[spellName].confirmed = true + -- Capture combo points if it's a combo scaling spell + if spellName and CleveRoids.IsComboScalingSpell(spellName) then + local currentCP = CleveRoids.GetComboPoints() + if currentCP and currentCP > 0 then + CleveRoids.lastComboPoints = currentCP + if CleveRoids.debug then + DEFAULT_CHAT_FRAME:AddMessage( + string.format("|cffaaaaff[UseAction]|r Captured %d combo points before casting %s", + currentCP, spellName) + ) + end + end end + end) + + -- Call original to execute the action (and capture return value) + local result1, result2, result3 = originalUseAction(slot, target, button) + + -- Track combo points after casting (with error protection) + if spellName and CleveRoids.IsComboScalingSpell(spellName) then + pcall(function() + CleveRoids.TrackComboPointCast(spellName) + if CleveRoids.ComboPointTracking[spellName] then + CleveRoids.ComboPointTracking[spellName].confirmed = true + end + end) end + + return result1, result2, result3 end end end