1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-27 06:47:45 +00:00

Fixed datreader

This commit is contained in:
mordred 2018-10-25 12:17:40 +02:00
parent dc46fea1b0
commit ec0322ce36
10 changed files with 80 additions and 87 deletions

View file

@ -52,18 +52,18 @@ namespace xiv
_exh = i_exh; _exh = i_exh;
_files = i_files; _files = i_files;
// Iterates over all the files // Iterates over all the files
const uint32_t member_count = _exh->get_members().size(); const uint32_t member_count = _exh->get_members().size();
for ( auto &file_ptr : _files ) for ( auto &file_ptr : _files )
{ {
// Get a stream // Get a stream
std::vector< char > dataCpy = file_ptr->get_data_sections().front(); std::vector< char > dataCpy = file_ptr->get_data_sections().front();
xiv::utils::stream::vectorwrapbuf<char> databuf(dataCpy); std::istringstream iss( std::string( dataCpy.begin(), dataCpy.end() ) );
std::istream stream(&databuf);
// Extract the header and skip to the record indices // Extract the header and skip to the record indices
auto exd_header = extract< ExdHeader >( stream ); auto exd_header = extract< ExdHeader >( iss );
stream.seekg( 0x20 ); iss.seekg( 0x20 );
// Preallocate and extract the record_indices // Preallocate and extract the record_indices
const uint32_t record_count = exd_header.index_size / sizeof( ExdRecordIndex ); const uint32_t record_count = exd_header.index_size / sizeof( ExdRecordIndex );
@ -71,7 +71,7 @@ namespace xiv
record_indices.reserve( record_count ); record_indices.reserve( record_count );
for ( uint32_t i = 0; i < record_count; ++i ) for ( uint32_t i = 0; i < record_count; ++i )
{ {
auto recordIndex = extract< ExdRecordIndex >( stream ); auto recordIndex = extract< ExdRecordIndex >( iss );
_idCache[recordIndex.id] = ExdCacheEntry{file_ptr, recordIndex.offset}; _idCache[recordIndex.id] = ExdCacheEntry{file_ptr, recordIndex.offset};
} }
} }
@ -93,8 +93,7 @@ namespace xiv
auto& file_ptr = cacheEntryIt->second.file; auto& file_ptr = cacheEntryIt->second.file;
std::vector< char > dataCpy = file_ptr->get_data_sections().front(); std::vector< char > dataCpy = file_ptr->get_data_sections().front();
xiv::utils::stream::vectorwrapbuf<char> databuf(dataCpy); std::istringstream iss( std::string( dataCpy.begin(), dataCpy.end() ) );
std::istream stream(&databuf);
// Get the vector fields for the given record and preallocate it // Get the vector fields for the given record and preallocate it
auto fields = _data[id]; auto fields = _data[id];
@ -104,7 +103,7 @@ namespace xiv
{ {
// 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 // 6 is because we have uint32_t/uint16_t at the start of each record
stream.seekg( cacheEntryIt->second.offset + 6 + member_entry.offset ); iss.seekg( cacheEntryIt->second.offset + 6 + member_entry.offset );
// Switch depending on the type to extract // Switch depending on the type to extract
switch( member_entry.type ) switch( member_entry.type )
@ -113,53 +112,53 @@ namespace xiv
// Extract the offset to the actual string // Extract the offset to the actual string
// Seek to it then extract the actual string // Seek to it then extract the actual string
{ {
auto string_offset = extract<uint32_t>( stream, "string_offset", false ); auto string_offset = extract<uint32_t>( iss, "string_offset", false );
stream.seekg( cacheEntryIt->second.offset + 6 + _exh->get_header().data_offset + string_offset ); iss.seekg( cacheEntryIt->second.offset + 6 + _exh->get_header().data_offset + string_offset );
fields.emplace_back( utils::bparse::extract_cstring( stream, "string" ) ); fields.emplace_back( utils::bparse::extract_cstring( iss, "string" ) );
} }
break; break;
case DataType::boolean: case DataType::boolean:
fields.emplace_back( extract<bool>( stream, "bool" ) ); fields.emplace_back( extract<bool>( iss, "bool" ) );
break; break;
case DataType::int8: case DataType::int8:
fields.emplace_back( extract<int8_t>( stream, "int8_t" ) ); fields.emplace_back( extract<int8_t>( iss, "int8_t" ) );
break; break;
case DataType::uint8: case DataType::uint8:
fields.emplace_back( extract<uint8_t>( stream, "uint8_t" ) ); fields.emplace_back( extract<uint8_t>( iss, "uint8_t" ) );
break; break;
case DataType::int16: case DataType::int16:
fields.emplace_back( extract<int16_t>( stream, "int16_t", false ) ); fields.emplace_back( extract<int16_t>( iss, "int16_t", false ) );
break; break;
case DataType::uint16: case DataType::uint16:
fields.emplace_back( extract<uint16_t>( stream, "uint16_t", false ) ); fields.emplace_back( extract<uint16_t>( iss, "uint16_t", false ) );
break; break;
case DataType::int32: case DataType::int32:
fields.emplace_back( extract<int32_t>( stream, "int32_t", false ) ); fields.emplace_back( extract<int32_t>( iss, "int32_t", false ) );
break; break;
case DataType::uint32: case DataType::uint32:
fields.emplace_back( extract<uint32_t>( stream, "uint32_t", false ) ); fields.emplace_back( extract<uint32_t>( iss, "uint32_t", false ) );
break; break;
case DataType::float32: case DataType::float32:
fields.emplace_back( extract<float>( stream, "float", false ) ); fields.emplace_back( extract<float>( iss, "float", false ) );
break; break;
case DataType::uint64: case DataType::uint64:
fields.emplace_back( extract<uint64_t>( stream, "uint64_t", false ) ); fields.emplace_back( extract<uint64_t>( iss, "uint64_t", false ) );
break; break;
default: default:
auto type = static_cast< uint16_t >( member_entry.type ); auto type = static_cast< uint16_t >( member_entry.type );
if( type < 0x19 || type > 0x20 ) if( type < 0x19 || type > 0x20 )
throw std::runtime_error("Unknown DataType: " + std::to_string( type )); throw std::runtime_error("Unknown DataType: " + std::to_string( type ));
uint64_t val = extract< uint64_t >( stream, "bool" ); uint64_t val = extract< uint64_t >( iss, "bool" );
int32_t shift = type - 0x19; int32_t shift = type - 0x19;
int32_t i = 1 << shift; int32_t i = 1 << shift;
val &= i; val &= i;
@ -180,12 +179,11 @@ namespace xiv
{ {
// Get a stream // Get a stream
std::vector< char > dataCpy = file_ptr->get_data_sections().front(); std::vector< char > dataCpy = file_ptr->get_data_sections().front();
xiv::utils::stream::vectorwrapbuf<char> databuf(dataCpy); std::istringstream iss( std::string( dataCpy.begin(), dataCpy.end() ) );
std::istream stream(&databuf);
// Extract the header and skip to the record indices // Extract the header and skip to the record indices
auto exd_header = extract<ExdHeader>( stream ); auto exd_header = extract<ExdHeader>( iss );
stream.seekg( 0x20 ); iss.seekg( 0x20 );
// Preallocate and extract the record_indices // Preallocate and extract the record_indices
const uint32_t record_count = exd_header.index_size / sizeof( ExdRecordIndex ); const uint32_t record_count = exd_header.index_size / sizeof( ExdRecordIndex );
@ -193,7 +191,7 @@ namespace xiv
record_indices.reserve( record_count ); record_indices.reserve( record_count );
for( uint32_t i = 0; i < record_count; ++i ) for( uint32_t i = 0; i < record_count; ++i )
{ {
record_indices.emplace_back( extract<ExdRecordIndex>( stream ) ); record_indices.emplace_back( extract<ExdRecordIndex>( iss ) );
} }
for( auto& record_index : record_indices ) for( auto& record_index : record_indices )
@ -207,7 +205,7 @@ namespace xiv
{ {
// 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 // 6 is because we have uint32_t/uint16_t at the start of each record
stream.seekg( record_index.offset + 6 + member_entry.offset ); iss.seekg( record_index.offset + 6 + member_entry.offset );
// Switch depending on the type to extract // Switch depending on the type to extract
switch( member_entry.type ) switch( member_entry.type )
@ -216,53 +214,53 @@ namespace xiv
// Extract the offset to the actual string // Extract the offset to the actual string
// Seek to it then extract the actual string // Seek to it then extract the actual string
{ {
auto string_offset = extract<uint32_t>( stream, "string_offset", false ); auto string_offset = extract<uint32_t>( iss, "string_offset", false );
stream.seekg( record_index.offset + 6 + _exh->get_header().data_offset + string_offset ); iss.seekg( record_index.offset + 6 + _exh->get_header().data_offset + string_offset );
fields.emplace_back( utils::bparse::extract_cstring( stream, "string" ) ); fields.emplace_back( utils::bparse::extract_cstring( iss, "string" ) );
} }
break; break;
case DataType::boolean: case DataType::boolean:
fields.emplace_back( extract<bool>( stream, "bool" ) ); fields.emplace_back( extract<bool>( iss, "bool" ) );
break; break;
case DataType::int8: case DataType::int8:
fields.emplace_back( extract<int8_t>( stream, "int8_t" ) ); fields.emplace_back( extract<int8_t>( iss, "int8_t" ) );
break; break;
case DataType::uint8: case DataType::uint8:
fields.emplace_back( extract<uint8_t>( stream, "uint8_t" ) ); fields.emplace_back( extract<uint8_t>( iss, "uint8_t" ) );
break; break;
case DataType::int16: case DataType::int16:
fields.emplace_back( extract<int16_t>( stream, "int16_t", false ) ); fields.emplace_back( extract<int16_t>( iss, "int16_t", false ) );
break; break;
case DataType::uint16: case DataType::uint16:
fields.emplace_back( extract<uint16_t>( stream, "uint16_t", false ) ); fields.emplace_back( extract<uint16_t>( iss, "uint16_t", false ) );
break; break;
case DataType::int32: case DataType::int32:
fields.emplace_back( extract<int32_t>( stream, "int32_t", false ) ); fields.emplace_back( extract<int32_t>( iss, "int32_t", false ) );
break; break;
case DataType::uint32: case DataType::uint32:
fields.emplace_back( extract<uint32_t>( stream, "uint32_t", false ) ); fields.emplace_back( extract<uint32_t>( iss, "uint32_t", false ) );
break; break;
case DataType::float32: case DataType::float32:
fields.emplace_back( extract<float>( stream, "float", false ) ); fields.emplace_back( extract<float>( iss, "float", false ) );
break; break;
case DataType::uint64: case DataType::uint64:
fields.emplace_back( extract<uint64_t>( stream, "uint64_t", false ) ); fields.emplace_back( extract<uint64_t>( iss, "uint64_t", false ) );
break; break;
default: default:
auto type = static_cast< uint16_t >( member_entry.type ); auto type = static_cast< uint16_t >( member_entry.type );
if( type < 0x19 || type > 0x20 ) if( type < 0x19 || type > 0x20 )
throw std::runtime_error("Unknown DataType: " + std::to_string( type )); throw std::runtime_error("Unknown DataType: " + std::to_string( type ));
uint64_t val = extract< uint64_t >( stream, "bool" ); uint64_t val = extract< uint64_t >( iss, "bool" );
int32_t shift = type - 0x19; int32_t shift = type - 0x19;
int32_t i = 1 << shift; int32_t i = 1 << shift;
val &= i; val &= i;

View file

@ -28,11 +28,11 @@ namespace xiv
_name(i_name) _name(i_name)
{ {
//XIV_INFO(xiv_exd_logger, "Initializing Cat with name: " << i_name); //XIV_INFO(xiv_exd_logger, "Initializing Cat with name: " << i_name);
// creates the header .exh // creates the header .exh
{ {
auto header_file = i_game_data.getFile("exd/" + i_name + ".exh"); auto header_file = i_game_data.getFile("exd/" + i_name + ".exh");
_header = std::shared_ptr< Exh >( new Exh( *header_file ) ); _header = std::shared_ptr< Exh >( new Exh( *header_file ) );
} }
for(auto language: _header->get_languages()) for(auto language: _header->get_languages())

View file

@ -23,7 +23,6 @@ ExdData::ExdData(dat::GameData& i_game_data) try :
xiv::utils::stream::vectorwrapbuf<char> databuf(dataCpy); xiv::utils::stream::vectorwrapbuf<char> databuf(dataCpy);
std::istream stream(&databuf); std::istream stream(&databuf);
// Iterates over the lines while skipping the first one // Iterates over the lines while skipping the first one
std::string line; std::string line;
std::getline(stream, line); // extract first line EXLT,2 std::getline(stream, line); // extract first line EXLT,2

View file

@ -3,6 +3,7 @@
#include "stream.h" #include "stream.h"
#include "File.h" #include "File.h"
#include <sstream>
using xiv::utils::bparse::extract; using xiv::utils::bparse::extract;
@ -10,38 +11,37 @@ namespace xiv
{ {
namespace exd namespace exd
{ {
Exh::Exh(const dat::File& i_file) Exh::Exh(const dat::File& i_file)
{ {
// Get a stream from the file // Get a stream from the file
std::vector< char > dataCpy = i_file.get_data_sections().front(); std::vector< char > dataCpy = i_file.get_data_sections().front();
xiv::utils::stream::vectorwrapbuf<char> databuf(dataCpy); std::istringstream iss( std::string( dataCpy.begin(), dataCpy.end() ) );
std::istream stream(&databuf);
// Extract header and skip to member definitions // Extract header and skip to member definitions
_header = extract<ExhHeader>(stream); _header = extract<ExhHeader>(iss);
stream.seekg(0x20); iss.seekg(0x20);
// Extract all the members and feed the _members map // Extract all the members and feed the _members map
for (auto i = 0; i < _header.field_count; ++i) for (auto i = 0; i < _header.field_count; ++i)
{ {
auto member = extract<ExhMember>(stream); auto member = extract<ExhMember>(iss);
_members[member.offset] = member; _members[member.offset] = member;
_exh_defs.push_back( member ); _exh_defs.push_back( member );
std::cout << "member_offset: " << member.offset << "\n";
} }
// Extract all the exd_defs // Extract all the exd_defs
_exd_defs.reserve(_header.exd_count); _exd_defs.reserve(_header.exd_count);
for (auto i = 0; i < _header.exd_count; ++i) for (auto i = 0; i < _header.exd_count; ++i)
{ {
_exd_defs.emplace_back(extract<ExhExdDef>(stream)); _exd_defs.emplace_back(extract<ExhExdDef>(iss));
} }
// Extract all the languages // Extract all the languages
_languages.reserve(_header.language_count); _languages.reserve(_header.language_count);
for (auto i = 0; i < _header.language_count; ++i) for (auto i = 0; i < _header.language_count; ++i)
{ {
_languages.emplace_back(Language(extract<uint16_t>(stream, "language"))); _languages.emplace_back(Language(extract<uint16_t>(iss, "language")));
} }
} }

View file

@ -8,7 +8,8 @@ file(GLOB SERVER_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}*.c*")
add_executable( sapphire_lobby ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES} ) add_executable( sapphire_lobby ${SERVER_PUBLIC_INCLUDE_FILES} ${SERVER_SOURCE_FILES} )
set_target_properties(sapphire_lobby PROPERTIES set_target_properties( sapphire_lobby
PROPERTIES
CXX_STANDARD 17 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON CXX_EXTENSIONS ON
@ -19,6 +20,9 @@ set_target_properties(sapphire_lobby PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/" VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../../bin/"
) )
target_link_libraries( sapphire_lobby PRIVATE common ) target_link_libraries( sapphire_lobby
PRIVATE
common
stdc++fs )
cotire( sapphire_lobby ) cotire( sapphire_lobby )

View file

@ -20,9 +20,6 @@
#include <Forwards.h> #include <Forwards.h>
#include <thread> #include <thread>
#include <boost/thread.hpp>
#include <boost/algorithm/string.hpp>
Core::Logger g_log; Core::Logger g_log;
Core::Network::RestConnector g_restConnector; Core::Network::RestConnector g_restConnector;
@ -76,9 +73,13 @@ void ServerLobby::run( int32_t argc, char* argv[] )
"Lobby server running on " + m_pConfig->getValue< std::string >( "LobbyNetwork.ListenIp", "0.0.0.0" ) + ":" + "Lobby server running on " + m_pConfig->getValue< std::string >( "LobbyNetwork.ListenIp", "0.0.0.0" ) + ":" +
m_pConfig->getValue< std::string >( "LobbyNetwork.ListenPort", "80" ) ); m_pConfig->getValue< std::string >( "LobbyNetwork.ListenPort", "80" ) );
boost::thread_group worker_threads; std::vector< std::thread > threadGroup;
worker_threads.create_thread( boost::bind( &Network::Hive::Run, hive.get() ) );
worker_threads.join_all(); threadGroup.emplace_back( std::bind( &Network::Hive::Run, hive.get() ) );
for( auto& thread : threadGroup )
if( thread.joinable() )
thread.join();
} }
@ -99,7 +100,7 @@ bool ServerLobby::loadSettings( int32_t argc, char* argv[] )
try try
{ {
arg = boost::to_lower_copy( std::string( args[ i ] ) ); std::transform( arg.begin(), arg.end(), arg.begin(), [](unsigned char c){ return std::tolower( c ); } );
val = std::string( args[ i + 1 ] ); val = std::string( args[ i + 1 ] );
// trim '-' from start of arg // trim '-' from start of arg

View file

@ -1,7 +1,6 @@
#ifndef CLIENT_HTTP_HPP #ifndef CLIENT_HTTP_HPP
#define CLIENT_HTTP_HPP #define CLIENT_HTTP_HPP
#include <boost/utility/string_ref.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
@ -68,7 +67,7 @@ namespace SimpleWeb {
/// Set before calling request /// Set before calling request
Config config; Config config;
std::shared_ptr<Response> request( const std::string& request_type, const std::string& path = "/", boost::string_ref content = "", std::shared_ptr<Response> request( const std::string& request_type, const std::string& path = "/", std::string_view content = "",
const std::map<std::string, std::string>& header = std::map<std::string, std::string>() ) { const std::map<std::string, std::string>& header = std::map<std::string, std::string>() ) {
auto corrected_path = path; auto corrected_path = path;
if( corrected_path == "" ) if( corrected_path == "" )

View file

@ -2,8 +2,6 @@ cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0015 NEW) cmake_policy(SET CMP0015 NEW)
project(Tool_ExdStructTest) project(Tool_ExdStructTest)
set(SAPPHIRE_BOOST_VER 1.63.0)
set(SAPPHIRE_BOOST_FOLDER_NAME boost_1_63_0)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../bin/")
@ -24,10 +22,8 @@ set_target_properties(exd_struct_test PROPERTIES
) )
if (UNIX) if (UNIX)
target_link_libraries (exd_struct_test common xivdat pthread mysqlclient dl z) target_link_libraries (exd_struct_test common xivdat pthread mysqlclient dl z stdc++fs )
else() else()
target_link_libraries (exd_struct_test common xivdat libmysql zlib1) target_link_libraries (exd_struct_test common xivdat libmysql zlib1)
endif() endif()
target_link_libraries(exd_struct_test ${Boost_LIBRARIES} ${Boost_LIBRARIES})

View file

@ -11,10 +11,6 @@
#include <set> #include <set>
#include <Exd/ExdDataGenerated.h> #include <Exd/ExdDataGenerated.h>
#include <Logging/Logger.h> #include <Logging/Logger.h>
#include <boost/range/algorithm/remove_if.hpp>
#include <boost/algorithm/string/classification.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <fstream> #include <fstream>
#include <streambuf> #include <streambuf>