Add a toggle to keep metadata changes to the default value when importing TTMPs.

This commit is contained in:
Ottermandias 2022-12-26 18:36:52 +01:00
parent 707ae090bf
commit ef19af481b
6 changed files with 26 additions and 14 deletions

View file

@ -69,6 +69,7 @@ public partial class Configuration : IPluginConfiguration
public string DefaultModImportPath { get; set; } = string.Empty; public string DefaultModImportPath { get; set; } = string.Empty;
public bool AlwaysOpenDefaultImport { get; set; } = false; public bool AlwaysOpenDefaultImport { get; set; } = false;
public bool KeepDefaultMetaChanges { get; set; } = false;
public string DefaultModAuthor { get; set; } = DefaultTexToolsData.Author; public string DefaultModAuthor { get; set; } = DefaultTexToolsData.Author;
public Dictionary< ColorId, uint > Colors { get; set; } public Dictionary< ColorId, uint > Colors { get; set; }

View file

@ -22,7 +22,7 @@ public partial class TexToolsMeta
var value = Eqp.FromSlotAndBytes( metaFileInfo.EquipSlot, data ); var value = Eqp.FromSlotAndBytes( metaFileInfo.EquipSlot, data );
var def = new EqpManipulation( ExpandedEqpFile.GetDefault( metaFileInfo.PrimaryId ), metaFileInfo.EquipSlot, metaFileInfo.PrimaryId ); var def = new EqpManipulation( ExpandedEqpFile.GetDefault( metaFileInfo.PrimaryId ), metaFileInfo.EquipSlot, metaFileInfo.PrimaryId );
var manip = new EqpManipulation( value, 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 ); MetaManipulations.Add( manip );
} }
@ -53,7 +53,7 @@ public partial class TexToolsMeta
metaFileInfo.EquipSlot, metaFileInfo.EquipSlot,
gr.Split().Item1, gr.Split().Item2, metaFileInfo.PrimaryId ); gr.Split().Item1, gr.Split().Item2, metaFileInfo.PrimaryId );
var manip = new EqdpManipulation( value, 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 ); MetaManipulations.Add( manip );
} }
@ -72,7 +72,7 @@ public partial class TexToolsMeta
var value = ( GmpEntry )reader.ReadUInt32(); var value = ( GmpEntry )reader.ReadUInt32();
value.UnknownTotal = reader.ReadByte(); value.UnknownTotal = reader.ReadByte();
var def = ExpandedGmpFile.GetDefault( metaFileInfo.PrimaryId ); var def = ExpandedGmpFile.GetDefault( metaFileInfo.PrimaryId );
if( value != def ) if( _keepDefault || value != def )
{ {
MetaManipulations.Add( new GmpManipulation( value, metaFileInfo.PrimaryId ) ); MetaManipulations.Add( new GmpManipulation( value, metaFileInfo.PrimaryId ) );
} }
@ -107,7 +107,7 @@ public partial class TexToolsMeta
} }
var def = EstFile.GetDefault( type, gr, id ); 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 ) ); 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. var partIdx = ImcFile.PartIndex( manip.EquipSlot ); // Gets turned to unknown for things without equip, and unknown turns to 0.
foreach( var value in values ) 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 ) ); MetaManipulations.Add( new ImcManipulation( manip.ObjectType, manip.BodySlot, manip.PrimaryId, manip.SecondaryId, i, manip.EquipSlot, value ) );
} }

View file

@ -9,7 +9,7 @@ namespace Penumbra.Import;
public partial class TexToolsMeta public partial class TexToolsMeta
{ {
// Parse a single rgsp file. // 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 ) if( data.Length != 45 && data.Length != 42 )
{ {
@ -47,7 +47,7 @@ public partial class TexToolsMeta
void Add( RspAttribute attribute, float value ) void Add( RspAttribute attribute, float value )
{ {
var def = CmpFile.GetDefault( subRace, attribute ); var def = CmpFile.GetDefault( subRace, attribute );
if( value != def ) if( keepDefault || value != def )
{ {
ret.MetaManipulations.Add( new RspManipulation( subRace, attribute, value ) ); ret.MetaManipulations.Add( new RspManipulation( subRace, attribute, value ) );
} }

View file

@ -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. // The info class determines the files or table locations the changes need to apply to from the filename.
public readonly uint Version; public readonly uint Version;
public readonly string FilePath; public readonly string FilePath;
public readonly List< MetaManipulation > MetaManipulations = new(); public readonly List< MetaManipulation > MetaManipulations = new();
private readonly bool _keepDefault = false;
public TexToolsMeta( byte[] data ) public TexToolsMeta( byte[] data, bool keepDefault )
{ {
_keepDefault = keepDefault;
try try
{ {
using var reader = new BinaryReader( new MemoryStream( data ) ); using var reader = new BinaryReader( new MemoryStream( data ) );

View file

@ -201,7 +201,7 @@ public partial class Mod
continue; 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}" ); Penumbra.Log.Verbose( $"Incorporating {file} as Metadata file of {meta.MetaManipulations.Count} manipulations {deleteString}" );
deleteList.Add( file.FullName ); deleteList.Add( file.FullName );
ManipulationData.UnionWith( meta.MetaManipulations ); ManipulationData.UnionWith( meta.MetaManipulations );
@ -214,7 +214,7 @@ public partial class Mod
continue; 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}" ); Penumbra.Log.Verbose( $"Incorporating {file} as racial scaling file of {rgsp.MetaManipulations.Count} manipulations {deleteString}" );
deleteList.Add( file.FullName ); deleteList.Add( file.FullName );
@ -274,7 +274,9 @@ public partial class Mod
{ {
try 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 ); meta.UnionWith( x.MetaManipulations );
} }
catch catch

View file

@ -19,10 +19,17 @@ public partial class ConfigWindow
OpenTutorial( BasicTutorialSteps.AdvancedSettings ); OpenTutorial( BasicTutorialSteps.AdvancedSettings );
if( !header ) if( !header )
{
return; return;
}
Checkbox( "Auto Deduplicate on Import", Checkbox( "Auto Deduplicate on Import",
"Automatically deduplicate mod files on import. This will make mod file sizes smaller, but deletes (binary identical) files.", "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 ); 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(); DrawRequestedResourceLogging();
DrawEnableHttpApiBox(); DrawEnableHttpApiBox();
DrawEnableDebugModeBox(); DrawEnableDebugModeBox();