OregonCore  revision 3611e8a-git
Your Favourite TBC server
M2Stores.h File Reference
#include "SharedDefines.h"
#include "Common.h"

Go to the source code of this file.

Classes

struct  FlyByCamera
 

Typedefs

typedef std::vector< FlyByCameraFlyByCameraCollection
 

Functions

void LoadM2Cameras (std::string const &dataPath)
 

Variables

std::unordered_map< uint32, FlyByCameraCollectionsFlyByCameraStore
 

Typedef Documentation

typedef std::vector<FlyByCamera> FlyByCameraCollection

Definition at line 30 of file M2Stores.h.

Function Documentation

void LoadM2Cameras ( std::string const &  dataPath)

Definition at line 164 of file M2Stores.cpp.

References error_log, getMSTime(), M2Header::ofsCameras, readCamera(), and sCinematicCameraStore.

Referenced by World::SetInitialWorldSettings().

165 {
166  sFlyByCameraStore.clear();
167 
168  uint32 oldMSTime = getMSTime();
169  for (uint32 i = 0; i < sCinematicCameraStore.GetNumRows(); ++i)
170  {
171  if (CinematicCameraEntry const* dbcentry = sCinematicCameraStore.LookupEntry(i))
172  {
173  std::string filename = dataPath;
174  filename.append(dbcentry->Model);
175 
176  // Replace slashes
177  std::replace(filename.begin(), filename.end(), '\\', '/');
178 
179  // Replace mdx to .m2
180  size_t loc = filename.find(".mdx");
181  if (loc != std::string::npos)
182  filename.replace(loc, 4, ".m2");
183 
184  std::ifstream m2file(filename.c_str(), std::ios::in | std::ios::binary);
185  if (!m2file.is_open())
186  continue;
187 
188  // Get file size
189  m2file.seekg(0, std::ios::end);
190  std::streamoff const fileSize = m2file.tellg();
191 
192  // Reject if not at least the size of the header
193  if (static_cast<uint32 const>(fileSize) < sizeof(M2Header))
194  {
195  error_log("Camera file %s is damaged. File is smaller than header size", filename.c_str());
196  m2file.close();
197  continue;
198  }
199 
200  // Read 4 bytes (signature)
201  m2file.seekg(0, std::ios::beg);
202  char fileCheck[5];
203  m2file.read(fileCheck, 4);
204  fileCheck[4] = 0;
205 
206  // Check file has correct magic (MD20)
207  if (strcmp(fileCheck, "MD20"))
208  {
209  error_log("Camera file %s is damaged. File identifier not found", filename.c_str());
210  m2file.close();
211  continue;
212  }
213 
214  // Now we have a good file, read it all into a vector of char's, then close the file.
215  std::vector<char> buffer(fileSize);
216  m2file.seekg(0, std::ios::beg);
217  if (!m2file.read(buffer.data(), fileSize))
218  {
219  m2file.close();
220  continue;
221  }
222  m2file.close();
223 
224  // Read header
225  M2Header const* header = reinterpret_cast<M2Header const*>(buffer.data());
226 
227  if (header->ofsCameras + sizeof(M2Camera) > static_cast<uint32 const>(fileSize))
228  {
229  error_log("server.loading", "Camera file %s is damaged. Camera references position beyond file end (header)", filename.c_str());
230  continue;
231  }
232 
233  // Get camera(s) - Main header, then dump them.
234  M2Camera const* cam = reinterpret_cast<M2Camera const*>(buffer.data() + header->ofsCameras);
235  if (!readCamera(cam, fileSize, header, dbcentry))
236  error_log("Camera file %s is damaged. Camera references position beyond file end (camera)", filename.c_str());
237  }
238  }
239 }
std::unordered_map< uint32, FlyByCameraCollection > sFlyByCameraStore
Definition: M2Stores.cpp:29
bool readCamera(M2Camera const *cam, uint32 buffSize, M2Header const *header, CinematicCameraEntry const *dbcentry)
Definition: M2Stores.cpp:51
uint32 getMSTime()
Definition: Timer.h:32
uint32 ofsCameras
Definition: M2Structure.h:115
DBCStorage< CinematicCameraEntry > sCinematicCameraStore(CinematicCameraEntryfmt)
#define error_log
Definition: Log.h:202
ACE_UINT32 uint32
Definition: Define.h:71

Variable Documentation

std::unordered_map<uint32, FlyByCameraCollection> sFlyByCameraStore