2017-08-08 13:53:47 +02:00
|
|
|
#ifndef _GAMEPACKET_H_
|
|
|
|
#define _GAMEPACKET_H_
|
|
|
|
|
|
|
|
#include "CommonNetwork.h"
|
2017-12-18 12:36:52 +01:00
|
|
|
#include <common/Forwards.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
namespace Network {
|
|
|
|
namespace Packets {
|
|
|
|
|
2017-12-29 20:12:03 +01:00
|
|
|
class GamePacket
|
|
|
|
{
|
2017-08-08 13:53:47 +02:00
|
|
|
public:
|
|
|
|
GamePacket( uint16_t subType, uint16_t size, uint32_t id1, uint32_t id2, uint16_t type = 0x03 );
|
2017-12-29 20:12:03 +01:00
|
|
|
GamePacket( char* pData, uint16_t size, bool bWriteStamp = true );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
GamePacket( const Packets::FFXIVARR_PACKET_RAW& packetData );
|
|
|
|
|
|
|
|
GamePacket( void );
|
|
|
|
~GamePacket( void );
|
|
|
|
|
2017-08-17 17:30:00 +02:00
|
|
|
uint16_t getSize() const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
return m_segHdr.size;
|
|
|
|
}
|
|
|
|
|
2017-08-17 17:30:00 +02:00
|
|
|
uint16_t getType() const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
return m_segHdr.type;
|
|
|
|
}
|
|
|
|
|
2017-08-17 17:30:00 +02:00
|
|
|
uint16_t getSubType() const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
return m_subType;
|
|
|
|
}
|
|
|
|
|
2017-12-29 20:12:03 +01:00
|
|
|
template< class T >
|
2017-08-08 13:53:47 +02:00
|
|
|
void setValAt( uint16_t pos, T value )
|
|
|
|
{
|
2017-08-26 15:07:31 +09:00
|
|
|
assert( m_segHdr.size > pos );
|
2017-08-11 22:56:30 +01:00
|
|
|
memcpy( reinterpret_cast< uint8_t* >( &m_dataBuf[0] + pos ), &value, sizeof( T ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-12-29 20:12:03 +01:00
|
|
|
template< class T >
|
2017-08-17 17:30:00 +02:00
|
|
|
T getValAt( uint16_t pos ) const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2017-12-09 13:09:56 +09:00
|
|
|
assert( m_segHdr.size > pos );
|
2017-08-17 17:30:00 +02:00
|
|
|
return *reinterpret_cast< const T* >( &m_dataBuf[0] + pos );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 22:56:30 +01:00
|
|
|
void setBytesAt( uint16_t offset, uint8_t * bytes, uint16_t length )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2017-12-09 13:09:56 +09:00
|
|
|
assert( m_segHdr.size > offset );
|
2017-08-11 22:56:30 +01:00
|
|
|
memcpy( reinterpret_cast< uint8_t* >( &m_dataBuf[0] + offset ), bytes, length );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-12-29 20:12:03 +01:00
|
|
|
const char* getStringAt( uint16_t pos ) const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2017-12-09 13:09:56 +09:00
|
|
|
assert( m_segHdr.size > pos );
|
2017-08-17 17:30:00 +02:00
|
|
|
return reinterpret_cast< const char* >( &m_dataBuf[0] + pos );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setStringAt( uint16_t pos, const std::string& str )
|
|
|
|
{
|
2017-12-09 13:09:56 +09:00
|
|
|
assert( m_segHdr.size > pos );
|
2017-08-11 22:56:30 +01:00
|
|
|
memcpy( reinterpret_cast< uint8_t* >( &m_dataBuf[0] + pos ), str.c_str(), str.length() );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
2017-12-29 20:12:03 +01:00
|
|
|
const uint8_t* getData() const
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2017-12-09 13:09:56 +09:00
|
|
|
return reinterpret_cast< const uint8_t* >( &m_dataBuf[0] );
|
|
|
|
}
|
|
|
|
|
2017-12-29 20:12:03 +01:00
|
|
|
const uint8_t* getDataAt(uint16_t pos) const
|
2017-12-09 13:09:56 +09:00
|
|
|
{
|
2017-12-09 13:14:06 +09:00
|
|
|
assert( m_segHdr.size > pos );
|
|
|
|
return reinterpret_cast< const uint8_t* >( &m_dataBuf[0] + pos );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void setHeader( uint16_t size, uint16_t type, uint32_t id1, uint32_t id2, uint16_t subType, uint32_t unknown = 0xFED2E000 );
|
|
|
|
|
2017-08-17 17:30:00 +02:00
|
|
|
std::string toString() const;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
void savePacket();
|
|
|
|
|
|
|
|
FFXIVARR_PACKET_SEGMENT_HEADER m_segHdr;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
uint16_t m_unknown2;
|
|
|
|
uint16_t m_subType;
|
|
|
|
uint32_t m_timeStamp;
|
2017-12-29 20:12:03 +01:00
|
|
|
std::vector< uint8_t > m_dataBuf;
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|