update honorific integration (#50)
This commit is contained in:
@@ -36,9 +36,11 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
private readonly ICallGateSubscriber<GameObject, object?> _heelsUnregisterPlayer;
|
private readonly ICallGateSubscriber<GameObject, object?> _heelsUnregisterPlayer;
|
||||||
private readonly ICallGateSubscriber<(uint major, uint minor)> _honorificApiVersion;
|
private readonly ICallGateSubscriber<(uint major, uint minor)> _honorificApiVersion;
|
||||||
private readonly ICallGateSubscriber<Character, object> _honorificClearCharacterTitle;
|
private readonly ICallGateSubscriber<Character, object> _honorificClearCharacterTitle;
|
||||||
private readonly ICallGateSubscriber<(string Title, bool IsPrefix)> _honorificGetLocalCharacterTitle;
|
private readonly ICallGateSubscriber<string> _honorificGetLocalCharacterTitle;
|
||||||
private readonly ICallGateSubscriber<string, bool, object> _honorificLocalCharacterTitleChanged;
|
private readonly ICallGateSubscriber<string, object> _honorificLocalCharacterTitleChanged;
|
||||||
private readonly ICallGateSubscriber<Character, string, bool, object> _honorificSetCharacterTitle;
|
private readonly ICallGateSubscriber<Character, string, object> _honorificSetCharacterTitle;
|
||||||
|
private readonly ICallGateSubscriber<object> _honorificDisposing;
|
||||||
|
private readonly ICallGateSubscriber<object> _honorificReady;
|
||||||
private readonly ConcurrentQueue<Action> _normalQueue = new();
|
private readonly ConcurrentQueue<Action> _normalQueue = new();
|
||||||
private readonly ICallGateSubscriber<string> _palettePlusApiVersion;
|
private readonly ICallGateSubscriber<string> _palettePlusApiVersion;
|
||||||
private readonly ICallGateSubscriber<Character, string> _palettePlusBuildCharaPalette;
|
private readonly ICallGateSubscriber<Character, string> _palettePlusBuildCharaPalette;
|
||||||
@@ -133,12 +135,16 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
_palettePlusPaletteChanged.Subscribe(OnPalettePlusPaletteChange);
|
_palettePlusPaletteChanged.Subscribe(OnPalettePlusPaletteChange);
|
||||||
|
|
||||||
_honorificApiVersion = pi.GetIpcSubscriber<(uint, uint)>("Honorific.ApiVersion");
|
_honorificApiVersion = pi.GetIpcSubscriber<(uint, uint)>("Honorific.ApiVersion");
|
||||||
_honorificGetLocalCharacterTitle = pi.GetIpcSubscriber<(string, bool)>("Honorific.GetLocalCharacterTitle");
|
_honorificGetLocalCharacterTitle = pi.GetIpcSubscriber<string>("Honorific.GetLocalCharacterTitle");
|
||||||
_honorificClearCharacterTitle = pi.GetIpcSubscriber<Character, object>("Honorific.ClearCharacterTitle");
|
_honorificClearCharacterTitle = pi.GetIpcSubscriber<Character, object>("Honorific.ClearCharacterTitle");
|
||||||
_honorificSetCharacterTitle = pi.GetIpcSubscriber<Character, string, bool, object>("Honorific.SetCharacterTitle");
|
_honorificSetCharacterTitle = pi.GetIpcSubscriber<Character, string, object>("Honorific.SetCharacterTitle");
|
||||||
_honorificLocalCharacterTitleChanged = pi.GetIpcSubscriber<string, bool, object>("Honorific.LocalCharacterTitleChanged");
|
_honorificLocalCharacterTitleChanged = pi.GetIpcSubscriber<string, object>("Honorific.LocalCharacterTitleChanged");
|
||||||
|
_honorificDisposing = pi.GetIpcSubscriber<object>("Honorific.Disposing");
|
||||||
|
_honorificReady = pi.GetIpcSubscriber<object>("Honorific.Ready");
|
||||||
|
|
||||||
_honorificLocalCharacterTitleChanged.Subscribe(OnHonorificLocalCharacterTitleChanged);
|
_honorificLocalCharacterTitleChanged.Subscribe(OnHonorificLocalCharacterTitleChanged);
|
||||||
|
_honorificDisposing.Subscribe(OnHonorificDisposing);
|
||||||
|
_honorificReady.Subscribe(OnHonorificReady);
|
||||||
|
|
||||||
if (Initialized)
|
if (Initialized)
|
||||||
{
|
{
|
||||||
@@ -323,11 +329,11 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
public string HonorificGetTitle()
|
public string HonorificGetTitle()
|
||||||
{
|
{
|
||||||
if (!CheckHonorificApi()) return string.Empty;
|
if (!CheckHonorificApi()) return string.Empty;
|
||||||
(string? title, bool isPrefix) = _honorificGetLocalCharacterTitle.InvokeFunc();
|
string title = _honorificGetLocalCharacterTitle.InvokeFunc();
|
||||||
return string.IsNullOrEmpty(title) ? string.Empty : $"{(isPrefix ? 1 : 0)}{title}";
|
return string.IsNullOrEmpty(title) ? string.Empty : Convert.ToBase64String(Encoding.UTF8.GetBytes(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task HonorificSetTitleAsync(IntPtr character, string honorificData)
|
public async Task HonorificSetTitleAsync(IntPtr character, string honorificDataB64)
|
||||||
{
|
{
|
||||||
if (!CheckHonorificApi()) return;
|
if (!CheckHonorificApi()) return;
|
||||||
Logger.LogTrace("Applying Honorific data to {chara}", character.ToString("X"));
|
Logger.LogTrace("Applying Honorific data to {chara}", character.ToString("X"));
|
||||||
@@ -336,13 +342,14 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
var gameObj = _dalamudUtil.CreateGameObject(character);
|
var gameObj = _dalamudUtil.CreateGameObject(character);
|
||||||
if (gameObj is PlayerCharacter pc)
|
if (gameObj is PlayerCharacter pc)
|
||||||
{
|
{
|
||||||
|
string honorificData = string.IsNullOrEmpty(honorificDataB64) ? string.Empty : Encoding.UTF8.GetString(Convert.FromBase64String(honorificDataB64));
|
||||||
if (string.IsNullOrEmpty(honorificData))
|
if (string.IsNullOrEmpty(honorificData))
|
||||||
{
|
{
|
||||||
_honorificClearCharacterTitle!.InvokeAction(pc);
|
_honorificClearCharacterTitle!.InvokeAction(pc);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_honorificSetCharacterTitle!.InvokeAction(pc, honorificData[1..], honorificData[0] == '1');
|
_honorificSetCharacterTitle!.InvokeAction(pc, honorificData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).ConfigureAwait(false);
|
}).ConfigureAwait(false);
|
||||||
@@ -498,6 +505,8 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
_palettePlusPaletteChanged.Unsubscribe(OnPalettePlusPaletteChange);
|
_palettePlusPaletteChanged.Unsubscribe(OnPalettePlusPaletteChange);
|
||||||
_customizePlusOnScaleUpdate.Unsubscribe(OnCustomizePlusScaleChange);
|
_customizePlusOnScaleUpdate.Unsubscribe(OnCustomizePlusScaleChange);
|
||||||
_honorificLocalCharacterTitleChanged.Unsubscribe(OnHonorificLocalCharacterTitleChanged);
|
_honorificLocalCharacterTitleChanged.Unsubscribe(OnHonorificLocalCharacterTitleChanged);
|
||||||
|
_honorificDisposing.Unsubscribe(OnHonorificDisposing);
|
||||||
|
_honorificReady.Unsubscribe(OnHonorificReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckCustomizePlusApiInternal()
|
private bool CheckCustomizePlusApiInternal()
|
||||||
@@ -551,7 +560,7 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _honorificApiVersion.InvokeFunc() is { Item1: 1, Item2: >= 0 };
|
return _honorificApiVersion.InvokeFunc() is { Item1: 2, Item2: >= 0 };
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
@@ -636,9 +645,21 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
|
|||||||
Mediator.Publish(new CustomizePlusMessage());
|
Mediator.Publish(new CustomizePlusMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHonorificLocalCharacterTitleChanged(string title, bool isPrefix)
|
private void OnHonorificLocalCharacterTitleChanged(string titleJson)
|
||||||
{
|
{
|
||||||
Mediator.Publish(new HonorificMessage((isPrefix ? 1 : 0) + title));
|
string titleData = string.IsNullOrEmpty(titleJson) ? string.Empty : Convert.ToBase64String(Encoding.UTF8.GetBytes(titleJson));
|
||||||
|
Mediator.Publish(new HonorificMessage(titleData));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHonorificDisposing()
|
||||||
|
{
|
||||||
|
Mediator.Publish(new HonorificMessage(string.Empty));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHonorificReady()
|
||||||
|
{
|
||||||
|
_honorificAvailable = CheckHonorificApiInternal();
|
||||||
|
Mediator.Publish(new HonorificReadyMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPalettePlusPaletteChange(Character character, string palette)
|
private void OnPalettePlusPaletteChange(Character character, string palette)
|
||||||
|
|||||||
@@ -535,6 +535,12 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
|
|||||||
_lastGlamourerData = await _ipcManager.GlamourerGetCharacterCustomizationAsync(PlayerCharacter).ConfigureAwait(false);
|
_lastGlamourerData = await _ipcManager.GlamourerGetCharacterCustomizationAsync(PlayerCharacter).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Mediator.Subscribe<HonorificReadyMessage>(this, async (_) =>
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_cachedData?.HonorificData)) return;
|
||||||
|
Logger.LogTrace("Reapplying Honorific data for {this}", this);
|
||||||
|
await _ipcManager.HonorificSetTitleAsync(PlayerCharacter, _cachedData.HonorificData).ConfigureAwait(false);
|
||||||
|
});
|
||||||
|
|
||||||
_downloadManager.Initialize();
|
_downloadManager.Initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ public record PenumbraResourceLoadMessage(IntPtr GameObject, string GamePath, st
|
|||||||
public record CustomizePlusMessage : MessageBase;
|
public record CustomizePlusMessage : MessageBase;
|
||||||
public record PalettePlusMessage(Character Character) : MessageBase;
|
public record PalettePlusMessage(Character Character) : MessageBase;
|
||||||
public record HonorificMessage(string NewHonorificTitle) : MessageBase;
|
public record HonorificMessage(string NewHonorificTitle) : 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;
|
||||||
public record TransientResourceChangedMessage(IntPtr Address) : MessageBase;
|
public record TransientResourceChangedMessage(IntPtr Address) : MessageBase;
|
||||||
|
|||||||
Reference in New Issue
Block a user