From 15602f5be53ea379bf4554f42771d26bb2804513 Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Fri, 29 Apr 2022 15:59:41 +0200 Subject: [PATCH] Fix some enabling stuff. Always use PathResolver. Add counter to materials and imcs. --- .../Collections/ModCollection.Cache.Access.cs | 3 +++ Penumbra/Collections/ModCollection.Cache.cs | 7 ++++++- .../Interop/Resolver/PathResolver.Material.cs | 6 ++++-- Penumbra/Interop/Resolver/PathResolver.cs | 21 +------------------ Penumbra/Meta/Manager/MetaManager.Imc.cs | 7 +++++-- Penumbra/Penumbra.cs | 13 +++--------- 6 files changed, 22 insertions(+), 35 deletions(-) diff --git a/Penumbra/Collections/ModCollection.Cache.Access.cs b/Penumbra/Collections/ModCollection.Cache.Access.cs index dd2fe073..1720632a 100644 --- a/Penumbra/Collections/ModCollection.Cache.Access.cs +++ b/Penumbra/Collections/ModCollection.Cache.Access.cs @@ -16,6 +16,9 @@ public partial class ModCollection public bool HasCache => _cache != null; + public int RecomputeCounter + => _cache?.RecomputeCounter ?? 0; + // Only create, do not update. private void CreateCache( bool isDefault ) { diff --git a/Penumbra/Collections/ModCollection.Cache.cs b/Penumbra/Collections/ModCollection.Cache.cs index fe008820..20e3cc51 100644 --- a/Penumbra/Collections/ModCollection.Cache.cs +++ b/Penumbra/Collections/ModCollection.Cache.cs @@ -18,7 +18,7 @@ public partial class ModCollection // Shared caches to avoid allocations. private static readonly Dictionary< Utf8GamePath, FileRegister > RegisteredFiles = new(1024); private static readonly Dictionary< MetaManipulation, FileRegister > RegisteredManipulations = new(1024); - private static readonly List< ModSettings? > ResolvedSettings = new(128); + private static readonly List< ModSettings? > ResolvedSettings = new(128); private readonly ModCollection _collection; private readonly SortedList< string, object? > _changedItems = new(); @@ -27,6 +27,10 @@ public partial class ModCollection public readonly MetaManager MetaManipulations; public ConflictCache Conflicts = new(); + // Count the number of recalculations of the effective file list. + // This is used for material and imc changes. + public int RecomputeCounter { get; private set; } = 0; + // Obtain currently changed items. Computes them if they haven't been computed before. public IReadOnlyDictionary< string, object? > ChangedItems { @@ -120,6 +124,7 @@ public partial class ModCollection } AddMetaFiles(); + ++RecomputeCounter; } // Identify and record all manipulated objects for this entire collection. diff --git a/Penumbra/Interop/Resolver/PathResolver.Material.cs b/Penumbra/Interop/Resolver/PathResolver.Material.cs index e2d88fee..aa6fff01 100644 --- a/Penumbra/Interop/Resolver/PathResolver.Material.cs +++ b/Penumbra/Interop/Resolver/PathResolver.Material.cs @@ -78,7 +78,9 @@ public unsafe partial class PathResolver return false; } - if( Penumbra.CollectionManager.ByName( split.ToString(), out var collection ) ) + var lastUnderscore = split.LastIndexOf( ( byte )'_' ); + var name = lastUnderscore == -1 ? split.ToString() : split.Substring( 0, lastUnderscore ).ToString(); + if( Penumbra.CollectionManager.ByName( name, out var collection ) ) { PluginLog.Verbose( "Using MtrlLoadHandler with collection {$Split:l} for path {$Path:l}.", split, path ); SetCollection( path, collection ); @@ -100,7 +102,7 @@ public unsafe partial class PathResolver { if( nonDefault && type == ResourceType.Mtrl ) { - var fullPath = new FullPath( $"|{collection.Name}|{path}" ); + var fullPath = new FullPath( $"|{collection.RecomputeCounter}_{collection.Name}|{path}" ); data = ( fullPath, collection ); } else diff --git a/Penumbra/Interop/Resolver/PathResolver.cs b/Penumbra/Interop/Resolver/PathResolver.cs index e9412a3a..d25517da 100644 --- a/Penumbra/Interop/Resolver/PathResolver.cs +++ b/Penumbra/Interop/Resolver/PathResolver.cs @@ -26,7 +26,6 @@ public partial class PathResolver : IDisposable SetupHumanHooks(); SetupWeaponHooks(); SetupMetaHooks(); - Penumbra.CollectionManager.CollectionChanged += OnCollectionChange; } // The modified resolver that handles game path resolving. @@ -74,7 +73,7 @@ public partial class PathResolver : IDisposable PluginLog.Debug( "Character Path Resolver enabled." ); } - private void Disable() + public void Disable() { if( !Enabled ) { @@ -103,23 +102,5 @@ public partial class PathResolver : IDisposable DisposeMtrlHooks(); DisposeDataHooks(); DisposeMetaHooks(); - Penumbra.CollectionManager.CollectionChanged -= OnCollectionChange; - } - - private void OnCollectionChange( ModCollection.Type type, ModCollection? _1, ModCollection? _2, string? characterName ) - { - if( type != ModCollection.Type.Character ) - { - return; - } - - if( Penumbra.CollectionManager.HasCharacterCollections ) - { - Enable(); - } - else - { - Disable(); - } } } \ No newline at end of file diff --git a/Penumbra/Meta/Manager/MetaManager.Imc.cs b/Penumbra/Meta/Manager/MetaManager.Imc.cs index 161307fa..7c829216 100644 --- a/Penumbra/Meta/Manager/MetaManager.Imc.cs +++ b/Penumbra/Meta/Manager/MetaManager.Imc.cs @@ -125,7 +125,7 @@ public partial class MetaManager } private FullPath CreateImcPath( Utf8GamePath path ) - => new($"|{_collection.Name}|{path}"); + => new($"|{_collection.RecomputeCounter}_{_collection.Name}|{path}"); private static unsafe bool ImcLoadHandler( Utf8String split, Utf8String path, ResourceManager* resourceManager, SeFileDescriptor* fileDescriptor, int priority, bool isSync, out byte ret ) @@ -138,7 +138,10 @@ public partial class MetaManager PluginLog.Verbose( "Using ImcLoadHandler for path {$Path:l}.", path ); ret = Penumbra.ResourceLoader.ReadSqPackHook.Original( resourceManager, fileDescriptor, priority, isSync ); - if( Penumbra.CollectionManager.ByName( split.ToString(), out var collection ) + + var lastUnderscore = split.LastIndexOf( ( byte )'_' ); + var name = lastUnderscore == -1 ? split.ToString() : split.Substring( 0, lastUnderscore ).ToString(); + if( Penumbra.CollectionManager.ByName( name, out var collection ) && collection.HasCache && collection.MetaCache!.Imc.Files.TryGetValue( Utf8GamePath.FromSpan( path.Span, out var p ) ? p : Utf8GamePath.Empty, out var file ) ) diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 546f29dd..a60493dd 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -90,11 +90,6 @@ public class Penumbra : IDalamudPlugin HelpMessage = "/penumbra - toggle ui\n/penumbra reload - reload mod file lists & discover any new mods", } ); - if( Config.DebugMode ) - { - ResourceLoader.EnableDebug(); - } - ResidentResources.Reload(); Api = new PenumbraApi( this ); @@ -111,6 +106,7 @@ public class Penumbra : IDalamudPlugin if( Config.EnableMods ) { ResourceLoader.EnableReplacements(); + PathResolver.Enable(); } if( Config.DebugMode ) @@ -124,11 +120,6 @@ public class Penumbra : IDalamudPlugin ResourceLoader.EnableFullLogging(); } - if( CollectionManager.HasCharacterCollections ) - { - PathResolver.Enable(); - } - ResidentResources.Reload(); } @@ -162,6 +153,7 @@ public class Penumbra : IDalamudPlugin ResourceLoader.EnableReplacements(); CollectionManager.Default.SetFiles(); ResidentResources.Reload(); + PathResolver.Enable(); Config.Save(); ObjectReloader.RedrawAll( RedrawType.Redraw ); @@ -179,6 +171,7 @@ public class Penumbra : IDalamudPlugin ResourceLoader.DisableReplacements(); CharacterUtility.ResetAll(); ResidentResources.Reload(); + PathResolver.Disable(); Config.Save(); ObjectReloader.RedrawAll( RedrawType.Redraw );