From 9f6729dd0b65c0c5d74be054d63f31d36dc07544 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Thu, 24 Mar 2022 22:32:40 +0100 Subject: [PATCH] Only enable PathResolver if any character collections are set, fix mtrl staying in PathCollections. --- .../Interop/Resolver/PathResolver.Material.cs | 9 +++-- Penumbra/Interop/Resolver/PathResolver.cs | 37 ++++++++++++++++++- Penumbra/Penumbra.cs | 4 ++ 3 files changed, 46 insertions(+), 4 deletions(-) diff --git a/Penumbra/Interop/Resolver/PathResolver.Material.cs b/Penumbra/Interop/Resolver/PathResolver.Material.cs index ed2ce84c..8569f547 100644 --- a/Penumbra/Interop/Resolver/PathResolver.Material.cs +++ b/Penumbra/Interop/Resolver/PathResolver.Material.cs @@ -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 diff --git a/Penumbra/Interop/Resolver/PathResolver.cs b/Penumbra/Interop/Resolver/PathResolver.cs index c9543189..9dc67a17 100644 --- a/Penumbra/Interop/Resolver/PathResolver.cs +++ b/Penumbra/Interop/Resolver/PathResolver.cs @@ -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(); + } } } \ No newline at end of file diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 8517d5c5..e2116f65 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -109,6 +109,10 @@ public class Penumbra : IDalamudPlugin { ResourceLoader.EnableFullLogging(); } + + if (CollectionManager.CharacterCollection.Count > 0) + PathResolver.Enable(); + ResidentResources.Reload(); }