mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-13 01:08:35 +00:00
feat(Core/DBC): rework load DBC (#3002)
* Move DBC load system from TC * Add db tables for all dbc * Support override data from db * Support override spells from db (#2994)
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license: https://github.com/azerothcore/azerothcore-wotlk/blob/master/LICENSE-GPL2
|
||||
* Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2008-2020 TrinityCore <http://www.trinitycore.org/>
|
||||
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "DBCFileLoader.h"
|
||||
#include "Errors.h"
|
||||
|
||||
DBCFileLoader::DBCFileLoader() : recordSize(0), recordCount(0), fieldCount(0), stringSize(0), fieldsOffset(NULL), data(NULL), stringTable(NULL) { }
|
||||
DBCFileLoader::DBCFileLoader() : recordSize(0), recordCount(0), fieldCount(0), stringSize(0), fieldsOffset(nullptr), data(nullptr), stringTable(nullptr) { }
|
||||
|
||||
bool DBCFileLoader::Load(const char* filename, const char* fmt)
|
||||
bool DBCFileLoader::Load(char const* filename, char const* fmt)
|
||||
{
|
||||
uint32 header;
|
||||
if (data)
|
||||
{
|
||||
delete [] data;
|
||||
data = NULL;
|
||||
data = nullptr;
|
||||
}
|
||||
|
||||
FILE* f = fopen(filename, "rb");
|
||||
@@ -32,7 +31,6 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
EndianConvert(header);
|
||||
|
||||
if (header != 0x43424457) //'WDBC'
|
||||
@@ -75,6 +73,7 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt)
|
||||
|
||||
fieldsOffset = new uint32[fieldCount];
|
||||
fieldsOffset[0] = 0;
|
||||
|
||||
for (uint32 i = 1; i < fieldCount; ++i)
|
||||
{
|
||||
fieldsOffset[i] = fieldsOffset[i - 1];
|
||||
@@ -100,23 +99,22 @@ bool DBCFileLoader::Load(const char* filename, const char* fmt)
|
||||
|
||||
DBCFileLoader::~DBCFileLoader()
|
||||
{
|
||||
if (data)
|
||||
delete [] data;
|
||||
delete[] data;
|
||||
|
||||
if (fieldsOffset)
|
||||
delete [] fieldsOffset;
|
||||
delete[] fieldsOffset;
|
||||
}
|
||||
|
||||
DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
|
||||
{
|
||||
assert(data);
|
||||
ASSERT(data);
|
||||
return Record(*this, data + id * recordSize);
|
||||
}
|
||||
|
||||
uint32 DBCFileLoader::GetFormatRecordSize(const char* format, int32* index_pos)
|
||||
uint32 DBCFileLoader::GetFormatRecordSize(char const* format, int32* index_pos)
|
||||
{
|
||||
uint32 recordsize = 0;
|
||||
int32 i = -1;
|
||||
|
||||
for (uint32 x = 0; format[x]; ++x)
|
||||
{
|
||||
switch (format[x])
|
||||
@@ -158,7 +156,7 @@ uint32 DBCFileLoader::GetFormatRecordSize(const char* format, int32* index_pos)
|
||||
return recordsize;
|
||||
}
|
||||
|
||||
char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**& indexTable, uint32 sqlRecordCount, uint32 sqlHighestIndex, char*& sqlDataTable)
|
||||
char* DBCFileLoader::AutoProduceData(char const* format, uint32& records, char**& indexTable)
|
||||
{
|
||||
/*
|
||||
format STRING, NA, FLOAT, NA, INT <=>
|
||||
@@ -173,7 +171,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
||||
|
||||
typedef char* ptr;
|
||||
if (strlen(format) != fieldCount)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
//get struct size and index pos
|
||||
int32 i;
|
||||
@@ -190,10 +188,6 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
||||
maxi = ind;
|
||||
}
|
||||
|
||||
// If higher index avalible from sql - use it instead of dbcs
|
||||
if (sqlHighestIndex > maxi)
|
||||
maxi = sqlHighestIndex;
|
||||
|
||||
++maxi;
|
||||
records = maxi;
|
||||
indexTable = new ptr[maxi];
|
||||
@@ -201,11 +195,11 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
||||
}
|
||||
else
|
||||
{
|
||||
records = recordCount + sqlRecordCount;
|
||||
indexTable = new ptr[recordCount + sqlRecordCount];
|
||||
records = recordCount;
|
||||
indexTable = new ptr[recordCount];
|
||||
}
|
||||
|
||||
char* dataTable = new char[(recordCount + sqlRecordCount) * recordsize];
|
||||
char* dataTable = new char[recordCount * recordsize];
|
||||
|
||||
uint32 offset = 0;
|
||||
|
||||
@@ -234,7 +228,7 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
||||
offset += sizeof(uint8);
|
||||
break;
|
||||
case FT_STRING:
|
||||
*((char**)(&dataTable[offset])) = NULL; // will replace non-empty or "" strings in AutoProduceStrings
|
||||
*((char**)(&dataTable[offset])) = nullptr; // will replace non-empty or "" strings in AutoProduceStrings
|
||||
offset += sizeof(char*);
|
||||
break;
|
||||
case FT_LOGIC:
|
||||
@@ -251,15 +245,13 @@ char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**
|
||||
}
|
||||
}
|
||||
|
||||
sqlDataTable = dataTable + offset;
|
||||
|
||||
return dataTable;
|
||||
}
|
||||
|
||||
char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
||||
char* DBCFileLoader::AutoProduceStrings(char const* format, char* dataTable)
|
||||
{
|
||||
if (strlen(format) != fieldCount)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
char* stringPool = new char[stringSize];
|
||||
memcpy(stringPool, stringTable, stringSize);
|
||||
@@ -289,21 +281,21 @@ char* DBCFileLoader::AutoProduceStrings(const char* format, char* dataTable)
|
||||
if (!*slot || !**slot)
|
||||
{
|
||||
const char * st = getRecord(y).getString(x);
|
||||
*slot=stringPool+(st-(const char*)stringTable);
|
||||
*slot = stringPool + (st - (char const*)stringTable);
|
||||
}
|
||||
offset += sizeof(char*);
|
||||
break;
|
||||
}
|
||||
case FT_LOGIC:
|
||||
ASSERT(false && "Attempted to load DBC files that does not have field types that match what is in the core. Check DBCfmt.h or your DBC files.");
|
||||
break;
|
||||
case FT_NA:
|
||||
case FT_NA_BYTE:
|
||||
case FT_SORT:
|
||||
break;
|
||||
default:
|
||||
ASSERT(false && "Unknown field format character in DBCfmt.h");
|
||||
break;
|
||||
}
|
||||
case FT_LOGIC:
|
||||
ASSERT(false && "Attempted to load DBC files that does not have field types that match what is in the core. Check DBCfmt.h or your DBC files.");
|
||||
break;
|
||||
case FT_NA:
|
||||
case FT_NA_BYTE:
|
||||
case FT_SORT:
|
||||
break;
|
||||
default:
|
||||
ASSERT(false && "Unknown field format character in DBCfmt.h");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user