diff --git a/Penumbra/Interop/MusicManager.cs b/Penumbra/Interop/MusicManager.cs index 39885eef..7e7568d8 100644 --- a/Penumbra/Interop/MusicManager.cs +++ b/Penumbra/Interop/MusicManager.cs @@ -1,5 +1,6 @@ using System; using Dalamud.Logging; +using Dalamud.Utility.Signatures; namespace Penumbra.Interop; @@ -7,16 +8,17 @@ namespace Penumbra.Interop; // which will allow replacement of .scd files. public unsafe class MusicManager { + // The wildcard is the offset in framework to the MusicManager in Framework. + [Signature( "48 8B 8E ?? ?? ?? ?? 39 78 20 0F 94 C2 45 33 C0", ScanType = ScanType.Text )] + private readonly IntPtr _musicInitCallLocation = IntPtr.Zero; + private readonly IntPtr _musicManager; public MusicManager() { - var framework = Dalamud.Framework.Address.BaseAddress; - // The wildcard is the offset in framework to the MusicManager in Framework. - var musicInitCallLocation = Dalamud.SigScanner.ScanText( "48 8B 8E ?? ?? ?? ?? 39 78 20 0F 94 C2 45 33 C0" ); - var musicManagerOffset = *( int* )( musicInitCallLocation + 3 ); - PluginLog.Debug( "Found MusicInitCall location at 0x{Location:X16}. Framework offset for MusicManager is 0x{Offset:X8}", - musicInitCallLocation.ToInt64(), musicManagerOffset ); + SignatureHelper.Initialise( this ); + var framework = Dalamud.Framework.Address.BaseAddress; + var musicManagerOffset = *( int* )( _musicInitCallLocation + 3 ); _musicManager = *( IntPtr* )( framework + musicManagerOffset ); PluginLog.Debug( "MusicManager found at 0x{Location:X16}", _musicManager.ToInt64() ); } diff --git a/Penumbra/Interop/ObjectReloader.cs b/Penumbra/Interop/ObjectReloader.cs index 6d345858..b28e54ab 100644 --- a/Penumbra/Interop/ObjectReloader.cs +++ b/Penumbra/Interop/ObjectReloader.cs @@ -48,13 +48,11 @@ public unsafe class ObjectReloader : IDisposable if( _currentObjectName != null && _mods.Collections.CharacterCollection.TryGetValue( _currentObjectName, out var collection ) ) { _changedSettings = true; - _mods.Collections.SetActiveCollection( collection, _currentObjectName ); } } private void RestoreSettings() { - _mods.Collections.ResetActiveCollection(); _changedSettings = false; } diff --git a/Penumbra/Mods/CollectionManager.cs b/Penumbra/Mods/CollectionManager.cs index cbada433..8018d942 100644 --- a/Penumbra/Mods/CollectionManager.cs +++ b/Penumbra/Mods/CollectionManager.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Dalamud.Logging; +using Lumina.Excel.GeneratedSheets; using Penumbra.Mod; using Penumbra.Util; @@ -25,14 +26,15 @@ public class CollectionManager { private readonly ModManager _manager; - public string CollectionChangedTo { get; private set; } = string.Empty; public Dictionary< string, ModCollection > Collections { get; } = new(StringComparer.InvariantCultureIgnoreCase); public Dictionary< string, ModCollection > CharacterCollection { get; } = new(); public ModCollection CurrentCollection { get; private set; } = ModCollection.Empty; public ModCollection DefaultCollection { get; private set; } = ModCollection.Empty; public ModCollection ForcedCollection { get; private set; } = ModCollection.Empty; - public ModCollection ActiveCollection { get; private set; } = ModCollection.Empty; + + public bool IsActive( ModCollection collection ) + => ReferenceEquals( collection, DefaultCollection ) || ReferenceEquals( collection, ForcedCollection ); // Is invoked after the collections actually changed. public event CollectionChangeDelegate? CollectionChanged; @@ -43,34 +45,8 @@ public class CollectionManager ReadCollections(); LoadConfigCollections( Penumbra.Config ); - SetActiveCollection( DefaultCollection, string.Empty ); } - public bool SetActiveCollection( ModCollection newActive, string name ) - { - CollectionChangedTo = name; - if( newActive == ActiveCollection ) - { - return false; - } - - if( ActiveCollection.Cache?.MetaManipulations.Count > 0 || newActive.Cache?.MetaManipulations.Count > 0 ) - { - ActiveCollection = newActive; - Penumbra.ResidentResources.Reload(); - ActiveCollection.SetFiles(); - } - else - { - ActiveCollection = newActive; - } - - return true; - } - - public bool ResetActiveCollection() - => SetActiveCollection( DefaultCollection, string.Empty ); - public void CreateNecessaryCaches() { AddCache( DefaultCollection ); @@ -121,7 +97,7 @@ public class CollectionManager } } - if( reloadMeta && ActiveCollection.Settings.TryGetValue( mod.BasePath.Name, out var config ) && config.Enabled ) + if( reloadMeta && DefaultCollection.Settings.TryGetValue( mod.BasePath.Name, out var config ) && config.Enabled ) { Penumbra.ResidentResources.Reload(); } @@ -130,7 +106,7 @@ public class CollectionManager public bool AddCollection( string name, Dictionary< string, ModSettings > settings ) { var nameFixed = name.RemoveInvalidPathSymbols().ToLowerInvariant(); - if( nameFixed == string.Empty || Collections.Values.Any( c => c.Name.RemoveInvalidPathSymbols().ToLowerInvariant() == nameFixed ) ) + if( nameFixed.Length == 0 || Collections.Values.Any( c => c.Name.RemoveInvalidPathSymbols().ToLowerInvariant() == nameFixed ) ) { PluginLog.Warning( $"The new collection {name} would lead to the same path as one that already exists." ); return false; @@ -232,29 +208,21 @@ public class CollectionManager case CollectionType.Default: DefaultCollection = newCollection; Penumbra.Config.DefaultCollection = newCollection.Name; - if( CollectionChangedTo.Length == 0 ) - { - SetActiveCollection( newCollection, string.Empty ); - } - + Penumbra.ResidentResources.Reload(); + DefaultCollection.SetFiles(); break; case CollectionType.Forced: ForcedCollection = newCollection; Penumbra.Config.ForcedCollection = newCollection.Name; + Penumbra.ResidentResources.Reload(); break; case CollectionType.Current: CurrentCollection = newCollection; Penumbra.Config.CurrentCollection = newCollection.Name; break; case CollectionType.Character: - if( CollectionChangedTo == characterName && CharacterCollection.ContainsKey( characterName ) ) - { - SetActiveCollection( newCollection, CollectionChangedTo ); - } - CharacterCollection[ characterName! ] = newCollection; Penumbra.Config.CharacterCollections[ characterName! ] = newCollection.Name; - break; } diff --git a/Penumbra/Mods/ModCollection.cs b/Penumbra/Mods/ModCollection.cs index 0408367a..8b285c36 100644 --- a/Penumbra/Mods/ModCollection.cs +++ b/Penumbra/Mods/ModCollection.cs @@ -6,8 +6,6 @@ using System.IO; using System.Linq; using Dalamud.Logging; using Penumbra.GameData.ByteString; -using Penumbra.GameData.Util; -using Penumbra.Interop.Structs; using Penumbra.Meta.Manager; using Penumbra.Mod; using Penumbra.Util; @@ -138,20 +136,20 @@ public class ModCollection } } - public void CalculateEffectiveFileList( bool withMetaManipulations, bool activeCollection ) + public void CalculateEffectiveFileList( bool withMetaManipulations, bool reloadResident ) { - PluginLog.Debug( "Recalculating effective file list for {CollectionName} [{WithMetaManipulations}] [{IsActiveCollection}]", Name, - withMetaManipulations, activeCollection ); + PluginLog.Debug( "Recalculating effective file list for {CollectionName} [{WithMetaManipulations}]", Name, withMetaManipulations ); Cache ??= new ModCollectionCache( this ); UpdateSettings( false ); Cache.CalculateEffectiveFileList(); if( withMetaManipulations ) { Cache.UpdateMetaManipulations(); - if( activeCollection ) - { - Penumbra.ResidentResources.Reload(); - } + } + + if( reloadResident ) + { + Penumbra.ResidentResources.Reload(); } } diff --git a/Penumbra/Mods/ModManager.cs b/Penumbra/Mods/ModManager.cs index 4a7ba3bd..e391fa3e 100644 --- a/Penumbra/Mods/ModManager.cs +++ b/Penumbra/Mods/ModManager.cs @@ -248,7 +248,7 @@ public class ModManager public FullPath? ResolveSwappedOrReplacementPath( Utf8GamePath gameResourcePath ) { - var ret = Collections.ActiveCollection.ResolveSwappedOrReplacementPath( gameResourcePath ); + var ret = Collections.DefaultCollection.ResolveSwappedOrReplacementPath( gameResourcePath ); ret ??= Collections.ForcedCollection.ResolveSwappedOrReplacementPath( gameResourcePath ); return ret; } diff --git a/Penumbra/Mods/ModManagerEditExtensions.cs b/Penumbra/Mods/ModManagerEditExtensions.cs index 6b8dde28..17e600c4 100644 --- a/Penumbra/Mods/ModManagerEditExtensions.cs +++ b/Penumbra/Mods/ModManagerEditExtensions.cs @@ -205,7 +205,7 @@ public static class ModManagerEditExtensions if( collection.Cache != null && settings.Enabled ) { collection.CalculateEffectiveFileList( mod.Resources.MetaManipulations.Count > 0, - collection == manager.Collections.ActiveCollection ); + manager.Collections.IsActive( collection ) ); } } } diff --git a/Penumbra/UI/MenuTabs/TabChangedItems.cs b/Penumbra/UI/MenuTabs/TabChangedItems.cs index 9e45038d..87d0b58c 100644 --- a/Penumbra/UI/MenuTabs/TabChangedItems.cs +++ b/Penumbra/UI/MenuTabs/TabChangedItems.cs @@ -26,8 +26,8 @@ public partial class SettingsInterface } var modManager = Penumbra.ModManager; - var items = modManager.Collections.ActiveCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >(); - var forced = modManager.Collections.ForcedCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >(); + var items = modManager.Collections.DefaultCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >(); + var forced = modManager.Collections.ForcedCollection.Cache?.ChangedItems ?? new Dictionary< string, object? >(); using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTabItem ); diff --git a/Penumbra/UI/MenuTabs/TabDebug.cs b/Penumbra/UI/MenuTabs/TabDebug.cs index b0281631..ab109e49 100644 --- a/Penumbra/UI/MenuTabs/TabDebug.cs +++ b/Penumbra/UI/MenuTabs/TabDebug.cs @@ -6,7 +6,9 @@ using System.Numerics; using System.Reflection; using System.Runtime.InteropServices; using Dalamud.Game.ClientState.Objects.Types; +using Dalamud.Interface; using ImGuiNET; +using Lumina.Excel.GeneratedSheets; using Penumbra.Api; using Penumbra.GameData.Enums; using Penumbra.GameData.Structs; @@ -47,8 +49,6 @@ public partial class SettingsInterface using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTable ); var manager = Penumbra.ModManager; - PrintValue( "Active Collection", manager.Collections.ActiveCollection.Name ); - PrintValue( " has Cache", ( manager.Collections.ActiveCollection.Cache != null ).ToString() ); PrintValue( "Current Collection", manager.Collections.CurrentCollection.Name ); PrintValue( " has Cache", ( manager.Collections.CurrentCollection.Cache != null ).ToString() ); PrintValue( "Default Collection", manager.Collections.DefaultCollection.Name ); @@ -287,59 +287,6 @@ public partial class SettingsInterface return; } - var eqp = 0; - ImGui.InputInt( "##EqpInput", ref eqp ); - try - { - var def = ExpandedEqpFile.GetDefault( eqp ); - var val = Penumbra.ModManager.Collections.ActiveCollection.Cache?.MetaManipulations.Eqp.File?[ eqp ] ?? def; - ImGui.Text( Convert.ToString( ( long )def, 2 ).PadLeft( 64, '0' ) ); - ImGui.Text( Convert.ToString( ( long )val, 2 ).PadLeft( 64, '0' ) ); - } - catch - { } - - var eqdp = 0; - ImGui.InputInt( "##EqdpInput", ref eqdp ); - try - { - var def = ExpandedEqdpFile.GetDefault( GenderRace.MidlanderMale, false, eqdp ); - var val = - Penumbra.ModManager.Collections.ActiveCollection.Cache?.MetaManipulations.Eqdp.File( GenderRace.MidlanderMale, false )?[ eqdp ] - ?? def; - ImGui.Text( Convert.ToString( ( ushort )def, 2 ).PadLeft( 16, '0' ) ); - ImGui.Text( Convert.ToString( ( ushort )val, 2 ).PadLeft( 16, '0' ) ); - } - catch - { } - - var est = 0; - ImGui.InputInt( "##EstInput", ref est ); - try - { - var def = EstFile.GetDefault( EstManipulation.EstType.Body, GenderRace.MidlanderFemale, ( ushort )est ); - var val = Penumbra.ModManager.Collections.ActiveCollection.Cache?.MetaManipulations.Est.BodyFile?[ GenderRace.MidlanderFemale, - ( ushort )est ] - ?? def; - ImGui.Text( def.ToString() ); - ImGui.Text( val.ToString() ); - } - catch - { } - - var gmp = 0; - ImGui.InputInt( "##GmpInput", ref gmp ); - try - { - var def = ExpandedGmpFile.GetDefault( gmp ); - var val = Penumbra.ModManager.Collections.ActiveCollection.Cache?.MetaManipulations.Gmp.File?[ gmp ] ?? def; - ImGui.Text( def.Value.ToString( "X" ) ); - ImGui.Text( val.Value.ToString( "X" ) ); - } - catch - { } - - if( !ImGui.BeginTable( "##CharacterUtilityDebugList", 6, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingFixedFit, -Vector2.UnitX ) ) { return; diff --git a/Penumbra/UI/MenuTabs/TabEffective.cs b/Penumbra/UI/MenuTabs/TabEffective.cs index ae9f35b9..101ac00e 100644 --- a/Penumbra/UI/MenuTabs/TabEffective.cs +++ b/Penumbra/UI/MenuTabs/TabEffective.cs @@ -14,7 +14,7 @@ public partial class SettingsInterface { private class TabEffective { - private const string LabelTab = "Effective Changes"; + private const string LabelTab = "Effective Changes"; private string _gamePathFilter = string.Empty; private string _gamePathFilterLower = string.Empty; @@ -140,17 +140,17 @@ public partial class SettingsInterface const ImGuiTableFlags flags = ImGuiTableFlags.RowBg | ImGuiTableFlags.ScrollX; - var modManager = Penumbra.ModManager; - var activeCollection = modManager.Collections.ActiveCollection.Cache; - var forcedCollection = modManager.Collections.ForcedCollection.Cache; + var modManager = Penumbra.ModManager; + var defaultCollection = modManager.Collections.DefaultCollection.Cache; + var forcedCollection = modManager.Collections.ForcedCollection.Cache; - var (activeResolved, activeMeta) = activeCollection != null - ? ( activeCollection.ResolvedFiles.Count, activeCollection.MetaManipulations.Count ) + var (defaultResolved, defaultMeta) = defaultCollection != null + ? ( defaultCollection.ResolvedFiles.Count, defaultCollection.MetaManipulations.Count ) : ( 0, 0 ); var (forcedResolved, forcedMeta) = forcedCollection != null ? ( forcedCollection.ResolvedFiles.Count, forcedCollection.MetaManipulations.Count ) : ( 0, 0 ); - var totalLines = activeResolved + forcedResolved + activeMeta + forcedMeta; + var totalLines = defaultResolved + forcedResolved + defaultMeta + forcedMeta; if( totalLines == 0 ) { return; @@ -166,7 +166,7 @@ public partial class SettingsInterface if( _filePathFilter.Length > 0 || _gamePathFilter.Length > 0 ) { - DrawFilteredRows( activeCollection, forcedCollection ); + DrawFilteredRows( defaultCollection, forcedCollection ); } else { @@ -185,18 +185,18 @@ public partial class SettingsInterface { var row = actualRow; ImGui.TableNextRow(); - if( row < activeResolved ) + if( row < defaultResolved ) { - var (gamePath, file) = activeCollection!.ResolvedFiles.ElementAt( row ); + var (gamePath, file) = defaultCollection!.ResolvedFiles.ElementAt( row ); DrawLine( gamePath, file ); } - else if( ( row -= activeResolved ) < activeMeta ) + else if( ( row -= defaultResolved ) < defaultMeta ) { // TODO //var (manip, mod) = activeCollection!.MetaManipulations.Manipulations.ElementAt( row ); DrawLine( 0.ToString(), 0.ToString() ); } - else if( ( row -= activeMeta ) < forcedResolved ) + else if( ( row -= defaultMeta ) < forcedResolved ) { var (gamePath, file) = forcedCollection!.ResolvedFiles.ElementAt( row ); DrawLine( gamePath, file ); @@ -204,7 +204,7 @@ public partial class SettingsInterface else { // TODO - row -= forcedResolved; + row -= forcedResolved; //var (manip, mod) = forcedCollection!.MetaManipulations.Manipulations.ElementAt( row ); DrawLine( 0.ToString(), 0.ToString() ); } diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs index d2000ba6..192126b1 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledDetails.cs @@ -426,7 +426,7 @@ public partial class SettingsInterface foreach( var collection in modManager.Collections.Collections.Values .Where( c => c.Cache != null && c.Settings[ Mod!.Data.BasePath.Name ].Enabled ) ) { - collection.CalculateEffectiveFileList( false, collection == modManager.Collections.ActiveCollection ); + collection.CalculateEffectiveFileList( false, modManager.Collections.IsActive( collection ) ); } // If the mod is enabled in the current collection, its conflicts may have changed. diff --git a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs index d805e41b..943bc84a 100644 --- a/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs +++ b/Penumbra/UI/MenuTabs/TabInstalled/TabInstalledSelector.cs @@ -529,7 +529,7 @@ public partial class SettingsInterface var collection = Penumbra.ModManager.Collections.CurrentCollection; if( collection.Cache != null ) { - collection.CalculateEffectiveFileList( metaManips, collection == Penumbra.ModManager.Collections.ActiveCollection ); + collection.CalculateEffectiveFileList( metaManips, Penumbra.ModManager.Collections.IsActive( collection ) ); } collection.Save(); @@ -602,8 +602,8 @@ public partial class SettingsInterface public Selector( SettingsInterface ui, IReadOnlySet< string > newMods ) { - _base = ui; - Cache = new ModListCache( Penumbra.ModManager, newMods ); + _base = ui; + Cache = new ModListCache( Penumbra.ModManager, newMods ); } private void DrawCollectionButton( string label, string tooltipLabel, float size, ModCollection collection ) diff --git a/Penumbra/UI/SettingsInterface.cs b/Penumbra/UI/SettingsInterface.cs index 897419f3..915bf84d 100644 --- a/Penumbra/UI/SettingsInterface.cs +++ b/Penumbra/UI/SettingsInterface.cs @@ -68,8 +68,7 @@ public partial class SettingsInterface : IDisposable var current = modManager.Collections.CurrentCollection; if( current.Cache != null ) { - current.CalculateEffectiveFileList( recalculateMeta, - current == modManager.Collections.ActiveCollection ); + current.CalculateEffectiveFileList( recalculateMeta, modManager.Collections.IsActive( current ) ); _menu.InstalledTab.Selector.Cache.TriggerFilterReset(); } }