From feb96f1eb6f05e1a569e548f9270daff05f1e7b4 Mon Sep 17 00:00:00 2001
From: Amorilia <amorilia@users.sourceforge.net>
Date: Tue, 30 May 2006 02:31:43 +0000
Subject: [PATCH] Made niflib more verbose: prints blocks as it reads the NIF
 file (helps identifying buggy blocks); fixed output of bytes.

---
 NIF_IO.cpp |  5 +++++
 NIF_IO.h   |  5 ++++-
 niflib.cpp | 47 +++++++++++++++++++++++++++--------------------
 3 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/NIF_IO.cpp b/NIF_IO.cpp
index 39881899..f74e1438 100644
--- a/NIF_IO.cpp
+++ b/NIF_IO.cpp
@@ -625,3 +625,8 @@ void StreamQuatKey( Key<Quaternion> const & key, ostream& file, KeyType type ) {
 		WriteFloat( key.continuity, file);
 	}
 }
+
+//Byte
+ostream & operator<<( ostream & out, byte const & val ) {
+	return out << uint(val);
+}
diff --git a/NIF_IO.h b/NIF_IO.h
index e632404c..027fbcb3 100644
--- a/NIF_IO.h
+++ b/NIF_IO.h
@@ -52,7 +52,7 @@ enum ExportOptions {
 };
 
 
-//--Non-mathamatical Basic Types--//
+//--Non-mathematical Basic Types--//
 
 typedef unsigned char	byte;
 typedef unsigned short	ushort;
@@ -434,4 +434,7 @@ void StreamQuatKey( Key<Quaternion> const & key, ostream& file, uint version, Ke
 //a debug string for information that is not understood
 string HexString( const byte * src, uint len );
 
+//Byte
+ostream & operator<<( ostream & out, byte const & val );
+
 #endif
diff --git a/niflib.cpp b/niflib.cpp
index 6baf9f3f..21b9aff4 100644
--- a/niflib.cpp
+++ b/niflib.cpp
@@ -1,6 +1,8 @@
 /* Copyright (c) 2006, NIF File Format Library and Tools
 All rights reserved.  Please see niflib.h for licence. */
 
+#define DEBUG // this will produce lot's of output
+
 #include "niflib.h"
 #include "obj/NiAVObject.h"
 #include "obj/NiNode.h"
@@ -146,9 +148,9 @@ vector<NiObjectRef> ReadNifList( istream & in ) {
 	uint version = ReadUInt( in );
 
 	//There is an unknown Byte here from version 20.0.0.4 on
-	byte unknownByte;
+	byte endianType;
 	if ( version >= VER_20_0_0_4 ) {
-		unknownByte = ReadByte( in );
+		endianType = ReadByte( in );
 	}
 
 	//There is an Unknown Int here from version 10.1.0.0 on
@@ -185,35 +187,40 @@ vector<NiObjectRef> ReadNifList( istream & in ) {
 			blockTypeIndex[i] = ReadUShort( in );
 		}
 
-		//uint unknownInt2 =
+		uint unknownInt2 =
 		ReadUInt( in );
 
-		////Output
+		//Output
+#ifdef DEBUG
 		cout << endl << endl 
 			 << "====[ " << "File Header ]====" << endl
 			 << "Header:  " << header_string << endl
 			 << "Version:  " << version << endl
+			 << "Endian Type:  " << endianType << endl
 			 << "User Version:  " << userVersion << endl
-			 << "Number of Blocks: " << int(numBlocks) << endl
+			 << "Number of Blocks: " << numBlocks << endl
 			 << "Block Types:  " << uint(blockTypes.size()) << endl;
 
-		//for ( uint i = 0; i < blockTypes.size(); ++i ) {
-		//	cout << "   " << i << ":  " << blockTypes[i] << endl;
-		//}
+		for ( uint i = 0; i < blockTypes.size(); ++i ) {
+			cout << "   " << i << ":  " << blockTypes[i] << endl;
+		}
 
-		//cout << "Block Type Indices:  " << numBlocks << endl;
-		//for ( uint i = 0; i < blockTypeIndex.size(); ++i ) {
-		//	cout << "   " << i + 1 << ":  " << blockTypeIndex[i] << endl;
-		//}
+		cout << "Block Type Indices:  " << numBlocks << endl;
+		for ( uint i = 0; i < blockTypeIndex.size(); ++i ) {
+			cout << "   " << i + 1 << ":  " << blockTypeIndex[i] << "(" << blockTypes[blockTypeIndex[i]] << ")" << endl;
+		}
 
-		//cout << "Unknown Int 2:  " << unknownInt2 << endl;
+		cout << "Unknown Int 2:  " << unknownInt2 << endl;
+#endif
 	} else {
-		////Output
-		//cout << endl << endl 
-		//	<< "====[ " << "File Header ]====" << endl
-		//	<< "Header:  " << header_string << endl
-		//	<< "Version:  " << Hex(version) << endl
-		//	<< "Number of Blocks: " << int(numBlocks) << endl;
+#ifdef DEBUG
+		//Output
+		cout << endl << endl 
+			<< "====[ " << "File Header ]====" << endl
+			<< "Header:  " << header_string << endl
+			<< "Version:  " << version << endl
+			<< "Number of Blocks: " << numBlocks << endl;
+#endif
 	}
 
 
@@ -288,7 +295,7 @@ vector<NiObjectRef> ReadNifList( istream & in ) {
 		//blocks[i]->SetBlockNum(i);
 		blocks[i]->Read( in, link_stack, version );
 
-		//cout << endl << blocks[i]->asString() << endl;
+		cout << endl << blocks[i]->asString() << endl;
 	}
 
 	//cout << endl;
-- 
GitLab