diff --git a/Penumbra/Collections/ModCollection.Cache.cs b/Penumbra/Collections/ModCollection.Cache.cs index efc10988..925a37d4 100644 --- a/Penumbra/Collections/ModCollection.Cache.cs +++ b/Penumbra/Collections/ModCollection.Cache.cs @@ -253,16 +253,15 @@ public partial class ModCollection if( addMetaChanges ) { ++ChangeCounter; + if( mod.TotalManipulations > 0 ) + { + AddMetaFiles(); + } if( _collection == Penumbra.CollectionManager.Default ) { Penumbra.ResidentResources.Reload(); MetaManipulations.SetFiles(); } - - if( mod.TotalManipulations > 0 ) - { - AddMetaFiles(); - } } } diff --git a/Penumbra/Meta/Files/ImcFile.cs b/Penumbra/Meta/Files/ImcFile.cs index e0a5c7c9..965df0f9 100644 --- a/Penumbra/Meta/Files/ImcFile.cs +++ b/Penumbra/Meta/Files/ImcFile.cs @@ -134,7 +134,7 @@ public unsafe class ImcFile : MetaBaseFile var defaultPtr = ( ImcEntry* )( Data + PreambleSize ); for( var i = oldCount + 1; i < numVariants + 1; ++i ) { - Functions.MemCpyUnchecked( defaultPtr + i, defaultPtr, NumParts * sizeof( ImcEntry ) ); + Functions.MemCpyUnchecked( defaultPtr + i * NumParts, defaultPtr, NumParts * sizeof( ImcEntry ) ); } PluginLog.Verbose( "Expanded IMC {Path} from {Count} to {NewCount} variants.", Path, oldCount, numVariants ); @@ -197,9 +197,10 @@ public unsafe class ImcFile : MetaBaseFile } } - public static ImcEntry GetDefault( Utf8GamePath path, EquipSlot slot, int variantIdx ) + public static ImcEntry GetDefault( Utf8GamePath path, EquipSlot slot, int variantIdx, out bool exists ) { var file = Dalamud.GameData.GetFile( path.ToString() ); + exists = false; if( file == null ) { throw new Exception(); @@ -208,7 +209,12 @@ public unsafe class ImcFile : MetaBaseFile fixed( byte* ptr = file.Data ) { var entry = VariantPtr( ptr, PartIndex( slot ), variantIdx ); - return entry == null ? new ImcEntry() : *entry; + if( entry != null ) + { + exists = true; + return *entry; + } + return new ImcEntry(); } } diff --git a/Penumbra/Meta/Manager/MetaManager.Imc.cs b/Penumbra/Meta/Manager/MetaManager.Imc.cs index c3858564..1c0279d5 100644 --- a/Penumbra/Meta/Manager/MetaManager.Imc.cs +++ b/Penumbra/Meta/Manager/MetaManager.Imc.cs @@ -104,7 +104,7 @@ public partial class MetaManager return false; } - var def = ImcFile.GetDefault( path, m.EquipSlot, m.Variant ); + var def = ImcFile.GetDefault( path, m.EquipSlot, m.Variant, out _ ); var manip = m with { Entry = def }; if( !manip.Apply( file ) ) { diff --git a/Penumbra/UI/Classes/ModEditWindow.Meta.cs b/Penumbra/UI/Classes/ModEditWindow.Meta.cs index 96cfd632..7cdb10ea 100644 --- a/Penumbra/UI/Classes/ModEditWindow.Meta.cs +++ b/Penumbra/UI/Classes/ModEditWindow.Meta.cs @@ -286,7 +286,7 @@ public partial class ModEditWindow { try { - return ImcFile.GetDefault( imc.GamePath(), imc.EquipSlot, imc.Variant ); + return ImcFile.GetDefault( imc.GamePath(), imc.EquipSlot, imc.Variant, out _ ); } catch {