Guest User

Wildstar PACK Index File

a guest
Jun 12th, 2013
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.80 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "BinFile.h"
  4.  
  5. #pragma pack(push, 1)
  6.  
  7. struct PackDirectoryHeader
  8. {
  9.     uint64 directoryOffset;
  10.     uint64 blockSize;
  11. };
  12.  
  13. struct AIDX
  14. {
  15.     uint32 magic;
  16.     uint32 version;
  17.     uint32 someConstantAlways17B8;
  18.     uint32 rootBlock;
  19. };
  20.  
  21. #pragma pack(pop)
  22.  
  23. struct RootDirectoryEntry
  24. {
  25.     uint32 nextBlock;
  26.     std::wstring directoryName;
  27. };
  28.  
  29. class IFileSystemEntry;
  30. typedef std::shared_ptr<IFileSystemEntry> IFileSystemEntryPtr;
  31.  
  32. class IFileSystemEntry
  33. {
  34. protected:
  35.     IFileSystemEntryPtr mParent;
  36.     std::list<IFileSystemEntryPtr> mChildren;
  37.     std::wstring mEntryName;
  38.  
  39. public:
  40.     IFileSystemEntryPtr getParent() const { return mParent; }
  41.     std::wstring getEntryName() const { return mEntryName; }
  42.     const std::list<IFileSystemEntryPtr>& getChildren() const { return mChildren; }
  43.  
  44.     virtual bool isDirectory() const = 0;
  45.  
  46.     virtual void dumpFiles(std::wstring basePath, std::wostream& output) = 0;
  47. };
  48.  
  49. class PackArchive;
  50. typedef std::shared_ptr<PackArchive> PackArchivePtr;
  51.  
  52. class DirectoryEntry : public IFileSystemEntry, public std::enable_shared_from_this<DirectoryEntry>
  53. {
  54. protected:
  55.     PackArchivePtr mArchive;
  56.     uint32 mNextBlock;
  57.     bool mIsRootDirectory;
  58. public:
  59.     DirectoryEntry(IFileSystemEntryPtr parent, const std::wstring& name, uint32 nextBlock, PackArchivePtr archive);
  60.  
  61.     virtual void parseChildren();
  62.  
  63.     void dumpFiles(std::wstring basePath, std::wostream& output);
  64.     void setRoot(bool root) { mIsRootDirectory = root; }
  65.     void getFiles(std::vector<IFileSystemEntryPtr>& files);
  66.     IFileSystemEntryPtr getFile(std::wstring path);
  67.  
  68.     bool isDirectory() const { return true; }
  69. };
  70.  
  71. typedef std::shared_ptr<DirectoryEntry> DirectoryEntryPtr;
  72.  
  73. class FileEntry : public IFileSystemEntry
  74. {
  75.     uint32 flags;
  76.     uint64 unkValue;
  77.     uint64 compressedSize;
  78.     uint64 uncompressedSize;
  79.     uint8 hash[20];
  80.     uint32 block;
  81. public:
  82.     FileEntry(IFileSystemEntryPtr parent, const std::wstring& name, const std::vector<uint8>& junk) {
  83.         mParent = parent;
  84.         mEntryName = name;
  85.         flags = *(uint32*)(junk.data());
  86.         unkValue = *(uint64*)(junk.data() + 4);
  87.         uncompressedSize = *(uint64*)(junk.data() + 12);
  88.         compressedSize = *(uint64*)(junk.data() + 20);
  89.         memcpy(hash, junk.data() + 28, 20);
  90.     }
  91.  
  92.     bool isDirectory() const { return false; }
  93.  
  94.     const uint8* getHash() const { return hash; }
  95.     uint32 getFlags() { return flags; }
  96.  
  97.     uint64 getSizeUncompressed() const { return uncompressedSize; }
  98.  
  99.     void dumpFiles(std::wstring basePath, std::wostream& output) {
  100.         output << basePath << mEntryName << L" (Type: " << flags << L", Compressed: " << compressedSize << L", Uncompressed: " << uncompressedSize << L")" << std::endl;
  101.     }
  102.  
  103.     std::wstring getFullPath() {
  104.         std::wstring path = mEntryName;
  105.         auto parent = mParent;
  106.         while(parent != nullptr) {
  107.             if(parent->getEntryName().empty() == false) {
  108.                 path = parent->getEntryName() + L"\\" + path;
  109.             }
  110.  
  111.             parent = parent->getParent();          
  112.         }
  113.  
  114.         return path;
  115.     }
  116. };
  117.  
  118. typedef std::shared_ptr<FileEntry> FileEntryPtr;
  119.  
  120. class PackArchive : public std::enable_shared_from_this<PackArchive>
  121. {
  122.     BinFilePtr mFile;
  123.     uint32 mDirectoryCount;
  124.     uint64 mDirectoryTableStart;
  125.     AIDX mIndexHeader;
  126.     std::vector<PackDirectoryHeader> mDirectoryHeaders;
  127.     DirectoryEntryPtr mFileRoot;
  128. public:
  129.     PackArchive(BinFilePtr binFile);
  130.     void validate();
  131.     void loadDirectoryTree();
  132.  
  133.     FileEntryPtr getFile(const std::wstring& name) { return std::dynamic_pointer_cast<FileEntry>(mFileRoot->getFile(name)); }
  134.     IFileSystemEntryPtr getEntry(const std::wstring& name) { return mFileRoot->getFile(name); }
  135.     DirectoryEntryPtr getRoot() const { return mFileRoot; }
  136.  
  137.     BinFilePtr getFile() const { return mFile; }
  138.  
  139.     const std::vector<PackDirectoryHeader>& getBlockTable() const { return mDirectoryHeaders; }
  140.  
  141.     static const uint32 FileMagic = 'PACK';
  142.     static const uint32 IndexMagic = 'AIDX';
  143. };
Advertisement
Add Comment
Please, Sign In to add comment