From 28abe4c6f94c38f7d758e057f96c0a6e3ca19990 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 24 Nov 2018 01:35:25 +0100 Subject: [PATCH] Variant2 exds are now readable --- deps/datReader/Exd.cpp | 33 ++++++++++++++++++++++-------- deps/datReader/Exh.h | 6 +++--- src/common/Exd/ExdDataGenerated.h | 16 +++++++++++++++ src/tools/exd_struct_test/main.cpp | 21 +++++++++++-------- 4 files changed, 56 insertions(+), 20 deletions(-) diff --git a/deps/datReader/Exd.cpp b/deps/datReader/Exd.cpp index f86ac318..e82fcc96 100644 --- a/deps/datReader/Exd.cpp +++ b/deps/datReader/Exd.cpp @@ -2,7 +2,7 @@ #include "bparse.h" #include "stream.h" - +#include #include "Exh.h" using xiv::utils::bparse::extract; @@ -58,7 +58,7 @@ namespace xiv for ( auto &file_ptr : _files ) { // Get a stream - std::vector< char > dataCpy = file_ptr->get_data_sections().front(); + std::vector< char > dataCpy = file_ptr->get_data_sections().front(); std::istringstream iss( std::string( dataCpy.begin(), dataCpy.end() ) ); // Extract the header and skip to the record indices @@ -101,12 +101,17 @@ namespace xiv iss.seekg( cacheEntryIt->second.offset + 6 ); uint8_t subRows = *reinterpret_cast< uint8_t* >( &dataCpy[ cacheEntryIt->second.offset + 5 ] ); - + + if( subRow >= subRows ) + throw std::runtime_error( "Out of bounds sub-row!" ); + + int offset = cacheEntryIt->second.offset + 6 + ( subRow * _exh->get_header().data_offset + 2 * ( subRow + 1 ) ); + for( auto& member_entry : _exh->get_exh_members() ) { - // Seek to the position of the member to extract. + // Seek to the position of the member to extract. // 6 is because we have uint32_t/uint16_t at the start of each record - iss.seekg( cacheEntryIt->second.offset + 6 + member_entry.offset ); + iss.seekg( offset + member_entry.offset ); // Switch depending on the type to extract switch( member_entry.type ) @@ -115,9 +120,10 @@ namespace xiv // Extract the offset to the actual string // Seek to it then extract the actual string { - auto string_offset = extract( iss, "string_offset", false ); - iss.seekg( cacheEntryIt->second.offset + 6 + _exh->get_header().data_offset + string_offset ); - fields.emplace_back( utils::bparse::extract_cstring( iss, "string" ) ); + throw std::runtime_error( "String not implemented for variant 2!" ); + //auto string_offset = extract( iss, "string_offset", false ); + //iss.seekg( cacheEntryIt->second.offset + 6 + _exh->get_header().data_offset + string_offset ); + //fields.emplace_back( utils::bparse::extract_cstring( iss, "string" ) ); } break; @@ -129,9 +135,18 @@ namespace xiv fields.emplace_back( extract( iss, "int8_t" ) ); break; + case DataType::uint8: + fields.emplace_back( extract( iss, "uint8_t" ) ); + break; + case DataType::int16: fields.emplace_back( extract( iss, "int16_t", false ) ); break; + + case DataType::uint16: + fields.emplace_back( extract( iss, "uint16_t", false ) ); + break; + case DataType::int32: fields.emplace_back( extract( iss, "int32_t", false ) ); break; @@ -184,7 +199,7 @@ namespace xiv fields.reserve( member_count ); iss.seekg( cacheEntryIt->second.offset + 6 ); - uint8_t subRows = *reinterpret_cast< uint8_t* >( &dataCpy[ cacheEntryIt->second.offset + 5 ] ); + uint8_t subRows = *reinterpret_cast< uint8_t* >( &dataCpy[ cacheEntryIt->second.offset + 5 ] ); for( auto& member_entry : _exh->get_exh_members() ) { diff --git a/deps/datReader/Exh.h b/deps/datReader/Exh.h index 80b11150..be273185 100644 --- a/deps/datReader/Exh.h +++ b/deps/datReader/Exh.h @@ -31,9 +31,9 @@ namespace xiv uint16_t field_count; uint16_t exd_count; uint16_t language_count; - uint16_t unknown1; - uint8_t u2; - uint8_t variant; + uint16_t unknown1; + uint8_t u2; + uint8_t variant; }; struct ExhMember diff --git a/src/common/Exd/ExdDataGenerated.h b/src/common/Exd/ExdDataGenerated.h index d4b76dc5..6eda3351 100644 --- a/src/common/Exd/ExdDataGenerated.h +++ b/src/common/Exd/ExdDataGenerated.h @@ -6117,6 +6117,22 @@ struct ZoneSharedGroup return nullptr; } + template< class T > + std::shared_ptr< T > get( uint32_t id, uint32_t slotId ) + { + try + { + auto info = std::make_shared< T >( id, slotId, this ); + return info; + } + catch( std::runtime_error error ) + { + std::cout << error.what(); + return nullptr; + } + return nullptr; + } + std::set< uint32_t > m_AchievementIdList; std::set< uint32_t > m_AchievementCategoryIdList; diff --git a/src/tools/exd_struct_test/main.cpp b/src/tools/exd_struct_test/main.cpp index a13d017b..ea4389d9 100644 --- a/src/tools/exd_struct_test/main.cpp +++ b/src/tools/exd_struct_test/main.cpp @@ -21,8 +21,8 @@ Core::Logger g_log; Core::Data::ExdDataGenerated g_exdData; -const std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" ); -//const std::string datLocation( "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack\\ffxiv" ); +//const std::string datLocation( "/opt/sapphire_3_15_0/bin/sqpack" ); +const std::string datLocation( "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" ); int main() @@ -38,15 +38,20 @@ int main() } - g_log.info( "getting id list " ); - auto idList = g_exdData.getTerritoryTypeIdList(); + //g_log.info( "getting id list " ); + //auto idList = g_exdData.getGilShopIdList(); - g_log.info( "getting id list done" ); - for( auto id : idList ) + //g_log.info( "getting id list done" ); + //for( auto id : idList ) { - auto teri1 = g_exdData.get< Core::Data::TerritoryType >( id ); + auto teri1 = g_exdData.get< Core::Data::GilShopItem >( 262440, 0 ); + g_log.info( "0 -> " + std::to_string( teri1->item ) ); - g_log.info( teri1->name ); + auto teri2 = g_exdData.get< Core::Data::GilShopItem >( 262440, 1 ); + g_log.info( "1 -> " + std::to_string( teri2->item ) ); + + auto teri3 = g_exdData.get< Core::Data::GilShopItem >( 262440, 2 ); + g_log.info( "2 -> " + std::to_string( teri3->item ) ); } return 0;