mirror of
https://github.com/xivdev/Penumbra.git
synced 2026-02-23 08:17:59 +01:00
Add display for subfile resources and clean up better.
This commit is contained in:
parent
87b6fe6aa6
commit
e534ce37d5
8 changed files with 95 additions and 19 deletions
|
|
@ -249,8 +249,6 @@ public unsafe partial class ResourceLoader
|
|||
Penumbra.Log.Information( $"[ResourceLoader] [{handle->FileType}] Loaded {pathString} to 0x{( ulong )handle:X}. (Refcount {handle->RefCount})" );
|
||||
}
|
||||
|
||||
private static void LogLoadedFile( ByteString path, bool success, bool custom )
|
||||
=> Penumbra.Log.Information( success
|
||||
? $"[ResourceLoader] Loaded {path} from {( custom ? "local files" : "SqPack" )}"
|
||||
: $"[ResourceLoader] Failed to load {path} from {( custom ? "local files" : "SqPack" )}." );
|
||||
private static void LogLoadedFile( Structs.ResourceHandle* resource, ByteString path, bool success, bool custom )
|
||||
=> Penumbra.Log.Information( $"[ResourceLoader] Loading {path} from {( custom ? "local files" : "SqPack" )} into 0x{( ulong )resource:X} returned {success}." );
|
||||
}
|
||||
|
|
@ -214,7 +214,7 @@ public unsafe partial class ResourceLoader
|
|||
SeFileDescriptor* fileDescriptor, int priority, bool isSync )
|
||||
{
|
||||
var ret = Penumbra.ResourceLoader.ReadSqPackHook.Original( resourceManager, fileDescriptor, priority, isSync );
|
||||
FileLoaded?.Invoke( path, ret != 0, false );
|
||||
FileLoaded?.Invoke( fileDescriptor->ResourceHandle, path, ret != 0, false );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ public unsafe partial class ResourceLoader
|
|||
|
||||
// Use the SE ReadFile function.
|
||||
var ret = ReadFile( resourceManager, fileDescriptor, priority, isSync );
|
||||
FileLoaded?.Invoke( gamePath, ret != 0, true );
|
||||
FileLoaded?.Invoke( fileDescriptor->ResourceHandle, gamePath, ret != 0, true );
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ public unsafe partial class ResourceLoader : IDisposable
|
|||
// Event fired whenever a resource is newly loaded.
|
||||
// Success indicates the return value of the loading function (which does not imply that the resource was actually successfully loaded)
|
||||
// custom is true if the file was loaded from local files instead of the default SqPacks.
|
||||
public delegate void FileLoadedDelegate( ByteString path, bool success, bool custom );
|
||||
public delegate void FileLoadedDelegate( ResourceHandle* resource, ByteString path, bool success, bool custom );
|
||||
public event FileLoadedDelegate? FileLoaded;
|
||||
|
||||
// Customization point to control how path resolving is handled.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Utility.Signatures;
|
||||
using FFXIVClientStructs.FFXIV.Client.System.Resource;
|
||||
|
|
@ -17,7 +19,7 @@ public unsafe partial class PathResolver
|
|||
// Materials and avfx do contain their own paths to textures and shader packages or atex respectively.
|
||||
// Those are loaded synchronously.
|
||||
// Thus, we need to ensure the correct files are loaded when a material is loaded.
|
||||
public class SubfileHelper : IDisposable
|
||||
public class SubfileHelper : IDisposable, IReadOnlyCollection<KeyValuePair<IntPtr, ResolveData>>
|
||||
{
|
||||
private readonly ResourceLoader _loader;
|
||||
|
||||
|
|
@ -81,7 +83,8 @@ public unsafe partial class PathResolver
|
|||
_loadMtrlTexHook.Enable();
|
||||
_apricotResourceLoadHook.Enable();
|
||||
_loader.ResourceLoadCustomization += SubfileLoadHandler;
|
||||
_loader.ResourceLoaded += SubfileContainerLoaded;
|
||||
_loader.ResourceLoaded += SubfileContainerRequested;
|
||||
_loader.FileLoaded += SubfileContainerLoaded;
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
|
|
@ -90,7 +93,8 @@ public unsafe partial class PathResolver
|
|||
_loadMtrlTexHook.Disable();
|
||||
_apricotResourceLoadHook.Disable();
|
||||
_loader.ResourceLoadCustomization -= SubfileLoadHandler;
|
||||
_loader.ResourceLoaded -= SubfileContainerLoaded;
|
||||
_loader.ResourceLoaded -= SubfileContainerRequested;
|
||||
_loader.FileLoaded -= SubfileContainerLoaded;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
|
|
@ -101,13 +105,28 @@ public unsafe partial class PathResolver
|
|||
_apricotResourceLoadHook.Dispose();
|
||||
}
|
||||
|
||||
private void SubfileContainerLoaded( ResourceHandle* handle, Utf8GamePath originalPath, FullPath? manipulatedPath, ResolveData resolveData )
|
||||
private void SubfileContainerRequested( ResourceHandle* handle, Utf8GamePath originalPath, FullPath? manipulatedPath, ResolveData resolveData )
|
||||
{
|
||||
switch( handle->FileType )
|
||||
{
|
||||
case ResourceType.Mtrl:
|
||||
case ResourceType.Avfx:
|
||||
_subFileCollection[ ( IntPtr )handle ] = resolveData;
|
||||
if( handle->FileSize == 0 )
|
||||
{
|
||||
_subFileCollection[ ( IntPtr )handle ] = resolveData;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void SubfileContainerLoaded( ResourceHandle* handle, ByteString path, bool success, bool custom )
|
||||
{
|
||||
switch( handle->FileType )
|
||||
{
|
||||
case ResourceType.Mtrl:
|
||||
case ResourceType.Avfx:
|
||||
_subFileCollection.TryRemove( ( IntPtr )handle, out _ );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -131,7 +150,6 @@ public unsafe partial class PathResolver
|
|||
// Was called with True on my client and with false on other peoples clients,
|
||||
// which caused problems.
|
||||
ret = Penumbra.ResourceLoader.DefaultLoadResource( path, resourceManager, fileDescriptor, priority, true );
|
||||
_subFileCollection.TryRemove( ( IntPtr )fileDescriptor->ResourceHandle, out _ );
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -184,5 +202,20 @@ public unsafe partial class PathResolver
|
|||
_avfxData = ResolveData.Invalid;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public IEnumerator< KeyValuePair< IntPtr, ResolveData > > GetEnumerator()
|
||||
=> _subFileCollection.GetEnumerator();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
=> GetEnumerator();
|
||||
|
||||
public int Count
|
||||
=> _subFileCollection.Count;
|
||||
|
||||
internal ResolveData MtrlData
|
||||
=> _mtrlData;
|
||||
|
||||
internal ResolveData AvfxData
|
||||
=> _avfxData;
|
||||
}
|
||||
}
|
||||
|
|
@ -169,4 +169,13 @@ public partial class PathResolver : IDisposable
|
|||
|
||||
internal IEnumerable< KeyValuePair< int, global::Dalamud.Game.ClientState.Objects.Types.GameObject > > CutsceneActors
|
||||
=> Cutscenes.Actors;
|
||||
|
||||
internal IEnumerable< KeyValuePair< IntPtr, ResolveData > > ResourceCollections
|
||||
=> _subFiles;
|
||||
|
||||
internal ResolveData CurrentMtrlData
|
||||
=> _subFiles.MtrlData;
|
||||
|
||||
internal ResolveData CurrentAvfxData
|
||||
=> _subFiles.AvfxData;
|
||||
}
|
||||
|
|
@ -67,6 +67,15 @@ public unsafe struct ResourceHandle
|
|||
[FieldOffset( 0x10 )]
|
||||
public uint Id;
|
||||
|
||||
[FieldOffset( 0x28 )]
|
||||
public uint FileSize;
|
||||
|
||||
[FieldOffset( 0x2C )]
|
||||
public uint FileSize2;
|
||||
|
||||
[FieldOffset( 0x34 )]
|
||||
public uint FileSize3;
|
||||
|
||||
[FieldOffset( 0x48 )]
|
||||
public byte* FileNameData;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue