Change resolving to possibly work correctly for all materials and load specific materials for each collection.

This commit is contained in:
Ottermandias 2022-03-24 22:01:39 +01:00
parent b6ed27e235
commit 1e5776a481
16 changed files with 408 additions and 172 deletions

View file

@ -1,6 +1,8 @@
using System;
using Dalamud.Utility.Signatures;
using FFXIVClientStructs.FFXIV.Client.System.Resource;
using Penumbra.GameData.ByteString;
using Penumbra.GameData.Enums;
using Penumbra.Interop.Loader;
namespace Penumbra.Interop.Resolver;
@ -14,9 +16,6 @@ public partial class PathResolver : IDisposable
{
private readonly ResourceLoader _loader;
// Keep track of the last path resolver to be able to restore it.
private Func< Utf8GamePath, (FullPath?, object?) > _oldResolver = null!;
public PathResolver( ResourceLoader loader )
{
_loader = loader;
@ -28,22 +27,18 @@ public partial class PathResolver : IDisposable
}
// The modified resolver that handles game path resolving.
private (FullPath?, object?) CharacterResolver( Utf8GamePath gamePath )
private bool CharacterResolver( Utf8GamePath gamePath, ResourceCategory _1, ResourceType type, int _2, out (FullPath?, object?) data )
{
// Check if the path was marked for a specific collection,
// or if it is a file loaded by a material, and if we are currently in a material load.
// If not use the default collection.
var nonDefault = HandleMaterialSubFiles( gamePath, out var collection ) || PathCollections.TryGetValue( gamePath.Path, out collection );
// We can remove paths after they have actually been loaded.
// A potential next request will add the path anew.
var nonDefault = HandleMaterialSubFiles( type, out var collection ) || PathCollections.TryRemove( gamePath.Path, out collection );
if( !nonDefault )
{
collection = Penumbra.CollectionManager.DefaultCollection;
}
else
{
// We can remove paths after they have actually been loaded.
// A potential next request will add the path anew.
PathCollections.Remove( gamePath.Path );
}
// Resolve using character/default collection first, otherwise forced, as usual.
var resolved = collection!.ResolveSwappedOrReplacementPath( gamePath );
@ -53,12 +48,8 @@ public partial class PathResolver : IDisposable
if( resolved == null )
{
// We also need to handle defaulted materials against a non-default collection.
if( nonDefault && gamePath.Path.EndsWith( 'm', 't', 'r', 'l' ) )
{
SetCollection( gamePath.Path, collection );
}
return ( null, collection );
HandleMtrlCollection( collection, gamePath.Path.ToString(), nonDefault, type, resolved, out data );
return true;
}
collection = Penumbra.CollectionManager.ForcedCollection;
@ -66,12 +57,8 @@ public partial class PathResolver : IDisposable
// Since mtrl files load their files separately, we need to add the new, resolved path
// so that the functions loading tex and shpk can find that path and use its collection.
if( nonDefault && resolved.Value.Extension == ".mtrl" )
{
SetCollection( resolved.Value.InternalName, nonDefault ? collection : null );
}
return ( resolved, collection );
HandleMtrlCollection( collection, resolved.Value.FullName, nonDefault, type, resolved, out data );
return true;
}
public void Enable()
@ -84,8 +71,7 @@ public partial class PathResolver : IDisposable
EnableDataHooks();
EnableMetaHooks();
_oldResolver = _loader.ResolvePath;
_loader.ResolvePath = CharacterResolver;
_loader.ResolvePathCustomization += CharacterResolver;
}
public void Disable()
@ -96,7 +82,7 @@ public partial class PathResolver : IDisposable
DisableDataHooks();
DisableMetaHooks();
_loader.ResolvePath = _oldResolver;
_loader.ResolvePathCustomization -= CharacterResolver;
}
public void Dispose()