From fa05bb6383b3b5bcde7b81f5969a71e9a348a264 Mon Sep 17 00:00:00 2001 From: Jade Macho Date: Wed, 9 Jul 2025 23:13:39 +0200 Subject: [PATCH] antilag: Use last 5 frames, even on title screen with notif --- CustomResolution2782/ConfigurationEnums.cs | 4 +-- CustomResolution2782/Plugin.cs | 38 ++++++++++++++++++-- CustomResolution2782/Service.cs | 3 ++ CustomResolution2782/Windows/ConfigWindow.cs | 11 ++++-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/CustomResolution2782/ConfigurationEnums.cs b/CustomResolution2782/ConfigurationEnums.cs index 6a36686..4e24f84 100644 --- a/CustomResolution2782/ConfigurationEnums.cs +++ b/CustomResolution2782/ConfigurationEnums.cs @@ -176,9 +176,7 @@ public static class ResolutionScalingModeExt public static bool IsBroken(this ResolutionScalingMode mode) => mode switch { -#if !DEBUG - ResolutionScalingMode.DLSS => true, -#endif + ResolutionScalingMode.DLSS => !Service.DebugConfig.IsDebug, _ => false }; diff --git a/CustomResolution2782/Plugin.cs b/CustomResolution2782/Plugin.cs index 22e0ee8..a5b4c47 100644 --- a/CustomResolution2782/Plugin.cs +++ b/CustomResolution2782/Plugin.cs @@ -1,5 +1,6 @@ using Dalamud.Game.ClientState.Keys; using Dalamud.Game.Config; +using Dalamud.Interface.ImGuiNotification; using Dalamud.Plugin; using Dalamud.Plugin.Services; using ImGuiNET; @@ -16,6 +17,9 @@ public sealed unsafe class Plugin : IDalamudPlugin private readonly List _cmds; private bool _ignoreConfigChanges = false; + private int _lagsIndex = 0; + private readonly bool[] _lagsAll = new bool[5]; + public Plugin(IDalamudPluginInterface pluginInterface) { pluginInterface.Create(); @@ -54,6 +58,9 @@ public sealed unsafe class Plugin : IDalamudPlugin public bool Unloading { get; private set; } = false; + public int LagsTotal { get; private set; } = 0; + public bool Lag { get; private set; } = false; + public void Dispose() { Unloading = true; @@ -80,10 +87,25 @@ public sealed unsafe class Plugin : IDalamudPlugin private void OnFrameworkUpdateForSize(IFramework framework, string type, ref ConfigurationV1.SizeConfig size) { - if (Service.ClientState.IsLoggedIn && framework.UpdateDelta.TotalSeconds >= 1 && Service.Config._.DisableOnHang && size.IsEnabled) + if (Lag && Service.Config._.DisableOnHang && size.IsEnabled) { Service.PluginLog.Warning($"Disabling because hang: {type}"); - Service.PrintChat($"Lag detected, \"{type}\" custom resolution disabled."); + if (Service.ClientState.IsLoggedIn) + { + Service.PrintChat($"Lag detected, \"{type}\" custom resolution disabled."); + } + else + { + // An initial duration of 15 might seem absurd, but we're dealing with lag here! + Service.NotificationManager.AddNotification(new Notification() + { + Title = "CustomResolution", + Content = $"Lag detected, \"{type}\" custom resolution disabled.", + Type = NotificationType.Error, + InitialDuration = TimeSpan.FromSeconds(framework.UpdateDelta.TotalSeconds + 15), + Minimized = false + }); + } size.IsEnabled = false; Service.Config.Save(); } @@ -114,6 +136,18 @@ public sealed unsafe class Plugin : IDalamudPlugin private void OnFrameworkUpdate(IFramework framework) { + if (_lagsAll[_lagsIndex]) + { + LagsTotal--; + } + if (_lagsAll[_lagsIndex] = framework.UpdateDelta.TotalSeconds > 1.0) + { + LagsTotal++; + } + _lagsIndex = (_lagsIndex + 1) % _lagsAll.Length; + + Lag = LagsTotal == _lagsAll.Length; + lock (_disposeLock) { OnFrameworkUpdateForSize(framework, "Display", ref Service.Config._.Display); diff --git a/CustomResolution2782/Service.cs b/CustomResolution2782/Service.cs index d69d99b..b954c4d 100644 --- a/CustomResolution2782/Service.cs +++ b/CustomResolution2782/Service.cs @@ -58,6 +58,9 @@ public sealed class Service [PluginService] public static IGameConfig GameConfig { get; private set; } = null!; + [PluginService] + public static INotificationManager NotificationManager { get; private set; } = null!; + public static void PrintChat(string msg) { ChatGui.Print(new XivChatEntry diff --git a/CustomResolution2782/Windows/ConfigWindow.cs b/CustomResolution2782/Windows/ConfigWindow.cs index 5147a04..2f64476 100644 --- a/CustomResolution2782/Windows/ConfigWindow.cs +++ b/CustomResolution2782/Windows/ConfigWindow.cs @@ -166,7 +166,7 @@ Changed via /gres"); { using var border = ImRaii.PushColor(ImGuiCol.Border, 0xFF00FFFF); if (ImGui.Button(@$"Your game system configuration is currently stuck on -an unsupported graphics upscaling option: {Service.GameSize.ConfigGraphicsRezoType} +an unsupported graphics upscaling option: {Service.GameSize.ConfigGraphicsRezoType.ToHumanNameString()} This can happen after you've replaced your GPU, or when your graphic driver has encountered problems. @@ -330,11 +330,11 @@ Not intended to be used with proper fullscreen."); ImGui.EndCombo(); } - ImGui.Checkbox("Game hang protection", ref _.DisableOnHang); + ImGui.Checkbox("Disable on lag", ref _.DisableOnHang); if (ImGui.IsItemHovered()) { - ImGui.SetTooltip(@$"Automatically disables scaling if the game hangs for more than a second. + ImGui.SetTooltip(@$"Automatically disables scaling if FPS goes below 1 FPS. Leave this option enabled if you want this plugin to disable itself as a protection in case the resolution changes unexpectedly, or in case the resolution goes too high. @@ -348,5 +348,10 @@ In the absolute worst case, delete the following file to reset your settings: ImGui.Checkbox("DEBUG!", ref debug); Service.DebugConfig.IsDebug = debug; #endif + + if (Service.DebugConfig.IsDebug) + { + ImGui.Text($"LAG: {Service.Plugin.LagsTotal} {Service.Plugin.Lag}"); + } } }