From c49454fc25a8a2a78c7bfcc3a37380a68f0b6b6b Mon Sep 17 00:00:00 2001 From: Ottermandias Date: Sat, 22 Apr 2023 00:11:47 +0200 Subject: [PATCH] Move MetaList out of CharacterUtility and remove static CollectionManager. --- Penumbra/Collections/Cache/CmpCache.cs | 2 +- Penumbra/Collections/Cache/EqdpCache.cs | 2 +- Penumbra/Collections/Cache/EqpCache.cs | 2 +- Penumbra/Collections/Cache/EstCache.cs | 2 +- Penumbra/Collections/Cache/GmpCache.cs | 2 +- Penumbra/Collections/Cache/MetaCache.cs | 10 +- .../Collections/ModCollection.Cache.Access.cs | 22 +-- Penumbra/Configuration.cs | 9 +- .../Interop/Services/CharacterUtility.List.cs | 166 ------------------ Penumbra/Interop/Services/CharacterUtility.cs | 14 +- Penumbra/Interop/Services/MetaList.cs | 157 +++++++++++++++++ Penumbra/Meta/MetaFileManager.cs | 2 +- Penumbra/Penumbra.cs | 56 +++--- Penumbra/Services/ConfigMigrationService.cs | 12 +- Penumbra/UI/AdvancedWindow/ModEditWindow.cs | 26 +-- 15 files changed, 237 insertions(+), 247 deletions(-) delete mode 100644 Penumbra/Interop/Services/CharacterUtility.List.cs create mode 100644 Penumbra/Interop/Services/MetaList.cs diff --git a/Penumbra/Collections/Cache/CmpCache.cs b/Penumbra/Collections/Cache/CmpCache.cs index 47d6a441..9333501a 100644 --- a/Penumbra/Collections/Cache/CmpCache.cs +++ b/Penumbra/Collections/Cache/CmpCache.cs @@ -21,7 +21,7 @@ public struct CmpCache : IDisposable public void SetFiles(MetaFileManager manager) => manager.SetFile(_cmpFile, MetaIndex.HumanCmp); - public CharacterUtility.MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager) + public MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager) => manager.TemporarilySetFile(_cmpFile, MetaIndex.HumanCmp); public void Reset() diff --git a/Penumbra/Collections/Cache/EqdpCache.cs b/Penumbra/Collections/Cache/EqdpCache.cs index 4a1325ed..db40fcb6 100644 --- a/Penumbra/Collections/Cache/EqdpCache.cs +++ b/Penumbra/Collections/Cache/EqdpCache.cs @@ -34,7 +34,7 @@ public readonly struct EqdpCache : IDisposable manager.SetFile(_eqdpFiles[i], index); } - public CharacterUtility.MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager, GenderRace genderRace, bool accessory) + public MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager, GenderRace genderRace, bool accessory) { var idx = CharacterUtilityData.EqdpIdx(genderRace, accessory); Debug.Assert(idx >= 0, $"Invalid Gender, Race or Accessory for EQDP file {genderRace}, {accessory}."); diff --git a/Penumbra/Collections/Cache/EqpCache.cs b/Penumbra/Collections/Cache/EqpCache.cs index f3b7e8f1..5fe40426 100644 --- a/Penumbra/Collections/Cache/EqpCache.cs +++ b/Penumbra/Collections/Cache/EqpCache.cs @@ -24,7 +24,7 @@ public struct EqpCache : IDisposable public static void ResetFiles(MetaFileManager manager) => manager.SetFile( null, MetaIndex.Eqp ); - public CharacterUtility.MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager) + public MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager) => manager.TemporarilySetFile( _eqpFile, MetaIndex.Eqp ); public void Reset() diff --git a/Penumbra/Collections/Cache/EstCache.cs b/Penumbra/Collections/Cache/EstCache.cs index ac30e0d6..d079a532 100644 --- a/Penumbra/Collections/Cache/EstCache.cs +++ b/Penumbra/Collections/Cache/EstCache.cs @@ -49,7 +49,7 @@ public struct EstCache : IDisposable } } - public CharacterUtility.MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager, EstManipulation.EstType type) + public MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager, EstManipulation.EstType type) { var (file, idx) = type switch { diff --git a/Penumbra/Collections/Cache/GmpCache.cs b/Penumbra/Collections/Cache/GmpCache.cs index 2698af7b..4e485036 100644 --- a/Penumbra/Collections/Cache/GmpCache.cs +++ b/Penumbra/Collections/Cache/GmpCache.cs @@ -21,7 +21,7 @@ public struct GmpCache : IDisposable public void SetFiles(MetaFileManager manager) => manager.SetFile( _gmpFile, MetaIndex.Gmp ); - public CharacterUtility.MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager) + public MetaList.MetaReverter TemporarilySetFiles(MetaFileManager manager) => manager.TemporarilySetFile( _gmpFile, MetaIndex.Gmp ); public void Reset() diff --git a/Penumbra/Collections/Cache/MetaCache.cs b/Penumbra/Collections/Cache/MetaCache.cs index 514e2589..559fb3cd 100644 --- a/Penumbra/Collections/Cache/MetaCache.cs +++ b/Penumbra/Collections/Cache/MetaCache.cs @@ -159,19 +159,19 @@ public class MetaCache : IDisposable, IEnumerable _imcCache.SetFiles(_collection); - public CharacterUtility.MetaList.MetaReverter TemporarilySetEqpFile() + public MetaList.MetaReverter TemporarilySetEqpFile() => _eqpCache.TemporarilySetFiles(_manager); - public CharacterUtility.MetaList.MetaReverter TemporarilySetEqdpFile(GenderRace genderRace, bool accessory) + public MetaList.MetaReverter TemporarilySetEqdpFile(GenderRace genderRace, bool accessory) => _eqdpCache.TemporarilySetFiles(_manager, genderRace, accessory); - public CharacterUtility.MetaList.MetaReverter TemporarilySetGmpFile() + public MetaList.MetaReverter TemporarilySetGmpFile() => _gmpCache.TemporarilySetFiles(_manager); - public CharacterUtility.MetaList.MetaReverter TemporarilySetCmpFile() + public MetaList.MetaReverter TemporarilySetCmpFile() => _cmpCache.TemporarilySetFiles(_manager); - public CharacterUtility.MetaList.MetaReverter TemporarilySetEstFile(EstManipulation.EstType type) + public MetaList.MetaReverter TemporarilySetEstFile(EstManipulation.EstType type) => _estCache.TemporarilySetFiles(_manager, type); diff --git a/Penumbra/Collections/ModCollection.Cache.Access.cs b/Penumbra/Collections/ModCollection.Cache.Access.cs index 2ccdf3c3..7597f7ca 100644 --- a/Penumbra/Collections/ModCollection.Cache.Access.cs +++ b/Penumbra/Collections/ModCollection.Cache.Access.cs @@ -5,14 +5,13 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using System.Runtime.CompilerServices; using Penumbra.Interop.Structs; using Penumbra.Meta.Files; using Penumbra.Meta.Manipulations; using Penumbra.String.Classes; -using CharacterUtility = Penumbra.Interop.Services.CharacterUtility; -using Penumbra.Collections.Cache; - +using Penumbra.Collections.Cache; +using Penumbra.Interop.Services; + namespace Penumbra.Collections; public partial class ModCollection @@ -94,28 +93,23 @@ public partial class ModCollection } // Used for short periods of changed files. - public CharacterUtility.MetaList.MetaReverter TemporarilySetEqdpFile(GenderRace genderRace, bool accessory) + public MetaList.MetaReverter TemporarilySetEqdpFile(GenderRace genderRace, bool accessory) => _cache?.Meta.TemporarilySetEqdpFile(genderRace, accessory) ?? Penumbra.CharacterUtility.TemporarilyResetResource(Interop.Structs.CharacterUtilityData.EqdpIdx(genderRace, accessory)); - public CharacterUtility.MetaList.MetaReverter TemporarilySetEqpFile() + public MetaList.MetaReverter TemporarilySetEqpFile() => _cache?.Meta.TemporarilySetEqpFile() ?? Penumbra.CharacterUtility.TemporarilyResetResource(MetaIndex.Eqp); - public CharacterUtility.MetaList.MetaReverter TemporarilySetGmpFile() + public MetaList.MetaReverter TemporarilySetGmpFile() => _cache?.Meta.TemporarilySetGmpFile() ?? Penumbra.CharacterUtility.TemporarilyResetResource(MetaIndex.Gmp); - public CharacterUtility.MetaList.MetaReverter TemporarilySetCmpFile() + public MetaList.MetaReverter TemporarilySetCmpFile() => _cache?.Meta.TemporarilySetCmpFile() ?? Penumbra.CharacterUtility.TemporarilyResetResource(MetaIndex.HumanCmp); - public CharacterUtility.MetaList.MetaReverter TemporarilySetEstFile(EstManipulation.EstType type) + public MetaList.MetaReverter TemporarilySetEstFile(EstManipulation.EstType type) => _cache?.Meta.TemporarilySetEstFile(type) ?? Penumbra.CharacterUtility.TemporarilyResetResource((MetaIndex)type); -} - - -public static class CollectionCacheExtensions -{ } \ No newline at end of file diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index 568b2fc5..3799d9db 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -10,6 +10,7 @@ using OtterGui.Filesystem; using OtterGui.Widgets; using Penumbra.GameData.Enums; using Penumbra.Import.Structs; +using Penumbra.Interop.Services; using Penumbra.Mods; using Penumbra.Services; using Penumbra.UI; @@ -101,14 +102,14 @@ public class Configuration : IPluginConfiguration, ISavable /// Load the current configuration. /// Includes adding new colors and migrating from old versions. /// - public Configuration(FilenameService fileNames, ConfigMigrationService migrator, SaveService saveService) + public Configuration(CharacterUtility utility, FilenameService fileNames, ConfigMigrationService migrator, SaveService saveService) { _saveService = saveService; - Load(fileNames, migrator); + Load(utility, fileNames, migrator); UI.Classes.Colors.SetColors(this); } - public void Load(FilenameService fileNames, ConfigMigrationService migrator) + public void Load(CharacterUtility utility, FilenameService fileNames, ConfigMigrationService migrator) { static void HandleDeserializationError(object? sender, ErrorEventArgs errorArgs) { @@ -126,7 +127,7 @@ public class Configuration : IPluginConfiguration, ISavable }); } - migrator.Migrate(this); + migrator.Migrate(utility, this); } /// Save the current configuration. diff --git a/Penumbra/Interop/Services/CharacterUtility.List.cs b/Penumbra/Interop/Services/CharacterUtility.List.cs deleted file mode 100644 index abe024af..00000000 --- a/Penumbra/Interop/Services/CharacterUtility.List.cs +++ /dev/null @@ -1,166 +0,0 @@ -using System; -using System.Collections.Generic; -using Penumbra.Interop.Structs; - -namespace Penumbra.Interop.Services; - -public unsafe partial class CharacterUtility -{ - public class MetaList : IDisposable - { - private readonly LinkedList _entries = new(); - public readonly InternalIndex Index; - public readonly MetaIndex GlobalMetaIndex; - - public IReadOnlyCollection Entries - => _entries; - - private nint _defaultResourceData = nint.Zero; - private int _defaultResourceSize = 0; - public bool Ready { get; private set; } = false; - - public MetaList(InternalIndex index) - { - Index = index; - GlobalMetaIndex = RelevantIndices[index.Value]; - } - - public void SetDefaultResource(nint data, int size) - { - if (Ready) - return; - - _defaultResourceData = data; - _defaultResourceSize = size; - Ready = _defaultResourceData != nint.Zero && size != 0; - if (_entries.Count <= 0) - return; - - var first = _entries.First!.Value; - SetResource(first.Data, first.Length); - } - - public (nint Address, int Size) DefaultResource - => (_defaultResourceData, _defaultResourceSize); - - public MetaReverter TemporarilySetResource(nint data, int length) - { -#if false - Penumbra.Log.Verbose($"Temporarily set resource {GlobalMetaIndex} to 0x{(ulong)data:X} ({length} bytes)."); -#endif - var reverter = new MetaReverter(this, data, length); - _entries.AddFirst(reverter); - SetResourceInternal(data, length); - return reverter; - } - - public MetaReverter TemporarilyResetResource() - { -#if false - Penumbra.Log.Verbose( - $"Temporarily reset resource {GlobalMetaIndex} to default at 0x{_defaultResourceData:X} ({_defaultResourceSize} bytes)."); -#endif - var reverter = new MetaReverter(this); - _entries.AddFirst(reverter); - ResetResourceInternal(); - return reverter; - } - - public void SetResource(nint data, int length) - { -#if false - Penumbra.Log.Verbose($"Set resource {GlobalMetaIndex} to 0x{(ulong)data:X} ({length} bytes)."); -#endif - SetResourceInternal(data, length); - } - - public void ResetResource() - { -#if false - Penumbra.Log.Verbose($"Reset resource {GlobalMetaIndex} to default at 0x{_defaultResourceData:X} ({_defaultResourceSize} bytes)."); -#endif - ResetResourceInternal(); - } - - /// Set the currently stored data of this resource to new values. - private void SetResourceInternal(nint data, int length) - { - if (!Ready) - return; - - var resource = Penumbra.CharacterUtility.Address->Resource(GlobalMetaIndex); - resource->SetData(data, length); - } - - /// Reset the currently stored data of this resource to its default values. - private void ResetResourceInternal() - => SetResourceInternal(_defaultResourceData, _defaultResourceSize); - - private void SetResourceToDefaultCollection() - => Penumbra.CollectionManager.Active.Default.SetMetaFile(GlobalMetaIndex); - - public void Dispose() - { - if (_entries.Count > 0) - { - foreach (var entry in _entries) - entry.Disposed = true; - - _entries.Clear(); - } - - ResetResourceInternal(); - } - - public sealed class MetaReverter : IDisposable - { - public readonly MetaList MetaList; - public readonly nint Data; - public readonly int Length; - public readonly bool Resetter; - public bool Disposed; - - public MetaReverter(MetaList metaList, nint data, int length) - { - MetaList = metaList; - Data = data; - Length = length; - } - - public MetaReverter(MetaList metaList) - { - MetaList = metaList; - Data = nint.Zero; - Length = 0; - Resetter = true; - } - - public void Dispose() - { - if (Disposed) - return; - - var list = MetaList._entries; - var wasCurrent = ReferenceEquals(this, list.First?.Value); - list.Remove(this); - if (!wasCurrent) - return; - - if (list.Count == 0) - { - MetaList.SetResourceToDefaultCollection(); - } - else - { - var next = list.First!.Value; - if (next.Resetter) - MetaList.ResetResourceInternal(); - else - MetaList.SetResourceInternal(next.Data, next.Length); - } - - Disposed = true; - } - } - } -} \ No newline at end of file diff --git a/Penumbra/Interop/Services/CharacterUtility.cs b/Penumbra/Interop/Services/CharacterUtility.cs index 17052101..3ac83e50 100644 --- a/Penumbra/Interop/Services/CharacterUtility.cs +++ b/Penumbra/Interop/Services/CharacterUtility.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using Dalamud.Game; using Dalamud.Utility.Signatures; +using Penumbra.Collections.Manager; using Penumbra.GameData; using Penumbra.Interop.Structs; @@ -45,9 +46,7 @@ public unsafe partial class CharacterUtility : IDisposable .Select(i => new InternalIndex(Array.IndexOf(RelevantIndices, (MetaIndex)i))) .ToArray(); - private readonly MetaList[] _lists = Enumerable.Range(0, RelevantIndices.Length) - .Select(idx => new MetaList(new InternalIndex(idx))) - .ToArray(); + private readonly MetaList[] _lists; public IReadOnlyList Lists => _lists; @@ -55,12 +54,17 @@ public unsafe partial class CharacterUtility : IDisposable public (nint Address, int Size) DefaultResource(InternalIndex idx) => _lists[idx.Value].DefaultResource; - private readonly Framework _framework; + private readonly Framework _framework; + public readonly ActiveCollectionData Active; - public CharacterUtility(Framework framework) + public CharacterUtility(Framework framework, ActiveCollectionData active) { SignatureHelper.Initialise(this); + _lists = Enumerable.Range(0, RelevantIndices.Length) + .Select(idx => new MetaList(this, new InternalIndex(idx))) + .ToArray(); _framework = framework; + Active = active; LoadingFinished += () => Penumbra.Log.Debug("Loading of CharacterUtility finished."); LoadDefaultResources(null!); if (!Ready) diff --git a/Penumbra/Interop/Services/MetaList.cs b/Penumbra/Interop/Services/MetaList.cs new file mode 100644 index 00000000..c0c38ff4 --- /dev/null +++ b/Penumbra/Interop/Services/MetaList.cs @@ -0,0 +1,157 @@ +using System; +using System.Collections.Generic; +using Penumbra.Interop.Structs; + +namespace Penumbra.Interop.Services; + +public unsafe class MetaList : IDisposable +{ + private readonly CharacterUtility _utility; + private readonly LinkedList _entries = new(); + public readonly CharacterUtility.InternalIndex Index; + public readonly MetaIndex GlobalMetaIndex; + + public IReadOnlyCollection Entries + => _entries; + + private nint _defaultResourceData = nint.Zero; + private int _defaultResourceSize = 0; + public bool Ready { get; private set; } = false; + + public MetaList(CharacterUtility utility, CharacterUtility.InternalIndex index) + { + _utility = utility; + Index = index; + GlobalMetaIndex = CharacterUtility.RelevantIndices[index.Value]; + } + + public void SetDefaultResource(nint data, int size) + { + if (Ready) + return; + + _defaultResourceData = data; + _defaultResourceSize = size; + Ready = _defaultResourceData != nint.Zero && size != 0; + if (_entries.Count <= 0) + return; + + var first = _entries.First!.Value; + SetResource(first.Data, first.Length); + } + + public (nint Address, int Size) DefaultResource + => (_defaultResourceData, _defaultResourceSize); + + public MetaReverter TemporarilySetResource(nint data, int length) + { + Penumbra.Log.Excessive($"Temporarily set resource {GlobalMetaIndex} to 0x{(ulong)data:X} ({length} bytes)."); + var reverter = new MetaReverter(this, data, length); + _entries.AddFirst(reverter); + SetResourceInternal(data, length); + return reverter; + } + + public MetaReverter TemporarilyResetResource() + { + Penumbra.Log.Excessive( + $"Temporarily reset resource {GlobalMetaIndex} to default at 0x{_defaultResourceData:X} ({_defaultResourceSize} bytes)."); + var reverter = new MetaReverter(this); + _entries.AddFirst(reverter); + ResetResourceInternal(); + return reverter; + } + + public void SetResource(nint data, int length) + { + Penumbra.Log.Excessive($"Set resource {GlobalMetaIndex} to 0x{(ulong)data:X} ({length} bytes)."); + SetResourceInternal(data, length); + } + + public void ResetResource() + { + Penumbra.Log.Excessive($"Reset resource {GlobalMetaIndex} to default at 0x{_defaultResourceData:X} ({_defaultResourceSize} bytes)."); + ResetResourceInternal(); + } + + /// Set the currently stored data of this resource to new values. + private void SetResourceInternal(nint data, int length) + { + if (!Ready) + return; + + var resource = _utility.Address->Resource(GlobalMetaIndex); + resource->SetData(data, length); + } + + /// Reset the currently stored data of this resource to its default values. + private void ResetResourceInternal() + => SetResourceInternal(_defaultResourceData, _defaultResourceSize); + + private void SetResourceToDefaultCollection() + => _utility.Active.Default.SetMetaFile(GlobalMetaIndex); + + public void Dispose() + { + if (_entries.Count > 0) + { + foreach (var entry in _entries) + entry.Disposed = true; + + _entries.Clear(); + } + + ResetResourceInternal(); + } + + public sealed class MetaReverter : IDisposable + { + public readonly MetaList MetaList; + public readonly nint Data; + public readonly int Length; + public readonly bool Resetter; + public bool Disposed; + + public MetaReverter(MetaList metaList, nint data, int length) + { + MetaList = metaList; + Data = data; + Length = length; + } + + public MetaReverter(MetaList metaList) + { + MetaList = metaList; + Data = nint.Zero; + Length = 0; + Resetter = true; + } + + public void Dispose() + { + if (Disposed) + return; + + var list = MetaList._entries; + var wasCurrent = ReferenceEquals(this, list.First?.Value); + list.Remove(this); + if (!wasCurrent) + return; + + if (list.Count == 0) + { + MetaList.SetResourceToDefaultCollection(); + } + else + { + var next = list.First!.Value; + if (next.Resetter) + MetaList.ResetResourceInternal(); + else + MetaList.SetResourceInternal(next.Data, next.Length); + } + + Disposed = true; + } + } +} diff --git a/Penumbra/Meta/MetaFileManager.cs b/Penumbra/Meta/MetaFileManager.cs index 033fc4ea..30186768 100644 --- a/Penumbra/Meta/MetaFileManager.cs +++ b/Penumbra/Meta/MetaFileManager.cs @@ -78,7 +78,7 @@ public unsafe class MetaFileManager } [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] - public CharacterUtility.MetaList.MetaReverter TemporarilySetFile(MetaBaseFile? file, MetaIndex metaIndex) + public MetaList.MetaReverter TemporarilySetFile(MetaBaseFile? file, MetaIndex metaIndex) => file == null ? CharacterUtility.TemporarilyResetResource(metaIndex) : CharacterUtility.TemporarilySetResource(metaIndex, (nint)file.Data, file.Length); diff --git a/Penumbra/Penumbra.cs b/Penumbra/Penumbra.cs index 3eb83f65..4892f5d9 100644 --- a/Penumbra/Penumbra.cs +++ b/Penumbra/Penumbra.cs @@ -15,12 +15,8 @@ using Penumbra.UI; using Penumbra.Util; using Penumbra.Collections; using Penumbra.Collections.Cache; -using Penumbra.GameData.Actors; using Penumbra.Interop.ResourceLoading; using Penumbra.Interop.PathResolving; -using CharacterUtility = Penumbra.Interop.Services.CharacterUtility; -using DalamudUtil = Dalamud.Utility.Util; -using ResidentResourceManager = Penumbra.Interop.Services.ResidentResourceManager; using Penumbra.Services; using Penumbra.Interop.Services; using Penumbra.Mods.Manager; @@ -34,11 +30,10 @@ public class Penumbra : IDalamudPlugin public string Name => "Penumbra"; - public static Logger Log { get; private set; } = null!; - public static ChatService ChatService { get; private set; } = null!; + public static Logger Log { get; private set; } = null!; + public static ChatService ChatService { get; private set; } = null!; - public static CharacterUtility CharacterUtility { get; private set; } = null!; - public static CollectionManager CollectionManager { get; private set; } = null!; + public static CharacterUtility CharacterUtility { get; private set; } = null!; public readonly RedrawService RedrawService; public readonly ModFileSystem ModFileSystem; @@ -50,7 +45,9 @@ public class Penumbra : IDalamudPlugin private readonly TempModManager _tempMods; private readonly TempCollectionManager _tempCollections; private readonly ModManager _modManager; + private readonly CollectionManager _collectionManager; private readonly Configuration _config; + private readonly CharacterUtility _characterUtility; private PenumbraWindowSystem? _windowSystem; private bool _disposed; @@ -65,16 +62,17 @@ public class Penumbra : IDalamudPlugin ChatService = _tmp.Services.GetRequiredService(); _validityChecker = _tmp.Services.GetRequiredService(); _tmp.Services.GetRequiredService(); - _config = _tmp.Services.GetRequiredService(); - CharacterUtility = _tmp.Services.GetRequiredService(); + _config = _tmp.Services.GetRequiredService(); + _characterUtility = _tmp.Services.GetRequiredService(); + CharacterUtility = _characterUtility; _tempMods = _tmp.Services.GetRequiredService(); _residentResources = _tmp.Services.GetRequiredService(); _tmp.Services.GetRequiredService(); - _modManager = _tmp.Services.GetRequiredService(); - CollectionManager = _tmp.Services.GetRequiredService(); - _tempCollections = _tmp.Services.GetRequiredService(); - ModFileSystem = _tmp.Services.GetRequiredService(); - RedrawService = _tmp.Services.GetRequiredService(); + _modManager = _tmp.Services.GetRequiredService(); + _collectionManager = _tmp.Services.GetRequiredService(); + _tempCollections = _tmp.Services.GetRequiredService(); + ModFileSystem = _tmp.Services.GetRequiredService(); + RedrawService = _tmp.Services.GetRequiredService(); _tmp.Services.GetRequiredService(); // Initialize because not required anywhere else. _tmp.Services.GetRequiredService(); // Initialize because not required anywhere else. using (var t = _tmp.Services.GetRequiredService().Measure(StartTimeType.PathResolver)) @@ -91,7 +89,7 @@ public class Penumbra : IDalamudPlugin OtterTex.NativeDll.Initialize(pluginInterface.AssemblyLocation.DirectoryName); Log.Information($"Loading native OtterTex assembly from {OtterTex.NativeDll.Directory}."); - if (CharacterUtility.Ready) + if (_characterUtility.Ready) _residentResources.Reload(); } catch @@ -149,18 +147,18 @@ public class Penumbra : IDalamudPlugin _config.EnableMods = enabled; if (enabled) { - if (CharacterUtility.Ready) + if (_characterUtility.Ready) { - CollectionManager.Active.Default.SetFiles(); + _collectionManager.Active.Default.SetFiles(); _residentResources.Reload(); RedrawService.RedrawAll(RedrawType.Redraw); } } else { - if (CharacterUtility.Ready) + if (_characterUtility.Ready) { - CharacterUtility.ResetAll(); + _characterUtility.ResetAll(); _residentResources.Reload(); RedrawService.RedrawAll(RedrawType.Redraw); } @@ -194,7 +192,7 @@ public class Penumbra : IDalamudPlugin sb.Append($"> **`Commit Hash: `** {_validityChecker.CommitHash}\n"); sb.Append($"> **`Enable Mods: `** {_config.EnableMods}\n"); sb.Append($"> **`Enable HTTP API: `** {_config.EnableHttpApi}\n"); - sb.Append($"> **`Operating System: `** {(DalamudUtil.IsLinux() ? "Mac/Linux (Wine)" : "Windows")}\n"); + sb.Append($"> **`Operating System: `** {(Dalamud.Utility.Util.IsLinux() ? "Mac/Linux (Wine)" : "Windows")}\n"); sb.Append($"> **`Root Directory: `** `{_config.ModDirectory}`, {(exists ? "Exists" : "Not Existing")}\n"); sb.Append( $"> **`Free Drive Space: `** {(drive != null ? Functions.HumanReadableSize(drive.AvailableFreeSpace) : "Unknown")}\n"); @@ -225,23 +223,23 @@ public class Penumbra : IDalamudPlugin + $"> **`Conflicts (Solved/Total): `** {c.AllConflicts.SelectMany(x => x).Sum(x => x.HasPriority && x.Solved ? x.Conflicts.Count : 0)}/{c.AllConflicts.SelectMany(x => x).Sum(x => x.HasPriority ? x.Conflicts.Count : 0)}\n"); sb.AppendLine("**Collections**"); - sb.Append($"> **`#Collections: `** {CollectionManager.Storage.Count - 1}\n"); + sb.Append($"> **`#Collections: `** {_collectionManager.Storage.Count - 1}\n"); sb.Append($"> **`#Temp Collections: `** {_tempCollections.Count}\n"); - sb.Append($"> **`Active Collections: `** {CollectionManager.Caches.Count - _tempCollections.Count}\n"); - sb.Append($"> **`Base Collection: `** {CollectionManager.Active.Default.AnonymizedName}\n"); - sb.Append($"> **`Interface Collection: `** {CollectionManager.Active.Interface.AnonymizedName}\n"); - sb.Append($"> **`Selected Collection: `** {CollectionManager.Active.Current.AnonymizedName}\n"); + sb.Append($"> **`Active Collections: `** {_collectionManager.Caches.Count - _tempCollections.Count}\n"); + sb.Append($"> **`Base Collection: `** {_collectionManager.Active.Default.AnonymizedName}\n"); + sb.Append($"> **`Interface Collection: `** {_collectionManager.Active.Interface.AnonymizedName}\n"); + sb.Append($"> **`Selected Collection: `** {_collectionManager.Active.Current.AnonymizedName}\n"); foreach (var (type, name, _) in CollectionTypeExtensions.Special) { - var collection = CollectionManager.Active.ByType(type); + var collection = _collectionManager.Active.ByType(type); if (collection != null) sb.Append($"> **`{name,-30}`** {collection.AnonymizedName}\n"); } - foreach (var (name, id, collection) in CollectionManager.Active.Individuals.Assignments) + foreach (var (name, id, collection) in _collectionManager.Active.Individuals.Assignments) sb.Append($"> **`{id[0].Incognito(name) + ':',-30}`** {collection.AnonymizedName}\n"); - foreach (var (collection, cache) in CollectionManager.Caches.Active) + foreach (var (collection, cache) in _collectionManager.Caches.Active) PrintCollection(collection, cache); return sb.ToString(); diff --git a/Penumbra/Services/ConfigMigrationService.cs b/Penumbra/Services/ConfigMigrationService.cs index 2d525c00..33f41deb 100644 --- a/Penumbra/Services/ConfigMigrationService.cs +++ b/Penumbra/Services/ConfigMigrationService.cs @@ -2,17 +2,16 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Dalamud.Plugin; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OtterGui.Filesystem; using Penumbra.Collections; using Penumbra.Collections.Manager; +using Penumbra.Interop.Services; using Penumbra.Mods; using Penumbra.Mods.Manager; using Penumbra.UI.Classes; using Penumbra.Util; -using SixLabors.ImageSharp; namespace Penumbra.Services; @@ -50,7 +49,7 @@ public class ConfigMigrationService config.Save(); } - public void Migrate(Configuration config) + public void Migrate(CharacterUtility utility, Configuration config) { _config = config; // Do this on every migration from now on for a while @@ -67,7 +66,7 @@ public class ConfigMigrationService CreateBackup(); Version0To1(); - Version1To2(); + Version1To2(utility); Version2To3(); Version3To4(); Version4To5(); @@ -149,14 +148,15 @@ public class ConfigMigrationService // Sort Order was moved to a separate file and may contain empty folders. // Active collections in general were moved to their own file. // Delete the penumbrametatmp folder if it exists. - private void Version1To2() + private void Version1To2(CharacterUtility utility) { if (_config.Version != 1) return; // Ensure the right meta files are loaded. DeleteMetaTmp(); - Penumbra.CharacterUtility.LoadCharacterResources(); + if (utility.Ready) + utility.LoadCharacterResources(); ResettleSortOrder(); ResettleCollectionSettings(); ResettleForcedCollection(); diff --git a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs index 46aedb33..517118c9 100644 --- a/Penumbra/UI/AdvancedWindow/ModEditWindow.cs +++ b/Penumbra/UI/AdvancedWindow/ModEditWindow.cs @@ -9,13 +9,13 @@ using Dalamud.Interface.Windowing; using ImGuiNET; using OtterGui; using OtterGui.Raii; +using Penumbra.Collections.Manager; using Penumbra.GameData.Enums; using Penumbra.GameData.Files; using Penumbra.Import.Textures; using Penumbra.Interop.ResourceTree; using Penumbra.Meta; using Penumbra.Mods; -using Penumbra.Mods.Manager; using Penumbra.Services; using Penumbra.String.Classes; using Penumbra.UI.Classes; @@ -33,6 +33,7 @@ public partial class ModEditWindow : Window, IDisposable private readonly ItemSwapTab _itemSwapTab; private readonly DataManager _gameData; private readonly MetaFileManager _metaFileManager; + private readonly ActiveCollections _activeCollections; private readonly StainService _stainService; private Mod? _mod; @@ -56,7 +57,7 @@ public partial class ModEditWindow : Window, IDisposable _modelTab.Reset(); _materialTab.Reset(); _shaderPackageTab.Reset(); - _itemSwapTab.UpdateMod(mod, Penumbra.CollectionManager.Active.Current[mod.Index].Settings); + _itemSwapTab.UpdateMod(mod, _activeCollections.Current[mod.Index].Settings); } public void ChangeOption(SubMod? subMod) @@ -479,7 +480,7 @@ public partial class ModEditWindow : Window, IDisposable /// private FullPath FindBestMatch(Utf8GamePath path) { - var currentFile = Penumbra.CollectionManager.Active.Current.ResolvePath(path); + var currentFile = _activeCollections.Current.ResolvePath(path); if (currentFile != null) return currentFile.Value; @@ -497,17 +498,18 @@ public partial class ModEditWindow : Window, IDisposable public ModEditWindow(PerformanceTracker performance, FileDialogService fileDialog, ItemSwapTab itemSwapTab, DataManager gameData, Configuration config, ModEditor editor, ResourceTreeFactory resourceTreeFactory, MetaFileManager metaFileManager, - StainService stainService) + StainService stainService, ActiveCollections activeCollections) : base(WindowBaseLabel) { - _performance = performance; - _itemSwapTab = itemSwapTab; - _config = config; - _editor = editor; - _metaFileManager = metaFileManager; - _stainService = stainService; - _gameData = gameData; - _fileDialog = fileDialog; + _performance = performance; + _itemSwapTab = itemSwapTab; + _config = config; + _editor = editor; + _metaFileManager = metaFileManager; + _stainService = stainService; + _activeCollections = activeCollections; + _gameData = gameData; + _fileDialog = fileDialog; _materialTab = new FileEditor(this, gameData, config, _fileDialog, "Materials", ".mtrl", () => _editor.Files.Mtrl, DrawMaterialPanel, () => _mod?.ModPath.FullName ?? string.Empty, bytes => new MtrlTab(this, new MtrlFile(bytes)));