#pragma once #include #include namespace dnf90_premium_clock { constexpr size_t kNativeBodySize = 77; // success:u8, action:u16, blob74 constexpr size_t kServerHeaderSize = 16; constexpr size_t kClockTrailerSize = 8; constexpr size_t kPacketSize = kServerHeaderSize + kNativeBodySize + kClockTrailerSize; inline uint32_t ReadU32(const unsigned char* bytes) { return uint32_t(bytes[0]) | (uint32_t(bytes[1]) << 8) | (uint32_t(bytes[2]) << 16) | (uint32_t(bytes[3]) << 24); } // Only our exact marked server16/class1/op903 action1 packet is eligible. // The unchanged native prefix remains owned by the original handler. inline bool Decode(const unsigned char* bytes, size_t available, int* serverUnix) { if (!bytes || !serverUnix || available < kPacketSize || bytes[0] != 1 || bytes[1] != 0x87 || bytes[2] != 3 || ReadU32(bytes + 3) != kPacketSize || bytes[16] != 1 || bytes[17] != 1 || bytes[18] != 0) return false; const unsigned char* trailer = bytes + kServerHeaderSize + kNativeBodySize; if (trailer[0] != 'T' || trailer[1] != 'I' || trailer[2] != 'M' || trailer[3] != 'E') return false; uint32_t timestamp = ReadU32(trailer + 4); // The native clock uses signed time32. Refuse zero, wrapped and out-of-era // timestamps rather than writing arbitrary values to native globals. if (timestamp < 946684800u || timestamp > 0x7fffffffu) return false; *serverUnix = static_cast(timestamp); return true; } } // namespace dnf90_premium_clock