mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 18:10:26 +00:00
Big re-organization of repository [W.I.P]
This commit is contained in:
@@ -1,44 +0,0 @@
|
||||
# Copyright (C)
|
||||
# Copyright (C)
|
||||
#
|
||||
# This file is free software; as a special exception the author gives
|
||||
# unlimited permission to copy and/or distribute it, with or without
|
||||
# modifications, as long as this notice is preserved.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
file(GLOB_RECURSE sources *.cpp *.h)
|
||||
|
||||
set(include_Dirs
|
||||
${CMAKE_SOURCE_DIR}/src/server/shared
|
||||
${CMAKE_SOURCE_DIR}/modules/dep/libmpq
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/loadlib
|
||||
)
|
||||
|
||||
if( WIN32 )
|
||||
set(include_Dirs
|
||||
${include_Dirs}
|
||||
${CMAKE_SOURCE_DIR}/modules/dep/libmpq/win
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(${include_Dirs})
|
||||
|
||||
add_executable(mapextractor
|
||||
${sources}
|
||||
)
|
||||
|
||||
target_link_libraries(mapextractor
|
||||
mpq
|
||||
${BZIP2_LIBRARIES}
|
||||
${ZLIB_LIBRARIES}
|
||||
)
|
||||
|
||||
if( UNIX )
|
||||
install(TARGETS mapextractor DESTINATION bin)
|
||||
elseif( WIN32 )
|
||||
install(TARGETS mapextractor DESTINATION "${CMAKE_INSTALL_PREFIX}")
|
||||
endif()
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,156 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
|
||||
#include "adt.h"
|
||||
|
||||
// Helper
|
||||
int holetab_h[4] = {0x1111, 0x2222, 0x4444, 0x8888};
|
||||
int holetab_v[4] = {0x000F, 0x00F0, 0x0F00, 0xF000};
|
||||
|
||||
u_map_fcc MHDRMagic = { {'R','D','H','M'} };
|
||||
u_map_fcc MCINMagic = { {'N','I','C','M'} };
|
||||
u_map_fcc MH2OMagic = { {'O','2','H','M'} };
|
||||
u_map_fcc MCNKMagic = { {'K','N','C','M'} };
|
||||
u_map_fcc MCVTMagic = { {'T','V','C','M'} };
|
||||
u_map_fcc MCLQMagic = { {'Q','L','C','M'} };
|
||||
|
||||
bool isHole(int holes, int i, int j)
|
||||
{
|
||||
int testi = i / 2;
|
||||
int testj = j / 4;
|
||||
if(testi > 3) testi = 3;
|
||||
if(testj > 3) testj = 3;
|
||||
return (holes & holetab_h[testi] & holetab_v[testj]) != 0;
|
||||
}
|
||||
|
||||
//
|
||||
// Adt file loader class
|
||||
//
|
||||
ADT_file::ADT_file()
|
||||
{
|
||||
a_grid = 0;
|
||||
}
|
||||
|
||||
ADT_file::~ADT_file()
|
||||
{
|
||||
free();
|
||||
}
|
||||
|
||||
void ADT_file::free()
|
||||
{
|
||||
a_grid = 0;
|
||||
FileLoader::free();
|
||||
}
|
||||
|
||||
//
|
||||
// Adt file check function
|
||||
//
|
||||
bool ADT_file::prepareLoadedData()
|
||||
{
|
||||
// Check parent
|
||||
if (!FileLoader::prepareLoadedData())
|
||||
return false;
|
||||
|
||||
// Check and prepare MHDR
|
||||
a_grid = (adt_MHDR *)(GetData()+8+version->size);
|
||||
if (!a_grid->prepareLoadedData())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adt_MHDR::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MHDRMagic.fcc)
|
||||
return false;
|
||||
|
||||
if (size!=sizeof(adt_MHDR)-8)
|
||||
return false;
|
||||
|
||||
// Check and prepare MCIN
|
||||
if (offsMCIN && !getMCIN()->prepareLoadedData())
|
||||
return false;
|
||||
|
||||
// Check and prepare MH2O
|
||||
if (offsMH2O && !getMH2O()->prepareLoadedData())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adt_MCIN::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MCINMagic.fcc)
|
||||
return false;
|
||||
|
||||
// Check cells data
|
||||
for (int i=0; i<ADT_CELLS_PER_GRID;i++)
|
||||
for (int j=0; j<ADT_CELLS_PER_GRID;j++)
|
||||
if (cells[i][j].offsMCNK && !getMCNK(i,j)->prepareLoadedData())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adt_MH2O::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MH2OMagic.fcc)
|
||||
return false;
|
||||
|
||||
// Check liquid data
|
||||
// for (int i=0; i<ADT_CELLS_PER_GRID;i++)
|
||||
// for (int j=0; j<ADT_CELLS_PER_GRID;j++)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adt_MCNK::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MCNKMagic.fcc)
|
||||
return false;
|
||||
|
||||
// Check height map
|
||||
if (offsMCVT && !getMCVT()->prepareLoadedData())
|
||||
return false;
|
||||
// Check liquid data
|
||||
if (offsMCLQ && !getMCLQ()->prepareLoadedData())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adt_MCVT::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MCVTMagic.fcc)
|
||||
return false;
|
||||
|
||||
if (size != sizeof(adt_MCVT)-8)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool adt_MCLQ::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MCLQMagic.fcc)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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 ADT_H
|
||||
#define ADT_H
|
||||
|
||||
#include "loadlib.h"
|
||||
|
||||
#define TILESIZE (533.33333f)
|
||||
#define CHUNKSIZE ((TILESIZE) / 16.0f)
|
||||
#define UNITSIZE (CHUNKSIZE / 8.0f)
|
||||
|
||||
enum LiquidType
|
||||
{
|
||||
LIQUID_TYPE_WATER = 0,
|
||||
LIQUID_TYPE_OCEAN = 1,
|
||||
LIQUID_TYPE_MAGMA = 2,
|
||||
LIQUID_TYPE_SLIME = 3
|
||||
};
|
||||
|
||||
//**************************************************************************************
|
||||
// ADT file class
|
||||
//**************************************************************************************
|
||||
#define ADT_CELLS_PER_GRID 16
|
||||
#define ADT_CELL_SIZE 8
|
||||
#define ADT_GRID_SIZE (ADT_CELLS_PER_GRID*ADT_CELL_SIZE)
|
||||
|
||||
//
|
||||
// Adt file height map chunk
|
||||
//
|
||||
class adt_MCVT
|
||||
{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
public:
|
||||
float height_map[(ADT_CELL_SIZE+1)*(ADT_CELL_SIZE+1)+ADT_CELL_SIZE*ADT_CELL_SIZE];
|
||||
|
||||
bool prepareLoadedData();
|
||||
};
|
||||
|
||||
//
|
||||
// Adt file liquid map chunk (old)
|
||||
//
|
||||
class adt_MCLQ
|
||||
{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
public:
|
||||
float height1;
|
||||
float height2;
|
||||
struct liquid_data{
|
||||
uint32 light;
|
||||
float height;
|
||||
} liquid[ADT_CELL_SIZE+1][ADT_CELL_SIZE+1];
|
||||
|
||||
// 1<<0 - ochen
|
||||
// 1<<1 - lava/slime
|
||||
// 1<<2 - water
|
||||
// 1<<6 - all water
|
||||
// 1<<7 - dark water
|
||||
// == 0x0F - not show liquid
|
||||
uint8 flags[ADT_CELL_SIZE][ADT_CELL_SIZE];
|
||||
uint8 data[84];
|
||||
bool prepareLoadedData();
|
||||
};
|
||||
|
||||
//
|
||||
// Adt file cell chunk
|
||||
//
|
||||
class adt_MCNK
|
||||
{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
public:
|
||||
uint32 flags;
|
||||
uint32 ix;
|
||||
uint32 iy;
|
||||
uint32 nLayers;
|
||||
uint32 nDoodadRefs;
|
||||
uint32 offsMCVT; // height map
|
||||
uint32 offsMCNR; // Normal vectors for each vertex
|
||||
uint32 offsMCLY; // Texture layer definitions
|
||||
uint32 offsMCRF; // A list of indices into the parent file's MDDF chunk
|
||||
uint32 offsMCAL; // Alpha maps for additional texture layers
|
||||
uint32 sizeMCAL;
|
||||
uint32 offsMCSH; // Shadow map for static shadows on the terrain
|
||||
uint32 sizeMCSH;
|
||||
uint32 areaid;
|
||||
uint32 nMapObjRefs;
|
||||
uint32 holes;
|
||||
uint16 s[2];
|
||||
uint32 data1;
|
||||
uint32 data2;
|
||||
uint32 data3;
|
||||
uint32 predTex;
|
||||
uint32 nEffectDoodad;
|
||||
uint32 offsMCSE;
|
||||
uint32 nSndEmitters;
|
||||
uint32 offsMCLQ; // Liqid level (old)
|
||||
uint32 sizeMCLQ; //
|
||||
float zpos;
|
||||
float xpos;
|
||||
float ypos;
|
||||
uint32 offsMCCV; // offsColorValues in WotLK
|
||||
uint32 props;
|
||||
uint32 effectId;
|
||||
|
||||
bool prepareLoadedData();
|
||||
adt_MCVT *getMCVT()
|
||||
{
|
||||
if (offsMCVT)
|
||||
return (adt_MCVT *)((uint8 *)this + offsMCVT);
|
||||
return 0;
|
||||
}
|
||||
adt_MCLQ *getMCLQ()
|
||||
{
|
||||
if (offsMCLQ)
|
||||
return (adt_MCLQ *)((uint8 *)this + offsMCLQ);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Adt file grid chunk
|
||||
//
|
||||
class adt_MCIN
|
||||
{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
public:
|
||||
struct adt_CELLS{
|
||||
uint32 offsMCNK;
|
||||
uint32 size;
|
||||
uint32 flags;
|
||||
uint32 asyncId;
|
||||
} cells[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
|
||||
|
||||
bool prepareLoadedData();
|
||||
// offset from begin file (used this-84)
|
||||
adt_MCNK *getMCNK(int x, int y)
|
||||
{
|
||||
if (cells[x][y].offsMCNK)
|
||||
return (adt_MCNK *)((uint8 *)this + cells[x][y].offsMCNK - 84);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
#define ADT_LIQUID_HEADER_FULL_LIGHT 0x01
|
||||
#define ADT_LIQUID_HEADER_NO_HIGHT 0x02
|
||||
|
||||
struct adt_liquid_header{
|
||||
uint16 liquidType; // Index from LiquidType.dbc
|
||||
uint16 formatFlags;
|
||||
float heightLevel1;
|
||||
float heightLevel2;
|
||||
uint8 xOffset;
|
||||
uint8 yOffset;
|
||||
uint8 width;
|
||||
uint8 height;
|
||||
uint32 offsData2a;
|
||||
uint32 offsData2b;
|
||||
};
|
||||
|
||||
//
|
||||
// Adt file liquid data chunk (new)
|
||||
//
|
||||
class adt_MH2O
|
||||
{
|
||||
public:
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
|
||||
struct adt_LIQUID{
|
||||
uint32 offsData1;
|
||||
uint32 used;
|
||||
uint32 offsData2;
|
||||
} liquid[ADT_CELLS_PER_GRID][ADT_CELLS_PER_GRID];
|
||||
|
||||
bool prepareLoadedData();
|
||||
|
||||
adt_liquid_header *getLiquidData(int x, int y)
|
||||
{
|
||||
if (liquid[x][y].used && liquid[x][y].offsData1)
|
||||
return (adt_liquid_header *)((uint8*)this + 8 + liquid[x][y].offsData1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
float *getLiquidHeightMap(adt_liquid_header *h)
|
||||
{
|
||||
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
|
||||
return 0;
|
||||
if (h->offsData2b)
|
||||
return (float *)((uint8*)this + 8 + h->offsData2b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8 *getLiquidLightMap(adt_liquid_header *h)
|
||||
{
|
||||
if (h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT)
|
||||
return 0;
|
||||
if (h->offsData2b)
|
||||
{
|
||||
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
|
||||
return (uint8 *)((uint8*)this + 8 + h->offsData2b);
|
||||
return (uint8 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint32 *getLiquidFullLightMap(adt_liquid_header *h)
|
||||
{
|
||||
if (!(h->formatFlags&ADT_LIQUID_HEADER_FULL_LIGHT))
|
||||
return 0;
|
||||
if (h->offsData2b)
|
||||
{
|
||||
if (h->formatFlags & ADT_LIQUID_HEADER_NO_HIGHT)
|
||||
return (uint32 *)((uint8*)this + 8 + h->offsData2b);
|
||||
return (uint32 *)((uint8*)this + 8 + h->offsData2b + (h->width+1)*(h->height+1)*4);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64 getLiquidShowMap(adt_liquid_header *h)
|
||||
{
|
||||
if (h->offsData2a)
|
||||
return *((uint64 *)((uint8*)this + 8 + h->offsData2a));
|
||||
else
|
||||
return 0xFFFFFFFFFFFFFFFFuLL;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//
|
||||
// Adt file header chunk
|
||||
//
|
||||
class adt_MHDR
|
||||
{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
|
||||
uint32 pad;
|
||||
uint32 offsMCIN; // MCIN
|
||||
uint32 offsTex; // MTEX
|
||||
uint32 offsModels; // MMDX
|
||||
uint32 offsModelsIds; // MMID
|
||||
uint32 offsMapObejcts; // MWMO
|
||||
uint32 offsMapObejctsIds; // MWID
|
||||
uint32 offsDoodsDef; // MDDF
|
||||
uint32 offsObjectsDef; // MODF
|
||||
uint32 offsMFBO; // MFBO
|
||||
uint32 offsMH2O; // MH2O
|
||||
uint32 data1;
|
||||
uint32 data2;
|
||||
uint32 data3;
|
||||
uint32 data4;
|
||||
uint32 data5;
|
||||
public:
|
||||
bool prepareLoadedData();
|
||||
adt_MCIN *getMCIN(){ return (adt_MCIN *)((uint8 *)&pad+offsMCIN);}
|
||||
adt_MH2O *getMH2O(){ return offsMH2O ? (adt_MH2O *)((uint8 *)&pad+offsMH2O) : 0;}
|
||||
|
||||
};
|
||||
|
||||
class ADT_file : public FileLoader{
|
||||
public:
|
||||
bool prepareLoadedData();
|
||||
ADT_file();
|
||||
~ADT_file();
|
||||
void free();
|
||||
|
||||
adt_MHDR *a_grid;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
|
||||
#include "dbcfile.h"
|
||||
#include "mpq_libmpq04.h"
|
||||
|
||||
DBCFile::DBCFile(const std::string& filename):
|
||||
filename(filename), recordSize(0), recordCount(0), fieldCount(0), stringSize(0), data(NULL), stringTable(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool DBCFile::open()
|
||||
{
|
||||
MPQFile f(filename.c_str());
|
||||
char header[4];
|
||||
unsigned int na,nb,es,ss;
|
||||
|
||||
if(f.read(header,4)!=4) // Number of records
|
||||
return false;
|
||||
|
||||
if(header[0]!='W' || header[1]!='D' || header[2]!='B' || header[3]!='C')
|
||||
return false;
|
||||
|
||||
if(f.read(&na,4)!=4) // Number of records
|
||||
return false;
|
||||
if(f.read(&nb,4)!=4) // Number of fields
|
||||
return false;
|
||||
if(f.read(&es,4)!=4) // Size of a record
|
||||
return false;
|
||||
if(f.read(&ss,4)!=4) // String size
|
||||
return false;
|
||||
|
||||
recordSize = es;
|
||||
recordCount = na;
|
||||
fieldCount = nb;
|
||||
stringSize = ss;
|
||||
if(fieldCount*4 != recordSize)
|
||||
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)
|
||||
return false;
|
||||
f.close();
|
||||
return true;
|
||||
}
|
||||
DBCFile::~DBCFile()
|
||||
{
|
||||
delete [] data;
|
||||
}
|
||||
|
||||
DBCFile::Record DBCFile::getRecord(size_t id)
|
||||
{
|
||||
assert(data);
|
||||
return Record(*this, data + id*recordSize);
|
||||
}
|
||||
|
||||
size_t DBCFile::getMaxId()
|
||||
{
|
||||
assert(data);
|
||||
|
||||
size_t maxId = 0;
|
||||
for(size_t i = 0; i < getRecordCount(); ++i)
|
||||
{
|
||||
if(maxId < getRecord(i).getUInt(0))
|
||||
maxId = getRecord(i).getUInt(0);
|
||||
}
|
||||
return maxId;
|
||||
}
|
||||
|
||||
DBCFile::Iterator DBCFile::begin()
|
||||
{
|
||||
assert(data);
|
||||
return Iterator(*this, data);
|
||||
}
|
||||
DBCFile::Iterator DBCFile::end()
|
||||
{
|
||||
assert(data);
|
||||
return Iterator(*this, stringTable);
|
||||
}
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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 DBCFILE_H
|
||||
#define DBCFILE_H
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
|
||||
class DBCFile
|
||||
{
|
||||
public:
|
||||
DBCFile(const std::string &filename);
|
||||
~DBCFile();
|
||||
|
||||
// Open database. It must be openened before it can be used.
|
||||
bool open();
|
||||
|
||||
// Database exceptions
|
||||
class Exception
|
||||
{
|
||||
public:
|
||||
Exception(const std::string &message): message(message)
|
||||
{ }
|
||||
virtual ~Exception()
|
||||
{ }
|
||||
const std::string &getMessage() {return message;}
|
||||
private:
|
||||
std::string message;
|
||||
};
|
||||
class NotFound: public Exception
|
||||
{
|
||||
public:
|
||||
NotFound(): Exception("Key was not found")
|
||||
{ }
|
||||
};
|
||||
// Iteration over database
|
||||
class Iterator;
|
||||
class Record
|
||||
{
|
||||
public:
|
||||
float getFloat(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<float*>(offset+field*4);
|
||||
}
|
||||
unsigned int getUInt(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<unsigned int*>(offset+field*4);
|
||||
}
|
||||
int getInt(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
return *reinterpret_cast<int*>(offset+field*4);
|
||||
}
|
||||
const char *getString(size_t field) const
|
||||
{
|
||||
assert(field < file.fieldCount);
|
||||
size_t stringOffset = getUInt(field);
|
||||
assert(stringOffset < file.stringSize);
|
||||
return reinterpret_cast<char*>(file.stringTable + stringOffset);
|
||||
}
|
||||
private:
|
||||
Record(DBCFile &file, unsigned char *offset): file(file), offset(offset) {}
|
||||
DBCFile &file;
|
||||
unsigned char *offset;
|
||||
|
||||
friend class DBCFile;
|
||||
friend class DBCFile::Iterator;
|
||||
};
|
||||
/** Iterator that iterates over records
|
||||
*/
|
||||
class Iterator
|
||||
{
|
||||
public:
|
||||
Iterator(DBCFile &file, unsigned char *offset):
|
||||
record(file, offset) {}
|
||||
/// Advance (prefix only)
|
||||
Iterator & operator++() {
|
||||
record.offset += record.file.recordSize;
|
||||
return *this;
|
||||
}
|
||||
/// Return address of current instance
|
||||
Record const & operator*() const { return record; }
|
||||
const Record* operator->() const {
|
||||
return &record;
|
||||
}
|
||||
/// Comparison
|
||||
bool operator==(const Iterator &b) const
|
||||
{
|
||||
return record.offset == b.record.offset;
|
||||
}
|
||||
bool operator!=(const Iterator &b) const
|
||||
{
|
||||
return record.offset != b.record.offset;
|
||||
}
|
||||
private:
|
||||
Record record;
|
||||
};
|
||||
|
||||
// Get record by id
|
||||
Record getRecord(size_t id);
|
||||
/// Get begin iterator over records
|
||||
Iterator begin();
|
||||
/// Get begin iterator over records
|
||||
Iterator end();
|
||||
/// Trivial
|
||||
size_t getRecordCount() const { return recordCount;}
|
||||
size_t getFieldCount() const { return fieldCount; }
|
||||
size_t getMaxId();
|
||||
private:
|
||||
std::string filename;
|
||||
size_t recordSize;
|
||||
size_t recordCount;
|
||||
size_t fieldCount;
|
||||
size_t stringSize;
|
||||
unsigned char *data;
|
||||
unsigned char *stringTable;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
|
||||
#include "loadlib.h"
|
||||
#include "mpq_libmpq04.h"
|
||||
#include <cstdio>
|
||||
|
||||
class MPQFile;
|
||||
|
||||
u_map_fcc MverMagic = { {'R','E','V','M'} };
|
||||
|
||||
FileLoader::FileLoader()
|
||||
{
|
||||
data = 0;
|
||||
data_size = 0;
|
||||
version = 0;
|
||||
}
|
||||
|
||||
FileLoader::~FileLoader()
|
||||
{
|
||||
free();
|
||||
}
|
||||
|
||||
bool FileLoader::loadFile(char *filename, bool log)
|
||||
{
|
||||
free();
|
||||
MPQFile mf(filename);
|
||||
if(mf.isEof())
|
||||
{
|
||||
if (log)
|
||||
printf("No such file %s\n", filename);
|
||||
return false;
|
||||
}
|
||||
|
||||
data_size = mf.getSize();
|
||||
|
||||
data = new uint8 [data_size];
|
||||
mf.read(data, data_size);
|
||||
mf.close();
|
||||
if (prepareLoadedData())
|
||||
return true;
|
||||
|
||||
printf("Error loading %s", filename);
|
||||
mf.close();
|
||||
free();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool FileLoader::prepareLoadedData()
|
||||
{
|
||||
// Check version
|
||||
version = (file_MVER *) data;
|
||||
if (version->fcc != MverMagic.fcc)
|
||||
return false;
|
||||
if (version->ver != FILE_FORMAT_VERSION)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void FileLoader::free()
|
||||
{
|
||||
if (data) delete[] data;
|
||||
data = 0;
|
||||
data_size = 0;
|
||||
version = 0;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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 LOAD_LIB_H
|
||||
#define LOAD_LIB_H
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef __int64 int64;
|
||||
typedef __int32 int32;
|
||||
typedef __int16 int16;
|
||||
typedef __int8 int8;
|
||||
typedef unsigned __int64 uint64;
|
||||
typedef unsigned __int32 uint32;
|
||||
typedef unsigned __int16 uint16;
|
||||
typedef unsigned __int8 uint8;
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#ifndef uint64_t
|
||||
#ifdef __linux__
|
||||
#include <linux/types.h>
|
||||
#endif
|
||||
#endif
|
||||
typedef int64_t int64;
|
||||
typedef int32_t int32;
|
||||
typedef int16_t int16;
|
||||
typedef int8_t int8;
|
||||
typedef uint64_t uint64;
|
||||
typedef uint32_t uint32;
|
||||
typedef uint16_t uint16;
|
||||
typedef uint8_t uint8;
|
||||
#endif
|
||||
|
||||
#define FILE_FORMAT_VERSION 18
|
||||
|
||||
union u_map_fcc
|
||||
{
|
||||
char fcc_txt[4];
|
||||
uint32 fcc;
|
||||
};
|
||||
|
||||
//
|
||||
// File version chunk
|
||||
//
|
||||
struct file_MVER
|
||||
{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
uint32 size;
|
||||
uint32 ver;
|
||||
};
|
||||
|
||||
class FileLoader{
|
||||
uint8 *data;
|
||||
uint32 data_size;
|
||||
public:
|
||||
virtual bool prepareLoadedData();
|
||||
uint8 *GetData() {return data;}
|
||||
uint32 GetDataSize() {return data_size;}
|
||||
|
||||
file_MVER *version;
|
||||
FileLoader();
|
||||
~FileLoader();
|
||||
bool loadFile(char *filename, bool log = true);
|
||||
virtual void free();
|
||||
};
|
||||
#endif
|
||||
@@ -1,129 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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 "mpq_libmpq04.h"
|
||||
#include <deque>
|
||||
#include <cstdio>
|
||||
|
||||
ArchiveSet gOpenArchives;
|
||||
|
||||
MPQArchive::MPQArchive(const char* filename)
|
||||
{
|
||||
int result = libmpq__archive_open(&mpq_a, filename, -1);
|
||||
printf("Opening %s\n", filename);
|
||||
if(result) {
|
||||
switch(result) {
|
||||
case LIBMPQ_ERROR_OPEN :
|
||||
printf("Error opening archive '%s': Does file really exist?\n", filename);
|
||||
break;
|
||||
case LIBMPQ_ERROR_FORMAT : /* bad file format */
|
||||
printf("Error opening archive '%s': Bad file format\n", filename);
|
||||
break;
|
||||
case LIBMPQ_ERROR_SEEK : /* seeking in file failed */
|
||||
printf("Error opening archive '%s': Seeking in file failed\n", filename);
|
||||
break;
|
||||
case LIBMPQ_ERROR_READ : /* Read error in archive */
|
||||
printf("Error opening archive '%s': Read error in archive\n", filename);
|
||||
break;
|
||||
case LIBMPQ_ERROR_MALLOC : /* maybe not enough memory? :) */
|
||||
printf("Error opening archive '%s': Maybe not enough memory\n", filename);
|
||||
break;
|
||||
default:
|
||||
printf("Error opening archive '%s': Unknown error\n", filename);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
gOpenArchives.push_front(this);
|
||||
}
|
||||
|
||||
void MPQArchive::close()
|
||||
{
|
||||
//gOpenArchives.erase(erase(&mpq_a);
|
||||
libmpq__archive_close(mpq_a);
|
||||
}
|
||||
|
||||
MPQFile::MPQFile(const char* filename):
|
||||
eof(false),
|
||||
buffer(0),
|
||||
pointer(0),
|
||||
size(0)
|
||||
{
|
||||
for(ArchiveSet::iterator i=gOpenArchives.begin(); i!=gOpenArchives.end();++i)
|
||||
{
|
||||
mpq_archive *mpq_a = (*i)->mpq_a;
|
||||
|
||||
uint32_t filenum;
|
||||
if(libmpq__file_number(mpq_a, filename, &filenum)) continue;
|
||||
libmpq__off_t transferred;
|
||||
libmpq__file_unpacked_size(mpq_a, filenum, &size);
|
||||
|
||||
// HACK: in patch.mpq some files don't want to open and give 1 for filesize
|
||||
if (size<=1) {
|
||||
// printf("warning: file %s has size %d; cannot read.\n", filename, size);
|
||||
eof = true;
|
||||
buffer = 0;
|
||||
return;
|
||||
}
|
||||
buffer = new char[size];
|
||||
|
||||
//libmpq_file_getdata
|
||||
libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
|
||||
/*libmpq_file_getdata(&mpq_a, hash, fileno, (unsigned char*)buffer);*/
|
||||
return;
|
||||
|
||||
}
|
||||
eof = true;
|
||||
buffer = 0;
|
||||
}
|
||||
|
||||
size_t MPQFile::read(void* dest, size_t bytes)
|
||||
{
|
||||
if (eof) return 0;
|
||||
|
||||
size_t rpos = pointer + bytes;
|
||||
if (rpos > size_t(size)) {
|
||||
bytes = size - pointer;
|
||||
eof = true;
|
||||
}
|
||||
|
||||
memcpy(dest, &(buffer[pointer]), bytes);
|
||||
|
||||
pointer = rpos;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void MPQFile::seek(int offset)
|
||||
{
|
||||
pointer = offset;
|
||||
eof = (pointer >= size);
|
||||
}
|
||||
|
||||
void MPQFile::seekRelative(int offset)
|
||||
{
|
||||
pointer += offset;
|
||||
eof = (pointer >= size);
|
||||
}
|
||||
|
||||
void MPQFile::close()
|
||||
{
|
||||
if (buffer) delete[] buffer;
|
||||
buffer = 0;
|
||||
eof = true;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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 MPQ_H
|
||||
#define MPQ_H
|
||||
|
||||
#include "loadlib/loadlib.h"
|
||||
#include "libmpq/mpq.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <deque>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class MPQArchive
|
||||
{
|
||||
|
||||
public:
|
||||
mpq_archive_s *mpq_a;
|
||||
|
||||
MPQArchive(const char* filename);
|
||||
~MPQArchive() { close(); }
|
||||
void close();
|
||||
|
||||
void GetFileListTo(vector<string>& filelist) {
|
||||
uint32_t filenum;
|
||||
if(libmpq__file_number(mpq_a, "(listfile)", &filenum)) return;
|
||||
libmpq__off_t size, transferred;
|
||||
libmpq__file_unpacked_size(mpq_a, filenum, &size);
|
||||
|
||||
char *buffer = new char[size+1];
|
||||
buffer[size] = '\0';
|
||||
|
||||
libmpq__file_read(mpq_a, filenum, (unsigned char*)buffer, size, &transferred);
|
||||
|
||||
char seps[] = "\n";
|
||||
char *token;
|
||||
|
||||
token = strtok( buffer, seps );
|
||||
uint32 counter = 0;
|
||||
while ((token != NULL) && (counter < size)) {
|
||||
//cout << token << endl;
|
||||
token[strlen(token) - 1] = 0;
|
||||
string s = token;
|
||||
filelist.push_back(s);
|
||||
counter += strlen(token) + 2;
|
||||
token = strtok(NULL, seps);
|
||||
}
|
||||
|
||||
delete[] buffer;
|
||||
}
|
||||
};
|
||||
typedef std::deque<MPQArchive*> ArchiveSet;
|
||||
|
||||
class MPQFile
|
||||
{
|
||||
//MPQHANDLE handle;
|
||||
bool eof;
|
||||
char *buffer;
|
||||
libmpq__off_t pointer,size;
|
||||
|
||||
// disable copying
|
||||
MPQFile(const MPQFile& /*f*/) {}
|
||||
void operator=(const MPQFile& /*f*/) {}
|
||||
|
||||
public:
|
||||
MPQFile(const char* filename); // filenames are not case sensitive
|
||||
~MPQFile() { close(); }
|
||||
size_t read(void* dest, size_t bytes);
|
||||
size_t getSize() { return size; }
|
||||
size_t getPos() { return pointer; }
|
||||
char* getBuffer() { return buffer; }
|
||||
char* getPointer() { return buffer + pointer; }
|
||||
bool isEof() { return eof; }
|
||||
void seek(int offset);
|
||||
void seekRelative(int offset);
|
||||
void close();
|
||||
};
|
||||
|
||||
inline void flipcc(char *fcc)
|
||||
{
|
||||
char t;
|
||||
t=fcc[0];
|
||||
fcc[0]=fcc[3];
|
||||
fcc[3]=t;
|
||||
t=fcc[1];
|
||||
fcc[1]=fcc[2];
|
||||
fcc[2]=t;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#define _CRT_SECURE_NO_DEPRECATE
|
||||
|
||||
#include "wdt.h"
|
||||
|
||||
u_map_fcc MWMOMagic = { {'O', 'M', 'W', 'M'} };
|
||||
u_map_fcc MPHDMagic = { {'D', 'H', 'P', 'M'} };
|
||||
u_map_fcc MAINMagic = { {'N', 'I', 'A', 'M'} };
|
||||
|
||||
bool wdt_MWMO::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MWMOMagic.fcc)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wdt_MPHD::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MPHDMagic.fcc)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wdt_MAIN::prepareLoadedData()
|
||||
{
|
||||
if (fcc != MAINMagic.fcc)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
WDT_file::WDT_file()
|
||||
{
|
||||
mphd = 0;
|
||||
main = 0;
|
||||
wmo = 0;
|
||||
}
|
||||
|
||||
WDT_file::~WDT_file()
|
||||
{
|
||||
free();
|
||||
}
|
||||
|
||||
void WDT_file::free()
|
||||
{
|
||||
mphd = 0;
|
||||
main = 0;
|
||||
wmo = 0;
|
||||
FileLoader::free();
|
||||
}
|
||||
|
||||
bool WDT_file::prepareLoadedData()
|
||||
{
|
||||
// Check parent
|
||||
if (!FileLoader::prepareLoadedData())
|
||||
return false;
|
||||
|
||||
mphd = (wdt_MPHD *)((uint8*)version+version->size+8);
|
||||
if (!mphd->prepareLoadedData())
|
||||
return false;
|
||||
main = (wdt_MAIN *)((uint8*)mphd + mphd->size+8);
|
||||
if (!main->prepareLoadedData())
|
||||
return false;
|
||||
wmo = (wdt_MWMO *)((uint8*)main+ main->size+8);
|
||||
if (!wmo->prepareLoadedData())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright (C)
|
||||
* Copyright (C)
|
||||
*
|
||||
* 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 WDT_H
|
||||
#define WDT_H
|
||||
#include "loadlib.h"
|
||||
|
||||
//**************************************************************************************
|
||||
// WDT file class and structures
|
||||
//**************************************************************************************
|
||||
#define WDT_MAP_SIZE 64
|
||||
|
||||
class wdt_MWMO{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
public:
|
||||
uint32 size;
|
||||
bool prepareLoadedData();
|
||||
};
|
||||
|
||||
class wdt_MPHD{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
public:
|
||||
uint32 size;
|
||||
|
||||
uint32 data1;
|
||||
uint32 data2;
|
||||
uint32 data3;
|
||||
uint32 data4;
|
||||
uint32 data5;
|
||||
uint32 data6;
|
||||
uint32 data7;
|
||||
uint32 data8;
|
||||
bool prepareLoadedData();
|
||||
};
|
||||
|
||||
class wdt_MAIN{
|
||||
union{
|
||||
uint32 fcc;
|
||||
char fcc_txt[4];
|
||||
};
|
||||
public:
|
||||
uint32 size;
|
||||
|
||||
struct adtData{
|
||||
uint32 exist;
|
||||
uint32 data1;
|
||||
} adt_list[64][64];
|
||||
|
||||
bool prepareLoadedData();
|
||||
};
|
||||
|
||||
class WDT_file : public FileLoader{
|
||||
public:
|
||||
bool prepareLoadedData();
|
||||
|
||||
WDT_file();
|
||||
~WDT_file();
|
||||
void free();
|
||||
|
||||
wdt_MPHD *mphd;
|
||||
wdt_MAIN *main;
|
||||
wdt_MWMO *wmo;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user