#pragma once #include #include namespace dnf90_dungeon_assist { constexpr uint16_t kOpcode = 0x7f47; constexpr size_t kHeaderSize = 46; constexpr size_t kMaxKeys = 128; inline uint16_t U16(const unsigned char* p) { return uint16_t(p[0]) | uint16_t(p[1]) << 8; } inline uint32_t U32(const unsigned char* p) { return uint32_t(U16(p)) | uint32_t(U16(p + 2)) << 16; } // A native active wave or a completed hit threshold must never be advanced // again, even while a spawn animation has not produced its actors yet. inline bool CanAdvanceGate(bool wavePresent, bool spawning, int hits, int threshold) { return !wavePresent && !spawning && hits >= 0 && threshold > 0 && hits < threshold; } inline bool ValidQuery(const unsigned char* body, size_t size) { if (!body || size < kHeaderSize + 1 || body[0] != 1 || body[33] > 1 || !U16(body + 1) || !U32(body + 19) || !U32(body + 23) || !U32(body + 27)) return false; const size_t count = body[kHeaderSize]; if (!count || count > kMaxKeys || size != kHeaderSize + 1 + count * 2) return false; for (size_t i = 0; i < count; ++i) { const uint16_t key = U16(body + kHeaderSize + 1 + i * 2); if (!key || key == 0xffff) return false; for (size_t j = 0; j < i; ++j) if (key == U16(body + kHeaderSize + 1 + j * 2)) return false; } return true; } }