rodecomp/Source/Contents/Emblems/EmblemDownload.cpp
ragnarok-clanker a47d20f8be Reconstruct readable C++ and organize cohesive source subsystems
Administrative source import: native x86 compilation passed for 423 authored units. Source placement and submission states are migrated separately; this commit does not imply peer acceptance.

Previous head: 35d2a8cb36
Payload SHA256: 592f016d2730c5593bb653aa054c1e5f76a6df72c8f5a09e66f74876e2e33dee
2026-10-25 07:42:41 +00:00

78 lines
1.9 KiB
C++

#include "Contents/Emblems/EmblemDownload.h"
#include "Network/Connection/Connection.h"
#include "Utility/Async/AsyncDiagnostic.h"
#include <algorithm>
#include <cstdlib>
#include <cstring>
namespace {
#pragma pack(push, 1)
struct EmblemPacket {
std::uint16_t id;
std::uint16_t bytes;
std::uint16_t state;
std::uint32_t guildId;
std::uint32_t version;
unsigned char data[1010];
};
#pragma pack(pop)
static_assert(sizeof(EmblemPacket) == 1024);
struct EmblemPacketAllocation {
std::uint32_t marker;
std::uint32_t unused;
EmblemPacket packet;
};
static_assert(sizeof(EmblemPacketAllocation) == 1032);
}
// OFFSET: 0x005EB800
// FUNCTION: fn_03975
void CompleteEmblemDownload(
AsyncDiagnostic diagnostic, int responseCode, std::string response, std::uint32_t guildId, std::uint32_t version, CConnection& connection
) {
if (!diagnostic.success || responseCode != 200) {
return;
}
auto* storage = static_cast<EmblemPacketAllocation*>(std::malloc(sizeof(EmblemPacketAllocation)));
if (!storage) {
return;
}
storage->marker = 0xDDDD;
EmblemPacket& packet = storage->packet;
packet.id = 0x0B36;
packet.bytes = 14;
packet.state = 2;
packet.guildId = guildId;
packet.version = version;
connection.Prepend(packet.bytes, &packet);
int remaining = static_cast<int>(response.size());
while (remaining > 0) {
const int bytes = std::min(remaining, 1010);
remaining -= bytes;
packet.id = 0x0B36;
packet.bytes = static_cast<std::uint16_t>(bytes + 14);
packet.state = 1;
packet.guildId = guildId;
packet.version = version;
std::memcpy(packet.data, response.data() + remaining, bytes);
connection.Prepend(packet.bytes, &packet);
}
packet.id = 0x0B36;
packet.bytes = 14;
packet.state = 0;
packet.guildId = guildId;
packet.version = version;
connection.Prepend(packet.bytes, &packet);
if (storage->marker == 0xDDDD) {
std::free(storage);
}
}