antilag: Use last 5 frames, even on title screen with notif

This commit is contained in:
Jade Macho 2025-07-09 23:13:39 +02:00
parent ec59c46440
commit fa05bb6383
Signed by: 0x0ade
GPG key ID: E1960710FE4FBEEF
4 changed files with 48 additions and 8 deletions

View file

@ -176,9 +176,7 @@ public static class ResolutionScalingModeExt
public static bool IsBroken(this ResolutionScalingMode mode) => mode switch public static bool IsBroken(this ResolutionScalingMode mode) => mode switch
{ {
#if !DEBUG ResolutionScalingMode.DLSS => !Service.DebugConfig.IsDebug,
ResolutionScalingMode.DLSS => true,
#endif
_ => false _ => false
}; };

View file

@ -1,5 +1,6 @@
using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Keys;
using Dalamud.Game.Config; using Dalamud.Game.Config;
using Dalamud.Interface.ImGuiNotification;
using Dalamud.Plugin; using Dalamud.Plugin;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using ImGuiNET; using ImGuiNET;
@ -16,6 +17,9 @@ public sealed unsafe class Plugin : IDalamudPlugin
private readonly List<Cmd> _cmds; private readonly List<Cmd> _cmds;
private bool _ignoreConfigChanges = false; private bool _ignoreConfigChanges = false;
private int _lagsIndex = 0;
private readonly bool[] _lagsAll = new bool[5];
public Plugin(IDalamudPluginInterface pluginInterface) public Plugin(IDalamudPluginInterface pluginInterface)
{ {
pluginInterface.Create<Service>(); pluginInterface.Create<Service>();
@ -54,6 +58,9 @@ public sealed unsafe class Plugin : IDalamudPlugin
public bool Unloading { get; private set; } = false; public bool Unloading { get; private set; } = false;
public int LagsTotal { get; private set; } = 0;
public bool Lag { get; private set; } = false;
public void Dispose() public void Dispose()
{ {
Unloading = true; Unloading = true;
@ -80,10 +87,25 @@ public sealed unsafe class Plugin : IDalamudPlugin
private void OnFrameworkUpdateForSize(IFramework framework, string type, ref ConfigurationV1.SizeConfig size) 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.PluginLog.Warning($"Disabling because hang: {type}");
if (Service.ClientState.IsLoggedIn)
{
Service.PrintChat($"Lag detected, \"{type}\" custom resolution disabled."); 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; size.IsEnabled = false;
Service.Config.Save(); Service.Config.Save();
} }
@ -114,6 +136,18 @@ public sealed unsafe class Plugin : IDalamudPlugin
private void OnFrameworkUpdate(IFramework framework) 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) lock (_disposeLock)
{ {
OnFrameworkUpdateForSize(framework, "Display", ref Service.Config._.Display); OnFrameworkUpdateForSize(framework, "Display", ref Service.Config._.Display);

View file

@ -58,6 +58,9 @@ public sealed class Service
[PluginService] [PluginService]
public static IGameConfig GameConfig { get; private set; } = null!; public static IGameConfig GameConfig { get; private set; } = null!;
[PluginService]
public static INotificationManager NotificationManager { get; private set; } = null!;
public static void PrintChat(string msg) public static void PrintChat(string msg)
{ {
ChatGui.Print(new XivChatEntry ChatGui.Print(new XivChatEntry

View file

@ -166,7 +166,7 @@ Changed via /gres");
{ {
using var border = ImRaii.PushColor(ImGuiCol.Border, 0xFF00FFFF); using var border = ImRaii.PushColor(ImGuiCol.Border, 0xFF00FFFF);
if (ImGui.Button(@$"Your game system configuration is currently stuck on 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, This can happen after you've replaced your GPU,
or when your graphic driver has encountered problems. or when your graphic driver has encountered problems.
@ -330,11 +330,11 @@ Not intended to be used with proper fullscreen.");
ImGui.EndCombo(); ImGui.EndCombo();
} }
ImGui.Checkbox("Game hang protection", ref _.DisableOnHang); ImGui.Checkbox("Disable on lag", ref _.DisableOnHang);
if (ImGui.IsItemHovered()) 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 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. 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); ImGui.Checkbox("DEBUG!", ref debug);
Service.DebugConfig.IsDebug = debug; Service.DebugConfig.IsDebug = debug;
#endif #endif
if (Service.DebugConfig.IsDebug)
{
ImGui.Text($"LAG: {Service.Plugin.LagsTotal} {Service.Plugin.Lag}");
}
} }
} }