@@ -7,9 +7,8 @@
#include < cstring>
#include < optional>
#include < zlib.h>
#include " Common/CommonTypes.h"
#include " Common/Hash.h"
namespace ciface ::DualShockUDPClient::Proto
{
@@ -217,11 +216,6 @@ struct FromClient
};
} // namespace MessageType
static inline u32 CRC32 (const void * buffer, unsigned length)
{
return crc32 (crc32 (0L , Z_NULL, 0 ), static_cast <const Bytef*>(buffer), length);
}
template <typename MsgType>
struct Message
{
@@ -236,15 +230,20 @@ struct Message
m_message.message_type = MsgType::TYPE;
}
void Finish () { m_message.header .crc32 = CRC32 (&m_message, sizeof (m_message)); }
void Finish ()
{
m_message.header .crc32 =
Common::ComputeCRC32 (reinterpret_cast <const u8*>(&m_message), sizeof (m_message));
}
template <class ToMsgType >
std::optional<ToMsgType> CheckAndCastTo ()
{
const u32 crc32_in_header = m_message.header .crc32 ;
// zero out the crc32 in the packet once we got it since that's whats needed for calculation
m_message.header .crc32 = 0 ;
const u32 crc32_calculated = CRC32 (&m_message, sizeof (ToMsgType));
const u32 crc32_calculated =
Common::ComputeCRC32 (reinterpret_cast <const u8*>(&m_message), sizeof (ToMsgType));
if (crc32_in_header != crc32_calculated)
{
NOTICE_LOG_FMT (