From 849b5c19dea4159b76a87e449d06145b9c2e5547 Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Mon, 18 Mar 2024 04:46:08 +0300 Subject: [PATCH] Profile.GetCurrentlyActiveProfileOnCharacter -> Profile.GetActiveProfileIdOnCharacter (now returns profile id instead of profile contents), Profile.GetProfileById -> Profile.GetProfileByUniqueId --- CustomizePlus/Api/CustomizePlusIpc.Profile.cs | 28 ++++----------- .../MainWindow/Tabs/Debug/IPCTestTab.cs | 34 ++++++++++++++----- .../UI/Windows/PopupSystem.Messages.cs | 6 ++-- 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs index ab26d81..02f8169 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs @@ -49,8 +49,8 @@ public partial class CustomizePlusIpc /// /// Get JSON copy of profile with specified unique id /// - [EzIPC("Profile.GetProfileById")] - private (int, string?) GetProfileById(Guid uniqueId) + [EzIPC("Profile.GetProfileByUniqueId")] + private (int, string?) GetProfileByUniqueId(Guid uniqueId) { if (uniqueId == Guid.Empty) return ((int)ErrorCode.ProfileNotFound, null); @@ -120,10 +120,10 @@ public partial class CustomizePlusIpc } /// - /// Get JSON copy of active profile for character. + /// Get unique id of currently active profile for character. /// - [EzIPC("Profile.GetCurrentlyActiveProfileOnCharacter")] - private (int, string?) GetCurrentlyActiveProfileOnCharacter(Character character) + [EzIPC("Profile.GetActiveProfileIdOnCharacter")] + private (int, Guid?) GetActiveProfileIdOnCharacter(Character character) { if (character == null) return ((int)ErrorCode.InvalidCharacter, null); @@ -133,23 +133,7 @@ public partial class CustomizePlusIpc if (profile == null) return ((int)ErrorCode.ProfileNotFound, null); - var convertedProfile = IPCCharacterProfile.FromFullProfile(profile); - - if (convertedProfile == null) - { - _logger.Error($"IPCCharacterProfile.FromFullProfile returned empty converted profile for character {character?.Name.ToString().Incognify()}, profile: {profile.UniqueId}"); - return ((int)ErrorCode.UnknownError, null); - } - - try - { - return ((int)ErrorCode.Success, JsonConvert.SerializeObject(convertedProfile)); - } - catch(Exception ex) - { - _logger.Error($"Exception in IPCCharacterProfile.FromFullProfile for character {character?.Name.ToString().Incognify()}, profile: {profile.UniqueId}: {ex}"); - return ((int)ErrorCode.UnknownError, null); - } + return ((int)ErrorCode.Success, profile.UniqueId); } /// diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs index 5f4e3ea..a7cd82d 100644 --- a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs +++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs @@ -47,8 +47,8 @@ public class IPCTestTab //: IDisposable [EzIPC("Profile.DisableByUniqueId")] private readonly Action _disableProfileByUniqueIdIpcFunc; - [EzIPC("Profile.GetCurrentlyActiveProfileOnCharacter")] - private readonly Func _getCurrentlyActiveProfileOnCharacterIpcFunc; + [EzIPC("Profile.GetActiveProfileIdOnCharacter")] + private readonly Func _getActiveProfileIdOnCharacterIpcFunc; [EzIPC("Profile.SetTemporaryProfileOnCharacter")] private readonly Func _setTemporaryProfileOnCharacterIpcFunc; @@ -59,7 +59,7 @@ public class IPCTestTab //: IDisposable [EzIPC("Profile.DeleteTemporaryProfileByUniqueId")] private readonly Func _deleteTemporaryProfileByUniqueIdIpcFunc; - [EzIPC("Profile.GetProfileById")] + [EzIPC("Profile.GetProfileByUniqueId")] private readonly Func _getProfileByIdIpcFunc; //private readonly ICallGateSubscriber? _setCharacterProfile; @@ -161,16 +161,19 @@ public class IPCTestTab //: IDisposable _popupSystem.ShowPopup(PopupSystem.Messages.IPCV4ProfileRemembered); } - if (ImGui.Button("GetCurrentlyActiveProfileOnCharacter into memory")) + if (ImGui.Button("GetActiveProfileIdOnCharacter into clipboard")) { var actors = _gameObjectService.FindActorsByName(_targetCharacterName).ToList(); if (actors.Count == 0) return; - (int result, _rememberedProfileJson) = _getCurrentlyActiveProfileOnCharacterIpcFunc(FindCharacterByAddress(actors[0].Item2.Address)); + (int result, Guid? uniqueId) = _getActiveProfileIdOnCharacterIpcFunc(FindCharacterByAddress(actors[0].Item2.Address)); if(result == 0) - _popupSystem.ShowPopup(PopupSystem.Messages.IPCGetProfileFromChrRemembered); + { + ImGui.SetClipboardText(uniqueId.ToString()); + _popupSystem.ShowPopup(PopupSystem.Messages.IPCCopiedToClipboard); + } else { _logger.Error($"Error code {result} while calling GetCurrentlyActiveProfileOnCharacter"); @@ -186,7 +189,7 @@ public class IPCTestTab //: IDisposable if (actors.Count == 0) return; - (int result, Guid? profileGuid) = _setTemporaryProfileOnCharacterIpcFunc(FindCharacterByAddress(actors[0].Item2.Address),_rememberedProfileJson); + (int result, Guid? profileGuid) = _setTemporaryProfileOnCharacterIpcFunc(FindCharacterByAddress(actors[0].Item2.Address), _rememberedProfileJson); if (result == 0) { _popupSystem.ShowPopup(PopupSystem.Messages.IPCSetProfileToChrDone); @@ -228,7 +231,7 @@ public class IPCTestTab //: IDisposable ImGui.SameLine(); ImGui.InputText("##profileguid", ref _targetProfileId, 128); - if (ImGui.Button("Get profile by Unique ID")) + if (ImGui.Button("Get profile by Unique ID into clipboard")) { (int result, string? profileJson) = _getProfileByIdIpcFunc(Guid.Parse(_targetProfileId)); if (result == 0) @@ -243,6 +246,21 @@ public class IPCTestTab //: IDisposable } } + if (ImGui.Button("Get profile by Unique ID into memory")) + { + (int result, string? profileJson) = _getProfileByIdIpcFunc(Guid.Parse(_targetProfileId)); + if (result == 0) + { + _rememberedProfileJson = profileJson; + _popupSystem.ShowPopup(PopupSystem.Messages.IPCV4ProfileRemembered); + } + else + { + _logger.Error($"Error code {result} while calling GetProfileById"); + _popupSystem.ShowPopup(PopupSystem.Messages.ActionError); + } + } + if (ImGui.Button("Enable profile by Unique ID")) { _enableProfileByUniqueIdIpcFunc(Guid.Parse(_targetProfileId)); diff --git a/CustomizePlus/UI/Windows/PopupSystem.Messages.cs b/CustomizePlus/UI/Windows/PopupSystem.Messages.cs index 9fec7f3..7c66bb4 100644 --- a/CustomizePlus/UI/Windows/PopupSystem.Messages.cs +++ b/CustomizePlus/UI/Windows/PopupSystem.Messages.cs @@ -11,7 +11,7 @@ public partial class PopupSystem public const string FantasiaPlusDetected = "fantasia_detected_warn"; public const string IPCV4ProfileRemembered = "ipc_v4_profile_remembered"; - public const string IPCGetProfileFromChrRemembered = "ipc_get_profile_from_character_remembered"; + public const string IPCGetProfileByIdRemembered = "ipc_get_profile_by_id_remembered"; public const string IPCSetProfileToChrDone = "ipc_set_profile_to_character_done"; public const string IPCRevertDone = "ipc_revert_done"; public const string IPCCopiedToClipboard = "ipc_copied_to clipboard"; @@ -31,9 +31,9 @@ public partial class PopupSystem RegisterPopup(Messages.FantasiaPlusDetected, "Customize+ detected that you have Fantasia+ installed.\nPlease delete or turn it off and restart your game to use Customize+."); RegisterPopup(Messages.IPCV4ProfileRemembered, "Current profile has been copied into memory"); - RegisterPopup(Messages.IPCGetProfileFromChrRemembered, "GetProfileFromCharacter result has been copied into memory"); + RegisterPopup(Messages.IPCGetProfileByIdRemembered, "GetProfileByUniqueId result has been copied into memory"); RegisterPopup(Messages.IPCSetProfileToChrDone, "SetProfileToCharacter has been called with data from memory, profile id printed to log"); - RegisterPopup(Messages.IPCRevertDone, "Revert has been called"); + RegisterPopup(Messages.IPCRevertDone, "DeleteTemporaryProfileByUniqueId has been called"); RegisterPopup(Messages.IPCCopiedToClipboard, "Copied into clipboard"); RegisterPopup(Messages.IPCEnableProfileByIdDone, "Enable profile by id has been called"); RegisterPopup(Messages.IPCDisableProfileByIdDone, "Disable profile by id has been called");