diff --git a/Peeping Tom.Ipc/IpcInfo.cs b/Peeping Tom.Ipc/IpcInfo.cs index 9bb2416..b67c65a 100755 --- a/Peeping Tom.Ipc/IpcInfo.cs +++ b/Peeping Tom.Ipc/IpcInfo.cs @@ -1,4 +1,5 @@ using Dalamud.Plugin; +using Dalamud.Plugin.Ipc; using PeepingTom.Ipc.From; using PeepingTom.Ipc.To; diff --git a/Peeping Tom.Ipc/JsonConverters.cs b/Peeping Tom.Ipc/JsonConverters.cs new file mode 100755 index 0000000..6c66a9d --- /dev/null +++ b/Peeping Tom.Ipc/JsonConverters.cs @@ -0,0 +1,27 @@ +using System; +using Dalamud.Game.Text.SeStringHandling; +using Newtonsoft.Json; + +namespace PeepingTom.Ipc { + public class SeStringConverter : JsonConverter { + public override void WriteJson(JsonWriter writer, SeString? value, JsonSerializer serializer) { + if (value == null) { + writer.WriteNull(); + return; + } + + var bytes = value.Encode(); + writer.WriteValue(Convert.ToBase64String(bytes)); + } + + public override SeString? ReadJson(JsonReader reader, Type objectType, SeString? existingValue, bool hasExistingValue, JsonSerializer serializer) { + var base64 = (string?) reader.Value; + if (base64 == null) { + return null; + } + + var bytes = Convert.FromBase64String(base64); + return SeString.Parse(bytes); + } + } +} diff --git a/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj b/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj index 565c6a4..af3c27d 100755 --- a/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj +++ b/Peeping Tom.Ipc/Peeping Tom.Ipc.csproj @@ -16,6 +16,10 @@ $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll false + + $(AppData)\XIVLauncher\addon\Hooks\dev\Newtonsoft.Json.dll + false + diff --git a/Peeping Tom.Ipc/Targeter.cs b/Peeping Tom.Ipc/Targeter.cs index d34a88f..3f30eed 100755 --- a/Peeping Tom.Ipc/Targeter.cs +++ b/Peeping Tom.Ipc/Targeter.cs @@ -3,10 +3,12 @@ using System.Linq; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.Text.SeStringHandling; +using Newtonsoft.Json; namespace PeepingTom.Ipc { [Serializable] public class Targeter { + [JsonConverter(typeof(SeStringConverter))] public SeString Name { get; } public uint HomeWorldId { get; } public uint ObjectId { get; } @@ -19,6 +21,14 @@ namespace PeepingTom.Ipc { this.When = DateTime.UtcNow; } + [JsonConstructor] + public Targeter(SeString name, uint homeWorldId, uint objectId, DateTime when) { + this.Name = name; + this.HomeWorldId = homeWorldId; + this.ObjectId = objectId; + this.When = when; + } + public PlayerCharacter? GetPlayerCharacter(ObjectTable objectTable) { return objectTable.FirstOrDefault(actor => actor.ObjectId == this.ObjectId && actor is PlayerCharacter) as PlayerCharacter; } diff --git a/Peeping Tom/IpcManager.cs b/Peeping Tom/IpcManager.cs index d801ab9..d6b0757 100755 --- a/Peeping Tom/IpcManager.cs +++ b/Peeping Tom/IpcManager.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using Dalamud.Plugin; +using Dalamud.Plugin.Ipc; using PeepingTom.Ipc; using PeepingTom.Ipc.From; using PeepingTom.Ipc.To; diff --git a/Peeping Tom/Peeping Tom.csproj b/Peeping Tom/Peeping Tom.csproj index d1f646b..b983d6e 100755 --- a/Peeping Tom/Peeping Tom.csproj +++ b/Peeping Tom/Peeping Tom.csproj @@ -27,10 +27,6 @@ $(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll False - - $(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll - False - $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll False @@ -39,6 +35,10 @@ $(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll False + + $(AppData)\XIVLauncher\addon\Hooks\dev\Newtonsoft.Json.dll + False + diff --git a/Peeping Tom/TargetWatcher.cs b/Peeping Tom/TargetWatcher.cs index 516173c..1b44422 100644 --- a/Peeping Tom/TargetWatcher.cs +++ b/Peeping Tom/TargetWatcher.cs @@ -10,6 +10,7 @@ using Dalamud.Game; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text; +using Dalamud.Logging; using PeepingTom.Ipc; using PeepingTom.Resources; @@ -64,11 +65,19 @@ namespace PeepingTom { var newCurrent = this.GetTargeting(this.Plugin.ObjectTable, player); foreach (var newTargeter in newCurrent.Where(t => this.Current.All(c => c.ObjectId != t.ObjectId))) { - this.Plugin.IpcManager.SendNewTargeter(newTargeter); + try { + this.Plugin.IpcManager.SendNewTargeter(newTargeter); + } catch (Exception ex) { + PluginLog.LogError(ex, "Failed to send IPC message"); + } } foreach (var stopped in this.Current.Where(t => newCurrent.All(c => c.ObjectId != t.ObjectId))) { - this.Plugin.IpcManager.SendStoppedTargeting(stopped); + try { + this.Plugin.IpcManager.SendStoppedTargeting(stopped); + } catch (Exception ex) { + PluginLog.LogError(ex, "Failed to send IPC message"); + } } this.Current = newCurrent;