Pet Nicknames IPC implementation (#74)
* Pet Nicknames IPC implementation * Moodles works again
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
using Dalamud.Plugin;
|
using Dalamud.Game.ClientState.Objects.SubKinds;
|
||||||
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Ipc;
|
||||||
using MareSynchronos.Services;
|
using MareSynchronos.Services;
|
||||||
using MareSynchronos.Services.Mediator;
|
using MareSynchronos.Services.Mediator;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
@@ -11,6 +13,16 @@ public sealed class IpcCallerPetNames : IIpcCaller
|
|||||||
private readonly DalamudUtilService _dalamudUtil;
|
private readonly DalamudUtilService _dalamudUtil;
|
||||||
private readonly MareMediator _mareMediator;
|
private readonly MareMediator _mareMediator;
|
||||||
|
|
||||||
|
private readonly ICallGateSubscriber<object> _petnamesReady;
|
||||||
|
private readonly ICallGateSubscriber<object> _petnamesDisposing;
|
||||||
|
private readonly ICallGateSubscriber<(uint, uint)> _apiVersion;
|
||||||
|
private readonly ICallGateSubscriber<bool> _enabled;
|
||||||
|
|
||||||
|
private readonly ICallGateSubscriber<string, object> _playerDataChanged;
|
||||||
|
private readonly ICallGateSubscriber<string> _getPlayerData;
|
||||||
|
private readonly ICallGateSubscriber<string, object> _setPlayerData;
|
||||||
|
private readonly ICallGateSubscriber<ushort, object> _clearPlayerData;
|
||||||
|
|
||||||
public IpcCallerPetNames(ILogger<IpcCallerPetNames> logger, IDalamudPluginInterface pi, DalamudUtilService dalamudUtil,
|
public IpcCallerPetNames(ILogger<IpcCallerPetNames> logger, IDalamudPluginInterface pi, DalamudUtilService dalamudUtil,
|
||||||
MareMediator mareMediator)
|
MareMediator mareMediator)
|
||||||
{
|
{
|
||||||
@@ -18,18 +30,128 @@ public sealed class IpcCallerPetNames : IIpcCaller
|
|||||||
_dalamudUtil = dalamudUtil;
|
_dalamudUtil = dalamudUtil;
|
||||||
_mareMediator = mareMediator;
|
_mareMediator = mareMediator;
|
||||||
|
|
||||||
// todo: implement this, bitch, look at moodles as example implementation
|
_petnamesReady = pi.GetIpcSubscriber<object>("PetRenamer.Ready");
|
||||||
|
_petnamesDisposing = pi.GetIpcSubscriber<object>("PetRenamer.Disposing");
|
||||||
|
_apiVersion = pi.GetIpcSubscriber<(uint, uint)>("PetRenamer.ApiVersion");
|
||||||
|
_enabled = pi.GetIpcSubscriber<bool>("PetRenamer.Enabled");
|
||||||
|
|
||||||
|
_playerDataChanged = pi.GetIpcSubscriber<string, object>("PetRenamer.PlayerDataChanged");
|
||||||
|
_getPlayerData = pi.GetIpcSubscriber<string>("PetRenamer.GetPlayerData");
|
||||||
|
_setPlayerData = pi.GetIpcSubscriber<string, object>("PetRenamer.SetPlayerData");
|
||||||
|
_clearPlayerData = pi.GetIpcSubscriber<ushort, object>("PetRenamer.ClearPlayerData");
|
||||||
|
|
||||||
|
_petnamesReady.Subscribe(OnPetNicknamesReady);
|
||||||
|
_petnamesDisposing.Subscribe(OnPetNicknamesDispose);
|
||||||
|
_playerDataChanged.Subscribe(OnLocalPetNicknamesDataChange);
|
||||||
|
|
||||||
|
CheckAPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool APIAvailable => throw new NotImplementedException();
|
public bool APIAvailable { get; private set; } = false;
|
||||||
|
|
||||||
public void CheckAPI()
|
public void CheckAPI()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
try
|
||||||
|
{
|
||||||
|
APIAvailable = _enabled?.InvokeFunc() ?? false;
|
||||||
|
if (APIAvailable)
|
||||||
|
{
|
||||||
|
APIAvailable = _apiVersion?.InvokeFunc() is { Item1: 3, Item2: >= 1 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
APIAvailable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPetNicknamesReady()
|
||||||
|
{
|
||||||
|
CheckAPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnPetNicknamesDispose()
|
||||||
|
{
|
||||||
|
_mareMediator.Publish(new PetNamesMessage(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetLocalNames()
|
||||||
|
{
|
||||||
|
if (!APIAvailable) return string.Empty;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string localNameData = _getPlayerData.InvokeFunc();
|
||||||
|
return string.IsNullOrEmpty(localNameData) ? string.Empty : localNameData;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(e, "Could not obtain Pet Nicknames data");
|
||||||
|
}
|
||||||
|
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SetPlayerData(nint character, string playerData)
|
||||||
|
{
|
||||||
|
if (!APIAvailable) return;
|
||||||
|
|
||||||
|
_logger.LogTrace("Applying Pet Nicknames data to {chara}", character.ToString("X"));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _dalamudUtil.RunOnFrameworkThread(() =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(playerData))
|
||||||
|
{
|
||||||
|
var gameObj = _dalamudUtil.CreateGameObject(character);
|
||||||
|
if (gameObj is IPlayerCharacter pc)
|
||||||
|
{
|
||||||
|
_clearPlayerData.InvokeAction(pc.ObjectIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_setPlayerData.InvokeAction(playerData);
|
||||||
|
}
|
||||||
|
}).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(e, "Could not apply Pet Nicknames data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ClearPlayerData(nint characterPointer)
|
||||||
|
{
|
||||||
|
if (!APIAvailable) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _dalamudUtil.RunOnFrameworkThread(() =>
|
||||||
|
{
|
||||||
|
var gameObj = _dalamudUtil.CreateGameObject(characterPointer);
|
||||||
|
if (gameObj is IPlayerCharacter pc)
|
||||||
|
{
|
||||||
|
_logger.LogTrace("Pet Nicknames removing for {addr}", pc.Address.ToString("X"));
|
||||||
|
_clearPlayerData.InvokeAction(pc.ObjectIndex);
|
||||||
|
}
|
||||||
|
}).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(e, "Could not clear Pet Nicknames data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnLocalPetNicknamesDataChange(string data)
|
||||||
|
{
|
||||||
|
_mareMediator.Publish(new PetNamesMessage(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
_petnamesReady.Unsubscribe(OnPetNicknamesReady);
|
||||||
|
_petnamesDisposing.Unsubscribe(OnPetNicknamesDispose);
|
||||||
|
_playerDataChanged.Unsubscribe(OnLocalPetNicknamesDataChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -216,9 +216,11 @@ public class PlayerDataFactory
|
|||||||
_logger.LogDebug("Heels is now: {heels}", previousData.HeelsData);
|
_logger.LogDebug("Heels is now: {heels}", previousData.HeelsData);
|
||||||
if (objectKind == ObjectKind.Player)
|
if (objectKind == ObjectKind.Player)
|
||||||
{
|
{
|
||||||
// TODO: use petnames here and save it to moodles data for temporary transfer
|
|
||||||
previousData.MoodlesData = await _ipcManager.Moodles.GetStatusAsync(playerRelatedObject.Address).ConfigureAwait(false) ?? string.Empty;
|
previousData.MoodlesData = await _ipcManager.Moodles.GetStatusAsync(playerRelatedObject.Address).ConfigureAwait(false) ?? string.Empty;
|
||||||
_logger.LogDebug("Moodles is now: {moodles}", previousData.MoodlesData);
|
_logger.LogDebug("Moodles is now: {moodles}", previousData.MoodlesData);
|
||||||
|
|
||||||
|
previousData.MoodlesData = _ipcManager.PetNames.GetLocalNames();
|
||||||
|
_logger.LogDebug("Pet Nicknames is now: {moodles}", previousData.MoodlesData);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (previousData.FileReplacements.TryGetValue(objectKind, out HashSet<FileReplacement>? fileReplacements))
|
if (previousData.FileReplacements.TryGetValue(objectKind, out HashSet<FileReplacement>? fileReplacements))
|
||||||
|
|||||||
@@ -342,8 +342,9 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PlayerChanges.Moodles:
|
case PlayerChanges.Moodles:
|
||||||
// TODO: send it to petnames ipc here instead
|
|
||||||
await _ipcManager.Moodles.SetStatusAsync(handler.Address, charaData.MoodlesData).ConfigureAwait(false);
|
await _ipcManager.Moodles.SetStatusAsync(handler.Address, charaData.MoodlesData).ConfigureAwait(false);
|
||||||
|
|
||||||
|
await _ipcManager.PetNames.SetPlayerData(handler.Address, charaData.MoodlesData).ConfigureAwait(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PlayerChanges.ForcedRedraw:
|
case PlayerChanges.ForcedRedraw:
|
||||||
@@ -582,6 +583,8 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
|
|||||||
await _ipcManager.Honorific.ClearTitleAsync(address).ConfigureAwait(false);
|
await _ipcManager.Honorific.ClearTitleAsync(address).ConfigureAwait(false);
|
||||||
Logger.LogDebug("[{applicationId}] Restoring Moodles for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name);
|
Logger.LogDebug("[{applicationId}] Restoring Moodles for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name);
|
||||||
await _ipcManager.Moodles.RevertStatusAsync(address).ConfigureAwait(false);
|
await _ipcManager.Moodles.RevertStatusAsync(address).ConfigureAwait(false);
|
||||||
|
Logger.LogDebug("[{applicationId}] Restoring Pet Nicknames for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name);
|
||||||
|
await _ipcManager.PetNames.ClearPlayerData(address).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (objectKind == ObjectKind.MinionOrMount)
|
else if (objectKind == ObjectKind.MinionOrMount)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,4 +6,5 @@ public record OptionalPluginWarning
|
|||||||
public bool ShownCustomizePlusWarning { get; set; } = false;
|
public bool ShownCustomizePlusWarning { get; set; } = false;
|
||||||
public bool ShownHonorificWarning { get; set; } = false;
|
public bool ShownHonorificWarning { get; set; } = false;
|
||||||
public bool ShownMoodlesWarning { get; set; } = false;
|
public bool ShownMoodlesWarning { get; set; } = false;
|
||||||
|
public bool ShowPetNicknamesWarning { get; set; } = false;
|
||||||
}
|
}
|
||||||
@@ -21,6 +21,7 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
private Task? _cacheCreationTask;
|
private Task? _cacheCreationTask;
|
||||||
private CancellationTokenSource _honorificCts = new();
|
private CancellationTokenSource _honorificCts = new();
|
||||||
private CancellationTokenSource _moodlesCts = new();
|
private CancellationTokenSource _moodlesCts = new();
|
||||||
|
private CancellationTokenSource _petNicknamesCts = new();
|
||||||
private bool _isZoning = false;
|
private bool _isZoning = false;
|
||||||
private readonly Dictionary<ObjectKind, CancellationTokenSource> _glamourerCts = new();
|
private readonly Dictionary<ObjectKind, CancellationTokenSource> _glamourerCts = new();
|
||||||
|
|
||||||
@@ -122,9 +123,15 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
MoodlesChanged();
|
MoodlesChanged();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Mediator.Subscribe<PetNamesMessage>(this, (msg) =>
|
||||||
// TODO: if event is needed for petnames add it here similar to moodles
|
{
|
||||||
|
if (_isZoning) return;
|
||||||
|
if (!string.Equals(msg.PetNicknamesData, _playerData.MoodlesData, StringComparison.Ordinal))
|
||||||
|
{
|
||||||
|
Logger.LogDebug("Received Pet Nicknames change, updating player");
|
||||||
|
PetNicknamesChanged();
|
||||||
|
}
|
||||||
|
});
|
||||||
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, (msg) =>
|
Mediator.Subscribe<PenumbraModSettingChangedMessage>(this, (msg) =>
|
||||||
{
|
{
|
||||||
Logger.LogDebug("Received Penumbra Mod settings change, updating player");
|
Logger.LogDebug("Received Penumbra Mod settings change, updating player");
|
||||||
@@ -194,6 +201,20 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
|
|||||||
}, token);
|
}, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void PetNicknamesChanged()
|
||||||
|
{
|
||||||
|
_petNicknamesCts?.Cancel();
|
||||||
|
_petNicknamesCts?.Dispose();
|
||||||
|
_petNicknamesCts = new();
|
||||||
|
var token = _petNicknamesCts.Token;
|
||||||
|
|
||||||
|
_ = Task.Run(async () =>
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(3), token).ConfigureAwait(false);
|
||||||
|
await AddPlayerCacheToCreate().ConfigureAwait(false);
|
||||||
|
}, token);
|
||||||
|
}
|
||||||
|
|
||||||
private void ProcessCacheCreation()
|
private void ProcessCacheCreation()
|
||||||
{
|
{
|
||||||
if (_isZoning) return;
|
if (_isZoning) return;
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public record PenumbraResourceLoadMessage(IntPtr GameObject, string GamePath, st
|
|||||||
public record CustomizePlusMessage(string ProfileName) : MessageBase;
|
public record CustomizePlusMessage(string ProfileName) : MessageBase;
|
||||||
public record HonorificMessage(string NewHonorificTitle) : MessageBase;
|
public record HonorificMessage(string NewHonorificTitle) : MessageBase;
|
||||||
public record MoodlesMessage(IntPtr Address) : MessageBase;
|
public record MoodlesMessage(IntPtr Address) : MessageBase;
|
||||||
|
public record PetNamesMessage(string PetNicknamesData) : MessageBase;
|
||||||
public record HonorificReadyMessage : MessageBase;
|
public record HonorificReadyMessage : MessageBase;
|
||||||
public record PlayerChangedMessage(CharacterData Data) : MessageBase;
|
public record PlayerChangedMessage(CharacterData Data) : MessageBase;
|
||||||
public record CharacterChangedMessage(GameObjectHandler GameObjectHandler) : MessageBase;
|
public record CharacterChangedMessage(GameObjectHandler GameObjectHandler) : MessageBase;
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ public class PluginWarningNotificationService
|
|||||||
ShownCustomizePlusWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
ShownCustomizePlusWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
||||||
ShownHeelsWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
ShownHeelsWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
||||||
ShownHonorificWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
ShownHonorificWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
||||||
ShownMoodlesWarning = _mareConfigService.Current.DisableOptionalPluginWarnings
|
ShownMoodlesWarning = _mareConfigService.Current.DisableOptionalPluginWarnings,
|
||||||
|
ShowPetNicknamesWarning = _mareConfigService.Current.DisableOptionalPluginWarnings
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,13 +54,18 @@ public class PluginWarningNotificationService
|
|||||||
warning.ShownHonorificWarning = true;
|
warning.ShownHonorificWarning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: change the moodles apiavailable to petnames for testing
|
|
||||||
if (changes.Contains(PlayerChanges.Moodles) && !warning.ShownMoodlesWarning && !_ipcManager.Moodles.APIAvailable)
|
if (changes.Contains(PlayerChanges.Moodles) && !warning.ShownMoodlesWarning && !_ipcManager.Moodles.APIAvailable)
|
||||||
{
|
{
|
||||||
missingPluginsForData.Add("Moodles");
|
missingPluginsForData.Add("Moodles");
|
||||||
warning.ShownMoodlesWarning = true;
|
warning.ShownMoodlesWarning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (changes.Contains(PlayerChanges.Moodles) && !warning.ShowPetNicknamesWarning && !_ipcManager.PetNames.APIAvailable)
|
||||||
|
{
|
||||||
|
missingPluginsForData.Add("PetNicknames");
|
||||||
|
warning.ShowPetNicknamesWarning = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (missingPluginsForData.Any())
|
if (missingPluginsForData.Any())
|
||||||
{
|
{
|
||||||
_mediator.Publish(new NotificationMessage("Missing plugins for " + playerName,
|
_mediator.Publish(new NotificationMessage("Missing plugins for " + playerName,
|
||||||
|
|||||||
Reference in New Issue
Block a user