From b359c183603733f8fc44de1c146370aa1831341c Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 24 Sep 2022 15:16:03 +0200 Subject: [PATCH] Add debug tab for meta changes (pretty useless...) and maybe fix reset problem. --- Penumbra/Interop/CharacterUtility.List.cs | 5 ++- Penumbra/Interop/CharacterUtility.cs | 4 +++ .../Resolver/PathResolver.DrawObjectState.cs | 2 +- Penumbra/UI/ConfigWindow.DebugTab.cs | 33 ++++++++++++++++--- 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/Penumbra/Interop/CharacterUtility.List.cs b/Penumbra/Interop/CharacterUtility.List.cs index e6f412ae..1e33592b 100644 --- a/Penumbra/Interop/CharacterUtility.List.cs +++ b/Penumbra/Interop/CharacterUtility.List.cs @@ -11,6 +11,9 @@ public unsafe partial class CharacterUtility public readonly InternalIndex Index; public readonly Structs.CharacterUtility.Index GlobalIndex; + public IReadOnlyCollection< MetaReverter > Entries + => _entries; + private IntPtr _defaultResourceData = IntPtr.Zero; private int _defaultResourceSize = 0; public bool Ready { get; private set; } = false; @@ -93,8 +96,8 @@ public unsafe partial class CharacterUtility if( _entries.Count > 0 ) { _entries.Clear(); - ResetResourceInternal(); } + ResetResourceInternal(); } public sealed class MetaReverter : IDisposable diff --git a/Penumbra/Interop/CharacterUtility.cs b/Penumbra/Interop/CharacterUtility.cs index 44b9204e..63d08bc0 100644 --- a/Penumbra/Interop/CharacterUtility.cs +++ b/Penumbra/Interop/CharacterUtility.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Dalamud.Utility.Signatures; @@ -43,6 +44,9 @@ public unsafe partial class CharacterUtility : IDisposable .Select( idx => new List( new InternalIndex( idx ) ) ) .ToArray(); + public IReadOnlyList< List > Lists + => _lists; + public (IntPtr Address, int Size) DefaultResource( InternalIndex idx ) => _lists[ idx.Value ].DefaultResource; diff --git a/Penumbra/Interop/Resolver/PathResolver.DrawObjectState.cs b/Penumbra/Interop/Resolver/PathResolver.DrawObjectState.cs index d30248f9..40228fad 100644 --- a/Penumbra/Interop/Resolver/PathResolver.DrawObjectState.cs +++ b/Penumbra/Interop/Resolver/PathResolver.DrawObjectState.cs @@ -160,7 +160,7 @@ public unsafe partial class PathResolver var ret = _characterBaseCreateHook.Original( a, b, c, d ); using( meta ) { - if( LastGameObject != null ) + if( LastGameObject != null && ret != IntPtr.Zero ) { _drawObjectToObject[ ret ] = ( _lastCreatedCollection!, LastGameObject->ObjectIndex ); CreatedCharacterBase?.Invoke( ( IntPtr )LastGameObject, _lastCreatedCollection!.ModCollection, ret ); diff --git a/Penumbra/UI/ConfigWindow.DebugTab.cs b/Penumbra/UI/ConfigWindow.DebugTab.cs index fd36f308..8ced65cb 100644 --- a/Penumbra/UI/ConfigWindow.DebugTab.cs +++ b/Penumbra/UI/ConfigWindow.DebugTab.cs @@ -58,6 +58,8 @@ public partial class ConfigWindow ImGui.NewLine(); DrawDebugCharacterUtility(); ImGui.NewLine(); + DrawDebugTabMetaLists(); + ImGui.NewLine(); DrawDebugResidentResources(); ImGui.NewLine(); DrawResourceProblems(); @@ -237,7 +239,7 @@ public partial class ConfigWindow { var idx = CharacterUtility.RelevantIndices[ i ]; var intern = new CharacterUtility.InternalIndex( i ); - var resource = ( ResourceHandle* )Penumbra.CharacterUtility.Address->Resource(idx); + var resource = ( ResourceHandle* )Penumbra.CharacterUtility.Address->Resource( idx ); ImGui.TableNextColumn(); ImGui.TextUnformatted( $"0x{( ulong )resource:X}" ); ImGui.TableNextColumn(); @@ -259,18 +261,39 @@ public partial class ConfigWindow ImGui.TableNextColumn(); ImGui.TextUnformatted( $"{resource->GetData().Length}" ); ImGui.TableNextColumn(); - ImGui.Selectable( $"0x{Penumbra.CharacterUtility.DefaultResource(intern).Address:X}" ); + ImGui.Selectable( $"0x{Penumbra.CharacterUtility.DefaultResource( intern ).Address:X}" ); if( ImGui.IsItemClicked() ) { ImGui.SetClipboardText( string.Join( "\n", - new ReadOnlySpan< byte >( ( byte* )Penumbra.CharacterUtility.DefaultResource(intern).Address, - Penumbra.CharacterUtility.DefaultResource(intern).Size ).ToArray().Select( b => b.ToString( "X2" ) ) ) ); + new ReadOnlySpan< byte >( ( byte* )Penumbra.CharacterUtility.DefaultResource( intern ).Address, + Penumbra.CharacterUtility.DefaultResource( intern ).Size ).ToArray().Select( b => b.ToString( "X2" ) ) ) ); } ImGuiUtil.HoverTooltip( "Click to copy bytes to clipboard." ); ImGui.TableNextColumn(); - ImGui.TextUnformatted( $"{Penumbra.CharacterUtility.DefaultResource(intern).Size}" ); + ImGui.TextUnformatted( $"{Penumbra.CharacterUtility.DefaultResource( intern ).Size}" ); + } + } + + private static void DrawDebugTabMetaLists() + { + if( !ImGui.CollapsingHeader( "Metadata Changes" ) ) + { + return; + } + + using var table = ImRaii.Table( "##DebugMetaTable", 3, ImGuiTableFlags.SizingFixedFit ); + if( !table ) + { + return; + } + + foreach( var list in Penumbra.CharacterUtility.Lists ) + { + ImGuiUtil.DrawTableColumn( list.GlobalIndex.ToString() ); + ImGuiUtil.DrawTableColumn( list.Entries.Count.ToString() ); + ImGuiUtil.DrawTableColumn( string.Join( ", ", list.Entries.Select( e => $"0x{e.Data:X}" ) ) ); } }