Disable Pandora's GCVendorDefault feature during turn-in
This commit is contained in:
parent
a6005bdaba
commit
3e68dd6e79
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0-windows</TargetFramework>
|
<TargetFramework>net7.0-windows</TargetFramework>
|
||||||
<Version>2.2</Version>
|
<Version>2.3</Version>
|
||||||
<LangVersion>11.0</LangVersion>
|
<LangVersion>11.0</LangVersion>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||||
|
@ -35,7 +35,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||||
private readonly Configuration _configuration;
|
private readonly Configuration _configuration;
|
||||||
|
|
||||||
private readonly YesAlreadyIpc _yesAlreadyIpc;
|
private readonly ExternalPluginHandler _externalPluginHandler;
|
||||||
|
|
||||||
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
// ReSharper disable once PrivateFieldCanBeConvertedToLocalVariable
|
||||||
private readonly GcRewardsCache _gcRewardsCache;
|
private readonly GcRewardsCache _gcRewardsCache;
|
||||||
@ -47,7 +47,6 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
private Stage _currentStageInternal = Stage.Stopped;
|
private Stage _currentStageInternal = Stage.Stopped;
|
||||||
private DateTime _continueAt = DateTime.MinValue;
|
private DateTime _continueAt = DateTime.MinValue;
|
||||||
private List<PurchaseItemRequest> _itemsToPurchaseNow = new();
|
private List<PurchaseItemRequest> _itemsToPurchaseNow = new();
|
||||||
private (bool Saved, bool? PreviousState) _yesAlreadyState = (false, null);
|
|
||||||
|
|
||||||
public DeliverooPlugin(DalamudPluginInterface pluginInterface, IChatGui chatGui, IGameGui gameGui,
|
public DeliverooPlugin(DalamudPluginInterface pluginInterface, IChatGui chatGui, IGameGui gameGui,
|
||||||
IFramework framework, IClientState clientState, IObjectTable objectTable, ITargetManager targetManager,
|
IFramework framework, IClientState clientState, IObjectTable objectTable, ITargetManager targetManager,
|
||||||
@ -64,8 +63,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
_commandManager = commandManager;
|
_commandManager = commandManager;
|
||||||
_pluginLog = pluginLog;
|
_pluginLog = pluginLog;
|
||||||
|
|
||||||
var dalamudReflector = new DalamudReflector(_pluginInterface, _framework, _pluginLog);
|
_externalPluginHandler = new ExternalPluginHandler(_pluginInterface, _framework, _pluginLog);
|
||||||
_yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector);
|
|
||||||
_configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration();
|
_configuration = (Configuration?)_pluginInterface.GetPluginConfig() ?? new Configuration();
|
||||||
_gcRewardsCache = new GcRewardsCache(dataManager);
|
_gcRewardsCache = new GcRewardsCache(dataManager);
|
||||||
_configWindow = new ConfigWindow(_pluginInterface, this, _configuration, _gcRewardsCache, _clientState, _pluginLog);
|
_configWindow = new ConfigWindow(_pluginInterface, this, _configuration, _gcRewardsCache, _clientState, _pluginLog);
|
||||||
@ -161,7 +159,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
_turnInWindow.State = false;
|
_turnInWindow.State = false;
|
||||||
if (CurrentStage != Stage.Stopped)
|
if (CurrentStage != Stage.Stopped)
|
||||||
{
|
{
|
||||||
RestoreYesAlready();
|
_externalPluginHandler.Restore();
|
||||||
CurrentStage = Stage.Stopped;
|
CurrentStage = Stage.Stopped;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -174,7 +172,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
{
|
{
|
||||||
if (CurrentStage != Stage.Stopped)
|
if (CurrentStage != Stage.Stopped)
|
||||||
{
|
{
|
||||||
RestoreYesAlready();
|
_externalPluginHandler.Restore();
|
||||||
CurrentStage = Stage.Stopped;
|
CurrentStage = Stage.Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -207,8 +205,8 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
CurrentStage = Stage.SelectRewardTier;
|
CurrentStage = Stage.SelectRewardTier;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CurrentStage != Stage.Stopped && CurrentStage != Stage.RequestStop && !_yesAlreadyState.Saved)
|
if (CurrentStage != Stage.Stopped && CurrentStage != Stage.RequestStop && !_externalPluginHandler.Saved)
|
||||||
SaveYesAlready();
|
_externalPluginHandler.Save();
|
||||||
|
|
||||||
switch (CurrentStage)
|
switch (CurrentStage)
|
||||||
{
|
{
|
||||||
@ -277,7 +275,7 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Stage.RequestStop:
|
case Stage.RequestStop:
|
||||||
RestoreYesAlready();
|
_externalPluginHandler.Restore();
|
||||||
CurrentStage = Stage.Stopped;
|
CurrentStage = Stage.Stopped;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -301,32 +299,8 @@ public sealed partial class DeliverooPlugin : IDalamudPlugin
|
|||||||
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
|
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
|
||||||
_framework.Update -= FrameworkUpdate;
|
_framework.Update -= FrameworkUpdate;
|
||||||
|
|
||||||
RestoreYesAlready();
|
_externalPluginHandler.Restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessCommand(string command, string arguments) => _configWindow.Toggle();
|
private void ProcessCommand(string command, string arguments) => _configWindow.Toggle();
|
||||||
|
|
||||||
private void SaveYesAlready()
|
|
||||||
{
|
|
||||||
if (_yesAlreadyState.Saved)
|
|
||||||
{
|
|
||||||
_pluginLog.Information("Not overwriting yesalready state");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_yesAlreadyState = (true, _yesAlreadyIpc.DisableIfNecessary());
|
|
||||||
_pluginLog.Information($"Previous yesalready state: {_yesAlreadyState.PreviousState}");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RestoreYesAlready()
|
|
||||||
{
|
|
||||||
if (_yesAlreadyState.Saved)
|
|
||||||
{
|
|
||||||
_pluginLog.Information($"Restoring previous yesalready state: {_yesAlreadyState.PreviousState}");
|
|
||||||
if (_yesAlreadyState.PreviousState == true)
|
|
||||||
_yesAlreadyIpc.Enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
_yesAlreadyState = (false, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
78
Deliveroo/External/ExternalPluginHandler.cs
vendored
Normal file
78
Deliveroo/External/ExternalPluginHandler.cs
vendored
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
using Dalamud.Plugin;
|
||||||
|
using Dalamud.Plugin.Services;
|
||||||
|
|
||||||
|
namespace Deliveroo.External;
|
||||||
|
|
||||||
|
internal sealed class ExternalPluginHandler
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
_pluginLog = pluginLog;
|
||||||
|
|
||||||
|
var dalamudReflector = new DalamudReflector(pluginInterface, framework, pluginLog);
|
||||||
|
_yesAlreadyIpc = new YesAlreadyIpc(dalamudReflector);
|
||||||
|
_pandoraIpc = new PandoraIpc(dalamudReflector);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Saved { get; private set; }
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
if (Saved)
|
||||||
|
{
|
||||||
|
_pluginLog.Information("Not overwriting external plugin state");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_pluginLog.Information("Saving external plugin state...");
|
||||||
|
SaveYesAlreadyState();
|
||||||
|
SavePandoraState();
|
||||||
|
Saved = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveYesAlreadyState()
|
||||||
|
{
|
||||||
|
_yesAlreadyState = _yesAlreadyIpc.DisableIfNecessary();
|
||||||
|
_pluginLog.Information($"Previous yesalready state: {_yesAlreadyState}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SavePandoraState()
|
||||||
|
{
|
||||||
|
_pandoraState = _pandoraIpc.DisableIfNecessary();
|
||||||
|
_pluginLog.Info($"Previous pandora feature state: {_pandoraState}");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Restore()
|
||||||
|
{
|
||||||
|
if (Saved)
|
||||||
|
{
|
||||||
|
RestoreYesAlready();
|
||||||
|
RestorePandora();
|
||||||
|
}
|
||||||
|
|
||||||
|
Saved = false;
|
||||||
|
_yesAlreadyState = null;
|
||||||
|
_pandoraState = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RestoreYesAlready()
|
||||||
|
{
|
||||||
|
_pluginLog.Information($"Restoring previous yesalready state: {_yesAlreadyState}");
|
||||||
|
if (_yesAlreadyState == true)
|
||||||
|
_yesAlreadyIpc.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RestorePandora()
|
||||||
|
{
|
||||||
|
_pluginLog.Information($"Restoring previous pandora state: {_pandoraState}");
|
||||||
|
if (_pandoraState == true)
|
||||||
|
_pandoraIpc.Enable();
|
||||||
|
}
|
||||||
|
}
|
58
Deliveroo/External/PandoraIpc.cs
vendored
Normal file
58
Deliveroo/External/PandoraIpc.cs
vendored
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Deliveroo.External;
|
||||||
|
|
||||||
|
internal sealed class PandoraIpc
|
||||||
|
{
|
||||||
|
private const string GcTabFeature = "GCVendorDefault";
|
||||||
|
|
||||||
|
private readonly DalamudReflector _dalamudReflector;
|
||||||
|
|
||||||
|
public PandoraIpc(DalamudReflector dalamudReflector)
|
||||||
|
{
|
||||||
|
_dalamudReflector = dalamudReflector;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IEnumerable<object>? GetFeatures()
|
||||||
|
{
|
||||||
|
if (_dalamudReflector.TryGetDalamudPlugin("Pandora's Box", out var plugin))
|
||||||
|
{
|
||||||
|
return ((IEnumerable)plugin!.GetType().GetProperty("Features")!.GetValue(plugin)!).Cast<object>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private object? GetFeature(string name)
|
||||||
|
{
|
||||||
|
IEnumerable<object> features = GetFeatures() ?? Array.Empty<object>();
|
||||||
|
return features.FirstOrDefault(x => x.GetType().Name == name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool? DisableIfNecessary()
|
||||||
|
{
|
||||||
|
object? feature = GetFeature(GcTabFeature);
|
||||||
|
if (feature == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if ((bool)feature.GetType().GetProperty("Enabled")!.GetValue(feature)!)
|
||||||
|
{
|
||||||
|
feature.GetType().GetMethod("Disable")!.Invoke(feature, Array.Empty<object>());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Enable()
|
||||||
|
{
|
||||||
|
object? feature = GetFeature(GcTabFeature);
|
||||||
|
if (feature == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
feature.GetType().GetMethod("Enable")!.Invoke(feature, Array.Empty<object>());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user