diff --git a/Penumbra/Configuration.cs b/Penumbra/Configuration.cs index b51251a1..0e6b70d2 100644 --- a/Penumbra/Configuration.cs +++ b/Penumbra/Configuration.cs @@ -69,6 +69,7 @@ public partial class Configuration : IPluginConfiguration public string DefaultModImportPath { get; set; } = string.Empty; public bool AlwaysOpenDefaultImport { get; set; } = false; + public bool KeepDefaultMetaChanges { get; set; } = false; public string DefaultModAuthor { get; set; } = DefaultTexToolsData.Author; public Dictionary< ColorId, uint > Colors { get; set; } diff --git a/Penumbra/Import/TexToolsMeta.Deserialization.cs b/Penumbra/Import/TexToolsMeta.Deserialization.cs index ce8a0bd0..2ea01648 100644 --- a/Penumbra/Import/TexToolsMeta.Deserialization.cs +++ b/Penumbra/Import/TexToolsMeta.Deserialization.cs @@ -22,7 +22,7 @@ public partial class TexToolsMeta var value = Eqp.FromSlotAndBytes( metaFileInfo.EquipSlot, data ); var def = new EqpManipulation( ExpandedEqpFile.GetDefault( metaFileInfo.PrimaryId ), metaFileInfo.EquipSlot, metaFileInfo.PrimaryId ); var manip = new EqpManipulation( value, metaFileInfo.EquipSlot, metaFileInfo.PrimaryId ); - if( def.Entry != manip.Entry ) + if( _keepDefault || def.Entry != manip.Entry ) { MetaManipulations.Add( manip ); } @@ -53,7 +53,7 @@ public partial class TexToolsMeta metaFileInfo.EquipSlot, gr.Split().Item1, gr.Split().Item2, metaFileInfo.PrimaryId ); var manip = new EqdpManipulation( value, metaFileInfo.EquipSlot, gr.Split().Item1, gr.Split().Item2, metaFileInfo.PrimaryId ); - if( def.Entry != manip.Entry ) + if( _keepDefault || def.Entry != manip.Entry ) { MetaManipulations.Add( manip ); } @@ -72,7 +72,7 @@ public partial class TexToolsMeta var value = ( GmpEntry )reader.ReadUInt32(); value.UnknownTotal = reader.ReadByte(); var def = ExpandedGmpFile.GetDefault( metaFileInfo.PrimaryId ); - if( value != def ) + if( _keepDefault || value != def ) { MetaManipulations.Add( new GmpManipulation( value, metaFileInfo.PrimaryId ) ); } @@ -107,7 +107,7 @@ public partial class TexToolsMeta } var def = EstFile.GetDefault( type, gr, id ); - if( def != value ) + if( _keepDefault || def != value ) { MetaManipulations.Add( new EstManipulation( gr.Split().Item1, gr.Split().Item2, type, id, value ) ); } @@ -136,7 +136,7 @@ public partial class TexToolsMeta var partIdx = ImcFile.PartIndex( manip.EquipSlot ); // Gets turned to unknown for things without equip, and unknown turns to 0. foreach( var value in values ) { - if( !value.Equals( def.GetEntry( partIdx, i ) ) ) + if( _keepDefault || !value.Equals( def.GetEntry( partIdx, i ) ) ) { MetaManipulations.Add( new ImcManipulation( manip.ObjectType, manip.BodySlot, manip.PrimaryId, manip.SecondaryId, i, manip.EquipSlot, value ) ); } diff --git a/Penumbra/Import/TexToolsMeta.Rgsp.cs b/Penumbra/Import/TexToolsMeta.Rgsp.cs index cc4055ad..8eb0c49a 100644 --- a/Penumbra/Import/TexToolsMeta.Rgsp.cs +++ b/Penumbra/Import/TexToolsMeta.Rgsp.cs @@ -9,7 +9,7 @@ namespace Penumbra.Import; public partial class TexToolsMeta { // Parse a single rgsp file. - public static TexToolsMeta FromRgspFile( string filePath, byte[] data ) + public static TexToolsMeta FromRgspFile( string filePath, byte[] data, bool keepDefault ) { if( data.Length != 45 && data.Length != 42 ) { @@ -47,7 +47,7 @@ public partial class TexToolsMeta void Add( RspAttribute attribute, float value ) { var def = CmpFile.GetDefault( subRace, attribute ); - if( value != def ) + if( keepDefault || value != def ) { ret.MetaManipulations.Add( new RspManipulation( subRace, attribute, value ) ); } diff --git a/Penumbra/Import/TexToolsMeta.cs b/Penumbra/Import/TexToolsMeta.cs index 2a2c98e5..8a8bb193 100644 --- a/Penumbra/Import/TexToolsMeta.cs +++ b/Penumbra/Import/TexToolsMeta.cs @@ -23,12 +23,14 @@ public partial class TexToolsMeta // The info class determines the files or table locations the changes need to apply to from the filename. - public readonly uint Version; - public readonly string FilePath; - public readonly List< MetaManipulation > MetaManipulations = new(); + public readonly uint Version; + public readonly string FilePath; + public readonly List< MetaManipulation > MetaManipulations = new(); + private readonly bool _keepDefault = false; - public TexToolsMeta( byte[] data ) + public TexToolsMeta( byte[] data, bool keepDefault ) { + _keepDefault = keepDefault; try { using var reader = new BinaryReader( new MemoryStream( data ) ); diff --git a/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs b/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs index 0cdb9aa8..b38307be 100644 --- a/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs +++ b/Penumbra/Mods/Subclasses/Mod.Files.SubMod.cs @@ -201,7 +201,7 @@ public partial class Mod continue; } - var meta = new TexToolsMeta( File.ReadAllBytes( file.FullName ) ); + var meta = new TexToolsMeta( File.ReadAllBytes( file.FullName ), Penumbra.Config.KeepDefaultMetaChanges ); Penumbra.Log.Verbose( $"Incorporating {file} as Metadata file of {meta.MetaManipulations.Count} manipulations {deleteString}" ); deleteList.Add( file.FullName ); ManipulationData.UnionWith( meta.MetaManipulations ); @@ -214,7 +214,7 @@ public partial class Mod continue; } - var rgsp = TexToolsMeta.FromRgspFile( file.FullName, File.ReadAllBytes( file.FullName ) ); + var rgsp = TexToolsMeta.FromRgspFile( file.FullName, File.ReadAllBytes( file.FullName ), Penumbra.Config.KeepDefaultMetaChanges ); Penumbra.Log.Verbose( $"Incorporating {file} as racial scaling file of {rgsp.MetaManipulations.Count} manipulations {deleteString}" ); deleteList.Add( file.FullName ); @@ -274,7 +274,9 @@ public partial class Mod { try { - var x = file.EndsWith( "rgsp" ) ? TexToolsMeta.FromRgspFile( file, data ) : new TexToolsMeta( data ); + var x = file.EndsWith( "rgsp" ) + ? TexToolsMeta.FromRgspFile( file, data, Penumbra.Config.KeepDefaultMetaChanges ) + : new TexToolsMeta( data, Penumbra.Config.KeepDefaultMetaChanges ); meta.UnionWith( x.MetaManipulations ); } catch diff --git a/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs b/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs index 2d47e290..d0ed97a7 100644 --- a/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs +++ b/Penumbra/UI/ConfigWindow.SettingsTab.Advanced.cs @@ -19,10 +19,17 @@ public partial class ConfigWindow OpenTutorial( BasicTutorialSteps.AdvancedSettings ); if( !header ) + { return; + } + Checkbox( "Auto Deduplicate on Import", "Automatically deduplicate mod files on import. This will make mod file sizes smaller, but deletes (binary identical) files.", Penumbra.Config.AutoDeduplicateOnImport, v => Penumbra.Config.AutoDeduplicateOnImport = v ); + Checkbox( "Keep Default Metadata Changes on Import", + "Normally, metadata changes that equal their default values, which are sometimes exported by TexTools, are discarded. " + + "Toggle this to keep them, for example if an option in a mod is supposed to disable a metadata change from a prior option.", + Penumbra.Config.KeepDefaultMetaChanges, v => Penumbra.Config.KeepDefaultMetaChanges = v ); DrawRequestedResourceLogging(); DrawEnableHttpApiBox(); DrawEnableDebugModeBox();