Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libMBIN/Source/Common/BinaryStreamExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void Align( this BinaryWriter writer, int alignBy, string name, by
} else {
writer.Write( new byte[alignBy - mod] );
}
NMSTemplate.DebugLogTemplate( $"[C] aligned {name} to offset 0x{writer.BaseStream.Position:X}" );
//NMSTemplate.DebugLogTemplate( $"[C] aligned {name} to offset 0x{writer.BaseStream.Position:X}" );
}
}

Expand Down
8 changes: 8 additions & 0 deletions libMBIN/Source/Template/NMSTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,9 @@ public void SerializeValue(

public void AppendToWriter( BinaryWriter writer, ref List<Tuple<long, object>> additionalData, ref int addtDataIndex, Type parent, UInt32 listEnding = 0xAAAAAA01, byte paddingByte = 0 ) {
long templatePosition = writer.BaseStream.Position;
#if DEBUG_TEMPLATE
Logger.LogDebug( $"[C] writing {GetType().Name} to offset 0x{templatePosition:X} (parent: {parent.Name})" );
#endif
var type = GetType();
var fields = type.GetFields().OrderBy( field => field.MetadataToken ); // hack to get fields in order of declaration (todo: use something less hacky, this might break mono?)

Expand Down Expand Up @@ -963,7 +965,9 @@ public void SerializeGenericList( BinaryWriter writer, IList list, long listHead
var template = (NMSTemplate) entry;
var listObjects = new List<Tuple<long, object>>(); // new list of objects so that this data is serialised first
var addtData = new Dictionary<long, object>();
#if DEBUG_TEMPLATE
Logger.LogDebug( $"[C] writing {template.GetType().Name} to offset 0x{writer.BaseStream.Position:X}" );
#endif
// pass the new listObject object in place of additionalData so that this branch is serialised before the whole layer
template.AppendToWriter( writer, ref listObjects, ref addtDataIndexThis, GetType(), paddingByte: paddingByte );
for ( int i = 0; i < listObjects.Count; i++ ) {
Expand Down Expand Up @@ -1062,7 +1066,9 @@ public void SerializeList( BinaryWriter writer, IList list, long listHeaderPosit
int addtDataIndexThis = addtDataIndex;

foreach ( var entry in list ) {
#if DEBUG_TEMPLATE
DebugLogTemplate( $"[C] writing {entry.GetType().Name} to offset 0x{writer.BaseStream.Position:X}" );
#endif
SerializeValue( writer, entry.GetType(), entry, null, null, ref additionalData, ref addtDataIndexThis, listEnding, paddingByte );
}
}
Expand Down Expand Up @@ -1125,7 +1131,9 @@ public byte[] SerializeBytes() {

if ( typeof(INMSVariableLengthString).IsAssignableFrom(data.Item2.GetType()) ) {
var str = (INMSVariableLengthString) data.Item2;
#if DEBUG_TEMPLATE
Logger.LogDebug($"[C+] Writing {str.StringValue()} to 0x{writer.BaseStream.Position:X}");
#endif
long stringPos = writer.BaseStream.Position;
writer.WriteString(str.StringValue(), Encoding.UTF8, null, true, paddingByte);
long stringEndPos = writer.BaseStream.Position;
Expand Down
Loading