From 889fc101a88d39b330fd8ce4d8b4998ba2574741 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Tue, 10 Jan 2023 08:52:36 +0100 Subject: [PATCH] Add collection logging to resolve logging. --- Penumbra/Collections/ResolveData.cs | 28 +++++++++++++++++++ .../Interop/Loader/ResourceLoader.Debug.cs | 5 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Penumbra/Collections/ResolveData.cs b/Penumbra/Collections/ResolveData.cs index 722675fd..90c56144 100644 --- a/Penumbra/Collections/ResolveData.cs +++ b/Penumbra/Collections/ResolveData.cs @@ -1,4 +1,7 @@ using System; +using System.Linq; +using FFXIVClientStructs.FFXIV.Client.Game.Object; +using Penumbra.String; namespace Penumbra.Collections; @@ -34,6 +37,31 @@ public readonly struct ResolveData public override string ToString() => ModCollection.Name; + + public unsafe string AssociatedName() + { + if( AssociatedGameObject == IntPtr.Zero ) + { + return "no associated object."; + } + + try + { + var id = Penumbra.Actors.FromObject( ( GameObject* )AssociatedGameObject, out _, false, true ); + if( id.IsValid ) + { + var name = id.ToString(); + var parts = name.Split( ' ', 3 ); + return string.Join( " ", parts.Length != 3 ? parts.Select( n => $"{n[ 0 ]}." ) : parts[ ..2 ].Select( n => $"{n[ 0 ]}." ).Append( parts[ 2 ] ) ); + } + } + catch + { + // ignored + } + + return $"0x{AssociatedGameObject:X}"; + } } public static class ResolveDataExtensions diff --git a/Penumbra/Interop/Loader/ResourceLoader.Debug.cs b/Penumbra/Interop/Loader/ResourceLoader.Debug.cs index 64ae0026..6791f5be 100644 --- a/Penumbra/Interop/Loader/ResourceLoader.Debug.cs +++ b/Penumbra/Interop/Loader/ResourceLoader.Debug.cs @@ -253,10 +253,11 @@ public unsafe partial class ResourceLoader private static void LogPath( Utf8GamePath path, bool synchronous ) => Penumbra.Log.Information( $"[ResourceLoader] Requested {path} {( synchronous ? "synchronously." : "asynchronously." )}" ); - private static void LogResource( Structs.ResourceHandle* handle, Utf8GamePath path, FullPath? manipulatedPath, ResolveData _ ) + private static void LogResource( Structs.ResourceHandle* handle, Utf8GamePath path, FullPath? manipulatedPath, ResolveData data ) { var pathString = manipulatedPath != null ? $"custom file {manipulatedPath} instead of {path}" : path.ToString(); - Penumbra.Log.Information( $"[ResourceLoader] [{handle->FileType}] Loaded {pathString} to 0x{( ulong )handle:X}. (Refcount {handle->RefCount})" ); + Penumbra.Log.Information( + $"[ResourceLoader] [{handle->FileType}] Loaded {pathString} to 0x{( ulong )handle:X} using collection {data.ModCollection.AnonymizedName} for {data.AssociatedName()}. (Refcount {handle->RefCount}) " ); } private static void LogLoadedFile( Structs.ResourceHandle* resource, ByteString path, bool success, bool custom )