From 684bc9190e0022d74b33cf2b2ef0c0c0a14b23ba Mon Sep 17 00:00:00 2001 From: Jrc13245 Date: Wed, 11 Feb 2026 17:47:12 -0500 Subject: [PATCH] fix playerguid race condition --- .../MikCombatEventHelper.lua | 58 +++++++++++++++++-- .../MikScrollingBattleText.lua | 37 +++++++++++- 2 files changed, 86 insertions(+), 9 deletions(-) diff --git a/MikScrollingBattleText/MikCombatEventHelper.lua b/MikScrollingBattleText/MikCombatEventHelper.lua index 4585ae0..08e699b 100644 --- a/MikScrollingBattleText/MikCombatEventHelper.lua +++ b/MikScrollingBattleText/MikCombatEventHelper.lua @@ -313,8 +313,9 @@ function MikCEH.OnLoad() MikCEH.SetupNampowerEvents(); end - -- Register for the ADDON_LOADED event. + -- Register for the ADDON_LOADED and PLAYER_ENTERING_WORLD events. MCEHEventFrame:RegisterEvent("ADDON_LOADED"); + MCEHEventFrame:RegisterEvent("PLAYER_ENTERING_WORLD"); end @@ -337,6 +338,19 @@ function MikCEH.OnEvent() MikCEH.Init(); end + -- Retry playerGUID initialization when the player fully enters the world. + elseif (event == "PLAYER_ENTERING_WORLD") then + this:UnregisterEvent("PLAYER_ENTERING_WORLD"); + if not playerGUID then + if hasSuperWoW and UnitExists("player") then + local _, _, guid = pcall(UnitExists, "player") + if guid then playerGUID = guid end + elseif hasNampower and UnitGUID then + local ok, guid = pcall(UnitGUID, "player") + if ok and guid then playerGUID = guid end + end + end + -- Leave Combat elseif (event == "PLAYER_REGEN_ENABLED") then local eventData = MikCEH.GetNotificationEventData(MikCEH.NOTIFICATIONTYPE_COMBAT_LEAVE, nil, nil); @@ -827,10 +841,29 @@ local function ParseNampowerMitigation(mitigationStr, eventData) end +-- ********************************************************************************** +-- Ensures playerGUID is set. Called lazily by Nampower event handlers since +-- UnitGUID may not be available during ADDON_LOADED for some users. +-- ********************************************************************************** +local function EnsurePlayerGUID() + if playerGUID then return true end + if hasSuperWoW and UnitExists("player") then + local _, _, guid = pcall(UnitExists, "player") + if guid then playerGUID = guid; return true end + end + if hasNampower and UnitGUID then + local ok, guid = pcall(UnitGUID, "player") + if ok and guid then playerGUID = guid; return true end + end + return false +end + + -- ********************************************************************************** -- Nampower event dispatcher — called by the Nampower event frame's OnEvent. -- ********************************************************************************** function MikCEH.OnNampowerEvent() + EnsurePlayerGUID() local handler = nampowerHandlers[event] if handler then handler() end end @@ -953,7 +986,6 @@ end -- Args: attackerGuid, targetGuid, totalDamage, hitInfo, victimState, subDamageCount, blockedAmount, totalAbsorb, totalResist -- ********************************************************************************** nampowerHandlers["AUTO_ATTACK_SELF"] = function() - nampowerAutoAttackActive = true local casterGuid, targetGuid = arg1, arg2 local damage = arg3 local hitInfo = arg4 @@ -972,6 +1004,9 @@ nampowerHandlers["AUTO_ATTACK_SELF"] = function() return end + -- Only disable CHAT_MSG fallback after we've confirmed playerGUID works. + nampowerAutoAttackActive = true + local targetName = GetNameFromGUID(targetGuid) local actionType = nampowerVictimStateToAction[victimState] or MikCEH.ACTIONTYPE_HIT @@ -1024,7 +1059,6 @@ end -- Args: attackerGuid, targetGuid, totalDamage, hitInfo, victimState, subDamageCount, blockedAmount, totalAbsorb, totalResist -- ********************************************************************************** nampowerHandlers["AUTO_ATTACK_OTHER"] = function() - nampowerAutoAttackActive = true local casterGuid, targetGuid = arg1, arg2 local damage = arg3 local hitInfo = arg4 @@ -1043,6 +1077,9 @@ nampowerHandlers["AUTO_ATTACK_OTHER"] = function() return end + -- Only disable CHAT_MSG fallback after we've confirmed playerGUID works. + nampowerAutoAttackActive = true + local casterName = GetNameFromGUID(casterGuid) local actionType = nampowerVictimStateToAction[victimState] or MikCEH.ACTIONTYPE_HIT @@ -1091,7 +1128,6 @@ end -- Args: targetGuid, casterGuid, spellId, amount, critical, periodic -- ********************************************************************************** nampowerHandlers["SPELL_HEAL_ON_SELF"] = function() - nampowerHealsActive = true local targetGuid, casterGuid = arg1, arg2 local spellId = arg3 local healAmount = arg4 @@ -1101,6 +1137,9 @@ nampowerHandlers["SPELL_HEAL_ON_SELF"] = function() -- Only for player. if not IsPlayerGUID(targetGuid) then return end + -- Only disable CHAT_MSG fallback after we've confirmed playerGUID works. + nampowerHealsActive = true + local spellName = GetSpellNameFromId(spellId) local casterName = GetNameFromGUID(casterGuid) @@ -1129,7 +1168,6 @@ end -- Args: targetGuid, casterGuid, spellId, amount, critical, periodic -- ********************************************************************************** nampowerHandlers["SPELL_HEAL_BY_SELF"] = function() - nampowerHealsActive = true local targetGuid, casterGuid = arg1, arg2 local spellId = arg3 local healAmount = arg4 @@ -1137,8 +1175,14 @@ nampowerHandlers["SPELL_HEAL_BY_SELF"] = function() local isHot = arg6 -- Skip self-heals (handled by SPELL_HEAL_ON_SELF). + -- When playerGUID is nil, we can't identify self-heals, so bail out + -- and let the CHAT_MSG fallback handle it. + if not playerGUID then return end if IsPlayerGUID(targetGuid) then return end + -- Only disable CHAT_MSG fallback after we've confirmed playerGUID works. + nampowerHealsActive = true + local spellName = GetSpellNameFromId(spellId) local targetName = GetNameFromGUID(targetGuid) @@ -1166,7 +1210,6 @@ end -- Args: targetGuid, casterGuid, spellId, powerType, amount, periodic -- ********************************************************************************** nampowerHandlers["SPELL_ENERGIZE_ON_SELF"] = function() - nampowerEnergizeActive = true local spellId = arg3 local powerType = arg4 local amount = arg5 @@ -1174,6 +1217,9 @@ nampowerHandlers["SPELL_ENERGIZE_ON_SELF"] = function() local powerTypeStr = nampowerPowerTypeToString[powerType] if not powerTypeStr then return end + -- Only disable CHAT_MSG fallback after we've confirmed this handler works. + nampowerEnergizeActive = true + local spellName = GetSpellNameFromId(spellId) local eventData = MikCEH.GetNotificationEventData(MikCEH.NOTIFICATIONTYPE_POWER_GAIN, amount, powerTypeStr, spellName) diff --git a/MikScrollingBattleText/MikScrollingBattleText.lua b/MikScrollingBattleText/MikScrollingBattleText.lua index fb12d35..6aefdd9 100644 --- a/MikScrollingBattleText/MikScrollingBattleText.lua +++ b/MikScrollingBattleText/MikScrollingBattleText.lua @@ -1328,12 +1328,43 @@ function MikSBT.UpdateProfiles() end if (profile.CreationVersion < 4.4) then - + profile.BlizzardFontSettings = MikSBT.CopyTable(MikSBT.DEFAULT_CONFIG.BlizzardFontSettings); - + profile.CreationVersion = 4.4; end - + + if (profile.CreationVersion < 4.5) then + + -- Add missing outgoing pet event settings (omitted from the 4.3 migration). + local petOutgoingEvents = { + "MSBT_EVENTTYPE_OUTGOING_PET_DAMAGE", + "MSBT_EVENTTYPE_OUTGOING_PET_MISS", + "MSBT_EVENTTYPE_OUTGOING_PET_DODGE", + "MSBT_EVENTTYPE_OUTGOING_PET_PARRY", + "MSBT_EVENTTYPE_OUTGOING_PET_BLOCK", + "MSBT_EVENTTYPE_OUTGOING_PET_ABSORB", + "MSBT_EVENTTYPE_OUTGOING_PET_IMMUNE", + "MSBT_EVENTTYPE_OUTGOING_PET_EVADE", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_DAMAGE", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_MISS", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_DODGE", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_PARRY", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_BLOCK", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_RESIST", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_ABSORB", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_IMMUNE", + "MSBT_EVENTTYPE_OUTGOING_PET_SPELL_EVADE", + }; + for _, evtName in petOutgoingEvents do + if not profile.EventSettings[evtName] and MikSBT.DEFAULT_CONFIG.EventSettings[evtName] then + profile.EventSettings[evtName] = MikSBT.CopyTable(MikSBT.DEFAULT_CONFIG.EventSettings[evtName]); + end + end + + profile.CreationVersion = 4.5; + end + end end