diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ada33ad..e2cdd5d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ set( LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/libraries" ) ########################################################################## # Dependencies and compiler settings include( "cmake/boost.cmake" ) -include( "cmake/mysql.cmake" ) +#include( "cmake/mysql.cmake" ) include( "cmake/compiler.cmake" ) include( "cmake/cotire.cmake" ) ############################## @@ -41,16 +41,15 @@ configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/src/common/Version.cpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/common/Version.cpp" @ONLY ) ########################################################################## -add_subdirectory( "src/libraries/sapphire/datReader" ) -add_subdirectory( "src/libraries/sapphire/mysqlConnector" ) +#add_subdirectory( "src/libraries/sapphire/datReader" ) +#add_subdirectory( "src/libraries/sapphire/mysqlConnector" ) add_subdirectory( "src/common" ) +#add_subdirectory( "src/servers" ) -add_subdirectory( "src/servers" ) - -add_subdirectory( "src/tools/exd_common_gen" ) -add_subdirectory( "src/tools/exd_struct_gen" ) -add_subdirectory( "src/tools/exd_struct_test" ) -add_subdirectory( "src/tools/quest_parser" ) -add_subdirectory( "src/tools/discovery_parser" ) +#add_subdirectory( "src/tools/exd_common_gen" ) +#add_subdirectory( "src/tools/exd_struct_gen" ) +#add_subdirectory( "src/tools/exd_struct_test" ) +#add_subdirectory( "src/tools/quest_parser" ) +#add_subdirectory( "src/tools/discovery_parser" ) #add_subdirectory("src/tools/pcb_reader") #add_subdirectory("src/tools/event_object_parser") diff --git a/bin/libmysql.dll b/bin/libmysql.dll deleted file mode 100644 index 479cefda..00000000 Binary files a/bin/libmysql.dll and /dev/null differ diff --git a/bin/zlib1.dll b/bin/zlib1.dll deleted file mode 100644 index ea747b42..00000000 Binary files a/bin/zlib1.dll and /dev/null differ diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index c49d6bb5..d9f0b811 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -1,6 +1,50 @@ cmake_minimum_required( VERSION 3.0.2 ) project( Sapphire ) +include( ExternalProject ) + +############################################################################# + +set( MYSQLCONNECTOR_ROOT ${CMAKE_BINARY_DIR}/external/MysqlConnector ) +set( MYSQLCONNECTOR_LIB_DIR ${MYSQLCONNECTOR_ROOT}/bin/lib ) +set( MYSQLCONNECTOR_INCLUDE_DIR ${MYSQLCONNECTOR_ROOT}/bin/include ) + +ExternalProject_Add( mysqlConnector_external + PREFIX ${MYSQLCONNECTOR_ROOT} + GIT_REPOSITORY "https://github.com/SapphireMordred/MysqlConnector.git" + UPDATE_COMMAND "" + PATCH_COMMAND "" + BINARY_DIR ${MYSQLCONNECTOR_ROOT}/src/MysqlConnector + SOURCE_DIR ${MYSQLCONNECTOR_ROOT}/src/MysqlConnector + INSTALL_DIR ${MYSQLCONNECTOR_ROOT}/bin + BUILD_COMMAND nmake ) + +add_library( mysqlConnector STATIC IMPORTED ) +set_target_properties( mysqlConnector PROPERTIES IMPORTED_LOCATION ${MYSQLCONNECTOR_LIB_DIR}/mysqlConnector.a ) +add_dependencies( mysqlConnector mysqlConnector_external ) + +############################################################################# + +set( XIVDAT_ROOT ${CMAKE_BINARY_DIR}/external/XivDat ) +set( XIVDAT_LIB_DIR ${XIVDAT_ROOT}/bin/lib ) +set( XIVDAT_INCLUDE_DIR ${XIVDAT_ROOT}/bin/include ) + +ExternalProject_Add( xivdat_external + PREFIX ${XIVDAT_ROOT} + GIT_REPOSITORY "https://github.com/SapphireMordred/XivDat.git" + UPDATE_COMMAND "" + PATCH_COMMAND "" + BINARY_DIR ${XIVDAT_ROOT}/src/XivDat + SOURCE_DIR ${XIVDAT_ROOT}/src/XivDat + INSTALL_DIR ${XIVDAT_ROOT}/bin + BUILD_COMMAND nmake ) + +add_library( xivdat STATIC IMPORTED ) +set_target_properties( xivdat PROPERTIES IMPORTED_LOCATION ${XIVDAT_LIB_DIR}/xivdat.a ) +add_dependencies( xivdat xivdat_external ) + +############################################################################# + file(GLOB UTILS_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Config/*.cpp" @@ -13,29 +57,17 @@ file(GLOB UTILS_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/Script/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/Util/*.cpp") -set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} ) +set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib ) add_library( common ${UTILS_PUBLIC_INCLUDE_FILES} ${UTILS_SOURCE_FILES} ) -set_target_properties( common PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/" - RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/" - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/" - RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL "${CMAKE_CURRENT_SOURCE_DIR}/../../bin/" -) - target_link_libraries( common PUBLIC xivdat ) target_link_libraries( common PUBLIC mysqlConnector ) -if( UNIX ) - target_link_libraries( common PUBLIC mysqlclient ) -else() - target_link_libraries( common PUBLIC libmysql ) -endif() +target_include_directories( common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/" + "${MYSQLCONNECTOR_ROOT}/src/MysqlConnector/src/" + "${XIVDAT_ROOT}/src/XivDat/src/" ) -target_include_directories( common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/" ) target_include_directories( common PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src/libraries/external/") + diff --git a/src/common/Database/DbConnection.cpp b/src/common/Database/DbConnection.cpp index 366fc954..3b0bd3cc 100644 --- a/src/common/Database/DbConnection.cpp +++ b/src/common/Database/DbConnection.cpp @@ -55,8 +55,8 @@ uint32_t Core::Db::DbConnection::open() { boost::shared_ptr< Mysql::MySqlBase > base( new Mysql::MySqlBase() ); Mysql::optionMap options; - options[ MYSQL_OPT_RECONNECT ] = "1"; - options[ MYSQL_SET_CHARSET_NAME ] = "utf8"; + //options[ MYSQL_OPT_RECONNECT ] = "1"; + //options[ MYSQL_SET_CHARSET_NAME ] = "utf8"; try { diff --git a/src/common/Database/DbLoader.cpp b/src/common/Database/DbLoader.cpp index 56cd4be2..499b0928 100644 --- a/src/common/Database/DbLoader.cpp +++ b/src/common/Database/DbLoader.cpp @@ -1,5 +1,4 @@ #include "DbLoader.h" -#include #include "CharaDbConnection.h" #include "DbWorkerPool.h" #include "Logging/Logger.h" @@ -32,7 +31,7 @@ Core::Db::DbLoader& Core::Db::DbLoader::addDb( Core::Db::DbWorkerPool< T >& pool if( uint32_t error = pool.open() ) { // Database does not exist - if( error == ER_BAD_DB_ERROR ) + if( error == 1049 /* BAD_DB_ERROR */ ) { return false; } diff --git a/src/common/Database/DbWorkerPool.cpp b/src/common/Database/DbWorkerPool.cpp index 785b857d..32513094 100644 --- a/src/common/Database/DbWorkerPool.cpp +++ b/src/common/Database/DbWorkerPool.cpp @@ -134,10 +134,7 @@ void Core::Db::DbWorkerPool< T >::escapeString( std::string& str ) if( str.empty() ) return; - char* buf = new char[str.size() * 2 + 1]; - escapeString( buf, str.c_str(), str.size() ); - str = buf; - delete[] buf; + str = m_connections[IDX_SYNCH].front()->getConnection()->escapeString( str ); } template< class T > @@ -187,15 +184,7 @@ uint32_t Core::Db::DbWorkerPool< T >::openConnections( InternalIndex type, uint8 return 0; } -template< class T > -unsigned long Core::Db::DbWorkerPool< T >::escapeString( char *to, const char *from, unsigned long length ) -{ - if( !to || !from || !length ) - return 0; - return mysql_real_escape_string( - m_connections[IDX_SYNCH].front()->getConnection()->getRawCon(), to, from, length ); -} template< class T > void Core::Db::DbWorkerPool< T >::enqueue( boost::shared_ptr< Operation > op ) diff --git a/src/common/Database/DbWorkerPool.h b/src/common/Database/DbWorkerPool.h index b5722a53..c750dc3f 100644 --- a/src/common/Database/DbWorkerPool.h +++ b/src/common/Database/DbWorkerPool.h @@ -68,8 +68,6 @@ public: private: uint32_t openConnections( InternalIndex type, uint8_t numConnections ); - unsigned long escapeString( char *to, const char *from, unsigned long length ); - void enqueue( boost::shared_ptr< Operation > op ); boost::shared_ptr< T > getFreeConnection(); diff --git a/src/common/Exd/ExdData.cpp b/src/common/Exd/ExdData.cpp deleted file mode 100644 index 4a455f94..00000000 --- a/src/common/Exd/ExdData.cpp +++ /dev/null @@ -1,725 +0,0 @@ -#include "ExdData.h" -#include - -#include - -/* TYPES !! - case DataType::boolean: 1 - case DataType::int8: 2 - case DataType::uint8: 3 - case DataType::int16: 4 - case DataType::uint16: 5 - case DataType::int32: 6 - case DataType::uint32: 7 - case DataType::float32: 8 - case DataType::uint64: 9 - */ - - - -Core::Data::ExdData::ExdData() -{ -} - -Core::Data::ExdData::~ExdData( void ) -{ -} - -xiv::exd::Exd Core::Data::ExdData::setupDatAccess( const std::string& name, xiv::exd::Language lang ) -{ - auto& cat = m_exd_data->get_category( name ); - return static_cast< xiv::exd::Exd >( cat.get_data_ln( lang ) ); -}; - -bool Core::Data::ExdData::init( const std::string& path ) -{ - try - { - m_data = boost::make_shared< xiv::dat::GameData >( path ); - m_exd_data = boost::make_shared< xiv::exd::ExdData >( *m_data ); - - m_questDat = setupDatAccess( "Quest", xiv::exd::Language::en ); - m_openingDat = setupDatAccess( "Opening", xiv::exd::Language::none ); - m_customTalkDat = setupDatAccess( "CustomTalk", xiv::exd::Language::en ); - m_aetheryteDat = setupDatAccess( "Aetheryte", xiv::exd::Language::en ); - m_levelDat = setupDatAccess( "Level", xiv::exd::Language::none ); - m_placeNameDat = setupDatAccess( "PlaceName", xiv::exd::Language::en ); - m_itemsDat = setupDatAccess( "Item", xiv::exd::Language::en ); - m_classJobCatDat = setupDatAccess( "ClassJobCategory", xiv::exd::Language::en ); - m_raceDat = setupDatAccess( "Race", xiv::exd::Language::en ); - m_eventItemDat = setupDatAccess( "EventItem", xiv::exd::Language::en ); - } - catch( std::runtime_error ) - { - return false; - } - - return true; -} - -bool Core::Data::ExdData::loadZoneInfo() -{ - auto territoryTypeData = setupDatAccess( "TerritoryType", xiv::exd::Language::none ); - auto placeNameData = setupDatAccess( "PlaceName", xiv::exd::Language::en ); - auto mapData = setupDatAccess( "Map", xiv::exd::Language::none ); - auto weatherRate = setupDatAccess( "WeatherRate", xiv::exd::Language::none ); - - auto territoryTypeDataRows = territoryTypeData.get_rows(); - - for( auto row : territoryTypeDataRows ) - { - auto& fields = row.second; - uint32_t id = row.first; - - uint16_t place_id = getField< uint16_t >( fields, 5 ); - uint16_t map_id = getField< uint16_t >( fields, 6 ); - std::string zoneStr = getField< std::string >( fields, 0 ); - - if( zoneStr.empty() ) - continue; - - auto placeNameDataFields = placeNameData.get_row( place_id ); - std::string zone_str = getField< std::string >( placeNameDataFields, 0 ); - - auto mapDataFields = mapData.get_row( map_id ); - int16_t map_index = getField< int16_t >( mapDataFields, 12 ); - bool is_two_bytes = getField< bool >( mapDataFields, 15 ); - - uint8_t weather_rate = getField< uint8_t >( fields, 12 ) > 75 ? 0 : getField< uint8_t >( fields, 12 ); - auto weatherRateFields = weatherRate.get_row( weather_rate ); - - int32_t aetheryte_index = getField< int32_t >( fields, 23 ); - uint8_t zoneType = getField< uint8_t >( fields, 9 ); - - - ZoneInfo info{ 0 }; - info.id = id; - info.zone_name = zoneStr; - info.zone_str = zone_str; - info.layout_id = id; - info.discovery_index = map_index; - info.is_two_byte = is_two_bytes; - info.map_id = map_id; - info.weather_rate = weather_rate; // TODO: deal with weather groups - info.aetheryte_index = aetheryte_index; - info.zone_type = zoneType; - - - uint8_t sumPc = 0; - for( size_t i = 0; i < 16; ) - { - int32_t weatherId = getField< int32_t >( weatherRateFields, i ); - - if( weatherId == 0 ) - break; - - sumPc += getField< uint8_t >( weatherRateFields, i + 1 ); - info.weather_rate_map[sumPc] = weatherId; - - i += 2; - } - - m_zoneInfoMap[id] = info; - - } - - return true; -} - -bool Core::Data::ExdData::loadStatusEffectInfo() -{ - auto StatusDat = setupDatAccess( "Status", xiv::exd::Language::en ); - auto rows1 = StatusDat.get_rows(); - - for( auto row : rows1 ) - { - auto& fields = row.second; - uint32_t id = row.first; - - StatusEffectInfo info { 0 }; - info.id = id; - info.name = getField< std::string >( fields, 0 ); - info.lock_movement = getField< bool >( fields, 7 ); // 7 - info.lock_actions = getField< bool >( fields, 9 ); // 9 - info.lock_control = getField< bool >( fields, 10 ); // 10 - info.transfiguration = getField< bool >( fields, 11 ); // 11 - info.can_dispel = getField< bool >( fields, 13 ); // 13 - info.is_permanent = getField< bool >( fields, 15 ); // 15 - info.inflicted_by_actor = getField< bool >( fields, 17 ); // 17 - info.is_fc_buff = getField< bool >( fields, 21 ); // 21 - info.invisibility = getField< bool >( fields, 22 ); // 22 - - m_statusEffectInfoMap[id] = info; - } - - return true; -} - -bool Core::Data::ExdData::loadAetheryteInfo() -{ - auto AetheryteDat = setupDatAccess( "Aetheryte", xiv::exd::Language::en ); - auto rows = AetheryteDat.get_rows(); - - for( auto row : rows ) - { - auto& fields = row.second; - auto info = boost::make_shared< AetheryteInfo >(); - info->id = row.first; - info->target_zone = getField< uint16_t >( fields, 10 ); - - info->isAetheryte = getField< bool >( fields, 15 ); - - uint16_t placename = getField< uint16_t >( fields, 8 ); - auto placeNameInfo = getPlaceNameInfo( placename ); - - if( placeNameInfo ) - { - info->placename = placeNameInfo->placename; - } - - - uint16_t placename_aethernet = getField< uint16_t >( fields, 9 ); - - auto placename_aethernetInfo = getPlaceNameInfo( placename_aethernet ); - - if( placename_aethernetInfo ) - { - info->placename_aethernet = placename_aethernetInfo->placename; - } - - info->levelId = getField< uint32_t >( fields, 11 ); - - info->map_coord_x = getField< int16_t >( fields, 20 ); - info->map_coord_y = getField< int16_t >( fields, 21 ); - m_aetheryteInfoMap.emplace( std::make_pair( info->id, info ) ); - } - return true; -} - -bool Core::Data::ExdData::loadClassJobInfo() -{ - auto ClassJobDat = setupDatAccess( "ClassJob", xiv::exd::Language::en ); - auto rows = ClassJobDat.get_rows(); - - for( auto row : rows ) - { - auto& fields = row.second; - ClassJobInfo info { 0 }; - - uint32_t id = row.first; - - if( id == 0 ) - continue; - - std::string name = getField< std::string >( fields, 0 ); - std::string short_name = getField< std::string >( fields, 1 ); - int8_t exp_idx = getField< int8_t >( fields, 4 ); - - - info.id = id; - info.name = name; - info.name_short = short_name; - info.exp_idx = exp_idx; - info.start_weapon_id = getField< int32_t >( fields, 28 ); - info.mod_hp = getField< uint16_t >( fields, 9 ); - info.mod_mpcpgp = getField< uint16_t >( fields, 10 ); - info.mod_str = getField< uint16_t >( fields, 11 ); - info.mod_vit = getField< uint16_t >( fields, 12 ); - info.mod_dex = getField< uint16_t >( fields, 13 ); - info.mod_int = getField< uint16_t >( fields, 14 ); - info.mod_mnd = getField< uint16_t >( fields, 15 ); - info.mod_pie = getField< uint16_t >( fields, 16 ); - - m_classJobInfoMap[id] = info; - } - - return true; -} - -bool Core::Data::ExdData::loadParamGrowInfo() -{ - auto ParamGrowDat = setupDatAccess( "ParamGrow", xiv::exd::Language::none ); - auto rows = ParamGrowDat.get_rows(); - - for( auto row : rows ) - { - auto& fields = row.second; - - ParamGrowthInfo info { 0 }; - uint32_t id = row.first; - info.level = id; - info.needed_exp = getField< int32_t >( fields, 0 ); - info.mp_mod = getField< uint16_t >( fields, 3 ); // 3 - info.mp_const = getField< int32_t >( fields, 4 ); // 4 - info.base_secondary = getField< int32_t >( fields, 5 );// 5 - info.quest_exp_mod = getField< uint8_t >( fields, 7 ); // 7 - info.hp_mod = getField< uint16_t >(fields, 8); // 8 - - - m_paramGrowthInfoMap[id] = info; - } - - return true; -} - -bool Core::Data::ExdData::loadTribeInfo() -{ - auto tribeDat = setupDatAccess( "Tribe", xiv::exd::Language::en ); - auto rows = tribeDat.get_rows(); - - for( auto row : rows ) - { - auto& fields = row.second; - - TribeInfo info { 0 }; - uint32_t id = row.first; - info.id = id; - info.name = getField< std::string >( fields, 0 ); - info.mod_str = getField< int8_t >( fields, 4 ); - info.mod_vit = getField< int8_t >( fields, 5 ); - info.mod_dex = getField< int8_t >( fields, 6 ); - info.mod_int = getField< int8_t >( fields, 7 ); - info.mod_mnd = getField< int8_t >( fields, 8 ); - info.mod_pie = getField< int8_t >( fields, 9 ); - - m_tribeInfoMap[id] = info; - } - - return true; -} - -bool Core::Data::ExdData::loadEventActionInfo() -{ - auto EventActionDat = setupDatAccess( "EventAction", xiv::exd::Language::en ); - auto rows = EventActionDat.get_rows(); - - for( auto row : rows ) - { - auto& fields = row.second; - - EventActionInfo info { 0 }; - - uint32_t id = row.first; - - if( id == 0 ) - { - continue; - } - - std::string name = getField< std::string >( fields, 0 ); - uint8_t time = getField< uint8_t >( fields, 2 ); - - info.id = id; - info.name = name; - info.castTime = time * 1000; - - m_EventActionInfoMap[id] = info; - - } - - return true; -} - -bool Core::Data::ExdData::loadActionInfo() -{ - auto ActionDat = setupDatAccess( "Action", xiv::exd::Language::en ); - auto rows = ActionDat.get_rows(); - - for( auto row : rows ) - { - auto& fields = row.second; - auto info = boost::make_shared< ActionInfo >(); - - uint32_t id = row.first; - if( id == 0 ) - { - continue; - } - - std::string name = getField< std::string >( fields, 0 ); // 0 - uint8_t category = getField< uint8_t >( fields, 3 ); // 3 - - int8_t class_job = getField< int8_t >( fields, 10 ); // 10 - uint8_t unlock_level = getField< uint8_t >( fields, 11 ); // 11 - int8_t range = getField< int8_t >( fields, 14 ); // 13 - bool can_target_self = getField< bool >( fields, 15 ); // 14 - bool can_target_party = getField< bool>( fields, 16 ); // 15 - bool can_target_friendly = getField< bool >( fields, 17 ); // 16 - bool can_target_enemy = getField< bool >( fields, 18 ); // 17 - - bool is_ground_aoe = getField< bool >( fields, 21 ); // 20 - // Column 23: Seems to be related to raising skills (Raise, Resurrection, Reanimate) - bool can_target_ko = getField< bool >( fields, 25 ); // 24 - - uint8_t aoe_type = getField< uint8_t >( fields, 27 ); // 26 - uint8_t aoe_range = getField< uint8_t >( fields, 28 ); // 27 - uint8_t aoe_width = getField< uint8_t >( fields, 29 ); // 28 - - uint8_t points_type = getField< uint8_t >( fields, 31 ); // 30 - uint16_t points_cost = getField< uint16_t >( fields, 32 ); // 31 - - bool is_instant = getField< bool >( fields, 36 ); // 35 - uint16_t cast_time = getField< uint16_t >( fields, 37 ); // 36 - uint16_t recast_time = getField< uint16_t >( fields, 38 ); // 37 - - int8_t model = getField< int8_t >( fields, 40 ); // 39 - uint8_t aspect = getField< uint8_t >( fields, 41 ); // 40 - - uint16_t toggle_status_id = getField< uint16_t >( fields, 43 ); // 42 - bool affects_position = getField< bool >( fields, 48 ); // 47 - - bool no_effect_in_battle = getField< bool >( fields, 61 ); // 60 - - - info->id = id; - info->name = name; - info->category = category; - - info->class_job = class_job; - info->unlock_level = unlock_level; - info->range = range; - info->can_target_self = can_target_self; - info->can_target_party = can_target_party; - info->can_target_friendly = can_target_friendly; - info->can_target_enemy = can_target_enemy; - - info->can_target_ko = can_target_ko; - - info->is_ground_aoe = is_ground_aoe; - - - info->aoe_type = aoe_type; - info->aoe_range = aoe_range; - info->aoe_width = aoe_width; - - info->points_type = points_type; - info->points_cost = points_cost; - - info->is_instant = is_instant; - info->cast_time = cast_time * 100; - info->recast_time = recast_time * 100; - - info->model = model; - info->aspect = aspect; - - info->toggle_status_id = toggle_status_id; - info->affects_position = affects_position; - - info->no_effect_in_battle = no_effect_in_battle; - - // If action type is SingleTarget with an AoE radius set, or if action type isn't SingleTarget - info->is_aoe = ( info->aoe_type == 1 && info->aoe_width != 0 ) || ( info->aoe_type != 1 ); - - m_actionInfoMap.emplace( std::make_pair( info->id, info ) ); - - } - - return true; -} - -boost::shared_ptr< Core::Data::PlaceNameInfo > - Core::Data::ExdData::getPlaceNameInfo( uint32_t placeNameId ) -{ - try - { - auto row = m_placeNameDat.get_row( placeNameId ); - auto info = boost::make_shared< PlaceNameInfo >(); - info->id = placeNameId; - info->placename = getField< std::string >( row, 0 ); - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; - -} - -boost::shared_ptr< Core::Data::ItemInfo > - Core::Data::ExdData::getItemInfo( uint32_t catalogId ) -{ - try - { - auto row = m_itemsDat.get_row( catalogId ); - auto info = boost::make_shared< ItemInfo >(); - info->id = catalogId; - info->name = getField< std::string >( row, 0 ); - info->item_level = getField< uint16_t >( row, 11 ); - info->required_level = getField< uint8_t >( row, 12 ); - info->ui_category = getField< uint8_t >( row, 17 ); - info->stack_size = getField< uint32_t >( row, 19 ); - info->is_hqable = getField< bool >( row, 20 ); - info->model_primary = getField< uint64_t >( row, 45 ); - info->model_secondary = getField< uint64_t >( row, 46 ); - info->physical_damage = getField< uint16_t >( row, 49 ); - info->magical_damage = getField< uint16_t >( row, 50 ); - info->delayMs = getField< uint16_t >( row, 51 ); - info->is_unique = getField< int16_t >( row, 64 ) != 0 ? true : false; - info->is_untradeable = getField< uint8_t >( row, 65 ) != 0 ? true : false; - - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; -} - -boost::shared_ptr< Core::Data::AetheryteInfo > - Core::Data::ExdData::getAetheryteInfo( uint32_t aetheryteId ) -{ - try - { - return m_aetheryteInfoMap[aetheryteId]; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; - -} - -boost::shared_ptr< Core::Data::ActionInfo > -Core::Data::ExdData::getActionInfo( uint32_t actionId ) -{ - try - { - return m_actionInfoMap[actionId]; - } - catch ( ... ) - { - return nullptr; - } - - return nullptr; - -} - -boost::shared_ptr< Core::Data::CustomTalkInfo > - Core::Data::ExdData::getCustomTalkInfo( uint32_t customTalkId ) -{ - - try - { - auto row = m_customTalkDat.get_row( customTalkId ); - auto info = boost::make_shared< CustomTalkInfo >(); - info->id = customTalkId; - info->name_intern = getField< std::string >( row, 2 ); - - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; - -} - -boost::shared_ptr< Core::Data::QuestInfo > - Core::Data::ExdData::getQuestInfo( uint32_t questId ) -{ - - - try - { - auto row = m_questDat.get_row( questId ); - auto info = boost::make_shared< QuestInfo >(); - info->id = questId; - info->name = getField< std::string >( row, 0 ); - info->name_intern = getField< std::string >( row, 1 ); - - info->quest_level = getField< uint16_t >( row, 4 ); - - info->enpc_resident_start = getField< uint32_t >( row, 40 ); - info->enpc_resident_end = getField< uint32_t >( row, 42 ); - - info->reward_exp_factor = getField< uint16_t >( row, 1439 ); - info->reward_gil = getField< uint32_t >( row, 1440 ); - info->reward_gc_seals = getField< uint16_t >( row, 1442 ); - - info->reward_item_type = getField< uint8_t >( row, 1449 ); - - for( uint32_t i = 0; i < 6; i++ ) - { - uint32_t entry = getField< uint32_t >( row, i + 1450 ); - if( entry > 0 ) - info->reward_item.push_back( entry ); - - uint8_t entry1 = getField< uint8_t >( row, i + 1457 ); - if( entry1 > 0 ) - info->reward_item_count.push_back( entry1 ); - - uint8_t entry2 = getField< uint8_t >( row, i + 1464 ); - if( entry2 > 0 ) - info->reward_item_stain.push_back( entry2 ); - - } - - for( uint32_t i = 0; i < 5; i++ ) - { - uint32_t entry = getField< uint32_t >( row, i + 1471 ); - if( entry > 0 ) - info->reward_item_optional.push_back( entry ); - - uint8_t entry1 = getField< uint8_t >( row, i + 1476 ); - if( entry1 > 0 ) - info->reward_item_optional_count.push_back( entry1 ); - - uint8_t entry2 = getField< uint8_t >( row, i + 1486 ); - if( entry2 > 0 ) - info->reward_item_optional_stain.push_back( entry2 ); - } - - info->reward_emote = getField< uint8_t >( row, 1491 ); - info->reward_action = getField< uint16_t >( row, 1492 ); - info->reward_action_general1 = getField< uint8_t >( row, 1493 ); - info->reward_action_general2 = getField< uint8_t >( row, 1494 ); - info->reward_other = getField< uint8_t >( row, 1496 ); - - info->instanced_content_unlock = getField< uint32_t >( row, 1499 ); - - info->reward_tome_type = getField< uint8_t >( row, 1501 ); - info->reward_tome_count = getField< uint8_t >( row, 1502 ); - - info->reward_reputation = getField< uint8_t >( row, 1503 ); - - for( uint32_t i = 0; i < 50; i++ ) - { - std::string entry = getField< std::string >( row, i + 49 ); - if( entry.size() > 0 ) - { - info->script_entity.push_back( entry ); - uint32_t entry1 = getField< uint32_t >( row, i + 99 ); - info->script_value.push_back( entry1 ); - } - } - - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; - -} - -boost::shared_ptr< Core::Data::EventItemInfo > - Core::Data::ExdData::getEventItemInfo( uint32_t eventItemId ) -{ - - try - { - auto row = m_eventItemDat.get_row( eventItemId ); - auto info = boost::make_shared< EventItemInfo >(); - info->id = eventItemId; - info->name = getField< std::string >( row, 0 ); - info->eventId = getField< uint32_t >( row, 14 ); - info->castTime = getField< uint8_t >( row, 15 ) * 1000; - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; - -} - -boost::shared_ptr< Core::Data::LevelInfo > - Core::Data::ExdData::getLevelInfo( uint32_t levelId ) -{ - try - { - auto row = m_levelDat.get_row( levelId ); - auto info = boost::make_shared< LevelInfo >(); - info->id = levelId; - info->x = getField< float >( row, 0 ); - info->y = getField< float >( row, 1 ); - info->z = getField< float >( row, 2 ); - info->r = getField< float >( row, 3 ); - info->actor_id = getField< uint32_t >( row, 6 ); - info->zone_id = getField< uint16_t >( row, 9 ); - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; -} - -const std::vector > Core::Data::ExdData::getAetheryteInfoForZone( uint16_t zoneId ) -{ - std::vector< boost::shared_ptr< AetheryteInfo > > aetheryteList; - - for( auto& aetheryteInfo : m_aetheryteInfoMap ) - { - if( aetheryteInfo.second->target_zone == zoneId ) - { - aetheryteList.push_back( aetheryteInfo.second ); - } - } - return aetheryteList; -} - - -boost::shared_ptr< Core::Data::OpeningInfo > - Core::Data::ExdData::getOpeningInfo( uint32_t openingId ) -{ - try - { - auto row = m_openingDat.get_row( openingId ); - auto info = boost::make_shared< OpeningInfo >(); - info->id = openingId; - info->name = getField< std::string >( row, 0 ); - - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; -} - -boost::shared_ptr< Core::Data::RaceInfo > - Core::Data::ExdData::getRaceInfo( uint32_t raceId ) -{ - try - { - - auto row = m_raceDat.get_row( raceId ); - auto info = boost::make_shared< RaceInfo >(); - info->id = raceId; - info->name = getField< std::string >( row, 0 ); - info->male_body = getField< int32_t >( row, 2 ); - info->male_hands = getField< int32_t >( row, 3 ); - info->male_legs = getField< int32_t >( row, 4 ); - info->male_feet = getField< int32_t >( row, 5 ); - info->female_body = getField< int32_t >( row, 6 ); - info->female_hands = getField< int32_t >( row, 7 ); - info->female_legs = getField< int32_t >( row, 8 ); - info->female_feet = getField< int32_t >( row, 9 ); - - return info; - } - catch( ... ) - { - return nullptr; - } - - return nullptr; -} diff --git a/src/common/Exd/ExdData.h b/src/common/Exd/ExdData.h deleted file mode 100644 index d17bffb8..00000000 --- a/src/common/Exd/ExdData.h +++ /dev/null @@ -1,356 +0,0 @@ -#ifndef _EXDDATA_H -#define _EXDDATA_H - -#include -#include -#include -#include -#include - -/* TYPES !! -case DataType::boolean: 1 -case DataType::int8: 2 -case DataType::uint8: 3 -case DataType::int16: 4 -case DataType::uint16: 5 -case DataType::int32: 6 -case DataType::uint32: 7 -case DataType::float32: 8 -case DataType::uint64: 9 -*/ - - -namespace Core { - - namespace Data { - - struct ZoneInfo - { - uint16_t id; - std::string zone_str; - std::string zone_name; - uint32_t layout_id; - uint16_t map_id; - int16_t discovery_index; - bool is_two_byte; - uint16_t weather_rate; - std::map< uint8_t, int32_t> weather_rate_map; - - int32_t aetheryte_index; - uint8_t zone_type; - }; - - struct ClassJobInfo - { - uint8_t id; - std::string name; - std::string name_short; - uint8_t exp_idx; - uint32_t start_weapon_id; - uint16_t mod_hp; - uint16_t mod_mpcpgp; - uint16_t mod_str; - uint16_t mod_vit; - uint16_t mod_dex; - uint16_t mod_int; - uint16_t mod_mnd; - uint16_t mod_pie; - }; - - struct QuestInfo - { - uint32_t id; - std::string name; - std::string name_intern; - uint16_t quest_level; - uint32_t enpc_resident_start; - uint32_t enpc_resident_end; - uint16_t reward_exp_factor; - uint32_t reward_gil; - uint16_t reward_gc_seals; - uint8_t reward_item_type; - - std::vector< uint32_t > reward_item; - std::vector< uint8_t > reward_item_count; - std::vector< uint8_t > reward_item_stain; - - std::vector< uint32_t > reward_item_optional; - std::vector< uint8_t > reward_item_optional_count; - std::vector< uint8_t > reward_item_optional_stain; - - uint8_t reward_emote; - uint16_t reward_action; - uint8_t reward_action_general1; - uint8_t reward_action_general2; - - uint8_t reward_other; - - uint32_t instanced_content_unlock; - - uint8_t reward_tome_type; - uint8_t reward_tome_count; - - uint8_t reward_reputation; - - - - std::vector< std::string > script_entity; - std::vector< uint32_t > script_value; - }; - - struct EventActionInfo - { - uint32_t id; - std::string name; - uint32_t castTime; - }; - - struct OpeningInfo - { - uint32_t id; - std::string name; - }; - - struct ParamGrowthInfo - { - uint32_t level; - uint32_t needed_exp; - int16_t hp_mod; - int32_t mp_const; - int16_t mp_mod; - int32_t base_secondary; - uint16_t quest_exp_mod; - }; - - struct CustomTalkInfo - { - uint32_t id; - std::string name_intern; - }; - - struct PlaceNameInfo - { - uint32_t id; - std::string placename; - }; - - struct AetheryteInfo - { - uint32_t id; - std::string placename; - std::string placename_aethernet; - int32_t target_zone; - int32_t levelId; - bool isAetheryte; - - int16_t map_coord_x; - int16_t map_coord_y; - }; - - struct RaceInfo - { - uint32_t id; - std::string name; - uint32_t male_body; - uint32_t male_hands; - uint32_t male_legs; - uint32_t male_feet; - uint32_t female_body; - uint32_t female_hands; - uint32_t female_legs; - uint32_t female_feet; - - int8_t mod_str; - int8_t mod_dex; - int8_t mod_vit; - int8_t mod_int; - int8_t mod_mnd; - int8_t mod_pie; - }; - - struct TribeInfo - { - uint32_t id; - std::string name; - - int8_t mod_str; - int8_t mod_dex; - int8_t mod_vit; - int8_t mod_int; - int8_t mod_mnd; - int8_t mod_pie; - }; - - struct LevelInfo - { - uint32_t id; - float x; - float y; - float z; - float r; - uint32_t actor_id; - uint32_t zone_id; - }; - - struct ClassJobCategoryInfo - { - uint32_t id; - // should they add new jobs, this needs to be changed - bool can_equip[0x33]; - }; - - struct ItemInfo - { - uint32_t id; - std::string name; //0 - uint16_t item_level; //11 - uint8_t required_level; //12 - uint16_t unknown_category; //15 - uint16_t ui_category; //17 - uint32_t stack_size; //19 - bool is_hqable; //20 - uint64_t model_primary; //28 - uint64_t model_secondary; //29 - uint16_t physical_damage; //49 - uint16_t magical_damage; //50 - uint16_t delayMs; //51 - uint32_t class_job_requirement; //58 - bool is_unique; //72 - bool is_untradeable; //73 - uint32_t class_job_index; //86 - }; - - struct ActionInfo - { - uint32_t id; - std::string name; // 0 - uint16_t category; // 3 - - int8_t class_job; // 10 - uint8_t unlock_level; // 11 - int8_t range; // 13 - bool can_target_self; // 14 - bool can_target_party; // 15 - bool can_target_friendly; // 16 - bool can_target_enemy; // 17 - - bool is_ground_aoe; // 20 - - bool can_target_ko; // 24 - - uint8_t aoe_type; // 26 - uint8_t aoe_range; // 27 - uint8_t aoe_width; // 28 - - uint8_t points_type; // 30 - uint16_t points_cost; // 31 - - bool is_instant; // 35 - uint32_t cast_time; // 36 - uint32_t recast_time; // 37 - - int8_t model; // 39 - uint8_t aspect; // 40 - - uint16_t toggle_status_id; // 42 - - bool affects_position; // 47 - - bool no_effect_in_battle; // 60 - - - bool is_aoe; // Internal only - - }; - - struct EventItemInfo - { - uint32_t id; - std::string name; //0 - uint32_t eventId; - uint32_t castTime; - }; - - struct StatusEffectInfo - { - uint32_t id; - std::string name; // 0 - bool lock_movement; // 7 - bool lock_actions; // 9 - bool lock_control; // 10 - bool transfiguration; // 11 - bool can_dispel; // 13 - bool is_permanent; // 15 - bool inflicted_by_actor; // 17 - bool is_fc_buff; // 21 - bool invisibility; // 22 - }; - - class ExdData - { - public: - ExdData(); - ~ExdData(void); - - bool init( const std::string& path ); - - xiv::exd::Exd setupDatAccess( const std::string& name, xiv::exd::Language lang ); - - template< class T > - T getField( std::vector< xiv::exd::Field >& fields, uint32_t index ) - { - return *boost::get< T >( &fields.at( index ) ); - } - - boost::shared_ptr m_data; - boost::shared_ptr m_exd_data; - - xiv::exd::Exd m_questDat; - xiv::exd::Exd m_openingDat; - xiv::exd::Exd m_customTalkDat; - xiv::exd::Exd m_aetheryteDat; - xiv::exd::Exd m_levelDat; - xiv::exd::Exd m_placeNameDat; - xiv::exd::Exd m_itemsDat; - xiv::exd::Exd m_classJobCatDat; - xiv::exd::Exd m_raceDat; - xiv::exd::Exd m_eventItemDat; - - std::map m_zoneInfoMap; - std::map m_classJobInfoMap; - std::map m_paramGrowthInfoMap; - std::map m_EventActionInfoMap; - std::map > m_actionInfoMap; - std::map m_statusEffectInfoMap; - std::map > m_aetheryteInfoMap; - std::map m_tribeInfoMap; - - bool loadZoneInfo(); - bool loadClassJobInfo(); - bool loadParamGrowInfo(); - bool loadEventActionInfo(); - bool loadActionInfo(); - bool loadStatusEffectInfo(); - bool loadAetheryteInfo(); - bool loadTribeInfo(); - - boost::shared_ptr< QuestInfo > getQuestInfo( uint32_t questId ); - boost::shared_ptr< OpeningInfo > getOpeningInfo( uint32_t openingId ); - boost::shared_ptr< CustomTalkInfo > getCustomTalkInfo( uint32_t customTalkId ); - boost::shared_ptr< AetheryteInfo > getAetheryteInfo( uint32_t aetheryteId ); - boost::shared_ptr< ActionInfo > getActionInfo( uint32_t actionId ); - boost::shared_ptr< PlaceNameInfo > getPlaceNameInfo( uint32_t placeNameId ); - boost::shared_ptr< ItemInfo > getItemInfo( uint32_t catalogId ); - boost::shared_ptr< RaceInfo > getRaceInfo( uint32_t raceId ); - boost::shared_ptr< EventItemInfo > getEventItemInfo( uint32_t eventItemId ); - boost::shared_ptr< LevelInfo > getLevelInfo( uint32_t levelId ); - - const std::vector< boost::shared_ptr< AetheryteInfo > > getAetheryteInfoForZone( uint16_t zoneId ); - - }; - - } -} - -#endif - diff --git a/src/common/Network/GamePacket.cpp b/src/common/Network/GamePacket.cpp index c4d61f81..bc142ab5 100644 --- a/src/common/Network/GamePacket.cpp +++ b/src/common/Network/GamePacket.cpp @@ -7,16 +7,17 @@ #include #include "Util/Util.h" -Core::Network::Packets::GamePacket::GamePacket( uint16_t subType, uint16_t size, uint32_t id1, uint32_t id2, uint16_t type ) +Core::Network::Packets::GamePacket::GamePacket( uint16_t subType, uint16_t size, + uint32_t id1, uint32_t id2, uint16_t type ) { - m_dataBuf = std::vector( size ); + m_dataBuf = std::vector< uint8_t >( size ); memset( &m_segHdr, 0, sizeof( m_segHdr ) ); setHeader( size, type, id1, id2, subType, 0x00 ); - } -void Core::Network::Packets::GamePacket::setHeader( uint16_t size, uint16_t type, uint32_t id1, uint32_t id2, uint16_t subType, uint32_t unknown ) +void Core::Network::Packets::GamePacket::setHeader( uint16_t size, uint16_t type, uint32_t id1, + uint32_t id2, uint16_t subType, uint32_t unknown ) { m_segHdr.size = size; @@ -40,7 +41,7 @@ void Core::Network::Packets::GamePacket::setHeader( uint16_t size, uint16_t type Core::Network::Packets::GamePacket::GamePacket( char * pData, uint16_t size, bool bWriteStamp ) { - m_dataBuf = std::vector( size ); + m_dataBuf = std::vector< uint8_t >( size ); memcpy( &m_dataBuf[0], pData, size ); m_unknown2 = 0; @@ -65,9 +66,12 @@ Core::Network::Packets::GamePacket::GamePacket( const Packets::FFXIVARR_PACKET_R { m_segHdr = packetData.segHdr; - m_dataBuf = std::vector( m_segHdr.size ); + m_dataBuf = std::vector< uint8_t >( m_segHdr.size ); + + memcpy( &m_dataBuf[0] + sizeof( Packets::FFXIVARR_PACKET_SEGMENT_HEADER ), + &packetData.data[0], + m_segHdr.size - sizeof( Packets::FFXIVARR_PACKET_SEGMENT_HEADER ) ); - memcpy( &m_dataBuf[0] + sizeof( Packets::FFXIVARR_PACKET_SEGMENT_HEADER ), &packetData.data[0], m_segHdr.size - sizeof( Packets::FFXIVARR_PACKET_SEGMENT_HEADER ) ); memcpy( &m_dataBuf[0], &m_segHdr, sizeof( Packets::FFXIVARR_PACKET_SEGMENT_HEADER ) ); m_subType = *reinterpret_cast< uint16_t* >( &m_dataBuf[0] + 0x12 ); @@ -98,5 +102,5 @@ void Core::Network::Packets::GamePacket::savePacket() std::string Core::Network::Packets::GamePacket::toString() const { - return Core::Util::binaryToHexDump( const_cast( &m_dataBuf[0] ), getSize() ); + return Core::Util::binaryToHexDump( const_cast< uint8_t* >( &m_dataBuf[0] ), getSize() ); } diff --git a/src/common/Network/GamePacketNew.h b/src/common/Network/GamePacketNew.h index 451c4eee..595b8222 100644 --- a/src/common/Network/GamePacketNew.h +++ b/src/common/Network/GamePacketNew.h @@ -20,7 +20,7 @@ template < typename T, typename T1 > class GamePacketNew; template < typename T, typename T1 > -std::ostream& operator<< ( std::ostream& os, const GamePacketNew< T, T1 >& packet ); +std::ostream& operator << ( std::ostream& os, const GamePacketNew< T, T1 >& packet ); template< class T > using ZoneChannelPacket = GamePacketNew< T, ServerZoneIpcType >; @@ -32,15 +32,15 @@ using ChatChannelPacket = GamePacketNew< T, ServerChatIpcType >; * The base implementation of a game packet. Needed for parsing packets. */ template < typename T1 > -class FFXIVPacketBase +class FFXIVIpcPacketBase { public: - virtual ~FFXIVPacketBase() = default; + virtual ~FFXIVIpcPacketBase() = default; /** * @brief Gets the IPC type of this packet. (Useful for determining the * type of a parsed packet.) */ - virtual T1 ipcType( void ) = 0; + virtual T1 ipcType() = 0; }; /** @@ -50,7 +50,7 @@ public: * 32 byte header information.) */ template < typename T, typename T1 > -class GamePacketNew : public FFXIVPacketBase< T1 > +class GamePacketNew : public FFXIVIpcPacketBase< T1 > { public: /** @@ -96,7 +96,7 @@ protected: }; public: - virtual T1 ipcType( void ) + virtual T1 ipcType() { return static_cast< T1 >( m_data._ServerIpcType ); }; diff --git a/src/common/Network/GamePacketParser.cpp b/src/common/Network/GamePacketParser.cpp index 4a9fd067..52cfe1a3 100644 --- a/src/common/Network/GamePacketParser.cpp +++ b/src/common/Network/GamePacketParser.cpp @@ -5,131 +5,122 @@ using namespace Core::Network::Packets; -namespace Core +PacketParseResult Core::Network::Packets::getHeader( const std::vector< uint8_t > &buffer, + const uint32_t offset, + FFXIVARR_PACKET_HEADER &header ) { - namespace Network - { - namespace Packets - { - PacketParseResult getHeader( const std::vector< uint8_t > &buffer, - const uint32_t offset, - FFXIVARR_PACKET_HEADER &header ) - { - const auto headerSize = sizeof( FFXIVARR_PACKET_HEADER ); + const auto headerSize = sizeof( FFXIVARR_PACKET_HEADER ); - // Check if we have enough bytes in the buffer. - auto remainingBytes = buffer.size() - offset; - if( remainingBytes < headerSize ) - return Incomplete; + // Check if we have enough bytes in the buffer. + auto remainingBytes = buffer.size() - offset; + if( remainingBytes < headerSize ) + return Incomplete; - // Copy packet header. - memcpy( &header, buffer.data() + offset, headerSize ); + // Copy packet header. + memcpy( &header, buffer.data() + offset, headerSize ); - if( !checkHeader(header) ) - return Malformed; + if( !checkHeader(header) ) + return Malformed; - return Success; - } - - PacketParseResult getSegmentHeader( const std::vector< uint8_t > &buffer, - const uint32_t offset, - FFXIVARR_PACKET_SEGMENT_HEADER &header ) - { - const auto headerSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ); - - // Check if we have enough bytes in the buffer. - auto remainingBytes = buffer.size() - offset; - if( remainingBytes < headerSize ) - return Incomplete; - - // Copy segment header - memcpy( &header, buffer.data() + offset, headerSize ); - - return Success; - } - - PacketParseResult getPackets( const std::vector< uint8_t > &buffer, - const uint32_t offset, - const FFXIVARR_PACKET_HEADER &packetHeader, - std::vector< FFXIVARR_PACKET_RAW > &packets ) - { - // sanity check: check there's enough bytes in the buffer - const auto bytesExpected = packetHeader.size - sizeof( struct FFXIVARR_PACKET_HEADER ); - if( buffer.size() - offset < bytesExpected ) - return Incomplete; - - // Loop each message - uint32_t count = 0; - uint32_t bytesProcessed = 0; - while( count < packetHeader.count ) - { - FFXIVARR_PACKET_RAW rawPacket; - - // Copy ipc packet message - const auto packetResult = getPacket( buffer, offset + bytesProcessed, rawPacket ); - if( packetResult != Success ) - return packetResult; - - // NOTE: isn't rawPacket is allocated on stack? - // why is okay to do this? - packets.push_back( rawPacket ); - - // Add message size and count - bytesProcessed += rawPacket.segHdr.size; - count += 1; - } - - // sanity check: check if we processed all bytes. - // this check can fail if size of messages don't add up to size reported from packet header. - if( bytesExpected != bytesProcessed ) - return Malformed; - - return Success; - } - - PacketParseResult getPacket( const std::vector< uint8_t > &buffer, const uint32_t offset, - FFXIVARR_PACKET_RAW &packet ) - { - // Copy segment header - const auto headerResult = getSegmentHeader( buffer, offset, packet.segHdr ); - if( headerResult != Success ) - return headerResult; - - // Check header sanity and it's size - if( !checkSegmentHeader( packet.segHdr ) ) - return Malformed; - - const auto dataOffset = offset + sizeof( struct FFXIVARR_PACKET_SEGMENT_HEADER ); - const auto dataSize = packet.segHdr.size; - - // Allocate data buffer and copy - packet.data.resize( dataSize ); - memcpy( packet.data.data(), buffer.data() + dataOffset, dataSize ); - - return Success; - } - - bool checkHeader( const FFXIVARR_PACKET_HEADER &header ) - { - // Max size of the packet is capped at 1MB for now. - if( header.size > 1 * 1024 * 1024 ) - return false; - - // Max number of message is capped at 255 for now. - if( header.count > 255 ) - return false; - - return true; - } - - bool checkSegmentHeader( const FFXIVARR_PACKET_SEGMENT_HEADER &header ) - { - // Max size of individual message is capped at 256KB for now. - if( header.size > 256 * 1024 ) - return false; - - return true; - } - } - } + return Success; +} + +PacketParseResult Core::Network::Packets::getSegmentHeader( const std::vector< uint8_t > &buffer, + const uint32_t offset, + FFXIVARR_PACKET_SEGMENT_HEADER &header ) +{ + const auto headerSize = sizeof( FFXIVARR_PACKET_SEGMENT_HEADER ); + + // Check if we have enough bytes in the buffer. + auto remainingBytes = buffer.size() - offset; + if( remainingBytes < headerSize ) + return Incomplete; + + // Copy segment header + memcpy( &header, buffer.data() + offset, headerSize ); + + return Success; +} + +PacketParseResult Core::Network::Packets::getPackets( const std::vector< uint8_t > &buffer, + const uint32_t offset, + const FFXIVARR_PACKET_HEADER &packetHeader, + std::vector< FFXIVARR_PACKET_RAW > &packets ) +{ + // sanity check: check there's enough bytes in the buffer + const auto bytesExpected = packetHeader.size - sizeof( struct FFXIVARR_PACKET_HEADER ); + if( buffer.size() - offset < bytesExpected ) + return Incomplete; + + // Loop each message + uint32_t count = 0; + uint32_t bytesProcessed = 0; + while( count < packetHeader.count ) + { + FFXIVARR_PACKET_RAW rawPacket; + + // Copy ipc packet message + const auto packetResult = getPacket( buffer, offset + bytesProcessed, rawPacket ); + if( packetResult != Success ) + return packetResult; + + // NOTE: isn't rawPacket is allocated on stack? + // why is okay to do this? + packets.push_back( rawPacket ); + + // Add message size and count + bytesProcessed += rawPacket.segHdr.size; + count += 1; + } + + // sanity check: check if we processed all bytes. + // this check can fail if size of messages don't add up to size reported from packet header. + if( bytesExpected != bytesProcessed ) + return Malformed; + + return Success; +} + +PacketParseResult Core::Network::Packets::getPacket( const std::vector< uint8_t > &buffer, const uint32_t offset, + FFXIVARR_PACKET_RAW &packet ) +{ + // Copy segment header + const auto headerResult = getSegmentHeader( buffer, offset, packet.segHdr ); + if( headerResult != Success ) + return headerResult; + + // Check header sanity and it's size + if( !checkSegmentHeader( packet.segHdr ) ) + return Malformed; + + const auto dataOffset = offset + sizeof( struct FFXIVARR_PACKET_SEGMENT_HEADER ); + const auto dataSize = packet.segHdr.size; + + // Allocate data buffer and copy + packet.data.resize( dataSize ); + memcpy( packet.data.data(), buffer.data() + dataOffset, dataSize ); + + return Success; +} + +bool Core::Network::Packets::checkHeader( const FFXIVARR_PACKET_HEADER &header ) +{ + // Max size of the packet is capped at 1MB for now. + if( header.size > 1 * 1024 * 1024 ) + return false; + + // Max number of message is capped at 255 for now. + if( header.count > 255 ) + return false; + + return true; +} + +bool Core::Network::Packets::checkSegmentHeader( const FFXIVARR_PACKET_SEGMENT_HEADER &header ) +{ + // Max size of individual message is capped at 256KB for now. + if( header.size > 256 * 1024 ) + return false; + + return true; } diff --git a/src/common/Network/GamePacketParser.h b/src/common/Network/GamePacketParser.h index 1ffda893..6f870bd2 100644 --- a/src/common/Network/GamePacketParser.h +++ b/src/common/Network/GamePacketParser.h @@ -2,62 +2,49 @@ #define _GAMEPACKETPARSER_H #include "CommonNetwork.h" -namespace Core -{ - namespace Network +namespace Core { +namespace Network { +namespace Packets { + + enum PacketParseResult { - namespace Packets - { - enum PacketParseResult - { - /// Dissected game packet successfully - Success, + /// Dissected game packet successfully + Success, - /// Buffer is too short to dissect a message. - Incomplete, - - /// Invalid data detected. - Malformed - }; + /// Buffer is too short to dissect a message. + Incomplete, - /// Read packet header from buffer with given offset. - /// Buffer with given offset must be pointing to start of the new FFXIV packet. - PacketParseResult getHeader( - const std::vector< uint8_t > &buffer, - const uint32_t offset, - FFXIVARR_PACKET_HEADER &header - ); + /// Invalid data detected. + Malformed + }; - /// Read packet header from buffer with given offset. - /// Buffer with given offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data. - /// Keep in mind that this function does check for data validity. Call checkSegmentHeader() if that's needed. - PacketParseResult getSegmentHeader( - const std::vector< uint8_t > &buffer, - const uint32_t offset, - FFXIVARR_PACKET_SEGMENT_HEADER &header - ); + /// Read packet header from buffer with given offset. + /// Buffer with given offset must be pointing to start of the new FFXIV packet. + PacketParseResult getHeader( const std::vector< uint8_t > &buffer, const uint32_t offset, + FFXIVARR_PACKET_HEADER &header ); - /// Read packets from the buffer with given offset. - /// Buffer with given offset must be pointing to end of FFXIVARR_PACKET_HEADER data. - PacketParseResult getPackets( - const std::vector< uint8_t > &buffer, - const uint32_t offset, - const FFXIVARR_PACKET_HEADER &header, - std::vector< Packets::FFXIVARR_PACKET_RAW > &packets); - - /// Read single packet from the buffer with given offset. - /// Buffer with an offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data. - PacketParseResult getPacket( - const std::vector< uint8_t > &buffer, - const uint32_t offset, - FFXIVARR_PACKET_RAW &packet - ); + /// Read packet header from buffer with given offset. + /// Buffer with given offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data. + /// Keep in mind that this function does check for data validity. Call checkSegmentHeader() if that's needed. + PacketParseResult getSegmentHeader( const std::vector< uint8_t > &buffer, const uint32_t offset, + FFXIVARR_PACKET_SEGMENT_HEADER &header ); - bool checkHeader(const FFXIVARR_PACKET_HEADER &header); - bool checkSegmentHeader(const FFXIVARR_PACKET_SEGMENT_HEADER &header); + /// Read packets from the buffer with given offset. + /// Buffer with given offset must be pointing to end of FFXIVARR_PACKET_HEADER data. + PacketParseResult getPackets( const std::vector< uint8_t > &buffer, const uint32_t offset, + const FFXIVARR_PACKET_HEADER &header, + std::vector< Packets::FFXIVARR_PACKET_RAW > &packets ); - } - } + /// Read single packet from the buffer with given offset. + /// Buffer with an offset must be pointing to start of FFXIVARR_PACKET_SEGMENT_HEADER data. + PacketParseResult getPacket( const std::vector< uint8_t > &buffer, const uint32_t offset, + FFXIVARR_PACKET_RAW &packet ); + + bool checkHeader(const FFXIVARR_PACKET_HEADER &header); + bool checkSegmentHeader(const FFXIVARR_PACKET_SEGMENT_HEADER &header); + +} +} } diff --git a/src/libraries b/src/libraries deleted file mode 160000 index 67b949df..00000000 --- a/src/libraries +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 67b949dfe3ffbbba7963b0861670ab4bb1819991 diff --git a/src/servers/CMakeLists.txt b/src/servers/CMakeLists.txt deleted file mode 100644 index 28e43594..00000000 --- a/src/servers/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -cmake_minimum_required(VERSION 2.6) -project (Sapphire) - -set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}) -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) - -set(PROJECT_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/include) - -include_directories("${PROJECT_INCLUDE_DIR}") -include_directories("${PROJECT_SOURCE_DIR}") - -add_subdirectory(${PROJECT_SOURCE_DIR}/sapphire_lobby) -add_subdirectory(${PROJECT_SOURCE_DIR}/sapphire_api) -add_subdirectory(${PROJECT_SOURCE_DIR}/sapphire_zone) -add_subdirectory(${PROJECT_SOURCE_DIR}/Scripts) diff --git a/src/servers/Scripts/CMakeLists.txt b/src/servers/Scripts/CMakeLists.txt deleted file mode 100644 index 3d03ca0d..00000000 --- a/src/servers/Scripts/CMakeLists.txt +++ /dev/null @@ -1,73 +0,0 @@ -cmake_minimum_required(VERSION 3.0) -project(Sapphire_Script) - -file(GLOB SCRIPT_INCLUDE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.h") - -message("exec: ${EXECUTABLE_OUTPUT_DIRECTORY}") - -set(SCRIPT_LIB_DIR "${EXECUTABLE_OUTPUT_DIRECTORY}/compiledscripts/" ) -set(EXECUTABLE_OUTPUT_PATH "${SCRIPT_LIB_DIR}") -set(LIBRARY_OUTPUT_PATH "${SCRIPT_LIB_DIR}") -set(RUNTIME_OUTPUT_DIRECTORY "${SCRIPT_LIB_DIR}") - - -file(GLOB children "${CMAKE_CURRENT_SOURCE_DIR}/*" ) -foreach(_scriptDir ${children}) - get_filename_component(_name "${_scriptDir}" NAME_WE) - if(IS_DIRECTORY ${_scriptDir} AND NOT ${_name} MATCHES "CMakeFiles" AND NOT ${_name} MATCHES "\\.dir$") - message("discovered plugin lib: ${_scriptDir} (${_name})") - - file(GLOB_RECURSE SCRIPT_BUILD_FILES "${_scriptDir}/*.cpp") - file(GLOB_RECURSE SCRIPT_FILES RELATIVE "${_scriptDir}" "${_name}/*.cpp") - - # build file list - foreach(_script ${SCRIPT_FILES}) - get_filename_component( _scriptname "${_script}" NAME_WE) - - if(NOT ${_scriptname} MATCHES "ScriptLoader") - if(ScriptIncludes) - set(ScriptIncludes "${ScriptIncludes}\n#include \"${_script}\"") - else() - set(ScriptIncludes "#include \"${_script}\"") - endif() - - set(ScriptNames "${ScriptNames} static_cast< ScriptObject* >( new ${_scriptname} ),\n") - endif() - endforeach() - - add_library("script_${_name}" MODULE ${SCRIPT_BUILD_FILES} "${SCRIPT_INCLUDE_FILES}" "${_scriptDir}/ScriptLoader.cpp") - target_link_libraries( "script_${_name}" sapphire_zone ) - - if(MSVC) - target_link_libraries( "script_${_name}" ${Boost_LIBRARIES}) - set_target_properties( "script_${_name}" PROPERTIES - CXX_STANDARD 14 - CXX_STANDARD_REQUIRED ON - CXX_EXTENSIONS ON - LIBRARY_OUTPUT_DIRECTORY_DEBUG "${SCRIPT_LIB_DIR}" - LIBRARY_OUTPUT_DIRECTORY_RELEASE "${SCRIPT_LIB_DIR}" - LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO "${SCRIPT_LIB_DIR}" - LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL "${SCRIPT_LIB_DIR}" - ) - endif() - target_include_directories("script_${_name}" PUBLIC "${CMAKE_SOURCE_DIR}/src/servers/sapphire_zone/") - target_include_directories("script_${_name}" PUBLIC "${CMAKE_SOURCE_DIR}/src/servers/Script/Scripts") - target_include_directories("script_${_name}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") - target_include_directories("script_${_name}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/Scripts") - - configure_file("${CMAKE_CURRENT_SOURCE_DIR}/ScriptLoader.cpp.in" "${_scriptDir}/ScriptLoader.cpp") - - cotire("script_${_name}") - - if(MSVC) - add_custom_command(TARGET "script_${_name}" POST_BUILD - COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.exp" - COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.lib" - COMMAND ${CMAKE_COMMAND} -E remove "${SCRIPT_LIB_DIR}/script_${_name}.ilk" - ) - endif() - - unset(ScriptIncludes) - unset(ScriptNames) - endif() -endforeach() diff --git a/src/servers/Scripts/ScriptLoader.cpp.in b/src/servers/Scripts/ScriptLoader.cpp.in deleted file mode 100644 index 739b32af..00000000 --- a/src/servers/Scripts/ScriptLoader.cpp.in +++ /dev/null @@ -1,14 +0,0 @@ -#include