More InvokeSafely calls (#2215)

* Safely invoke DutyState event handlers

* Safely invoke GameGui event handlers
This commit is contained in:
Haselnussbomber 2025-03-28 17:19:25 +01:00 committed by GitHub
parent c1557df585
commit b28fab2d08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 24 deletions

View file

@ -1,10 +1,11 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Hooking; using Dalamud.Hooking;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Dalamud.Utility;
namespace Dalamud.Game.DutyState; namespace Dalamud.Game.DutyState;
@ -81,33 +82,33 @@ internal unsafe class DutyState : IInternalDisposableService, IDutyState
// Duty Commenced // Duty Commenced
case 0x4000_0001: case 0x4000_0001:
this.IsDutyStarted = true; this.IsDutyStarted = true;
this.DutyStarted?.Invoke(this, this.clientState.TerritoryType); this.DutyStarted?.InvokeSafely(this, this.clientState.TerritoryType);
break; break;
// Party Wipe // Party Wipe
case 0x4000_0005: case 0x4000_0005:
this.IsDutyStarted = false; this.IsDutyStarted = false;
this.DutyWiped?.Invoke(this, this.clientState.TerritoryType); this.DutyWiped?.InvokeSafely(this, this.clientState.TerritoryType);
break; break;
// Duty Recommence // Duty Recommence
case 0x4000_0006: case 0x4000_0006:
this.IsDutyStarted = true; this.IsDutyStarted = true;
this.DutyRecommenced?.Invoke(this, this.clientState.TerritoryType); this.DutyRecommenced?.InvokeSafely(this, this.clientState.TerritoryType);
break; break;
// Duty Completed Flytext Shown // Duty Completed Flytext Shown
case 0x4000_0002 when !this.CompletedThisTerritory: case 0x4000_0002 when !this.CompletedThisTerritory:
this.IsDutyStarted = false; this.IsDutyStarted = false;
this.CompletedThisTerritory = true; this.CompletedThisTerritory = true;
this.DutyCompleted?.Invoke(this, this.clientState.TerritoryType); this.DutyCompleted?.InvokeSafely(this, this.clientState.TerritoryType);
break; break;
// Duty Completed // Duty Completed
case 0x4000_0003 when !this.CompletedThisTerritory: case 0x4000_0003 when !this.CompletedThisTerritory:
this.IsDutyStarted = false; this.IsDutyStarted = false;
this.CompletedThisTerritory = true; this.CompletedThisTerritory = true;
this.DutyCompleted?.Invoke(this, this.clientState.TerritoryType); this.DutyCompleted?.InvokeSafely(this, this.clientState.TerritoryType);
break; break;
} }
} }

View file

@ -307,15 +307,7 @@ internal sealed unsafe class GameGui : IInternalDisposableService, IGameGui
if (values != null && valueCount == 1 && values->Int == -1) if (values != null && valueCount == 1 && values->Int == -1)
{ {
this.HoveredItem = 0; this.HoveredItem = 0;
this.HoveredItemChanged?.InvokeSafely(this, 0ul);
try
{
this.HoveredItemChanged?.Invoke(this, 0);
}
catch (Exception e)
{
Log.Error(e, "Could not dispatch HoveredItemChanged event.");
}
Log.Verbose("HoveredItem changed: 0"); Log.Verbose("HoveredItem changed: 0");
} }
@ -347,15 +339,7 @@ internal sealed unsafe class GameGui : IInternalDisposableService, IGameGui
this.HoveredAction.ActionKind = HoverActionKind.None; this.HoveredAction.ActionKind = HoverActionKind.None;
this.HoveredAction.BaseActionID = 0; this.HoveredAction.BaseActionID = 0;
this.HoveredAction.ActionID = 0; this.HoveredAction.ActionID = 0;
this.HoveredActionChanged?.InvokeSafely(this, this.HoveredAction);
try
{
this.HoveredActionChanged?.Invoke(this, this.HoveredAction);
}
catch (Exception e)
{
Log.Error(e, "Could not dispatch HoveredActionChanged event.");
}
Log.Verbose("HoverActionId: 0"); Log.Verbose("HoverActionId: 0");
} }