From 6f797922ea5eae6e8a06b768692bd9b15d9d0559 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Mon, 9 Feb 2026 23:15:45 -0800 Subject: [PATCH] Add comprehensive packet boundary debugging for quest opcodes Logs for opcodes 0x18F, 0x18D, 0x188, 0x186: - Raw header bytes (size + opcode) - Total packet size vs buffer size - Payload hex dump (first 16 bytes) - Next packet header preview This will reveal packet desync issues, wrong size fields, or incorrect opcode mappings. --- src/network/world_socket.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/network/world_socket.cpp b/src/network/world_socket.cpp index df6a6c4d..0062a8c3 100644 --- a/src/network/world_socket.cpp +++ b/src/network/world_socket.cpp @@ -212,6 +212,41 @@ void WorldSocket::tryParsePackets() { // Total packet size: size field (2) + size value (which includes opcode + payload) size_t totalSize = 2 + size; + // DEBUG: Log packet boundary details for quest-related opcodes + if (opcode == 0x18F || opcode == 0x18D || opcode == 0x188 || opcode == 0x186) { + char hexBuf[256]; + snprintf(hexBuf, sizeof(hexBuf), + "PACKET BOUNDARY: opcode=0x%04X size=%u totalSize=%zu bufferSize=%zu", + opcode, size, totalSize, receiveBuffer.size()); + core::Logger::getInstance().info(hexBuf); + + // Dump header bytes + snprintf(hexBuf, sizeof(hexBuf), + " Header: %02x %02x %02x %02x", + receiveBuffer[0], receiveBuffer[1], receiveBuffer[2], receiveBuffer[3]); + core::Logger::getInstance().info(hexBuf); + + // Dump first 16 bytes of payload (if available) + if (totalSize <= receiveBuffer.size()) { + std::string payloadHex = " Payload: "; + for (size_t i = 4; i < std::min(totalSize, size_t(20)); ++i) { + char buf[4]; + snprintf(buf, sizeof(buf), "%02x ", receiveBuffer[i]); + payloadHex += buf; + } + core::Logger::getInstance().info(payloadHex); + } + + // Dump what comes after this packet (next header preview) + if (receiveBuffer.size() > totalSize && receiveBuffer.size() >= totalSize + 4) { + snprintf(hexBuf, sizeof(hexBuf), + " Next header: %02x %02x %02x %02x", + receiveBuffer[totalSize], receiveBuffer[totalSize+1], + receiveBuffer[totalSize+2], receiveBuffer[totalSize+3]); + core::Logger::getInstance().info(hexBuf); + } + } + if (receiveBuffer.size() < totalSize) { // Not enough data yet - header stays decrypted in buffer break;