TrinityCore
Loading...
Searching...
No Matches
loadlib.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3
*
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License as published by the
6
* Free Software Foundation; either version 2 of the License, or (at your
7
* option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#define _CRT_SECURE_NO_DEPRECATE
19
20
#include "loadlib.h"
21
#include "
mpq_libmpq.h
"
22
#include <cstdio>
23
24
class
MPQFile
;
25
26
u_map_fcc
MverMagic
= { {
'R'
,
'E'
,
'V'
,
'M'
} };
27
28
FileLoader::FileLoader
()
29
{
30
data
= 0;
31
data_size
= 0;
32
version
= 0;
33
}
34
35
FileLoader::~FileLoader
()
36
{
37
free
();
38
}
39
40
bool
FileLoader::loadFile
(std::string
const
& fileName,
bool
log)
41
{
42
free
();
43
MPQFile
mf(fileName.c_str());
44
if
(mf.
isEof
())
45
{
46
if
(log)
47
printf(
"No such file %s\n"
, fileName.c_str());
48
return
false
;
49
}
50
51
data_size
= mf.
getSize
();
52
53
data
=
new
uint8
[
data_size
];
54
mf.
read
(
data
,
data_size
);
55
mf.
close
();
56
if
(
prepareLoadedData
())
57
return
true
;
58
59
printf(
"Error loading %s"
, fileName.c_str());
60
mf.
close
();
61
free
();
62
return
false
;
63
}
64
65
bool
FileLoader::prepareLoadedData
()
66
{
67
// Check version
68
version
= (
file_MVER
*)
data
;
69
if
(
version
->
fcc
!=
MverMagic
.
fcc
)
70
return
false
;
71
if
(
version
->
ver
!=
FILE_FORMAT_VERSION
)
72
return
false
;
73
return
true
;
74
}
75
76
void
FileLoader::free
()
77
{
78
delete
[]
data
;
79
data
= 0;
80
data_size
= 0;
81
version
= 0;
82
}
uint8
uint8_t uint8
Definition
Define.h:135
FileLoader::~FileLoader
~FileLoader()
Definition
loadlib.cpp:35
FileLoader::loadFile
bool loadFile(std::string const &fileName, bool log=true)
Definition
loadlib.cpp:40
FileLoader::data_size
uint32 data_size
Definition
loadlib.h:50
FileLoader::version
file_MVER * version
Definition
loadlib.h:56
FileLoader::FileLoader
FileLoader()
Definition
loadlib.cpp:28
FileLoader::free
virtual void free()
Definition
loadlib.cpp:76
FileLoader::prepareLoadedData
virtual bool prepareLoadedData()
Definition
loadlib.cpp:65
FileLoader::data
uint8 * data
Definition
loadlib.h:49
MPQFile
Definition
mpq_libmpq.h:73
MPQFile::getSize
size_t getSize()
Definition
mpq_libmpq.h:87
MPQFile::read
size_t read(void *dest, size_t bytes)
Definition
mpq_libmpq.cpp:100
MPQFile::isEof
bool isEof()
Definition
mpq_libmpq.h:91
MPQFile::close
void close()
Definition
mpq_libmpq.cpp:129
MverMagic
u_map_fcc MverMagic
Definition
loadlib.cpp:26
mpq_libmpq.h
file_MVER
Definition
loadlib.h:39
file_MVER::ver
uint32 ver
Definition
loadlib.h:45
file_MVER::fcc
uint32 fcc
Definition
loadlib.h:41
u_map_fcc
Definition
loadlib.h:30
u_map_fcc::fcc
uint32 fcc
Definition
loadlib.h:32
FILE_FORMAT_VERSION
#define FILE_FORMAT_VERSION
Definition
loadlib.h:23
tools
map_extractor
loadlib.cpp
Generated on Sun May 10 2026 02:30:26 for TrinityCore by
1.9.8