diff --git a/CustomizePlus/Api/Compatibility/CustomizePlusLegacyIpc.cs b/CustomizePlus/Api/Compatibility/CustomizePlusLegacyIpc.cs deleted file mode 100644 index 40ec55c..0000000 --- a/CustomizePlus/Api/Compatibility/CustomizePlusLegacyIpc.cs +++ /dev/null @@ -1,299 +0,0 @@ -using Dalamud.Plugin.Services; -using Dalamud.Plugin; -using System; -using System.Text; -using OtterGui.Log; -using Newtonsoft.Json; -using System.IO.Compression; -using System.IO; -using Dalamud.Plugin.Ipc; -using Dalamud.Game.ClientState.Objects.Types; -using CustomizePlus.Configuration.Helpers; -using CustomizePlus.Profiles; -using CustomizePlus.Configuration.Data.Version3; -using CustomizePlus.Profiles.Data; -using CustomizePlus.Game.Services; -using CustomizePlus.Templates.Events; -using CustomizePlus.Profiles.Events; -using CustomizePlus.Templates.Data; -using CustomizePlus.GameData.Data; -using CustomizePlus.Core.Extensions; -using CustomizePlus.Armatures.Events; -using CustomizePlus.Armatures.Data; -using CustomizePlus.GameData.Extensions; -using Penumbra.GameData.Interop; -using CustomizePlus.Profiles.Exceptions; - -namespace CustomizePlus.Api.Compatibility; - -[Obsolete("Will be removed in the near future, do not use this IPC")] -public class CustomizePlusLegacyIpc : IDisposable -{ - private readonly IObjectTable _objectTable; - private readonly DalamudPluginInterface _pluginInterface; - private readonly Logger _logger; - private readonly ProfileManager _profileManager; - private readonly GameObjectService _gameObjectService; - - private readonly ProfileChanged _profileChangedEvent; - private readonly ArmatureChanged _armatureChangedEvent; - - private const int _configurationVersion = 3; - - public const string ProviderApiVersionLabel = $"CustomizePlus.{nameof(GetApiVersion)}"; - public const string GetProfileFromCharacterLabel = $"CustomizePlus.{nameof(GetProfileFromCharacter)}"; - public const string SetProfileToCharacterLabel = $"CustomizePlus.{nameof(SetProfileToCharacter)}"; - public const string RevertCharacterLabel = $"CustomizePlus.{nameof(RevertCharacter)}"; - public const string OnProfileUpdateLabel = $"CustomizePlus.{nameof(OnProfileUpdate)}"; - public static readonly (int, int) ApiVersion = (3, 0); - - //Sends local player's profile every time their active profile is changed - //If no profile is applied sends null - internal ICallGateProvider? ProviderOnProfileUpdate; - internal ICallGateProvider? ProviderRevertCharacter; - internal ICallGateProvider? ProviderSetProfileToCharacter; - internal ICallGateProvider? ProviderGetProfileFromCharacter; - internal ICallGateProvider<(int, int)>? ProviderGetApiVersion; - - public CustomizePlusLegacyIpc( - IObjectTable objectTable, - DalamudPluginInterface pluginInterface, - Logger logger, - ProfileManager profileManager, - GameObjectService gameObjectService, - ArmatureChanged armatureChangedEvent, - ProfileChanged profileChangedEvent) - { - _objectTable = objectTable; - _pluginInterface = pluginInterface; - _logger = logger; - _profileManager = profileManager; - _gameObjectService = gameObjectService; - _profileChangedEvent = profileChangedEvent; - _armatureChangedEvent = armatureChangedEvent; - - InitializeProviders(); - - _profileChangedEvent.Subscribe(OnProfileChange, ProfileChanged.Priority.CustomizePlusLegacyIpc); - _armatureChangedEvent.Subscribe(OnArmatureChanged, ArmatureChanged.Priority.CustomizePlusIpc); - } - - public void Dispose() - { - _profileChangedEvent.Unsubscribe(OnProfileChange); - _armatureChangedEvent.Unsubscribe(OnArmatureChanged); - DisposeProviders(); - } - - //warn: limitation - ignores default profiles but why you would use default profile on your own character - private void OnProfileChange(ProfileChanged.Type type, Profile? profile, object? arg3) - { - if (type != ProfileChanged.Type.AddedTemplate && - type != ProfileChanged.Type.RemovedTemplate && - type != ProfileChanged.Type.MovedTemplate && - type != ProfileChanged.Type.ChangedTemplate) - return; - - if (profile == null || - !profile.Enabled || - profile.CharacterName.Text != _gameObjectService.GetCurrentPlayerName()) - return; - - OnProfileUpdate(profile); - } - - private void OnArmatureChanged(ArmatureChanged.Type type, Armature armature, object? arg3) - { - string currentPlayerName = _gameObjectService.GetCurrentPlayerName(); - - if (armature.ActorIdentifier.ToNameWithoutOwnerName() != currentPlayerName) - return; - - if (type == ArmatureChanged.Type.Created || - type == ArmatureChanged.Type.Updated) - { - if(armature.Profile == null) - _logger.Warning("[LEGACY IPC DO NOT USE] Armature created/rebound and profile is null"); - - OnProfileUpdate(armature.Profile); - return; - } - - if(type == ArmatureChanged.Type.Deleted) - { - OnProfileUpdate(null); - return; - } - } - - private void InitializeProviders() - { - _logger.Debug("[LEGACY IPC DO NOT USE] Initializing legacy Customize+ IPC providers."); - try - { - ProviderGetApiVersion = _pluginInterface.GetIpcProvider<(int, int)>(ProviderApiVersionLabel); - ProviderGetApiVersion.RegisterFunc(GetApiVersion); - } - catch (Exception ex) - { - _logger.Error($"[LEGACY IPC DO NOT USE] Error registering legacy Customize+ IPC provider for {ProviderApiVersionLabel}: {ex}"); - } - - try - { - ProviderGetProfileFromCharacter = - _pluginInterface.GetIpcProvider(GetProfileFromCharacterLabel); - ProviderGetProfileFromCharacter.RegisterFunc(GetProfileFromCharacter); - } - catch (Exception ex) - { - _logger.Error($"[LEGACY IPC DO NOT USE] Error registering legacy Customize+ IPC provider for {GetProfileFromCharacterLabel}: {ex}"); - } - - try - { - ProviderSetProfileToCharacter = - _pluginInterface.GetIpcProvider(SetProfileToCharacterLabel); - ProviderSetProfileToCharacter.RegisterAction(SetProfileToCharacter); - } - catch (Exception ex) - { - _logger.Error($"[LEGACY IPC DO NOT USE] Error registering legacy Customize+ IPC provider for {SetProfileToCharacterLabel}: {ex}"); - } - - try - { - ProviderRevertCharacter = - _pluginInterface.GetIpcProvider(RevertCharacterLabel); - ProviderRevertCharacter.RegisterAction(RevertCharacter); - } - catch (Exception ex) - { - _logger.Error($"[LEGACY IPC DO NOT USE] Error registering legacy Customize+ IPC provider for {RevertCharacterLabel}: {ex}"); - } - - try - { - ProviderOnProfileUpdate = _pluginInterface.GetIpcProvider(OnProfileUpdateLabel); - } - catch (Exception ex) - { - _logger.Error($"[LEGACY IPC DO NOT USE] Error registering legacy Customize+ IPC provider for {OnProfileUpdateLabel}: {ex}"); - } - } - - private void DisposeProviders() - { - ProviderGetProfileFromCharacter?.UnregisterFunc(); - ProviderSetProfileToCharacter?.UnregisterAction(); - ProviderRevertCharacter?.UnregisterAction(); - ProviderGetApiVersion?.UnregisterFunc(); - ProviderOnProfileUpdate?.UnregisterFunc(); - } - - private void OnProfileUpdate(Profile? profile) - { - _logger.Debug($"[LEGACY IPC DO NOT USE] Sending local player update message: {(profile != null ? profile.ToString() : "no profile")}"); - - var convertedProfile = profile != null ? GetVersion3Profile(profile) : null; - - ProviderOnProfileUpdate?.SendMessage(convertedProfile?.CharacterName ?? null, convertedProfile == null ? null : JsonConvert.SerializeObject(convertedProfile)); - } - - private static (int, int) GetApiVersion() - { - return ApiVersion; - } - - private string? GetCharacterProfile(string characterName) - { - var profile = _profileManager.GetProfileByCharacterName(characterName, true); - - var convertedProfile = profile != null ? GetVersion3Profile(profile) : null; - - return convertedProfile != null ? JsonConvert.SerializeObject(convertedProfile) : null; - } - - private string? GetProfileFromCharacter(Character? character) - { - return character == null ? null : GetCharacterProfile(character.Name.ToString()); - } - - private void SetProfileToCharacter(string profileJson, Character? character) - { - if (character == null) - return; - - var actor = (Actor)character.Address; - if (!actor.Valid) - return; - - /*if (character == _objectTable[0]) - { - _logger.Error($"Received request to set profile on local character, this is not allowed"); - return; - }*/ - - try - { - var profile = JsonConvert.DeserializeObject(profileJson); - if (profile != null) - { - if (profile.ConfigVersion != _configurationVersion) - throw new Exception("Incompatible version"); - - _profileManager.AddTemporaryProfile(GetProfileFromVersion3(profile).Item1, actor); - } - } - catch (Exception ex) - { - _logger.Warning($"[LEGACY IPC DO NOT USE] Unable to set body profile. Character: {character?.Name}, exception: {ex}, debug data: {GetBase64String(profileJson)}"); - } - } - - private void RevertCharacter(Character? character) - { - if (character == null) - return; - - var actor = (Actor)character.Address; - if (!actor.Valid) - return; - - /*if (character == _objectTable[0]) - { - _logger.Error($"Received request to revert profile on local character, this is not allowed"); - return; - }*/ - - try - { - _profileManager.RemoveTemporaryProfile(actor); - } - catch (Exception ex) - { - _logger.Warning($"[LEGACY IPC DO NOT USE] Unable to revert character. Character: {character?.Name}, exception: {ex}"); - } - } - - private string GetBase64String(string data) - { - var json = JsonConvert.SerializeObject(data, Formatting.None); - var bytes = Encoding.UTF8.GetBytes(json); - using var compressedStream = new MemoryStream(); - using (var zipStream = new GZipStream(compressedStream, CompressionMode.Compress)) - zipStream.Write(bytes, 0, bytes.Length); - - return Convert.ToBase64String(compressedStream.ToArray()); - } - - private Version3Profile GetVersion3Profile(Profile profile) - { - return V4ProfileToV3Converter.Convert(profile); - } - - private (Profile, Template) GetProfileFromVersion3(Version3Profile profile) - { - return V3ProfileToV4Converter.Convert(profile); - } -} diff --git a/CustomizePlus/Configuration/Helpers/V4ProfileToV3Converter.cs b/CustomizePlus/Configuration/Helpers/V4ProfileToV3Converter.cs deleted file mode 100644 index 58d845b..0000000 --- a/CustomizePlus/Configuration/Helpers/V4ProfileToV3Converter.cs +++ /dev/null @@ -1,39 +0,0 @@ -using CustomizePlus.Configuration.Data.Version3; -using CustomizePlus.Profiles.Data; -using System; -using System.Collections.Generic; - -namespace CustomizePlus.Configuration.Helpers; - -internal static class V4ProfileToV3Converter -{ - public static Version3Profile Convert(Profile v4Profile) - { - var profile = new Version3Profile - { - ProfileName = v4Profile.Name, - CharacterName = v4Profile.CharacterName, - CreationDate = v4Profile.CreationDate.DateTime, - ModifiedDate = DateTime.UtcNow, - Enabled = v4Profile.Enabled, - OwnedOnly = v4Profile.LimitLookupToOwnedObjects, - ConfigVersion = 3, - Bones = new Dictionary() - }; - - foreach (var template in v4Profile.Templates) - { - foreach (var kvPair in template.Bones) //not super optimal but whatever - { - profile.Bones[kvPair.Key] = new V3BoneTransform - { - Translation = kvPair.Value.Translation, - Rotation = kvPair.Value.Rotation, - Scaling = kvPair.Value.Scaling - }; - } - } - - return profile; - } -} diff --git a/CustomizePlus/Core/ServiceManagerBuilder.cs b/CustomizePlus/Core/ServiceManagerBuilder.cs index 51b4ae5..b5d28f8 100644 --- a/CustomizePlus/Core/ServiceManagerBuilder.cs +++ b/CustomizePlus/Core/ServiceManagerBuilder.cs @@ -23,16 +23,13 @@ using CustomizePlus.UI.Windows; using CustomizePlus.UI.Windows.MainWindow.Tabs; using CustomizePlus.Templates.Events; using CustomizePlus.Profiles.Events; -using CustomizePlus.Api.Compatibility; using CustomizePlus.Game.Services.GPose; using CustomizePlus.Game.Services.GPose.ExternalTools; using CustomizePlus.GameData.Services; using CustomizePlus.Configuration.Services.Temporary; using OtterGui.Services; using Penumbra.GameData.Actors; -using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; -using OtterGui; using OtterGui.Raii; using CustomizePlus.Api; @@ -156,7 +153,6 @@ public static class ServiceManagerBuilder private static ServiceManager AddApi(this ServiceManager services) { services - .AddSingleton() .AddSingleton(); return services; diff --git a/CustomizePlus/Plugin.cs b/CustomizePlus/Plugin.cs index af8326a..4bc0456 100644 --- a/CustomizePlus/Plugin.cs +++ b/CustomizePlus/Plugin.cs @@ -1,12 +1,10 @@ using System; using System.Reflection; using Dalamud.Plugin; -using Microsoft.Extensions.DependencyInjection; using OtterGui.Log; using CustomizePlus.Core.Services; using CustomizePlus.UI; using CustomizePlus.Core; -using CustomizePlus.Api.Compatibility; using CustomizePlus.Configuration.Services.Temporary; using OtterGui.Services; using CustomizePlus.Api; @@ -39,7 +37,6 @@ public sealed class Plugin : IDalamudPlugin v3ConfigFixer.FixV3ConfigIfNeeded(); _services.GetService(); - _services.GetService(); _services.GetService(); _services.GetService(); diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs index e7ea908..b78b511 100644 --- a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs +++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs @@ -147,23 +147,6 @@ public class IPCTestTab //: IDisposable ImGui.SameLine(); ImGui.InputText("##operateon", ref _targetCharacterName, 128); - if (ImGui.Button("Copy current profile into memory as V3")) - { - var actors = _gameObjectService.FindActorsByName(_targetCharacterName).ToList(); - if (actors.Count == 0) - return; - - if (!actors[0].Item2.Identifier(_actorManager, out var identifier)) - return; - - var profile = _profileManager.GetEnabledProfilesByActor(identifier).FirstOrDefault(); - if (profile == null) - return; - - _rememberedProfileJson = JsonConvert.SerializeObject(V4ProfileToV3Converter.Convert(profile)); - _popupSystem.ShowPopup(PopupSystem.Messages.IPCV4ProfileRemembered); - } - if (ImGui.Button("GetActiveProfileIdOnCharacter into clipboard")) { var actors = _gameObjectService.FindActorsByName(_targetCharacterName).ToList(); @@ -255,7 +238,7 @@ public class IPCTestTab //: IDisposable if (result == 0) { _rememberedProfileJson = profileJson; - _popupSystem.ShowPopup(PopupSystem.Messages.IPCV4ProfileRemembered); + _popupSystem.ShowPopup(PopupSystem.Messages.IPCProfileRemembered); } else { diff --git a/CustomizePlus/UI/Windows/PopupSystem.Messages.cs b/CustomizePlus/UI/Windows/PopupSystem.Messages.cs index 7c66bb4..a968c7f 100644 --- a/CustomizePlus/UI/Windows/PopupSystem.Messages.cs +++ b/CustomizePlus/UI/Windows/PopupSystem.Messages.cs @@ -10,7 +10,7 @@ public partial class PopupSystem public const string FantasiaPlusDetected = "fantasia_detected_warn"; - public const string IPCV4ProfileRemembered = "ipc_v4_profile_remembered"; + public const string IPCProfileRemembered = "ipc_profile_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"; @@ -30,7 +30,7 @@ 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.IPCProfileRemembered, "Current profile 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, "DeleteTemporaryProfileByUniqueId has been called");