From 1021220064b1845ff356dcf0676e40e7c692752a Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 7 Nov 2023 20:07:22 +0100 Subject: [PATCH] IPC for YesAlready 1.4.x.x --- Workshoppa/External/ExternalPluginHandler.cs | 25 ++++----- Workshoppa/External/YesAlreadyIpc.cs | 53 -------------------- Workshoppa/WorkshopPlugin.cs | 2 +- Workshoppa/Workshoppa.csproj | 2 +- 4 files changed, 15 insertions(+), 67 deletions(-) delete mode 100644 Workshoppa/External/YesAlreadyIpc.cs diff --git a/Workshoppa/External/ExternalPluginHandler.cs b/Workshoppa/External/ExternalPluginHandler.cs index b77db50..dc037b0 100644 --- a/Workshoppa/External/ExternalPluginHandler.cs +++ b/Workshoppa/External/ExternalPluginHandler.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Dalamud.Plugin; using Dalamud.Plugin.Services; -using LLib; namespace Workshoppa.External; @@ -9,19 +8,15 @@ internal sealed class ExternalPluginHandler { private readonly DalamudPluginInterface _pluginInterface; private readonly IPluginLog _pluginLog; - private readonly YesAlreadyIpc _yesAlreadyIpc; private readonly PandoraIpc _pandoraIpc; - private bool? _yesAlreadyState; private bool? _pandoraState; - public ExternalPluginHandler(DalamudPluginInterface pluginInterface, IFramework framework, IPluginLog pluginLog) + public ExternalPluginHandler(DalamudPluginInterface pluginInterface, IPluginLog pluginLog) { _pluginInterface = pluginInterface; _pluginLog = pluginLog; - var dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog); - _yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector); _pandoraIpc = new PandoraIpc(pluginInterface, pluginLog); } @@ -43,8 +38,12 @@ internal sealed class ExternalPluginHandler private void SaveYesAlreadyState() { - _yesAlreadyState = _yesAlreadyIpc.DisableIfNecessary(); - _pluginLog.Information($"Previous yesalready state: {_yesAlreadyState}"); + if (_pluginInterface.TryGetData>("YesAlready.StopRequests", out var data) && + !data.Contains(nameof(Workshoppa))) + { + _pluginLog.Debug("Disabling YesAlready"); + data.Add(nameof(Workshoppa)); + } } private void SavePandoraState() @@ -76,15 +75,17 @@ internal sealed class ExternalPluginHandler } Saved = false; - _yesAlreadyState = null; _pandoraState = null; } private void RestoreYesAlready() { - _pluginLog.Information($"Restoring previous yesalready state: {_yesAlreadyState}"); - if (_yesAlreadyState == true) - _yesAlreadyIpc.Enable(); + if (_pluginInterface.TryGetData>("YesAlready.StopRequests", out var data) && + data.Contains(nameof(Workshoppa))) + { + _pluginLog.Debug("Restoring YesAlready"); + data.Remove(nameof(Workshoppa)); + } } private void RestorePandora() diff --git a/Workshoppa/External/YesAlreadyIpc.cs b/Workshoppa/External/YesAlreadyIpc.cs deleted file mode 100644 index 259ba57..0000000 --- a/Workshoppa/External/YesAlreadyIpc.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Reflection; -using LLib; - -namespace Workshoppa.External; - -internal sealed class YesAlreadyIpc -{ - private readonly DalamudReflector _dalamudReflector; - - public YesAlreadyIpc(DalamudReflector dalamudReflector) - { - _dalamudReflector = dalamudReflector; - } - - private object? GetConfiguration() - { - if (_dalamudReflector.TryGetDalamudPlugin("Yes Already", out var plugin)) - { - var pluginService = plugin!.GetType().Assembly.GetType("YesAlready.Service"); - return pluginService!.GetProperty("Configuration", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null); - } - - return null; - } - - public bool? DisableIfNecessary() - { - object? configuration = GetConfiguration(); - if (configuration == null) - return null; - - var property = configuration.GetType().GetProperty("Enabled")!; - bool enabled = (bool)property.GetValue(configuration)!; - if (enabled) - { - property.SetValue(configuration, false); - return true; - } - - return false; - } - - public void Enable() - { - object? configuration = GetConfiguration(); - if (configuration == null) - return; - - - var property = configuration.GetType().GetProperty("Enabled")!; - property.SetValue(configuration, true); - } -} diff --git a/Workshoppa/WorkshopPlugin.cs b/Workshoppa/WorkshopPlugin.cs index 909e80b..5aa7356 100644 --- a/Workshoppa/WorkshopPlugin.cs +++ b/Workshoppa/WorkshopPlugin.cs @@ -65,7 +65,7 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin _addonLifecycle = addonLifecycle; _chatGui = chatGui; - _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _framework, _pluginLog); + _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _pluginLog); _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _workshopCache = new WorkshopCache(dataManager, _pluginLog); _gameStrings = new(dataManager, _pluginLog); diff --git a/Workshoppa/Workshoppa.csproj b/Workshoppa/Workshoppa.csproj index f92fccd..0d3e9f4 100644 --- a/Workshoppa/Workshoppa.csproj +++ b/Workshoppa/Workshoppa.csproj @@ -1,7 +1,7 @@ net7.0-windows - 3.4 + 3.5 11.0 enable true