update customize+ ipc

Co-authored-by: Stanley Dimant <root.darkarchon@outlook.com>
This commit is contained in:
Loporrit
2024-05-28 22:08:05 +00:00
parent 8e2f17b25d
commit ec3633de13
3 changed files with 61 additions and 25 deletions

View File

@@ -21,10 +21,12 @@ namespace MareSynchronos.Interop;
public sealed class IpcManager : DisposableMediatorSubscriberBase public sealed class IpcManager : DisposableMediatorSubscriberBase
{ {
private readonly ICallGateSubscriber<(int, int)> _customizePlusApiVersion; private readonly ICallGateSubscriber<(int, int)> _customizePlusApiVersion;
private readonly ICallGateSubscriber<Character?, string?> _customizePlusGetBodyScale; private readonly ICallGateSubscriber<Character, (int, Guid?)> _customizePlusGetActiveProfile;
private readonly ICallGateSubscriber<string?, string?, object> _customizePlusOnScaleUpdate; private readonly ICallGateSubscriber<Guid, (int, string?)> _customizePlusGetProfileById;
private readonly ICallGateSubscriber<Character?, object> _customizePlusRevertCharacter; private readonly ICallGateSubscriber<Character, Guid, object> _customizePlusOnScaleUpdate;
private readonly ICallGateSubscriber<string, Character?, object> _customizePlusSetBodyScaleToCharacter; private readonly ICallGateSubscriber<Character, int> _customizePlusRevertCharacter;
private readonly ICallGateSubscriber<Character, string, (int, Guid?)> _customizePlusSetBodyScaleToCharacter;
private readonly ICallGateSubscriber<Guid, int> _customizePlusDeleteByUniqueId;
private readonly DalamudPluginInterface _pi; private readonly DalamudPluginInterface _pi;
private readonly DalamudUtilService _dalamudUtil; private readonly DalamudUtilService _dalamudUtil;
private readonly Glamourer.Api.IpcSubscribers.ApiVersion _glamourerApiVersions; private readonly Glamourer.Api.IpcSubscribers.ApiVersion _glamourerApiVersions;
@@ -160,11 +162,13 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
_heelsOffsetUpdate.Subscribe(HeelsOffsetChange); _heelsOffsetUpdate.Subscribe(HeelsOffsetChange);
_customizePlusApiVersion = pi.GetIpcSubscriber<(int, int)>("CustomizePlus.GetApiVersion"); _customizePlusApiVersion = pi.GetIpcSubscriber<(int, int)>("CustomizePlus.General.GetApiVersion");
_customizePlusGetBodyScale = pi.GetIpcSubscriber<Character?, string?>("CustomizePlus.GetProfileFromCharacter"); _customizePlusGetActiveProfile = pi.GetIpcSubscriber<Character, (int, Guid?)>("CustomizePlus.Profile.GetActiveProfileIdOnCharacter");
_customizePlusRevertCharacter = pi.GetIpcSubscriber<Character?, object>("CustomizePlus.RevertCharacter"); _customizePlusGetProfileById = pi.GetIpcSubscriber<Guid, (int, string?)>("CustomizePlus.Profile.GetByUniqueId");
_customizePlusSetBodyScaleToCharacter = pi.GetIpcSubscriber<string, Character?, object>("CustomizePlus.SetProfileToCharacter"); _customizePlusRevertCharacter = pi.GetIpcSubscriber<Character, int>("CustomizePlus.Profile.DeleteTemporaryProfileOnCharacter");
_customizePlusOnScaleUpdate = pi.GetIpcSubscriber<string?, string?, object>("CustomizePlus.OnProfileUpdate"); _customizePlusSetBodyScaleToCharacter = pi.GetIpcSubscriber<Character, string, (int, Guid?)>("CustomizePlus.Profile.SetTemporaryProfileOnCharacter");
_customizePlusOnScaleUpdate = pi.GetIpcSubscriber<Character, Guid, object>("CustomizePlus.Profile.OnUpdate");
_customizePlusDeleteByUniqueId = pi.GetIpcSubscriber<Guid, int>("CustomizePlus.Profile.DeleteTemporaryProfileByUniqueId");
_customizePlusOnScaleUpdate.Subscribe(OnCustomizePlusScaleChange); _customizePlusOnScaleUpdate.Subscribe(OnCustomizePlusScaleChange);
@@ -235,10 +239,19 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
public async Task CustomizePlusSetBodyScaleAsync(IntPtr character, string scale) public async Task CustomizePlusRevertByIdAsync(Guid? profileId)
{ {
if (!CheckCustomizePlusApi()) return; if (!CheckCustomizePlusApi() || profileId == null) return;
await _dalamudUtil.RunOnFrameworkThread(() => await _dalamudUtil.RunOnFrameworkThread(() =>
{
_ = _customizePlusDeleteByUniqueId.InvokeFunc(profileId.Value);
}).ConfigureAwait(false);
}
public async Task<Guid?> CustomizePlusSetBodyScaleAsync(IntPtr character, string scale)
{
if (!CheckCustomizePlusApi()) return null;
return await _dalamudUtil.RunOnFrameworkThread(() =>
{ {
var gameObj = _dalamudUtil.CreateGameObject(character); var gameObj = _dalamudUtil.CreateGameObject(character);
if (gameObj is Character c) if (gameObj is Character c)
@@ -248,12 +261,16 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
if (scale.IsNullOrEmpty()) if (scale.IsNullOrEmpty())
{ {
_customizePlusRevertCharacter!.InvokeAction(c); _customizePlusRevertCharacter!.InvokeAction(c);
return null;
} }
else else
{ {
_customizePlusSetBodyScaleToCharacter!.InvokeAction(decodedScale, c); var result = _customizePlusSetBodyScaleToCharacter!.InvokeFunc(c, decodedScale);
return result.Item2;
} }
} }
return null;
}).ConfigureAwait(false); }).ConfigureAwait(false);
} }
@@ -265,7 +282,10 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
var gameObj = _dalamudUtil.CreateGameObject(character); var gameObj = _dalamudUtil.CreateGameObject(character);
if (gameObj is Character c) if (gameObj is Character c)
{ {
return _customizePlusGetBodyScale.InvokeFunc(c); var res = _customizePlusGetActiveProfile.InvokeFunc(c);
Logger.LogTrace("CustomizePlus GetActiveProfile returned {err}", res.Item1);
if (res.Item1 != 0 || res.Item2 == null) return string.Empty;
return _customizePlusGetProfileById.InvokeFunc(res.Item2.Value).Item2;
} }
return string.Empty; return string.Empty;
@@ -701,7 +721,7 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
try try
{ {
var version = _customizePlusApiVersion.InvokeFunc(); var version = _customizePlusApiVersion.InvokeFunc();
if (version.Item1 == 3 && version.Item2 >= 0) return true; if (version.Item1 == 4 && version.Item2 >= 0) return true;
return false; return false;
} }
catch catch
@@ -828,9 +848,9 @@ public sealed class IpcManager : DisposableMediatorSubscriberBase
Mediator.Publish(new HeelsOffsetMessage()); Mediator.Publish(new HeelsOffsetMessage());
} }
private void OnCustomizePlusScaleChange(string? profileName, string? scale) private void OnCustomizePlusScaleChange(Character c, Guid g)
{ {
Mediator.Publish(new CustomizePlusMessage(profileName ?? string.Empty)); Mediator.Publish(new CustomizePlusMessage(c.Name.ToString() ?? string.Empty));
} }
private void OnHonorificDisposing() private void OnHonorificDisposing()

View File

@@ -10,6 +10,7 @@ using MareSynchronos.Services;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
using MareSynchronos.Utils; using MareSynchronos.Utils;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Text;
using CharacterData = MareSynchronos.API.Data.CharacterData; using CharacterData = MareSynchronos.API.Data.CharacterData;
namespace MareSynchronos.PlayerData.Export; namespace MareSynchronos.PlayerData.Export;
@@ -21,6 +22,7 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
private readonly MareCharaFileDataFactory _factory; private readonly MareCharaFileDataFactory _factory;
private readonly GameObjectHandlerFactory _gameObjectHandlerFactory; private readonly GameObjectHandlerFactory _gameObjectHandlerFactory;
private readonly Dictionary<string, GameObjectHandler> _gposeGameObjects; private readonly Dictionary<string, GameObjectHandler> _gposeGameObjects;
private readonly List<Guid?> _gposeCustomizeObjects;
private readonly IpcManager _ipcManager; private readonly IpcManager _ipcManager;
private readonly ILogger<MareCharaFileManager> _logger; private readonly ILogger<MareCharaFileManager> _logger;
private readonly FileCacheManager _manager; private readonly FileCacheManager _manager;
@@ -39,6 +41,7 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
_configService = configService; _configService = configService;
_dalamudUtil = dalamudUtil; _dalamudUtil = dalamudUtil;
_gposeGameObjects = []; _gposeGameObjects = [];
_gposeCustomizeObjects = [];
Mediator.Subscribe<GposeStartMessage>(this, _ => _isInGpose = true); Mediator.Subscribe<GposeStartMessage>(this, _ => _isInGpose = true);
Mediator.Subscribe<GposeEndMessage>(this, async _ => Mediator.Subscribe<GposeEndMessage>(this, async _ =>
{ {
@@ -59,6 +62,10 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
item.Value.Dispose(); item.Value.Dispose();
} }
foreach (var id in _gposeCustomizeObjects.Where(d => d != null))
{
await _ipcManager.CustomizePlusRevertByIdAsync(id).ConfigureAwait(false);
}
_gposeGameObjects.Clear(); _gposeGameObjects.Clear();
}); });
} }
@@ -109,11 +116,13 @@ public class MareCharaFileManager : DisposableMediatorSubscriberBase
await _ipcManager.PenumbraRemoveTemporaryCollectionAsync(_logger, applicationId, coll).ConfigureAwait(false); await _ipcManager.PenumbraRemoveTemporaryCollectionAsync(_logger, applicationId, coll).ConfigureAwait(false);
if (!string.IsNullOrEmpty(LoadedCharaFile.CharaFileData.CustomizePlusData)) if (!string.IsNullOrEmpty(LoadedCharaFile.CharaFileData.CustomizePlusData))
{ {
await _ipcManager.CustomizePlusSetBodyScaleAsync(tempHandler.Address, LoadedCharaFile.CharaFileData.CustomizePlusData).ConfigureAwait(false); var id = await _ipcManager.CustomizePlusSetBodyScaleAsync(tempHandler.Address, LoadedCharaFile.CharaFileData.CustomizePlusData).ConfigureAwait(false);
_gposeCustomizeObjects.Add(id);
} }
else else
{ {
await _ipcManager.CustomizePlusRevertAsync(tempHandler.Address).ConfigureAwait(false); var id = await _ipcManager.CustomizePlusSetBodyScaleAsync(tempHandler.Address, Convert.ToBase64String(Encoding.UTF8.GetBytes("{}"))).ConfigureAwait(false);
_gposeCustomizeObjects.Add(id);
} }
} }
} }

View File

@@ -37,6 +37,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
private bool _forceApplyMods = false; private bool _forceApplyMods = false;
private bool _isVisible; private bool _isVisible;
private Guid _penumbraCollection; private Guid _penumbraCollection;
private Dictionary<ObjectKind, Guid?> _customizeIds = [];
private bool _redrawOnNextApplication = false; private bool _redrawOnNextApplication = false;
private CombatData? _dataReceivedInCombat; private CombatData? _dataReceivedInCombat;
public long LastAppliedDataSize { get; private set; } public long LastAppliedDataSize { get; private set; }
@@ -294,11 +295,12 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
case PlayerChanges.Customize: case PlayerChanges.Customize:
if (charaData.CustomizePlusData.TryGetValue(changes.Key, out var customizePlusData)) if (charaData.CustomizePlusData.TryGetValue(changes.Key, out var customizePlusData))
{ {
await _ipcManager.CustomizePlusSetBodyScaleAsync(handler.Address, customizePlusData).ConfigureAwait(false); _customizeIds[changes.Key] = await _ipcManager.CustomizePlusSetBodyScaleAsync(handler.Address, customizePlusData).ConfigureAwait(false);
} }
else else if (_customizeIds.TryGetValue(changes.Key, out var customizeId))
{ {
await _ipcManager.CustomizePlusRevertAsync(handler.Address).ConfigureAwait(false); await _ipcManager.CustomizePlusRevertByIdAsync(customizeId).ConfigureAwait(false);
_customizeIds.Remove(changes.Key);
} }
break; break;
@@ -520,6 +522,11 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
Logger.LogDebug("[{applicationId}] Reverting all Customization for {alias}/{name} {objectKind}", applicationId, OnlineUser.User.AliasOrUID, name, objectKind); Logger.LogDebug("[{applicationId}] Reverting all Customization for {alias}/{name} {objectKind}", applicationId, OnlineUser.User.AliasOrUID, name, objectKind);
if (_customizeIds.TryGetValue(objectKind, out var customizeId))
{
_customizeIds.Remove(objectKind);
}
if (objectKind == ObjectKind.Player) if (objectKind == ObjectKind.Player)
{ {
using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.Player, () => address, isWatched: false).ConfigureAwait(false); using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.Player, () => address, isWatched: false).ConfigureAwait(false);
@@ -531,7 +538,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
await _ipcManager.HeelsRestoreOffsetForPlayerAsync(address).ConfigureAwait(false); await _ipcManager.HeelsRestoreOffsetForPlayerAsync(address).ConfigureAwait(false);
tempHandler.CompareNameAndThrow(name); tempHandler.CompareNameAndThrow(name);
Logger.LogDebug("[{applicationId}] Restoring C+ for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name); Logger.LogDebug("[{applicationId}] Restoring C+ for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name);
await _ipcManager.CustomizePlusRevertAsync(address).ConfigureAwait(false); await _ipcManager.CustomizePlusRevertByIdAsync(customizeId).ConfigureAwait(false);
tempHandler.CompareNameAndThrow(name); tempHandler.CompareNameAndThrow(name);
Logger.LogDebug("[{applicationId}] Restoring Honorific for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name); Logger.LogDebug("[{applicationId}] Restoring Honorific for {alias}/{name}", applicationId, OnlineUser.User.AliasOrUID, name);
await _ipcManager.HonorificClearTitleAsync(address).ConfigureAwait(false); await _ipcManager.HonorificClearTitleAsync(address).ConfigureAwait(false);
@@ -541,7 +548,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
var minionOrMount = await _dalamudUtil.GetMinionOrMountAsync(address).ConfigureAwait(false); var minionOrMount = await _dalamudUtil.GetMinionOrMountAsync(address).ConfigureAwait(false);
if (minionOrMount != nint.Zero) if (minionOrMount != nint.Zero)
{ {
await _ipcManager.CustomizePlusRevertAsync(minionOrMount).ConfigureAwait(false); await _ipcManager.CustomizePlusRevertByIdAsync(customizeId).ConfigureAwait(false);
using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.MinionOrMount, () => minionOrMount, isWatched: false).ConfigureAwait(false); using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.MinionOrMount, () => minionOrMount, isWatched: false).ConfigureAwait(false);
await _ipcManager.GlamourerRevert(Logger, tempHandler.Name, tempHandler, applicationId, cancelToken).ConfigureAwait(false); await _ipcManager.GlamourerRevert(Logger, tempHandler.Name, tempHandler, applicationId, cancelToken).ConfigureAwait(false);
await _ipcManager.PenumbraRedrawAsync(Logger, tempHandler, applicationId, cancelToken).ConfigureAwait(false); await _ipcManager.PenumbraRedrawAsync(Logger, tempHandler, applicationId, cancelToken).ConfigureAwait(false);
@@ -552,7 +559,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
var pet = await _dalamudUtil.GetPetAsync(address).ConfigureAwait(false); var pet = await _dalamudUtil.GetPetAsync(address).ConfigureAwait(false);
if (pet != nint.Zero) if (pet != nint.Zero)
{ {
await _ipcManager.CustomizePlusRevertAsync(pet).ConfigureAwait(false); await _ipcManager.CustomizePlusRevertByIdAsync(customizeId).ConfigureAwait(false);
using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.Pet, () => pet, isWatched: false).ConfigureAwait(false); using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.Pet, () => pet, isWatched: false).ConfigureAwait(false);
await _ipcManager.GlamourerRevert(Logger, tempHandler.Name, tempHandler, applicationId, cancelToken).ConfigureAwait(false); await _ipcManager.GlamourerRevert(Logger, tempHandler.Name, tempHandler, applicationId, cancelToken).ConfigureAwait(false);
await _ipcManager.PenumbraRedrawAsync(Logger, tempHandler, applicationId, cancelToken).ConfigureAwait(false); await _ipcManager.PenumbraRedrawAsync(Logger, tempHandler, applicationId, cancelToken).ConfigureAwait(false);
@@ -563,7 +570,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
var companion = await _dalamudUtil.GetCompanionAsync(address).ConfigureAwait(false); var companion = await _dalamudUtil.GetCompanionAsync(address).ConfigureAwait(false);
if (companion != nint.Zero) if (companion != nint.Zero)
{ {
await _ipcManager.CustomizePlusRevertAsync(companion).ConfigureAwait(false); await _ipcManager.CustomizePlusRevertByIdAsync(customizeId).ConfigureAwait(false);
using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.Pet, () => companion, isWatched: false).ConfigureAwait(false); using GameObjectHandler tempHandler = await _gameObjectHandlerFactory.Create(ObjectKind.Pet, () => companion, isWatched: false).ConfigureAwait(false);
await _ipcManager.GlamourerRevert(Logger, tempHandler.Name, tempHandler, applicationId, cancelToken).ConfigureAwait(false); await _ipcManager.GlamourerRevert(Logger, tempHandler.Name, tempHandler, applicationId, cancelToken).ConfigureAwait(false);
await _ipcManager.PenumbraRedrawAsync(Logger, tempHandler, applicationId, cancelToken).ConfigureAwait(false); await _ipcManager.PenumbraRedrawAsync(Logger, tempHandler, applicationId, cancelToken).ConfigureAwait(false);