Commits

Mathias Panzenböck committed 9232c58

vpk 2 fixes

Comments (0)

Files changed (4)

 	     0     4  U32   file magic: 0x55AA1234
 	     4     4  U32   version: 2
 	     8     4  U32   index size
-	    12     4  U32   ?
-	    16     4  U32   footer length? extra CRC length?
-	    20     4  U32   extra size?
-	    24     4  U32   ?
+	    12     4  U32   footer offset
+	    16     4  U32   always 0?
+	    20     4  U32   footer size?
+	    24     4  U32   always 48?
 
 #### Index
 Files are grouped by their type (file name extension).
 	 0x0000      1  U32     File magic: 0x55AA1234
 	 0x0004      1  U32     VPK version: 2
 	 0x0008      1  U32     Index size.
-	 0x000C      1  U32     ?
-	 0x0010      1  U32     Footer length? Extra CRC length?
-	 0x0014      1  U32     Extra size?
-	 0x0018      1  U32     ?
+	 0x000C      1  U32     Footer offset.
+	 0x0010      1  U32     Always 0?
+	 0x0014      1  U32     Footer size.
+	 0x0018      1  U32     Always 48?
 
 
 ### Body

libvpk/include/vpk/package.h

 	class Package : public Dir {
 	public:
 		Package(Handler *handler = 0) :
-			Dir(""), m_version(0), m_dataoff(0), m_pkgHashSize(0), m_extraSize(0), m_srcdir("."), m_handler(handler) {}
+			Dir(""), m_version(0), m_dataOffset(0), m_footerOffset(0), m_footerSize(0), m_srcdir("."), m_handler(handler) {}
 
 		void read(const char *path) { read(boost::filesystem::path(path)); }
 		void read(const std::string &path) { read(boost::filesystem::path(path)); }
 		std::string             archiveName(uint16_t index) const;
 		boost::filesystem::path archivePath(uint16_t index) const;
 		unsigned int version() const { return m_version; }
-		unsigned int dataoff() const { return m_dataoff; }
-		unsigned int packageHashSize() const { return m_pkgHashSize; }
-		unsigned int extraSize() const { return m_extraSize; }
+		unsigned int dataoff() const { return m_dataOffset; }
+		unsigned int footerOffset() const { return m_footerOffset; }
+		unsigned int footerSize() const { return m_footerSize; }
 		const std::string &srcdir() const { return m_srcdir; }
 		const std::string &dirfile() const { return m_dirfile; }
 		Node *get(const std::string &path) { return get(path.c_str()); }
 		bool error(const std::exception &exc, const std::string &path, ErrorMethod handler) const;
 
 		unsigned int m_version;
-		unsigned int m_dataoff;
-		unsigned int m_pkgHashSize;
-		unsigned int m_extraSize;
+		unsigned int m_dataOffset;
+		unsigned int m_footerOffset;
+		unsigned int m_footerSize;
 		std::string  m_srcdir;
 		std::string  m_dirfile;
 		Handler     *m_handler;

libvpk/src/package.cpp

 	size_t headerSize = 0;
 	unsigned int indexSize = 0;
 
-	m_version = 0;
-	m_dataoff = 0;
-	m_pkgHashSize = 0;
-	m_extraSize   = 0;
+	m_version      = 0;
+	m_dataOffset   = 0;
+	m_footerOffset = 0;
+	m_footerSize   = 0;
 
 	if (io.readLU32() != 0x55AA1234) {
 		io.seek(-4, FileIO::CUR);
 	}
 	else {
-		m_version  = io.readLU32();
-		indexSize  = io.readLU32();
-		headerSize = io.tell();
-		m_dataoff  = indexSize + headerSize; // + footerSize?
+		m_version    = io.readLU32();
+		indexSize    = io.readLU32();
+		headerSize   = io.tell();
+		m_dataOffset = indexSize + headerSize; // + footerSize?
 
 		if (m_version == 2) {
+			m_footerOffset = io.readLU32();
 			io.readLU32(); // UNKNOWN
-			m_pkgHashSize = io.readLU32();
-			m_extraSize   = io.readLU32();
+			m_footerSize = io.readLU32();
 			io.readLU32(); // UNKNOWN
 		}
 		else if (m_version != 1) {
 	}
 
 	if (m_version == 0) {
-		m_dataoff = io.tell();
+		m_dataOffset = io.tell();
 	}
-	else if (io.tell() != m_dataoff) {
+	else if (m_version == 1 && io.tell() != m_dataOffset) {
 		Exception exc(
 			(boost::format("missmatch between header index size (%u) and real index size (%u)")
 			% indexSize % (io.tell() - headerSize)).str());
 	}
 
 	for (std::vector<File*>::iterator i = dirfiles.begin(); i != dirfiles.end(); ++ i) {
-		(*i)->offset += m_dataoff;
+		(*i)->offset += m_dataOffset;
 	}
 }