Tools: Moved db2 metadata structures to a location shared by all tools

This commit is contained in:
Shauren
2018-03-03 14:24:50 +01:00
parent be0f2c297c
commit 6d5e25ddd4
7 changed files with 280 additions and 242 deletions

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include "DB2FileSystemSource.h"
#include <boost/filesystem/operations.hpp>
DB2FileSystemSource::DB2FileSystemSource(std::string const& fileName)
{
_fileName = fileName;
_file = fopen(_fileName.c_str(), "rb");
}
DB2FileSystemSource::~DB2FileSystemSource()
{
if (_file)
fclose(_file);
}
bool DB2FileSystemSource::IsOpen() const
{
return _file != nullptr;
}
bool DB2FileSystemSource::Read(void* buffer, std::size_t numBytes)
{
return fread(buffer, numBytes, 1, _file) == 1;
}
std::size_t DB2FileSystemSource::GetPosition() const
{
return ftell(_file);
}
std::size_t DB2FileSystemSource::GetFileSize() const
{
boost::system::error_code error;
std::size_t size = boost::filesystem::file_size(_fileName, error);
return !error ? size : 0;
}
char const* DB2FileSystemSource::GetFileName() const
{
return _fileName.c_str();
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef DB2FileSystemSource_h__
#define DB2FileSystemSource_h__
#include "DB2FileLoader.h"
#include <string>
struct TC_COMMON_API DB2FileSystemSource : public DB2FileSource
{
DB2FileSystemSource(std::string const& fileName);
~DB2FileSystemSource();
bool IsOpen() const override;
bool Read(void* buffer, std::size_t numBytes) override;
std::size_t GetPosition() const override;
std::size_t GetFileSize() const override;
char const* GetFileName() const override;
private:
std::string _fileName;
FILE* _file;
};
#endif // DB2FileSystemSource_h__

View File

@@ -18,54 +18,8 @@
#include "DB2Store.h"
#include "ByteBuffer.h"
#include "DB2DatabaseLoader.h"
#include "DB2FileSystemSource.h"
#include "DB2Meta.h"
#include <boost/filesystem/operations.hpp>
struct DB2FileSystemSource : public DB2FileSource
{
DB2FileSystemSource(std::string const& fileName)
{
_fileName = fileName;
_file = fopen(_fileName.c_str(), "rb");
}
~DB2FileSystemSource()
{
if (_file)
fclose(_file);
}
bool IsOpen() const override
{
return _file != nullptr;
}
bool Read(void* buffer, std::size_t numBytes) override
{
return fread(buffer, numBytes, 1, _file) == 1;
}
std::size_t GetPosition() const override
{
return ftell(_file);
}
std::size_t GetFileSize() const override
{
boost::system::error_code error;
std::size_t size = boost::filesystem::file_size(_fileName, error);
return !error ? size : 0;
}
char const* GetFileName() const override
{
return _fileName.c_str();
}
private:
std::string _fileName;
FILE* _file;
};
DB2StorageBase::DB2StorageBase(char const* fileName, DB2LoadInfo const* loadInfo)
: _tableHash(0), _layoutHash(0), _fileName(fileName), _fieldCount(0), _loadInfo(loadInfo), _dataTable(nullptr), _dataTableEx(nullptr), _indexTableSize(0)

View File

@@ -0,0 +1,178 @@
/*
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef ExtractorDB2LoadInfo_h__
#define ExtractorDB2LoadInfo_h__
#include "DB2FileLoader.h"
#include "DB2Meta.h"
#include <array>
struct CinematicCameraLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_INT, "SoundID" },
{ false, FT_FLOAT, "OriginX" },
{ false, FT_FLOAT, "OriginY" },
{ false, FT_FLOAT, "OriginZ" },
{ false, FT_FLOAT, "OriginFacing" },
{ false, FT_INT, "FileDataID" },
};
static char const* types = "iffi";
static uint8 const arraySizes[4] = { 1, 3, 1, 1 };
static DB2Meta const meta(-1, 4, 0x0062B0F4, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
struct GameobjectDisplayInfoLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ true, FT_INT, "FileDataID" },
{ false, FT_FLOAT, "GeoBoxMinX" },
{ false, FT_FLOAT, "GeoBoxMinY" },
{ false, FT_FLOAT, "GeoBoxMinZ" },
{ false, FT_FLOAT, "GeoBoxMaxX" },
{ false, FT_FLOAT, "GeoBoxMaxY" },
{ false, FT_FLOAT, "GeoBoxMaxZ" },
{ false, FT_FLOAT, "OverrideLootEffectScale" },
{ false, FT_FLOAT, "OverrideNameScale" },
{ true, FT_SHORT, "ObjectEffectPackageID" },
};
static char const* types = "ifffh";
static uint8 const arraySizes[5] = { 1, 6, 1, 1, 1 };
static DB2Meta const meta(-1, 5, 0x9F2098D1, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
struct LiquidTypeLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_STRING_NOT_LOCALIZED, "Name" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture1" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture2" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture3" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture4" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture5" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture6" },
{ false, FT_INT, "SpellID" },
{ false, FT_FLOAT, "MaxDarkenDepth" },
{ false, FT_FLOAT, "FogDarkenIntensity" },
{ false, FT_FLOAT, "AmbDarkenIntensity" },
{ false, FT_FLOAT, "DirDarkenIntensity" },
{ false, FT_FLOAT, "ParticleScale" },
{ true, FT_INT, "Color1" },
{ true, FT_INT, "Color2" },
{ false, FT_FLOAT, "Float1" },
{ false, FT_FLOAT, "Float2" },
{ false, FT_FLOAT, "Float3" },
{ false, FT_FLOAT, "Float4" },
{ false, FT_FLOAT, "Float5" },
{ false, FT_FLOAT, "Float6" },
{ false, FT_FLOAT, "Float7" },
{ false, FT_FLOAT, "Float8" },
{ false, FT_FLOAT, "Float9" },
{ false, FT_FLOAT, "Float10" },
{ false, FT_FLOAT, "Float11" },
{ false, FT_FLOAT, "Float12" },
{ false, FT_FLOAT, "Float13" },
{ false, FT_FLOAT, "Float14" },
{ false, FT_FLOAT, "Float15" },
{ false, FT_FLOAT, "Float16" },
{ false, FT_FLOAT, "Float17" },
{ false, FT_FLOAT, "Float18" },
{ false, FT_INT, "Int1" },
{ false, FT_INT, "Int2" },
{ false, FT_INT, "Int3" },
{ false, FT_INT, "Int4" },
{ false, FT_SHORT, "Flags" },
{ false, FT_SHORT, "LightID" },
{ false, FT_BYTE, "SoundBank" },
{ false, FT_BYTE, "ParticleMovement" },
{ false, FT_BYTE, "ParticleTexSlots" },
{ false, FT_BYTE, "MaterialID" },
{ false, FT_BYTE, "FrameCountTexture1" },
{ false, FT_BYTE, "FrameCountTexture2" },
{ false, FT_BYTE, "FrameCountTexture3" },
{ false, FT_BYTE, "FrameCountTexture4" },
{ false, FT_BYTE, "FrameCountTexture5" },
{ false, FT_BYTE, "FrameCountTexture6" },
{ false, FT_INT, "SoundID" },
};
static char const* types = "ssifffffifihhbbbbbi";
static uint8 const arraySizes[19] = { 1, 6, 1, 1, 1, 1, 1, 1, 2, 18, 4, 1, 1, 1, 1, 1, 1, 6, 1 };
static DB2Meta const meta(-1, 19, 0x3313BBF3, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
struct MapLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_STRING_NOT_LOCALIZED, "Directory" },
{ false, FT_STRING, "MapName" },
{ false, FT_STRING, "MapDescription0" },
{ false, FT_STRING, "MapDescription1" },
{ false, FT_STRING, "PvpShortDescription" },
{ false, FT_STRING, "PvpLongDescription" },
{ true, FT_INT, "Flags1" },
{ true, FT_INT, "Flags2" },
{ false, FT_FLOAT, "MinimapIconScale" },
{ false, FT_FLOAT, "CorpseX" },
{ false, FT_FLOAT, "CorpseY" },
{ false, FT_SHORT, "AreaTableID" },
{ true, FT_SHORT, "LoadingScreenID" },
{ true, FT_SHORT, "CorpseMapID" },
{ true, FT_SHORT, "TimeOfDayOverride" },
{ true, FT_SHORT, "ParentMapID" },
{ true, FT_SHORT, "CosmeticParentMapID" },
{ true, FT_SHORT, "WindSettingsID" },
{ false, FT_BYTE, "InstanceType" },
{ false, FT_BYTE, "MapType" },
{ false, FT_BYTE, "ExpansionID" },
{ false, FT_BYTE, "MaxPlayers" },
{ false, FT_BYTE, "TimeOffset" },
};
static char const* types = "ssssssiffhhhhhhhbbbbb";
static uint8 const arraySizes[21] = { 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
static DB2Meta const meta(-1, 21, 0xF568DF12, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
#endif // ExtractorDB2LoadInfo_h__

View File

@@ -22,6 +22,7 @@
#include "DB2CascFileSource.h"
#include "DB2Meta.h"
#include "DBFilesClientList.h"
#include "ExtractorDB2LoadInfo.h"
#include "StringFormat.h"
#include "adt.h"
#include "wdt.h"
@@ -50,133 +51,6 @@ std::set<std::string> CameraFileNames;
boost::filesystem::path input_path;
boost::filesystem::path output_path;
struct CinematicCameraLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_INT, "SoundID" },
{ false, FT_FLOAT, "OriginX" },
{ false, FT_FLOAT, "OriginY" },
{ false, FT_FLOAT, "OriginZ" },
{ false, FT_FLOAT, "OriginFacing" },
{ false, FT_INT, "ModelFileDataID" },
};
static char const* types = "iffi";
static uint8 const arraySizes[4] = { 1, 3, 1, 1 };
static DB2Meta const meta(-1, 4, 0x0062B0F4, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
struct LiquidTypeLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_STRING, "Name" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture1" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture2" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture3" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture4" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture5" },
{ false, FT_STRING_NOT_LOCALIZED, "Texture6" },
{ false, FT_INT, "SpellID" },
{ false, FT_FLOAT, "MaxDarkenDepth" },
{ false, FT_FLOAT, "FogDarkenIntensity" },
{ false, FT_FLOAT, "AmbDarkenIntensity" },
{ false, FT_FLOAT, "DirDarkenIntensity" },
{ false, FT_FLOAT, "ParticleScale" },
{ false, FT_INT, "Color1" },
{ false, FT_INT, "Color2" },
{ false, FT_FLOAT, "Float1" },
{ false, FT_FLOAT, "Float2" },
{ false, FT_FLOAT, "Float3" },
{ false, FT_FLOAT, "Float4" },
{ false, FT_FLOAT, "Float5" },
{ false, FT_FLOAT, "Float6" },
{ false, FT_FLOAT, "Float7" },
{ false, FT_FLOAT, "Float8" },
{ false, FT_FLOAT, "Float9" },
{ false, FT_FLOAT, "Float10" },
{ false, FT_FLOAT, "Float11" },
{ false, FT_FLOAT, "Float12" },
{ false, FT_FLOAT, "Float13" },
{ false, FT_FLOAT, "Float14" },
{ false, FT_FLOAT, "Float15" },
{ false, FT_FLOAT, "Float16" },
{ false, FT_FLOAT, "Float17" },
{ false, FT_FLOAT, "Float18" },
{ false, FT_INT, "Int1" },
{ false, FT_INT, "Int2" },
{ false, FT_INT, "Int3" },
{ false, FT_INT, "Int4" },
{ false, FT_SHORT, "Flags" },
{ false, FT_SHORT, "LightID" },
{ false, FT_BYTE, "Type" },
{ false, FT_BYTE, "ParticleMovement" },
{ false, FT_BYTE, "ParticleTexSlots" },
{ false, FT_BYTE, "MaterialID" },
{ false, FT_BYTE, "DepthTexCount1" },
{ false, FT_BYTE, "DepthTexCount2" },
{ false, FT_BYTE, "DepthTexCount3" },
{ false, FT_BYTE, "DepthTexCount4" },
{ false, FT_BYTE, "DepthTexCount5" },
{ false, FT_BYTE, "DepthTexCount6" },
{ false, FT_INT, "SoundID" },
};
static char const* types = "ssifffffifihhbbbbbi";
static uint8 const arraySizes[19] = { 1, 6, 1, 1, 1, 1, 1, 1, 2, 18, 4, 1, 1, 1, 1, 1, 1, 6, 1 };
static DB2Meta const meta(-1, 19, 0x3313BBF3, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
struct MapLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_STRING_NOT_LOCALIZED, "Directory" },
{ false, FT_STRING, "MapName" },
{ false, FT_STRING, "MapDescription0" },
{ false, FT_STRING, "MapDescription1" },
{ false, FT_STRING, "ShortDescription" },
{ false, FT_STRING, "LongDescription" },
{ false, FT_INT, "Flags1" },
{ false, FT_INT, "Flags2" },
{ false, FT_FLOAT, "MinimapIconScale" },
{ false, FT_FLOAT, "CorpsePosX" },
{ false, FT_FLOAT, "CorpsePosY" },
{ false, FT_SHORT, "AreaTableID" },
{ false, FT_SHORT, "LoadingScreenID" },
{ true, FT_SHORT, "CorpseMapID" },
{ false, FT_SHORT, "TimeOfDayOverride" },
{ true, FT_SHORT, "ParentMapID" },
{ true, FT_SHORT, "CosmeticParentMapID" },
{ false, FT_SHORT, "WindSettingsID" },
{ false, FT_BYTE, "InstanceType" },
{ false, FT_BYTE, "unk5" },
{ false, FT_BYTE, "ExpansionID" },
{ false, FT_BYTE, "MaxPlayers" },
{ false, FT_BYTE, "TimeOffset" },
};
static char const* types = "ssssssiffhhhhhhhbbbbb";
static uint8 const arraySizes[21] = { 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
static DB2Meta const meta(-1, 21, 0xF568DF12, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
// **************************************************
// Extractor options
// **************************************************
@@ -389,7 +263,7 @@ void ReadLiquidTypeTableDBC()
for (uint32 x = 0; x < db2.GetRecordCount(); ++x)
{
DB2Record record = db2.GetRecord(x);
LiqType[record.GetId()] = record.GetUInt8("Type");
LiqType[record.GetId()] = record.GetUInt8("SoundBank");
}
for (uint32 x = 0; x < db2.GetRecordCopyCount(); ++x)

View File

@@ -18,8 +18,8 @@
#include "adtfile.h"
#include "DB2CascFileSource.h"
#include "DB2Meta.h"
#include "Errors.h"
#include "ExtractorDB2LoadInfo.h"
#include "model.h"
#include "StringFormat.h"
#include "vmapexport.h"
@@ -57,32 +57,6 @@ bool ExtractSingleModel(std::string& fname)
extern CASC::StorageHandle CascStorage;
struct GameobjectDisplayInfoLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_INT, "FileDataID" },
{ false, FT_FLOAT, "GeoBoxMinX" },
{ false, FT_FLOAT, "GeoBoxMinY" },
{ false, FT_FLOAT, "GeoBoxMinZ" },
{ false, FT_FLOAT, "GeoBoxMaxX" },
{ false, FT_FLOAT, "GeoBoxMaxY" },
{ false, FT_FLOAT, "GeoBoxMaxZ" },
{ false, FT_FLOAT, "OverrideLootEffectScale" },
{ false, FT_FLOAT, "OverrideNameScale" },
{ false, FT_SHORT, "ObjectEffectPackageID" },
};
static char const* types = "ifffh";
static uint8 const arraySizes[5] = { 1, 6, 1, 1, 1 };
static DB2Meta const meta(-1, 5, 0x9F2098D1, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
enum ModelTypes : uint32
{
MODEL_MD20 = '02DM',

View File

@@ -21,7 +21,7 @@
#include "Common.h"
#include "cascfile.h"
#include "DB2CascFileSource.h"
#include "DB2Meta.h"
#include "ExtractorDB2LoadInfo.h"
#include "StringFormat.h"
#include "vmapexport.h"
#include "wdtfile.h"
@@ -66,45 +66,6 @@ std::unordered_set<uint32> maps_that_are_parents;
boost::filesystem::path input_path;
bool preciseVectorData = false;
struct MapLoadInfo
{
static DB2FileLoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_STRING_NOT_LOCALIZED, "Directory" },
{ false, FT_STRING, "MapName" },
{ false, FT_STRING, "MapDescription0" },
{ false, FT_STRING, "MapDescription1" },
{ false, FT_STRING, "ShortDescription" },
{ false, FT_STRING, "LongDescription" },
{ false, FT_INT, "Flags1" },
{ false, FT_INT, "Flags2" },
{ false, FT_FLOAT, "MinimapIconScale" },
{ false, FT_FLOAT, "CorpsePosX" },
{ false, FT_FLOAT, "CorpsePosY" },
{ false, FT_SHORT, "AreaTableID" },
{ false, FT_SHORT, "LoadingScreenID" },
{ true, FT_SHORT, "CorpseMapID" },
{ false, FT_SHORT, "TimeOfDayOverride" },
{ true, FT_SHORT, "ParentMapID" },
{ true, FT_SHORT, "CosmeticParentMapID" },
{ false, FT_SHORT, "WindSettingsID" },
{ false, FT_BYTE, "InstanceType" },
{ false, FT_BYTE, "unk5" },
{ false, FT_BYTE, "ExpansionID" },
{ false, FT_BYTE, "MaxPlayers" },
{ false, FT_BYTE, "TimeOffset" },
};
static char const* types = "ssssssiffhhhhhhhbbbbb";
static uint8 const arraySizes[21] = { 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
static DB2Meta const meta(-1, 21, 0xF568DF12, types, arraySizes, -1);
static DB2FileLoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, &meta);
return &loadInfo;
}
};
// Constants
//static const char * szWorkDirMaps = ".\\Maps";