From 9d41573d0ab98fcfbad1aacf4d6158232c3a750a Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Thu, 30 Jun 2022 10:46:40 +0200 Subject: [PATCH 1/2] Add IPC overrides using Character --- Glamourer/Api/GlamourerIpc.cs | 145 ++++++++++++++++++++++++++++++---- 1 file changed, 131 insertions(+), 14 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.cs b/Glamourer/Api/GlamourerIpc.cs index 1591f82..79d45db 100644 --- a/Glamourer/Api/GlamourerIpc.cs +++ b/Glamourer/Api/GlamourerIpc.cs @@ -10,29 +10,39 @@ namespace Glamourer.Api; public class GlamourerIpc : IDisposable { - public const int CurrentApiVersion = 0; - public const string LabelProviderApiVersion = "Glamourer.ApiVersion"; - public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization"; - public const string LabelProviderApplyAll = "Glamourer.ApplyAll"; - public const string LabelProviderApplyOnlyEquipment = "Glamourer.ApplyOnlyEquipment"; + public const int CurrentApiVersion = 0; + public const string LabelProviderApiVersion = "Glamourer.ApiVersion"; + public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization"; + public const string LabelProviderGetAllCustomizationFromCharacter = "Glamourer.GetAllCustomizationFromCharacter"; + public const string LabelProviderApplyAll = "Glamourer.ApplyAll"; + public const string LabelProviderApplyAllToCharacter = "Glamourer.ApplyAllToCharacter"; + public const string LabelProviderApplyOnlyEquipment = "Glamourer.ApplyOnlyEquipment"; + public const string LabelProviderApplyOnlyEquipmentToCharacter = "Glamourer.ApplyOnlyEquipmentToCharacter"; public const string LabelProviderApplyOnlyCustomization = "Glamourer.ApplyOnlyCustomization"; - public const string LabelProviderRevert = "Glamourer.Revert"; + public const string LabelProviderApplyOnlyCustomizationToCharacter = "Glamourer.ApplyOnlyCustomizationToCharacter"; + public const string LabelProviderRevert = "Glamourer.Revert"; + public const string LabelProviderRevertCharacter = "Glamourer.RevertCharacter"; - private readonly ClientState _clientState; - private readonly ObjectTable _objectTable; + private readonly ClientState _clientState; + private readonly ObjectTable _objectTable; private readonly DalamudPluginInterface _pluginInterface; - internal ICallGateProvider? ProviderGetAllCustomization; + internal ICallGateProvider? ProviderGetAllCustomization; + internal ICallGateProvider? ProviderGetAllCustomizationFromCharacter; internal ICallGateProvider? ProviderApplyAll; + internal ICallGateProvider? ProviderApplyAllToCharacter; internal ICallGateProvider? ProviderApplyOnlyCustomization; + internal ICallGateProvider? ProviderApplyOnlyCustomizationToCharacter; internal ICallGateProvider? ProviderApplyOnlyEquipment; - internal ICallGateProvider? ProviderRevert; - internal ICallGateProvider? ProviderGetApiVersion; + internal ICallGateProvider? ProviderApplyOnlyEquipmentToCharacter; + internal ICallGateProvider? ProviderRevert; + internal ICallGateProvider? ProviderRevertCharacter; + internal ICallGateProvider? ProviderGetApiVersion; public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface) { - _clientState = clientState; - _objectTable = objectTable; + _clientState = clientState; + _objectTable = objectTable; _pluginInterface = pluginInterface; InitializeProviders(); @@ -44,12 +54,17 @@ public class GlamourerIpc : IDisposable private void DisposeProviders() { ProviderGetAllCustomization?.UnregisterFunc(); + ProviderGetAllCustomizationFromCharacter?.UnregisterFunc(); ProviderApplyAll?.UnregisterAction(); + ProviderApplyAllToCharacter?.UnregisterAction(); ProviderApplyOnlyCustomization?.UnregisterAction(); + ProviderApplyOnlyCustomizationToCharacter?.UnregisterAction(); ProviderApplyOnlyEquipment?.UnregisterAction(); + ProviderApplyOnlyEquipmentToCharacter?.UnregisterAction(); ProviderRevert?.UnregisterAction(); + ProviderRevertCharacter?.UnregisterAction(); ProviderGetApiVersion?.UnregisterFunc(); - + } private void InitializeProviders() @@ -74,6 +89,16 @@ public class GlamourerIpc : IDisposable PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}."); } + try + { + ProviderGetAllCustomizationFromCharacter = _pluginInterface.GetIpcProvider(LabelProviderGetAllCustomizationFromCharacter); + ProviderGetAllCustomizationFromCharacter.RegisterFunc(GetAllCustomization); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderGetAllCustomizationFromCharacter}."); + } + try { ProviderApplyAll = @@ -85,6 +110,17 @@ public class GlamourerIpc : IDisposable PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyAll}."); } + try + { + ProviderApplyAllToCharacter = + _pluginInterface.GetIpcProvider(LabelProviderApplyAllToCharacter); + ProviderApplyAllToCharacter.RegisterAction(ApplyAll); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyAll}."); + } + try { ProviderApplyOnlyCustomization = @@ -96,6 +132,17 @@ public class GlamourerIpc : IDisposable PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyCustomization}."); } + try + { + ProviderApplyOnlyCustomizationToCharacter = + _pluginInterface.GetIpcProvider(LabelProviderApplyOnlyCustomizationToCharacter); + ProviderApplyOnlyCustomizationToCharacter.RegisterAction(ApplyOnlyCustomization); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyCustomization}."); + } + try { ProviderApplyOnlyEquipment = @@ -107,6 +154,17 @@ public class GlamourerIpc : IDisposable PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}."); } + try + { + ProviderApplyOnlyEquipmentToCharacter = + _pluginInterface.GetIpcProvider(LabelProviderApplyOnlyEquipmentToCharacter); + ProviderApplyOnlyEquipmentToCharacter.RegisterAction(ApplyOnlyEquipment); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}."); + } + try { ProviderRevert = @@ -117,6 +175,17 @@ public class GlamourerIpc : IDisposable { PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevert}."); } + + try + { + ProviderRevertCharacter = + _pluginInterface.GetIpcProvider(LabelProviderRevertCharacter); + ProviderRevertCharacter.RegisterAction(Revert); + } + catch (Exception ex) + { + PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevert}."); + } } private static int GetApiVersion() @@ -138,6 +207,16 @@ public class GlamourerIpc : IDisposable } } + private void ApplyAll(string customization, Character? character) + { + if (character == null) + return; + var save = CharacterSave.FromString(customization); + Glamourer.RevertableDesigns.Revert(character); + save.Apply(character); + Glamourer.Penumbra.UpdateCharacters(character, null); + } + private void ApplyOnlyCustomization(string customization, string characterName) { var save = CharacterSave.FromString(customization); @@ -154,6 +233,16 @@ public class GlamourerIpc : IDisposable } } + private void ApplyOnlyCustomization(string customization, Character? character) + { + if (character == null) + return; + var save = CharacterSave.FromString(customization); + Glamourer.RevertableDesigns.Revert(character); + save.ApplyOnlyCustomizations(character); + Glamourer.Penumbra.UpdateCharacters(character, null); + } + private void ApplyOnlyEquipment(string customization, string characterName) { var save = CharacterSave.FromString(customization); @@ -170,6 +259,16 @@ public class GlamourerIpc : IDisposable } } + private void ApplyOnlyEquipment(string customization, Character? character) + { + if (character == null) + return; + var save = CharacterSave.FromString(customization); + Glamourer.RevertableDesigns.Revert(character); + save.ApplyOnlyEquipment(character); + Glamourer.Penumbra.UpdateCharacters(character, null); + } + private void Revert(string characterName) { foreach (var gameObject in _objectTable) @@ -186,6 +285,24 @@ public class GlamourerIpc : IDisposable Glamourer.RevertableDesigns.RevertByNameWithoutApplication(characterName); } + private void Revert(Character? character) + { + if (character == null) + return; + Glamourer.RevertableDesigns.Revert(character); + Glamourer.Penumbra.UpdateCharacters(character, null); + } + + private string? GetAllCustomization(Character? character) + { + if (character == null) + return null; + + CharacterSave save = new CharacterSave(); + save.LoadCharacter(character); + return save.ToBase64(); + } + private string? GetAllCustomization(string characterName) { CharacterSave save = null!; From edbf66c25e897743dcd41c13d915ca4b3b831fb6 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Thu, 30 Jun 2022 10:47:15 +0200 Subject: [PATCH 2/2] fix formating --- Glamourer/Api/GlamourerIpc.cs | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/Glamourer/Api/GlamourerIpc.cs b/Glamourer/Api/GlamourerIpc.cs index 79d45db..36157dc 100644 --- a/Glamourer/Api/GlamourerIpc.cs +++ b/Glamourer/Api/GlamourerIpc.cs @@ -10,34 +10,34 @@ namespace Glamourer.Api; public class GlamourerIpc : IDisposable { - public const int CurrentApiVersion = 0; - public const string LabelProviderApiVersion = "Glamourer.ApiVersion"; - public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization"; - public const string LabelProviderGetAllCustomizationFromCharacter = "Glamourer.GetAllCustomizationFromCharacter"; - public const string LabelProviderApplyAll = "Glamourer.ApplyAll"; - public const string LabelProviderApplyAllToCharacter = "Glamourer.ApplyAllToCharacter"; - public const string LabelProviderApplyOnlyEquipment = "Glamourer.ApplyOnlyEquipment"; - public const string LabelProviderApplyOnlyEquipmentToCharacter = "Glamourer.ApplyOnlyEquipmentToCharacter"; - public const string LabelProviderApplyOnlyCustomization = "Glamourer.ApplyOnlyCustomization"; + public const int CurrentApiVersion = 0; + public const string LabelProviderApiVersion = "Glamourer.ApiVersion"; + public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization"; + public const string LabelProviderGetAllCustomizationFromCharacter = "Glamourer.GetAllCustomizationFromCharacter"; + public const string LabelProviderApplyAll = "Glamourer.ApplyAll"; + public const string LabelProviderApplyAllToCharacter = "Glamourer.ApplyAllToCharacter"; + public const string LabelProviderApplyOnlyEquipment = "Glamourer.ApplyOnlyEquipment"; + public const string LabelProviderApplyOnlyEquipmentToCharacter = "Glamourer.ApplyOnlyEquipmentToCharacter"; + public const string LabelProviderApplyOnlyCustomization = "Glamourer.ApplyOnlyCustomization"; public const string LabelProviderApplyOnlyCustomizationToCharacter = "Glamourer.ApplyOnlyCustomizationToCharacter"; - public const string LabelProviderRevert = "Glamourer.Revert"; - public const string LabelProviderRevertCharacter = "Glamourer.RevertCharacter"; + public const string LabelProviderRevert = "Glamourer.Revert"; + public const string LabelProviderRevertCharacter = "Glamourer.RevertCharacter"; - private readonly ClientState _clientState; - private readonly ObjectTable _objectTable; + private readonly ClientState _clientState; + private readonly ObjectTable _objectTable; private readonly DalamudPluginInterface _pluginInterface; - internal ICallGateProvider? ProviderGetAllCustomization; - internal ICallGateProvider? ProviderGetAllCustomizationFromCharacter; - internal ICallGateProvider? ProviderApplyAll; + internal ICallGateProvider? ProviderGetAllCustomization; + internal ICallGateProvider? ProviderGetAllCustomizationFromCharacter; + internal ICallGateProvider? ProviderApplyAll; internal ICallGateProvider? ProviderApplyAllToCharacter; - internal ICallGateProvider? ProviderApplyOnlyCustomization; + internal ICallGateProvider? ProviderApplyOnlyCustomization; internal ICallGateProvider? ProviderApplyOnlyCustomizationToCharacter; - internal ICallGateProvider? ProviderApplyOnlyEquipment; + internal ICallGateProvider? ProviderApplyOnlyEquipment; internal ICallGateProvider? ProviderApplyOnlyEquipmentToCharacter; - internal ICallGateProvider? ProviderRevert; - internal ICallGateProvider? ProviderRevertCharacter; - internal ICallGateProvider? ProviderGetApiVersion; + internal ICallGateProvider? ProviderRevert; + internal ICallGateProvider? ProviderRevertCharacter; + internal ICallGateProvider? ProviderGetApiVersion; public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface) {