now all MODL chunks from MSH2 are saved,

searching only subchunks and not all behind,
finding corrupted size information and trying to continue
This commit is contained in:
Anakin 2016-10-10 12:34:01 +02:00
parent 4f1ff65f71
commit 59446f088f
2 changed files with 27 additions and 10 deletions

View File

@ -2,10 +2,11 @@
#include <vector> #include <vector>
#include <list> #include <list>
#include <fstream> #include <fstream>
//#include <windows.h>
struct chunkHeader { struct chunkHeader {
char name[5]; char name[5];
int size; std::uint32_t size;
std::streampos position; std::streampos position;
}; };
@ -18,12 +19,12 @@ public:
private: private:
std::list<chunkHeader*> lChunkMsh2; std::list<chunkHeader*> lChunkMsh2;
std::list<chunkHeader*> lChunkModl; std::list<std::list<chunkHeader*>*> lChunkModls;
std::fstream fsMesh; std::fstream fsMesh;
private: private:
void loadChunks(std::list<chunkHeader*> &destination, std::streampos start, const char end[5]); void loadChunks(std::list<chunkHeader*> &destination, std::streampos start, const std::uint32_t end);
public: public:

View File

@ -14,6 +14,7 @@ Object::Object(const char* path)
if (!fsMesh.is_open()) if (!fsMesh.is_open())
throw std::invalid_argument(std::string("file not found: ") += path); throw std::invalid_argument(std::string("file not found: ") += path);
// jump into msh2 todo: search for MSH2 if there is a shadowvolume
fsMesh.seekg(8); fsMesh.seekg(8);
char tempChunkName[5] = { 0 }; char tempChunkName[5] = { 0 };
fsMesh.read(reinterpret_cast<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1); fsMesh.read(reinterpret_cast<char*>(&tempChunkName[0]), sizeof(tempChunkName) - 1);
@ -21,15 +22,20 @@ Object::Object(const char* path)
if (strcmp(tempChunkName, "MSH2")) if (strcmp(tempChunkName, "MSH2"))
throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName); throw std::invalid_argument(std::string("corrupted file MSH2 expected instead of ") += tempChunkName);
fsMesh.seekg(4, std::ios_base::cur); std::uint32_t tempSize;
fsMesh.read(reinterpret_cast<char*>(&tempSize), sizeof(tempSize));
loadChunks(lChunkMsh2, fsMesh.tellg(), "CL1L"); // get all sub chunks from MSH2
loadChunks(lChunkMsh2, fsMesh.tellg(), tempSize);
// search for all MODL Chunks
for (std::list<chunkHeader*>::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++) for (std::list<chunkHeader*>::iterator it = lChunkMsh2.begin(); it != lChunkMsh2.end(); it++)
{ {
if (!strcmp("MODL", (*it)->name)) if (!strcmp("MODL", (*it)->name))
{ {
loadChunks(lChunkModl, (*it)->position, "CL1L"); std::list<chunkHeader*>* tempModlList = new std::list<chunkHeader*>;
loadChunks(*tempModlList, (*it)->position, (*it)->size);
lChunkModls.push_back(tempModlList);
} }
} }
@ -47,9 +53,9 @@ Object::~Object()
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// private functions // private functions
void Object::loadChunks(std::list<chunkHeader*>& destination, std::streampos start, const char end[5]) void Object::loadChunks(std::list<chunkHeader*>& destination, std::streampos start, const std::uint32_t end)
{ {
// Jump into Mesh2 // jump to first chunk
fsMesh.seekg(start); fsMesh.seekg(start);
do do
@ -64,9 +70,19 @@ void Object::loadChunks(std::list<chunkHeader*>& destination, std::streampos sta
fsMesh.seekg(tempHeader->size, std::ios_base::cur); fsMesh.seekg(tempHeader->size, std::ios_base::cur);
if (!std::strcmp(tempHeader->name, end)) // reached end
if (fsMesh.tellg() - start == end)
break; break;
} while (fsMesh.good());
// error. Maybe the size information is corrupted
if (!fsMesh.good())
{
std::cout << "WARNING: corrupted file. Trying to continue" << std::endl;
fsMesh.clear();
break;
}
} while (true);
std::cout << "got all chunks, totaly found: " << destination.size() << std::endl; std::cout << "got all chunks, totaly found: " << destination.size() << std::endl;