Add collection logging to resolve logging.

This commit is contained in:
Ottermandias 2023-01-10 08:52:36 +01:00
parent 58f86743eb
commit 889fc101a8
2 changed files with 31 additions and 2 deletions

View file

@ -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

View file

@ -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 )