forked from liza/Deliveroo
IPC for YesAlready 1.4.x.x
This commit is contained in:
parent
d5a12ac9a4
commit
3fa2753b6b
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0-windows</TargetFramework>
|
||||
<Version>2.15</Version>
|
||||
<Version>2.16</Version>
|
||||
<LangVersion>11.0</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
|
@ -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);
|
||||
|
31
Deliveroo/External/ExternalPluginHandler.cs
vendored
31
Deliveroo/External/ExternalPluginHandler.cs
vendored
@ -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<HashSet<string>>("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<HashSet<string>>("YesAlready.StopRequests", out var data) &&
|
||||
data.Contains(nameof(Deliveroo)))
|
||||
{
|
||||
_pluginLog.Debug("Restoring YesAlready");
|
||||
data.Remove(nameof(Deliveroo));
|
||||
}
|
||||
}
|
||||
|
||||
private void RestorePandora()
|
||||
|
53
Deliveroo/External/YesAlreadyIpc.cs
vendored
53
Deliveroo/External/YesAlreadyIpc.cs
vendored
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user