1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-12 13:37:46 +00:00

loads of datreader cleanup/consistency fixes

This commit is contained in:
NotAdam 2020-02-10 14:05:04 +11:00
parent b7ddb054f4
commit 5f18c43dd6
27 changed files with 1727 additions and 1734 deletions

View file

@ -4,14 +4,11 @@
#include "File.h"
namespace
{
namespace {
const uint32_t model_section_count = 0xB;
}
namespace xiv
{
namespace dat
namespace xiv::dat
{
struct DatFileHeader
{
@ -63,15 +60,9 @@ namespace dat
uint32_t block_id;
uint32_t block_count;
};
}
}
namespace xiv
{
namespace utils
{
namespace bparse
namespace xiv::utils::bparse
{
template<>
inline void reorder< xiv::dat::DatFileHeader >( xiv::dat::DatFileHeader& i_struct )
@ -79,7 +70,10 @@ namespace bparse
xiv::utils::bparse::reorder( i_struct.size );
xiv::utils::bparse::reorder( i_struct.entry_type );
xiv::utils::bparse::reorder( i_struct.total_uncompressed_size );
for (int32_t i = 0; i < 0x2; ++i) { xiv::utils::bparse::reorder(i_struct.unknown[i]); }
for( int32_t i = 0; i < 0x2; ++i )
{
xiv::utils::bparse::reorder( i_struct.unknown[ i ] );
}
}
template<>
@ -87,7 +81,10 @@ namespace bparse
{
xiv::utils::bparse::reorder( i_struct.offset );
xiv::utils::bparse::reorder( i_struct.size );
for (int32_t i = 0; i < 0x4; ++i) { xiv::utils::bparse::reorder(i_struct.unknown[i]); }
for( int32_t i = 0; i < 0x4; ++i )
{
xiv::utils::bparse::reorder( i_struct.unknown[ i ] );
}
xiv::utils::bparse::reorder( i_struct.block_hash );
}
@ -112,12 +109,30 @@ namespace bparse
inline void reorder< xiv::dat::DatMdlFileBlockInfos >( xiv::dat::DatMdlFileBlockInfos& i_struct )
{
xiv::utils::bparse::reorder( i_struct.unknown1 );
for (auto i = 0; i < ::model_section_count; ++i) { xiv::utils::bparse::reorder(i_struct.uncompressed_sizes[i]); }
for (auto i = 0; i < ::model_section_count; ++i) { xiv::utils::bparse::reorder(i_struct.compressed_sizes[i]); }
for (auto i = 0; i < ::model_section_count; ++i) { xiv::utils::bparse::reorder(i_struct.offsets[i]); }
for (auto i = 0; i < ::model_section_count; ++i) { xiv::utils::bparse::reorder(i_struct.block_ids[i]); }
for (auto i = 0; i < ::model_section_count; ++i) { xiv::utils::bparse::reorder(i_struct.block_counts[i]); }
for (auto i = 0; i < 0x2; ++i) { xiv::utils::bparse::reorder(i_struct.unknown2[i]); }
for( auto i = 0; i < ::model_section_count; ++i )
{
xiv::utils::bparse::reorder( i_struct.uncompressed_sizes[ i ] );
}
for( auto i = 0; i < ::model_section_count; ++i )
{
xiv::utils::bparse::reorder( i_struct.compressed_sizes[ i ] );
}
for( auto i = 0; i < ::model_section_count; ++i )
{
xiv::utils::bparse::reorder( i_struct.offsets[ i ] );
}
for( auto i = 0; i < ::model_section_count; ++i )
{
xiv::utils::bparse::reorder( i_struct.block_ids[ i ] );
}
for( auto i = 0; i < ::model_section_count; ++i )
{
xiv::utils::bparse::reorder( i_struct.block_counts[ i ] );
}
for( auto i = 0; i < 0x2; ++i )
{
xiv::utils::bparse::reorder( i_struct.unknown2[ i ] );
}
}
template<>
@ -130,14 +145,10 @@ namespace bparse
xiv::utils::bparse::reorder( i_struct.block_count );
}
}
}
};
using xiv::utils::bparse::extract;
namespace xiv
{
namespace dat
namespace xiv::dat
{
Dat::Dat( const std::filesystem::path& i_path, uint32_t i_nb ) :
@ -266,7 +277,8 @@ std::unique_ptr<File> Dat::getFile( uint32_t i_offset )
break;
default:
throw std::runtime_error("Invalid entry_type: " + std::to_string(static_cast<uint32_t>(file_header.entry_type)));
throw std::runtime_error(
"Invalid entry_type: " + std::to_string( static_cast<uint32_t>(file_header.entry_type) ) );
}
}
@ -308,4 +320,3 @@ uint32_t Dat::getNum() const
}
}
}

View file

@ -7,9 +7,7 @@
#include <filesystem>
namespace xiv
{
namespace dat
namespace xiv::dat
{
class File;
@ -39,7 +37,6 @@ protected:
uint32_t m_num;
};
}
}
#endif // XIV_DAT_DAT_H

View file

@ -26,7 +26,7 @@ Cat::Cat( const std::filesystem::path& basePath, uint32_t catNum, const std::str
// For all dat files linked to this index, create it: XX0000.win32.datX
for( uint32_t i = 0; i < getIndex().getDatCount(); ++i )
{
m_dats.emplace_back( std::unique_ptr<Dat>( new Dat( basePath / "ffxiv" / ( prefix + ".dat" + std::to_string( i ) ), i ) ) );
m_dats.emplace_back( std::make_unique< Dat >(basePath / "ffxiv" / ( prefix + ".dat" + std::to_string( i ) ), i ) );
}
}
@ -36,12 +36,12 @@ Cat::Cat( const std::filesystem::path& basePath, uint32_t catNum, const std::str
m_chunk( chunk )
{
// Creates the index: XX0000.win32.index
m_index = std::unique_ptr<Index>( new Index( basePath / GameData::buildDatStr( "ex" + std::to_string( exNum ), catNum, exNum, chunk, "win32", "index" ) ) );
m_index = std::make_unique< Index >( basePath / GameData::buildDatStr( "ex" + std::to_string( exNum ), catNum, exNum, chunk, "win32", "index" ) );
// For all dat files linked to this index, create it: XX0000.win32.datX
for( uint32_t i = 0; i < getIndex().getDatCount(); ++i )
{
m_dats.emplace_back( std::unique_ptr<Dat>( new Dat( basePath / GameData::buildDatStr( "ex" + std::to_string( exNum ), catNum, exNum, chunk, "win32", "dat" + std::to_string( i ) ), i ) ) );
m_dats.emplace_back( std::make_unique< Dat >( basePath / GameData::buildDatStr( "ex" + std::to_string( exNum ), catNum, exNum, chunk, "win32", "dat" + std::to_string( i ) ), i ) );
}
}

View file

@ -5,11 +5,13 @@
#include <vector>
#include <filesystem>
namespace xiv {
namespace dat {
namespace xiv::dat
{
class Index;
class Dat;
class File;
// A category represents an .index and its associated .datX
@ -26,7 +28,9 @@ public:
// name: The name of the category, empty if not known
// exNum: The number of the expansion to load from
// chunk: The chunk to load from
Cat( const std::filesystem::path& basePath, uint32_t catNum, const std::string& name, uint32_t exNum, uint32_t chunk );
Cat( const std::filesystem::path& basePath, uint32_t catNum, const std::string& name, uint32_t exNum,
uint32_t chunk );
~Cat();
// Returns .index of the category
@ -37,6 +41,7 @@ public:
bool doesFileExist( uint32_t dir_hash, uint32_t filename_hash ) const;
bool doesDirExist( uint32_t dir_hash ) const;
@ -58,7 +63,6 @@ protected:
std::vector< std::unique_ptr< Dat>> m_dats;
};
}
}
#endif // XIV_DAT_CAT_H

View file

@ -8,11 +8,8 @@
using xiv::utils::bparse::extract;
namespace xiv
namespace xiv::exd
{
namespace exd
{
struct ExdHeader
{
char magic[0x4];
@ -26,27 +23,36 @@ namespace xiv
uint32_t id;
uint32_t offset;
};
}
}
namespace xiv
namespace xiv::utils::bparse {
template<>
inline void reorder< xiv::exd::ExdHeader >( xiv::exd::ExdHeader& i_struct )
{
namespace utils
for( int32_t i = 0; i < 0x4; ++i )
{
namespace bparse
{
template <> inline void reorder<xiv::exd::ExdHeader>( xiv::exd::ExdHeader& i_struct ) { for( int32_t i = 0; i < 0x4; ++i ) { xiv::utils::bparse::reorder( i_struct.magic[i] ); } i_struct.unknown = xiv::utils::bparse::byteswap( i_struct.unknown ); xiv::utils::bparse::reorder( i_struct.unknown ); i_struct.unknown2 = xiv::utils::bparse::byteswap( i_struct.unknown2 ); xiv::utils::bparse::reorder( i_struct.unknown2 ); i_struct.index_size = xiv::utils::bparse::byteswap( i_struct.index_size ); xiv::utils::bparse::reorder( i_struct.index_size ); }
template <> inline void reorder<xiv::exd::ExdRecordIndex>( xiv::exd::ExdRecordIndex& i_struct ) { i_struct.id = xiv::utils::bparse::byteswap( i_struct.id ); xiv::utils::bparse::reorder( i_struct.id ); i_struct.offset = xiv::utils::bparse::byteswap( i_struct.offset ); xiv::utils::bparse::reorder( i_struct.offset ); }
xiv::utils::bparse::reorder( i_struct.magic[ i ] );
}
i_struct.unknown = xiv::utils::bparse::byteswap( i_struct.unknown );
xiv::utils::bparse::reorder( i_struct.unknown );
i_struct.unknown2 = xiv::utils::bparse::byteswap( i_struct.unknown2 );
xiv::utils::bparse::reorder( i_struct.unknown2 );
i_struct.index_size = xiv::utils::bparse::byteswap( i_struct.index_size );
xiv::utils::bparse::reorder( i_struct.index_size );
}
template<>
inline void reorder< xiv::exd::ExdRecordIndex >( xiv::exd::ExdRecordIndex& i_struct )
{
i_struct.id = xiv::utils::bparse::byteswap( i_struct.id );
xiv::utils::bparse::reorder( i_struct.id );
i_struct.offset = xiv::utils::bparse::byteswap( i_struct.offset );
xiv::utils::bparse::reorder( i_struct.offset );
}
};
namespace xiv
namespace xiv::exd
{
namespace exd
{
Exd::Exd( std::shared_ptr< Exh > i_exh, const std::vector< std::shared_ptr< dat::File>>& i_files )
{
_exh = i_exh;
@ -376,5 +382,4 @@ namespace xiv
}
}
}

12
deps/datReader/Exd.h vendored
View file

@ -8,9 +8,7 @@
#include "File.h"
namespace xiv
{
namespace exd
namespace xiv::exd
{
class Exh;
@ -40,8 +38,12 @@ class Exd
public:
// i_exh: the header
// i_files: the multiple exd files
Exd() {}
Exd()
{
}
Exd( std::shared_ptr< Exh > i_exh, const std::vector< std::shared_ptr< dat::File>>& i_files );
~Exd();
// Get a row by its id
@ -49,6 +51,7 @@ public:
// Get a row by its id and sub-row
const std::vector< Field > get_row( uint32_t id, uint32_t subRow );
// Get all rows
const std::map< uint32_t, std::vector< Field>>& get_rows();
@ -60,7 +63,6 @@ protected:
std::map< uint32_t, ExdCacheEntry > _idCache;
};
}
}
#endif // XIV_EXD_EXD_H

View file

@ -11,19 +11,18 @@ namespace
{
// Suffix of the filenames given a language
std::map<xiv::exd::Language, std::string> language_map =
{{xiv::exd::Language::none, ""},
{
{xiv::exd::Language::none, ""},
{xiv::exd::Language::ja, "_ja"},
{xiv::exd::Language::en, "_en"},
{xiv::exd::Language::de, "_de"},
{xiv::exd::Language::fr, "_fr"},
{xiv::exd::Language::chs, "_chs"}};
{xiv::exd::Language::chs, "_chs"}
};
}
namespace xiv
namespace xiv::exd
{
namespace exd
{
Cat::Cat( dat::GameData& i_game_data, const std::string& i_name ) :
_name( i_name )
{
@ -44,10 +43,11 @@ namespace xiv
std::vector< std::shared_ptr< dat::File>> files;
for( auto& exd_def: _header->get_exd_defs() )
{
files.emplace_back( i_game_data.getFile("exd/" + i_name + "_" + std::to_string(exd_def.start_id) + language_map.at(language) + ".exd") );
files.emplace_back( i_game_data.getFile(
"exd/" + i_name + "_" + std::to_string( exd_def.start_id ) + language_map.at( language ) + ".exd" ) );
}
// Instantiate the data for this language
_data[language] = std::unique_ptr<Exd>(new Exd(_header, files));
_data[ language ] = std::make_unique< Exd >( _header, files );
}
}
}
@ -79,4 +79,3 @@ namespace xiv
}
}
}

View file

@ -7,10 +7,7 @@
#include "ExdCat.h"
namespace xiv
{
namespace exd
{
namespace xiv::exd {
ExdData::ExdData( dat::GameData& i_game_data ) try :
_game_data( i_game_data )
@ -42,7 +39,7 @@ ExdData::ExdData(dat::GameData& i_game_data) try :
// instantiate the creation mutex for this category
_cat_names.push_back( category );
_cats[ category ] = std::unique_ptr< Cat >();
_cat_creation_mutexes[category] = std::unique_ptr<std::mutex>(new std::mutex());
_cat_creation_mutexes[ category ] = std::make_unique< std::mutex >();
std::getline( stream, line );
}
@ -92,9 +89,8 @@ void ExdData::create_category(const std::string& i_cat_name)
// Maybe after unlocking it has already been created, so check (most likely if it blocked)
if( !_cats[ i_cat_name ] )
{
_cats[i_cat_name] = std::unique_ptr<Cat>(new Cat(_game_data, i_cat_name));
_cats[ i_cat_name ] = std::make_unique< Cat >( _game_data, i_cat_name );
}
}
}
}

View file

@ -7,10 +7,9 @@
using xiv::utils::bparse::extract;
namespace xiv
{
namespace exd
namespace xiv::exd
{
Exh::Exh( const dat::File& i_file )
{
// Get a stream from the file
@ -74,4 +73,3 @@ const std::vector<ExhMember>& Exh::get_exh_members() const
}
}
}

66
deps/datReader/Exh.h vendored
View file

@ -5,11 +5,10 @@
#include "bparse.h"
namespace xiv
namespace xiv::exd
{
namespace exd
{
enum class DataType : uint16_t
enum class DataType :
uint16_t
{
string = 0,
boolean = 1,
@ -47,32 +46,60 @@ namespace xiv
uint32_t start_id;
uint32_t count_id;
};
};
namespace xiv::utils::bparse {
template<>
inline void reorder< xiv::exd::ExhHeader >( xiv::exd::ExhHeader& i_struct )
{
for( int32_t i = 0; i < 0x4; ++i )
{
xiv::utils::bparse::reorder( i_struct.magic[ i ] );
}
i_struct.unknown = xiv::utils::bparse::byteswap( i_struct.unknown );
xiv::utils::bparse::reorder( i_struct.unknown );
i_struct.data_offset = xiv::utils::bparse::byteswap( i_struct.data_offset );
xiv::utils::bparse::reorder( i_struct.data_offset );
i_struct.field_count = xiv::utils::bparse::byteswap( i_struct.field_count );
xiv::utils::bparse::reorder( i_struct.field_count );
i_struct.exd_count = xiv::utils::bparse::byteswap( i_struct.exd_count );
xiv::utils::bparse::reorder( i_struct.exd_count );
i_struct.language_count = xiv::utils::bparse::byteswap( i_struct.language_count );
xiv::utils::bparse::reorder( i_struct.language_count );
}
template<>
inline void reorder< xiv::exd::ExhMember >( xiv::exd::ExhMember& i_struct )
{
i_struct.type = xiv::utils::bparse::byteswap( i_struct.type );
xiv::utils::bparse::reorder( i_struct.type );
i_struct.offset = xiv::utils::bparse::byteswap( i_struct.offset );
xiv::utils::bparse::reorder( i_struct.offset );
}
template<>
inline void reorder< xiv::exd::ExhExdDef >( xiv::exd::ExhExdDef& i_struct )
{
i_struct.start_id = xiv::utils::bparse::byteswap( i_struct.start_id );
xiv::utils::bparse::reorder( i_struct.start_id );
i_struct.count_id = xiv::utils::bparse::byteswap( i_struct.count_id );
xiv::utils::bparse::reorder( i_struct.count_id );
}
};
namespace xiv
{
namespace utils
{
namespace bparse
{
template <> inline void reorder<xiv::exd::ExhHeader>( xiv::exd::ExhHeader& i_struct ) { for( int32_t i = 0; i < 0x4; ++i ) { xiv::utils::bparse::reorder( i_struct.magic[i] ); } i_struct.unknown = xiv::utils::bparse::byteswap( i_struct.unknown ); xiv::utils::bparse::reorder( i_struct.unknown ); i_struct.data_offset = xiv::utils::bparse::byteswap( i_struct.data_offset ); xiv::utils::bparse::reorder( i_struct.data_offset ); i_struct.field_count = xiv::utils::bparse::byteswap( i_struct.field_count ); xiv::utils::bparse::reorder( i_struct.field_count ); i_struct.exd_count = xiv::utils::bparse::byteswap( i_struct.exd_count ); xiv::utils::bparse::reorder( i_struct.exd_count ); i_struct.language_count = xiv::utils::bparse::byteswap( i_struct.language_count ); xiv::utils::bparse::reorder( i_struct.language_count ); }
template <> inline void reorder<xiv::exd::ExhMember>( xiv::exd::ExhMember& i_struct ) { i_struct.type = xiv::utils::bparse::byteswap( i_struct.type ); xiv::utils::bparse::reorder( i_struct.type ); i_struct.offset = xiv::utils::bparse::byteswap( i_struct.offset ); xiv::utils::bparse::reorder( i_struct.offset ); }
template <> inline void reorder<xiv::exd::ExhExdDef>( xiv::exd::ExhExdDef& i_struct ) { i_struct.start_id = xiv::utils::bparse::byteswap( i_struct.start_id ); xiv::utils::bparse::reorder( i_struct.start_id ); i_struct.count_id = xiv::utils::bparse::byteswap( i_struct.count_id ); xiv::utils::bparse::reorder( i_struct.count_id ); }
}
}
};
namespace xiv
{
namespace dat
{
class File;
}
namespace exd
{
enum Language : uint16_t;
enum Language :
uint16_t;
// Header file for exd data
class Exh
@ -80,12 +107,17 @@ namespace xiv
public:
// The header file
Exh( const dat::File& i_file );
~Exh();
const ExhHeader& get_header() const;
const std::vector< ExhExdDef >& get_exd_defs() const;
const std::vector< Language >& get_languages() const;
const std::map< uint32_t, ExhMember >& get_members() const;
const std::vector< ExhMember >& get_exh_members() const;
protected:

View file

@ -2,9 +2,7 @@
#include <fstream>
namespace xiv
{
namespace dat
namespace xiv::dat
{
File::File() :
@ -42,4 +40,3 @@ void File::exportToFile(const std::filesystem::path& i_path) const
}
}
}

20
deps/datReader/File.h vendored
View file

@ -7,25 +7,16 @@
#include <stdint.h>
#include "bparse.h"
namespace xiv
namespace xiv::dat
{
namespace dat
{
enum class FileType : uint32_t
enum class FileType :
uint32_t
{
empty = 1,
standard = 2,
model = 3,
texture = 4,
};
}
};
namespace xiv
{
namespace dat
{
class Dat;
@ -33,14 +24,17 @@ namespace xiv
class File
{
friend class Dat;
public:
File();
~File();
FileType get_type() const;
// Getters functions for the data in the file
const std::vector< std::vector< char>>& get_data_sections() const;
std::vector< std::vector< char>>& access_data_sections();
void exportToFile( const std::filesystem::path& i_path ) const;
@ -49,8 +43,6 @@ namespace xiv
FileType _type;
std::vector< std::vector< char>> _data_sections;
};
}
}
#endif // XIV_DAT_FILE_H

View file

@ -11,8 +11,7 @@
#include "DatCat.h"
#include "File.h"
namespace
{
namespace {
// Relation between category number and category name
// These names are taken straight from the exe, it helps resolve dispatching when getting files by path
@ -48,11 +47,8 @@ namespace
{ 0x0C, "music" } };
}
namespace xiv
namespace xiv::dat
{
namespace dat
{
GameData::GameData( const std::filesystem::path& path ) try :
m_path( path )
{
@ -66,14 +62,17 @@ GameData::GameData(const std::filesystem::path& path) try :
#endif
// Determine which expansions are available
while( std::filesystem::exists( std::filesystem::path( m_path.string() + sep + "ex" + std::to_string( maxExLevel + 1 ) + sep + "ex" + std::to_string( maxExLevel + 1 ) + ".ver" ) ) )
while( std::filesystem::exists( std::filesystem::path(
m_path.string() + sep + "ex" + std::to_string( maxExLevel + 1 ) + sep + "ex" + std::to_string( maxExLevel + 1 ) +
".ver" ) ) )
{
maxExLevel++;
}
// Iterate over the files in path
for( auto it = std::filesystem::directory_iterator( m_path.string() + "//ffxiv" ); it != std::filesystem::directory_iterator(); ++it )
for( auto it = std::filesystem::directory_iterator( m_path.string() + "//ffxiv" );
it != std::filesystem::directory_iterator(); ++it )
{
// Get the filename of the current element
auto filename = it->path().filename().string();
@ -92,12 +91,13 @@ GameData::GameData(const std::filesystem::path& path) try :
// instantiate the creation mutex for this category
m_catNums.push_back( cat_nb );
m_cats[ cat_nb ] = std::unique_ptr< Cat >();
m_catCreationMutexes[cat_nb] = std::unique_ptr<std::mutex>( new std::mutex() );
m_catCreationMutexes[ cat_nb ] = std::make_unique< std::mutex >();
// Check for expansion
for( int exNum = 1; exNum <= maxExLevel; exNum++ )
{
const std::string path = m_path.string() + sep + buildDatStr( "ex" + std::to_string( exNum ), cat_nb, exNum, 0, "win32", "index" );
const std::string path =
m_path.string() + sep + buildDatStr( "ex" + std::to_string( exNum ), cat_nb, exNum, 0, "win32", "index" );
if( std::filesystem::exists( std::filesystem::path( path ) ) )
{
@ -106,7 +106,9 @@ GameData::GameData(const std::filesystem::path& path) try :
for( int chunkTest = 0; chunkTest < 256; chunkTest++ )
{
if( std::filesystem::exists( m_path.string() + sep + buildDatStr( "ex" + std::to_string( exNum ), cat_nb, exNum, chunkTest, "win32", "index" ) ) )
if( std::filesystem::exists( m_path.string() + sep +
buildDatStr( "ex" + std::to_string( exNum ), cat_nb, exNum, chunkTest, "win32",
"index" ) ) )
{
m_exCats[ cat_nb ].exNumToChunkMap[ exNum ].chunkToCatMap[ chunkTest ] = std::unique_ptr< Cat >();
chunkCount++;
@ -130,7 +132,8 @@ GameData::~GameData()
}
const std::string GameData::buildDatStr( const std::string folder, const int cat, const int exNum, const int chunk, const std::string platform, const std::string type )
const std::string GameData::buildDatStr( const std::string folder, const int cat, const int exNum, const int chunk,
const std::string platform, const std::string type )
{
char dat[1024];
sprintf( dat, "%s/%02x%02x%02x.%s.%s", folder.c_str(), cat, exNum, chunk, platform.c_str(), type.c_str() );
@ -290,7 +293,7 @@ void GameData::createCategory(uint32_t catNum)
}
// Actually creates the category
m_cats[catNum] = std::unique_ptr<Cat>( new Cat( m_path, catNum, catName ) );
m_cats[ catNum ] = std::make_unique< Cat >( m_path, catNum, catName );
}
}
@ -312,11 +315,11 @@ void GameData::createExCategory( uint32_t catNum )
for( auto const& chunk : m_exCats[ catNum ].exNumToChunkMap[ ex.first ].chunkToCatMap )
{
// Actually creates the category
m_exCats[catNum].exNumToChunkMap[ex.first].chunkToCatMap[chunk.first] = std::unique_ptr<Cat>( new Cat( m_path, catNum, catName, ex.first, chunk.first ) );
m_exCats[ catNum ].exNumToChunkMap[ ex.first ].chunkToCatMap[ chunk.first ] = std::unique_ptr< Cat >(
new Cat( m_path, catNum, catName, ex.first, chunk.first ) );
}
}
}
}
}
}

View file

@ -7,12 +7,11 @@
#include <filesystem>
namespace xiv
{
namespace dat
namespace xiv::dat
{
class Cat;
class File;
// Interface to all the datfiles - Main entry point
@ -22,15 +21,19 @@ class GameData
public:
// This should be the path in which the .index/.datX files are located
GameData( const std::filesystem::path& path );
~GameData();
static const std::string buildDatStr( const std::string folder, const int cat, const int exNum, const int chunk, const std::string platform, const std::string type );
static const std::string
buildDatStr( const std::string folder, const int cat, const int exNum, const int chunk, const std::string platform,
const std::string type );
// Returns all the scanned category number available in the path
const std::vector< uint32_t >& getCatNumbers() const;
// Return a specific category by its number (see getCatNumbers() for loops)
const Cat& getCategory( uint32_t catNum );
// Return a specific category by it's name (e.g.: "exd"/"game_script"/ etc...)
const Cat& getCategory( const std::string& catName );
@ -71,14 +74,19 @@ protected:
// Map of all EX categories and their chunks, "CatNum - (ExNum - (ChunkNum - Cat))"
// Map of all EX categories and their chunks, "CatNum - (ExNum - (ChunkNum - Cat))"
using ChunkToCatMap = struct { std::unordered_map< uint32_t, std::unique_ptr< Cat > > chunkToCatMap; };
using ExNumToChunkMap = struct { std::unordered_map< uint32_t, ChunkToCatMap > exNumToChunkMap; };
using ChunkToCatMap = struct
{
std::unordered_map< uint32_t, std::unique_ptr< Cat > > chunkToCatMap;
};
using ExNumToChunkMap = struct
{
std::unordered_map< uint32_t, ChunkToCatMap > exNumToChunkMap;
};
using CatNumToExNumMap = std::unordered_map< uint32_t, ExNumToChunkMap >;
CatNumToExNumMap m_exCats;
std::unordered_map< uint32_t, std::unique_ptr< std::mutex>> m_catCreationMutexes;
};
}
}
#endif // XIV_DAT_GAMEDATA_H

View file

@ -2,9 +2,7 @@
#include "bparse.h"
namespace xiv
{
namespace dat
namespace xiv::dat
{
struct IndexBlockRecord
{
@ -21,13 +19,8 @@ namespace dat
uint32_t padding;
};
}
}
namespace xiv
{
namespace utils
{
namespace bparse
namespace xiv::utils::bparse
{
template<>
inline void reorder< xiv::dat::IndexBlockRecord >( xiv::dat::IndexBlockRecord& i_struct )
@ -46,14 +39,10 @@ namespace bparse
xiv::utils::bparse::reorder( i_struct.padding );
}
}
}
};
using xiv::utils::bparse::extract;
namespace xiv
{
namespace dat
namespace xiv::dat
{
Index::Index( const std::filesystem::path& path ) :
@ -164,4 +153,3 @@ void Index::isIndexBlockValid( const IndexBlockRecord& i_index_block_record )
}
}
}

View file

@ -7,16 +7,18 @@
#include <filesystem>
namespace xiv {
namespace dat {
namespace xiv::dat
{
struct IndexBlockRecord;
class Index : public SqPack
class Index :
public SqPack
{
public:
// Full path to the index file
Index( const std::filesystem::path& i_path );
virtual ~Index();
// An entry in the hash table, representing a file in a given dat
@ -36,12 +38,15 @@ public:
uint32_t getDatCount() const;
bool doesFileExist( uint32_t dir_hash, uint32_t filename_hash ) const;
bool doesDirExist( uint32_t dir_hash ) const;
// Returns the whole HashTable
const HashTable& getHashTable() const;
// Returns the hash table for a specific dir
const DirHashTable& getDirHashTable( uint32_t dir_hash ) const;
// Returns the HashTableEntry for a given file given its hashes
const HashTableEntry& getHashTableEntry( uint32_t dir_hash, uint32_t filename_hash ) const;
@ -53,7 +58,6 @@ protected:
HashTable m_hashTable;
};
}
}
#endif // XIV_DAT_INDEX_H

View file

@ -8,23 +8,19 @@
#include "bparse.h"
namespace xiv
namespace xiv::dat
{
namespace dat
{
struct SqPackBlockHash
{
uint8_t hash[0x14];
uint32_t padding[0xB];
};
}
}
}
namespace xiv {
namespace utils {
namespace bparse {
template <> inline void reorder<xiv::dat::SqPackBlockHash>( xiv::dat::SqPackBlockHash& i_struct )
namespace xiv::utils::bparse
{
template<>
inline void reorder< xiv::dat::SqPackBlockHash >( xiv::dat::SqPackBlockHash& i_struct )
{
for( auto i = 0; i < 0x14; ++i )
{
@ -35,13 +31,9 @@ namespace xiv {
xiv::utils::bparse::reorder( i_struct.padding[ i ] );
}
}
}
}
};
namespace xiv
{
namespace dat
namespace xiv::dat
{
class SqPack
@ -50,6 +42,7 @@ class SqPack
public:
// Full path to the sqpack file
SqPack( const std::filesystem::path& i_path );
virtual ~SqPack();
protected:
@ -61,6 +54,5 @@ protected:
};
}
}
#endif // XIV_DAT_SQPACK_H

View file

@ -6,11 +6,7 @@
#include <sstream>
#include <vector>
namespace xiv
{
namespace utils
{
namespace bparse
namespace xiv::utils::bparse
{
// Internal macro for byteswapping
@ -40,7 +36,10 @@ void read(std::istream& i_stream, StructType& i_struct)
}
// By default a type does not need reordering
template <typename StructType> void reorder(StructType& i_struct) {}
template< typename StructType >
void reorder( StructType& i_struct )
{
}
// "Overload" for passed struct as arg
template< typename StructType >
@ -84,7 +83,8 @@ StructType extract(std::istream& i_stream, const std::string& i_name, bool i_is_
}
template< typename StructType >
void extract(std::istream& i_stream, const std::string& i_name, uint32_t i_size, std::vector<StructType>& o_structs, bool i_is_le = true)
void extract( std::istream& i_stream, const std::string& i_name, uint32_t i_size, std::vector< StructType >& o_structs,
bool i_is_le = true )
{
o_structs.reserve( i_size );
for( uint32_t i = 0; i < i_size; ++i )
@ -96,8 +96,6 @@ void extract(std::istream& i_stream, const std::string& i_name, uint32_t i_size,
// For cstrings
std::string extract_cstring( std::istream& i_stream, const std::string& i_name );
}
}
}
#endif // XIV_UTILS_BPARSE_H

View file

@ -1,8 +1,8 @@
#include "conv.h"
namespace xiv {
namespace utils {
namespace conv {
namespace xiv::utils::conv
{
float half2float( const uint16_t i_value )
{
uint32_t t1;
@ -30,6 +30,4 @@ namespace conv {
}
}
}
}

View file

@ -5,13 +5,11 @@
#include <vector>
#include <ostream>
namespace xiv {
namespace utils {
namespace conv {
namespace xiv::utils::conv
{
float half2float( const uint16_t i_value );
float ubyte2float( const uint8_t i_value );
}
}
}
#endif // XIV_UTILS_CONV_H

View file

@ -65,11 +65,7 @@ namespace internal
}
}
namespace xiv
{
namespace utils
{
namespace crc32
namespace xiv::utils::crc32
{
uint32_t compute( const std::string& i_input, uint32_t init_crc )
@ -130,7 +126,8 @@ void generate_hashes_1(std::string& i_format, const uint32_t i_first_index, std:
}
}
void generate_hashes_2(std::string& i_format, const uint32_t i_first_index, const uint32_t i_second_index, std::vector<uint32_t>& o_hashes)
void generate_hashes_2( std::string& i_format, const uint32_t i_first_index, const uint32_t i_second_index,
std::vector< uint32_t >& o_hashes )
{
char* str = const_cast<char*>(i_format.data());
const uint32_t str_size = i_format.size();
@ -176,5 +173,3 @@ void generate_hashes_2(std::string& i_format, const uint32_t i_first_index, cons
}
}
}

View file

@ -5,9 +5,8 @@
#include <vector>
#include <string>
namespace xiv {
namespace utils {
namespace crc32 {
namespace xiv::utils::crc32
{
// Normal crc32 computation from a given intial crc value, use zlib.crc32 instead, the final XOR 0xFFFFFFFF is not done
uint32_t compute( const std::string& i_input, uint32_t init_crc = 0xFFFFFFFF );
@ -17,10 +16,10 @@ namespace crc32 {
uint32_t rev_compute( const std::string& i_input, uint32_t init_crc = 0 );
void generate_hashes_1( std::string& i_format, const uint32_t i_first_index, std::vector< uint32_t >& o_hashes );
void generate_hashes_2( std::string& i_format, const uint32_t i_first_index, const uint32_t i_second_index, std::vector< uint32_t >& o_hashes );
}
}
void generate_hashes_2( std::string& i_format, const uint32_t i_first_index, const uint32_t i_second_index,
std::vector< uint32_t >& o_hashes );
}
#endif // XIV_UTILS_CRC32_H

View file

@ -4,13 +4,7 @@
#include <sstream>
#include <streambuf>
namespace xiv
{
namespace utils
{
namespace stream
namespace xiv::utils::stream
{
}
}
}

View file

@ -5,14 +5,11 @@
#include <iostream>
#include <vector>
namespace xiv
{
namespace utils
{
namespace stream
namespace xiv::utils::stream
{
template< typename CharT, typename TraitsT = std::char_traits< CharT > >
class vectorwrapbuf : public std::basic_streambuf<CharT, TraitsT>
class vectorwrapbuf :
public std::basic_streambuf< CharT, TraitsT >
{
public:
vectorwrapbuf( std::vector< CharT >& vec )
@ -21,7 +18,4 @@ public:
}
};
}
}
}
#endif // XIV_UTILS_STREAM_H

View file

@ -4,11 +4,7 @@
#include <zlib/zlib.h>
#include <vector>
namespace xiv
{
namespace utils
{
namespace zlib
namespace xiv::utils::zlib
{
void compress( const std::vector< char >& in, std::vector< char >& out )
@ -61,5 +57,3 @@ void no_header_decompress(uint8_t* in, uint32_t in_size, uint8_t* out, uint32_t
}
}
}
}

View file

@ -4,18 +4,13 @@
#include <cstdint>
#include <vector>
namespace xiv
{
namespace utils
{
namespace zlib
namespace xiv::utils::zlib
{
void compress( const std::vector< char >& in, std::vector< char >& out );
void no_header_decompress( uint8_t* in, uint32_t in_size, uint8_t* out, uint32_t out_size );
}
}
}
#endif // XIV_UTILS_ZLIB_H