diff --git a/Penumbra/Interop/Loader/ResourceLoader.Debug.cs b/Penumbra/Interop/Loader/ResourceLoader.Debug.cs index 41ba6c48..ce95d523 100644 --- a/Penumbra/Interop/Loader/ResourceLoader.Debug.cs +++ b/Penumbra/Interop/Loader/ResourceLoader.Debug.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Dalamud.Hooking; using Dalamud.Logging; using Dalamud.Utility.Signatures; using FFXIVClientStructs.FFXIV.Client.System.Resource; @@ -13,6 +14,23 @@ namespace Penumbra.Interop.Loader; public unsafe partial class ResourceLoader { + public delegate IntPtr ResourceHandleDestructor( ResourceHandle* handle ); + + [Signature( "48 89 5C 24 ?? 57 48 83 EC ?? 48 8D 05 ?? ?? ?? ?? 48 8B D9 48 89 01 B8", + DetourName = nameof( ResourceHandleDestructorDetour ) )] + public static Hook< ResourceHandleDestructor >? ResourceHandleDestructorHook; + + private IntPtr ResourceHandleDestructorDetour( ResourceHandle* handle ) + { + if( handle != null ) + { + PluginLog.Information( "[ResourceLoader] Destructing Resource Handle {Path:l} at 0x{Address:X} (Refcount {Refcount}) .", handle->FileName, + ( ulong )handle, handle->RefCount ); + } + + return ResourceHandleDestructorHook!.Original( handle ); + } + // A static pointer to the SE Resource Manager [Signature( "48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 32 C0", ScanType = ScanType.StaticAddress, UseFlags = SignatureUseFlags.Pointer )] public static ResourceManager** ResourceManager; diff --git a/Penumbra/Interop/Loader/ResourceLoader.Replacement.cs b/Penumbra/Interop/Loader/ResourceLoader.Replacement.cs index ee70d33c..eac70a20 100644 --- a/Penumbra/Interop/Loader/ResourceLoader.Replacement.cs +++ b/Penumbra/Interop/Loader/ResourceLoader.Replacement.cs @@ -256,6 +256,7 @@ public unsafe partial class ResourceLoader ReadSqPackHook.Dispose(); GetResourceSyncHook.Dispose(); GetResourceAsyncHook.Dispose(); + ResourceHandleDestructorHook?.Dispose(); } private int ComputeHash( Utf8String path, GetResourceParameters* pGetResParams ) diff --git a/Penumbra/Interop/Loader/ResourceLoader.cs b/Penumbra/Interop/Loader/ResourceLoader.cs index ad721b5e..bc575d2e 100644 --- a/Penumbra/Interop/Loader/ResourceLoader.cs +++ b/Penumbra/Interop/Loader/ResourceLoader.cs @@ -30,6 +30,7 @@ public unsafe partial class ResourceLoader : IDisposable ResourceRequested += LogPath; ResourceLoaded += LogResource; FileLoaded += LogLoadedFile; + ResourceHandleDestructorHook?.Enable(); EnableHooks(); } @@ -44,6 +45,7 @@ public unsafe partial class ResourceLoader : IDisposable ResourceRequested -= LogPath; ResourceLoaded -= LogResource; FileLoaded -= LogLoadedFile; + ResourceHandleDestructorHook?.Disable(); } public void EnableReplacements() diff --git a/Penumbra/UI/ConfigWindow.SettingsTab.cs b/Penumbra/UI/ConfigWindow.SettingsTab.cs index c8bfd663..d40d3e33 100644 --- a/Penumbra/UI/ConfigWindow.SettingsTab.cs +++ b/Penumbra/UI/ConfigWindow.SettingsTab.cs @@ -77,7 +77,6 @@ public partial class ConfigWindow : newName.Any( c => ( symbol = c ) > ( char )0x7F ) ? ( $"Path contains invalid symbol {symbol}. Only ASCII is allowed.", false ) : ( $"Press Enter or Click Here to Save (Current Directory: {old})", true ); - return ( ImGui.Button( text, w ) || saved ) && valid; }