Fix some enabling stuff. Always use PathResolver. Add counter to materials and imcs.

This commit is contained in:
Ottermandias 2022-04-29 15:59:41 +02:00
parent e8ee729ec5
commit 15602f5be5
6 changed files with 22 additions and 35 deletions

View file

@ -16,6 +16,9 @@ public partial class ModCollection
public bool HasCache public bool HasCache
=> _cache != null; => _cache != null;
public int RecomputeCounter
=> _cache?.RecomputeCounter ?? 0;
// Only create, do not update. // Only create, do not update.
private void CreateCache( bool isDefault ) private void CreateCache( bool isDefault )
{ {

View file

@ -27,6 +27,10 @@ public partial class ModCollection
public readonly MetaManager MetaManipulations; public readonly MetaManager MetaManipulations;
public ConflictCache Conflicts = new(); 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. // Obtain currently changed items. Computes them if they haven't been computed before.
public IReadOnlyDictionary< string, object? > ChangedItems public IReadOnlyDictionary< string, object? > ChangedItems
{ {
@ -120,6 +124,7 @@ public partial class ModCollection
} }
AddMetaFiles(); AddMetaFiles();
++RecomputeCounter;
} }
// Identify and record all manipulated objects for this entire collection. // Identify and record all manipulated objects for this entire collection.

View file

@ -78,7 +78,9 @@ public unsafe partial class PathResolver
return false; 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 ); PluginLog.Verbose( "Using MtrlLoadHandler with collection {$Split:l} for path {$Path:l}.", split, path );
SetCollection( path, collection ); SetCollection( path, collection );
@ -100,7 +102,7 @@ public unsafe partial class PathResolver
{ {
if( nonDefault && type == ResourceType.Mtrl ) if( nonDefault && type == ResourceType.Mtrl )
{ {
var fullPath = new FullPath( $"|{collection.Name}|{path}" ); var fullPath = new FullPath( $"|{collection.RecomputeCounter}_{collection.Name}|{path}" );
data = ( fullPath, collection ); data = ( fullPath, collection );
} }
else else

View file

@ -26,7 +26,6 @@ public partial class PathResolver : IDisposable
SetupHumanHooks(); SetupHumanHooks();
SetupWeaponHooks(); SetupWeaponHooks();
SetupMetaHooks(); SetupMetaHooks();
Penumbra.CollectionManager.CollectionChanged += OnCollectionChange;
} }
// The modified resolver that handles game path resolving. // The modified resolver that handles game path resolving.
@ -74,7 +73,7 @@ public partial class PathResolver : IDisposable
PluginLog.Debug( "Character Path Resolver enabled." ); PluginLog.Debug( "Character Path Resolver enabled." );
} }
private void Disable() public void Disable()
{ {
if( !Enabled ) if( !Enabled )
{ {
@ -103,23 +102,5 @@ public partial class PathResolver : IDisposable
DisposeMtrlHooks(); DisposeMtrlHooks();
DisposeDataHooks(); DisposeDataHooks();
DisposeMetaHooks(); 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();
}
} }
} }

View file

@ -125,7 +125,7 @@ public partial class MetaManager
} }
private FullPath CreateImcPath( Utf8GamePath path ) 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, private static unsafe bool ImcLoadHandler( Utf8String split, Utf8String path, ResourceManager* resourceManager,
SeFileDescriptor* fileDescriptor, int priority, bool isSync, out byte ret ) 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 ); PluginLog.Verbose( "Using ImcLoadHandler for path {$Path:l}.", path );
ret = Penumbra.ResourceLoader.ReadSqPackHook.Original( resourceManager, fileDescriptor, priority, isSync ); 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.HasCache
&& collection.MetaCache!.Imc.Files.TryGetValue( && collection.MetaCache!.Imc.Files.TryGetValue(
Utf8GamePath.FromSpan( path.Span, out var p ) ? p : Utf8GamePath.Empty, out var file ) ) Utf8GamePath.FromSpan( path.Span, out var p ) ? p : Utf8GamePath.Empty, out var file ) )

View file

@ -90,11 +90,6 @@ public class Penumbra : IDalamudPlugin
HelpMessage = "/penumbra - toggle ui\n/penumbra reload - reload mod file lists & discover any new mods", HelpMessage = "/penumbra - toggle ui\n/penumbra reload - reload mod file lists & discover any new mods",
} ); } );
if( Config.DebugMode )
{
ResourceLoader.EnableDebug();
}
ResidentResources.Reload(); ResidentResources.Reload();
Api = new PenumbraApi( this ); Api = new PenumbraApi( this );
@ -111,6 +106,7 @@ public class Penumbra : IDalamudPlugin
if( Config.EnableMods ) if( Config.EnableMods )
{ {
ResourceLoader.EnableReplacements(); ResourceLoader.EnableReplacements();
PathResolver.Enable();
} }
if( Config.DebugMode ) if( Config.DebugMode )
@ -124,11 +120,6 @@ public class Penumbra : IDalamudPlugin
ResourceLoader.EnableFullLogging(); ResourceLoader.EnableFullLogging();
} }
if( CollectionManager.HasCharacterCollections )
{
PathResolver.Enable();
}
ResidentResources.Reload(); ResidentResources.Reload();
} }
@ -162,6 +153,7 @@ public class Penumbra : IDalamudPlugin
ResourceLoader.EnableReplacements(); ResourceLoader.EnableReplacements();
CollectionManager.Default.SetFiles(); CollectionManager.Default.SetFiles();
ResidentResources.Reload(); ResidentResources.Reload();
PathResolver.Enable();
Config.Save(); Config.Save();
ObjectReloader.RedrawAll( RedrawType.Redraw ); ObjectReloader.RedrawAll( RedrawType.Redraw );
@ -179,6 +171,7 @@ public class Penumbra : IDalamudPlugin
ResourceLoader.DisableReplacements(); ResourceLoader.DisableReplacements();
CharacterUtility.ResetAll(); CharacterUtility.ResetAll();
ResidentResources.Reload(); ResidentResources.Reload();
PathResolver.Disable();
Config.Save(); Config.Save();
ObjectReloader.RedrawAll( RedrawType.Redraw ); ObjectReloader.RedrawAll( RedrawType.Redraw );