From 3fa2753b6bd4919ea8e87433ebc16be5700e7a24 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Tue, 7 Nov 2023 20:06:16 +0100 Subject: [PATCH] IPC for YesAlready 1.4.x.x --- Deliveroo/Deliveroo.csproj | 2 +- Deliveroo/DeliverooPlugin.cs | 2 +- Deliveroo/External/ExternalPluginHandler.cs | 31 ++++++------ Deliveroo/External/YesAlreadyIpc.cs | 53 --------------------- 4 files changed, 19 insertions(+), 69 deletions(-) delete mode 100644 Deliveroo/External/YesAlreadyIpc.cs diff --git a/Deliveroo/Deliveroo.csproj b/Deliveroo/Deliveroo.csproj index 6a6acaf..bf3557e 100644 --- a/Deliveroo/Deliveroo.csproj +++ b/Deliveroo/Deliveroo.csproj @@ -1,7 +1,7 @@ net7.0-windows - 2.15 + 2.16 11.0 enable true diff --git a/Deliveroo/DeliverooPlugin.cs b/Deliveroo/DeliverooPlugin.cs index 3091d18..3a8150b 100644 --- a/Deliveroo/DeliverooPlugin.cs +++ b/Deliveroo/DeliverooPlugin.cs @@ -74,7 +74,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin _addonLifecycle = addonLifecycle; _gameStrings = new GameStrings(dataManager, _pluginLog); - _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _framework, _pluginLog); + _externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _pluginLog); _configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration(); _gcRewardsCache = new GcRewardsCache(dataManager); _configWindow = new ConfigWindow(_pluginInterface, this, _configuration, _gcRewardsCache, _clientState, _pluginLog); diff --git a/Deliveroo/External/ExternalPluginHandler.cs b/Deliveroo/External/ExternalPluginHandler.cs index 8551c1d..9a1d152 100644 --- a/Deliveroo/External/ExternalPluginHandler.cs +++ b/Deliveroo/External/ExternalPluginHandler.cs @@ -1,26 +1,23 @@ -using Dalamud.Plugin; +using System.Collections.Generic; +using Dalamud.Plugin; using Dalamud.Plugin.Services; -using LLib; namespace Deliveroo.External; internal sealed class ExternalPluginHandler { + private readonly DalamudPluginInterface _pluginInterface; private readonly IPluginLog _pluginLog; private readonly DeliverooIpc _deliverooIpc; - 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; _deliverooIpc = new DeliverooIpc(pluginInterface); - - var dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog); - _yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector); _pandoraIpc = new PandoraIpc(pluginInterface, pluginLog); } @@ -43,8 +40,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(Deliveroo))) + { + _pluginLog.Debug("Disabling YesAlready"); + data.Add(nameof(Deliveroo)); + } } private void SavePandoraState() @@ -62,16 +63,18 @@ internal sealed class ExternalPluginHandler } Saved = false; - _yesAlreadyState = null; _pandoraState = null; _deliverooIpc.StopTurnIn(); } 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(Deliveroo))) + { + _pluginLog.Debug("Restoring YesAlready"); + data.Remove(nameof(Deliveroo)); + } } private void RestorePandora() diff --git a/Deliveroo/External/YesAlreadyIpc.cs b/Deliveroo/External/YesAlreadyIpc.cs deleted file mode 100644 index 1b7272e..0000000 --- a/Deliveroo/External/YesAlreadyIpc.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System.Reflection; -using LLib; - -namespace Deliveroo.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); - } -}