forked from aly/qstbak
137 lines
3.3 KiB
C#
137 lines
3.3 KiB
C#
using Dalamud.Plugin;
|
|
using Dalamud.Plugin.Ipc;
|
|
using Dalamud.Plugin.Ipc.Exceptions;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Questionable.External;
|
|
|
|
internal sealed class AutoHookIpc
|
|
{
|
|
private readonly ILogger<AutoHookIpc> _logger;
|
|
|
|
private readonly ICallGateSubscriber<bool> _getPluginState;
|
|
|
|
private readonly ICallGateSubscriber<bool, object> _setPluginState;
|
|
|
|
private readonly ICallGateSubscriber<bool> _getAutoStartFishing;
|
|
|
|
private readonly ICallGateSubscriber<bool, object> _setAutoStartFishing;
|
|
|
|
private readonly ICallGateSubscriber<uint, bool> _swapBaitById;
|
|
|
|
private readonly ICallGateSubscriber<string, object> _createAndSelectAnonymousPreset;
|
|
|
|
private readonly ICallGateSubscriber<object> _deleteAllAnonymousPresets;
|
|
|
|
public AutoHookIpc(IDalamudPluginInterface pluginInterface, ILogger<AutoHookIpc> logger)
|
|
{
|
|
_logger = logger;
|
|
_getPluginState = pluginInterface.GetIpcSubscriber<bool>("AutoHook.GetPluginState");
|
|
_setPluginState = pluginInterface.GetIpcSubscriber<bool, object>("AutoHook.SetPluginState");
|
|
_getAutoStartFishing = pluginInterface.GetIpcSubscriber<bool>("AutoHook.GetAutoStartFishing");
|
|
_setAutoStartFishing = pluginInterface.GetIpcSubscriber<bool, object>("AutoHook.SetAutoStartFishing");
|
|
_swapBaitById = pluginInterface.GetIpcSubscriber<uint, bool>("AutoHook.SwapBaitById");
|
|
_createAndSelectAnonymousPreset = pluginInterface.GetIpcSubscriber<string, object>("AutoHook.CreateAndSelectAnonymousPreset");
|
|
_deleteAllAnonymousPresets = pluginInterface.GetIpcSubscriber<object>("AutoHook.DeleteAllAnonymousPresets");
|
|
}
|
|
|
|
public bool IsAvailable()
|
|
{
|
|
try
|
|
{
|
|
_getPluginState.InvokeFunc();
|
|
return true;
|
|
}
|
|
catch (IpcError)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public bool GetPluginState()
|
|
{
|
|
try
|
|
{
|
|
return _getPluginState.InvokeFunc();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to get AutoHook plugin state");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void SetPluginState(bool enabled)
|
|
{
|
|
try
|
|
{
|
|
_setPluginState.InvokeAction(enabled);
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to set AutoHook plugin state");
|
|
}
|
|
}
|
|
|
|
public bool GetAutoStartFishing()
|
|
{
|
|
try
|
|
{
|
|
return _getAutoStartFishing.InvokeFunc();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to get AutoHook auto-start fishing state");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void SetAutoStartFishing(bool enabled)
|
|
{
|
|
try
|
|
{
|
|
_setAutoStartFishing.InvokeAction(enabled);
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to set AutoHook auto-start fishing state");
|
|
}
|
|
}
|
|
|
|
public bool SwapBaitById(uint baitId)
|
|
{
|
|
try
|
|
{
|
|
return _swapBaitById.InvokeFunc(baitId);
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to swap bait to {BaitId}", baitId);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void CreateAndSelectAnonymousPreset(string compressedPreset)
|
|
{
|
|
try
|
|
{
|
|
_createAndSelectAnonymousPreset.InvokeAction(compressedPreset);
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to create and select anonymous AutoHook preset");
|
|
}
|
|
}
|
|
|
|
public void DeleteAllAnonymousPresets()
|
|
{
|
|
try
|
|
{
|
|
_deleteAllAnonymousPresets.InvokeAction();
|
|
}
|
|
catch (IpcError exception)
|
|
{
|
|
_logger.LogError(exception, "Unable to delete anonymous AutoHook presets");
|
|
}
|
|
}
|
|
}
|