diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h
index a19fa059715..08248576820 100644
--- a/src/game/DBCStructure.h
+++ b/src/game/DBCStructure.h
@@ -1371,7 +1371,7 @@ struct SpellEntry
int32 EquippedItemInventoryTypeMask; // 67 m_equippedItemInvTypes (mask)
uint32 Effect[MAX_SPELL_EFFECTS]; // 68-70 m_effect
int32 EffectDieSides[MAX_SPELL_EFFECTS]; // 71-73 m_effectDieSides
- int32 EffectBaseDice[MAX_SPELL_EFFECTS]; // 74-76 m_effectBaseDice
+ uint32 EffectBaseDice[MAX_SPELL_EFFECTS]; // 74-76 m_effectBaseDice
float EffectDicePerLevel[MAX_SPELL_EFFECTS]; // 77-79 m_effectDicePerLevel
float EffectRealPointsPerLevel[MAX_SPELL_EFFECTS]; // 80-82 m_effectRealPointsPerLevel
int32 EffectBasePoints[MAX_SPELL_EFFECTS]; // 83-85 m_effectBasePoints (don't must be used in spell/auras explicitly, must be used cached Spell::m_currentBasePoints)
diff --git a/src/shared/Database/DBCEnums.h b/src/shared/Database/DBCEnums.h
new file mode 100644
index 00000000000..fbd87aafbe7
--- /dev/null
+++ b/src/shared/Database/DBCEnums.h
@@ -0,0 +1,123 @@
+/*
+* Copyright (C) 2005-2008 MaNGOS
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation; either version 2 of the License, or
+* (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#ifndef DBCENUMS_H
+#define DBCENUMS_H
+
+// client supported max level for player/pets/etc. Avoid overflow or client stability affected.
+// also see GT_MAX_LEVEL define
+#define MAX_LEVEL 100
+
+// Server side limitation. Base at used code requirements.
+// also see MAX_LEVEL and GT_MAX_LEVEL define
+#define STRONG_MAX_LEVEL 255
+
+enum AreaTeams
+{
+ AREATEAM_NONE = 0,
+ AREATEAM_ALLY = 2,
+ AREATEAM_HORDE = 4
+};
+
+enum AreaFlags
+{
+ AREA_FLAG_SNOW = 0x00000001, // snow (only Dun Morogh, Naxxramas, Razorfen Downs and Winterspring)
+ AREA_FLAG_UNK1 = 0x00000002, // unknown, (only Naxxramas and Razorfen Downs)
+ AREA_FLAG_UNK2 = 0x00000004, // Only used on development map
+ AREA_FLAG_SLAVE_CAPITAL = 0x00000008, // slave capital city flag?
+ AREA_FLAG_UNK3 = 0x00000010, // unknown
+ AREA_FLAG_SLAVE_CAPITAL2 = 0x00000020, // slave capital city flag?
+ AREA_FLAG_UNK4 = 0x00000040, // many zones have this flag
+ AREA_FLAG_ARENA = 0x00000080, // arena, both instanced and world arenas
+ AREA_FLAG_CAPITAL = 0x00000100, // main capital city flag
+ AREA_FLAG_CITY = 0x00000200, // only for one zone named "City" (where it located?)
+ AREA_FLAG_OUTLAND = 0x00000400, // outland zones? (only Eye of the Storm not have this flag, but have 0x00004000 flag)
+ AREA_FLAG_SANCTUARY = 0x00000800, // sanctuary area (PvP disabled)
+ AREA_FLAG_NEED_FLY = 0x00001000, // only Netherwing Ledge, Socrethar's Seat, Tempest Keep, The Arcatraz, The Botanica, The Mechanar, Sorrow Wing Point, Dragonspine Ridge, Netherwing Mines, Dragonmaw Base Camp, Dragonmaw Skyway
+ AREA_FLAG_UNUSED1 = 0x00002000, // not used now (no area/zones with this flag set in 2.4.2)
+ AREA_FLAG_OUTLAND2 = 0x00004000, // outland zones? (only Circle of Blood Arena not have this flag, but have 0x00000400 flag)
+ AREA_FLAG_PVP = 0x00008000, // pvp objective area? (Death's Door also has this flag although it's no pvp object area)
+ AREA_FLAG_ARENA_INSTANCE = 0x00010000, // used by instanced arenas only
+ AREA_FLAG_UNUSED2 = 0x00020000, // not used now (no area/zones with this flag set in 2.4.2)
+ AREA_FLAG_UNK5 = 0x00040000, // just used for Amani Pass, Hatchet Hills
+ AREA_FLAG_LOWLEVEL = 0x00100000 // used for some starting areas with area_level <=15
+};
+
+enum FactionTemplateFlags
+{
+ FACTION_TEMPLATE_FLAG_CONTESTED_GUARD = 0x00001000, // faction will attack players that were involved in PvP combats
+};
+
+enum FactionMasks
+{
+ FACTION_MASK_PLAYER = 1, // any player
+ FACTION_MASK_ALLIANCE = 2, // player or creature from alliance team
+ FACTION_MASK_HORDE = 4, // player or creature from horde team
+ FACTION_MASK_MONSTER = 8 // aggressive creature from monster team
+ // if none flags set then non-aggressive creature
+};
+
+enum MapTypes
+{
+ MAP_COMMON = 0,
+ MAP_INSTANCE = 1,
+ MAP_RAID = 2,
+ MAP_BATTLEGROUND = 3,
+ MAP_ARENA = 4
+};
+
+enum AbilytyLearnType
+{
+ ABILITY_LEARNED_ON_GET_PROFESSION_SKILL = 1,
+ ABILITY_LEARNED_ON_GET_RACE_OR_CLASS_SKILL = 2
+};
+
+enum ItemEnchantmentType
+{
+ ITEM_ENCHANTMENT_TYPE_NONE = 0,
+ ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL = 1,
+ ITEM_ENCHANTMENT_TYPE_DAMAGE = 2,
+ ITEM_ENCHANTMENT_TYPE_EQUIP_SPELL = 3,
+ ITEM_ENCHANTMENT_TYPE_RESISTANCE = 4,
+ ITEM_ENCHANTMENT_TYPE_STAT = 5,
+ ITEM_ENCHANTMENT_TYPE_TOTEM = 6
+};
+
+enum ItemEnchantmentAuraId
+{
+ ITEM_ENCHANTMENT_AURAID_POISON = 26,
+ ITEM_ENCHANTMENT_AURAID_NORMAL = 28,
+ ITEM_ENCHANTMENT_AURAID_FIRE = 32,
+ ITEM_ENCHANTMENT_AURAID_FROST = 33,
+ ITEM_ENCHANTMENT_AURAID_NATURE = 81,
+ ITEM_ENCHANTMENT_AURAID_SHADOW = 107
+};
+
+enum TotemCategoryType
+{
+ TOTEM_CATEGORY_TYPE_KNIFE = 1,
+ TOTEM_CATEGORY_TYPE_TOTEM = 2,
+ TOTEM_CATEGORY_TYPE_ROD = 3,
+ TOTEM_CATEGORY_TYPE_PICK = 21,
+ TOTEM_CATEGORY_TYPE_STONE = 22,
+ TOTEM_CATEGORY_TYPE_HAMMER = 23,
+ TOTEM_CATEGORY_TYPE_SPANNER = 24
+};
+
+#endif
+
diff --git a/src/shared/Database/DBCFileLoader.cpp b/src/shared/Database/DBCFileLoader.cpp
new file mode 100644
index 00000000000..23f602f5c93
--- /dev/null
+++ b/src/shared/Database/DBCFileLoader.cpp
@@ -0,0 +1,261 @@
+/*
+ * Copyright (C) 2005-2009 MaNGOS
+ *
+ * Copyright (C) 2008-2009 Trinity
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include
+#include
+#include
+
+#include "DBCFileLoader.h"
+
+DBCFileLoader::DBCFileLoader()
+{
+ data = NULL;
+ fieldsOffset = NULL;
+}
+
+bool DBCFileLoader::Load(const char *filename, const char *fmt)
+{
+
+ uint32 header;
+ if(data)
+ {
+ delete [] data;
+ data=NULL;
+ }
+
+ FILE * f=fopen(filename,"rb");
+ if(!f)return false;
+
+ if(fread(&header,4,1,f)!=1) // Number of records
+ return false;
+
+ EndianConvert(header);
+ if(header!=0x43424457)
+ return false; //'WDBC'
+
+ if(fread(&recordCount,4,1,f)!=1) // Number of records
+ return false;
+
+ EndianConvert(recordCount);
+
+ if(fread(&fieldCount,4,1,f)!=1) // Number of fields
+ return false;
+
+ EndianConvert(fieldCount);
+
+ if(fread(&recordSize,4,1,f)!=1) // Size of a record
+ return false;
+
+ EndianConvert(recordSize);
+
+ if(fread(&stringSize,4,1,f)!=1) // String size
+ return false;
+
+ EndianConvert(stringSize);
+
+ fieldsOffset = new uint32[fieldCount];
+ fieldsOffset[0] = 0;
+ for(uint32 i = 1; i < fieldCount; i++)
+ {
+ fieldsOffset[i] = fieldsOffset[i - 1];
+ if (fmt[i - 1] == 'b' || fmt[i - 1] == 'X') // byte fields
+ fieldsOffset[i] += 1;
+ else // 4 byte fields (int32/float/strings)
+ fieldsOffset[i] += 4;
+ }
+
+ data = new unsigned char[recordSize*recordCount+stringSize];
+ stringTable = data + recordSize*recordCount;
+
+ if(fread(data,recordSize*recordCount+stringSize,1,f)!=1)
+ return false;
+
+ fclose(f);
+ return true;
+}
+
+DBCFileLoader::~DBCFileLoader()
+{
+ if(data)
+ delete [] data;
+ if(fieldsOffset)
+ delete [] fieldsOffset;
+}
+
+DBCFileLoader::Record DBCFileLoader::getRecord(size_t id)
+{
+ assert(data);
+ return Record(*this, data + id*recordSize);
+}
+
+uint32 DBCFileLoader::GetFormatRecordSize(const char * format,int32* index_pos)
+{
+ uint32 recordsize = 0;
+ int32 i = -1;
+ for(uint32 x=0; format[x];++x)
+ switch(format[x])
+ {
+ case FT_FLOAT:
+ case FT_INT:
+ recordsize+=4;
+ break;
+ case FT_STRING:
+ recordsize+=sizeof(char*);
+ break;
+ case FT_SORT:
+ i=x;
+ break;
+ case FT_IND:
+ i=x;
+ recordsize+=4;
+ break;
+ case FT_BYTE:
+ recordsize += 1;
+ break;
+ }
+
+ if(index_pos)
+ *index_pos = i;
+
+ return recordsize;
+}
+
+char* DBCFileLoader::AutoProduceData(const char* format, uint32& records, char**& indexTable)
+{
+ /*
+ format STRING, NA, FLOAT,NA,INT <=>
+ struct{
+ char* field0,
+ float field1,
+ int field2
+ }entry;
+
+ this func will generate entry[rows] data;
+ */
+
+ typedef char * ptr;
+ if(strlen(format)!=fieldCount)
+ return NULL;
+
+ //get struct size and index pos
+ int32 i;
+ uint32 recordsize=GetFormatRecordSize(format,&i);
+
+ if(i>=0)
+ {
+ uint32 maxi=0;
+ //find max index
+ for(uint32 y=0;ymaxi)maxi=ind;
+ }
+
+ ++maxi;
+ records=maxi;
+ indexTable=new ptr[maxi];
+ memset(indexTable,0,maxi*sizeof(ptr));
+ }
+ else
+ {
+ records = recordCount;
+ indexTable = new ptr[recordCount];
+ }
+
+ char* dataTable= new char[recordCount*recordsize];
+
+ uint32 offset=0;
+
+ for(uint32 y =0;y=0)
+ {
+ indexTable[getRecord(y).getUInt(i)]=&dataTable[offset];
+ }
+ else
+ indexTable[y]=&dataTable[offset];
+
+ for(uint32 x=0;x
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef DBC_FILE_LOADER_H
+#define DBC_FILE_LOADER_H
+#include "Platform/Define.h"
+#include "Utilities/ByteConverter.h"
+#include
+
+enum
+{
+ FT_NA='x', //not used or unknown, 4 byte size
+ FT_NA_BYTE='X', //not used or unknown, byte
+ FT_STRING='s', //char*
+ FT_FLOAT='f', //float
+ FT_INT='i', //uint32
+ FT_BYTE='b', //uint8
+ FT_SORT='d', //sorted by this field, field is not included
+ FT_IND='n', //the same,but parsed to data
+ FT_LOGIC='l' //Logical (boolean)
+};
+
+class DBCFileLoader
+{
+ public:
+ DBCFileLoader();
+ ~DBCFileLoader();
+
+ bool Load(const char *filename, const char *fmt);
+
+ class Record
+ {
+ public:
+ float getFloat(size_t field) const
+ {
+ assert(field < file.fieldCount);
+ float val = *reinterpret_cast(offset+file.GetOffset(field));
+ EndianConvert(val);
+ return val;
+ }
+ uint32 getUInt(size_t field) const
+ {
+ assert(field < file.fieldCount);
+ uint32 val = *reinterpret_cast(offset+file.GetOffset(field));
+ EndianConvert(val);
+ return val;
+ }
+ uint8 getUInt8(size_t field) const
+ {
+ assert(field < file.fieldCount);
+ return *reinterpret_cast(offset+file.GetOffset(field));
+ }
+
+ const char *getString(size_t field) const
+ {
+ assert(field < file.fieldCount);
+ size_t stringOffset = getUInt(field);
+ assert(stringOffset < file.stringSize);
+ return reinterpret_cast(file.stringTable + stringOffset);
+ }
+
+ private:
+ Record(DBCFileLoader &file_, unsigned char *offset_): offset(offset_), file(file_) {}
+ unsigned char *offset;
+ DBCFileLoader &file;
+
+ friend class DBCFileLoader;
+
+ };
+
+ // Get record by id
+ Record getRecord(size_t id);
+ /// Get begin iterator over records
+
+ uint32 GetNumRows() const { return recordCount;}
+ uint32 GetCols() const { return fieldCount; }
+ uint32 GetOffset(size_t id) const { return (fieldsOffset != NULL && id < fieldCount) ? fieldsOffset[id] : 0; }
+ bool IsLoaded() {return (data!=NULL);}
+ char* AutoProduceData(const char* fmt, uint32& count, char**& indexTable);
+ char* AutoProduceStrings(const char* fmt, char* dataTable);
+ static uint32 GetFormatRecordSize(const char * format, int32 * index_pos = NULL);
+ private:
+
+ uint32 recordSize;
+ uint32 recordCount;
+ uint32 fieldCount;
+ uint32 stringSize;
+ uint32 *fieldsOffset;
+ unsigned char *data;
+ unsigned char *stringTable;
+};
+#endif
diff --git a/src/shared/Database/DBCStore.h b/src/shared/Database/DBCStore.h
new file mode 100644
index 00000000000..523d5c5a0b3
--- /dev/null
+++ b/src/shared/Database/DBCStore.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2005-2009 MaNGOS
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef DBCSTORE_H
+#define DBCSTORE_H
+
+#include "DBCFileLoader.h"
+
+template
+class DBCStorage
+{
+ typedef std::list StringPoolList;
+ public:
+ explicit DBCStorage(const char *f) : nCount(0), fieldCount(0), fmt(f), indexTable(NULL), m_dataTable(NULL) { }
+ ~DBCStorage() { Clear(); }
+
+ T const* LookupEntry(uint32 id) const { return (id>=nCount)?NULL:indexTable[id]; }
+ uint32 GetNumRows() const { return nCount; }
+ char const* GetFormat() const { return fmt; }
+ uint32 GetFieldCount() const { return fieldCount; }
+
+ bool Load(char const* fn)
+ {
+ DBCFileLoader dbc;
+ // Check if load was sucessful, only then continue
+ if(!dbc.Load(fn, fmt))
+ return false;
+
+ fieldCount = dbc.GetCols();
+ m_dataTable = (T*)dbc.AutoProduceData(fmt,nCount,(char**&)indexTable);
+ m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable));
+
+ // error in dbc file at loading if NULL
+ return indexTable!=NULL;
+ }
+
+ bool LoadStringsFrom(char const* fn)
+ {
+ // DBC must be already loaded using Load
+ if(!indexTable)
+ return false;
+
+ DBCFileLoader dbc;
+ // Check if load was successful, only then continue
+ if(!dbc.Load(fn, fmt))
+ return false;
+
+ m_stringPoolList.push_back(dbc.AutoProduceStrings(fmt,(char*)m_dataTable));
+
+ return true;
+ }
+
+ void Clear()
+ {
+ if (!indexTable)
+ return;
+
+ delete[] ((char*)indexTable);
+ indexTable = NULL;
+ delete[] ((char*)m_dataTable);
+ m_dataTable = NULL;
+
+ while(!m_stringPoolList.empty())
+ {
+ delete[] m_stringPoolList.front();
+ m_stringPoolList.pop_front();
+ }
+ nCount = 0;
+ }
+
+ private:
+ uint32 nCount;
+ uint32 fieldCount;
+ char const* fmt;
+ T** indexTable;
+ T* m_dataTable;
+ StringPoolList m_stringPoolList;
+};
+#endif
diff --git a/src/shared/Database/DBCStructure.h b/src/shared/Database/DBCStructure.h
new file mode 100644
index 00000000000..8e8aa8bfba8
--- /dev/null
+++ b/src/shared/Database/DBCStructure.h
@@ -0,0 +1,904 @@
+/*
+ * Copyright (C) 2005-2008 MaNGOS
+ *
+ * Copyright (C) 2008 Trinity
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef DBCSTRUCTURE_H
+#define DBCSTRUCTURE_H
+
+#include "DBCEnums.h"
+#include "Platform/Define.h"
+
+#include