diff --git a/NIF_Blocks.cpp b/NIF_Blocks.cpp index 10cd86d08a4ae18fefc39d3da9962f1917fd8fb1..3ebaee3cc4360dcc9295ce9f4559f159c68b67d5 100644 --- a/NIF_Blocks.cpp +++ b/NIF_Blocks.cpp @@ -210,7 +210,8 @@ list<blk_ref> ABlock::GetLinks() { vector<attr_ref>::iterator it; for ( it = _attr_vect.begin(); it != _attr_vect.end(); ++it ) { if ( (*it)->HasLinks() == true ) { - links.merge( list<blk_ref>(*it) ); + list<blk_ref> link_list = (*it)->asLinkList(); + links.merge( link_list ); } } @@ -2418,4 +2419,4 @@ void UnknownMixIn::Write( ofstream& out ) { //} //cout << dec << setfill(' '); -//delete [] data; \ No newline at end of file +//delete [] data; diff --git a/NIF_Blocks.h b/NIF_Blocks.h index a2e8b08283e24a62348b20a5add14859a177a7cc..107766df48d44ad045895606ab3b7642445e0615 100644 --- a/NIF_Blocks.h +++ b/NIF_Blocks.h @@ -1332,7 +1332,7 @@ public: } void asString( ostream & out ) { out << ABlock::asString(); - out << UnknownMixIn::asString; + out << UnknownMixIn::asString(); } string GetBlockType() { return UnknownMixIn::GetBlockType(); } }; @@ -1488,5 +1488,4 @@ public: // string GetBlockType() { return "NiParticleSystemController"; } //}; - -#endif // TAH_NIF_LIB_NIF_BLOCKS_H \ No newline at end of file +#endif // TAH_NIF_LIB_NIF_BLOCKS_H diff --git a/NIF_IO.cpp b/NIF_IO.cpp index 815dc4834c6d618915d5f63e7fea9808b2ff0a45..974048d39f850a4a77f43befb74f342fabe5b4b6 100644 --- a/NIF_IO.cpp +++ b/NIF_IO.cpp @@ -300,4 +300,39 @@ ostream & operator<<(ostream & lh, nifIndex & rh) { lh << "None"; } return lh; -} \ No newline at end of file +} + +ostream & operator<<(ostream & lh, Str & rh) { + //Fix string + char * s = new char[rh._n + 1]; + strncpy(s, rh._c, rh._n); + s[rh._n] = 0; + lh << s; + delete [] s; + return lh; +} + +ostream & operator<<(ostream & lh, Hex & rh) { + return lh << dec << rh._n << " (0x" << hex << uppercase << rh._n << ")" << dec; +} + +ostream & operator<<(ostream & lh, Index & rh) { + if (int(rh._n) != -1) + return lh << "Block " << rh._n; + else + return lh << "None"; +} + +ostream & operator<<(ostream & lh, Bin & rh) { + uint x = rh._n; + for (uint i = 0; i < rh._w; i++) { + if((x & 0x80) !=0) { + lh << "1"; + } + else { + lh << "0"; + } + x <<= 1; + } + return lh; +} diff --git a/NIF_IO.h b/NIF_IO.h index 906319d743520d3032b972f998ddefdcabf9c2ed..1860fefddb2d897fd45f7671f6111f977c947564 100644 --- a/NIF_IO.h +++ b/NIF_IO.h @@ -136,15 +136,7 @@ int BlockSearch( ifstream& in ); class Str { public: Str(const char * c, int n) { _c = c; _n = n; } - friend ostream & operator<<(ostream & lh, Str & rh) { - //Fix string - char * s = new char[rh._n + 1]; - strncpy(s, rh._c, rh._n); - s[rh._n] = 0; - lh << s; - delete [] s; - return lh; - } + friend ostream & operator<<(ostream & lh, Str & rh); private: const char * _c; uint _n; @@ -155,9 +147,7 @@ public: Hex(uint & n) { _n = n; } Hex(ushort & n) { _n = uint(n); } Hex(byte & n) { _n = uint(n); } - friend ostream & operator<<(ostream & lh, Hex & rh) { - return lh << dec << rh._n << " (0x" << hex << uppercase << rh._n << ")" << dec; - } + friend ostream & operator<<(ostream & lh, Hex & rh); private: uint _n; }; @@ -167,12 +157,7 @@ public: Index(uint & n) { _n = n; } Index(ushort & n) { _n = uint(n); } Index(byte & n) { _n = uint(n); } - friend ostream & operator<<(ostream & lh, Index & rh) { - if (int(rh._n) != -1) - return lh << "Block " << rh._n; - else - return lh << "None"; - } + friend ostream & operator<<(ostream & lh, Index & rh); private: uint _n; }; @@ -182,19 +167,7 @@ public: Bin(uint & n) { _n = n; _w = 32; } Bin(ushort & n) {_n = uint(n); _w = 16; } Bin(byte & n) { _n = uint(n); _w = 8; } - friend ostream & operator<<(ostream & lh, Bin & rh) { - uint x = rh._n; - for (uint i = 0; i < rh._w; i++) { - if((x & 0x80) !=0) { - lh << "1"; - } - else { - lh << "0"; - } - x <<= 1; - } - return lh; - } + friend ostream & operator<<(ostream & lh, Bin & rh); private: uint _n; uint _w; diff --git a/nif_attrs.h b/nif_attrs.h index b5a8a63d97ee83b7578be471fe5bb5751ec2a28a..17b12d3ec09319f088d5b20b41ea63958b62e4b6 100644 --- a/nif_attrs.h +++ b/nif_attrs.h @@ -1313,4 +1313,4 @@ private: int original_root; }; -#endif \ No newline at end of file +#endif diff --git a/nif_math.cpp b/nif_math.cpp index a46241c41c5a96c00f2af74f214b24fa9b201447..41a5948a0666366a4c16a541a263ebfefde9c41c 100644 --- a/nif_math.cpp +++ b/nif_math.cpp @@ -289,4 +289,4 @@ void QuatToEuler( Quaternion & quat, ostream & out ) { << " Attitude: " << a << endl << " Bank: " << b << endl; -} \ No newline at end of file +} diff --git a/niflib.cpp b/niflib.cpp index 326837515dd891e22ef3fd1d7e75a47c637615fb..63a67d7b2c7934272341d65156dbe4100ff1db5d 100644 --- a/niflib.cpp +++ b/niflib.cpp @@ -173,7 +173,8 @@ blk_ref CreateBlock( string block_type ) { //Reads the given file by file name and returns a reference to the root block blk_ref ReadNifTree( string file_name ) { //Read block list - return FindRoot( ReadNifList( file_name ) ); + vector<blk_ref> blocks = ReadNifList( file_name ); + return FindRoot( blocks ); } blk_ref FindRoot( vector<blk_ref> & blocks ) { @@ -248,7 +249,8 @@ vector<blk_ref> ReadNifList( string file_name ) { in.read( blockName, blockNameLength ); blockName[blockNameLength] = 0; if ( (blockName[0] != 'N' || blockName[1] != 'i') && (blockName[0] != 'R' || blockName[1] != 'o') && (blockName[0] != 'A' || blockName[1] != 'v')) { - cout << "ERROR! Bad block position. Invalid Name: " << Str(blockName, blockNameLength) << "\a" << endl; + Str block_name(blockName, blockNameLength); + cout << "ERROR! Bad block position. Invalid Name: " << block_name << "\a" << endl; cout << "====[ " << file_name << " | Block " << i - 1 << " | " << blocks[i - 1]->GetBlockType() << " ]====" << endl; cout << blocks[i - 1]->asString(); throw runtime_error("Read failue - Bad block position"); diff --git a/pyniflib.i b/pyniflib.i index 9ff41d841e3f7b9b7bc124528e9ed79b69f33b66..d172999b03cc3c0ceb5203f1b364057bce862e09 100644 --- a/pyniflib.i +++ b/pyniflib.i @@ -61,6 +61,7 @@ struct Key { }; %template(vector_float) std::vector<float>; +%template(vector_blk_ref) std::vector<attr_ref>; %template(vector_blk_ref) std::vector<blk_ref>; %template(vector_Vector3) std::vector<Vector3>; %template(vector_Color) std::vector<Color>;