diff --git a/FFXIVPlugin/IPC/Subscribers/PenumbraIPC.cs b/FFXIVPlugin/IPC/Subscribers/PenumbraIPC.cs index cd30914..0c3e176 100644 --- a/FFXIVPlugin/IPC/Subscribers/PenumbraIPC.cs +++ b/FFXIVPlugin/IPC/Subscribers/PenumbraIPC.cs @@ -1,17 +1,13 @@ using System; -using Dalamud.Game.Text.SeStringHandling; using Dalamud.Logging; using Dalamud.Plugin.Ipc; +using Dalamud.Plugin.Ipc.Exceptions; using XIVDeck.FFXIVPlugin.Base; -using XIVDeck.FFXIVPlugin.Game; -using XIVDeck.FFXIVPlugin.Resources.Localization; namespace XIVDeck.FFXIVPlugin.IPC.Subscribers; [PluginIpc] internal class PenumbraIPC : IPluginIpcClient { - private const int PenumbraIPCCompatVersion = 5; - // note: this is *extremely fragile* and honestly bad, but this will be instantiated by the system at a higher // level. if we want to consume the IPC, this should be a safe-ish way to do it, assuming null checks are used. internal static PenumbraIPC? Instance; @@ -21,7 +17,7 @@ internal class PenumbraIPC : IPluginIpcClient { private ICallGateSubscriber? _penumbraResolveDefaultSubscriber; private readonly ICallGateSubscriber _penumbraRegisteredSubscriber; - + internal PenumbraIPC() { Instance = this; @@ -42,10 +38,12 @@ public void Dispose() { this._penumbraApiVersionSubscriber = null; this._penumbraResolveDefaultSubscriber = null; + this.Enabled = false; + GC.SuppressFinalize(this); } - public int Version => this._penumbraApiVersionSubscriber?.InvokeFunc() ?? 0; + public int Version => this._penumbraApiVersionSubscriber?.InvokeFunc() ?? -1; private void _initializeIpc() { if (!Injections.PluginInterface.PluginNames.Contains("Penumbra")) { @@ -53,28 +51,25 @@ private void _initializeIpc() { return; } - var versionEndpoint = Injections.PluginInterface.GetIpcSubscriber("Penumbra.ApiVersion"); - - // this line may explode with an exception, but that should be fine as we'd normally catch that. - var version = versionEndpoint.InvokeFunc(); - - this._penumbraApiVersionSubscriber = versionEndpoint; + this._penumbraApiVersionSubscriber = Injections.PluginInterface.GetIpcSubscriber("Penumbra.ApiVersion"); + this._penumbraResolveDefaultSubscriber = Injections.PluginInterface.GetIpcSubscriber("Penumbra.ResolveDefaultPath"); - if (version == PenumbraIPCCompatVersion) { - this._penumbraResolveDefaultSubscriber = Injections.PluginInterface.GetIpcSubscriber("Penumbra.ResolveDefaultPath"); - - this.Enabled = true; - PluginLog.Information("Enabled Penumbra IPC connection!"); - } else { - PluginLog.Warning($"Penumbra IPC detected, but version {version} is incompatible!"); - DeferredChat.SendOrDeferMessage(new SeStringBuilder() - .AddUiForeground($"[{UIStrings.XIVDeck}] ", 514) - .AddText(UIStrings.PenumbraIPC_VersionMismatch) - .Build()); - } + this.Enabled = true; } public string ResolvePenumbraPath(string path) { - return this._penumbraResolveDefaultSubscriber?.InvokeFunc(path) ?? path; + if (!this.Enabled || this._penumbraResolveDefaultSubscriber == null) return path; + + try { + return this._penumbraResolveDefaultSubscriber.InvokeFunc(path); + } catch (IpcNotReadyError) { + PluginLog.Debug("Got a NotReadyError trying to call ResolveDefaultPath. Falling back to normal path"); + return path; + } catch (Exception ex) { + PluginLog.Error(ex, "Failed to invoke Penumbra IPC, disabling!"); + this.Enabled = false; + + return path; + } } } \ No newline at end of file diff --git a/FFXIVPlugin/XIVDeck.FFXIVPlugin.csproj b/FFXIVPlugin/XIVDeck.FFXIVPlugin.csproj index 18d78c1..88256b1 100644 --- a/FFXIVPlugin/XIVDeck.FFXIVPlugin.csproj +++ b/FFXIVPlugin/XIVDeck.FFXIVPlugin.csproj @@ -3,7 +3,7 @@ XIVDeck Game Plugin Kaz Wolfe Blacksite Technologies - 0.2.6 + 0.2.7 XIVDeck.FFXIVPlugin diff --git a/SDPlugin/package.json b/SDPlugin/package.json index bad566d..5a750fa 100644 --- a/SDPlugin/package.json +++ b/SDPlugin/package.json @@ -1,6 +1,6 @@ { "name": "@kazwolfe/xivdeck-sdplugin", - "version": "0.2.6", + "version": "0.2.7", "private": true, "scripts": { "build-release": "webpack --mode production",