diff --git a/ARControl/ARControl.csproj b/ARControl/ARControl.csproj index dbdd5ce..45ee9cc 100644 --- a/ARControl/ARControl.csproj +++ b/ARControl/ARControl.csproj @@ -1,7 +1,7 @@ net8.0-windows - 4.1 + 4.2 12 enable true diff --git a/ARControl/AutoRetainerControlPlugin.cs b/ARControl/AutoRetainerControlPlugin.cs index 89f4d21..96e51d4 100644 --- a/ARControl/AutoRetainerControlPlugin.cs +++ b/ARControl/AutoRetainerControlPlugin.cs @@ -39,10 +39,11 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin private readonly AllaganToolsIpc _allaganToolsIpc; private readonly ConfigWindow _configWindow; private readonly AutoRetainerApi _autoRetainerApi; + private readonly AutoRetainerReflection _autoRetainerReflection; public AutoRetainerControlPlugin(DalamudPluginInterface pluginInterface, IDataManager dataManager, IClientState clientState, IChatGui chatGui, ICommandManager commandManager, ITextureProvider textureProvider, - IPluginLog pluginLog) + IFramework framework, IPluginLog pluginLog) { ArgumentNullException.ThrowIfNull(pluginInterface); ArgumentNullException.ThrowIfNull(dataManager); @@ -67,6 +68,7 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin ECommonsMain.Init(_pluginInterface, this); _autoRetainerApi = new(); + _autoRetainerReflection = new AutoRetainerReflection(pluginInterface, framework, pluginLog, _autoRetainerApi); _pluginInterface.UiBuilder.Draw += _windowSystem.Draw; _pluginInterface.UiBuilder.OpenConfigUi += _configWindow.Toggle; @@ -102,6 +104,12 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin private unsafe uint? GetNextVenture(string retainerName, bool dryRun) { + if (!_autoRetainerReflection.ShouldReassign) + { + _pluginLog.Information("AutoRetainer is configured to not reassign ventures, so we are not checking any venture lists."); + return null; + } + var ch = _configuration.Characters.SingleOrDefault(x => x.LocalContentId == _clientState.LocalContentId); if (ch == null) { @@ -442,6 +450,7 @@ public sealed partial class AutoRetainerControlPlugin : IDalamudPlugin _pluginInterface.UiBuilder.Draw -= _windowSystem.Draw; _iconCache.Dispose(); + _autoRetainerReflection.Dispose(); _autoRetainerApi.Dispose(); ECommonsMain.Dispose(); } diff --git a/ARControl/External/AutoRetainerReflection.cs b/ARControl/External/AutoRetainerReflection.cs new file mode 100644 index 0000000..26d80a7 --- /dev/null +++ b/ARControl/External/AutoRetainerReflection.cs @@ -0,0 +1,68 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reflection; +using AutoRetainerAPI; +using Dalamud.Plugin; +using Dalamud.Plugin.Services; +using LLib; + +namespace ARControl.External +{ + internal sealed class AutoRetainerReflection : IDisposable + { + private readonly IPluginLog _pluginLog; + private readonly AutoRetainerApi _autoRetainerApi; + private readonly DalamudReflector _reflector; + + public AutoRetainerReflection(DalamudPluginInterface pluginInterface, IFramework framework, + IPluginLog pluginLog, AutoRetainerApi autoRetainerApi) + { + _pluginLog = pluginLog; + _autoRetainerApi = autoRetainerApi; + _reflector = new DalamudReflector(pluginInterface, framework, pluginLog); + } + + [SuppressMessage("Performance", "CA2000", Justification = "Should not dispose other plugins")] + public bool ShouldReassign + { + get + { + try + { + if (_autoRetainerApi.Ready && + _reflector.TryGetDalamudPlugin("AutoRetainer", out var autoRetainer, false, true)) + { + var config = + autoRetainer.GetType().GetProperty("C", BindingFlags.Static | BindingFlags.NonPublic)! + .GetValue(null); + if (config == null) + { + _pluginLog.Warning("Could not retrieve AR config"); + return true; + } + + bool dontReassign = (bool)config.GetType() + .GetField("_dontReassign", BindingFlags.Instance | BindingFlags.Public)! + .GetValue(config)!; + _pluginLog.Verbose($"DontReassign is set to {dontReassign}"); + return !dontReassign; + } + + + _pluginLog.Warning("Could not check if reassign is enabled, AutoRetainer not loaded"); + return true; + } + catch (Exception e) + { + _pluginLog.Warning(e, "Unable to check if reassign is enabled"); + return true; + } + } + } + + public void Dispose() + { + _reflector.Dispose(); + } + } +}