1. Mathias Panzenböck
  2. unvpk

Commits

Mathias Panzenböck  committed c45a403

guessed vpk version 2 support

  • Participants
  • Parent commits 2741321
  • Branches default

Comments (0)

Files changed (4)

File CMakeLists.txt

View file
   endif()
 elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
   # Update if necessary
-  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Wno-long-long -O2")
+  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -Werror -Wno-long-long -O2")
 endif()
 
 # Offsets in VPK archives are uint32_t but off_t might be int32_t on 32bit

File libvpk/include/vpk/package.h

View file
 	class Package : public Dir {
 	public:
 		Package(Handler *handler = 0) :
-			Dir(""), m_version(0), m_dataoff(0), m_srcdir("."), m_handler(handler) {}
+			Dir(""), m_version(0), m_dataoff(0), m_pkgHashSize(0), m_extraSize(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)); }
 		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; }
 		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 fileerror(const std::string &msg, const std::string &path)    const { return error(msg, path, &Handler::fileerror); }
 		bool archiveerror(const std::string &msg, const std::string &path) const { return error(msg, path, &Handler::archiveerror); }
 		bool filtererror(const std::string &msg, const std::string &path)  const { return error(msg, path, &Handler::filtererror); }
-	
+
 		bool error(const std::string &msg, const std::string &path, ErrorMethod handler) const;
 		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;
 		std::string  m_srcdir;
 		std::string  m_dirfile;
 		Handler     *m_handler;

File libvpk/src/package.cpp

View file
 void Vpk::Package::read(FileIO &io) {
 	size_t headerSize = 0;
 	unsigned int indexSize = 0;
+
+	m_version = 0;
+	m_dataoff = 0;
+	m_pkgHashSize = 0;
+	m_extraSize   = 0;
+
 	if (io.readLU32() != 0x55AA1234) {
 		io.seek(-4, FileIO::CUR);
 	}
 		m_version  = io.readLU32();
 		indexSize  = io.readLU32();
 		headerSize = io.tell();
-		m_dataoff  = indexSize + headerSize;
+		m_dataoff  = indexSize + headerSize; // + footerSize?
 
-		if (m_version != 1) {
+		if (m_version == 2) {
+			io.readLU32(); // UNKNOWN
+			m_pkgHashSize = io.readLU32();
+			m_extraSize   = io.readLU32();
+			io.readLU32(); // UNKNOWN
+		}
+		else if (m_version != 1) {
 			throw FileFormatError((boost::format("unsupported VPK version: %u")
 				% m_version).str());
 		}

File unvpk/src/main.cpp

View file
 		bool printall) {
 	Stats stats;
 
-	stats[0x7fff].coverage().add(0, package.dataoff());
+	Coverage &pkgcov = stats[0x7fff].coverage();
+	pkgcov.add(0, package.dataoff());
+	// TODO: footer?
 
 	std::string prefix = tolower(package.name());
 	prefix += '_';