2018-10-24 23:31:26 +11:00
|
|
|
#include "DatCat.h"
|
|
|
|
|
|
|
|
#include "Dat.h"
|
|
|
|
#include "File.h"
|
|
|
|
#include "GameData.h"
|
2023-04-23 15:30:18 +02:00
|
|
|
#include "Index.h"
|
2018-10-24 23:31:26 +11:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
namespace xiv::dat
|
2018-10-24 23:31:26 +11:00
|
|
|
{
|
2023-04-26 13:58:41 +02:00
|
|
|
Cat::Cat( const std::filesystem::path& basePath, uint32_t catNum, const std::string& name ) : m_name( name ),
|
|
|
|
m_catNum( catNum ),
|
|
|
|
m_chunk( -1 )
|
2023-04-23 15:30:18 +02:00
|
|
|
{
|
2023-04-26 13:58:41 +02:00
|
|
|
// Format the category number as a two-digit hex string
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << std::setw( 2 ) << std::setfill( '0' ) << std::hex << catNum;
|
|
|
|
std::string prefix = ss.str() + "0000.win32";
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
// Create an Index object using the formatted category number and basePath
|
|
|
|
m_index = std::make_unique< Index >( basePath / "ffxiv" / ( prefix + ".index" ) );
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
// Create Dat objects for each entry in the index
|
|
|
|
for( uint32_t i = 0; i < getIndex().getDatCount(); ++i )
|
2023-04-23 15:30:18 +02:00
|
|
|
{
|
2023-04-26 13:58:41 +02:00
|
|
|
m_dats.emplace_back( std::make_unique< Dat >( basePath / "ffxiv" / ( prefix + ".dat" + std::to_string( i ) ), i ) );
|
2023-04-23 15:30:18 +02:00
|
|
|
}
|
2023-04-26 13:58:41 +02:00
|
|
|
}
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
Cat::Cat( const std::filesystem::path& basePath, uint32_t catNum, const std::string& name, uint32_t exNum, uint32_t chunk ) : m_name( name ),
|
|
|
|
m_catNum( catNum ),
|
|
|
|
m_chunk( chunk )
|
|
|
|
{
|
|
|
|
// Create an Index object using the basePath and formatted information
|
|
|
|
m_index = std::make_unique< Index >( basePath / GameData::buildDatStr( "ex" + std::to_string( exNum ), catNum, exNum, chunk, "win32", "index" ) );
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
// Create Dat objects for each entry in the index
|
|
|
|
for( uint32_t i = 0; i < getIndex().getDatCount(); ++i )
|
2023-04-23 15:30:18 +02:00
|
|
|
{
|
2023-04-26 13:58:41 +02:00
|
|
|
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 ) );
|
2023-04-23 15:30:18 +02:00
|
|
|
}
|
2023-04-26 13:58:41 +02:00
|
|
|
}
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
Cat::~Cat() = default;
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
const Index& Cat::getIndex() const
|
|
|
|
{
|
|
|
|
return *m_index;
|
|
|
|
}
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
std::unique_ptr< File > Cat::getFile( uint32_t dir_hash, uint32_t filename_hash ) const
|
|
|
|
{
|
|
|
|
auto& hash_table_entry = getIndex().getHashTableEntry( dir_hash, filename_hash );
|
|
|
|
return m_dats[ hash_table_entry.datNum ]->getFile( hash_table_entry.datOffset );
|
|
|
|
}
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
bool Cat::doesFileExist( uint32_t dir_hash, uint32_t filename_hash ) const
|
|
|
|
{
|
|
|
|
return getIndex().doesFileExist( dir_hash, filename_hash );
|
|
|
|
}
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
bool Cat::doesDirExist( uint32_t dir_hash ) const
|
|
|
|
{
|
|
|
|
return getIndex().doesDirExist( dir_hash );
|
|
|
|
}
|
2023-04-23 15:30:18 +02:00
|
|
|
|
2023-04-26 13:58:41 +02:00
|
|
|
const std::string& Cat::getName() const
|
|
|
|
{
|
|
|
|
return m_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Cat::getCatNum() const
|
|
|
|
{
|
|
|
|
return m_catNum;
|
|
|
|
}
|
|
|
|
}// namespace xiv::dat
|