diff --git a/CustomizePlus/Api/CustomizePlusIpc.General.cs b/CustomizePlus/Api/CustomizePlusIpc.General.cs index 146a25b..463426e 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.General.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.General.cs @@ -4,7 +4,7 @@ namespace CustomizePlus.Api; public partial class CustomizePlusIpc { - private readonly (int Breaking, int Feature) _apiVersion = (6, 0); + private readonly (int Breaking, int Feature) _apiVersion = (6, 1); /// /// When there are breaking changes the first number is bumped up and second one is reset. diff --git a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs index f16543e..35d5acc 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs @@ -18,6 +18,7 @@ using Penumbra.GameData.Enums; using CustomizePlus.Templates.Data; using CustomizePlus.Templates.Events; using Penumbra.GameData.Actors; +using Penumbra.String; namespace CustomizePlus.Api; @@ -99,6 +100,70 @@ public partial class CustomizePlusIpc } } + /// + /// Adds a player character to a specified profile. + /// + [EzIPC("Profile.AddPlayerCharacter")] + private int AddPlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId) + { + if (uniqueId == Guid.Empty) + { + return (int)ErrorCode.ProfileNotFound; + } + + var profile = this._profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); + if (profile == null) + { + return (int)ErrorCode.ProfileNotFound; + } + + if (!ByteString.FromString(name, out var byteString)) + { + return (int)ErrorCode.InvalidCharacter; + } + + var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId); + if (playerIdentifier == ActorIdentifier.Invalid) + { + return (int)ErrorCode.InvalidCharacter; + } + + this._profileManager.AddCharacter(profile, playerIdentifier); + return (int)ErrorCode.Success; + } + + /// + /// Removes a player character to a specified profile. + /// + [EzIPC("Profile.RemovePlayerCharacter")] + private int RemovePlayerCharacterToProfile(Guid uniqueId, string name, ushort worldId) + { + if (uniqueId == Guid.Empty) + { + return (int)ErrorCode.ProfileNotFound; + } + + var profile = this._profileManager.Profiles.FirstOrDefault(x => x.UniqueId == uniqueId && !x.IsTemporary); + if (profile == null) + { + return (int)ErrorCode.ProfileNotFound; + } + + if (!ByteString.FromString(name, out var byteString)) + { + return (int)ErrorCode.InvalidCharacter; + } + + var playerIdentifier = this._actorManager.CreatePlayer(byteString, worldId); + if (playerIdentifier == ActorIdentifier.Invalid) + { + return (int)ErrorCode.InvalidCharacter; + } + + this._profileManager.DeleteCharacter(profile, playerIdentifier); + return (int)ErrorCode.Success; + } + /// /// Enable profile using its Unique ID. Does not work on temporary profiles. /// diff --git a/CustomizePlus/Api/CustomizePlusIpc.cs b/CustomizePlus/Api/CustomizePlusIpc.cs index 33e60cd..b686148 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.cs @@ -10,6 +10,7 @@ using Dalamud.Plugin; using ECommonsLite.EzIpcManager; using OtterGui.Log; using System; +using Penumbra.GameData.Actors; namespace CustomizePlus.Api; @@ -26,6 +27,7 @@ public partial class CustomizePlusIpc : IDisposable private readonly Logger _logger; private readonly HookingService _hookingService; private readonly ProfileManager _profileManager; + private readonly ActorManager _actorManager; private readonly GameObjectService _gameObjectService; private readonly ProfileFileSystem _profileFileSystem; private readonly CutsceneService _cutsceneService; @@ -43,6 +45,7 @@ public partial class CustomizePlusIpc : IDisposable Logger logger, HookingService hookingService, ProfileManager profileManager, + ActorManager actorManager, GameObjectService gameObjectService, ProfileFileSystem profileFileSystem, CutsceneService cutsceneService, @@ -53,6 +56,7 @@ public partial class CustomizePlusIpc : IDisposable _logger = logger; _hookingService = hookingService; _profileManager = profileManager; + _actorManager = actorManager; _gameObjectService = gameObjectService; _profileFileSystem = profileFileSystem; _cutsceneService = cutsceneService;