From 5e37f8d2e80ce37f94c862144adcd02ab8f4db5a Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 2 Feb 2024 23:27:56 +0100 Subject: [PATCH] add some glamour debug stuff. --- Glamourer/Gui/Tabs/DebugTab/DatFilePanel.cs | 2 +- Glamourer/Gui/Tabs/DebugTab/DebugTabHeader.cs | 3 +- .../Gui/Tabs/DebugTab/GlamourPlatePanel.cs | 135 ++++++++++++++++++ 3 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 Glamourer/Gui/Tabs/DebugTab/GlamourPlatePanel.cs diff --git a/Glamourer/Gui/Tabs/DebugTab/DatFilePanel.cs b/Glamourer/Gui/Tabs/DebugTab/DatFilePanel.cs index 35bd136..11f27fd 100644 --- a/Glamourer/Gui/Tabs/DebugTab/DatFilePanel.cs +++ b/Glamourer/Gui/Tabs/DebugTab/DatFilePanel.cs @@ -37,4 +37,4 @@ public class DatFilePanel(ImportService _importService) : IGameDataDrawer ImGui.TextUnformatted(_datFile.Value.Description); } } -} +} \ No newline at end of file diff --git a/Glamourer/Gui/Tabs/DebugTab/DebugTabHeader.cs b/Glamourer/Gui/Tabs/DebugTab/DebugTabHeader.cs index b2b7bdb..2519b84 100644 --- a/Glamourer/Gui/Tabs/DebugTab/DebugTabHeader.cs +++ b/Glamourer/Gui/Tabs/DebugTab/DebugTabHeader.cs @@ -36,7 +36,8 @@ public class DebugTabHeader(string label, params IGameDataDrawer[] subTrees) provider.GetRequiredService(), provider.GetRequiredService(), provider.GetRequiredService(), - provider.GetRequiredService() + provider.GetRequiredService(), + provider.GetRequiredService() ); public static DebugTabHeader CreateGameData(IServiceProvider provider) diff --git a/Glamourer/Gui/Tabs/DebugTab/GlamourPlatePanel.cs b/Glamourer/Gui/Tabs/DebugTab/GlamourPlatePanel.cs new file mode 100644 index 0000000..2129c1f --- /dev/null +++ b/Glamourer/Gui/Tabs/DebugTab/GlamourPlatePanel.cs @@ -0,0 +1,135 @@ +using Dalamud.Interface.Utility.Raii; +using Dalamud.Plugin.Services; +using Dalamud.Utility.Signatures; +using FFXIVClientStructs.FFXIV.Client.Game; +using Glamourer.Designs; +using Glamourer.Interop; +using Glamourer.Services; +using Glamourer.State; +using ImGuiNET; +using OtterGui; +using Penumbra.GameData.Enums; +using Penumbra.GameData.Gui.Debug; + +namespace Glamourer.Gui.Tabs.DebugTab; + +public unsafe class GlamourPlatePanel : IGameDataDrawer +{ + private readonly DesignManager _design; + private readonly ItemManager _items; + private readonly StateManager _state; + private readonly ObjectManager _objects; + + public string Label + => "Glamour Plates"; + + public bool Disabled + => false; + + public GlamourPlatePanel(IGameInteropProvider interop, ItemManager items, DesignManager design, StateManager state, ObjectManager objects) + { + _items = items; + _design = design; + _state = state; + _objects = objects; + interop.InitializeFromAttributes(this); + } + + public void Draw() + { + var manager = MirageManager.Instance(); + using (ImRaii.Group()) + { + ImGui.TextUnformatted("Address:"); + ImGui.TextUnformatted("Number of Glamour Plates:"); + ImGui.TextUnformatted("Glamour Plates Requested:"); + ImGui.TextUnformatted("Glamour Plates Loaded:"); + ImGui.TextUnformatted("Is Applying Glamour Plates:"); + } + + ImGui.SameLine(); + using (ImRaii.Group()) + { + ImGuiUtil.CopyOnClickSelectable($"0x{(ulong)manager:X}"); + ImGui.TextUnformatted(manager == null ? "-" : manager->GlamourPlatesSpan.Length.ToString()); + ImGui.TextUnformatted(manager == null ? "-" : manager->GlamourPlatesRequested.ToString()); + ImGui.SameLine(); + if (ImGui.SmallButton("Request Update")) + RequestGlamour(); + ImGui.TextUnformatted(manager == null ? "-" : manager->GlamourPlatesLoaded.ToString()); + ImGui.TextUnformatted(manager == null ? "-" : manager->IsApplyingGlamourPlate.ToString()); + } + + if (manager == null) + return; + + ActorState? state = null; + var (identifier, data) = _objects.PlayerData; + var enabled = data.Valid && _state.GetOrCreate(identifier, data.Objects[0], out state); + + for (var i = 0; i < manager->GlamourPlatesSpan.Length; ++i) + { + using var tree = ImRaii.TreeNode($"Plate #{i + 1:D2}"); + if (!tree) + continue; + + ref var plate = ref manager->GlamourPlatesSpan[i]; + if (ImGuiUtil.DrawDisabledButton("Apply to Player", Vector2.Zero, string.Empty, !enabled)) + { + var design = CreateDesign(plate); + _state.ApplyDesign(state!, design, ApplySettings.Manual); + } + + using (ImRaii.Group()) + { + foreach (var slot in EquipSlotExtensions.FullSlots) + ImGui.TextUnformatted(slot.ToName()); + } + + ImGui.SameLine(); + using (ImRaii.Group()) + { + foreach (var (_, index) in EquipSlotExtensions.FullSlots.WithIndex()) + ImGui.TextUnformatted($"{plate.ItemIds[index]:D6}, {plate.StainIds[index]:D3}"); + } + } + } + + [Signature("E8 ?? ?? ?? ?? 32 C0 48 8B 5C 24 ?? 48 8B 6C 24 ?? 48 83 C4 ?? 5F")] + private readonly delegate* unmanaged _requestUpdate = null!; + + public void RequestGlamour() + { + var manager = MirageManager.Instance(); + if (manager == null) + return; + + _requestUpdate(manager); + } + + public DesignBase CreateDesign(in MirageManager.GlamourPlate plate) + { + var design = _design.CreateTemporary(); + design.ApplyCustomize = 0; + design.ApplyCrest = 0; + design.ApplyMeta = 0; + design.ApplyParameters = 0; + design.ApplyEquip = 0; + foreach (var (slot, index) in EquipSlotExtensions.FullSlots.WithIndex()) + { + var itemId = plate.ItemIds[index]; + if (itemId == 0) + continue; + + var item = _items.Resolve(slot, itemId); + if (!item.Valid) + continue; + + design.GetDesignDataRef().SetItem(slot, item); + design.GetDesignDataRef().SetStain(slot, plate.StainIds[index]); + design.ApplyEquip |= slot.ToBothFlags(); + } + + return design; + } +}