feat: add "state" debugger to dalamud data window

This commit is contained in:
goat 2020-03-24 02:55:53 +09:00
parent 8c7d2f8de0
commit 37b1a4fce9
4 changed files with 55 additions and 58 deletions

View file

@ -192,7 +192,7 @@ namespace Dalamud {
}
if (ImGui.MenuItem("Open Data window"))
{
this.dataWindow = new DalamudDataWindow(this.Data);
this.dataWindow = new DalamudDataWindow(this);
this.isImguiDrawDataWindow = true;
}
if (ImGui.MenuItem("Open Credits window")) {
@ -313,11 +313,6 @@ namespace Dalamud {
HelpMessage = "Unmute a word or sentence. Usage: /xlunmute <word or sentence>"
});
CommandManager.AddHandler("/xldstate", new CommandInfo(OnDebugPrintGameStateCommand) {
HelpMessage = "Print parsed game state",
ShowInHelp = false
});
CommandManager.AddHandler("/ll", new CommandInfo(OnLastLinkCommand) {
HelpMessage = "Open the last posted link in your default browser."
});
@ -360,8 +355,7 @@ namespace Dalamud {
});
this.CommandManager.AddHandler("/xlcredits", new CommandInfo(OnOpenCreditsCommand) {
HelpMessage = "Opens the credits for dalamud.",
ShowInHelp = false
HelpMessage = "Opens the credits for dalamud."
});
}
@ -455,29 +449,6 @@ namespace Dalamud {
Process.Start(ChatHandlers.LastLink);
}
private void OnDebugPrintGameStateCommand(string command, string arguments) {
Framework.Gui.Chat.Print(this.ClientState.Actors.Length + " entries");
Framework.Gui.Chat.Print(this.ClientState.LocalPlayer.Name);
Framework.Gui.Chat.Print(this.ClientState.LocalPlayer.CurrentWorld.Name);
Framework.Gui.Chat.Print(this.ClientState.LocalPlayer.HomeWorld.Name);
Framework.Gui.Chat.Print(this.ClientState.LocalContentId.ToString("X"));
Framework.Gui.Chat.Print(Framework.Gui.Chat.LastLinkedItemId.ToString());
for (var i = 0; i < this.ClientState.Actors.Length; i++) {
var actor = this.ClientState.Actors[i];
Log.Debug(actor.Name);
Framework.Gui.Chat.Print(
$"{i} - {actor.Name} - {actor.Position.X} {actor.Position.Y} {actor.Position.Z}");
if (actor is Npc npc)
Framework.Gui.Chat.Print($"DataId: {npc.DataId}");
if (actor is Chara chara)
Framework.Gui.Chat.Print(
$"Level: {chara.Level} ClassJob: {chara.ClassJob.Name} CHP: {chara.CurrentHp} MHP: {chara.MaxHp} CMP: {chara.CurrentMp} MMP: {chara.MaxMp}");
}
}
private void OnBotJoinCommand(string command, string arguments) {
if (this.BotManager != null && this.BotManager.IsConnected)
Process.Start(

View file

@ -25,7 +25,7 @@ namespace Dalamud.Game.Internal {
/// <summary>
/// A raw pointer to the instance of Client::Framework
/// </summary>
private FrameworkAddressResolver Address { get; }
public FrameworkAddressResolver Address { get; }
#region Subsystems

View file

@ -7,10 +7,10 @@ using ImGuiScene;
namespace Dalamud.Interface
{
class DalamudCreditsWindow : IDisposable {
private string creditsText = @"
private string creditsText = @$"
Dalamud
A FFXIV Hooking Framework
Version {typeof(Dalamud).Assembly.GetName().Version}
created by:
@ -40,11 +40,12 @@ Truci
Haplo
Everyone in the XIVLauncher Discord server
Join us at: https://discord.gg/3NMcUV5
Licensed under AGPL
Read the code: https://github.com/goaaats/Dalamud
Contribute at: https://github.com/goaaats/Dalamud
Thank you for using XIVLauncher!

View file

@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using Dalamud.Data;
using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
using ImGuiNET;
using Newtonsoft.Json;
namespace Dalamud.Interface
{
class DalamudDataWindow {
private DataManager dataMgr;
private Dalamud dalamud;
private bool wasReady;
private string serverOpString;
@ -19,28 +15,26 @@ namespace Dalamud.Interface
private int currentKind;
public DalamudDataWindow(DataManager dataMgr) {
this.dataMgr = dataMgr;
public DalamudDataWindow(Dalamud dalamud) {
this.dalamud = dalamud;
Load();
}
private void Load() {
if (this.dataMgr.IsDataReady)
if (this.dalamud.Data.IsDataReady)
{
this.serverOpString = JsonConvert.SerializeObject(this.dataMgr.ServerOpCodes, Formatting.Indented);
this.serverOpString = JsonConvert.SerializeObject(this.dalamud.Data.ServerOpCodes, Formatting.Indented);
this.wasReady = true;
}
}
public bool Draw()
{
public bool Draw() {
ImGui.SetNextWindowSize(new Vector2(500, 500), ImGuiCond.Always);
var isOpen = true;
if (!ImGui.Begin("Dalamud Data", ref isOpen, ImGuiWindowFlags.NoCollapse))
{
if (!ImGui.Begin("Dalamud Data", ref isOpen, ImGuiWindowFlags.NoCollapse)) {
ImGui.End();
return false;
}
@ -51,7 +45,8 @@ namespace Dalamud.Interface
ImGui.SameLine();
var copy = ImGui.Button("Copy all");
ImGui.SameLine();
ImGui.Combo("Data kind", ref currentKind, new[] {"ServerOpCode", "ContentFinderCondition"}, 2);
ImGui.Combo("Data kind", ref this.currentKind, new[] {"ServerOpCode", "ContentFinderCondition", "State"},
3);
ImGui.BeginChild("scrolling", new Vector2(0, 0), false, ImGuiWindowFlags.HorizontalScrollbar);
@ -60,17 +55,47 @@ namespace Dalamud.Interface
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, new Vector2(0, 0));
if (this.wasReady) {
switch (currentKind) {
case 0: ImGui.TextUnformatted(this.serverOpString);
if (this.wasReady)
switch (this.currentKind) {
case 0:
ImGui.TextUnformatted(this.serverOpString);
break;
case 1: ImGui.TextUnformatted(this.cfcString);
case 1:
ImGui.TextUnformatted(this.cfcString);
break;
case 2: {
var stateString = string.Empty;
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.dalamud.ClientState.LocalPlayer.CurrentWorld.Name}\n";
stateString += $"HomeWorldName: {this.dalamud.ClientState.LocalPlayer.HomeWorld.Name}\n";
stateString += $"LocalCID: {this.dalamud.ClientState.LocalContentId:X}\n";
stateString += $"LastLinkedItem: {this.dalamud.Framework.Gui.Chat.LastLinkedItemId.ToString()}\n";
for (var i = 0; i < this.dalamud.ClientState.Actors.Length; i++) {
var actor = this.dalamud.ClientState.Actors[i];
stateString +=
$" -> {i} - {actor.Name} - {actor.Position.X} {actor.Position.Y} {actor.Position.Z}\n";
if (actor is Npc npc)
stateString += $" DataId: {npc.DataId}\n";
if (actor is Chara chara)
stateString +=
$" Level: {chara.Level} ClassJob: {chara.ClassJob.Name} CHP: {chara.CurrentHp} MHP: {chara.MaxHp} CMP: {chara.CurrentMp} MMP: {chara.MaxMp}\n";
;
}
ImGui.TextUnformatted(stateString);
}
break;
}
} else {
else
ImGui.TextUnformatted("Data not ready.");
}
ImGui.PopStyleVar();
ImGui.EndChild();