From bdede8c3ed9b1ebe0ff41ab52c16487472529fcf Mon Sep 17 00:00:00 2001 From: GreemDev Date: Fri, 20 Feb 2026 20:38:07 -0600 Subject: [PATCH 1/2] Put some compile guards on more debug logging --- libMBIN/Source/Template/NMSTemplate.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libMBIN/Source/Template/NMSTemplate.cs b/libMBIN/Source/Template/NMSTemplate.cs index 2e8e9ceba..ef3086969 100644 --- a/libMBIN/Source/Template/NMSTemplate.cs +++ b/libMBIN/Source/Template/NMSTemplate.cs @@ -909,7 +909,9 @@ public void SerializeValue( public void AppendToWriter( BinaryWriter writer, ref List> 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?) @@ -963,7 +965,9 @@ public void SerializeGenericList( BinaryWriter writer, IList list, long listHead var template = (NMSTemplate) entry; var listObjects = new List>(); // new list of objects so that this data is serialised first var addtData = new Dictionary(); + #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++ ) { @@ -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 ); } } @@ -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; From 61cc1a4f8899ac32109f2396749a98f048385bec Mon Sep 17 00:00:00 2001 From: GreemDev Date: Fri, 20 Feb 2026 20:40:05 -0600 Subject: [PATCH 2/2] comment (not remove) debug log in Align extension --- libMBIN/Source/Common/BinaryStreamExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libMBIN/Source/Common/BinaryStreamExtensions.cs b/libMBIN/Source/Common/BinaryStreamExtensions.cs index 5e5594ba8..2c7367cf8 100644 --- a/libMBIN/Source/Common/BinaryStreamExtensions.cs +++ b/libMBIN/Source/Common/BinaryStreamExtensions.cs @@ -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}" ); } }