mirror of
https://github.com/mangosfour/server.git
synced 2025-12-12 10:37:03 +00:00
Some missing from merge.
Signed-off-by: Salja <salja2012@hotmail.de>
This commit is contained in:
parent
ec939a5bce
commit
f4be15a7af
1895 changed files with 160408 additions and 53601 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
|
||||
#include "dbcfile.h"
|
||||
#include "mpq_libmpq.h"
|
||||
#include "loadlib/loadlib.h"
|
||||
|
||||
DBCFile::DBCFile(const std::string &filename):
|
||||
filename(filename),
|
||||
|
|
@ -9,43 +9,81 @@ DBCFile::DBCFile(const std::string &filename):
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
DBCFile::DBCFile(HANDLE file) : fileHandle(file), data(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DBCFile::open()
|
||||
{
|
||||
MPQFile f(filename.c_str());
|
||||
//if (!OpenNewestFile(filename.c_str(), &fileHandle))
|
||||
// return false;
|
||||
|
||||
char header[4];
|
||||
unsigned int na,nb,es,ss;
|
||||
|
||||
if(f.read(header,4)!=4) // Number of records
|
||||
if (!SFileReadFile(fileHandle, header, 4, NULL, NULL)) // Magic header
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
|
||||
if (header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(f.read(&na,4)!=4) // Number of records
|
||||
if (!SFileReadFile(fileHandle, &na, 4, NULL, NULL)) // Number of records
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
if(f.read(&nb,4)!=4) // Number of fields
|
||||
}
|
||||
|
||||
if (!SFileReadFile(fileHandle, &nb, 4, NULL, NULL)) // Number of fields
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
if(f.read(&es,4)!=4) // Size of a record
|
||||
}
|
||||
|
||||
if (!SFileReadFile(fileHandle, &es, 4, NULL, NULL)) // Size of a record
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
if(f.read(&ss,4)!=4) // String size
|
||||
}
|
||||
|
||||
if (!SFileReadFile(fileHandle, &ss, 4, NULL, NULL)) // String size
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
recordSize = es;
|
||||
recordCount = na;
|
||||
fieldCount = nb;
|
||||
stringSize = ss;
|
||||
if(fieldCount*4 != recordSize)
|
||||
if (fieldCount * 4 != recordSize)
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
}
|
||||
|
||||
data = new unsigned char[recordSize*recordCount+stringSize];
|
||||
stringTable = data + recordSize*recordCount;
|
||||
|
||||
size_t data_size = recordSize*recordCount+stringSize;
|
||||
if(f.read(data,data_size)!=data_size)
|
||||
|
||||
if (!SFileReadFile(fileHandle, data, data_size, NULL, NULL))
|
||||
{
|
||||
SFileCloseFile(fileHandle);
|
||||
return false;
|
||||
f.close();
|
||||
}
|
||||
|
||||
SFileCloseFile(fileHandle);
|
||||
return true;
|
||||
}
|
||||
|
||||
DBCFile::~DBCFile()
|
||||
{
|
||||
delete [] data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue