fix multiple redraws, fix wrong files being allowed to send

This commit is contained in:
rootdarkarchon
2023-10-05 23:53:48 +02:00
parent 2cb4e799ce
commit 1151d1bf2e
2 changed files with 14 additions and 28 deletions

View File

@@ -33,7 +33,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
private CancellationTokenSource? _downloadCancellationTokenSource = new();
private bool _forceApplyMods = false;
private string _penumbraCollection;
private CancellationTokenSource _redrawCts = new();
public PairHandler(ILogger<PairHandler> logger, OnlineUserIdentDto onlineUser,
GameObjectHandlerFactory gameObjectHandlerFactory,
@@ -210,6 +209,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
try
{
bool alreadyRedrawn = false;
if (handler.Address == nint.Zero)
{
return;
@@ -249,13 +249,18 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
case PlayerChanges.Glamourer:
if (charaData.GlamourerData.TryGetValue(changes.Key, out var glamourerData))
{
alreadyRedrawn = true;
await _ipcManager.GlamourerApplyAllAsync(Logger, handler, glamourerData, applicationId, token).ConfigureAwait(false);
}
break;
case PlayerChanges.ModFiles:
case PlayerChanges.ModManip:
await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false);
if (!alreadyRedrawn)
{
alreadyRedrawn = true;
await _ipcManager.PenumbraRedrawAsync(Logger, handler, applicationId, token).ConfigureAwait(false);
}
break;
}
token.ThrowIfCancellationRequested();
@@ -419,7 +424,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
else if (_charaHandler?.Address == nint.Zero && IsVisible)
{
IsVisible = false;
_charaHandler?.Invalidate();
_charaHandler.Invalidate();
_downloadCancellationTokenSource?.CancelDispose();
_downloadCancellationTokenSource = null;
Logger.LogTrace("{this} visibility changed, now: {visi}", this, IsVisible);
@@ -431,7 +436,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
PlayerName = name;
_charaHandler = _gameObjectHandlerFactory.Create(ObjectKind.Player, () => _dalamudUtil.GetPlayerCharacterFromCachedTableByIdent(OnlineUser.Ident), false).GetAwaiter().GetResult();
Mediator.Subscribe<PenumbraRedrawMessage>(this, IpcManagerOnPenumbraRedrawEvent);
Mediator.Subscribe<HonorificReadyMessage>(this, async (_) =>
{
if (string.IsNullOrEmpty(_cachedData?.HonorificData)) return;
@@ -442,28 +446,6 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
_ipcManager.PenumbraAssignTemporaryCollectionAsync(Logger, _penumbraCollection, _charaHandler.GetGameObject()!.ObjectIndex).GetAwaiter().GetResult();
}
private void IpcManagerOnPenumbraRedrawEvent(PenumbraRedrawMessage msg)
{
var player = _dalamudUtil.GetCharacterFromObjectTableByIndex(msg.ObjTblIdx);
if (player == null || !string.Equals(player.Name.ToString(), PlayerName, StringComparison.OrdinalIgnoreCase)) return;
_redrawCts = _redrawCts.CancelRecreate();
_redrawCts.CancelAfter(TimeSpan.FromSeconds(30));
var token = _redrawCts.Token;
_ = Task.Run(async () =>
{
var applicationId = Guid.NewGuid();
await _dalamudUtil.WaitWhileCharacterIsDrawing(Logger, _charaHandler!, applicationId, ct: token).ConfigureAwait(false);
Logger.LogDebug("Unauthorized character change detected");
if (_cachedData != null)
{
await ApplyCustomizationDataAsync(applicationId, new(ObjectKind.Player,
new HashSet<PlayerChanges>(new[] { PlayerChanges.Palette, PlayerChanges.Customize, PlayerChanges.Heels, PlayerChanges.Glamourer })),
_cachedData, token).ConfigureAwait(false);
}
}, token);
}
private async Task RevertCustomizationDataAsync(ObjectKind objectKind, string name, Guid applicationId)
{
nint address = _dalamudUtil.GetPlayerCharacterFromCachedTableByIdent(OnlineUser.Ident);
@@ -537,6 +519,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
moddedDictionary = new Dictionary<string, string>(StringComparer.Ordinal);
ConcurrentDictionary<string, string> outputDict = new(StringComparer.Ordinal);
bool hasMigrationChanges = false;
try
{
var replacementList = charaData.FileReplacements.SelectMany(k => k.Value.Where(v => string.IsNullOrEmpty(v.FileSwapPath))).ToList();