mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-13 12:14:18 +01:00
Merge pull request #42 from rootdarkarchon/main
Add IPC overrides using Character
This commit is contained in:
commit
e101101167
1 changed files with 133 additions and 16 deletions
|
|
@ -10,29 +10,39 @@ namespace Glamourer.Api;
|
||||||
|
|
||||||
public class GlamourerIpc : IDisposable
|
public class GlamourerIpc : IDisposable
|
||||||
{
|
{
|
||||||
public const int CurrentApiVersion = 0;
|
public const int CurrentApiVersion = 0;
|
||||||
public const string LabelProviderApiVersion = "Glamourer.ApiVersion";
|
public const string LabelProviderApiVersion = "Glamourer.ApiVersion";
|
||||||
public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization";
|
public const string LabelProviderGetAllCustomization = "Glamourer.GetAllCustomization";
|
||||||
public const string LabelProviderApplyAll = "Glamourer.ApplyAll";
|
public const string LabelProviderGetAllCustomizationFromCharacter = "Glamourer.GetAllCustomizationFromCharacter";
|
||||||
public const string LabelProviderApplyOnlyEquipment = "Glamourer.ApplyOnlyEquipment";
|
public const string LabelProviderApplyAll = "Glamourer.ApplyAll";
|
||||||
public const string LabelProviderApplyOnlyCustomization = "Glamourer.ApplyOnlyCustomization";
|
public const string LabelProviderApplyAllToCharacter = "Glamourer.ApplyAllToCharacter";
|
||||||
public const string LabelProviderRevert = "Glamourer.Revert";
|
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";
|
||||||
|
|
||||||
private readonly ClientState _clientState;
|
private readonly ClientState _clientState;
|
||||||
private readonly ObjectTable _objectTable;
|
private readonly ObjectTable _objectTable;
|
||||||
private readonly DalamudPluginInterface _pluginInterface;
|
private readonly DalamudPluginInterface _pluginInterface;
|
||||||
|
|
||||||
internal ICallGateProvider<string, string?>? ProviderGetAllCustomization;
|
internal ICallGateProvider<string, string?>? ProviderGetAllCustomization;
|
||||||
internal ICallGateProvider<string, string, object>? ProviderApplyAll;
|
internal ICallGateProvider<Character?, string?>? ProviderGetAllCustomizationFromCharacter;
|
||||||
internal ICallGateProvider<string, string, object>? ProviderApplyOnlyCustomization;
|
internal ICallGateProvider<string, string, object>? ProviderApplyAll;
|
||||||
internal ICallGateProvider<string, string, object>? ProviderApplyOnlyEquipment;
|
internal ICallGateProvider<string, Character?, object>? ProviderApplyAllToCharacter;
|
||||||
internal ICallGateProvider<string, object>? ProviderRevert;
|
internal ICallGateProvider<string, string, object>? ProviderApplyOnlyCustomization;
|
||||||
internal ICallGateProvider<int>? ProviderGetApiVersion;
|
internal ICallGateProvider<string, Character?, object>? ProviderApplyOnlyCustomizationToCharacter;
|
||||||
|
internal ICallGateProvider<string, string, object>? ProviderApplyOnlyEquipment;
|
||||||
|
internal ICallGateProvider<string, Character?, object>? ProviderApplyOnlyEquipmentToCharacter;
|
||||||
|
internal ICallGateProvider<string, object>? ProviderRevert;
|
||||||
|
internal ICallGateProvider<Character?, object>? ProviderRevertCharacter;
|
||||||
|
internal ICallGateProvider<int>? ProviderGetApiVersion;
|
||||||
|
|
||||||
public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface)
|
public GlamourerIpc(ClientState clientState, ObjectTable objectTable, DalamudPluginInterface pluginInterface)
|
||||||
{
|
{
|
||||||
_clientState = clientState;
|
_clientState = clientState;
|
||||||
_objectTable = objectTable;
|
_objectTable = objectTable;
|
||||||
_pluginInterface = pluginInterface;
|
_pluginInterface = pluginInterface;
|
||||||
|
|
||||||
InitializeProviders();
|
InitializeProviders();
|
||||||
|
|
@ -44,12 +54,17 @@ public class GlamourerIpc : IDisposable
|
||||||
private void DisposeProviders()
|
private void DisposeProviders()
|
||||||
{
|
{
|
||||||
ProviderGetAllCustomization?.UnregisterFunc();
|
ProviderGetAllCustomization?.UnregisterFunc();
|
||||||
|
ProviderGetAllCustomizationFromCharacter?.UnregisterFunc();
|
||||||
ProviderApplyAll?.UnregisterAction();
|
ProviderApplyAll?.UnregisterAction();
|
||||||
|
ProviderApplyAllToCharacter?.UnregisterAction();
|
||||||
ProviderApplyOnlyCustomization?.UnregisterAction();
|
ProviderApplyOnlyCustomization?.UnregisterAction();
|
||||||
|
ProviderApplyOnlyCustomizationToCharacter?.UnregisterAction();
|
||||||
ProviderApplyOnlyEquipment?.UnregisterAction();
|
ProviderApplyOnlyEquipment?.UnregisterAction();
|
||||||
|
ProviderApplyOnlyEquipmentToCharacter?.UnregisterAction();
|
||||||
ProviderRevert?.UnregisterAction();
|
ProviderRevert?.UnregisterAction();
|
||||||
|
ProviderRevertCharacter?.UnregisterAction();
|
||||||
ProviderGetApiVersion?.UnregisterFunc();
|
ProviderGetApiVersion?.UnregisterFunc();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeProviders()
|
private void InitializeProviders()
|
||||||
|
|
@ -74,6 +89,16 @@ public class GlamourerIpc : IDisposable
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderGetAllCustomizationFromCharacter = _pluginInterface.GetIpcProvider<Character?, string?>(LabelProviderGetAllCustomizationFromCharacter);
|
||||||
|
ProviderGetAllCustomizationFromCharacter.RegisterFunc(GetAllCustomization);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderGetAllCustomizationFromCharacter}.");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderApplyAll =
|
ProviderApplyAll =
|
||||||
|
|
@ -85,6 +110,17 @@ public class GlamourerIpc : IDisposable
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyAll}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyAll}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderApplyAllToCharacter =
|
||||||
|
_pluginInterface.GetIpcProvider<string, Character?, object>(LabelProviderApplyAllToCharacter);
|
||||||
|
ProviderApplyAllToCharacter.RegisterAction(ApplyAll);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyAll}.");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderApplyOnlyCustomization =
|
ProviderApplyOnlyCustomization =
|
||||||
|
|
@ -96,6 +132,17 @@ public class GlamourerIpc : IDisposable
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyCustomization}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyCustomization}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderApplyOnlyCustomizationToCharacter =
|
||||||
|
_pluginInterface.GetIpcProvider<string, Character?, object>(LabelProviderApplyOnlyCustomizationToCharacter);
|
||||||
|
ProviderApplyOnlyCustomizationToCharacter.RegisterAction(ApplyOnlyCustomization);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyCustomization}.");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderApplyOnlyEquipment =
|
ProviderApplyOnlyEquipment =
|
||||||
|
|
@ -107,6 +154,17 @@ public class GlamourerIpc : IDisposable
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderApplyOnlyEquipmentToCharacter =
|
||||||
|
_pluginInterface.GetIpcProvider<string, Character?, object>(LabelProviderApplyOnlyEquipmentToCharacter);
|
||||||
|
ProviderApplyOnlyEquipmentToCharacter.RegisterAction(ApplyOnlyEquipment);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyOnlyEquipment}.");
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProviderRevert =
|
ProviderRevert =
|
||||||
|
|
@ -117,6 +175,17 @@ public class GlamourerIpc : IDisposable
|
||||||
{
|
{
|
||||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevert}.");
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevert}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ProviderRevertCharacter =
|
||||||
|
_pluginInterface.GetIpcProvider<Character?, object>(LabelProviderRevertCharacter);
|
||||||
|
ProviderRevertCharacter.RegisterAction(Revert);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderRevert}.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetApiVersion()
|
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)
|
private void ApplyOnlyCustomization(string customization, string characterName)
|
||||||
{
|
{
|
||||||
var save = CharacterSave.FromString(customization);
|
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)
|
private void ApplyOnlyEquipment(string customization, string characterName)
|
||||||
{
|
{
|
||||||
var save = CharacterSave.FromString(customization);
|
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)
|
private void Revert(string characterName)
|
||||||
{
|
{
|
||||||
foreach (var gameObject in _objectTable)
|
foreach (var gameObject in _objectTable)
|
||||||
|
|
@ -186,6 +285,24 @@ public class GlamourerIpc : IDisposable
|
||||||
Glamourer.RevertableDesigns.RevertByNameWithoutApplication(characterName);
|
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)
|
private string? GetAllCustomization(string characterName)
|
||||||
{
|
{
|
||||||
CharacterSave save = null!;
|
CharacterSave save = null!;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue