fix playerguid race condition

This commit is contained in:
Jrc13245
2026-02-11 17:47:12 -05:00
parent f8d213d89a
commit 684bc9190e
2 changed files with 86 additions and 9 deletions
@@ -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)
@@ -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