Steam 协议 C++ 解压多消息

Steam Protocol C++ Unzip Multi message

我正在用 C++ 为 Steam 协议编写一个插件。我正在使用 https://github.com/seishun/SteamPP which uses protobufs from https://github.com/SteamRE/SteamKit 并且通常它有效。我可以与 Steam 通信,我可以毫无问题地发送和接收单个消息(包括登录),但是 Steam 发送的消息通常很少压缩在一条消息中(来自 protobuf 的 EMsg::Multi),这就是我的问题。我无法正确解压缩它们。我不明白我做错了什么。

std::string unzip(std::string &input) {
auto archive = archive_read_new();

auto result = archive_read_support_filter_all(archive);
assert(result == ARCHIVE_OK);

result = archive_read_support_format_zip(archive);
assert(result == ARCHIVE_OK);

result = archive_read_open_memory(archive, &input[0], input.size());
assert(result == ARCHIVE_OK);

archive_entry* entry;
result = archive_read_next_header(archive, &entry);
if (result != ARCHIVE_OK) {
    return "read next header error " + std::to_string(result);
}
assert(result == ARCHIVE_OK);

std::string output;
output.resize(archive_entry_size(entry));

auto length = archive_read_data(archive, &output[0], output.size());
assert(length == output.size());
if (length != output.size()) {
    return "hello world" + std::to_string(length);
}

assert(archive_read_next_header(archive, &entry) == ARCHIVE_EOF);

result = archive_read_free(archive);
assert(result == ARCHIVE_OK);

return output;
}

在这个函数中(libarchive)archive_read_data returns -25 这是一个错误代码,下一个断言会抛出错误。怎么了?它在 C# SteamKit 版本和 node.js 版本中运行良好。我也尝试过 Crypto++ Gunzip,但它引发了 CryptoPP::Gunzip::HeaderErr 异常。 CHECK DEBUG GIF

我认为您的 Libarchive 中缺少 Zlib,因为 Steam 消息已压缩,您需要 Zlib 来处理它们。现在 libarchive 无法处理它们,所以它 returns -25 因为不支持的文件类型。尝试在 CMake 中附加 Zlib 重新编译 libarchive。