Add debug tab for meta changes (pretty useless...) and maybe fix reset problem.

This commit is contained in:
Ottermandias 2022-09-24 15:16:03 +02:00
parent b7b15532f8
commit b359c18360
4 changed files with 37 additions and 7 deletions

View file

@ -11,6 +11,9 @@ public unsafe partial class CharacterUtility
public readonly InternalIndex Index; public readonly InternalIndex Index;
public readonly Structs.CharacterUtility.Index GlobalIndex; public readonly Structs.CharacterUtility.Index GlobalIndex;
public IReadOnlyCollection< MetaReverter > Entries
=> _entries;
private IntPtr _defaultResourceData = IntPtr.Zero; private IntPtr _defaultResourceData = IntPtr.Zero;
private int _defaultResourceSize = 0; private int _defaultResourceSize = 0;
public bool Ready { get; private set; } = false; public bool Ready { get; private set; } = false;
@ -93,8 +96,8 @@ public unsafe partial class CharacterUtility
if( _entries.Count > 0 ) if( _entries.Count > 0 )
{ {
_entries.Clear(); _entries.Clear();
ResetResourceInternal();
} }
ResetResourceInternal();
} }
public sealed class MetaReverter : IDisposable public sealed class MetaReverter : IDisposable

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using Dalamud.Utility.Signatures; using Dalamud.Utility.Signatures;
@ -43,6 +44,9 @@ public unsafe partial class CharacterUtility : IDisposable
.Select( idx => new List( new InternalIndex( idx ) ) ) .Select( idx => new List( new InternalIndex( idx ) ) )
.ToArray(); .ToArray();
public IReadOnlyList< List > Lists
=> _lists;
public (IntPtr Address, int Size) DefaultResource( InternalIndex idx ) public (IntPtr Address, int Size) DefaultResource( InternalIndex idx )
=> _lists[ idx.Value ].DefaultResource; => _lists[ idx.Value ].DefaultResource;

View file

@ -160,7 +160,7 @@ public unsafe partial class PathResolver
var ret = _characterBaseCreateHook.Original( a, b, c, d ); var ret = _characterBaseCreateHook.Original( a, b, c, d );
using( meta ) using( meta )
{ {
if( LastGameObject != null ) if( LastGameObject != null && ret != IntPtr.Zero )
{ {
_drawObjectToObject[ ret ] = ( _lastCreatedCollection!, LastGameObject->ObjectIndex ); _drawObjectToObject[ ret ] = ( _lastCreatedCollection!, LastGameObject->ObjectIndex );
CreatedCharacterBase?.Invoke( ( IntPtr )LastGameObject, _lastCreatedCollection!.ModCollection, ret ); CreatedCharacterBase?.Invoke( ( IntPtr )LastGameObject, _lastCreatedCollection!.ModCollection, ret );

View file

@ -58,6 +58,8 @@ public partial class ConfigWindow
ImGui.NewLine(); ImGui.NewLine();
DrawDebugCharacterUtility(); DrawDebugCharacterUtility();
ImGui.NewLine(); ImGui.NewLine();
DrawDebugTabMetaLists();
ImGui.NewLine();
DrawDebugResidentResources(); DrawDebugResidentResources();
ImGui.NewLine(); ImGui.NewLine();
DrawResourceProblems(); DrawResourceProblems();
@ -237,7 +239,7 @@ public partial class ConfigWindow
{ {
var idx = CharacterUtility.RelevantIndices[ i ]; var idx = CharacterUtility.RelevantIndices[ i ];
var intern = new CharacterUtility.InternalIndex( 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.TableNextColumn();
ImGui.TextUnformatted( $"0x{( ulong )resource:X}" ); ImGui.TextUnformatted( $"0x{( ulong )resource:X}" );
ImGui.TableNextColumn(); ImGui.TableNextColumn();
@ -259,18 +261,39 @@ public partial class ConfigWindow
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.TextUnformatted( $"{resource->GetData().Length}" ); ImGui.TextUnformatted( $"{resource->GetData().Length}" );
ImGui.TableNextColumn(); ImGui.TableNextColumn();
ImGui.Selectable( $"0x{Penumbra.CharacterUtility.DefaultResource(intern).Address:X}" ); ImGui.Selectable( $"0x{Penumbra.CharacterUtility.DefaultResource( intern ).Address:X}" );
if( ImGui.IsItemClicked() ) if( ImGui.IsItemClicked() )
{ {
ImGui.SetClipboardText( string.Join( "\n", ImGui.SetClipboardText( string.Join( "\n",
new ReadOnlySpan< byte >( ( byte* )Penumbra.CharacterUtility.DefaultResource(intern).Address, new ReadOnlySpan< byte >( ( byte* )Penumbra.CharacterUtility.DefaultResource( intern ).Address,
Penumbra.CharacterUtility.DefaultResource(intern).Size ).ToArray().Select( b => b.ToString( "X2" ) ) ) ); Penumbra.CharacterUtility.DefaultResource( intern ).Size ).ToArray().Select( b => b.ToString( "X2" ) ) ) );
} }
ImGuiUtil.HoverTooltip( "Click to copy bytes to clipboard." ); ImGuiUtil.HoverTooltip( "Click to copy bytes to clipboard." );
ImGui.TableNextColumn(); 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}" ) ) );
} }
} }