From a0fdef2e57cdf66ad1f24162b7e4ba1a7aa646a3 Mon Sep 17 00:00:00 2001 From: Shon Ferguson <shonferg@users.sourceforge.net> Date: Sun, 13 Nov 2005 23:52:15 +0000 Subject: [PATCH] Updated the WriteNifTree function to write the correct version string and hex number for the version requested. Still doesn't support the new header layout. --- NIF_Blocks.cpp | 26 +++++++++++++------------- NIF_Blocks.h | 8 ++++---- NIF_IO.cpp | 2 +- nif_attrs.h | 4 ++-- niflib.cpp | 20 ++++++++++++++++---- niflib.h | 10 ++++++++-- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/NIF_Blocks.cpp b/NIF_Blocks.cpp index f6ca0039..5d3e7e68 100644 --- a/NIF_Blocks.cpp +++ b/NIF_Blocks.cpp @@ -577,7 +577,7 @@ void AShapeData::Read( ifstream& in, unsigned int version ){ /// numTexSets up here up after from version 10.0.1.0 on short numTexSets; - if ( version >= 0x0A000100 ) { + if ( version >= VER_10_0_1_0 ) { numTexSets = ReadUShort( in ); } @@ -605,12 +605,12 @@ void AShapeData::Read( ifstream& in, unsigned int version ){ } } // numTexSets down here up to version 4.2.2.0 - if ( version <= 0x04020200 ) { + if ( version <= VER_4_2_2_0 ) { numTexSets = ReadUShort( in ); } // hasUVs does not exist after version 4.0.0.2 bool hasUVs = true; - if ( version <= 0x04000002 ) { + if ( version <= VER_4_0_0_2 ) { hasUVs = ReadBool( in, version ); } if ( numTexSets > 0 && hasUVs != 0 ){ @@ -627,7 +627,7 @@ void AShapeData::Read( ifstream& in, unsigned int version ){ //Unknown Short here from version 10.0.1.0 on //Just read it and throw it away for now - if ( version >= 0x0A000100 ) { + if ( version >= VER_10_0_1_0) { ReadUShort( in ); } } @@ -826,14 +826,14 @@ void AParticlesData::Read( ifstream& in, unsigned int version ) { AShapeData::Read( in, version ); //numActive exists up to version 4.0.0.2 - if ( version <= 0x04000002 ) { + if ( version <= VER_4_0_0_2 ) { numActive = ReadUShort( in ); } GetAttr("Active Radius")->Read( in, version ); //numValid exists up to version 4.0.0.2 - if ( version <= 0x04000002 ) { + if ( version <= VER_4_0_0_2 ) { numValid = ReadUShort( in ); } @@ -853,14 +853,14 @@ void AParticlesData::Write( ofstream& out, unsigned int version ) { AShapeData::Write( out, version ); //numActive exists up to version 4.0.0.2 - if ( version <= 0x04000002 ) { + if ( version <= VER_4_0_0_2 ) { WriteUShort( numActive, out ); } GetAttr("Active Radius")->Write( out, version ); //numValid exists up to version 4.0.0.2 - if ( version <= 0x04000002 ) { + if ( version <= VER_4_0_0_2 ) { WriteUShort( numValid, out ); } @@ -1220,7 +1220,7 @@ void NiSkinData::Read( ifstream& in, unsigned int version ) { int boneCount = ReadUInt( in ); unknownInt = ReadUInt( in ); //unknownByte exists from version 4.2.1.0 on - if ( version >= 0x04020100 ) { + if ( version >= VER_4_2_1_0 ) { unknownByte = ReadByte( in ); } bones.resize(boneCount); @@ -1257,7 +1257,7 @@ void NiSkinData::Write( ofstream& out, unsigned int version ) { WriteUInt(short(bone_map.size()), out); WriteUInt(unknownInt, out); //unknownByte exists from version 4.2.1.0 on - if ( version >= 0x04020100 ) { + if ( version >= VER_4_2_1_0) { WriteByte( unknownByte, out ); } @@ -2142,7 +2142,7 @@ void NiStringExtraData::Read( ifstream& in, unsigned int version ) { } //Up to version 4.2.2.0, read bytes remaining but don't bother to store it - if ( version <= 0x04020200 ) { + if ( version <= VER_4_2_2_0 ) { ReadUInt( in ); } @@ -2160,8 +2160,8 @@ void NiStringExtraData::Write( ofstream& out, unsigned int version ) { attr_ref string_data = GetAttr("String Data"); - //Up to version 4.2.2.0, Write Bytes Remaining - length of string + 4 - if ( version <= 0x04020200 ) { + //Up to version 4.2.2.0, Write Bytes Remaining; length of string + 4 + if ( version <= VER_4_2_2_0 ) { WriteUInt( uint(string_data->asString().length()) + 4, out ); } diff --git a/NIF_Blocks.h b/NIF_Blocks.h index 775f1d6b..ef594906 100644 --- a/NIF_Blocks.h +++ b/NIF_Blocks.h @@ -215,8 +215,8 @@ class AExtraData : public AData { public: AExtraData() { _namable = true; - _first_named_ver = 0x0A000100; //10.0.1.0 - AddAttr( attr_link, "Next Extra Data", 0, 0x04020200 ); + _first_named_ver = VER_10_0_1_0; //10.0.1.0 + AddAttr( attr_link, "Next Extra Data", 0, VER_4_2_2_0 ); } ~AExtraData() {}; }; @@ -569,7 +569,7 @@ class AParticlesData : public AShapeData { public: AParticlesData() { AddAttr( attr_float, "Active Radius" ); - AddAttr( attr_short, "Unknown Short", 0x0401000C ); + AddAttr( attr_short, "Unknown Short", VER_4_1_0_12 ); } ~AParticlesData() {} void Read( ifstream& in, unsigned int version ); @@ -1307,7 +1307,7 @@ public: class NiTextKeyExtraData : public AExtraData, public ITextKeyExtraData { public: NiTextKeyExtraData() { - AddAttr( attr_int, "Unknown Int", 0, 0x04020200 ); + AddAttr( attr_int, "Unknown Int", 0, VER_4_2_2_0 ); } ~NiTextKeyExtraData() {} diff --git a/NIF_IO.cpp b/NIF_IO.cpp index 1a15b0a4..0bd87225 100644 --- a/NIF_IO.cpp +++ b/NIF_IO.cpp @@ -232,7 +232,7 @@ string ReadString( ifstream &in ) { } bool ReadBool( ifstream &in, unsigned int version ) { - if ( version < 0x04010001 ) { + if ( version <= 0x04010001 ) { //Bools are stored as integers before version 4.1.0.1 return (ReadUInt( in ) != 0); } else { diff --git a/nif_attrs.h b/nif_attrs.h index 8033dd88..c613606a 100644 --- a/nif_attrs.h +++ b/nif_attrs.h @@ -855,7 +855,7 @@ public: data.PS2_K = ReadUShort( in ); //unknownShort exists up to version 4.1.0.12 - if ( version <= 0x0401000C ) { + if ( version <= VER_4_1_0_12) { data.unknownShort = ReadUShort( in ); } @@ -881,7 +881,7 @@ public: WriteUShort( data.PS2_L, out ); WriteUShort( data.PS2_K, out ); //unknownShort exists up to version 4.1.0.12 - if ( version <= 0x0401000C ) { + if ( version <= VER_4_1_0_12 ) { WriteUShort( data.unknownShort, out ); } if ( _isBumpMap ) { diff --git a/niflib.cpp b/niflib.cpp index 1a9bb260..c9036f78 100644 --- a/niflib.cpp +++ b/niflib.cpp @@ -126,7 +126,7 @@ vector<blk_ref> ReadNifList( string file_name ) { //There is an unknownInt here from version 10.1.0.0 on uint unknownInt1; - if ( version >= 0x0A010000 ) { + if ( version >= VER_10_1_0_0 ) { unknownInt1 = ReadUInt( in ); } @@ -331,10 +331,22 @@ void WriteNifTree( string file_name, blk_ref & root_block, unsigned int version ofstream out( file_name.c_str(), ofstream::binary ); //--Write Header--// - out.write( "NetImmerse File Format, Version 4.0.0.2 \n", HEADER_STRING_LEN ); + //Version 10.0.1.0 is the last known to use the name NetImmerse + stringstream header_string; + if ( version <= VER_10_0_1_0 ) { + header_string << "NetImmerse File Format, Version "; + } else { + header_string << "Gamebryo File Format, Version "; + } + char * byte_ver = (char*)&version; + int int_ver[4] = { byte_ver[3], byte_ver[2], byte_ver[1], byte_ver[0] }; + + + header_string << int_ver[3] << "." << int_ver[2] << "." << int_ver[1] << "." << int_ver[0] << " "; + + out << header_string.str(); WriteByte( 10, out ); // Unknown Byte = 10 - char ver[] = {2,0,0,4}; // Version = 4.0.0.2 for Morrowind - out.write( ver, 4 ); + WriteUInt( version, out ); WriteUInt( uint(blk_list.size()), out ); //Number of blocks //--WriteBlocks--// diff --git a/niflib.h b/niflib.h index bd0d5ed9..1706e550 100644 --- a/niflib.h +++ b/niflib.h @@ -68,7 +68,6 @@ struct ConditionalInt; struct SkinWeight; //--Constants--// -const unsigned int HEADER_STRING_LEN = 39; //Interface IDs const int ID_TRI_SHAPE_DATA = 0; @@ -91,7 +90,14 @@ const enum AttrTypes { //NIF Versions const int VER_4_0_0_2 = 0x04000002; +const int VER_4_1_0_12 = 0x0401000C; const int VER_4_2_0_2 = 0x04020002; +const int VER_4_2_1_0 = 0x04020100; +const int VER_4_2_2_0 = 0x04020200; +const int VER_10_0_1_0 = 0x0A000100; +const int VER_10_1_0_0 = 0x0A010000; +const int VER_10_2_0_0 = 0x0A020000; +const int VER_20_0_0_4 = 0x14000004; #ifndef NULL #define NULL 0 @@ -109,7 +115,7 @@ vector<blk_ref> ReadNifList( string file_name ); blk_ref ReadNifTree( string file_name ); //Writes a valid Nif File given a file name, a pointer to the root block of a file tree -void WriteNifTree( string file_name, blk_ref & root_block, unsigned int version = VER_4_2_0_2 ); +void WriteNifTree( string file_name, blk_ref & root_block, unsigned int version = VER_4_0_0_2 ); ////Returns the NIF spec version of a file, given a file name. //string GetFileVersion(string file_name); -- GitLab