diff --git a/Questionable/External/NavmeshIpc.cs b/Questionable/External/NavmeshIpc.cs index eb8c5b31..2f6c5e36 100644 --- a/Questionable/External/NavmeshIpc.cs +++ b/Questionable/External/NavmeshIpc.cs @@ -5,32 +5,33 @@ using System.Threading.Tasks; using Dalamud.Plugin; using Dalamud.Plugin.Ipc; using Dalamud.Plugin.Ipc.Exceptions; +using Microsoft.Extensions.Logging; namespace Questionable.External; internal sealed class NavmeshIpc { + private readonly ILogger _logger; private readonly ICallGateSubscriber _isNavReady; private readonly ICallGateSubscriber>> _navPathfind; private readonly ICallGateSubscriber, bool, object> _pathMoveTo; private readonly ICallGateSubscriber _pathStop; private readonly ICallGateSubscriber _pathIsRunning; private readonly ICallGateSubscriber> _pathListWaypoints; - private readonly ICallGateSubscriber _pathGetTolerance; private readonly ICallGateSubscriber _pathSetTolerance; private readonly ICallGateSubscriber _queryPointOnFloor; - public NavmeshIpc(IDalamudPluginInterface pluginInterface) + public NavmeshIpc(IDalamudPluginInterface pluginInterface, ILogger logger) { + _logger = logger; _isNavReady = pluginInterface.GetIpcSubscriber("vnavmesh.Nav.IsReady"); _navPathfind = pluginInterface.GetIpcSubscriber>>( - $"vnavmesh.Nav.PathfindCancelable"); + "vnavmesh.Nav.PathfindCancelable"); _pathMoveTo = pluginInterface.GetIpcSubscriber, bool, object>("vnavmesh.Path.MoveTo"); _pathStop = pluginInterface.GetIpcSubscriber("vnavmesh.Path.Stop"); _pathIsRunning = pluginInterface.GetIpcSubscriber("vnavmesh.Path.IsRunning"); _pathListWaypoints = pluginInterface.GetIpcSubscriber>("vnavmesh.Path.ListWaypoints"); - _pathGetTolerance = pluginInterface.GetIpcSubscriber("vnavmesh.Path.GetTolerance"); _pathSetTolerance = pluginInterface.GetIpcSubscriber("vnavmesh.Path.SetTolerance"); _queryPointOnFloor = pluginInterface.GetIpcSubscriber("vnavmesh.Query.Mesh.PointOnFloor"); @@ -51,31 +52,87 @@ internal sealed class NavmeshIpc } } - public bool IsPathRunning => _pathIsRunning.InvokeFunc(); + public bool IsPathRunning + { + get + { + try + { + return _pathIsRunning.InvokeFunc(); + } + catch (IpcError) + { + return false; + } + } + } - public void Stop() => _pathStop.InvokeAction(); + public void Stop() + { + try + { + _pathStop.InvokeAction(); + } + catch (IpcError e) + { + _logger.LogWarning(e, "Could not stop navigating via navmesh"); + } + } public Task> Pathfind(Vector3 localPlayerPosition, Vector3 targetPosition, bool fly, CancellationToken cancellationToken) { - _pathSetTolerance.InvokeAction(0.25f); - return _navPathfind.InvokeFunc(localPlayerPosition, targetPosition, fly, cancellationToken); + try + { + _pathSetTolerance.InvokeAction(0.25f); + return _navPathfind.InvokeFunc(localPlayerPosition, targetPosition, fly, cancellationToken); + } + catch (IpcError e) + { + _logger.LogWarning(e, "Could not pathfind via navmesh"); + return Task.FromException>(e); + } } public void MoveTo(List position, bool fly) { Stop(); - _pathMoveTo.InvokeAction(position, fly); + try + { + _pathMoveTo.InvokeAction(position, fly); + } + catch (IpcError e) + { + _logger.LogWarning(e, "Could not move via navmesh"); + } } public Vector3? GetPointOnFloor(Vector3 position) - => _queryPointOnFloor.InvokeFunc(position, true, 1); + { + try + { + return _queryPointOnFloor.InvokeFunc(position, true, 1); + } + catch (IpcError) + { + return null; + } + } public List GetWaypoints() { if (IsPathRunning) - return _pathListWaypoints.InvokeFunc(); + { + try + { + return _pathListWaypoints.InvokeFunc(); + } + catch (IpcError) + { + return []; + } + } else return []; }