using System; using BepInEx.Logging; namespace UXAssist.Common; /// /// Provides safe invocation helpers for game events. /// public static class GameEvent { /// /// Invokes each handler in the action's invocation list individually, /// logging a warning if any handler throws an exception. /// /// The action to invoke. /// The logger to use for warnings. /// The name of the event for diagnostic messages. public static void InvokeSafe(this Action action, ManualLogSource logger, string name) { if (action == null) return; foreach (var d in action.GetInvocationList()) { try { d.DynamicInvoke(); } catch (Exception ex) { logger?.LogWarning($"GameEvent '{name}' handler failed: {ex}"); } } } }