Pause at duty

This commit is contained in:
defnotken
2025-09-07 15:24:19 -05:00
parent 5e30cb7bea
commit 6832c80fbb
6 changed files with 71 additions and 13 deletions

View File

@@ -13,4 +13,5 @@ public class PlayerPerformanceConfig : ILightlessConfiguration
public int VRAMSizeAutoPauseThresholdMiB { get; set; } = 550; public int VRAMSizeAutoPauseThresholdMiB { get; set; } = 550;
public int TrisAutoPauseThresholdThousands { get; set; } = 250; public int TrisAutoPauseThresholdThousands { get; set; } = 250;
public List<string> UIDsToIgnore { get; set; } = new(); public List<string> UIDsToIgnore { get; set; } = new();
public bool PauseInInstanceDuty { get; set; } = false;
} }

View File

@@ -90,18 +90,20 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
}); });
Mediator.Subscribe<CombatOrPerformanceEndMessage>(this, (msg) => Mediator.Subscribe<CombatOrPerformanceEndMessage>(this, (msg) =>
{ {
if (IsVisible && _dataReceivedInDowntime != null) EnableSync();
{
ApplyCharacterData(_dataReceivedInDowntime.ApplicationId,
_dataReceivedInDowntime.CharacterData, _dataReceivedInDowntime.Forced);
_dataReceivedInDowntime = null;
}
}); });
Mediator.Subscribe<CombatOrPerformanceStartMessage>(this, _ => Mediator.Subscribe<CombatOrPerformanceStartMessage>(this, _ =>
{ {
_dataReceivedInDowntime = null; DisableSync();
_downloadCancellationTokenSource = _downloadCancellationTokenSource?.CancelRecreate(); });
_applicationCancellationTokenSource = _applicationCancellationTokenSource?.CancelRecreate(); Mediator.Subscribe<InstanceOrDutyStartMessage>(this, _ =>
{
DisableSync();
});
Mediator.Subscribe<InstanceOrDutyEndMessage>(this, (msg) =>
{
EnableSync();
}); });
LastAppliedDataBytes = -1; LastAppliedDataBytes = -1;
@@ -145,6 +147,16 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
return; return;
} }
if (_dalamudUtil.IsInInstance)
{
Mediator.Publish(new EventMessage(new Event(PlayerName, Pair.UserData, nameof(PairHandler), EventSeverity.Warning,
"Cannot apply character data: you are in an instance, deferring application")));
Logger.LogDebug("[BASE-{appBase}] Received data but player is in instance", applicationBase);
_dataReceivedInDowntime = new(applicationBase, characterData, forceApplyCustomization);
SetUploading(isUploading: false);
return;
}
if (_charaHandler == null || (PlayerCharacter == IntPtr.Zero)) if (_charaHandler == null || (PlayerCharacter == IntPtr.Zero))
{ {
Mediator.Publish(new EventMessage(new Event(PlayerName, Pair.UserData, nameof(PairHandler), EventSeverity.Warning, Mediator.Publish(new EventMessage(new Event(PlayerName, Pair.UserData, nameof(PairHandler), EventSeverity.Warning,
@@ -716,4 +728,21 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
Logger.LogDebug("[BASE-{appBase}] ModdedPaths calculated in {time}ms, missing files: {count}, total files: {total}", applicationBase, st.ElapsedMilliseconds, missingFiles.Count, moddedDictionary.Keys.Count); Logger.LogDebug("[BASE-{appBase}] ModdedPaths calculated in {time}ms, missing files: {count}, total files: {total}", applicationBase, st.ElapsedMilliseconds, missingFiles.Count, moddedDictionary.Keys.Count);
return [.. missingFiles]; return [.. missingFiles];
} }
private void DisableSync()
{
_dataReceivedInDowntime = null;
_downloadCancellationTokenSource = _downloadCancellationTokenSource?.CancelRecreate();
_applicationCancellationTokenSource = _applicationCancellationTokenSource?.CancelRecreate();
}
private void EnableSync()
{
if (IsVisible && _dataReceivedInDowntime != null)
{
ApplyCharacterData(_dataReceivedInDowntime.ApplicationId,
_dataReceivedInDowntime.CharacterData, _dataReceivedInDowntime.Forced);
_dataReceivedInDowntime = null;
}
}
} }

View File

@@ -136,7 +136,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(), collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService<ILogger<DalamudUtilService>>(),
clientState, objectTable, framework, gameGui, condition, gameData, targetManager, gameConfig, clientState, objectTable, framework, gameGui, condition, gameData, targetManager, gameConfig,
s.GetRequiredService<BlockedCharacterHandler>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PerformanceCollectorService>(), s.GetRequiredService<BlockedCharacterHandler>(), s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PerformanceCollectorService>(),
s.GetRequiredService<LightlessConfigService>())); s.GetRequiredService<LightlessConfigService>(), s.GetRequiredService<PlayerPerformanceConfigService>()));
collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<LightlessConfigService>(), collection.AddSingleton((s) => new DtrEntry(s.GetRequiredService<ILogger<DtrEntry>>(), dtrBar, s.GetRequiredService<LightlessConfigService>(),
s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>())); s.GetRequiredService<LightlessMediator>(), s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));
collection.AddSingleton(s => new PairManager(s.GetRequiredService<ILogger<PairManager>>(), s.GetRequiredService<PairFactory>(), collection.AddSingleton(s => new PairManager(s.GetRequiredService<ILogger<PairManager>>(), s.GetRequiredService<PairFactory>(),

View File

@@ -39,6 +39,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
private readonly IObjectTable _objectTable; private readonly IObjectTable _objectTable;
private readonly PerformanceCollectorService _performanceCollector; private readonly PerformanceCollectorService _performanceCollector;
private readonly LightlessConfigService _configService; private readonly LightlessConfigService _configService;
private readonly PlayerPerformanceConfigService _playerPerformanceConfigService;
private uint? _classJobId = 0; private uint? _classJobId = 0;
private DateTime _delayedFrameworkUpdateCheck = DateTime.UtcNow; private DateTime _delayedFrameworkUpdateCheck = DateTime.UtcNow;
private string _lastGlobalBlockPlayer = string.Empty; private string _lastGlobalBlockPlayer = string.Empty;
@@ -52,7 +53,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework, public DalamudUtilService(ILogger<DalamudUtilService> logger, IClientState clientState, IObjectTable objectTable, IFramework framework,
IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameConfig gameConfig, IGameGui gameGui, ICondition condition, IDataManager gameData, ITargetManager targetManager, IGameConfig gameConfig,
BlockedCharacterHandler blockedCharacterHandler, LightlessMediator mediator, PerformanceCollectorService performanceCollector, BlockedCharacterHandler blockedCharacterHandler, LightlessMediator mediator, PerformanceCollectorService performanceCollector,
LightlessConfigService configService) LightlessConfigService configService, PlayerPerformanceConfigService playerPerformanceConfigService)
{ {
_logger = logger; _logger = logger;
_clientState = clientState; _clientState = clientState;
@@ -66,6 +67,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
Mediator = mediator; Mediator = mediator;
_performanceCollector = performanceCollector; _performanceCollector = performanceCollector;
_configService = configService; _configService = configService;
_playerPerformanceConfigService = playerPerformanceConfigService;
WorldData = new(() => WorldData = new(() =>
{ {
return gameData.GetExcelSheet<Lumina.Excel.Sheets.World>(Dalamud.Game.ClientLanguage.English)! return gameData.GetExcelSheet<Lumina.Excel.Sheets.World>(Dalamud.Game.ClientLanguage.English)!
@@ -161,6 +163,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
public bool IsOnFrameworkThread => _framework.IsInFrameworkUpdateThread; public bool IsOnFrameworkThread => _framework.IsInFrameworkUpdateThread;
public bool IsZoning => _condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51]; public bool IsZoning => _condition[ConditionFlag.BetweenAreas] || _condition[ConditionFlag.BetweenAreas51];
public bool IsInCombatOrPerforming { get; private set; } = false; public bool IsInCombatOrPerforming { get; private set; } = false;
public bool IsInInstance { get; private set; } = false;
public bool HasModifiedGameFiles => _gameData.HasModifiedGameDataFiles; public bool HasModifiedGameFiles => _gameData.HasModifiedGameDataFiles;
public uint ClassJobId => _classJobId!.Value; public uint ClassJobId => _classJobId!.Value;
public Lazy<Dictionary<uint, string>> JobData { get; private set; } public Lazy<Dictionary<uint, string>> JobData { get; private set; }
@@ -667,20 +670,34 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
Mediator.Publish(new GposeEndMessage()); Mediator.Publish(new GposeEndMessage());
} }
if ((_condition[ConditionFlag.Performing] || _condition[ConditionFlag.InCombat]) && !IsInCombatOrPerforming) if ((_condition[ConditionFlag.Performing] || _condition[ConditionFlag.InCombat]) && !IsInCombatOrPerforming && (_condition[ConditionFlag.BoundByDuty] && !_playerPerformanceConfigService.Current.PauseInInstanceDuty))
{ {
_logger.LogDebug("Combat/Performance start"); _logger.LogDebug("Combat/Performance start");
IsInCombatOrPerforming = true; IsInCombatOrPerforming = true;
Mediator.Publish(new CombatOrPerformanceStartMessage()); Mediator.Publish(new CombatOrPerformanceStartMessage());
Mediator.Publish(new HaltScanMessage(nameof(IsInCombatOrPerforming))); Mediator.Publish(new HaltScanMessage(nameof(IsInCombatOrPerforming)));
} }
else if ((!_condition[ConditionFlag.Performing] && !_condition[ConditionFlag.InCombat]) && IsInCombatOrPerforming) else if ((!_condition[ConditionFlag.Performing] && !_condition[ConditionFlag.InCombat]) && IsInCombatOrPerforming && (_condition[ConditionFlag.BoundByDuty] && !_playerPerformanceConfigService.Current.PauseInInstanceDuty))
{ {
_logger.LogDebug("Combat/Performance end"); _logger.LogDebug("Combat/Performance end");
IsInCombatOrPerforming = false; IsInCombatOrPerforming = false;
Mediator.Publish(new CombatOrPerformanceEndMessage()); Mediator.Publish(new CombatOrPerformanceEndMessage());
Mediator.Publish(new ResumeScanMessage(nameof(IsInCombatOrPerforming))); Mediator.Publish(new ResumeScanMessage(nameof(IsInCombatOrPerforming)));
} }
if ((_condition[ConditionFlag.BoundByDuty]) && !IsInInstance && _playerPerformanceConfigService.Current.PauseInInstanceDuty)
{
_logger.LogDebug("Instance start");
IsInInstance = true;
Mediator.Publish(new InstanceOrDutyStartMessage());
Mediator.Publish(new HaltScanMessage(nameof(IsInInstance)));
}
else if (((!_condition[ConditionFlag.BoundByDuty]) && IsInInstance && _playerPerformanceConfigService.Current.PauseInInstanceDuty) || ((_condition[ConditionFlag.BoundByDuty]) && IsInInstance && !_playerPerformanceConfigService.Current.PauseInInstanceDuty))
{
_logger.LogDebug("Instance end");
IsInInstance = false;
Mediator.Publish(new InstanceOrDutyEndMessage());
Mediator.Publish(new ResumeScanMessage(nameof(IsInInstance)));
}
if (_condition[ConditionFlag.WatchingCutscene] && !IsInCutscene) if (_condition[ConditionFlag.WatchingCutscene] && !IsInCutscene)
{ {

View File

@@ -81,6 +81,8 @@ public record CensusUpdateMessage(byte Gender, byte RaceId, byte TribeId) : Mess
public record TargetPairMessage(Pair Pair) : MessageBase; public record TargetPairMessage(Pair Pair) : MessageBase;
public record CombatOrPerformanceStartMessage : MessageBase; public record CombatOrPerformanceStartMessage : MessageBase;
public record CombatOrPerformanceEndMessage : MessageBase; public record CombatOrPerformanceEndMessage : MessageBase;
public record InstanceOrDutyStartMessage : MessageBase;
public record InstanceOrDutyEndMessage : MessageBase;
public record EventMessage(Event Event) : MessageBase; public record EventMessage(Event Event) : MessageBase;
public record PenumbraDirectoryChangedMessage(string? ModDirectory) : MessageBase; public record PenumbraDirectoryChangedMessage(string? ModDirectory) : MessageBase;
public record PenumbraRedrawCharacterMessage(ICharacter Character) : SameThreadMessage; public record PenumbraRedrawCharacterMessage(ICharacter Character) : SameThreadMessage;

View File

@@ -1318,9 +1318,18 @@ public class SettingsUi : WindowMediatorSubscriberBase
bool autoPause = _playerPerformanceConfigService.Current.AutoPausePlayersExceedingThresholds; bool autoPause = _playerPerformanceConfigService.Current.AutoPausePlayersExceedingThresholds;
bool autoPauseEveryone = _playerPerformanceConfigService.Current.AutoPausePlayersWithPreferredPermissionsExceedingThresholds; bool autoPauseEveryone = _playerPerformanceConfigService.Current.AutoPausePlayersWithPreferredPermissionsExceedingThresholds;
bool autoPauseInDuty = _playerPerformanceConfigService.Current.PauseInInstanceDuty;
if (_uiShared.MediumTreeNode("Auto Pause", UIColors.Get("LightlessPurple"))) if (_uiShared.MediumTreeNode("Auto Pause", UIColors.Get("LightlessPurple")))
{ {
if (ImGui.Checkbox("Auto pause sync while in instances and duties", ref autoPauseInDuty))
{
_playerPerformanceConfigService.Current.PauseInInstanceDuty = autoPauseInDuty;
_playerPerformanceConfigService.Save();
}
_uiShared.DrawHelpText("When enabled, it will automatically pause all players while you are in an instance, such as a dungeon or raid." + Environment.NewLine
+ UiSharedService.TooltipSeparator + "Warning: You many have to leave the dungeon to resync with people again");
if (ImGui.Checkbox("Automatically pause players exceeding thresholds", ref autoPause)) if (ImGui.Checkbox("Automatically pause players exceeding thresholds", ref autoPause))
{ {
_playerPerformanceConfigService.Current.AutoPausePlayersExceedingThresholds = autoPause; _playerPerformanceConfigService.Current.AutoPausePlayersExceedingThresholds = autoPause;