using System.Threading; using Dalamud.IoC; using Dalamud.IoC.Internal; using Dalamud.Plugin.Services; namespace Dalamud.Game; /// /// Class offering cancellation tokens for common gameplay events. /// [PluginInterface] [InterfaceVersion("1.0")] [ServiceManager.BlockingEarlyLoadedService] #pragma warning disable SA1015 [ResolveVia] #pragma warning restore SA1015 internal class GameLifecycle : IServiceType, IGameLifecycle { private readonly CancellationTokenSource dalamudUnloadCts = new(); private readonly CancellationTokenSource gameShutdownCts = new(); private CancellationTokenSource logoutCts = new(); /// /// Initializes a new instance of the class. /// [ServiceManager.ServiceConstructor] internal GameLifecycle() { } /// public CancellationToken DalamudUnloadingToken => this.dalamudUnloadCts.Token; /// public CancellationToken GameShuttingDownToken => this.gameShutdownCts.Token; /// public CancellationToken LogoutToken => this.logoutCts.Token; /// /// Mark an unload. /// internal void SetUnloading() => this.dalamudUnloadCts.Cancel(); /// /// Mark a shutdown. /// internal void SetShuttingDown() => this.gameShutdownCts.Cancel(); /// /// Mark a logout. /// internal void SetLogout() => this.logoutCts.Cancel(); /// /// Unmark a logout. /// internal void ResetLogout() => this.logoutCts = new(); }