From b4dee8585fc342df8f7ee6317b918c4818826ed7 Mon Sep 17 00:00:00 2001 From: shagu Date: Fri, 10 May 2024 10:56:04 +0200 Subject: [PATCH] superwow: add superwow client mod compatibility --- ShaguTweaks.toc | 1 + mods/nameplate-castbar.lua | 5 +++ mods/superwow.lua | 71 ++++++++++++++++++++++++++++++++++++++ mods/target-castbar.lua | 14 ++++++-- 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 mods/superwow.lua diff --git a/ShaguTweaks.toc b/ShaguTweaks.toc index 6f40cff..299e95b 100644 --- a/ShaguTweaks.toc +++ b/ShaguTweaks.toc @@ -76,4 +76,5 @@ mods\unitframes-bighealth.lua mods\unitframes-classportrait.lua mods\cooldown-numbers.lua mods\turtle-wow.lua +mods\superwow.lua mods\reduced-actionbar.lua diff --git a/mods/nameplate-castbar.lua b/mods/nameplate-castbar.lua index 7dd1474..ef25f7b 100644 --- a/mods/nameplate-castbar.lua +++ b/mods/nameplate-castbar.lua @@ -79,6 +79,11 @@ module.enable = function(self) local name = this.name:GetText() local cast, nameSubtext, text, texture, startTime, endTime, isTradeSkill = UnitCastingInfo(name) + -- read enemy casts from SuperWoW if enabled + if ShaguTweaks.superwow_active then + cast, nameSubtext, text, texture, startTime, endTime, isTradeSkill = UnitCastingInfo(this:GetName(1)) + end + if cast then local duration = endTime - startTime local max = duration / 1000 diff --git a/mods/superwow.lua b/mods/superwow.lua new file mode 100644 index 0000000..8b222dc --- /dev/null +++ b/mods/superwow.lua @@ -0,0 +1,71 @@ +-- SuperWoW compatibility +-- +-- https://github.com/balakethelock/SuperWoW +-- +-- This module adds GUID based cast and channel data to the +-- libcast library that is used to query enemy casting infos. + +-- Skip module initialization if SuperWoW is not running. +if not GetPlayerBuffID or not CombatLogAdd or not SpellInfo then return end + +local T = ShaguTweaks.T + +local module = ShaguTweaks:register({ + title = T["Super WoW Compatibility"], + description = T["Adds compatibility for the SuperWoW client mod."], + expansions = { ["vanilla"] = true, ["tbc"] = false }, + category = T["General"], + enabled = true, +}) + +module.enable = function(self) + local libcast = ShaguTweaks.libcast + + local unitcast = CreateFrame("Frame") + unitcast:RegisterEvent("UNIT_CASTEVENT") + unitcast:SetScript("OnEvent", function() + if arg3 == "START" or arg3 == "CAST" or arg3 == "CHANNEL" then + -- human readable argument list + local guid = arg1 + local target = arg2 + local event_type = arg3 + local spell_id = arg4 + local timer = arg5 + local start = GetTime() + + -- get spell info from spell id + local spell, icon, _ + if SpellInfo and SpellInfo(spell_id) then + spell, _, icon = SpellInfo(spell_id) + end + + -- set fallback values + spell = spell or UNKNOWN + icon = icon or "Interface\\Icons\\INV_Misc_QuestionMark" + + -- add cast action to the database + if not libcast.db[guid] then libcast.db[guid] = {} end + libcast.db[guid].cast = spell + libcast.db[guid].rank = nil + libcast.db[guid].start = GetTime() + libcast.db[guid].casttime = timer + libcast.db[guid].icon = icon + libcast.db[guid].channel = event_type == "CHANNEL" or false + + -- write state variable + ShaguTweaks.superwow_active = true + elseif arg3 == "FAIL" then + local guid = arg1 + + -- delete all cast entries of guid + if libcast.db[guid] then + libcast.db[guid].cast = nil + libcast.db[guid].rank = nil + libcast.db[guid].start = nil + libcast.db[guid].casttime = nil + libcast.db[guid].icon = nil + libcast.db[guid].channel = nil + end + end + end) +end \ No newline at end of file diff --git a/mods/target-castbar.lua b/mods/target-castbar.lua index 8601ba1..0cd723b 100644 --- a/mods/target-castbar.lua +++ b/mods/target-castbar.lua @@ -66,10 +66,20 @@ module.enable = function(self) TargetFrame:SetScript("OnUpdate", function(arg) if oldUpdate then oldUpdate(arg) end - local cast, nameSubtext, text, texture, startTime, endTime, isTradeSkill = UnitCastingInfo(this.unit) + local query = this.unit + local channel = false + + -- try to read cast and guid from SuperWoW (except for self casts) + if ShaguTweaks.superwow_active and this.unit and not UnitIsUnit(this.unit, 'player') then + local _, guid = UnitExists(this.unit) + query = guid or query + end + + local cast, nameSubtext, text, texture, startTime, endTime, isTradeSkill = UnitCastingInfo(query) if not cast then -- scan for channel spells if no cast was found - cast, nameSubtext, text, texture, startTime, endTime, isTradeSkill = UnitChannelInfo(this.unit) + channel, nameSubtext, text, texture, startTime, endTime, isTradeSkill = UnitChannelInfo(query) + cast = channel end if cast then