mirror of
https://github.com/Ottermandias/Glamourer.git
synced 2025-12-12 10:17:23 +01:00
Add basic Glamourer IPC
This commit is contained in:
parent
e4e9ed81b8
commit
7d6e1323f4
2 changed files with 91 additions and 1 deletions
87
Glamourer/Api/GlamourerIpc.cs
Normal file
87
Glamourer/Api/GlamourerIpc.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
using Dalamud.Game.ClientState;
|
||||
using Dalamud.Game.ClientState.Objects;
|
||||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Ipc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Glamourer.Api
|
||||
{
|
||||
public class GlamourerIpc : IDisposable
|
||||
{
|
||||
public const string LabelProviderGetCharacterCustomization = "Glamourer.GetCharacterCustomization";
|
||||
public const string LabelProviderApplyCharacterCustomization = "Glamourer.ApplyCharacterCustomization";
|
||||
|
||||
private readonly ObjectTable objectTable;
|
||||
private readonly DalamudPluginInterface pi;
|
||||
|
||||
internal ICallGateProvider<string>? ProviderGetCharacterCustomization;
|
||||
internal ICallGateProvider<string, string, object>? ProviderApplyCharacterCustomization;
|
||||
|
||||
public GlamourerIpc(ObjectTable objectTable, DalamudPluginInterface pi)
|
||||
{
|
||||
this.objectTable = objectTable;
|
||||
this.pi = pi;
|
||||
|
||||
InitializeProviders();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeProviders();
|
||||
}
|
||||
|
||||
private void DisposeProviders()
|
||||
{
|
||||
ProviderApplyCharacterCustomization?.UnregisterFunc();
|
||||
ProviderGetCharacterCustomization?.UnregisterAction();
|
||||
}
|
||||
|
||||
private void InitializeProviders()
|
||||
{
|
||||
try
|
||||
{
|
||||
ProviderGetCharacterCustomization = pi.GetIpcProvider<string>(LabelProviderGetCharacterCustomization);
|
||||
ProviderGetCharacterCustomization.RegisterFunc(GetCharacterCustomization);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyCharacterCustomization}.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
ProviderApplyCharacterCustomization = pi.GetIpcProvider<string, string, object>(LabelProviderApplyCharacterCustomization);
|
||||
ProviderApplyCharacterCustomization.RegisterAction((customization, characterName) => ApplyCharacterCustomization(customization, characterName));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginLog.Error(ex, $"Error registering IPC provider for {LabelProviderApplyCharacterCustomization}.");
|
||||
}
|
||||
}
|
||||
|
||||
private void ApplyCharacterCustomization(string customization, string characterName)
|
||||
{
|
||||
var save = CharacterSave.FromString(customization);
|
||||
foreach (var gameObject in objectTable)
|
||||
{
|
||||
if (gameObject.Name.ToString() == characterName)
|
||||
{
|
||||
save.Apply((Character)gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetCharacterCustomization()
|
||||
{
|
||||
CharacterSave save = new CharacterSave();
|
||||
save.LoadCharacter((Character)Glamourer.GetPlayer("self")!);
|
||||
return save.ToBase64();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,7 @@ using System.Reflection;
|
|||
using Dalamud.Game.ClientState.Objects.Types;
|
||||
using Dalamud.Game.Command;
|
||||
using Dalamud.Plugin;
|
||||
using Glamourer.Api;
|
||||
using Glamourer.Customization;
|
||||
using Glamourer.Designs;
|
||||
using Glamourer.FileSystem;
|
||||
|
|
@ -27,6 +28,7 @@ namespace Glamourer
|
|||
public readonly DesignManager Designs;
|
||||
public readonly FixedDesigns FixedDesigns;
|
||||
public static RevertableDesigns RevertableDesigns = new();
|
||||
public readonly GlamourerIpc GlamourerIpc;
|
||||
|
||||
|
||||
public static string Version = string.Empty;
|
||||
|
|
@ -41,6 +43,7 @@ namespace Glamourer
|
|||
Designs = new DesignManager();
|
||||
Penumbra = new PenumbraAttach(Config.AttachToPenumbra);
|
||||
PlayerWatcher = PlayerWatchFactory.Create(Dalamud.Framework, Dalamud.ClientState, Dalamud.Objects);
|
||||
GlamourerIpc = new(Dalamud.Objects, pluginInterface);
|
||||
if (!Config.ApplyFixedDesigns)
|
||||
PlayerWatcher.Disable();
|
||||
|
||||
|
|
@ -61,7 +64,7 @@ namespace Glamourer
|
|||
public void OnGlamourer(string command, string arguments)
|
||||
=> _interface.ToggleVisibility();
|
||||
|
||||
private static GameObject? GetPlayer(string name)
|
||||
public static GameObject? GetPlayer(string name)
|
||||
{
|
||||
var lowerName = name.ToLowerInvariant();
|
||||
return lowerName switch
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue