TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
loadlib.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef LOAD_LIB_H
20 #define LOAD_LIB_H
21 
22 #include "Define.h"
23 #ifdef PLATFORM_WINDOWS
24 #undef PLATFORM_WINDOWS
25 #endif
26 #include "CascLib.h"
27 #include <map>
28 #include <string>
29 
30 #ifndef _WIN32
31 int GetLastError();
32 #endif
33 
34 #define FILE_FORMAT_VERSION 18
35 
36 #pragma pack(push, 1)
37 
38 union u_map_fcc
39 {
40  char fcc_txt[4];
42 };
43 
44 //
45 // File version chunk
46 //
47 struct file_MVER
48 {
49  union{
51  char fcc_txt[4];
52  };
55 };
56 
57 struct file_MWMO
58 {
61  char FileList[1];
62 };
63 
64 class FileChunk
65 {
66 public:
67  FileChunk(uint8* data_, uint32 size_) : data(data_), size(size_) { }
68  ~FileChunk();
69 
72 
73  template<class T>
74  T* As() { return (T*)data; }
75  void parseSubChunks();
76  std::multimap<std::string, FileChunk*> subchunks;
77  FileChunk* GetSubChunk(std::string const& name);
78 };
79 
81 {
82 public:
85 
86  uint8 *GetData() { return data; }
88 
89  ChunkedFile();
90  virtual ~ChunkedFile();
91  bool prepareLoadedData();
92  bool loadFile(HANDLE mpq, std::string const& fileName, bool log = true);
93  void free();
94 
95  void parseChunks();
96  std::multimap<std::string, FileChunk*> chunks;
97  FileChunk* GetChunk(std::string const& name);
98 };
99 
100 #pragma pack(pop)
101 
102 #endif
Definition: loadlib.h:38
u_map_fcc fcc
Definition: loadlib.h:59
void * HANDLE
Definition: CascPort.h:146
uint32 size
Definition: loadlib.h:53
void free()
Definition: loadlib.cpp:79
Definition: loadlib.h:80
FileChunk * GetSubChunk(std::string const &name)
Definition: loadlib.cpp:184
Definition: loadlib.h:47
char FileList[1]
Definition: loadlib.h:61
TC_SHARED_API::google::protobuf::internal::ExtensionIdentifier< ::google::protobuf::FieldOptions,::google::protobuf::internal::EnumTypeTraits< ::bgs::protocol::LogOption,::bgs::protocol::LogOption_IsValid >, 14, false > log
FileChunk * GetChunk(std::string const &name)
Definition: loadlib.cpp:140
std::multimap< std::string, FileChunk * > chunks
Definition: loadlib.h:96
uint32 GetDataSize()
Definition: loadlib.h:87
void parseChunks()
Definition: loadlib.cpp:112
virtual ~ChunkedFile()
Definition: loadlib.cpp:31
uint32 ver
Definition: loadlib.h:54
T * As()
Definition: loadlib.h:74
void parseSubChunks()
Definition: loadlib.cpp:157
ChunkedFile()
Definition: loadlib.cpp:25
Definition: loadlib.h:57
uint32 fcc
Definition: loadlib.h:41
bool prepareLoadedData()
Definition: loadlib.cpp:64
uint8 * data
Definition: loadlib.h:83
uint32 size
Definition: loadlib.h:60
uint32_t uint32
Definition: Define.h:150
uint32 data_size
Definition: loadlib.h:84
uint8 * data
Definition: loadlib.h:70
Definition: loadlib.h:64
uint32 fcc
Definition: loadlib.h:50
~FileChunk()
Definition: loadlib.cpp:149
std::multimap< std::string, FileChunk * > subchunks
Definition: loadlib.h:76
int GetLastError()
Definition: Common.cpp:70
uint32 size
Definition: loadlib.h:71
uint8_t uint8
Definition: Define.h:152
FileChunk(uint8 *data_, uint32 size_)
Definition: loadlib.h:67
char fcc_txt[4]
Definition: loadlib.h:40
uint8 * GetData()
Definition: loadlib.h:86
bool loadFile(HANDLE mpq, std::string const &fileName, bool log=true)
Definition: loadlib.cpp:36
char fcc_txt[4]
Definition: loadlib.h:51