From e9b3fc4d3d79d4dee2a73d1ae889df63ac9ac02a Mon Sep 17 00:00:00 2001 From: RisaDev <151885272+RisaDev@users.noreply.github.com> Date: Mon, 11 Mar 2024 00:17:09 +0300 Subject: [PATCH] EzIPC experiments --- .gitmodules | 4 +++ CustomizePlus.sln | 11 ++++++ CustomizePlus/Api/CustomizePlusIpc.General.cs | 34 ++++--------------- CustomizePlus/Api/CustomizePlusIpc.Profile.cs | 2 +- CustomizePlus/Api/CustomizePlusIpc.cs | 31 ++--------------- CustomizePlus/CustomizePlus.csproj | 1 + CustomizePlus/Plugin.cs | 5 +++ .../MainWindow/Tabs/Debug/IPCTestTab.cs | 29 ++++++++++++---- submodules/ECommons | 1 + 9 files changed, 54 insertions(+), 64 deletions(-) create mode 160000 submodules/ECommons diff --git a/.gitmodules b/.gitmodules index 7f60d60..f74de2d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/CustomizePlus.sln b/CustomizePlus.sln index 9a8ba6c..ec07346 100644 --- a/CustomizePlus.sln +++ b/CustomizePlus.sln @@ -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} diff --git a/CustomizePlus/Api/CustomizePlusIpc.General.cs b/CustomizePlus/Api/CustomizePlusIpc.General.cs index 230f413..f794500 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.General.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.General.cs @@ -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); + /// /// 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. /// - 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. /// - private const string _providerIsValidLabel = $"CustomizePlus.General.{nameof(IsValid)}"; - private ICallGateProvider? _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(_providerIsValidLabel); - _providerIsValid.RegisterFunc(IsValid); - } - - private void DisposeGeneralProviders() - { - _logger.Debug("Disposing General Customize+ IPC providers."); - _providerGetApiVersion?.UnregisterFunc(); - } } diff --git a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs index fa65609..0f23be3 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.Profile.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.Profile.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace CustomizePlus.Api; -public partial class CustomizePlusIpc : IDisposable +public partial class CustomizePlusIpc { } diff --git a/CustomizePlus/Api/CustomizePlusIpc.cs b/CustomizePlus/Api/CustomizePlusIpc.cs index 9ea050c..afcb2ea 100644 --- a/CustomizePlus/Api/CustomizePlusIpc.cs +++ b/CustomizePlus/Api/CustomizePlusIpc.cs @@ -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"); } } diff --git a/CustomizePlus/CustomizePlus.csproj b/CustomizePlus/CustomizePlus.csproj index ece3318..dd4adb0 100644 --- a/CustomizePlus/CustomizePlus.csproj +++ b/CustomizePlus/CustomizePlus.csproj @@ -50,6 +50,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive + $(DalamudLibPath)Newtonsoft.Json.dll diff --git a/CustomizePlus/Plugin.cs b/CustomizePlus/Plugin.cs index 4364c6b..9398c62 100644 --- a/CustomizePlus/Plugin.cs +++ b/CustomizePlus/Plugin.cs @@ -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(); } } \ No newline at end of file diff --git a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs index 2d95abc..4826a39 100644 --- a/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs +++ b/CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs @@ -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? _isValid; + [EzIPC("General.GetApiVersion")] + private readonly Func<(int, int)> _getApiVersionIpcFunc; + + [EzIPC("General.IsValid")] + private readonly Func _isValidIpcFunc; + private readonly ICallGateSubscriber? _setCharacterProfile; private readonly ICallGateSubscriber? _getProfileFromCharacter; private readonly ICallGateSubscriber? _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("CustomizePlus.General.IsValid"); + if (_getApiVersionIpcFunc != null) + _apiVersion = _getApiVersionIpcFunc(); _setCharacterProfile = pluginInterface.GetIpcSubscriber("CustomizePlus.SetProfileToCharacter"); _getProfileFromCharacter = pluginInterface.GetIpcSubscriber("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")}"); diff --git a/submodules/ECommons b/submodules/ECommons new file mode 160000 index 0000000..a3521ec --- /dev/null +++ b/submodules/ECommons @@ -0,0 +1 @@ +Subproject commit a3521ec6188fec91dcb01090cacf27f2104e8a2e