Only enable PathResolver if any character collections are set, fix mtrl staying in PathCollections.

This commit is contained in:
Ottermandias 2022-03-24 22:32:40 +01:00
parent 1e5776a481
commit 9f6729dd0b
3 changed files with 46 additions and 4 deletions

View file

@ -72,8 +72,12 @@ public unsafe partial class PathResolver
SeFileDescriptor* fileDescriptor, int priority, bool isSync, out byte ret )
{
ret = 0;
if( fileDescriptor->ResourceHandle->FileType == ResourceType.Mtrl
&& Penumbra.CollectionManager.ByName( split.ToString(), out var collection ) )
if( fileDescriptor->ResourceHandle->FileType != ResourceType.Mtrl )
{
return false;
}
if( Penumbra.CollectionManager.ByName( split.ToString(), out var collection ) )
{
SetCollection( path, collection );
}
@ -90,7 +94,6 @@ public unsafe partial class PathResolver
if( nonDefault && type == ResourceType.Mtrl )
{
var fullPath = new FullPath( $"|{collection.Name}|{path}" );
SetCollection( fullPath.InternalName, collection );
data = ( fullPath, collection );
}
else

View file

@ -4,6 +4,7 @@ using FFXIVClientStructs.FFXIV.Client.System.Resource;
using Penumbra.GameData.ByteString;
using Penumbra.GameData.Enums;
using Penumbra.Interop.Loader;
using Penumbra.Mods;
namespace Penumbra.Interop.Resolver;
@ -15,6 +16,7 @@ namespace Penumbra.Interop.Resolver;
public partial class PathResolver : IDisposable
{
private readonly ResourceLoader _loader;
public bool Enabled { get; private set; }
public PathResolver( ResourceLoader loader )
{
@ -23,7 +25,7 @@ public partial class PathResolver : IDisposable
SetupHumanHooks();
SetupWeaponHooks();
SetupMetaHooks();
Enable();
Penumbra.CollectionManager.CollectionChanged += OnCollectionChange;
}
// The modified resolver that handles game path resolving.
@ -63,6 +65,12 @@ public partial class PathResolver : IDisposable
public void Enable()
{
if( Enabled )
{
return;
}
Enabled = true;
InitializeDrawObjects();
EnableHumanHooks();
@ -76,12 +84,21 @@ public partial class PathResolver : IDisposable
public void Disable()
{
if( !Enabled )
{
return;
}
Enabled = false;
DisableHumanHooks();
DisableWeaponHooks();
DisableMtrlHooks();
DisableDataHooks();
DisableMetaHooks();
DrawObjectToObject.Clear();
PathCollections.Clear();
_loader.ResolvePathCustomization -= CharacterResolver;
}
@ -93,5 +110,23 @@ public partial class PathResolver : IDisposable
DisposeMtrlHooks();
DisposeDataHooks();
DisposeMetaHooks();
Penumbra.CollectionManager.CollectionChanged -= OnCollectionChange;
}
private void OnCollectionChange( ModCollection? _1, ModCollection? _2, CollectionType type, string? characterName )
{
if( type != CollectionType.Character )
{
return;
}
if( Penumbra.CollectionManager.CharacterCollection.Count > 0 )
{
Enable();
}
else
{
Disable();
}
}
}

View file

@ -109,6 +109,10 @@ public class Penumbra : IDalamudPlugin
{
ResourceLoader.EnableFullLogging();
}
if (CollectionManager.CharacterCollection.Count > 0)
PathResolver.Enable();
ResidentResources.Reload();
}