muffin v7.4.10
This commit is contained in:
parent
2df81c5d15
commit
b8dd142c23
47 changed files with 3604 additions and 1058 deletions
|
|
@ -1,42 +1,123 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading.Tasks;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Ipc;
|
||||
using Dalamud.Plugin.Ipc.Exceptions;
|
||||
using Dalamud.Plugin.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Questionable.Controller;
|
||||
using Questionable.Data;
|
||||
|
||||
namespace Questionable.External;
|
||||
|
||||
internal sealed class AutomatonIpc
|
||||
internal sealed class AutomatonIpc : IDisposable
|
||||
{
|
||||
private static readonly ImmutableHashSet<string> ConflictingTweaks = new HashSet<string>
|
||||
{
|
||||
"DateWithDestiny", "AutoFollow", "AutoPillion", "AutoInvite", "AutoBusy", "AutoEquipXPBoosts", "FateToolKit", "AutoMerge", "AutoQueue", "EnhancedDutyStartEnd",
|
||||
"EnhancedLoginLogout", "GettingTooAttached", "RetrieveMateria"
|
||||
}.ToImmutableHashSet();
|
||||
|
||||
private const string AutoSnipeTweak = "AutoSnipeQuests";
|
||||
|
||||
private readonly Configuration _configuration;
|
||||
|
||||
private readonly QuestController _questController;
|
||||
|
||||
private readonly TerritoryData _territoryData;
|
||||
|
||||
private readonly IClientState _clientState;
|
||||
|
||||
private readonly ILogger<AutomatonIpc> _logger;
|
||||
|
||||
private readonly ICallGateSubscriber<string, bool> _isTweakEnabled;
|
||||
|
||||
private bool _loggedIpcError;
|
||||
private readonly ICallGateSubscriber<string, bool, object?> _setTweakState;
|
||||
|
||||
public bool IsAutoSnipeEnabled
|
||||
private HashSet<string>? _pausedTweaks;
|
||||
|
||||
public AutomatonIpc(Configuration configuration, IDalamudPluginInterface pluginInterface, QuestController questController, TerritoryData territoryData, IClientState clientState, ILogger<AutomatonIpc> logger)
|
||||
{
|
||||
get
|
||||
_configuration = configuration;
|
||||
_questController = questController;
|
||||
_territoryData = territoryData;
|
||||
_clientState = clientState;
|
||||
_logger = logger;
|
||||
_isTweakEnabled = pluginInterface.GetIpcSubscriber<string, bool>("Automaton.IsTweakEnabled");
|
||||
_setTweakState = pluginInterface.GetIpcSubscriber<string, bool, object>("Automaton.SetTweakState");
|
||||
_questController.AutomationTypeChanged += OnAutomationTypeChanged;
|
||||
}
|
||||
|
||||
private void OnAutomationTypeChanged(object sender, QuestController.EAutomationType automationType)
|
||||
{
|
||||
if (automationType != QuestController.EAutomationType.Manual && !_territoryData.IsDutyInstance(_clientState.TerritoryType))
|
||||
{
|
||||
try
|
||||
{
|
||||
return _isTweakEnabled.InvokeFunc("AutoSnipeQuests");
|
||||
}
|
||||
catch (IpcError exception)
|
||||
{
|
||||
if (!_loggedIpcError)
|
||||
{
|
||||
_loggedIpcError = true;
|
||||
_logger.LogWarning(exception, "Could not query automaton for tweak status, probably not installed");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Task.Run((Action)DisableConflictingTweaks);
|
||||
}
|
||||
else
|
||||
{
|
||||
Task.Run((Action)RestoreConflictingTweaks);
|
||||
}
|
||||
}
|
||||
|
||||
public AutomatonIpc(IDalamudPluginInterface pluginInterface, ILogger<AutomatonIpc> logger)
|
||||
private void DisableConflictingTweaks()
|
||||
{
|
||||
_logger = logger;
|
||||
_isTweakEnabled = pluginInterface.GetIpcSubscriber<string, bool>("Automaton.IsTweakEnabled");
|
||||
logger.LogInformation("Automaton auto-snipe enabled: {IsTweakEnabled}", IsAutoSnipeEnabled);
|
||||
if (_pausedTweaks != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_pausedTweaks = new HashSet<string>();
|
||||
foreach (string conflictingTweak in ConflictingTweaks)
|
||||
{
|
||||
TryDisableTweak(conflictingTweak);
|
||||
}
|
||||
if (_configuration.General.AutoSnipe)
|
||||
{
|
||||
TryDisableTweak("AutoSnipeQuests");
|
||||
}
|
||||
}
|
||||
|
||||
private void TryDisableTweak(string tweak)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_isTweakEnabled.InvokeFunc(tweak))
|
||||
{
|
||||
_setTweakState.InvokeAction(tweak, arg2: false);
|
||||
_pausedTweaks.Add(tweak);
|
||||
_logger.LogInformation("Paused Automaton tweak: {Tweak}", tweak);
|
||||
}
|
||||
}
|
||||
catch (IpcError)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
private void RestoreConflictingTweaks()
|
||||
{
|
||||
if (_pausedTweaks == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (string pausedTweak in _pausedTweaks)
|
||||
{
|
||||
try
|
||||
{
|
||||
_setTweakState.InvokeAction(pausedTweak, arg2: true);
|
||||
_logger.LogInformation("Restored Automaton tweak: {Tweak}", pausedTweak);
|
||||
}
|
||||
catch (IpcError)
|
||||
{
|
||||
}
|
||||
}
|
||||
_pausedTweaks = null;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_questController.AutomationTypeChanged -= OnAutomationTypeChanged;
|
||||
RestoreConflictingTweaks();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue