EzIPC experiments

This commit is contained in:
RisaDev
2024-03-11 00:17:09 +03:00
parent 57c91eb834
commit e9b3fc4d3d
9 changed files with 54 additions and 64 deletions

4
.gitmodules vendored
View File

@@ -14,3 +14,7 @@
path = submodules/Penumbra.String
url = https://github.com/Ottermandias/Penumbra.String.git
branch = main
[submodule "submodules/ECommons"]
path = submodules/ECommons
url = https://github.com/NightmareXIV/ECommons.git
branch = master

View File

@@ -22,6 +22,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Penumbra.Api", "submodules\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Penumbra.String", "submodules\Penumbra.String\Penumbra.String.csproj", "{CB1DFB63-22D9-4E90-A8C1-A4F7CFEF7823}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ECommons", "submodules\ECommons\ECommons\ECommons.csproj", "{0234819A-193E-4B75-A528-23E71C9FB1C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -78,6 +80,14 @@ Global
{CB1DFB63-22D9-4E90-A8C1-A4F7CFEF7823}.Release|Any CPU.Build.0 = Release|Any CPU
{CB1DFB63-22D9-4E90-A8C1-A4F7CFEF7823}.Release|x64.ActiveCfg = Release|Any CPU
{CB1DFB63-22D9-4E90-A8C1-A4F7CFEF7823}.Release|x64.Build.0 = Release|Any CPU
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Debug|Any CPU.ActiveCfg = Debug|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Debug|Any CPU.Build.0 = Debug|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Debug|x64.ActiveCfg = Debug|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Debug|x64.Build.0 = Debug|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Release|Any CPU.ActiveCfg = Release|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Release|Any CPU.Build.0 = Release|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Release|x64.ActiveCfg = Release|x64
{0234819A-193E-4B75-A528-23E71C9FB1C8}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -87,6 +97,7 @@ Global
{D79C8833-D241-4867-BF6F-8097E0ED8067} = {121C2200-A844-44FD-85C4-22D6C7E35553}
{CC460943-1E07-4FA0-8B8C-67F0EF385290} = {121C2200-A844-44FD-85C4-22D6C7E35553}
{CB1DFB63-22D9-4E90-A8C1-A4F7CFEF7823} = {121C2200-A844-44FD-85C4-22D6C7E35553}
{0234819A-193E-4B75-A528-23E71C9FB1C8} = {121C2200-A844-44FD-85C4-22D6C7E35553}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B17E85B1-5F60-4440-9F9A-3DDE877E8CDF}

View File

@@ -1,4 +1,5 @@
using Dalamud.Plugin.Ipc;
using ECommons.EzIpcManager;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -8,20 +9,16 @@ using static Penumbra.Api.Ipc;
namespace CustomizePlus.Api;
//I'm not a big fan of having functions and variables/properties
//grouped up like that but it makes sense here
public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{
private readonly (int Breaking, int Feature) _apiVersion = (4, 0);
/// <summary>
/// When there are breaking changes the first number is bumped up and second one is reset.
/// When there are non-breaking changes only second number is bumped up.
/// In general clients should not try to use IPC if they encounter unexpected Breaking version.
/// </summary>
private readonly (int Breaking, int Feature) _apiVersion = (4, 0);
private const string _providerGetApiVersionLabel = $"CustomizePlus.General.{nameof(GetApiVersion)}";
private ICallGateProvider<(int, int)>? _providerGetApiVersion;
[EzIPC($"General.{nameof(GetApiVersion)}")]
private (int, int) GetApiVersion()
{
return _apiVersion;
@@ -32,30 +29,11 @@ public partial class CustomizePlusIpc : IDisposable
/// This only indicates that no fatal errors occured in Customize+.
/// This will still be true if, for example, user turns off Customize+ in its settings.
/// </summary>
private const string _providerIsValidLabel = $"CustomizePlus.General.{nameof(IsValid)}";
private ICallGateProvider<bool>? _providerIsValid;
[EzIPC($"General.{nameof(IsValid)}")]
private bool IsValid()
{
return !IPCFailed &&
!_hookingService.RenderHookFailed &&
!_hookingService.MovementHookFailed;
}
private void InitializeGeneralProviders()
{
_logger.Debug("Initializing General Customize+ IPC providers.");
_providerGetApiVersion = _pluginInterface.GetIpcProvider<(int, int)>(_providerGetApiVersionLabel);
_providerGetApiVersion.RegisterFunc(GetApiVersion);
_providerIsValid = _pluginInterface.GetIpcProvider<bool>(_providerIsValidLabel);
_providerIsValid.RegisterFunc(IsValid);
}
private void DisposeGeneralProviders()
{
_logger.Debug("Disposing General Customize+ IPC providers.");
_providerGetApiVersion?.UnregisterFunc();
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace CustomizePlus.Api;
public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{
}

View File

@@ -1,11 +1,12 @@
using CustomizePlus.Core.Services;
using Dalamud.Plugin;
using ECommons.EzIpcManager;
using OtterGui.Log;
using System;
namespace CustomizePlus.Api;
public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{
private readonly DalamudPluginInterface _pluginInterface;
private readonly Logger _logger;
@@ -25,32 +26,6 @@ public partial class CustomizePlusIpc : IDisposable
_logger = logger;
_hookingService = hookingService;
InitializeProviders();
}
private void InitializeProviders()
{
try
{
InitializeGeneralProviders();
}
catch(Exception ex)
{
_logger.Fatal($"Fatal error while initializing Customize+ IPC: {ex}");
IPCFailed = true;
DisposeProviders();
}
}
private void DisposeProviders()
{
DisposeGeneralProviders();
}
public void Dispose()
{
DisposeProviders();
EzIPC.Init(this, "CustomizePlus");
}
}

View File

@@ -50,6 +50,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<ProjectReference Include="..\CustomizePlus.GameData\CustomizePlus.GameData.csproj" />
<ProjectReference Include="..\submodules\ECommons\ECommons\ECommons.csproj" />
<ProjectReference Include="..\submodules\OtterGui\OtterGui.csproj" />
<Reference Include="Newtonsoft.Json">
<HintPath>$(DalamudLibPath)Newtonsoft.Json.dll</HintPath>

View File

@@ -10,6 +10,7 @@ using CustomizePlus.Api.Compatibility;
using CustomizePlus.Configuration.Services.Temporary;
using OtterGui.Services;
using CustomizePlus.Api;
using ECommons;
namespace CustomizePlus;
@@ -29,6 +30,8 @@ public sealed class Plugin : IDalamudPlugin
{
try
{
ECommonsMain.Init(pluginInterface, this);
_services = ServiceManagerBuilder.CreateProvider(pluginInterface, Logger);
//temporary
@@ -57,5 +60,7 @@ public sealed class Plugin : IDalamudPlugin
public void Dispose()
{
_services?.Dispose();
ECommonsMain.Dispose();
}
}

View File

@@ -11,6 +11,8 @@ using CustomizePlus.Configuration.Helpers;
using CustomizePlus.Game.Services;
using CustomizePlus.GameData.Services;
using Penumbra.GameData.Actors;
using ECommons.EzIpcManager;
using System;
namespace CustomizePlus.UI.Windows.MainWindow.Tabs.Debug;
@@ -23,8 +25,12 @@ public class IPCTestTab //: IDisposable
private readonly ObjectManager _objectManager;
private readonly ActorManager _actorManager;
private readonly ICallGateSubscriber<(int, int)>? _getApiVersion;
private readonly ICallGateSubscriber<bool>? _isValid;
[EzIPC("General.GetApiVersion")]
private readonly Func<(int, int)> _getApiVersionIpcFunc;
[EzIPC("General.IsValid")]
private readonly Func<bool> _isValidIpcFunc;
private readonly ICallGateSubscriber<string, Character?, object>? _setCharacterProfile;
private readonly ICallGateSubscriber<Character?, string>? _getProfileFromCharacter;
private readonly ICallGateSubscriber<Character?, object>? _revertCharacter;
@@ -33,6 +39,8 @@ public class IPCTestTab //: IDisposable
private string? _rememberedProfileJson;
private (int, int) _apiVersion;
private DateTime _lastValidCheckAt;
private bool _validResult;
private string? _targetCharacterName;
@@ -52,10 +60,10 @@ public class IPCTestTab //: IDisposable
_gameObjectService = gameObjectService;
_actorManager = actorManager;
_getApiVersion = pluginInterface.GetIpcSubscriber<(int, int)>("CustomizePlus.General.GetApiVersion");
_apiVersion = _getApiVersion.InvokeFunc();
EzIPC.Init(this, "CustomizePlus");
_isValid = pluginInterface.GetIpcSubscriber<bool>("CustomizePlus.General.IsValid");
if (_getApiVersionIpcFunc != null)
_apiVersion = _getApiVersionIpcFunc();
_setCharacterProfile = pluginInterface.GetIpcSubscriber<string, Character?, object>("CustomizePlus.SetProfileToCharacter");
_getProfileFromCharacter = pluginInterface.GetIpcSubscriber<Character?, string>("CustomizePlus.GetProfileFromCharacter");
@@ -82,8 +90,15 @@ public class IPCTestTab //: IDisposable
_targetCharacterName = _gameObjectService.GetCurrentPlayerName();
ImGui.Text($"Version: {_apiVersion.Item1}.{_apiVersion.Item2}");
//
//ImGui.Text($"IsValid: {_isValid?.InvokeFunc()}");
ImGui.Text($"IsValid: {_validResult} ({_lastValidCheckAt} UTC)");
ImGui.SameLine();
if(ImGui.Button("Check IPC validity") || _lastValidCheckAt == DateTime.MinValue)
{
_validResult = _isValidIpcFunc();
_lastValidCheckAt = DateTime.UtcNow;
}
//ImGui.Text($"Last profile update: {_lastProfileUpdate}, Character: {_lastProfileUpdateName}");
ImGui.Text($"Memory: {(string.IsNullOrWhiteSpace(_rememberedProfileJson) ? "empty" : "has data")}");

1
submodules/ECommons Submodule

Submodule submodules/ECommons added at a3521ec618