@@ -1184,7 +1184,16 @@ public byte[] SerializeBytes() {
11841184 return stream . ToArray ( ) ;
11851185 }
11861186 }
1187- public MXmlBase SerializeMXmlValue ( Type fieldType , FieldInfo field , NMSAttribute settings , object value , bool isField = true )
1187+
1188+ /// <summary>
1189+ /// .
1190+ /// </summary>
1191+ /// <param name="fieldType">The field type of the field.</param>
1192+ /// <param name="field">A field.</param>
1193+ /// <param name="settings">The settings of the field.</param>
1194+ /// <param name="value">The value of the field.</param>
1195+ /// <param name="IncludeTypeInfo">If true, type info is written to the MXML file.</param>
1196+ public MXmlBase SerializeMXmlValue ( Type fieldType , FieldInfo field , NMSAttribute settings , object value , bool IncludeTypeInfo )
11881197 {
11891198 string t = fieldType . Name ;
11901199 int i = 0 ;
@@ -1237,13 +1246,13 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute
12371246 case "Colour32" :
12381247 // Handle the Colour32 explicitly since we want to write floats to the MXML, not ints.
12391248 Colour colour = new Colour ( ( Colour32 ) value ) ;
1240- MXmlProperty colour_field = ( MXmlProperty ) colour . SerializeMXml ( true ) ;
1249+ MXmlProperty colour_field = ( MXmlProperty ) colour . SerializeMXml ( true , false , IncludeTypeInfo ) ;
12411250 colour_field . Name = fieldName ;
12421251 return colour_field ;
12431252 case "LinkableNMSTemplate" :
12441253 LinkableNMSTemplate linkedTemplate = ( LinkableNMSTemplate ) value ;
12451254 if ( linkedTemplate . Template != null ) {
1246- MXmlProperty templateXmlData = ( MXmlProperty ) linkedTemplate . Template . SerializeMXml ( true , true ) ;
1255+ MXmlProperty templateXmlData = ( MXmlProperty ) linkedTemplate . Template . SerializeMXml ( true , true , IncludeTypeInfo ) ;
12471256 templateXmlData . Name = fieldName ;
12481257 templateXmlData . Value = linkedTemplate . Template . GetType ( ) . Name ;
12491258 if ( linkedTemplate . Linked . StringValue ( ) != "" ) {
@@ -1280,7 +1289,7 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute
12801289 } else {
12811290 Dictionary < string , uint > IdCounter = new Dictionary < string , uint > { } ;
12821291 foreach ( var template in templates ) {
1283- MXmlProperty data = ( MXmlProperty ) SerializeMXmlValue ( listType , field , settings , template , false ) ;
1292+ MXmlProperty data = ( MXmlProperty ) SerializeMXmlValue ( listType , field , settings , template , IncludeTypeInfo ) ;
12841293 data . Name = fieldName ;
12851294 string typeIdField = TypeHasID ( listType ) ;
12861295 if ( typeIdField != null ) {
@@ -1310,7 +1319,7 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute
13101319 if ( value != null ) {
13111320 NMSTemplate template = ( NMSTemplate ) value ;
13121321
1313- MXmlProperty templateXmlData = ( MXmlProperty ) template . SerializeMXml ( true , true ) ;
1322+ MXmlProperty templateXmlData = ( MXmlProperty ) template . SerializeMXml ( true , true , IncludeTypeInfo ) ;
13141323 templateXmlData . Name = fieldName ;
13151324 templateXmlData . Value = template . GetType ( ) . Name ;
13161325
@@ -1335,7 +1344,7 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute
13351344 string id_field = field . GetCustomAttribute < NMSAttribute > ( ) ? . KeyField ?? "" ;
13361345
13371346 foreach ( var template in ( IEnumerable ) value ) {
1338- MXmlProperty data = ( MXmlProperty ) SerializeMXmlValue ( hashMapType , field , settings , template , false ) ;
1347+ MXmlProperty data = ( MXmlProperty ) SerializeMXmlValue ( hashMapType , field , settings , template , IncludeTypeInfo ) ;
13391348
13401349 // Get aforementioned id field and write to the `_id` attribute.
13411350 MXmlProperty IdData = ( MXmlProperty ) data . Elements . Where (
@@ -1357,7 +1366,7 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute
13571366 } else {
13581367 template = ( NMSTemplate ) value ;
13591368 }
1360- var templateXmlData = template . SerializeMXml ( true ) ;
1369+ var templateXmlData = template . SerializeMXml ( true , false , IncludeTypeInfo ) ;
13611370 templateXmlData . Name = fieldName ;
13621371
13631372 return templateXmlData ;
@@ -1367,11 +1376,15 @@ public MXmlBase SerializeMXmlValue(Type fieldType, FieldInfo field, NMSAttribute
13671376 Name = fieldName
13681377 } ;
13691378
1379+ if ( IncludeTypeInfo ) {
1380+ arrayProperty . ArraySize = field . GetCustomAttribute < NMSAttribute > ( ) ? . Size . ToString ( ) ;
1381+ }
1382+
13701383 Array array = ( Array ) value ;
13711384 string [ ] names = GetEnumNames ( field . Name , array . Length , settings ) ;
13721385 i = 0 ;
13731386 foreach ( var template in array ) {
1374- MXmlProperty data = ( MXmlProperty ) SerializeMXmlValue ( arrayType , field , settings , template , false ) ;
1387+ MXmlProperty data = ( MXmlProperty ) SerializeMXmlValue ( arrayType , field , settings , template , IncludeTypeInfo ) ;
13751388 // Only change the name if we have an associated enum.
13761389 string overwriteName = names [ i ] ;
13771390 if ( overwriteName != null && overwriteName != "" ) {
@@ -1467,7 +1480,13 @@ private static int GetArrayLength( string fieldName, NMSAttribute settings ) {
14671480 return GetEnumNames ( fieldName , settings ) . Length ;
14681481 }
14691482
1470- public MXmlBase SerializeMXml ( bool isChildTemplate , bool isGenericTemplate = false ) {
1483+ /// <summary>
1484+ /// .
1485+ /// </summary>
1486+ /// <param name="isChildTemplate">If true, </param>
1487+ /// <param name="isGenericTemplate">If true, </param>
1488+ /// <param name="IncludeTypeInfo">If true, type info is written to the MXML file.</param>
1489+ public MXmlBase SerializeMXml ( bool isChildTemplate , bool isGenericTemplate = false , bool IncludeTypeInfo = false ) {
14711490 Type type = GetType ( ) ;
14721491 string typeName = type . Name != "NMSString0x20A" ? type . Name : "NMSString0x20" ;
14731492 MXmlBase xmlData = new MXmlProperty { } ;
@@ -1495,9 +1514,9 @@ public MXmlBase SerializeMXml(bool isChildTemplate, bool isGenericTemplate = fal
14951514 if ( field . IsInitOnly ) continue ;
14961515
14971516 if ( isGenericTemplate ) {
1498- subElement . Elements . Add ( SerializeMXmlValue ( field . FieldType , field , settings , field . GetValue ( this ) ) ) ;
1517+ subElement . Elements . Add ( SerializeMXmlValue ( field . FieldType , field , settings , field . GetValue ( this ) , IncludeTypeInfo ) ) ;
14991518 } else {
1500- xmlData . Elements . Add ( SerializeMXmlValue ( field . FieldType , field , settings , field . GetValue ( this ) ) ) ;
1519+ xmlData . Elements . Add ( SerializeMXmlValue ( field . FieldType , field , settings , field . GetValue ( this ) , IncludeTypeInfo ) ) ;
15011520 }
15021521 }
15031522
@@ -1807,19 +1826,15 @@ public void WriteToMbin(string outputpath)
18071826 }
18081827 }
18091828
1810- /// <summary>
1811- /// Writes the NMSTemplate object to an .mxml file.
1812- /// </summary>
1813- /// <param name="outputpath">The location to write the .mxml file.</param>
1814- public void WriteToMxml ( string outputpath ) => WriteToMxml ( outputpath , false ) ;
18151829 /// <summary>
18161830 /// Writes the NMSTemplate object to an .mxml file.
18171831 /// </summary>
18181832 /// <param name="outputpath">The location to write the .mxml file.</param>
18191833 /// <param name="hideVersionInfo">If true, version info is not written to the MXML file.</param>
1820- public void WriteToMxml ( string outputpath , bool hideVersionInfo )
1834+ /// <param name="IncludeTypeInfo">If true, type info is written to the MXML file.</param>
1835+ public void WriteToMxml ( string outputpath , bool hideVersionInfo , bool IncludeTypeInfo )
18211836 {
1822- var data = MXmlFile . WriteTemplate ( this , hideVersionInfo ) ;
1837+ var data = MXmlFile . WriteTemplate ( this , hideVersionInfo , IncludeTypeInfo ) ;
18231838 File . WriteAllText ( outputpath , data ) ;
18241839 }
18251840
0 commit comments