From 5b2cba451cc9b2b8db63ba81ddc850135baef282 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sun, 1 Oct 2023 01:13:58 +0200 Subject: [PATCH] Improve reverting IPC a bit. --- Glamourer/Api/GlamourerIpc.Revert.cs | 42 +++++++++++++++++++++------- Glamourer/Api/GlamourerIpc.cs | 21 +++++++++++++- Glamourer/Gui/Tabs/DebugTab.cs | 2 +- 3 files changed, 53 insertions(+), 12 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.Revert.cs b/Glamourer/Api/GlamourerIpc.Revert.cs index b3760af..9d486ae 100644 --- a/Glamourer/Api/GlamourerIpc.Revert.cs +++ b/Glamourer/Api/GlamourerIpc.Revert.cs @@ -9,12 +9,14 @@ namespace Glamourer.Api; public partial class GlamourerIpc { - public const string LabelRevert = "Glamourer.Revert"; - public const string LabelRevertCharacter = "Glamourer.RevertCharacter"; - public const string LabelRevertLock = "Glamourer.RevertLock"; - public const string LabelRevertCharacterLock = "Glamourer.RevertCharacterLock"; - public const string LabelUnlock = "Glamourer.Unlock"; - public const string LabelRevertToAutomation = "Glamourer.RevertToAutomation"; + public const string LabelRevert = "Glamourer.Revert"; + public const string LabelRevertCharacter = "Glamourer.RevertCharacter"; + public const string LabelRevertLock = "Glamourer.RevertLock"; + public const string LabelRevertCharacterLock = "Glamourer.RevertCharacterLock"; + public const string LabelRevertToAutomation = "Glamourer.RevertToAutomation"; + public const string LabelRevertToAutomationCharacter = "Glamourer.RevertToAutomationCharacter"; + public const string LabelUnlock = "Glamourer.Unlock"; + public const string LabelUnlockName = "Glamourer.UnlockName"; private readonly ActionProvider _revertProvider; private readonly ActionProvider _revertCharacterProvider; @@ -22,8 +24,10 @@ public partial class GlamourerIpc private readonly ActionProvider _revertProviderLock; private readonly ActionProvider _revertCharacterProviderLock; - private readonly FuncProvider _revertToAutomationProvider; + private readonly FuncProvider _revertToAutomationProvider; + private readonly FuncProvider _revertToAutomationCharacterProvider; + private readonly FuncProvider _unlockNameProvider; private readonly FuncProvider _unlockProvider; public static ActionSubscriber RevertSubscriber(DalamudPluginInterface pi) @@ -32,27 +36,45 @@ public partial class GlamourerIpc public static ActionSubscriber RevertCharacterSubscriber(DalamudPluginInterface pi) => new(pi, LabelRevertCharacter); + public static ActionSubscriber RevertLockSubscriber(DalamudPluginInterface pi) + => new(pi, LabelRevertLock); + + public static ActionSubscriber RevertCharacterLockSubscriber(DalamudPluginInterface pi) + => new(pi, LabelRevertCharacterLock); + + public static FuncSubscriber UnlockNameSubscriber(DalamudPluginInterface pi) + => new(pi, LabelUnlockName); + public static FuncSubscriber UnlockSubscriber(DalamudPluginInterface pi) => new(pi, LabelUnlock); - public static FuncSubscriber RevertToAutomationSubscriber(DalamudPluginInterface pi) + public static FuncSubscriber RevertToAutomationSubscriber(DalamudPluginInterface pi) => new(pi, LabelRevertToAutomation); + public static FuncSubscriber RevertToAutomationCharacterSubscriber(DalamudPluginInterface pi) + => new(pi, LabelRevertToAutomationCharacter); + public void Revert(string characterName) - => Revert(FindActors(characterName), 0); + => Revert(FindActorsRevert(characterName), 0); public void RevertCharacter(Character? character) => Revert(FindActors(character), 0); public void RevertLock(string characterName, uint lockCode) - => Revert(FindActors(characterName), lockCode); + => Revert(FindActorsRevert(characterName), lockCode); public void RevertCharacterLock(Character? character, uint lockCode) => Revert(FindActors(character), lockCode); + public bool Unlock(string characterName, uint lockCode) + => Unlock(FindActorsRevert(characterName), lockCode); + public bool Unlock(Character? character, uint lockCode) => Unlock(FindActors(character), lockCode); + public bool RevertToAutomation(string characterName, uint lockCode) + => RevertToAutomation(FindActorsRevert(characterName), lockCode); + public bool RevertToAutomation(Character? character, uint lockCode) => RevertToAutomation(FindActors(character), lockCode); diff --git a/Glamourer/Api/GlamourerIpc.cs b/Glamourer/Api/GlamourerIpc.cs index a60e16e..398cdf2 100644 --- a/Glamourer/Api/GlamourerIpc.cs +++ b/Glamourer/Api/GlamourerIpc.cs @@ -67,8 +67,11 @@ public partial class GlamourerIpc : IDisposable _revertCharacterProvider = new ActionProvider(pi, LabelRevertCharacter, RevertCharacter); _revertProviderLock = new ActionProvider(pi, LabelRevertLock, RevertLock); _revertCharacterProviderLock = new ActionProvider(pi, LabelRevertCharacterLock, RevertCharacterLock); + _unlockNameProvider = new FuncProvider(pi, LabelUnlockName, Unlock); _unlockProvider = new FuncProvider(pi, LabelUnlock, Unlock); - _revertToAutomationProvider = new FuncProvider(pi, LabelRevertToAutomation, RevertToAutomation); + _revertToAutomationProvider = new FuncProvider(pi, LabelRevertToAutomation, RevertToAutomation); + _revertToAutomationCharacterProvider = + new FuncProvider(pi, LabelRevertToAutomationCharacter, RevertToAutomation); _stateChangedProvider = new EventProvider>(pi, LabelStateChanged); _gPoseChangedProvider = new EventProvider(pi, LabelGPoseChanged); @@ -102,8 +105,10 @@ public partial class GlamourerIpc : IDisposable _revertCharacterProvider.Dispose(); _revertProviderLock.Dispose(); _revertCharacterProviderLock.Dispose(); + _unlockNameProvider.Dispose(); _unlockProvider.Dispose(); _revertToAutomationProvider.Dispose(); + _revertToAutomationCharacterProvider.Dispose(); _stateChangedEvent.Unsubscribe(OnStateChanged); _stateChangedProvider.Dispose(); @@ -121,6 +126,20 @@ public partial class GlamourerIpc : IDisposable .Select(i => i.Key); } + private IEnumerable FindActorsRevert(string actorName) + { + if (actorName.Length == 0 || !ByteString.FromString(actorName, out var byteString)) + yield break; + + _objects.Update(); + foreach (var id in _objects.Where(i => i.Key is { IsValid: true, Type: IdentifierType.Player } && i.Key.PlayerName == byteString) + .Select(i => i.Key)) + yield return id; + + foreach (var id in _stateManager.Keys.Where(s => s.Type is IdentifierType.Player && s.PlayerName == byteString)) + yield return id; + } + private IEnumerable FindActors(Character? character) { var id = _actors.AwaitedService.FromObject(character, true, true, false); diff --git a/Glamourer/Gui/Tabs/DebugTab.cs b/Glamourer/Gui/Tabs/DebugTab.cs index eb26f82..27943fd 100644 --- a/Glamourer/Gui/Tabs/DebugTab.cs +++ b/Glamourer/Gui/Tabs/DebugTab.cs @@ -1692,7 +1692,7 @@ public unsafe class DebugTab : ITab ImGuiUtil.DrawTableColumn(GlamourerIpc.LabelRevertToAutomation); ImGui.TableNextColumn(); if (ImGui.Button("Revert##CustomizeCharacter")) - GlamourerIpc.RevertToAutomationSubscriber(_pluginInterface) + GlamourerIpc.RevertToAutomationCharacterSubscriber(_pluginInterface) .Invoke(_objectManager.Objects[_gameObjectIndex] as Character, 1337); }