listen to glamourer changes

This commit is contained in:
rootdarkarchon
2024-01-13 00:00:52 +01:00
committed by Loporrit
parent 06f6b75e72
commit 0cd953f514
4 changed files with 37 additions and 1 deletions

View File

@@ -114,6 +114,8 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
_glamourerRevertByName = pi.GetIpcSubscriber<string, uint, object?>("Glamourer.RevertLock");
_glamourerUnlock = pi.GetIpcSubscriber<string, uint, bool>("Glamourer.UnlockName");
pi.GetIpcSubscriber<int, nint, Lazy<string>, object?>("Glamourer.StateChanged").Subscribe((type, address, customize) => GlamourerChanged(address));
_heelsGetApiVersion = pi.GetIpcSubscriber<(int, int)>("SimpleHeels.ApiVersion");
_heelsGetOffset = pi.GetIpcSubscriber<string>("SimpleHeels.GetLocalPlayer");
_heelsRegisterPlayer = pi.GetIpcSubscriber<GameObject, string, object?>("SimpleHeels.RegisterPlayer");
@@ -755,6 +757,11 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
return _penumbraResolveModDir!.Invoke().ToLowerInvariant();
}
private void GlamourerChanged(nint address)
{
Mediator.Publish(new GlamourerChangedMessage(address));
}
private void HeelsOffsetChange(string offset)
{
Mediator.Publish(new HeelsOffsetMessage());

View File

@@ -22,6 +22,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
private CancellationTokenSource _honorificCts = new();
private bool _isZoning = false;
private CancellationTokenSource _palettePlusCts = new();
private readonly Dictionary<ObjectKind, CancellationTokenSource> _glamourerCts = new();
public CacheCreationService(ILogger<CacheCreationService> logger, MareMediator mediator, GameObjectHandlerFactory gameObjectHandlerFactory,
PlayerDataFactory characterDataFactory, DalamudUtilService dalamudUtil) : base(logger, mediator)
@@ -90,6 +91,15 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
Logger.LogDebug("Received Heels Offset change, updating player");
await AddPlayerCacheToCreate().ConfigureAwait(false);
});
Mediator.Subscribe<GlamourerChangedMessage>(this, async (msg) =>
{
if (_isZoning) return;
var changedType = _playerRelatedObjects.FirstOrDefault(f => f.Value.Address == msg.Address);
if (!default(KeyValuePair<ObjectKind, GameObjectHandler>).Equals(changedType))
{
GlamourerChanged(changedType.Key);
}
});
Mediator.Subscribe<PalettePlusMessage>(this, (msg) =>
{
if (_isZoning) return;
@@ -132,6 +142,23 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
_cacheCreateLock.Release();
}
private void GlamourerChanged(ObjectKind kind)
{
if (_glamourerCts.TryGetValue(kind, out var cts))
{
_glamourerCts[kind]?.Cancel();
_glamourerCts[kind]?.Dispose();
}
_glamourerCts[kind] = new();
var token = _glamourerCts[kind].Token;
_ = Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(1), token).ConfigureAwait(false);
await AddPlayerCacheToCreate(kind).ConfigureAwait(false);
});
}
private void HonorificChanged()
{
_honorificCts?.Cancel();

View File

@@ -80,7 +80,8 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<FileDownloadManagerFactory>();
collection.AddSingleton((s) => new PairHandlerFactory(s.GetRequiredService<ILoggerFactory>(), s.GetRequiredService<GameObjectHandlerFactory>(),
s.GetRequiredService<IpcManager>(), s.GetRequiredService<FileDownloadManagerFactory>(), s.GetRequiredService<DalamudUtilService>(),
s.GetRequiredService<PluginWarningNotificationService>(), CancellationTokenSource.CreateLinkedTokenSource(addonLifecycle.GameShuttingDownToken, addonLifecycle.DalamudUnloadingToken).Token,
s.GetRequiredService<PluginWarningNotificationService>(),
CancellationTokenSource.CreateLinkedTokenSource(addonLifecycle.GameShuttingDownToken, addonLifecycle.DalamudUnloadingToken).Token,
s.GetRequiredService<FileCacheManager>(), s.GetRequiredService<MareMediator>()));
collection.AddSingleton<PairFactory>();
collection.AddSingleton<CharacterAnalyzer>();

View File

@@ -34,6 +34,7 @@ public record PenumbraModSettingChangedMessage : MessageBase;
public record PenumbraInitializedMessage : MessageBase;
public record PenumbraDisposedMessage : MessageBase;
public record PenumbraRedrawMessage(IntPtr Address, int ObjTblIdx, bool WasRequested) : SameThreadMessage;
public record GlamourerChangedMessage(IntPtr Address) : MessageBase;
public record HeelsOffsetMessage : MessageBase;
public record PenumbraResourceLoadMessage(IntPtr GameObject, string GamePath, string FilePath) : SameThreadMessage;
public record CustomizePlusMessage(string ProfileName) : MessageBase;