rodecomp/Source/Network/Packets/PacketLengths.cpp
ragnarok-clanker 63b1377599 Decompile 5 functions in Source/Client/ReplayPacketRecorder.h, Source/Contents/Emblems/EmblemUpload.h, ...
Batch #1488 by ragnarok-clanker: 0 byte-identical, 5 confirmed by peer review.

- fn_18386 PacketLengths::IsRecorded: logic confirmed by peer review
- fn_18387 PacketLengths::Initialize: logic confirmed by peer review
- fn_18388 PacketLengths::Lookup: logic confirmed by peer review
- fn_20391 PacketLengths::FixedLength: logic confirmed by peer review
- fn_18171 ResourceFailures::Report: logic confirmed by peer review

Reviewed-by: ragnarok-clanker
2026-10-28 16:45:10 +00:00

74 lines
1.5 KiB
C++

#include "Network/Packets/PacketLengths.h"
#include <algorithm>
// GLOBAL: gl_24489
PacketLengths g_packetLengths;
// OFFSET: 0x00B09E50
// FUNCTION: fn_18388
PacketLengthResult PacketLengths::Lookup(int id) const {
const auto entry = this->m_values.find(id);
if (entry == this->m_values.end()) {
return {-1, 4};
}
if (entry->second.length == -1) {
return {0, entry->second.variable};
}
if (entry->second.length < 0) {
return {-1, 4};
}
return {1, entry->second.length};
}
// OFFSET: 0x00C7C970
// FUNCTION: fn_20391
int PacketLengths::FixedLength(int id) const {
if (id == 703) {
return 12;
}
if (id == 704) {
return 4;
}
return std::max(g_packetLengths.Lookup(id).length, 2);
}
namespace {
struct PacketRegistration {
int record;
int variable;
int length;
int id;
};
// STATIC: 0x00B02294
// GLOBAL: gl_00808
constexpr PacketRegistration registrations[] = {
#include "Network/Packets/PacketRegistrations.inc"
};
}
// OFFSET: 0x00B02260
// FUNCTION: fn_18387
void PacketLengths::Initialize() {
for (const PacketRegistration& value : registrations) {
this->m_values.try_emplace(value.id, PacketLengthValue{value.length, value.variable, value.record});
}
}
// OFFSET: 0x00B01E70
// FUNCTION: fn_18383
PacketLengths::PacketLengths() {
this->Initialize();
}
// OFFSET: 0x00B02210
// FUNCTION: fn_18386
int PacketLengths::IsRecorded(int id) const {
const auto entry = this->m_values.find(id);
return entry == this->m_values.end() ? 0 : entry->second.record;
}