From cd2acb4d197b80c1829c36f1469ce81da6c3606e Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 8 Aug 2020 17:42:24 -0400 Subject: [PATCH] fix: make dictionary work for history Also don't filter out minions like that, since apparently that issue was fixed in Dalamud? --- Peeping Tom/PluginUI.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Peeping Tom/PluginUI.cs b/Peeping Tom/PluginUI.cs index 05bf364..d0429b5 100644 --- a/Peeping Tom/PluginUI.cs +++ b/Peeping Tom/PluginUI.cs @@ -3,13 +3,11 @@ using Dalamud.Game.Chat.SeStringHandling; using Dalamud.Game.Chat.SeStringHandling.Payloads; using Dalamud.Game.ClientState; using Dalamud.Game.ClientState.Actors.Types; -using Dalamud.Plugin; using ImGuiNET; using System; using System.Collections.Generic; using System.Linq; using System.Numerics; -using System.Reflection; using System.Runtime.InteropServices; namespace PeepingTom { @@ -326,17 +324,15 @@ namespace PeepingTom { private void ShowMainWindow() { IReadOnlyCollection targeting = this.plugin.Watcher.CurrentTargeters; + IReadOnlyCollection previousTargeters = this.plugin.Config.KeepHistory ? this.plugin.Watcher.PreviousTargeters : null; // to prevent looping over a subset of the actors repeatedly when multiple people are targeting, // create a dictionary for O(1) lookups by actor id Dictionary actors = null; - if (targeting.Count > 1) { - FieldInfo field = typeof(Actor).GetField("actorStruct", BindingFlags.Instance | BindingFlags.NonPublic); + if (targeting.Count + (previousTargeters?.Count ?? 0) > 1) { actors = this.plugin.Interface.ClientState.Actors // only take into account players .Where(actor => actor.ObjectKind == Dalamud.Game.ClientState.Actors.ObjectKind.Player) - // filter out minions - .Where(actor => ((Dalamud.Game.ClientState.Structs.Actor)field.GetValue(actor)).PlayerTargetStatus == 2) .ToDictionary(actor => actor.ActorId); } @@ -363,7 +359,7 @@ namespace PeepingTom { } if (this.plugin.Config.KeepHistory) { // get a list of the previous targeters that aren't currently targeting - Targeter[] previous = this.plugin.Watcher.PreviousTargeters + Targeter[] previous = previousTargeters .Where(old => targeting.All(actor => actor.ActorId != old.ActorId)) .Take(this.plugin.Config.NumHistory) .ToArray();