refactor: new code style in DalamudDataWindow.cs, fix collapse bug

This commit is contained in:
goat 2021-03-31 23:33:35 +02:00
parent 0d8d9e57d4
commit e11c209f77
3 changed files with 306 additions and 239 deletions

View file

@ -9,3 +9,4 @@ using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "This is annoying", Scope = "namespaceanddescendants", Target = "~N:Dalamud")] [assembly: SuppressMessage("StyleCop.CSharp.LayoutRules", "SA1503:Braces should not be omitted", Justification = "This is annoying", Scope = "namespaceanddescendants", Target = "~N:Dalamud")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1127:Generic type constraints should be on their own line", Justification = "I like this better", Scope = "namespaceanddescendants", Target = "~N:Dalamud")] [assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1127:Generic type constraints should be on their own line", Justification = "I like this better", Scope = "namespaceanddescendants", Target = "~N:Dalamud")]
[assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "We don't do those yet")] [assembly: SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1633:File should have header", Justification = "We don't do those yet")]
[assembly: SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1118:Parameter should not span multiple lines", Justification = "Preventing long lines", Scope = "namespaceanddescendants", Target = "~N:Dalamud")]

View file

@ -2,8 +2,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Dynamic; using System.Dynamic;
using System.Linq; using System.Linq;
using System.Net.Mime;
using System.Numerics; using System.Numerics;
using Dalamud.Game.Chat; using Dalamud.Game.Chat;
using Dalamud.Game.ClientState; using Dalamud.Game.ClientState;
using Dalamud.Game.ClientState.Actors.Types; using Dalamud.Game.ClientState.Actors.Types;
@ -13,15 +13,17 @@ using Dalamud.Game.Internal;
using Dalamud.Game.Internal.Gui.Addon; using Dalamud.Game.Internal.Gui.Addon;
using Dalamud.Plugin; using Dalamud.Plugin;
using ImGuiNET; using ImGuiNET;
using JetBrains.Annotations;
using Newtonsoft.Json; using Newtonsoft.Json;
using Serilog; using Serilog;
using SharpDX.Direct3D11;
namespace Dalamud.Interface namespace Dalamud.Interface
{ {
class DalamudDataWindow { /// <summary>
private Dalamud dalamud; /// Class responsible for drawing the data/debug window.
/// </summary>
internal class DalamudDataWindow
{
private readonly Dalamud dalamud;
private bool wasReady; private bool wasReady;
private string serverOpString; private string serverOpString;
@ -38,45 +40,55 @@ namespace Dalamud.Interface
private int inputAddonIndex; private int inputAddonIndex;
private Addon resultAddon; private Addon resultAddon;
private IntPtr findAgentInterfacePtr;
private bool resolveGameData = false; private bool resolveGameData = false;
private UIDebug UIDebug = null; private UIDebug addonInspector = null;
private uint copyButtonIndex = 0; private uint copyButtonIndex = 0;
public DalamudDataWindow(Dalamud dalamud) { /// <summary>
/// Initializes a new instance of the <see cref="DalamudDataWindow"/> class.
/// </summary>
/// <param name="dalamud">The Dalamud instance to access data of.</param>
public DalamudDataWindow(Dalamud dalamud)
{
this.dalamud = dalamud; this.dalamud = dalamud;
Load(); this.Load();
} }
private void Load() { /// <summary>
if (this.dalamud.Data.IsDataReady) /// Draw the window via ImGui.
{ /// </summary>
this.serverOpString = JsonConvert.SerializeObject(this.dalamud.Data.ServerOpCodes, Formatting.Indented); /// <returns>Whether or not the window is open.</returns>
this.wasReady = true; public bool Draw()
} {
}
public bool Draw() {
this.copyButtonIndex = 0; this.copyButtonIndex = 0;
ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.FirstUseEver); ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.FirstUseEver);
var isOpen = true; var isOpen = true;
if (!ImGui.Begin("Dalamud Data", ref isOpen)) { ImGui.Begin("Dalamud Data", ref isOpen);
ImGui.End();
return false;
}
// Main window // Main window
if (ImGui.Button("Force Reload")) if (ImGui.Button("Force Reload"))
Load(); this.Load();
ImGui.SameLine(); ImGui.SameLine();
var copy = ImGui.Button("Copy all"); var copy = ImGui.Button("Copy all");
ImGui.SameLine(); ImGui.SameLine();
ImGui.Combo("Data kind", ref this.currentKind, new[] {"ServerOpCode", "Address", "Actor Table", "Font Test", "Party List", "Plugin IPC", "Condition", "Gauge", "Command", "Addon", "Addon Inspector", "StartInfo", "Target" },
13); ImGui.Combo(
"Data kind",
ref this.currentKind,
new[]
{
"ServerOpCode", "Address", "Actor Table", "Font Test", "Party List", "Plugin IPC", "Condition",
"Gauge", "Command", "Addon", "Addon Inspector", "StartInfo", "Target",
},
13);
ImGui.Checkbox("Resolve GameData", ref this.resolveGameData); ImGui.Checkbox("Resolve GameData", ref this.resolveGameData);
ImGui.BeginChild("scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.HorizontalScrollbar); ImGui.BeginChild("scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.HorizontalScrollbar);
@ -86,121 +98,68 @@ namespace Dalamud.Interface
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0)); ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
try { try
{
if (this.wasReady) if (this.wasReady)
switch (this.currentKind) { {
switch (this.currentKind)
{
case 0: case 0:
ImGui.TextUnformatted(this.serverOpString); ImGui.TextUnformatted(this.serverOpString);
break; break;
case 1: case 1:
ImGui.InputText(".text sig", ref this.inputSig, 400); ImGui.InputText(".text sig", ref this.inputSig, 400);
if (ImGui.Button("Resolve")) { if (ImGui.Button("Resolve"))
try { {
try
{
this.sigResult = this.dalamud.SigScanner.ScanText(this.inputSig); this.sigResult = this.dalamud.SigScanner.ScanText(this.inputSig);
} catch (KeyNotFoundException) { }
catch (KeyNotFoundException)
{
this.sigResult = new IntPtr(-1); this.sigResult = new IntPtr(-1);
} }
} }
ImGui.Text($"Result: {this.sigResult.ToInt64():X}"); ImGui.Text($"Result: {this.sigResult.ToInt64():X}");
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button($"C{this.copyButtonIndex++}")) { if (ImGui.Button($"C{this.copyButtonIndex++}"))
ImGui.SetClipboardText(this.sigResult.ToInt64().ToString("x")); ImGui.SetClipboardText(this.sigResult.ToInt64().ToString("x"));
}
foreach (var debugScannedValue in BaseAddressResolver.DebugScannedValues) { foreach (var debugScannedValue in BaseAddressResolver.DebugScannedValues)
{
ImGui.TextUnformatted($"{debugScannedValue.Key}"); ImGui.TextUnformatted($"{debugScannedValue.Key}");
foreach (var valueTuple in debugScannedValue.Value) { foreach (var valueTuple in debugScannedValue.Value)
{
ImGui.TextUnformatted( ImGui.TextUnformatted(
$" {valueTuple.Item1} - 0x{valueTuple.Item2.ToInt64():x}"); $" {valueTuple.Item1} - 0x{valueTuple.Item2.ToInt64():x}");
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button($"C##copyAddress{copyButtonIndex++}")) { if (ImGui.Button($"C##copyAddress{this.copyButtonIndex++}"))
ImGui.SetClipboardText(valueTuple.Item2.ToInt64().ToString("x")); ImGui.SetClipboardText(valueTuple.Item2.ToInt64().ToString("x"));
}
} }
} }
break; break;
// AT // AT
case 2: { case 2:
var stateString = string.Empty; this.DrawActorTable();
// LocalPlayer is null in a number of situations (at least with the current visible-actors list)
// which would crash here.
if (this.dalamud.ClientState.Actors.Length == 0) {
ImGui.TextUnformatted("Data not ready.");
} else if (this.dalamud.ClientState.LocalPlayer == null) {
ImGui.TextUnformatted("LocalPlayer null.");
} else {
stateString +=
$"FrameworkBase: {this.dalamud.Framework.Address.BaseAddress.ToInt64():X}\n";
stateString += $"ActorTableLen: {this.dalamud.ClientState.Actors.Length}\n";
stateString += $"LocalPlayerName: {this.dalamud.ClientState.LocalPlayer.Name}\n";
stateString +=
$"CurrentWorldName: {(this.resolveGameData ? this.dalamud.ClientState.LocalPlayer.CurrentWorld.GameData.Name : this.dalamud.ClientState.LocalPlayer.CurrentWorld.Id.ToString())}\n";
stateString +=
$"HomeWorldName: {(this.resolveGameData ? this.dalamud.ClientState.LocalPlayer.HomeWorld.GameData.Name : this.dalamud.ClientState.LocalPlayer.HomeWorld.Id.ToString())}\n";
stateString += $"LocalCID: {this.dalamud.ClientState.LocalContentId:X}\n";
stateString +=
$"LastLinkedItem: {this.dalamud.Framework.Gui.Chat.LastLinkedItemId.ToString()}\n";
stateString += $"TerritoryType: {this.dalamud.ClientState.TerritoryType}\n\n";
ImGui.TextUnformatted(stateString);
ImGui.Checkbox("Draw actors on screen", ref this.drawActors);
ImGui.SliderFloat("Draw Distance", ref this.maxActorDrawDistance, 2f, 40f);
for (var i = 0; i < this.dalamud.ClientState.Actors.Length; i++) {
var actor = this.dalamud.ClientState.Actors[i];
if (actor == null)
continue;
PrintActor(actor, i.ToString());
if (this.drawActors &&
this.dalamud.Framework.Gui.WorldToScreen(actor.Position, out var screenCoords)
) {
ImGui.PushID("ActorWindow" + i);
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
if (actor.YalmDistanceX > this.maxActorDrawDistance)
continue;
ImGui.SetNextWindowBgAlpha(
Math.Max(1f - (actor.YalmDistanceX / this.maxActorDrawDistance), 0.2f));
if (ImGui.Begin("Actor" + i,
ImGuiWindowFlags.NoDecoration |
ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoMove |
ImGuiWindowFlags.NoMouseInputs |
ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNav)) {
ImGui.Text(
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{i}] - {actor.ObjectKind} - {actor.Name}");
ImGui.End();
}
ImGui.PopID();
}
}
}
}
break; break;
// Font // Font
case 3: case 3:
var specialChars = string.Empty; var specialChars = string.Empty;
for (var i = 0xE020; i <= 0xE0DB; i++) { for (var i = 0xE020; i <= 0xE0DB; i++)
specialChars += $"0x{i:X} - {(SeIconChar) i} - {(char) i}\n"; specialChars += $"0x{i:X} - {(SeIconChar)i} - {(char)i}\n";
}
ImGui.TextUnformatted(specialChars); ImGui.TextUnformatted(specialChars);
foreach (var fontAwesomeIcon in Enum.GetValues(typeof(FontAwesomeIcon)) foreach (var fontAwesomeIcon in Enum.GetValues(typeof(FontAwesomeIcon))
.Cast<FontAwesomeIcon>()) { .Cast<FontAwesomeIcon>())
ImGui.Text(((int) fontAwesomeIcon.ToIconChar()).ToString("X") + " - "); {
ImGui.Text(((int)fontAwesomeIcon.ToIconChar()).ToString("X") + " - ");
ImGui.SameLine(); ImGui.SameLine();
ImGui.PushFont(InterfaceManager.IconFont); ImGui.PushFont(InterfaceManager.IconFont);
@ -214,14 +173,18 @@ namespace Dalamud.Interface
case 4: case 4:
var partyString = string.Empty; var partyString = string.Empty;
if (this.dalamud.ClientState.PartyList.Length == 0) { if (this.dalamud.ClientState.PartyList.Length == 0)
{
ImGui.TextUnformatted("Data not ready."); ImGui.TextUnformatted("Data not ready.");
} else { }
else
{
partyString += $"{this.dalamud.ClientState.PartyList.Count} Members\n"; partyString += $"{this.dalamud.ClientState.PartyList.Count} Members\n";
for (var i = 0; i < this.dalamud.ClientState.PartyList.Count; i++) { for (var i = 0; i < this.dalamud.ClientState.PartyList.Count; i++)
{
var member = this.dalamud.ClientState.PartyList[i]; var member = this.dalamud.ClientState.PartyList[i];
if (member == null) { if (member == null)
{
partyString += partyString +=
$"[{i}] was null\n"; $"[{i}] was null\n";
continue; continue;
@ -238,43 +201,7 @@ namespace Dalamud.Interface
// Subscriptions // Subscriptions
case 5: case 5:
var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null, this.DrawIpcDebug();
PluginLoadReason.Boot);
var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null,
PluginLoadReason.Boot);
if (ImGui.Button("Add test sub"))
i1.Subscribe("DalamudTestPub", o => {
dynamic msg = o;
Log.Debug(msg.Expand);
});
if (ImGui.Button("Add test sub any"))
i1.SubscribeAny((o, a) => {
dynamic msg = a;
Log.Debug($"From {o}: {msg.Expand}");
});
if (ImGui.Button("Remove test sub")) i1.Unsubscribe("DalamudTestPub");
if (ImGui.Button("Remove test sub any")) i1.UnsubscribeAny();
if (ImGui.Button("Send test message")) {
dynamic testMsg = new ExpandoObject();
testMsg.Expand = "dong";
i2.SendMessage(testMsg);
}
// This doesn't actually work, so don't mind it - impl relies on plugins being registered in PluginManager
if (ImGui.Button("Send test message any")) {
dynamic testMsg = new ExpandoObject();
testMsg.Expand = "dong";
i2.SendMessage("DalamudTestSub", testMsg);
}
foreach (var sub in this.dalamud.PluginManager.IpcSubscriptions) {
ImGui.Text($"Source:{sub.SourcePluginName} Sub:{sub.SubPluginName}");
}
break; break;
@ -289,22 +216,20 @@ namespace Dalamud.Interface
var didAny = false; var didAny = false;
for (var i = 0; i < Condition.MaxConditionEntries; i++) { for (var i = 0; i < Condition.MaxConditionEntries; i++)
var typedCondition = (ConditionFlag) i; {
var typedCondition = (ConditionFlag)i;
var cond = this.dalamud.ClientState.Condition[typedCondition]; var cond = this.dalamud.ClientState.Condition[typedCondition];
if (!cond) { if (!cond) continue;
continue;
}
didAny = true; didAny = true;
ImGui.Text($"ID: {i} Enum: {typedCondition}"); ImGui.Text($"ID: {i} Enum: {typedCondition}");
} }
if (!didAny) { if (!didAny)
ImGui.Text("None. Talk to a shop NPC or visit a market board to find out more!!!!!!!"); ImGui.Text("None. Talk to a shop NPC or visit a market board to find out more!!!!!!!");
}
break; break;
@ -317,57 +242,21 @@ namespace Dalamud.Interface
// Command // Command
case 8: case 8:
foreach (var command in this.dalamud.CommandManager.Commands) { foreach (var command in this.dalamud.CommandManager.Commands)
ImGui.Text( ImGui.Text($"{command.Key}\n -> {command.Value.HelpMessage}\n -> In help: {command.Value.ShowInHelp}\n\n");
$"{command.Key}\n -> {command.Value.HelpMessage}\n -> In help: {command.Value.ShowInHelp}\n\n");
}
break; break;
// Addon // Addon
case 9: case 9:
ImGui.InputText("Addon name", ref this.inputAddonName, 256); this.DrawAddonDebug();
ImGui.InputInt("Addon Index", ref this.inputAddonIndex);
if (ImGui.Button("Get Addon")) {
this.resultAddon =
this.dalamud.Framework.Gui.GetAddonByName(
this.inputAddonName, this.inputAddonIndex);
}
if (ImGui.Button("Find Agent")) {
this.findAgentInterfacePtr = FindAgentInterface(this.inputAddonName);
}
if (this.resultAddon != null) {
ImGui.TextUnformatted(
$"{this.resultAddon.Name} - 0x{this.resultAddon.Address.ToInt64():x}\n v:{this.resultAddon.Visible} x:{this.resultAddon.X} y:{this.resultAddon.Y} s:{this.resultAddon.Scale}, w:{this.resultAddon.Width}, h:{this.resultAddon.Height}");
}
if (this.findAgentInterfacePtr != IntPtr.Zero) {
ImGui.TextUnformatted(
$"Agent: 0x{this.findAgentInterfacePtr.ToInt64():x}");
ImGui.SameLine();
if (ImGui.Button("C"))
{
ImGui.SetClipboardText(this.findAgentInterfacePtr.ToInt64().ToString("x"));
}
}
if (ImGui.Button("Get Base UI object")) {
var addr = this.dalamud.Framework.Gui.GetBaseUIObject().ToInt64().ToString("x");
Log.Information("{0}", addr);
ImGui.SetClipboardText(addr);
}
break; break;
// Addon Inspector // Addon Inspector
case 10: case 10:
{ {
this.UIDebug ??= new UIDebug(this.dalamud); this.addonInspector ??= new UIDebug(this.dalamud);
this.UIDebug.Draw(); this.addonInspector.Draw();
break; break;
} }
@ -378,44 +267,17 @@ namespace Dalamud.Interface
// Target // Target
case 12: case 12:
var targetMgr = this.dalamud.ClientState.Targets; this.DrawTargetDebug();
if (targetMgr.CurrentTarget != null)
PrintActor(targetMgr.CurrentTarget, "CurrentTarget");
if (targetMgr.FocusTarget != null)
PrintActor(targetMgr.FocusTarget, "FocusTarget");
if (targetMgr.MouseOverTarget != null)
PrintActor(targetMgr.MouseOverTarget, "MouseOverTarget");
if (targetMgr.PreviousTarget != null)
PrintActor(targetMgr.PreviousTarget, "PreviousTarget");
if (ImGui.Button("Clear CT"))
targetMgr.ClearCurrentTarget();
if (ImGui.Button("Clear FT"))
targetMgr.ClearFocusTarget();
var localPlayer = this.dalamud.ClientState.LocalPlayer;
if (localPlayer != null)
{
if (ImGui.Button("Set CT"))
targetMgr.SetCurrentTarget(localPlayer);
if (ImGui.Button("Set FT"))
targetMgr.SetFocusTarget(localPlayer);
} else {
ImGui.Text("LocalPlayer is null.");
}
break; break;
} }
}
else else
{
ImGui.TextUnformatted("Data not ready."); ImGui.TextUnformatted("Data not ready.");
} catch (Exception ex) { }
}
catch (Exception ex)
{
ImGui.TextUnformatted(ex.ToString()); ImGui.TextUnformatted(ex.ToString());
} }
@ -427,7 +289,211 @@ namespace Dalamud.Interface
return isOpen; return isOpen;
} }
private IntPtr findAgentInterfacePtr; private void DrawActorTable()
{
var stateString = string.Empty;
// LocalPlayer is null in a number of situations (at least with the current visible-actors list)
// which would crash here.
if (this.dalamud.ClientState.Actors.Length == 0)
{
ImGui.TextUnformatted("Data not ready.");
}
else if (this.dalamud.ClientState.LocalPlayer == null)
{
ImGui.TextUnformatted("LocalPlayer null.");
}
else
{
stateString +=
$"FrameworkBase: {this.dalamud.Framework.Address.BaseAddress.ToInt64():X}\n";
stateString += $"ActorTableLen: {this.dalamud.ClientState.Actors.Length}\n";
stateString += $"LocalPlayerName: {this.dalamud.ClientState.LocalPlayer.Name}\n";
stateString +=
$"CurrentWorldName: {(this.resolveGameData ? this.dalamud.ClientState.LocalPlayer.CurrentWorld.GameData.Name : this.dalamud.ClientState.LocalPlayer.CurrentWorld.Id.ToString())}\n";
stateString +=
$"HomeWorldName: {(this.resolveGameData ? this.dalamud.ClientState.LocalPlayer.HomeWorld.GameData.Name : this.dalamud.ClientState.LocalPlayer.HomeWorld.Id.ToString())}\n";
stateString += $"LocalCID: {this.dalamud.ClientState.LocalContentId:X}\n";
stateString +=
$"LastLinkedItem: {this.dalamud.Framework.Gui.Chat.LastLinkedItemId.ToString()}\n";
stateString += $"TerritoryType: {this.dalamud.ClientState.TerritoryType}\n\n";
ImGui.TextUnformatted(stateString);
ImGui.Checkbox("Draw actors on screen", ref this.drawActors);
ImGui.SliderFloat("Draw Distance", ref this.maxActorDrawDistance, 2f, 40f);
for (var i = 0; i < this.dalamud.ClientState.Actors.Length; i++)
{
var actor = this.dalamud.ClientState.Actors[i];
if (actor == null)
continue;
this.PrintActor(actor, i.ToString());
if (this.drawActors &&
this.dalamud.Framework.Gui.WorldToScreen(actor.Position, out var screenCoords))
{
ImGui.PushID("ActorWindow" + i);
ImGui.SetNextWindowPos(new Vector2(screenCoords.X, screenCoords.Y));
if (actor.YalmDistanceX > this.maxActorDrawDistance)
continue;
ImGui.SetNextWindowBgAlpha(
Math.Max(1f - (actor.YalmDistanceX / this.maxActorDrawDistance), 0.2f));
if (ImGui.Begin(
"Actor" + i,
ImGuiWindowFlags.NoDecoration |
ImGuiWindowFlags.AlwaysAutoResize |
ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoMove |
ImGuiWindowFlags.NoMouseInputs |
ImGuiWindowFlags.NoFocusOnAppearing | ImGuiWindowFlags.NoNav))
{
ImGui.Text(
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{i}] - {actor.ObjectKind} - {actor.Name}");
ImGui.End();
}
ImGui.PopID();
}
}
}
}
private void DrawIpcDebug()
{
var i1 = new DalamudPluginInterface(this.dalamud, "DalamudTestSub", null, PluginLoadReason.Boot);
var i2 = new DalamudPluginInterface(this.dalamud, "DalamudTestPub", null, PluginLoadReason.Boot);
if (ImGui.Button("Add test sub"))
{
i1.Subscribe("DalamudTestPub", o =>
{
dynamic msg = o;
Log.Debug(msg.Expand);
});
}
if (ImGui.Button("Add test sub any"))
{
i1.SubscribeAny((o, a) =>
{
dynamic msg = a;
Log.Debug($"From {o}: {msg.Expand}");
});
}
if (ImGui.Button("Remove test sub")) i1.Unsubscribe("DalamudTestPub");
if (ImGui.Button("Remove test sub any")) i1.UnsubscribeAny();
if (ImGui.Button("Send test message"))
{
dynamic testMsg = new ExpandoObject();
testMsg.Expand = "dong";
i2.SendMessage(testMsg);
}
// This doesn't actually work, so don't mind it - impl relies on plugins being registered in PluginManager
if (ImGui.Button("Send test message any"))
{
dynamic testMsg = new ExpandoObject();
testMsg.Expand = "dong";
i2.SendMessage("DalamudTestSub", testMsg);
}
foreach (var sub in this.dalamud.PluginManager.IpcSubscriptions)
ImGui.Text($"Source:{sub.SourcePluginName} Sub:{sub.SubPluginName}");
}
private void DrawAddonDebug()
{
ImGui.InputText("Addon name", ref this.inputAddonName, 256);
ImGui.InputInt("Addon Index", ref this.inputAddonIndex);
if (ImGui.Button("Get Addon"))
{
this.resultAddon =
this.dalamud.Framework.Gui.GetAddonByName(
this.inputAddonName, this.inputAddonIndex);
}
if (ImGui.Button("Find Agent"))
this.findAgentInterfacePtr = this.FindAgentInterface(this.inputAddonName);
if (this.resultAddon != null)
{
ImGui.TextUnformatted(
$"{this.resultAddon.Name} - 0x{this.resultAddon.Address.ToInt64():x}\n v:{this.resultAddon.Visible} x:{this.resultAddon.X} y:{this.resultAddon.Y} s:{this.resultAddon.Scale}, w:{this.resultAddon.Width}, h:{this.resultAddon.Height}");
}
if (this.findAgentInterfacePtr != IntPtr.Zero)
{
ImGui.TextUnformatted(
$"Agent: 0x{this.findAgentInterfacePtr.ToInt64():x}");
ImGui.SameLine();
if (ImGui.Button("C"))
ImGui.SetClipboardText(this.findAgentInterfacePtr.ToInt64().ToString("x"));
}
if (ImGui.Button("Get Base UI object"))
{
var addr = this.dalamud.Framework.Gui.GetBaseUIObject().ToInt64().ToString("x");
Log.Information("{0}", addr);
ImGui.SetClipboardText(addr);
}
}
private void DrawTargetDebug()
{
var targetMgr = this.dalamud.ClientState.Targets;
if (targetMgr.CurrentTarget != null)
this.PrintActor(targetMgr.CurrentTarget, "CurrentTarget");
if (targetMgr.FocusTarget != null)
this.PrintActor(targetMgr.FocusTarget, "FocusTarget");
if (targetMgr.MouseOverTarget != null)
this.PrintActor(targetMgr.MouseOverTarget, "MouseOverTarget");
if (targetMgr.PreviousTarget != null)
this.PrintActor(targetMgr.PreviousTarget, "PreviousTarget");
if (ImGui.Button("Clear CT"))
targetMgr.ClearCurrentTarget();
if (ImGui.Button("Clear FT"))
targetMgr.ClearFocusTarget();
var localPlayer = this.dalamud.ClientState.LocalPlayer;
if (localPlayer != null)
{
if (ImGui.Button("Set CT"))
targetMgr.SetCurrentTarget(localPlayer);
if (ImGui.Button("Set FT"))
targetMgr.SetFocusTarget(localPlayer);
}
else
{
ImGui.Text("LocalPlayer is null.");
}
}
private void Load()
{
if (this.dalamud.Data.IsDataReady)
{
this.serverOpString = JsonConvert.SerializeObject(this.dalamud.Data.ServerOpCodes, Formatting.Indented);
this.wasReady = true;
}
}
private unsafe IntPtr FindAgentInterface(string addonName) private unsafe IntPtr FindAgentInterface(string addonName)
{ {
@ -443,16 +509,18 @@ namespace Dalamud.Interface
var agentModule = uiModule + 0xC3E78; var agentModule = uiModule + 0xC3E78;
for (var i = 0; i < 379; i++) for (var i = 0; i < 379; i++)
{ {
var agent = *(IntPtr*)(agentModule + 0x20 + i * 8); var agent = *(IntPtr*)(agentModule + 0x20 + (i * 8));
if (agent == IntPtr.Zero) if (agent == IntPtr.Zero)
continue; continue;
if (*(short*)(agent + 0x20) == id) if (*(short*)(agent + 0x20) == id)
return agent; return agent;
} }
return IntPtr.Zero; return IntPtr.Zero;
} }
private void PrintActor(Actor actor, string tag) { private void PrintActor(Actor actor, string tag)
{
var actorString = var actorString =
$"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{tag}] - {actor.ObjectKind} - {actor.Name} - X{actor.Position.X} Y{actor.Position.Y} Z{actor.Position.Z} D{actor.YalmDistanceX} R{actor.Rotation} - Target: {actor.TargetActorID:X}\n"; $"{actor.Address.ToInt64():X}:{actor.ActorId:X}[{tag}] - {actor.ObjectKind} - {actor.Name} - X{actor.Position.X} Y{actor.Position.Y} Z{actor.Position.Z} D{actor.YalmDistanceX} R{actor.Rotation} - Target: {actor.TargetActorID:X}\n";
@ -460,20 +528,23 @@ namespace Dalamud.Interface
actorString += $" DataId: {npc.DataId} NameId:{npc.NameId}\n"; actorString += $" DataId: {npc.DataId} NameId:{npc.NameId}\n";
if (actor is Chara chara) if (actor is Chara chara)
{
actorString += actorString +=
$" Level: {chara.Level} ClassJob: {(this.resolveGameData ? chara.ClassJob.GameData.Name : chara.ClassJob.Id.ToString())} CHP: {chara.CurrentHp} MHP: {chara.MaxHp} CMP: {chara.CurrentMp} MMP: {chara.MaxMp}\n Customize: {BitConverter.ToString(chara.Customize).Replace("-", " ")}\n"; $" Level: {chara.Level} ClassJob: {(this.resolveGameData ? chara.ClassJob.GameData.Name : chara.ClassJob.Id.ToString())} CHP: {chara.CurrentHp} MHP: {chara.MaxHp} CMP: {chara.CurrentMp} MMP: {chara.MaxMp}\n Customize: {BitConverter.ToString(chara.Customize).Replace("-", " ")}\n";
}
if (actor is PlayerCharacter pc) if (actor is PlayerCharacter pc)
{
actorString += actorString +=
$" HomeWorld: {(this.resolveGameData ? pc.HomeWorld.GameData.Name : pc.HomeWorld.Id.ToString())} CurrentWorld: {(this.resolveGameData ? pc.CurrentWorld.GameData.Name : pc.CurrentWorld.Id.ToString())} FC: {pc.CompanyTag}\n"; $" HomeWorld: {(this.resolveGameData ? pc.HomeWorld.GameData.Name : pc.HomeWorld.Id.ToString())} CurrentWorld: {(this.resolveGameData ? pc.CurrentWorld.GameData.Name : pc.CurrentWorld.Id.ToString())} FC: {pc.CompanyTag}\n";
}
ImGui.TextUnformatted(actorString); ImGui.TextUnformatted(actorString);
ImGui.SameLine(); ImGui.SameLine();
if (ImGui.Button($"C##{this.copyButtonIndex++}")) { if (ImGui.Button($"C##{this.copyButtonIndex++}"))
{
ImGui.SetClipboardText(actor.Address.ToInt64().ToString("X")); ImGui.SetClipboardText(actor.Address.ToInt64().ToString("X"));
} }
} }
} }
} }

View file

@ -155,11 +155,6 @@ namespace Dalamud.Interface
this.OpenChangelog(); this.OpenChangelog();
} }
if (this.dalamud.Fools != null)
{
ImGui.MenuItem("Draw Tippy", string.Empty, ref this.dalamud.Fools.IsEnabled);
}
ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow); ImGui.MenuItem("Draw ImGui demo", string.Empty, ref this.isImguiDrawDemoWindow);
ImGui.Separator(); ImGui.Separator();