clean up some stuff
This commit is contained in:
@@ -246,7 +246,7 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase
|
|||||||
|
|
||||||
private void DalamudUtil_FrameworkUpdate()
|
private void DalamudUtil_FrameworkUpdate()
|
||||||
{
|
{
|
||||||
_cachedFrameAddresses = _cachedFrameAddresses = new(_playerRelatedPointers.Where(k => k.Address != nint.Zero).ToDictionary(c => c.CurrentAddress(), c => c.ObjectKind));
|
_cachedFrameAddresses = new(_playerRelatedPointers.Where(k => k.Address != nint.Zero).ToDictionary(c => c.Address, c => c.ObjectKind));
|
||||||
lock (_cacheAdditionLock)
|
lock (_cacheAdditionLock)
|
||||||
{
|
{
|
||||||
_cachedHandledPaths.Clear();
|
_cachedHandledPaths.Clear();
|
||||||
|
|||||||
@@ -9,16 +9,15 @@ using ObjectKind = MareSynchronos.API.Data.Enum.ObjectKind;
|
|||||||
|
|
||||||
namespace MareSynchronos.PlayerData.Handlers;
|
namespace MareSynchronos.PlayerData.Handlers;
|
||||||
|
|
||||||
public sealed class GameObjectHandler : DisposableMediatorSubscriberBase
|
public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighPriorityMediatorSubscriber
|
||||||
{
|
{
|
||||||
private readonly DalamudUtilService _dalamudUtil;
|
private readonly DalamudUtilService _dalamudUtil;
|
||||||
private readonly Func<IntPtr> _getAddress;
|
private readonly Func<IntPtr> _getAddress;
|
||||||
private readonly bool _isOwnedObject;
|
private readonly bool _isOwnedObject;
|
||||||
private readonly PerformanceCollectorService _performanceCollector;
|
private readonly PerformanceCollectorService _performanceCollector;
|
||||||
|
private byte _classJob = 0;
|
||||||
private Task? _delayedZoningTask;
|
private Task? _delayedZoningTask;
|
||||||
private bool _haltProcessing = false;
|
private bool _haltProcessing = false;
|
||||||
private int _ptrNullCounter = 0;
|
|
||||||
private byte _classJob = 0;
|
|
||||||
private CancellationTokenSource _zoningCts = new();
|
private CancellationTokenSource _zoningCts = new();
|
||||||
|
|
||||||
public GameObjectHandler(ILogger<GameObjectHandler> logger, PerformanceCollectorService performanceCollector,
|
public GameObjectHandler(ILogger<GameObjectHandler> logger, PerformanceCollectorService performanceCollector,
|
||||||
@@ -91,21 +90,19 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase
|
|||||||
ModelFilesInSlotLoaded
|
ModelFilesInSlotLoaded
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte RaceId { get; private set; }
|
|
||||||
public byte Gender { get; private set; }
|
|
||||||
public byte TribeId { get; private set; }
|
|
||||||
|
|
||||||
public IntPtr Address { get; private set; }
|
public IntPtr Address { get; private set; }
|
||||||
|
public DrawCondition CurrentDrawCondition { get; set; } = DrawCondition.None;
|
||||||
|
public byte Gender { get; private set; }
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
public ObjectKind ObjectKind { get; }
|
public ObjectKind ObjectKind { get; }
|
||||||
|
public byte RaceId { get; private set; }
|
||||||
|
public byte TribeId { get; private set; }
|
||||||
private byte[] CustomizeData { get; set; } = new byte[26];
|
private byte[] CustomizeData { get; set; } = new byte[26];
|
||||||
private IntPtr DrawObjectAddress { get; set; }
|
private IntPtr DrawObjectAddress { get; set; }
|
||||||
private byte[] EquipSlotData { get; set; } = new byte[40];
|
private byte[] EquipSlotData { get; set; } = new byte[40];
|
||||||
private ushort[] MainHandData { get; set; } = new ushort[3];
|
private ushort[] MainHandData { get; set; } = new ushort[3];
|
||||||
private ushort[] OffHandData { get; set; } = new ushort[3];
|
private ushort[] OffHandData { get; set; } = new ushort[3];
|
||||||
|
|
||||||
public DrawCondition CurrentDrawCondition { get; set; } = DrawCondition.None;
|
|
||||||
|
|
||||||
public async Task ActOnFrameworkAfterEnsureNoDrawAsync(Action<Dalamud.Game.ClientState.Objects.Types.ICharacter> act, CancellationToken token)
|
public async Task ActOnFrameworkAfterEnsureNoDrawAsync(Action<Dalamud.Game.ClientState.Objects.Types.ICharacter> act, CancellationToken token)
|
||||||
{
|
{
|
||||||
while (await _dalamudUtil.RunOnFrameworkThread(() =>
|
while (await _dalamudUtil.RunOnFrameworkThread(() =>
|
||||||
@@ -135,12 +132,6 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntPtr CurrentAddress()
|
|
||||||
{
|
|
||||||
_dalamudUtil.EnsureIsOnFramework();
|
|
||||||
return _getAddress.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dalamud.Game.ClientState.Objects.Types.IGameObject? GetGameObject()
|
public Dalamud.Game.ClientState.Objects.Types.IGameObject? GetGameObject()
|
||||||
{
|
{
|
||||||
return _dalamudUtil.CreateGameObject(Address);
|
return _dalamudUtil.CreateGameObject(Address);
|
||||||
@@ -179,7 +170,6 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase
|
|||||||
Address = _getAddress();
|
Address = _getAddress();
|
||||||
if (Address != IntPtr.Zero)
|
if (Address != IntPtr.Zero)
|
||||||
{
|
{
|
||||||
_ptrNullCounter = 0;
|
|
||||||
var drawObjAddr = (IntPtr)((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Address)->DrawObject;
|
var drawObjAddr = (IntPtr)((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Address)->DrawObject;
|
||||||
DrawObjectAddress = drawObjAddr;
|
DrawObjectAddress = drawObjAddr;
|
||||||
CurrentDrawCondition = DrawCondition.None;
|
CurrentDrawCondition = DrawCondition.None;
|
||||||
@@ -363,38 +353,15 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unsafe IntPtr GetDrawObjUnsafe(nint curPtr)
|
private bool IsBeingDrawn()
|
||||||
{
|
{
|
||||||
return (IntPtr)((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)curPtr)->DrawObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsBeingDrawn()
|
|
||||||
{
|
|
||||||
var curPtr = _getAddress();
|
|
||||||
Logger.LogTrace("[{this}] IsBeingDrawn, CurPtr: {ptr}", this, curPtr.ToString("X"));
|
|
||||||
|
|
||||||
if (curPtr == IntPtr.Zero && _ptrNullCounter < 2)
|
|
||||||
{
|
|
||||||
Logger.LogTrace("[{this}] IsBeingDrawn, CurPtr is ZERO, counter is {cnt}", this, _ptrNullCounter);
|
|
||||||
_ptrNullCounter++;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curPtr == IntPtr.Zero)
|
|
||||||
{
|
|
||||||
Logger.LogTrace("[{this}] IsBeingDrawn, CurPtr is ZERO, returning", this);
|
|
||||||
|
|
||||||
Address = IntPtr.Zero;
|
|
||||||
DrawObjectAddress = IntPtr.Zero;
|
|
||||||
throw new ArgumentNullException($"CurPtr for {this} turned ZERO");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_dalamudUtil.IsAnythingDrawing)
|
if (_dalamudUtil.IsAnythingDrawing)
|
||||||
{
|
{
|
||||||
Logger.LogTrace("[{this}] IsBeingDrawn, Global draw block", this);
|
Logger.LogTrace("[{this}] IsBeingDrawn, Global draw block", this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger.LogTrace("[{this}] IsBeingDrawn, Condition: {cond}", this, CurrentDrawCondition);
|
||||||
return CurrentDrawCondition != DrawCondition.None;
|
return CurrentDrawCondition != DrawCondition.None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
private readonly SemaphoreSlim _cacheCreateLock = new(1);
|
private readonly SemaphoreSlim _cacheCreateLock = new(1);
|
||||||
private readonly HashSet<ObjectKind> _cachesToCreate = [];
|
private readonly HashSet<ObjectKind> _cachesToCreate = [];
|
||||||
private readonly PlayerDataFactory _characterDataFactory;
|
private readonly PlayerDataFactory _characterDataFactory;
|
||||||
private readonly CancellationTokenSource _runtimeCts = new();
|
private readonly HashSet<ObjectKind> _currentlyCreating = [];
|
||||||
|
private readonly HashSet<ObjectKind> _debouncedObjectCache = [];
|
||||||
private readonly CharacterData _playerData = new();
|
private readonly CharacterData _playerData = new();
|
||||||
private readonly Dictionary<ObjectKind, GameObjectHandler> _playerRelatedObjects = [];
|
private readonly Dictionary<ObjectKind, GameObjectHandler> _playerRelatedObjects = [];
|
||||||
|
private readonly CancellationTokenSource _runtimeCts = new();
|
||||||
|
private CancellationTokenSource _creationCts = new();
|
||||||
private CancellationTokenSource _debounceCts = new();
|
private CancellationTokenSource _debounceCts = new();
|
||||||
private readonly HashSet<ObjectKind> _debouncedObjectCache = [];
|
|
||||||
private bool _isZoning = false;
|
|
||||||
private bool _haltCharaDataCreation;
|
private bool _haltCharaDataCreation;
|
||||||
|
private bool _isZoning = false;
|
||||||
|
|
||||||
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, GameObjectHandlerFactory gameObjectHandlerFactory,
|
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, GameObjectHandlerFactory gameObjectHandlerFactory,
|
||||||
PlayerDataFactory characterDataFactory, DalamudUtilService dalamudUtil) : base(logger, mediator)
|
PlayerDataFactory characterDataFactory, DalamudUtilService dalamudUtil) : base(logger, mediator)
|
||||||
@@ -103,7 +105,6 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
Logger.LogDebug("Received Moodles change, updating player");
|
Logger.LogDebug("Received Moodles change, updating player");
|
||||||
AddCacheToCreate(ObjectKind.Player);
|
AddCacheToCreate(ObjectKind.Player);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -153,7 +154,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
_ = Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromSeconds(1), token).ConfigureAwait(false);
|
await Task.Delay(TimeSpan.FromSeconds(1), token).ConfigureAwait(false);
|
||||||
Logger.LogWarning("Debounce complete, inserting objects to create for: {obj}", string.Join(", ", _debouncedObjectCache));
|
Logger.LogTrace("Debounce complete, inserting objects to create for: {obj}", string.Join(", ", _debouncedObjectCache));
|
||||||
await _cacheCreateLock.WaitAsync(token).ConfigureAwait(false);
|
await _cacheCreateLock.WaitAsync(token).ConfigureAwait(false);
|
||||||
foreach (var item in _debouncedObjectCache)
|
foreach (var item in _debouncedObjectCache)
|
||||||
{
|
{
|
||||||
@@ -164,9 +165,6 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HashSet<ObjectKind> _currentlyCreating = [];
|
|
||||||
private CancellationTokenSource _creationCts = new();
|
|
||||||
|
|
||||||
private void ProcessCacheCreation()
|
private void ProcessCacheCreation()
|
||||||
{
|
{
|
||||||
if (_isZoning || _haltCharaDataCreation) return;
|
if (_isZoning || _haltCharaDataCreation) return;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace MareSynchronos.Services.Mediator;
|
||||||
|
|
||||||
|
public interface IHighPriorityMediatorSubscriber : IMediatorSubscriber { }
|
||||||
@@ -92,6 +92,7 @@ public sealed class MareMediator : IHostedService
|
|||||||
{
|
{
|
||||||
_messageQueue.Clear();
|
_messageQueue.Clear();
|
||||||
_loopCts.Cancel();
|
_loopCts.Cancel();
|
||||||
|
_loopCts.Dispose();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +106,6 @@ public sealed class MareMediator : IHostedService
|
|||||||
{
|
{
|
||||||
throw new InvalidOperationException("Already subscribed");
|
throw new InvalidOperationException("Already subscribed");
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogDebug("Subscriber added for message {message}: {sub}", typeof(T).Name, subscriber.GetType().Name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +142,7 @@ public sealed class MareMediator : IHostedService
|
|||||||
List<SubscriberAction> subscribersCopy = [];
|
List<SubscriberAction> subscribersCopy = [];
|
||||||
lock (_addRemoveLock)
|
lock (_addRemoveLock)
|
||||||
{
|
{
|
||||||
subscribersCopy = subscribers?.Where(s => s.Subscriber != null).ToList() ?? [];
|
subscribersCopy = subscribers?.Where(s => s.Subscriber != null).OrderBy(k => k.Subscriber is IHighPriorityMediatorSubscriber ? 0 : 1).ToList() ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
#pragma warning disable S3011 // Reflection should not be used to increase accessibility of classes, methods, or fields
|
||||||
@@ -151,7 +150,7 @@ public sealed class MareMediator : IHostedService
|
|||||||
if (!_genericExecuteMethods.TryGetValue(msgType, out var methodInfo))
|
if (!_genericExecuteMethods.TryGetValue(msgType, out var methodInfo))
|
||||||
{
|
{
|
||||||
_genericExecuteMethods[msgType] = methodInfo = GetType()
|
_genericExecuteMethods[msgType] = methodInfo = GetType()
|
||||||
.GetMethod(nameof(ExecuteReflected), System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)?
|
.GetMethod(nameof(ExecuteReflected), BindingFlags.NonPublic | BindingFlags.Instance)?
|
||||||
.MakeGenericMethod(msgType);
|
.MakeGenericMethod(msgType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -268,18 +268,24 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
NotificationType.Error, TimeSpan.FromSeconds(15)));
|
NotificationType.Error, TimeSpan.FromSeconds(15)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_dalamudUtil.IsLodEnabled)
|
if (_dalamudUtil.IsLodEnabled && !_naggedAboutLod)
|
||||||
{
|
{
|
||||||
|
_naggedAboutLod = true;
|
||||||
Logger.LogWarning("Model LOD is enabled during connection");
|
Logger.LogWarning("Model LOD is enabled during connection");
|
||||||
if (!_mareConfigService.Current.DebugStopWhining)
|
if (!_mareConfigService.Current.DebugStopWhining)
|
||||||
{
|
{
|
||||||
Mediator.Publish(new NotificationMessage("Model LOD is enabled",
|
Mediator.Publish(new NotificationMessage("Model LOD is enabled",
|
||||||
"You have \"Use low-detail models on distant objects (LOD)\" enabled. Having model LOD enabled is known to be a reason to cause " +
|
"You have \"Use low-detail models on distant objects (LOD)\" enabled. Having model LOD enabled is known to be a reason to cause " +
|
||||||
"random crashes when loading in or rendering modded pairs. Disable LOD while using Mare: " +
|
"random crashes when loading in or rendering modded pairs. Disabling LOD has a very low performance impact. Disable LOD while using Mare: " +
|
||||||
"Go to XIV Menu -> System Configuration -> Graphics Settings and disable the model LOD option.", NotificationType.Warning, TimeSpan.FromSeconds(15)));
|
"Go to XIV Menu -> System Configuration -> Graphics Settings and disable the model LOD option.", NotificationType.Warning, TimeSpan.FromSeconds(15)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_naggedAboutLod && !_dalamudUtil.IsLodEnabled)
|
||||||
|
{
|
||||||
|
_naggedAboutLod = false;
|
||||||
|
}
|
||||||
|
|
||||||
await LoadIninitialPairsAsync().ConfigureAwait(false);
|
await LoadIninitialPairsAsync().ConfigureAwait(false);
|
||||||
await LoadOnlinePairsAsync().ConfigureAwait(false);
|
await LoadOnlinePairsAsync().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
@@ -318,6 +324,8 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _naggedAboutLod = false;
|
||||||
|
|
||||||
public Task CyclePauseAsync(UserData userData)
|
public Task CyclePauseAsync(UserData userData)
|
||||||
{
|
{
|
||||||
CancellationTokenSource cts = new();
|
CancellationTokenSource cts = new();
|
||||||
@@ -533,8 +541,6 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
|
|
||||||
private async Task<bool> RefreshTokenAsync(CancellationToken ct)
|
private async Task<bool> RefreshTokenAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Checking token");
|
|
||||||
|
|
||||||
bool requireReconnect = false;
|
bool requireReconnect = false;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -222,7 +222,6 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber
|
|||||||
var jwt = handler.ReadJwtToken(token);
|
var jwt = handler.ReadJwtToken(token);
|
||||||
if (jwt.ValidTo == DateTime.MinValue || jwt.ValidTo.Subtract(TimeSpan.FromMinutes(5)) > DateTime.UtcNow)
|
if (jwt.ValidTo == DateTime.MinValue || jwt.ValidTo.Subtract(TimeSpan.FromMinutes(5)) > DateTime.UtcNow)
|
||||||
{
|
{
|
||||||
_logger.LogTrace("GetOrUpdate: Returning token from cache");
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user