diff --git a/libMBIN/Source/Template/NMSTemplate.cs b/libMBIN/Source/Template/NMSTemplate.cs index ef3086969..5182740a7 100644 --- a/libMBIN/Source/Template/NMSTemplate.cs +++ b/libMBIN/Source/Template/NMSTemplate.cs @@ -810,9 +810,10 @@ public void SerializeValue( IEnumerable end = Enumerable.Repeat((byte)0xEB, 4); byte[] hashPadding = start.Concat(new byte[(8 << (int)templ.EndPaddingLShift) - 8]).Concat(end).ToArray(); // This is always added at the start. - // Also set the offset as -1. We'll add a check for this to avoid writing an offset in this case. + // Also set the offset as -8. This indicates that the value is an alignment value + // (+ve values are handled as offsets, -ve are handled as alignments). - additionalData.Insert( addtDataIndex, new Tuple( -1, hashPadding ) ); + additionalData.Insert( addtDataIndex, new Tuple( -8, hashPadding ) ); addtDataIndex++; if ( addtDataIndex >= additionalData.Count ) { additionalData.Add( hmData ); @@ -1176,10 +1177,13 @@ public byte[] SerializeBytes() { } else if ( data.Item2.GetType() == typeof( byte[] ) ) { // write the offset in the list header long dataPosition = writer.BaseStream.Position; - if (data.Item1 != -1) { + if (data.Item1 >= 0) { writer.BaseStream.Position = data.Item1; writer.Write( dataPosition - data.Item1 ); writer.BaseStream.Position = dataPosition; + } else { + // We'll use the absolute value of the "position" as the alignment value as a lazy hack... + writer.Align((int)Math.Abs(data.Item1), data.Item2.GetType().Name, paddingByte); } SerializeValue( writer, data.Item2.GetType(), data.Item2, attributes, null, ref additionalData, ref i, paddingByte: paddingByte ); // passing i here *should* be fine as we will only be writing bytes which can't affect i @@ -1313,12 +1317,12 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute data.ID = IdData.Value; if (!IdCounter.ContainsKey(IdData.Value)) { IdCounter.Add(IdData.Value, 1); - } else { + } else if (!(listType == typeof(NMSTemplate) || listType == typeof(LinkableNMSTemplate))) { data.Index = IdCounter[IdData.Value].ToString(); IdCounter[IdData.Value] = IdCounter[IdData.Value] + 1; } } - } else { + } else if (!(listType == typeof(NMSTemplate) || listType == typeof(LinkableNMSTemplate))) { data.Index = i.ToString(); } listProperty.Elements.Add( data ); diff --git a/libMBIN/Source/Version.cs b/libMBIN/Source/Version.cs index 40dd3f674..7e1218789 100644 --- a/libMBIN/Source/Version.cs +++ b/libMBIN/Source/Version.cs @@ -25,7 +25,7 @@ public static class Version { // the Prerelease version should be reset to 1 // When the Release version is incremented: // the Prerelease version should be reset to 0 - internal const string VERSION_STRING = "6.44.0.2"; + internal const string VERSION_STRING = "6.44.0.3"; /// Shorthand for AssemblyVersion.Major public static int Major => AssemblyVersion.Major;