Don't assign ventures if AR is set to collect only

This is only effective when the 'Operation' under Settings → General is
set to 'Collect', it ignores any hotkeys that would (normally) modify
how AR operates.
This commit is contained in:
Liza 2024-05-05 11:38:51 +02:00
parent 8a3a6399b2
commit 0425d446a1
Signed by: liza
GPG Key ID: 7199F8D727D55F67
3 changed files with 79 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Version>4.1</Version>
<Version>4.2</Version>
<LangVersion>12</LangVersion>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

View File

@ -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();
}

View File

@ -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();
}
}
}