libcast: optimize spell cast hooks

- move rank & texture caching to CastCustom
- extend CastCustom with additional arguments
- remove action id scanning from CastSpellByName
This commit is contained in:
Kyriakos (Dominick) Sidiropoulos
2024-06-07 09:02:22 +02:00
committed by GitHub
parent b7289a702c
commit 5a7ee5277b
+24 -36
View File
@@ -373,15 +373,18 @@ libcast.customcast[strlower(multishot)] = function(begin, duration)
end end
end end
local function CastCustom(spell) local function CastCustom(id, bookType, rawSpellName, rank, texture, castingTime)
if not spell then return end if not id or not rawSpellName or not castingTime then return end -- ignore if the spell is not found or if it is instant-cast
if not UnitCastingInfo(UnitName("player")) then
for custom, func in pairs(libcast.customcast) do lastrank = rank
if strfind(strlower(spell), custom) or strlower(spell) == custom then lastcasttex = texture
func(true)
end local func = libcast.customcast[strlower(rawSpellName)]
end if not func then return end
end
if GetSpellCooldown(id, bookType) == 0 or UnitCastingInfo(player) then return end -- detect casting
func(true)
end end
hooksecurefunc("UseContainerItem", function(id, index) hooksecurefunc("UseContainerItem", function(id, index)
@@ -389,42 +392,27 @@ hooksecurefunc("UseContainerItem", function(id, index)
end) end)
hooksecurefunc("CastSpell", function(id, bookType) hooksecurefunc("CastSpell", function(id, bookType)
local spellName, rank, texture, _, _, _, cachedId = libspell.GetSpellInfo(id, bookType) local cachedRawSpellName, cachedRank, cachedTexture, cachedCastingTime, _, _, cachedSpellId, cachedBookType = libspell.GetSpellInfo(id, bookType)
if not spellName or not cachedId then return end -- ignore if the spell is not found
lastrank = rank CastCustom(cachedSpellId, cachedBookType, cachedRawSpellName, cachedRank, cachedTexture, cachedCastingTime)
lastcasttex = texture
if GetSpellCooldown(id, bookType) ~= 0 then
CastCustom(spellName)
end
end, true) end, true)
hooksecurefunc("CastSpellByName", function(spellCasted, target) hooksecurefunc("CastSpellByName", function(spellCasted, target)
local spellName, rank, texture, _, _, _, cachedId = libspell.GetSpellInfo(spellCasted) local cachedRawSpellName, cachedRank, cachedTexture, cachedCastingTime, _, _, cachedSpellId, cachedBookType = libspell.GetSpellInfo(spellCasted)
if not spellName or not cachedId then return end -- ignore if the spell is not found
lastrank = rank CastCustom(cachedSpellId, cachedBookType, cachedRawSpellName, cachedRank, cachedTexture, cachedCastingTime)
lastcasttex = texture
for i=1,120 do
-- detect if any cast is ongoing
if IsCurrentAction(i) then
CastCustom(spellCasted)
return
end
end
end, true) end, true)
hooksecurefunc("UseAction", function(slot, target, button) hooksecurefunc("UseAction", function(slot, target, button)
scanner:SetAction(slot)
local spellName, rank = scanner:Line(1)
lastcasttex = GetActionTexture(slot)
lastrank = rank
if GetActionText(slot) or not IsCurrentAction(slot) then return end if GetActionText(slot) or not IsCurrentAction(slot) then return end
CastCustom(spellName)
scanner:SetAction(slot)
local rawSpellName, rank = scanner:Line(1)
if not rawSpellName then return end -- ignore if the spell is not found
local cachedRawSpellName, cachedRank, cachedTexture, cachedCastingTime, _, _, cachedSpellId, cachedBookType = libspell.GetSpellInfo(rawSpellName .. (rank and ("(" .. rank .. ")") or ""))
CastCustom(cachedSpellId, cachedBookType, cachedRawSpellName, cachedRank, cachedTexture, cachedCastingTime)
end, true) end, true)
-- add libcast to pfUI API -- add libcast to pfUI API