Skip to content

Commit

Permalink
EzIPC experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
RisaDev committed Mar 10, 2024
1 parent 57c91eb commit e9b3fc4
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 64 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions CustomizePlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down
34 changes: 6 additions & 28 deletions CustomizePlus/Api/CustomizePlusIpc.General.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Plugin.Ipc;
using ECommons.EzIpcManager;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -8,20 +9,16 @@

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;
Expand All @@ -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();
}
}
2 changes: 1 addition & 1 deletion CustomizePlus/Api/CustomizePlusIpc.Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace CustomizePlus.Api;

public partial class CustomizePlusIpc : IDisposable
public partial class CustomizePlusIpc
{

}
31 changes: 3 additions & 28 deletions CustomizePlus/Api/CustomizePlusIpc.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,32 +26,6 @@ public CustomizePlusIpc(
_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");
}
}
1 change: 1 addition & 0 deletions CustomizePlus/CustomizePlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 5 additions & 0 deletions CustomizePlus/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using CustomizePlus.Configuration.Services.Temporary;
using OtterGui.Services;
using CustomizePlus.Api;
using ECommons;

namespace CustomizePlus;

Expand All @@ -29,6 +30,8 @@ public Plugin(DalamudPluginInterface pluginInterface)
{
try
{
ECommonsMain.Init(pluginInterface, this);

_services = ServiceManagerBuilder.CreateProvider(pluginInterface, Logger);

//temporary
Expand Down Expand Up @@ -57,5 +60,7 @@ public Plugin(DalamudPluginInterface pluginInterface)
public void Dispose()
{
_services?.Dispose();

ECommonsMain.Dispose();
}
}
29 changes: 22 additions & 7 deletions CustomizePlus/UI/Windows/MainWindow/Tabs/Debug/IPCTestTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using CustomizePlus.Game.Services;
using CustomizePlus.GameData.Services;
using Penumbra.GameData.Actors;
using ECommons.EzIpcManager;
using System;

namespace CustomizePlus.UI.Windows.MainWindow.Tabs.Debug;

Expand All @@ -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;
Expand All @@ -33,6 +39,8 @@ public class IPCTestTab //: IDisposable
private string? _rememberedProfileJson;

private (int, int) _apiVersion;
private DateTime _lastValidCheckAt;
private bool _validResult;

private string? _targetCharacterName;

Expand All @@ -52,10 +60,10 @@ public IPCTestTab(
_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");
Expand All @@ -82,8 +90,15 @@ public unsafe void Draw()
_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")}");
Expand Down
1 change: 1 addition & 0 deletions submodules/ECommons
Submodule ECommons added at a3521e

0 comments on commit e9b3fc4

Please sign in to comment.