From fb64a748383c2eab5fcc33816093e2e81adae08d Mon Sep 17 00:00:00 2001 From: monkeyman192 Date: Wed, 24 Apr 2024 21:20:56 +1000 Subject: [PATCH] Fixup some classes which never recompiled 1:1 --- .../Source/NMS/Toolkit/TkAnimNodeFrameData.cs | 4 +-- .../NMS/Toolkit/TkAnimNodeFrameHalfData.cs | 4 +-- libMBIN/Source/NMS/Toolkit/TkGeometryData.cs | 6 ++--- libMBIN/Source/NMS/Toolkit/TkMeshData.cs | 4 +-- libMBIN/Source/Template/NMSTemplate.cs | 27 +++++++++++-------- 5 files changed, 25 insertions(+), 20 deletions(-) diff --git a/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameData.cs b/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameData.cs index cfbf80dba..76030fe0d 100644 --- a/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameData.cs +++ b/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameData.cs @@ -106,7 +106,7 @@ public override object CustomDeserialize(BinaryReader reader, Type field, NMSAtt return null; } - public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) + public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) { if (field == null || fieldInfo == null) return false; @@ -154,7 +154,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie } - additionalData.Insert(addtDataIndex, new Tuple(listPos, outputData)); + additionalData.Insert(addtDataIndex, new Tuple(listPos, outputData, 0)); addtDataIndex++; return true; } diff --git a/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameHalfData.cs b/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameHalfData.cs index 38db81c24..27a05d4b7 100644 --- a/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameHalfData.cs +++ b/libMBIN/Source/NMS/Toolkit/TkAnimNodeFrameHalfData.cs @@ -105,7 +105,7 @@ public override object CustomDeserialize(BinaryReader reader, Type field, NMSAtt return null; } - public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) + public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) { if (field == null || fieldInfo == null) return false; @@ -153,7 +153,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie } - additionalData.Insert(addtDataIndex, new Tuple(listPos, outputData)); + additionalData.Insert(addtDataIndex, new Tuple(listPos, outputData, 0)); addtDataIndex++; return true; } diff --git a/libMBIN/Source/NMS/Toolkit/TkGeometryData.cs b/libMBIN/Source/NMS/Toolkit/TkGeometryData.cs index 5710936d5..893786223 100644 --- a/libMBIN/Source/NMS/Toolkit/TkGeometryData.cs +++ b/libMBIN/Source/NMS/Toolkit/TkGeometryData.cs @@ -32,7 +32,7 @@ public class TkGeometryData : NMSTemplate /* 0x13C */ public int VertexCount; // TODO: add the list ending to this?? - public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) { + public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) { if (field == null || fieldInfo == null) return false; Dictionary TypeMap = new Dictionary { { 5131, 8 }, { 36255, 4 }, { 5121, 4 } }; @@ -51,7 +51,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie IList data = (IList)fieldData; if (Indices16Bit != 1) { // if 32bit indices, we can just pass it directly - additionalData.Insert(addtDataIndex, new Tuple(listPos, data)); + additionalData.Insert(addtDataIndex, new Tuple(listPos, data, 0)); } else { // otherwise we have to create 32bit indices from the 16bit ones @@ -70,7 +70,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie list32Bit.Add(val32Bit); } - additionalData.Insert(addtDataIndex, new Tuple(listPos, list32Bit)); + additionalData.Insert(addtDataIndex, new Tuple(listPos, list32Bit, 0)); } addtDataIndex++; return true; diff --git a/libMBIN/Source/NMS/Toolkit/TkMeshData.cs b/libMBIN/Source/NMS/Toolkit/TkMeshData.cs index 8b3a512d8..5eef1f43a 100644 --- a/libMBIN/Source/NMS/Toolkit/TkMeshData.cs +++ b/libMBIN/Source/NMS/Toolkit/TkMeshData.cs @@ -40,7 +40,7 @@ public override object CustomDeserialize( BinaryReader reader, Type field, NMSAt return null; } - public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) + public override bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) { var fieldName = fieldInfo.Name; switch (fieldName) @@ -54,7 +54,7 @@ public override bool CustomSerialize(BinaryWriter writer, Type field, object fie writer.Write((Int32) (MeshDataStream?.Length ?? 0)); // size of data chunk in bytes writer.Write((UInt32) 0xFEFEFE01); - additionalData.Insert(addtDataIndex, new Tuple(listPos, fieldData)); + additionalData.Insert(addtDataIndex, new Tuple(listPos, fieldData, 0x4)); addtDataIndex++; return true; } diff --git a/libMBIN/Source/Template/NMSTemplate.cs b/libMBIN/Source/Template/NMSTemplate.cs index 753c7718a..51e08d014 100644 --- a/libMBIN/Source/Template/NMSTemplate.cs +++ b/libMBIN/Source/Template/NMSTemplate.cs @@ -91,7 +91,7 @@ public int GetDataSize() { using (var ms = new MemoryStream()) using (var bw = new BinaryWriter(ms)) { - var addt = new List>(); + var addt = new List>(); int addtIdx = 0; var prevState = isDebugLogTemplateEnabled; @@ -583,7 +583,7 @@ public static List DeserializeList( BinaryReader reader, FieldInfo field, return list; } - public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldData, NMSAttribute settings, FieldInfo field, ref List> additionalData, ref int addtDataIndex, UInt32 listEnding = 0xAAAAAA01 ) { + public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldData, NMSAttribute settings, FieldInfo field, ref List> additionalData, ref int addtDataIndex, UInt32 listEnding = 0xAAAAAA01 ) { //Logger.LogDebug( $"{field?.DeclaringType.Name}.{field?.Name}\ttype:\t{fieldType.Name}\tadditionalData.Count:\t{additionalData?.Count ?? 0}\taddtDataIndex:\t{addtDataIndex}" ); if (CustomSerialize(writer, fieldType, fieldData, settings, field, ref additionalData, ref addtDataIndex)) return; @@ -656,7 +656,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat if ( listData == null ) break; if ( listData.Count == 0 ) break; - var data = new Tuple( listPos, listData ); + var data = new Tuple( listPos, listData, 0 ); if ( addtDataIndex >= additionalData.Count ) { additionalData.Add( data ); } else { @@ -689,7 +689,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat throw new InvalidGUIDException(template); } - var data = new Tuple( refPos, template ); + var data = new Tuple( refPos, template, 0 ); if ( addtDataIndex >= additionalData.Count ) { additionalData.Add( data ); } else { @@ -712,7 +712,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat writer.Write( listEnding ); var fieldValue = (NMS.VariableSizeString) fieldData; - additionalData.Insert( addtDataIndex++, new Tuple( fieldPos, fieldValue ) ); + additionalData.Insert( addtDataIndex++, new Tuple( fieldPos, fieldValue, 0 ) ); } else if ( fieldType.IsArray ) { var arrayType = fieldType.GetElementType(); @@ -754,7 +754,7 @@ public void SerializeValue( BinaryWriter writer, Type fieldType, object fieldDat } } - public void AppendToWriter( BinaryWriter writer, ref List> additionalData, ref int addtDataIndex, Type parent, UInt32 listEnding = 0xAAAAAA01 ) { + public void AppendToWriter( BinaryWriter writer, ref List> additionalData, ref int addtDataIndex, Type parent, UInt32 listEnding = 0xAAAAAA01 ) { long templatePosition = writer.BaseStream.Position; //Logger.LogDebug( $"[C] writing {GetType().Name} to offset 0x{templatePosition:X} (parent: {parent.Name})" ); var type = GetType(); @@ -777,7 +777,7 @@ public void AppendToWriter( BinaryWriter writer, ref List> a } } - public void SerializeGenericList( BinaryWriter writer, IList list, long listHeaderPosition, ref List> additionalData, int addtDataIndex, UInt32 listEnding ) + public void SerializeGenericList( BinaryWriter writer, IList list, long listHeaderPosition, ref List> additionalData, int addtDataIndex, UInt32 listEnding ) // This serialises a List of NMSTemplate objects { writer.Align( 0x8, list.GetType().Name ); // Make sure that all c~ names are offset at 0x8. // make rel to listHeaderPosition? @@ -814,7 +814,7 @@ public void SerializeGenericList( BinaryWriter writer, IList list, long listHead entryOffsetNamePairs.Add( new KeyValuePair( writer.BaseStream.Position, entryName) ); var template = (NMSTemplate) entry; - var listObjects = new List>(); // new list of objects so that this data is serialised first + var listObjects = new List>(); // new list of objects so that this data is serialised first var addtData = new Dictionary(); //Logger.LogDebug( $"[C] writing {template.GetType().Name} to offset 0x{writer.BaseStream.Position:X}" ); // pass the new listObject object in place of additionalData so that this branch is serialised before the whole layer @@ -882,7 +882,7 @@ public void SerializeGenericList( BinaryWriter writer, IList list, long listHead writer.BaseStream.Position = dataEndOffset; } - public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosition, ref List> additionalData, int addtDataIndex, UInt32 listEnding = (UInt32) 0xAAAAAA01 ) { + public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosition, ref List> additionalData, int addtDataIndex, UInt32 listEnding = (UInt32) 0xAAAAAA01 ) { // first thing we want to do is align the writer with the location of the first element of the list if ( list.Count != 0 ) { writer.Align( AlignOf(list[0].GetType()), list[0].GetType().Name ); @@ -917,7 +917,7 @@ public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosit public byte[] SerializeBytes() { using ( var stream = new MemoryStream() ) using ( var writer = new BinaryWriter( stream, Encoding.ASCII ) ) { - var additionalData = new List>(); + var additionalData = new List>(); UInt32 listEnding = 0xAAAAAA01; @@ -991,6 +991,11 @@ public byte[] SerializeBytes() { } else if ( data.Item2.GetType() == typeof( byte[] ) ) { // write the offset in the list header + // The 3rd item in the tuple is the alignment override. + // 0 indicates no override, but a non-zero value can be used to force an alignment. + if (data.Item3 > 0) { + writer.Align(data.Item3, data.Item2.GetType().Name); + } long dataPosition = writer.BaseStream.Position; writer.BaseStream.Position = data.Item1; writer.Write( dataPosition - data.Item1 ); @@ -1551,7 +1556,7 @@ public virtual object CustomDeserialize( BinaryReader reader, Type field, NMSAtt return null; } - public virtual bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) + public virtual bool CustomSerialize(BinaryWriter writer, Type field, object fieldData, NMSAttribute settings, FieldInfo fieldInfo, ref List> additionalData, ref int addtDataIndex) { return false; }