2021-12-05 17:54:36 +00:00
|
|
|
#ifndef PACKETUTILS_H
|
|
|
|
#define PACKETUTILS_H
|
|
|
|
|
2023-05-03 21:38:32 +00:00
|
|
|
#include <MessageIdentifiers.h>
|
2021-12-05 17:54:36 +00:00
|
|
|
#include <BitStream.h>
|
|
|
|
#include <string>
|
|
|
|
|
2023-05-03 21:38:32 +00:00
|
|
|
enum class eConnectionType : uint16_t;
|
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
namespace PacketUtils {
|
2023-05-03 21:38:32 +00:00
|
|
|
template<typename T>
|
|
|
|
void WriteHeader(RakNet::BitStream& bitStream, eConnectionType connectionType, T internalPacketID) {
|
2023-05-07 06:45:07 +00:00
|
|
|
bitStream.Write<uint8_t>(MessageID(ID_USER_PACKET_ENUM));
|
|
|
|
bitStream.Write<eConnectionType>(connectionType);
|
|
|
|
bitStream.Write<uint32_t>(static_cast<uint32_t>(internalPacketID));
|
|
|
|
bitStream.Write<uint8_t>(0);
|
2023-05-03 21:38:32 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
|
|
|
uint16_t ReadPacketU16(uint32_t startLoc, Packet* packet);
|
|
|
|
uint32_t ReadPacketU32(uint32_t startLoc, Packet* packet);
|
|
|
|
uint64_t ReadPacketU64(uint32_t startLoc, Packet* packet);
|
|
|
|
int64_t ReadPacketS64(uint32_t startLoc, Packet* packet);
|
|
|
|
std::string ReadString(uint32_t startLoc, Packet* packet, bool wide, uint32_t maxLen = 33);
|
|
|
|
|
|
|
|
void WritePacketString(const std::string& string, uint32_t maxSize, RakNet::BitStream* bitStream);
|
2021-12-05 17:54:36 +00:00
|
|
|
void WriteString(RakNet::BitStream& bitStream, const std::string& s, uint32_t maxSize);
|
|
|
|
void WriteWString(RakNet::BitStream& bitStream, const std::string& string, uint32_t maxSize);
|
|
|
|
void WriteWString(RakNet::BitStream& bitStream, const std::u16string& string, uint32_t maxSize);
|
2022-07-28 13:39:57 +00:00
|
|
|
void WritePacketWString(const std::string& string, uint32_t maxSize, RakNet::BitStream* bitStream);
|
|
|
|
|
|
|
|
void SavePacket(const std::string& filename, const char* data, size_t length);
|
2021-12-05 17:54:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // PACKETUTILS_H
|