From c07c74924f0e1a5a9826f7306f5bf7a00199e188 Mon Sep 17 00:00:00 2001 From: Anna Date: Sat, 25 Sep 2021 21:11:38 -0400 Subject: [PATCH] feat: add debug view Also check generator return value. Also don't update friend list while in content. --- NominaOcculta/GameFunctions.cs | 4 +- NominaOcculta/NameRepository.cs | 5 +++ NominaOcculta/Obscurer.cs | 14 ++++++- NominaOcculta/Plugin.cs | 16 +++++-- NominaOcculta/PluginUi.cs | 74 ++++++++++++++++++++++++++++++++- 5 files changed, 107 insertions(+), 6 deletions(-) diff --git a/NominaOcculta/GameFunctions.cs b/NominaOcculta/GameFunctions.cs index d23bf33..6fad9bc 100755 --- a/NominaOcculta/GameFunctions.cs +++ b/NominaOcculta/GameFunctions.cs @@ -85,7 +85,9 @@ namespace NominaOcculta { } public string? GenerateName(int race, int clan, int gender) { - this.InternalGenerateName(race, clan, gender, this.First, this.Last); + if (this.InternalGenerateName(race, clan, gender, this.First, this.Last) == IntPtr.Zero) { + return null; + } var first = Marshal.PtrToStringUTF8(Marshal.ReadIntPtr(this.First)); var last = Marshal.PtrToStringUTF8(Marshal.ReadIntPtr(this.Last)); diff --git a/NominaOcculta/NameRepository.cs b/NominaOcculta/NameRepository.cs index 1d345ab..8547ea1 100755 --- a/NominaOcculta/NameRepository.cs +++ b/NominaOcculta/NameRepository.cs @@ -11,8 +11,13 @@ namespace NominaOcculta { private Random Rng { get; } = new(); private Dictionary<(byte, byte, byte), Queue> Names { get; } = new(); + internal IReadOnlyDictionary<(byte, byte, byte), Queue> ReadOnlyNames => this.Names; + private Dictionary Replacements { get; } = new(); + internal IReadOnlyDictionary ReadonlyReplacements => this.Replacements; + private Dictionary LastSeenInfo { get; } = new(); + internal IReadOnlyDictionary ReadOnlyLastSeenInfo => this.LastSeenInfo; private readonly int _numRaces; diff --git a/NominaOcculta/Obscurer.cs b/NominaOcculta/Obscurer.cs index fb41fea..a4c46d0 100755 --- a/NominaOcculta/Obscurer.cs +++ b/NominaOcculta/Obscurer.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using Dalamud.Game; +using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text; @@ -38,8 +39,19 @@ namespace NominaOcculta { this.Plugin.Framework.Update -= this.OnFrameworkUpdate; } + private static readonly ConditionFlag[] DutyFlags = { + ConditionFlag.BoundByDuty, + ConditionFlag.BoundByDuty56, + ConditionFlag.BoundByDuty95, + ConditionFlag.BoundToDuty97, + }; + + private bool IsInDuty() { + return DutyFlags.Any(flag => this.Plugin.Condition[flag]); + } + private void OnFrameworkUpdate(Framework framework) { - if (this.UpdateTimer.Elapsed < TimeSpan.FromSeconds(5)) { + if (this.UpdateTimer.Elapsed < TimeSpan.FromSeconds(5) || this.IsInDuty()) { return; } diff --git a/NominaOcculta/Plugin.cs b/NominaOcculta/Plugin.cs index 66c26c9..89dd6d6 100755 --- a/NominaOcculta/Plugin.cs +++ b/NominaOcculta/Plugin.cs @@ -1,6 +1,8 @@ using Dalamud.Data; using Dalamud.Game; using Dalamud.Game.ClientState; +using Dalamud.Game.ClientState.Conditions; +using Dalamud.Game.ClientState.Keys; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.ClientState.Party; using Dalamud.Game.Command; @@ -25,12 +27,18 @@ namespace NominaOcculta { [PluginService] internal CommandManager CommandManager { get; private init; } + [PluginService] + internal Condition Condition { get; private set; } + [PluginService] internal DataManager DataManager { get; private init; } [PluginService] internal Framework Framework { get; private init; } + [PluginService] + internal KeyState KeyState { get; private init; } + [PluginService] internal PartyList PartyList { get; private init; } @@ -44,21 +52,23 @@ namespace NominaOcculta { internal GameFunctions Functions { get; } internal Configuration Config { get; } - internal Commands Commands { get; } + private Commands Commands { get; } internal NameRepository NameRepository { get; } - internal Obscurer Obscurer { get; } + private Obscurer Obscurer { get; } internal PluginUi Ui { get; } + #pragma warning disable 8618 public Plugin() { this.Common = new XivCommonBase(Hooks.NamePlates); this.Functions = new GameFunctions(this); - this.Config = this.Interface.GetPluginConfig() as Configuration ?? new Configuration(); + this.Config = this.Interface!.GetPluginConfig() as Configuration ?? new Configuration(); this.Ui = new PluginUi(this); this.NameRepository = new NameRepository(this); this.Obscurer = new Obscurer(this); this.Commands = new Commands(this); } + #pragma warning restore 8618 public void Dispose() { this.Commands.Dispose(); diff --git a/NominaOcculta/PluginUi.cs b/NominaOcculta/PluginUi.cs index 33f0998..3acf53c 100755 --- a/NominaOcculta/PluginUi.cs +++ b/NominaOcculta/PluginUi.cs @@ -1,4 +1,5 @@ using System; +using Dalamud.Game.ClientState.Keys; using ImGuiNET; namespace NominaOcculta { @@ -6,6 +7,7 @@ namespace NominaOcculta { private Plugin Plugin { get; } internal bool Visible; + private bool _debug; internal PluginUi(Plugin plugin) { this.Plugin = plugin; @@ -51,10 +53,80 @@ namespace NominaOcculta { ImGui.Separator(); if (ImGui.Button("Reset names")) { - this.Plugin.NameRepository.Reset(); + if (this.Plugin.KeyState[VirtualKey.CONTROL] && this.Plugin.KeyState[VirtualKey.SHIFT]) { + this._debug ^= true; + } else { + this.Plugin.NameRepository.Reset(); + } + } + + if (this._debug) { + if (ImGui.CollapsingHeader("Debug")) { + ImGui.PushID("debug"); + try { + this.DrawDebug(); + } finally { + ImGui.PopID(); + } + } } ImGui.End(); } + + private void DrawDebug() { + ImGui.TextUnformatted($"Initialised: {this.Plugin.NameRepository.Initialised}"); + + ImGui.Separator(); + + if (ImGui.TreeNode("Name queue")) { + foreach (var (info, queue) in this.Plugin.NameRepository.ReadOnlyNames) { + if (ImGui.CollapsingHeader($"{info}")) { + if (ImGui.BeginTable($"{info} table", 2)) { + foreach (var name in queue) { + ImGui.TableNextColumn(); + ImGui.TextUnformatted(name); + } + + ImGui.EndTable(); + } + } + } + + ImGui.TreePop(); + } + + if (ImGui.TreeNode("Replacements")) { + if (ImGui.BeginTable("replacements", 2)) { + foreach (var (name, replacement) in this.Plugin.NameRepository.ReadonlyReplacements) { + ImGui.TableNextColumn(); + ImGui.TextUnformatted(name); + + ImGui.TableNextColumn(); + ImGui.TextUnformatted(replacement); + } + + ImGui.EndTable(); + } + + ImGui.TreePop(); + } + + if (ImGui.TreeNode("Last seen info")) { + if (ImGui.BeginTable("last seen info", 2)) { + foreach (var (name, info) in this.Plugin.NameRepository.ReadOnlyLastSeenInfo) { + ImGui.TableNextColumn(); + ImGui.TextUnformatted(name); + + ImGui.TableNextColumn(); + ImGui.TextUnformatted($"{info}"); + } + + ImGui.EndTable(); + } + } + + ImGui.TreePop(); + } } }