1 /* 2 * HLLib 3 * Copyright (C) 2006-2010 Ryan Gregg 4 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later 9 * version. 10 */ 11 12 #ifndef NCFFILE_H 13 #define NCFFILE_H 14 15 #include "stdafx.h" 16 #include "Package.h" 17 18 namespace HLLib 19 { 20 class HLLIB_API CNCFFile : public CPackage 21 { 22 private: 23 #pragma pack(1) 24 25 struct NCFHeader 26 { 27 hlUInt uiDummy0; // Always 0x00000001 28 hlUInt uiMajorVersion; // Always 0x00000002 29 hlUInt uiMinorVersion; // NCF version number. 30 hlUInt uiCacheID; 31 hlUInt uiLastVersionPlayed; 32 hlUInt uiDummy3; 33 hlUInt uiDummy4; 34 hlUInt uiFileSize; // Total size of NCF file in bytes. 35 hlUInt uiBlockSize; // Size of each data block in bytes. 36 hlUInt uiBlockCount; // Number of data blocks. 37 hlUInt uiDummy5; 38 }; 39 40 struct NCFDirectoryHeader 41 { 42 hlUInt uiDummy0; // Always 0x00000004 43 hlUInt uiCacheID; // Cache ID. 44 hlUInt uiLastVersionPlayed; // NCF file version. 45 hlUInt uiItemCount; // Number of items in the directory. 46 hlUInt uiFileCount; // Number of files in the directory. 47 hlUInt uiChecksumDataLength; // Always 0x00008000. Data per checksum? 48 hlUInt uiDirectorySize; // Size of lpNCFDirectoryEntries & lpNCFDirectoryNames & lpNCFDirectoryInfo1Entries & lpNCFDirectoryInfo2Entries & lpNCFDirectoryCopyEntries & lpNCFDirectoryLocalEntries in bytes. 49 hlUInt uiNameSize; // Size of the directory names in bytes. 50 hlUInt uiInfo1Count; // Number of Info1 entires. 51 hlUInt uiCopyCount; // Number of files to copy. 52 hlUInt uiLocalCount; // Number of files to keep local. 53 hlUInt uiDummy1; 54 hlUInt uiDummy2; 55 hlUInt uiChecksum; // Header checksum. 56 }; 57 58 struct NCFDirectoryEntry 59 { 60 hlUInt uiNameOffset; // Offset to the directory item name from the end of the directory items. 61 hlUInt uiItemSize; // Size of the item. (If file, file size. If folder, num items.) 62 hlUInt uiChecksumIndex; // Checksome index. (0xFFFFFFFF == None). 63 hlUInt uiDirectoryFlags; // Flags for the directory item. (0x00000000 == Folder). 64 hlUInt uiParentIndex; // Index of the parent directory item. (0xFFFFFFFF == None). 65 hlUInt uiNextIndex; // Index of the next directory item. (0x00000000 == None). 66 hlUInt uiFirstIndex; // Index of the first directory item. (0x00000000 == None). 67 }; 68 69 struct NCFDirectoryInfo1Entry 70 { 71 hlUInt uiDummy0; 72 }; 73 74 struct NCFDirectoryInfo2Entry 75 { 76 hlUInt uiDummy0; 77 }; 78 79 struct NCFDirectoryCopyEntry 80 { 81 hlUInt uiDirectoryIndex; // Index of the directory item. 82 }; 83 84 struct NCFDirectoryLocalEntry 85 { 86 hlUInt uiDirectoryIndex; // Index of the directory item. 87 }; 88 89 struct NCFUnknownHeader 90 { 91 hlUInt uiDummy0; // Always 0x00000001 92 hlUInt uiDummy1; // Always 0x00000000 93 }; 94 95 struct NCFUnknownEntry 96 { 97 hlUInt uiDummy0; 98 }; 99 100 struct NCFChecksumHeader 101 { 102 hlUInt uiDummy0; // Always 0x00000001 103 hlUInt uiChecksumSize; // Size of LPNCFCHECKSUMHEADER & LPNCFCHECKSUMMAPHEADER & in bytes. 104 }; 105 106 struct NCFChecksumMapHeader 107 { 108 hlUInt uiDummy0; // Always 0x14893721 109 hlUInt uiDummy1; // Always 0x00000001 110 hlUInt uiItemCount; // Number of items. 111 hlUInt uiChecksumCount; // Number of checksums. 112 }; 113 114 struct NCFChecksumMapEntry 115 { 116 hlUInt uiChecksumCount; // Number of checksums. 117 hlUInt uiFirstChecksumIndex; // Index of first checksum. 118 }; 119 120 struct NCFChecksumEntry 121 { 122 hlULong uiChecksum; // Checksum. 123 }; 124 125 #pragma pack() 126 127 private: 128 static const char *lpAttributeNames[]; 129 static const char *lpItemAttributeNames[]; 130 131 hlChar *lpRootPath; 132 133 Mapping::CView *pHeaderView; 134 135 NCFHeader *pHeader; 136 137 NCFDirectoryHeader *pDirectoryHeader; 138 NCFDirectoryEntry *lpDirectoryEntries; 139 hlChar *lpDirectoryNames; 140 NCFDirectoryInfo1Entry *lpDirectoryInfo1Entries; 141 NCFDirectoryInfo2Entry *lpDirectoryInfo2Entries; 142 NCFDirectoryCopyEntry *lpDirectoryCopyEntries; 143 NCFDirectoryLocalEntry *lpDirectoryLocalEntries; 144 145 NCFUnknownHeader *pUnknownHeader; 146 NCFUnknownEntry *lpUnknownEntries; 147 148 NCFChecksumHeader *pChecksumHeader; 149 NCFChecksumMapHeader *pChecksumMapHeader; 150 NCFChecksumMapEntry *lpChecksumMapEntries; 151 NCFChecksumEntry *lpChecksumEntries; 152 153 public: 154 CNCFFile(); 155 virtual ~CNCFFile(); 156 157 virtual HLPackageType GetType() const; 158 virtual const hlChar *GetExtension() const; 159 virtual const hlChar *GetDescription() const; 160 161 const hlChar *GetRootPath() const; 162 hlVoid SetRootPath(const hlChar *lpRootPath); 163 164 protected: 165 virtual hlBool MapDataStructures(); 166 virtual hlVoid UnmapDataStructures(); 167 168 virtual CDirectoryFolder *CreateRoot(); 169 170 virtual hlUInt GetAttributeCountInternal() const; 171 virtual const hlChar *GetAttributeNameInternal(HLPackageAttribute eAttribute) const; 172 virtual hlBool GetAttributeInternal(HLPackageAttribute eAttribute, HLAttribute &Attribute) const; 173 174 virtual hlUInt GetItemAttributeCountInternal() const; 175 virtual const hlChar *GetItemAttributeNameInternal(HLPackageAttribute eAttribute) const; 176 virtual hlBool GetItemAttributeInternal(const CDirectoryItem *pItem, HLPackageAttribute eAttribute, HLAttribute &Attribute) const; 177 178 virtual hlBool GetFileExtractableInternal(const CDirectoryFile *pFile, hlBool &bExtractable) const; 179 virtual hlBool GetFileValidationInternal(const CDirectoryFile *pFile, HLValidation &eValidation) const; 180 virtual hlBool GetFileSizeInternal(const CDirectoryFile *pFile, hlUInt &uiSize) const; 181 virtual hlBool GetFileSizeOnDiskInternal(const CDirectoryFile *pFile, hlUInt &uiSize) const; 182 183 virtual hlBool CreateStreamInternal(const CDirectoryFile *pFile, Streams::IStream *&pStream) const; 184 185 private: 186 hlVoid CreateRoot(CDirectoryFolder *pFolder); 187 188 hlVoid GetPath(const CDirectoryFile *pFile, hlChar *lpPath, hlUInt uiPathSize) const; 189 }; 190 } 191 192 #endif 193