diff --git a/Penumbra/Interop/MusicManager.cs b/Penumbra/Interop/MusicManager.cs index 45d0c8c4..7c46427c 100644 --- a/Penumbra/Interop/MusicManager.cs +++ b/Penumbra/Interop/MusicManager.cs @@ -24,7 +24,7 @@ namespace Penumbra.Interop PluginLog.Debug( "Found MusicInitCall location at 0x{Location:X16}. Framework offset for MusicManager is 0x{Offset:X8}", musicInitCallLocation.ToInt64(), musicManagerOffset ); _musicManager = *( IntPtr* )( framework + musicManagerOffset ); - PluginLog.Debug( "MusicManager found at 0x{Location:X16}", _musicManager ); + PluginLog.Debug( "MusicManager found at 0x{Location:X16}", _musicManager.ToInt64() ); } public bool StreamingEnabled diff --git a/Penumbra/Mods/ModManagerEditExtensions.cs b/Penumbra/Mods/ModManagerEditExtensions.cs index 6f510f8a..bca0e200 100644 --- a/Penumbra/Mods/ModManagerEditExtensions.cs +++ b/Penumbra/Mods/ModManagerEditExtensions.cs @@ -2,218 +2,215 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.IO; -using System.Linq; using Dalamud.Logging; -using Dalamud.Plugin; using Penumbra.Mod; using Penumbra.Structs; -namespace Penumbra.Mods +namespace Penumbra.Mods; + +// Extracted to keep the main file a bit more clean. +// Contains all change functions on a specific mod that also require corresponding changes to collections. +public static class ModManagerEditExtensions { - // Extracted to keep the main file a bit more clean. - // Contains all change functions on a specific mod that also require corresponding changes to collections. - public static class ModManagerEditExtensions + public static bool RenameMod( this ModManager manager, string newName, ModData mod ) { - public static bool RenameMod( this ModManager manager, string newName, ModData mod ) + if( newName.Length == 0 || string.Equals( newName, mod.Meta.Name, StringComparison.InvariantCulture ) ) { - if( newName.Length == 0 || string.Equals( newName, mod.Meta.Name, StringComparison.InvariantCulture ) ) - { - return false; - } - - mod.Meta.Name = newName; - mod.SaveMeta(); - - return true; + return false; } - public static bool ChangeSortOrder( this ModManager manager, ModData mod, string newSortOrder ) + mod.Meta.Name = newName; + mod.SaveMeta(); + + return true; + } + + public static bool ChangeSortOrder( this ModManager manager, ModData mod, string newSortOrder ) + { + if( string.Equals( mod.SortOrder.FullPath, newSortOrder, StringComparison.InvariantCultureIgnoreCase ) ) { - if( string.Equals(mod.SortOrder.FullPath, newSortOrder, StringComparison.InvariantCultureIgnoreCase ) ) + return false; + } + + var inRoot = new SortOrder( manager.StructuredMods, mod.Meta.Name ); + if( newSortOrder == string.Empty || newSortOrder == inRoot.SortOrderName ) + { + mod.SortOrder = inRoot; + manager.Config.ModSortOrder.Remove( mod.BasePath.Name ); + } + else + { + mod.Move( newSortOrder ); + manager.Config.ModSortOrder[ mod.BasePath.Name ] = mod.SortOrder.FullPath; + } + + manager.Config.Save(); + + return true; + } + + public static bool RenameModFolder( this ModManager manager, ModData mod, DirectoryInfo newDir, bool move = true ) + { + if( move ) + { + newDir.Refresh(); + if( newDir.Exists ) { return false; } - var inRoot = new SortOrder( manager.StructuredMods, mod.Meta.Name ); - if( newSortOrder == string.Empty || newSortOrder == inRoot.SortOrderName ) + var oldDir = new DirectoryInfo( mod.BasePath.FullName ); + try { - mod.SortOrder = inRoot; - manager.Config.ModSortOrder.Remove( mod.BasePath.Name ); + oldDir.MoveTo( newDir.FullName ); } - else + catch( Exception e ) { - mod.Move( newSortOrder ); - manager.Config.ModSortOrder[ mod.BasePath.Name ] = mod.SortOrder.FullPath; + PluginLog.Error( $"Error while renaming directory {oldDir.FullName} to {newDir.FullName}:\n{e}" ); + return false; } + } + manager.Mods.Remove( mod.BasePath.Name ); + manager.Mods[ newDir.Name ] = mod; + + var oldBasePath = mod.BasePath; + mod.BasePath = newDir; + mod.MetaFile = ModData.MetaFileInfo( newDir ); + manager.UpdateMod( mod ); + + if( manager.Config.ModSortOrder.ContainsKey( oldBasePath.Name ) ) + { + manager.Config.ModSortOrder[ newDir.Name ] = manager.Config.ModSortOrder[ oldBasePath.Name ]; + manager.Config.ModSortOrder.Remove( oldBasePath.Name ); manager.Config.Save(); - - return true; } - public static bool RenameModFolder( this ModManager manager, ModData mod, DirectoryInfo newDir, bool move = true ) + foreach( var collection in manager.Collections.Collections.Values ) { - if( move ) + if( collection.Settings.TryGetValue( oldBasePath.Name, out var settings ) ) { - newDir.Refresh(); - if( newDir.Exists ) - { - return false; - } - - var oldDir = new DirectoryInfo( mod.BasePath.FullName ); - try - { - oldDir.MoveTo( newDir.FullName ); - } - catch( Exception e ) - { - PluginLog.Error( $"Error while renaming directory {oldDir.FullName} to {newDir.FullName}:\n{e}" ); - return false; - } - } - - manager.Mods.Remove( mod.BasePath.Name ); - manager.Mods[ newDir.Name ] = mod; - - var oldBasePath = mod.BasePath; - mod.BasePath = newDir; - mod.MetaFile = ModData.MetaFileInfo( newDir ); - manager.UpdateMod( mod ); - - if( manager.Config.ModSortOrder.ContainsKey( oldBasePath.Name ) ) - { - manager.Config.ModSortOrder[ newDir.Name ] = manager.Config.ModSortOrder[ oldBasePath.Name ]; - manager.Config.ModSortOrder.Remove( oldBasePath.Name ); - manager.Config.Save(); - } - - foreach( var collection in manager.Collections.Collections.Values ) - { - if( collection.Settings.TryGetValue( oldBasePath.Name, out var settings ) ) - { - collection.Settings[ newDir.Name ] = settings; - collection.Settings.Remove( oldBasePath.Name ); - collection.Save(); - } - - if( collection.Cache != null ) - { - collection.Cache.RemoveMod( newDir ); - collection.AddMod( mod ); - } - } - - return true; - } - - public static bool ChangeModGroup( this ModManager manager, string oldGroupName, string newGroupName, ModData mod, - SelectType type = SelectType.Single ) - { - if( newGroupName == oldGroupName || mod.Meta.Groups.ContainsKey( newGroupName ) ) - { - return false; - } - - if( mod.Meta.Groups.TryGetValue( oldGroupName, out var oldGroup ) ) - { - if( newGroupName.Length > 0 ) - { - mod.Meta.Groups[ newGroupName ] = new OptionGroup() - { - GroupName = newGroupName, - SelectionType = oldGroup.SelectionType, - Options = oldGroup.Options, - }; - } - - mod.Meta.Groups.Remove( oldGroupName ); - } - else - { - if( newGroupName.Length == 0 ) - { - return false; - } - - mod.Meta.Groups[ newGroupName ] = new OptionGroup() - { - GroupName = newGroupName, - SelectionType = type, - Options = new List< Option >(), - }; - } - - mod.SaveMeta(); - - foreach( var collection in manager.Collections.Collections.Values ) - { - if( !collection.Settings.TryGetValue( mod.BasePath.Name, out var settings ) ) - { - continue; - } - - if( newGroupName.Length > 0 ) - { - settings.Settings[ newGroupName ] = settings.Settings.TryGetValue( oldGroupName, out var value ) ? value : 0; - } - - settings.Settings.Remove( oldGroupName ); + collection.Settings[ newDir.Name ] = settings; + collection.Settings.Remove( oldBasePath.Name ); collection.Save(); } - return true; + if( collection.Cache != null ) + { + collection.Cache.RemoveMod( newDir ); + collection.AddMod( mod ); + } } - public static bool RemoveModOption( this ModManager manager, int optionIdx, OptionGroup group, ModData mod ) + return true; + } + + public static bool ChangeModGroup( this ModManager manager, string oldGroupName, string newGroupName, ModData mod, + SelectType type = SelectType.Single ) + { + if( newGroupName == oldGroupName || mod.Meta.Groups.ContainsKey( newGroupName ) ) { - if( optionIdx < 0 || optionIdx >= group.Options.Count ) + return false; + } + + if( mod.Meta.Groups.TryGetValue( oldGroupName, out var oldGroup ) ) + { + if( newGroupName.Length > 0 ) + { + mod.Meta.Groups[ newGroupName ] = new OptionGroup() + { + GroupName = newGroupName, + SelectionType = oldGroup.SelectionType, + Options = oldGroup.Options, + }; + } + + mod.Meta.Groups.Remove( oldGroupName ); + } + else + { + if( newGroupName.Length == 0 ) { return false; } - group.Options.RemoveAt( optionIdx ); - mod.SaveMeta(); - - static int MoveMultiSetting( int oldSetting, int idx ) + mod.Meta.Groups[ newGroupName ] = new OptionGroup() { - var bitmaskFront = ( 1 << idx ) - 1; - var bitmaskBack = ~( bitmaskFront | ( 1 << idx ) ); - return ( oldSetting & bitmaskFront ) | ( ( oldSetting & bitmaskBack ) >> 1 ); - } - - foreach( var collection in manager.Collections.Collections.Values ) - { - if( !collection.Settings.TryGetValue( mod.BasePath.Name, out var settings ) ) - { - continue; - } - - if( !settings.Settings.TryGetValue( group.GroupName, out var setting ) ) - { - setting = 0; - } - - var newSetting = group.SelectionType switch - { - SelectType.Single => setting >= optionIdx ? setting - 1 : setting, - SelectType.Multi => MoveMultiSetting( setting, optionIdx ), - _ => throw new InvalidEnumArgumentException(), - }; - - if( newSetting != setting ) - { - settings.Settings[ group.GroupName ] = newSetting; - collection.Save(); - if( collection.Cache != null && settings.Enabled ) - { - collection.CalculateEffectiveFileList( manager.TempPath, mod.Resources.MetaManipulations.Count > 0, - collection == manager.Collections.ActiveCollection ); - } - } - } - - return true; + GroupName = newGroupName, + SelectionType = type, + Options = new List< Option >(), + }; } + + mod.SaveMeta(); + + foreach( var collection in manager.Collections.Collections.Values ) + { + if( !collection.Settings.TryGetValue( mod.BasePath.Name, out var settings ) ) + { + continue; + } + + if( newGroupName.Length > 0 ) + { + settings.Settings[ newGroupName ] = settings.Settings.TryGetValue( oldGroupName, out var value ) ? value : 0; + } + + settings.Settings.Remove( oldGroupName ); + collection.Save(); + } + + return true; + } + + public static bool RemoveModOption( this ModManager manager, int optionIdx, OptionGroup group, ModData mod ) + { + if( optionIdx < 0 || optionIdx >= group.Options.Count ) + { + return false; + } + + group.Options.RemoveAt( optionIdx ); + mod.SaveMeta(); + + static int MoveMultiSetting( int oldSetting, int idx ) + { + var bitmaskFront = ( 1 << idx ) - 1; + var bitmaskBack = ~( bitmaskFront | ( 1 << idx ) ); + return ( oldSetting & bitmaskFront ) | ( ( oldSetting & bitmaskBack ) >> 1 ); + } + + foreach( var collection in manager.Collections.Collections.Values ) + { + if( !collection.Settings.TryGetValue( mod.BasePath.Name, out var settings ) ) + { + continue; + } + + if( !settings.Settings.TryGetValue( group.GroupName, out var setting ) ) + { + setting = 0; + } + + var newSetting = group.SelectionType switch + { + SelectType.Single => setting >= optionIdx ? setting - 1 : setting, + SelectType.Multi => MoveMultiSetting( setting, optionIdx ), + _ => throw new InvalidEnumArgumentException(), + }; + + if( newSetting != setting ) + { + settings.Settings[ group.GroupName ] = newSetting; + collection.Save(); + if( collection.Cache != null && settings.Enabled ) + { + collection.CalculateEffectiveFileList( manager.TempPath, mod.Resources.MetaManipulations.Count > 0, + collection == manager.Collections.ActiveCollection ); + } + } + } + + return true; } } \ No newline at end of file diff --git a/Penumbra/UI/MenuTabs/TabResourceManager.cs b/Penumbra/UI/MenuTabs/TabResourceManager.cs index 9cd6812b..1f3ad8de 100644 --- a/Penumbra/UI/MenuTabs/TabResourceManager.cs +++ b/Penumbra/UI/MenuTabs/TabResourceManager.cs @@ -94,7 +94,7 @@ public partial class SettingsInterface using var raii = ImGuiRaii.DeferredEnd( ImGui.EndTabItem ); - var resourceHandler = *( ResourceManager** )( Dalamud.SigScanner.Module.BaseAddress + 0x1E603C0 ); + var resourceHandler = *( ResourceManager** )Dalamud.SigScanner.GetStaticAddressFromSig( "48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 32 C0" ); if( resourceHandler == null ) { diff --git a/Penumbra/Util/ModelChanger.cs b/Penumbra/Util/ModelChanger.cs index 7cb1f068..8cb65a70 100644 --- a/Penumbra/Util/ModelChanger.cs +++ b/Penumbra/Util/ModelChanger.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Text; -using System.Windows.Forms; using Dalamud.Logging; using Penumbra.GameData.Files; using Penumbra.Mod;