From 13976a91356948eb46f7a0e9aee74bd7d29263c9 Mon Sep 17 00:00:00 2001
From: RisaDev <151885272+RisaDev@users.noreply.github.com>
Date: Mon, 11 Mar 2024 01:01:50 +0300
Subject: [PATCH] Added Profile.GetProfileList, Profile.EnableByUniqueId,
Profile.DisableByUniqueId IPC endpoints
Co-authored-by: Limiana <5073202+Limiana@users.noreply.github.com>
---
CustomizePlus/Api/CustomizePlusIpc.General.cs | 4 +-
CustomizePlus/Api/CustomizePlusIpc.Profile.cs | 38 +++++++++++++++--
CustomizePlus/Api/CustomizePlusIpc.cs | 6 ++-
CustomizePlus/Profiles/ProfileManager.cs | 9 ++++
.../MainWindow/Tabs/Debug/IPCTestTab.cs | 41 +++++++++++++++++++
.../UI/Windows/PopupSystem.Messages.cs | 6 +++
6 files changed, 98 insertions(+), 6 deletions(-)
diff --git a/CustomizePlus/Api/CustomizePlusIpc.General.cs b/CustomizePlus/Api/CustomizePlusIpc.General.cs
index f794500..d8847de 100644
--- a/CustomizePlus/Api/CustomizePlusIpc.General.cs
+++ b/CustomizePlus/Api/CustomizePlusIpc.General.cs
@@ -18,7 +18,7 @@ public partial class CustomizePlusIpc
/// When there are non-breaking changes only second number is bumped up.
/// In general clients should not try to use IPC if they encounter unexpected Breaking version.
///
- [EzIPC($"General.{nameof(GetApiVersion)}")]
+ [EzIPC($"General.GetApiVersion")]
private (int, int) GetApiVersion()
{
return _apiVersion;
@@ -29,7 +29,7 @@ public partial class CustomizePlusIpc
/// This only indicates that no fatal errors occured in Customize+.
/// This will still be true if, for example, user turns off Customize+ in its settings.
///
- [EzIPC($"General.{nameof(IsValid)}")]
+ [EzIPC($"General.IsValid")]
private bool IsValid()
{
return !IPCFailed &&
diff --git a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs
index 0f23be3..98f17a5 100644
--- a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs
+++ b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs
@@ -1,12 +1,44 @@
-using System;
+using CustomizePlus.Profiles.Enums;
+using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using ECommons.EzIpcManager;
+
+using IPCProfileDataTuple = (System.Guid UniqueId, string Name, string CharacterName, bool IsEnabled);
namespace CustomizePlus.Api;
public partial class CustomizePlusIpc
{
+ ///
+ /// Retrieve list of all user profiles
+ ///
+ ///
+ [EzIPC($"Profile.GetProfileList")]
+ private IList GetProfileList()
+ {
+ return _profileManager.Profiles
+ .Where(x => x.ProfileType == ProfileType.Normal)
+ .Select(x => (x.UniqueId, x.Name.Text, x.CharacterName.Text, x.Enabled))
+ .ToList();
+ }
+ ///
+ /// Enable profile using its Unique ID
+ ///
+ ///
+ [EzIPC($"Profile.EnableByUniqueId")]
+ private void EnableProfileByUniqueId(Guid uniqueId)
+ {
+ _profileManager.SetEnabled(uniqueId, true);
+ }
+
+ ///
+ /// Disable profile using its Unique ID
+ ///
+ [EzIPC($"Profile.DisableByUniqueId")]
+ private void DisableProfileByUniqueId(Guid uniqueId)
+ {
+ _profileManager.SetEnabled(uniqueId, false);
+ }
}
diff --git a/CustomizePlus/Api/CustomizePlusIpc.cs b/CustomizePlus/Api/CustomizePlusIpc.cs
index afcb2ea..8090540 100644
--- a/CustomizePlus/Api/CustomizePlusIpc.cs
+++ b/CustomizePlus/Api/CustomizePlusIpc.cs
@@ -1,4 +1,5 @@
using CustomizePlus.Core.Services;
+using CustomizePlus.Profiles;
using Dalamud.Plugin;
using ECommons.EzIpcManager;
using OtterGui.Log;
@@ -11,6 +12,7 @@ public partial class CustomizePlusIpc
private readonly DalamudPluginInterface _pluginInterface;
private readonly Logger _logger;
private readonly HookingService _hookingService;
+ private readonly ProfileManager _profileManager;
///
/// Shows if IPC failed to initialize or any other unrecoverable fatal error occured.
@@ -20,11 +22,13 @@ public partial class CustomizePlusIpc
public CustomizePlusIpc(
DalamudPluginInterface pluginInterface,
Logger logger,
- HookingService hookingService)
+ HookingService hookingService,
+ ProfileManager profileManager)
{
_pluginInterface = pluginInterface;
_logger = logger;
_hookingService = hookingService;
+ _profileManager = profileManager;
EzIPC.Init(this, "CustomizePlus");
}
diff --git a/CustomizePlus/Profiles/ProfileManager.cs b/CustomizePlus/Profiles/ProfileManager.cs
index 0e467ea..40d9146 100644
--- a/CustomizePlus/Profiles/ProfileManager.cs
+++ b/CustomizePlus/Profiles/ProfileManager.cs
@@ -292,6 +292,15 @@ public class ProfileManager : IDisposable
}
}
+ public void SetEnabled(Guid guid, bool value)
+ {
+ var profile = Profiles.FirstOrDefault(x => x.UniqueId == guid && x.ProfileType == ProfileType.Normal);
+ if (profile != null)
+ {
+ SetEnabled(profile, value);
+ }
+ }
+
public void SetLimitLookupToOwned(Profile profile, bool value)
{
if (profile.LimitLookupToOwnedObjects != value)
diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs
index 4826a39..e1c5318 100644
--- a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs
+++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs
@@ -13,6 +13,10 @@ using CustomizePlus.GameData.Services;
using Penumbra.GameData.Actors;
using ECommons.EzIpcManager;
using System;
+using System.Collections;
+using System.Collections.Generic;
+
+using IPCProfileDataTuple = (System.Guid UniqueId, string Name, string CharacterName, bool IsEnabled);
namespace CustomizePlus.UI.Windows.MainWindow.Tabs.Debug;
@@ -31,6 +35,15 @@ public class IPCTestTab //: IDisposable
[EzIPC("General.IsValid")]
private readonly Func _isValidIpcFunc;
+ [EzIPC("Profile.GetProfileList")]
+ private readonly Func> _getProfileListIpcFunc;
+
+ [EzIPC("Profile.EnableByUniqueId")]
+ private readonly Action _enableProfileByUniqueIdIpcFunc;
+
+ [EzIPC("Profile.DisableByUniqueId")]
+ private readonly Action _disableProfileByUniqueIdIpcFunc;
+
private readonly ICallGateSubscriber? _setCharacterProfile;
private readonly ICallGateSubscriber? _getProfileFromCharacter;
private readonly ICallGateSubscriber? _revertCharacter;
@@ -44,6 +57,8 @@ public class IPCTestTab //: IDisposable
private string? _targetCharacterName;
+ private string _targetProfileId = "";
+
public IPCTestTab(
DalamudPluginInterface pluginInterface,
IObjectTable objectTable,
@@ -100,6 +115,8 @@ public class IPCTestTab //: IDisposable
_lastValidCheckAt = DateTime.UtcNow;
}
+ ImGui.Separator();
+
//ImGui.Text($"Last profile update: {_lastProfileUpdate}, Character: {_lastProfileUpdateName}");
ImGui.Text($"Memory: {(string.IsNullOrWhiteSpace(_rememberedProfileJson) ? "empty" : "has data")}");
@@ -156,6 +173,30 @@ public class IPCTestTab //: IDisposable
_revertCharacter!.InvokeAction(FindCharacterByAddress(actors[0].Item2.Address));
_popupSystem.ShowPopup(PopupSystem.Messages.IPCRevertDone);
}
+
+ ImGui.Separator();
+
+ if (ImGui.Button("Copy user profile list to clipboard"))
+ {
+ ImGui.SetClipboardText(string.Join("\n", _getProfileListIpcFunc().Select(x => $"{x.UniqueId}, {x.Name}, {x.CharacterName}, {x.IsEnabled}")));
+ _popupSystem.ShowPopup(PopupSystem.Messages.IPCProfileListCopied);
+ }
+
+ ImGui.Text("Profile Unique ID to set:");
+ ImGui.SameLine();
+ ImGui.InputText("##profileguid", ref _targetProfileId, 128);
+
+ if (ImGui.Button("Enable profile by Unique ID"))
+ {
+ _enableProfileByUniqueIdIpcFunc(Guid.Parse(_targetProfileId));
+ _popupSystem.ShowPopup(PopupSystem.Messages.IPCEnableProfileByIdDone);
+ }
+
+ if (ImGui.Button("Disable profile by Unique ID"))
+ {
+ _disableProfileByUniqueIdIpcFunc(Guid.Parse(_targetProfileId));
+ _popupSystem.ShowPopup(PopupSystem.Messages.IPCDisableProfileByIdDone);
+ }
}
private Character? FindCharacterByAddress(nint address)
diff --git a/CustomizePlus/UI/Windows/PopupSystem.Messages.cs b/CustomizePlus/UI/Windows/PopupSystem.Messages.cs
index 0a51d0f..08caa93 100644
--- a/CustomizePlus/UI/Windows/PopupSystem.Messages.cs
+++ b/CustomizePlus/UI/Windows/PopupSystem.Messages.cs
@@ -14,6 +14,9 @@ public partial class PopupSystem
public const string IPCGetProfileFromChrRemembered = "ipc_get_profile_from_character_remembered";
public const string IPCSetProfileToChrDone = "ipc_set_profile_to_character_done";
public const string IPCRevertDone = "ipc_revert_done";
+ public const string IPCProfileListCopied = "ipc_profile_list_copied";
+ public const string IPCEnableProfileByIdDone = "ipc_enable_profile_by_id_done";
+ public const string IPCDisableProfileByIdDone = "ipc_disable_profile_by_id_done";
public const string TemplateEditorActiveWarning = "template_editor_active_warn";
public const string ClipboardDataUnsupported = "clipboard_data_unsupported_version";
@@ -31,6 +34,9 @@ public partial class PopupSystem
RegisterPopup(Messages.IPCGetProfileFromChrRemembered, "GetProfileFromCharacter result has been copied into memory");
RegisterPopup(Messages.IPCSetProfileToChrDone, "SetProfileToCharacter has been called with data from memory");
RegisterPopup(Messages.IPCRevertDone, "Revert has been called");
+ RegisterPopup(Messages.IPCProfileListCopied, "Profile list copied into clipboard");
+ RegisterPopup(Messages.IPCEnableProfileByIdDone, "Enable profile by id has been called");
+ RegisterPopup(Messages.IPCDisableProfileByIdDone, "Disable profile by id has been called");
RegisterPopup(Messages.TemplateEditorActiveWarning, "You need to stop bone editing before doing this action");
RegisterPopup(Messages.ClipboardDataUnsupported, "Clipboard data you are trying to use cannot be used in this version of Customize+.");