Fix warning
This commit is contained in:
@@ -17,8 +17,8 @@ namespace MareSynchronos.Interop;
|
||||
|
||||
public record ChatChannelOverride
|
||||
{
|
||||
public string ChannelName = string.Empty;
|
||||
public Action<byte[]>? ChatMessageHandler;
|
||||
public string ChannelName { get; set; } = string.Empty;
|
||||
public Action<byte[]>? ChatMessageHandler { get; set; }
|
||||
}
|
||||
|
||||
public unsafe sealed class GameChatHooks : IDisposable
|
||||
|
||||
@@ -31,11 +31,11 @@ public class MdlFile
|
||||
public ushort Unknown9;
|
||||
|
||||
// Offsets are stored relative to RuntimeSize instead of file start.
|
||||
public uint[] VertexOffset = [0, 0, 0];
|
||||
public uint[] IndexOffset = [0, 0, 0];
|
||||
public uint[] VertexOffset;
|
||||
public uint[] IndexOffset;
|
||||
|
||||
public uint[] VertexBufferSize = [0, 0, 0];
|
||||
public uint[] IndexBufferSize = [0, 0, 0];
|
||||
public uint[] VertexBufferSize;
|
||||
public uint[] IndexBufferSize;
|
||||
public byte LodCount;
|
||||
public bool EnableIndexBufferStreaming;
|
||||
public bool EnableEdgeGeometry;
|
||||
@@ -43,15 +43,26 @@ public class MdlFile
|
||||
public ModelFlags1 Flags1;
|
||||
public ModelFlags2 Flags2;
|
||||
|
||||
public VertexDeclarationStruct[] VertexDeclarations = [];
|
||||
public ElementIdStruct[] ElementIds = [];
|
||||
public MeshStruct[] Meshes = [];
|
||||
public BoundingBoxStruct[] BoneBoundingBoxes = [];
|
||||
public LodStruct[] Lods = [];
|
||||
public ExtraLodStruct[] ExtraLods = [];
|
||||
public VertexDeclarationStruct[] VertexDeclarations;
|
||||
public ElementIdStruct[] ElementIds;
|
||||
public MeshStruct[] Meshes;
|
||||
public BoundingBoxStruct[] BoneBoundingBoxes;
|
||||
public LodStruct[] Lods;
|
||||
public ExtraLodStruct[] ExtraLods;
|
||||
|
||||
public MdlFile(string filePath)
|
||||
{
|
||||
VertexOffset = Array.Empty<uint>();
|
||||
IndexOffset = Array.Empty<uint>();
|
||||
VertexBufferSize = Array.Empty<uint>();
|
||||
IndexBufferSize = Array.Empty<uint>();
|
||||
VertexDeclarations = Array.Empty<VertexDeclarationStruct>();
|
||||
ElementIds = Array.Empty<ElementIdStruct>();
|
||||
Meshes = Array.Empty<MeshStruct>();
|
||||
BoneBoundingBoxes = Array.Empty<BoundingBoxStruct>();
|
||||
Lods = Array.Empty<LodStruct>();
|
||||
ExtraLods = Array.Empty<ExtraLodStruct>();
|
||||
|
||||
using var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
|
||||
using var r = new LuminaBinaryReader(stream);
|
||||
|
||||
@@ -256,4 +267,4 @@ public class MdlFile
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore S1104 // Fields should not have public accessibility
|
||||
#pragma warning restore S1104 // Fields should not have public accessibility
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using System;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Ipc;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
@@ -29,7 +30,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
private bool _marePluginEnabled = false;
|
||||
private bool _impersonating = false;
|
||||
private DateTime _unregisterTime = DateTime.UtcNow;
|
||||
private CancellationTokenSource _registerDelayCts = new();
|
||||
private CancellationTokenSource? _registerDelayCts = new();
|
||||
|
||||
public bool MarePluginEnabled => _marePluginEnabled;
|
||||
public bool ImpersonationActive => _impersonating;
|
||||
@@ -100,7 +101,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
{
|
||||
if (_mareConfig.Current.MareAPI)
|
||||
{
|
||||
var cancelToken = _registerDelayCts.Token;
|
||||
var cancelToken = EnsureFreshCts(ref _registerDelayCts).Token;
|
||||
Task.Run(async () =>
|
||||
{
|
||||
// Wait before registering to reduce the chance of a race condition
|
||||
@@ -125,7 +126,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
}
|
||||
else
|
||||
{
|
||||
_registerDelayCts = _registerDelayCts.CancelRecreate();
|
||||
EnsureFreshCts(ref _registerDelayCts);
|
||||
if (_impersonating)
|
||||
{
|
||||
_loadFileProviderMare?.UnregisterFunc();
|
||||
@@ -146,7 +147,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
_loadFileAsyncProvider?.UnregisterFunc();
|
||||
_handledGameAddresses?.UnregisterFunc();
|
||||
|
||||
_registerDelayCts.Cancel();
|
||||
TryCancel(_registerDelayCts);
|
||||
if (_impersonating)
|
||||
{
|
||||
_loadFileProviderMare?.UnregisterFunc();
|
||||
@@ -155,6 +156,7 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
}
|
||||
|
||||
Mediator.UnsubscribeAll(this);
|
||||
CancelAndDispose(ref _registerDelayCts);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -193,4 +195,31 @@ public class IpcProvider : IHostedService, IMediatorSubscriber
|
||||
|
||||
return _activeGameObjectHandlers.Where(g => g.Address != nint.Zero).Select(g => g.Address).Distinct().ToList();
|
||||
}
|
||||
|
||||
private static CancellationTokenSource EnsureFreshCts(ref CancellationTokenSource? cts)
|
||||
{
|
||||
CancelAndDispose(ref cts);
|
||||
cts = new CancellationTokenSource();
|
||||
return cts;
|
||||
}
|
||||
|
||||
private static void CancelAndDispose(ref CancellationTokenSource? cts)
|
||||
{
|
||||
if (cts == null) return;
|
||||
TryCancel(cts);
|
||||
cts.Dispose();
|
||||
cts = null;
|
||||
}
|
||||
|
||||
private static void TryCancel(CancellationTokenSource? cts)
|
||||
{
|
||||
if (cts == null) return;
|
||||
try
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using System;
|
||||
using MareSynchronos.PlayerData.Handlers;
|
||||
using MareSynchronos.Services;
|
||||
using MareSynchronos.Services.Mediator;
|
||||
using MareSynchronos.Utils;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace MareSynchronos.Interop.Ipc;
|
||||
|
||||
public class RedrawManager
|
||||
public class RedrawManager : IDisposable
|
||||
{
|
||||
private readonly MareMediator _mareMediator;
|
||||
private readonly DalamudUtilService _dalamudUtil;
|
||||
private readonly ConcurrentDictionary<nint, bool> _penumbraRedrawRequests = [];
|
||||
private CancellationTokenSource _disposalCts = new();
|
||||
private CancellationTokenSource? _disposalCts = new();
|
||||
private bool _disposed;
|
||||
|
||||
public SemaphoreSlim RedrawSemaphore { get; init; } = new(2, 2);
|
||||
|
||||
@@ -32,12 +33,12 @@ public class RedrawManager
|
||||
try
|
||||
{
|
||||
using CancellationTokenSource cancelToken = new CancellationTokenSource();
|
||||
using CancellationTokenSource combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancelToken.Token, token, _disposalCts.Token);
|
||||
using CancellationTokenSource combinedCts = CancellationTokenSource.CreateLinkedTokenSource(cancelToken.Token, token, EnsureFreshCts(ref _disposalCts).Token);
|
||||
var combinedToken = combinedCts.Token;
|
||||
cancelToken.CancelAfter(TimeSpan.FromSeconds(15));
|
||||
await handler.ActOnFrameworkAfterEnsureNoDrawAsync(action, combinedToken).ConfigureAwait(false);
|
||||
|
||||
if (!_disposalCts.Token.IsCancellationRequested)
|
||||
if (!_disposalCts!.Token.IsCancellationRequested)
|
||||
await _dalamudUtil.WaitWhileCharacterIsDrawing(logger, handler, applicationId, 30000, combinedToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
@@ -49,6 +50,45 @@ public class RedrawManager
|
||||
|
||||
internal void Cancel()
|
||||
{
|
||||
_disposalCts = _disposalCts.CancelRecreate();
|
||||
EnsureFreshCts(ref _disposalCts);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed) return;
|
||||
if (disposing)
|
||||
{
|
||||
CancelAndDispose(ref _disposalCts);
|
||||
}
|
||||
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
private static CancellationTokenSource EnsureFreshCts(ref CancellationTokenSource? cts)
|
||||
{
|
||||
CancelAndDispose(ref cts);
|
||||
cts = new CancellationTokenSource();
|
||||
return cts;
|
||||
}
|
||||
|
||||
private static void CancelAndDispose(ref CancellationTokenSource? cts)
|
||||
{
|
||||
if (cts == null) return;
|
||||
try
|
||||
{
|
||||
cts.Cancel();
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
}
|
||||
|
||||
cts.Dispose();
|
||||
cts = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user