Add IPC for Adding and Removing characters from a profile

This commit is contained in:
Caraxi
2025-04-18 10:33:53 +09:30
parent 8ea4cb6772
commit e225a788a7
3 changed files with 70 additions and 1 deletions

View File

@@ -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
}
}
/// <summary>
/// Adds a player character to a specified profile.
/// </summary>
[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;
}
/// <summary>
/// Removes a player character to a specified profile.
/// </summary>
[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;
}
/// <summary>
/// Enable profile using its Unique ID. Does not work on temporary profiles.
/// </summary>