![]() |
TSunmix 0.2
|
00001 /* 00002 * File: mix_file.h 00003 * Author: ivosh-l 00004 * 00005 * Created on 29. prosinec 2011, 11:32 00006 */ 00007 00008 #ifndef MIX_FILE_H 00009 #define MIX_FILE_H 00010 #include <string> 00011 #include <fstream> 00012 #include <vector> 00013 #include "MixData.h" 00014 00015 00016 00048 union t_mix_header 00049 { 00050 struct 00051 { 00052 unsigned short c_files; 00053 unsigned int size; 00054 }; 00055 unsigned int flags; 00056 }; 00057 00081 struct t_mix_index_entry 00082 { 00083 unsigned int id; // id, used to identify the file instead of a normal name 00084 unsigned int offset; // offset from start of body 00085 unsigned int size; // size of this internal file 00086 }; 00087 00088 typedef enum 00089 { 00090 game_ts, 00091 game_ra, 00092 game_td 00093 } t_game; 00094 00095 const int mix_checksum = 0x00010000; 00096 const int mix_encrypted = 0x00020000; 00097 00098 00105 class MixFile { 00106 public: 00107 MixFile(); 00108 MixFile(const MixFile& orig); 00109 virtual ~MixFile(); 00116 bool open(const std::string path); 00124 bool extractFile(unsigned int fileID, std::string outPath); 00132 bool extractFile(std::string fileName, std::string outPath); 00139 bool extractAll(std::string outPath = ".", bool withFileNames = true); 00145 bool checkFileName(std::string fname); 00154 std::string printFileList(int flags); 00161 unsigned int getID(t_game game, std::string name); 00162 std::vector<std::string> getFileNames(); 00163 std::vector<t_mix_index_entry> getFileIndex(){ return files; }; 00164 private: 00165 bool readIndex(); 00166 bool readEncryptedIndex(); 00167 bool readFileNames(); 00168 bool extractAllFast(std::string outPath = "."); 00169 t_mix_header mix_head; // mix file header 00170 std::vector<t_mix_index_entry> files; // list of file headers 00171 std::vector<std::string> filenames; // file names 00172 bool m_is_encrypted; 00173 bool m_has_checksum; 00174 MixData * mixdb; // local mix database.dat 00175 MixData * globaldb; // global filenames database 00176 int dataoffset; 00177 std::ifstream fh; // file handler 00178 char key_source[80]; 00179 char key[56]; 00180 char decrypt_buffer[8]; // begining of next index read at the end of last block 00181 int decrypt_size; // size of valid buffer data 00182 }; 00183 00184 #endif /* MIX_FILE_H */ 00185