refactor: update IPC to work
This commit is contained in:
parent
043c1efc1f
commit
d0305b14ec
|
@ -1,4 +1,5 @@
|
|||
using Dalamud.Plugin;
|
||||
using Dalamud.Plugin.Ipc;
|
||||
using PeepingTom.Ipc.From;
|
||||
using PeepingTom.Ipc.To;
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace PeepingTom.Ipc {
|
||||
public class SeStringConverter : JsonConverter<SeString> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,10 @@
|
|||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>false</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -27,10 +27,6 @@
|
|||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGui.NET.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="ImGuiScene">
|
||||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\ImGuiScene.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Lumina">
|
||||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
|
@ -39,6 +35,10 @@
|
|||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Lumina.Excel.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>$(AppData)\XIVLauncher\addon\Hooks\dev\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DalamudPackager" Version="2.1.2"/>
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue