Files

141 lines
7.6 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Owned-test diagnostic. Every cast still needs one hardware key press; the
-- secure wrapper only advances which spell the next press casts.
local function public(v)return type(issecretvalue)~="function" or not issecretvalue(v)end
local S
local function now()return GetTime and GetTime() or 0 end
local function log(kind,...)
if not S then return end
local row={t=now(),k=kind}
local n=select("#",...)
for i=1,n do local v=select(i,...);if public(v)and(type(v)=="string"or type(v)=="number"or type(v)=="boolean")then row[i]=v end end
S.events[#S.events+1]=row
if #S.events>20000 then table.remove(S.events,1)end
end
local function spellbook()
local out={}
local function add(id,name,sub,passive)
if not id or not public(id)then return end
local desc=GetSpellDescription and GetSpellDescription(id)
local usable,nomana
if C_Spell and C_Spell.IsSpellUsable then usable,nomana=C_Spell.IsSpellUsable(id) elseif IsUsableSpell then usable,nomana=IsUsableSpell(id) end
out[#out+1]={id=id,name=name,rank=sub,passive=passive and true or false,desc=public(desc)and desc or nil,usable=public(usable)and usable or nil,nomana=public(nomana)and nomana or nil}
end
if C_SpellBook and C_SpellBook.GetNumSpellBookSkillLines and C_SpellBook.GetSpellBookItemInfo then
for line=1,C_SpellBook.GetNumSpellBookSkillLines()do
local info=C_SpellBook.GetSpellBookSkillLineInfo(line)
if info then for i=info.itemIndexOffset+1,info.itemIndexOffset+info.numSpellBookItems do
local it=C_SpellBook.GetSpellBookItemInfo(i,Enum.SpellBookSpellBank.Player)
if it and it.spellID then add(it.spellID,it.name,it.subName,it.isPassive)end
end end
end
elseif GetNumSpellTabs then
for tab=1,GetNumSpellTabs()do
local _,_,off,num=GetSpellTabInfo(tab)
for i=off+1,off+num do
local name,sub=GetSpellBookItemName(i,"spell")
local _,id=GetSpellBookItemInfo(i,"spell")
add(id,name,sub,IsPassiveSpell and IsPassiveSpell(i,"spell"))
end
end
end
return out
end
local handler=CreateFrame("Frame","GWSpellAuditHandler",UIParent,"SecureHandlerBaseTemplate")
local function button(name,key)
local b=CreateFrame("Button",name,UIParent,"SecureActionButtonTemplate")
b:SetAttribute("type","spell");b:RegisterForClicks("AnyDown","AnyUp");b:SetAttribute("pressAndHoldAction",false)
return b
end
local cycle=button("GWSpellAuditCycle")
local single=button("GWSpellAuditSingle")
handler:WrapScript(cycle,"OnClick",[[
if not down then return false end
local n=self:GetAttribute("count") or 0
local i=(self:GetAttribute("index") or 0)+1
if i>n then i=1 end
self:SetAttribute("index",i)
self:SetAttribute("spell",self:GetAttribute("s"..i))
]])
handler:WrapScript(single,"OnClick",[[if not down then return false end]])
local stanceFirst={["Battle Stance"]=true,["Defensive Stance"]=true,["Berserker Stance"]=true}
local function plan()
local book=spellbook();local list={};local stances={};local others={}
for _,s in ipairs(book)do
if not s.passive and s.name and s.id and s.id>100 and s.name~="Auto Attack" and s.name~="Attack"then
if stanceFirst[s.name]then stances[#stances+1]=s.name else others[#others+1]=s.name end
end
end
if #stances==0 then stances={false}end
for _,st in ipairs(stances)do
if st then list[#list+1]=st end
for _,o in ipairs(others)do list[#list+1]=o end
end
for i,name in ipairs(list)do cycle:SetAttribute("s"..i,name)end
cycle:SetAttribute("count",#list);cycle:SetAttribute("index",0)
S.plan=list;S.book=book
end
cycle:HookScript("OnClick",function(_,_,down)if down then log("press",cycle:GetAttribute("spell"))end end)
single:HookScript("OnClick",function(_,_,down)if down then log("press1",single:GetAttribute("spell"))end end)
local f=CreateFrame("Frame")
for _,e in ipairs({"PLAYER_LOGIN","UNIT_SPELLCAST_SUCCEEDED","UNIT_SPELLCAST_FAILED","UNIT_SPELLCAST_FAILED_QUIET","UNIT_SPELLCAST_INTERRUPTED","UNIT_SPELLCAST_SENT","UI_ERROR_MESSAGE","UNIT_AURA","UNIT_HEALTH","UNIT_POWER_UPDATE","ADDON_ACTION_BLOCKED","ADDON_ACTION_FORBIDDEN"})do pcall(f.RegisterEvent,f,e)end
pcall(f.RegisterEvent,f,"COMBAT_LOG_EVENT_UNFILTERED")
local lastHealth
f:SetScript("OnEvent",function(_,e,unit,a,b,c)
if e=="PLAYER_LOGIN"then
WoWHybridSpellAuditSaved={events={},started=date and date("%Y-%m-%d %H:%M:%S")}
S=WoWHybridSpellAuditSaved
pcall(plan)
if not InCombatLockdown()then
SetOverrideBindingClick(handler,true,"F9","GWSpellAuditCycle","LeftButton")
SetOverrideBindingClick(handler,true,"F10","GWSpellAuditSingle","LeftButton")
end
log("ready",S.plan and #S.plan or -1)
return
end
if not S then return end
if e=="UNIT_SPELLCAST_SUCCEEDED"or e=="UNIT_SPELLCAST_FAILED"or e=="UNIT_SPELLCAST_FAILED_QUIET"or e=="UNIT_SPELLCAST_INTERRUPTED"or e=="UNIT_SPELLCAST_SENT"then
if unit=="player"then log(e,b,c)end
elseif e=="UI_ERROR_MESSAGE"then log(e,unit,a)
elseif e=="ADDON_ACTION_BLOCKED"or e=="ADDON_ACTION_FORBIDDEN"then log(e,unit,a)
elseif e=="UNIT_HEALTH"then
if unit=="target"then local h=UnitHealth("target");if public(h)then if lastHealth and h~=lastHealth then log("thp",h,lastHealth-h,UnitHealthMax("target"))end;lastHealth=h end end
elseif e=="UNIT_POWER_UPDATE"then
if unit=="player"then local p=UnitPower("player");if public(p)then log("pow",p)end end
elseif e=="UNIT_AURA"then
if unit=="player"or unit=="target"then
local names={}
if InCombatLockdown()then return end
if C_UnitAuras and C_UnitAuras.GetAuraDataByIndex then
for _,flt in ipairs({"HELPFUL","HARMFUL"})do for i=1,40 do local d=C_UnitAuras.GetAuraDataByIndex(unit,i,flt);if not d then break end
if public(d.spellId)then names[#names+1]=d.spellId end end end
end
log("aura",unit,table.concat(names,","))
end
elseif e=="COMBAT_LOG_EVENT_UNFILTERED"and CombatLogGetCurrentEventInfo then
local ok,r=pcall(function()return{CombatLogGetCurrentEventInfo()}end)
if ok and r then local src=r[4];if src==UnitGUID("player")or r[8]==UnitGUID("player")then log("cl",r[2],r[5],r[9],r[12],r[13],r[15],r[16],r[17],r[18],r[21])end end
end
end)
SLASH_GWSPELLAUDIT1="/gwsa"
SlashCmdList.GWSPELLAUDIT=function(msg)
if not S then return end
if msg=="replan"and not InCombatLockdown()then pcall(plan);log("replan",#S.plan)
elseif msg:match("^one ")and not InCombatLockdown()then single:SetAttribute("spell",msg:sub(5));log("single",msg:sub(5))
elseif msg=="book"then S.book=spellbook();local b,p,n=UnitAttackPower("player");log("book",#S.book,b,p,n,UnitLevel("player"))
elseif msg:match("^mark ")then log("mark",msg:sub(6))
elseif msg:match("^bar ")and not InCombatLockdown()then
-- Place up to 12 named spells on action slots 1-12 (keys 1..=), out of combat only.
local names={}for n in msg:sub(5):gmatch("[^,]+")do names[#names+1]=n:gsub("^%s+",""):gsub("%s+$","")end
local pick=(C_Spell and C_Spell.PickupSpell)or PickupSpell
for slot=1,12 do
ClearCursor()
if names[slot]then pcall(pick,names[slot]);if CursorHasSpell and CursorHasSpell()then PlaceAction(slot)end
else PickupAction(slot)end
ClearCursor()
end
log("bar",msg:sub(5))
end
end