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

@@ -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);
/// <summary>
/// When there are breaking changes the first number is bumped up and second one is reset.

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>

View File

@@ -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;