AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
M2Stores.h File Reference
#include "Define.h"
#include "Position.h"
#include <vector>

Go to the source code of this file.

Classes

struct  FlyByCamera
 

Functions

AC_GAME_API void LoadM2Cameras (std::string const &dataPath)
 
AC_GAME_API std::vector< FlyByCamera > const * GetFlyByCameras (uint32 cinematicCameraId)
 

Function Documentation

◆ GetFlyByCameras()

AC_GAME_API std::vector< FlyByCamera > const * GetFlyByCameras ( uint32  cinematicCameraId)
255{
256 return Acore::Containers::MapGetValuePtr(sFlyByCameraStore, cinematicCameraId);
257}
std::unordered_map< uint32, FlyByCameraCollection > sFlyByCameraStore
Definition: M2Stores.cpp:28
auto MapGetValuePtr(M &map, typename M::key_type const &key) -> decltype(AddressOrSelf(map.find(key) ->second))
Definition: Containers.h:206

References Acore::Containers::MapGetValuePtr(), and sFlyByCameraStore.

Referenced by CinematicMgr::BeginCinematic(), and debug_commandscript::HandleDebugPlayCinematicCommand().

◆ LoadM2Cameras()

AC_GAME_API void LoadM2Cameras ( std::string const &  dataPath)
174{
175 sFlyByCameraStore.clear();
176 LOG_INFO("server.loading", ">> Loading Cinematic Camera files");
177
178 uint32 oldMSTime = getMSTime();
179 for (CinematicCameraEntry const* dbcentry : sCinematicCameraStore)
180 {
181 std::string filenameWork = dataPath;
182 filenameWork.append(dbcentry->Model);
183
184 // Replace slashes (always to forward slash, because boost!)
185 std::replace(filenameWork.begin(), filenameWork.end(), '\\', '/');
186
187 boost::filesystem::path filename = filenameWork;
188
189 // Convert to native format
190 filename.make_preferred();
191
192 // Replace mdx to .m2
193 filename.replace_extension("m2");
194
195 std::ifstream m2file(filename.string().c_str(), std::ios::in | std::ios::binary);
196 if (!m2file.is_open())
197 continue;
198
199 // Get file size
200 m2file.seekg(0, std::ios::end);
201 std::streamoff fileSize = m2file.tellg();
202
203 // Reject if not at least the size of the header
204 if (static_cast<uint32>(fileSize) < sizeof(M2Header))
205 {
206 LOG_ERROR("server.loading", "Camera file {} is damaged. File is smaller than header size", filename.string());
207 m2file.close();
208 continue;
209 }
210
211 // Read 4 bytes (signature)
212 m2file.seekg(0, std::ios::beg);
213 char fileCheck[5];
214 m2file.read(fileCheck, 4);
215 fileCheck[4] = 0;
216
217 // Check file has correct magic (MD20)
218 if (strcmp(fileCheck, "MD20"))
219 {
220 LOG_ERROR("server.loading", "Camera file {} is damaged. File identifier not found", filename.string());
221 m2file.close();
222 continue;
223 }
224
225 // Now we have a good file, read it all into a vector of char's, then close the file.
226 std::vector<char> buffer(fileSize);
227 m2file.seekg(0, std::ios::beg);
228 if (!m2file.read(buffer.data(), fileSize))
229 {
230 m2file.close();
231 continue;
232 }
233 m2file.close();
234
235 // Read header
236 M2Header const* header = reinterpret_cast<M2Header const*>(buffer.data());
237
238 if (header->ofsCameras + sizeof(M2Camera) > static_cast<uint32>(fileSize))
239 {
240 LOG_ERROR("server.loading", "Camera file {} is damaged. Camera references position beyond file end", filename.string());
241 continue;
242 }
243
244 // Get camera(s) - Main header, then dump them.
245 M2Camera const* cam = reinterpret_cast<M2Camera const*>(buffer.data() + header->ofsCameras);
246 if (!readCamera(cam, fileSize, header, dbcentry))
247 LOG_ERROR("server.loading", "Camera file {} is damaged. Camera references position beyond file end", filename.string());
248 }
249
250 LOG_INFO("server.loading", ">> Loaded {} Cinematic Waypoint Sets in {} ms", (uint32)sFlyByCameraStore.size(), GetMSTimeDiffToNow(oldMSTime));
251 LOG_INFO("server.loading", " ");
252}
#define LOG_INFO(filterType__,...)
Definition: Log.h:165
#define LOG_ERROR(filterType__,...)
Definition: Log.h:157
std::uint32_t uint32
Definition: Define.h:107
uint32 GetMSTimeDiffToNow(uint32 oldMSTime)
Definition: Timer.h:131
uint32 getMSTime()
Definition: Timer.h:103
DBCStorage< CinematicCameraEntry > sCinematicCameraStore(CinematicCameraEntryfmt)
bool readCamera(M2Camera const *cam, uint32 buffSize, M2Header const *header, CinematicCameraEntry const *dbcentry)
Definition: M2Stores.cpp:50
Definition: M2Structure.h:35
uint32 ofsCameras
Definition: M2Structure.h:95
Definition: M2Structure.h:120
Definition: DBCStructure.h:703

References getMSTime(), GetMSTimeDiffToNow(), LOG_ERROR, LOG_INFO, M2Header::ofsCameras, readCamera(), sCinematicCameraStore, and sFlyByCameraStore.

Referenced by World::SetInitialWorldSettings().