From 147ebedfdeec3081e505e1c6461199ccb90760c7 Mon Sep 17 00:00:00 2001 From: Mordred Date: Mon, 6 Dec 2021 00:39:22 +0100 Subject: [PATCH] Added a util function to get opCode from RAW_PACKET --- src/common/Util/Util.cpp | 6 ++++++ src/common/Util/Util.h | 3 +++ src/lobby/GameConnection.cpp | 5 +++-- src/world/Network/GameConnection.cpp | 4 ++-- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/common/Util/Util.cpp b/src/common/Util/Util.cpp index 0f53d1e6..1085bd6a 100644 --- a/src/common/Util/Util.cpp +++ b/src/common/Util/Util.cpp @@ -19,6 +19,12 @@ std::string Util::binaryToHexString( uint8_t* pBinData, uint16_t size ) return outStr; } + +uint16_t Util::getOpCode( Sapphire::Network::Packets::FFXIVARR_PACKET_RAW& raw ) +{ + return *reinterpret_cast< uint16_t* >( &raw.data[ 2 ] ); +} + std::string Util::toLowerCopy( const std::string& inStr ) { std::string out = inStr; diff --git a/src/common/Util/Util.h b/src/common/Util/Util.h index 15e78f5a..3f80b6fc 100644 --- a/src/common/Util/Util.h +++ b/src/common/Util/Util.h @@ -4,10 +4,13 @@ #include #include #include +#include namespace Sapphire::Common::Util { + uint16_t getOpCode( Network::Packets::FFXIVARR_PACKET_RAW& raw ); + std::string binaryToHexString( uint8_t* pBinData, uint16_t size ); std::string binaryToHexDump( uint8_t* pBinData, uint16_t size ); diff --git a/src/lobby/GameConnection.cpp b/src/lobby/GameConnection.cpp index 8ca5fd5f..b0a7e753 100644 --- a/src/lobby/GameConnection.cpp +++ b/src/lobby/GameConnection.cpp @@ -23,6 +23,7 @@ #include "Forwards.h" using namespace Sapphire; +using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; using namespace Sapphire::Network::Packets::LobbyPackets; using namespace Sapphire::Network::Packets::LobbyPackets::Server; @@ -478,9 +479,9 @@ void Lobby::GameConnection::handleGamePacket( Network::Packets::FFXIVARR_PACKET_ if( m_pSession ) accountId = m_pSession->getAccountID(); - Logger::info( "[accountId#{0}] OpCode {1}", accountId, *reinterpret_cast< uint16_t* >( &packet.data[ 2 ] ) ); + Logger::info( "[accountId#{0}] OpCode {1}", accountId, Util::getOpCode( packet ) ); - switch( *reinterpret_cast< uint16_t* >( &packet.data[ 2 ] ) ) + switch( Util::getOpCode( packet ) ) { case LoginEx: { diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index 51aad754..d92308e9 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -228,7 +228,7 @@ void Sapphire::Network::GameConnection::queueOutPacket( std::vector< Packets::FF void Sapphire::Network::GameConnection::handleZonePacket( Sapphire::Network::Packets::FFXIVARR_PACKET_RAW& pPacket ) { - uint16_t opcode = *reinterpret_cast< uint16_t* >( &pPacket.data[ 0x02 ] ); + uint16_t opcode = Util::getOpCode( pPacket ); auto it = m_zoneHandlerMap.find( opcode ); if( it != m_zoneHandlerMap.end() ) @@ -259,7 +259,7 @@ void Sapphire::Network::GameConnection::handleZonePacket( Sapphire::Network::Pac void Sapphire::Network::GameConnection::handleChatPacket( Sapphire::Network::Packets::FFXIVARR_PACKET_RAW& pPacket ) { - uint16_t opcode = *reinterpret_cast< uint16_t* >( &pPacket.data[ 0x02 ] ); + uint16_t opcode = Util::getOpCode( pPacket ); auto it = m_chatHandlerMap.find( opcode ); if( it != m_chatHandlerMap.end() )