diff --git a/LightlessSync/Services/DalamudUtilService.cs b/LightlessSync/Services/DalamudUtilService.cs index f3bf08d..f476076 100644 --- a/LightlessSync/Services/DalamudUtilService.cs +++ b/LightlessSync/Services/DalamudUtilService.cs @@ -140,14 +140,14 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber public bool IsWine { get; init; } - public static unsafe GameObject* GposeTarget + public unsafe GameObject* GposeTarget { get => TargetSystem.Instance()->GPoseTarget; set => TargetSystem.Instance()->GPoseTarget = value; } - private static unsafe bool HasGposeTarget => GposeTarget != null; - private static unsafe int GPoseTargetIdx => !HasGposeTarget ? -1 : GposeTarget->ObjectIndex; + private unsafe bool HasGposeTarget => GposeTarget != null; + private unsafe int GPoseTargetIdx => !HasGposeTarget ? -1 : GposeTarget->ObjectIndex; public async Task GetGposeTargetGameObjectAsync() { diff --git a/LightlessSync/Services/PerformanceCollectorService.cs b/LightlessSync/Services/PerformanceCollectorService.cs index 877cc1c..d2b4c46 100644 --- a/LightlessSync/Services/PerformanceCollectorService.cs +++ b/LightlessSync/Services/PerformanceCollectorService.cs @@ -135,13 +135,13 @@ public sealed class PerformanceCollectorService : IHostedService if (pastEntries.Any()) { - sb.Append((" " + TimeSpan.FromTicks(pastEntries.LastOrDefault() == default ? 0 : pastEntries.Last().Item2).TotalMilliseconds.ToString("0.00000", CultureInfo.InvariantCulture)).PadRight(15)); + sb.Append((" " + TimeSpan.FromTicks(pastEntries.LastOrDefault() == default ? 0 : pastEntries[^1].Item2).TotalMilliseconds.ToString("0.00000", CultureInfo.InvariantCulture)).PadRight(15)); sb.Append('|'); sb.Append((" " + TimeSpan.FromTicks(pastEntries.Max(m => m.Item2)).TotalMilliseconds.ToString("0.00000", CultureInfo.InvariantCulture)).PadRight(15)); sb.Append('|'); sb.Append((" " + TimeSpan.FromTicks((long)pastEntries.Average(m => m.Item2)).TotalMilliseconds.ToString("0.00000", CultureInfo.InvariantCulture)).PadRight(15)); sb.Append('|'); - sb.Append((" " + (pastEntries.LastOrDefault() == default ? "-" : pastEntries.Last().Item1.ToString("HH:mm:ss.ffff", CultureInfo.InvariantCulture))).PadRight(15, ' ')); + sb.Append((" " + (pastEntries.LastOrDefault() == default ? "-" : pastEntries[^1].Item1.ToString("HH:mm:ss.ffff", CultureInfo.InvariantCulture))).PadRight(15, ' ')); sb.Append('|'); sb.Append((" " + pastEntries.Count).PadRight(10)); sb.Append('|'); @@ -183,7 +183,7 @@ public sealed class PerformanceCollectorService : IHostedService { try { - var last = entries.Value.ToList().Last(); + var last = entries.Value.ToList()[^1]; if (last.Item1.AddMinutes(10) < TimeOnly.FromDateTime(DateTime.Now) && !PerformanceCounters.TryRemove(entries.Key, out _)) { _logger.LogDebug("Could not remove performance counter {counter}", entries.Key); diff --git a/LightlessSync/Services/PlayerPerformanceService.cs b/LightlessSync/Services/PlayerPerformanceService.cs index 7db92e1..89a1e8e 100644 --- a/LightlessSync/Services/PlayerPerformanceService.cs +++ b/LightlessSync/Services/PlayerPerformanceService.cs @@ -97,7 +97,7 @@ public class PlayerPerformanceService warningText, pairHandler.Pair.UserData, pairHandler.Pair.IsPaused, - pairHandler.Pair.PlayerName)); + pairHandler.Pair.PlayerName ?? string.Empty)); } return true; @@ -148,8 +148,8 @@ public class PlayerPerformanceService $"{pair.PlayerName} ({pair.UserData.AliasOrUID}) automatically paused", message, pair.UserData, - true, - pair.PlayerName)); + IsPaused: true, + pair.PlayerName ?? string.Empty)); _mediator.Publish(new EventMessage(new Event(pair.PlayerName, pair.UserData, nameof(PlayerPerformanceService), EventSeverity.Warning, $"Exceeds triangle threshold: automatically paused ({triUsage}/{config.TrisAutoPauseThresholdThousands * 1000} triangles)"))); @@ -228,8 +228,8 @@ public class PlayerPerformanceService $"{pair.PlayerName} ({pair.UserData.AliasOrUID}) automatically paused", message, pair.UserData, - true, - pair.PlayerName)); + IsPaused: true, + pair.PlayerName ?? string.Empty)); _mediator.Publish(new PauseMessage(pair.UserData)); diff --git a/LightlessSync/UI/CharaDataHubUi.McdOnline.cs b/LightlessSync/UI/CharaDataHubUi.McdOnline.cs index e86ef10..2703acc 100644 --- a/LightlessSync/UI/CharaDataHubUi.McdOnline.cs +++ b/LightlessSync/UI/CharaDataHubUi.McdOnline.cs @@ -406,7 +406,7 @@ internal sealed partial class CharaDataHubUi { _uiSharedService.BigText("Poses"); var poseCount = updateDto.PoseList.Count(); - using (ImRaii.Disabled(poseCount >= maxPoses)) + using (ImRaii.Disabled(poseCount >= _maxPoses)) { if (_uiSharedService.IconTextButton(FontAwesomeIcon.Plus, "Add new Pose")) { @@ -414,8 +414,8 @@ internal sealed partial class CharaDataHubUi } } ImGui.SameLine(); - using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"), poseCount == maxPoses)) - ImGui.TextUnformatted($"{poseCount}/{maxPoses} poses attached"); + using (ImRaii.PushColor(ImGuiCol.Text, UIColors.Get("LightlessYellow"), poseCount == _maxPoses)) + ImGui.TextUnformatted($"{poseCount}/{_maxPoses} poses attached"); ImGuiHelpers.ScaledDummy(5); using var indent = ImRaii.PushIndent(10f); diff --git a/LightlessSync/UI/CharaDataHubUi.cs b/LightlessSync/UI/CharaDataHubUi.cs index 51723b9..8eb85d5 100644 --- a/LightlessSync/UI/CharaDataHubUi.cs +++ b/LightlessSync/UI/CharaDataHubUi.cs @@ -20,7 +20,7 @@ namespace LightlessSync.UI; internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase { - private const int maxPoses = 10; + private const int _maxPoses = 10; private readonly CharaDataManager _charaDataManager; private readonly CharaDataNearbyManager _charaDataNearbyManager; private readonly CharaDataConfigService _configService; @@ -32,7 +32,7 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase private readonly UiSharedService _uiSharedService; private CancellationTokenSource _closalCts = new(); private bool _disableUI = false; - private CancellationTokenSource _disposalCts = new(); + private readonly CancellationTokenSource _disposalCts = new(); private string _exportDescription = string.Empty; private string _filterCodeNote = string.Empty; private string _filterDescription = string.Empty; @@ -144,6 +144,8 @@ internal sealed partial class CharaDataHubUi : WindowMediatorSubscriberBase { _closalCts.CancelDispose(); _disposalCts.CancelDispose(); + _disposalCts.Dispose(); + _closalCts.Dispose(); } base.Dispose(disposing);