Skip to content

Commit 8ad5af3

Browse files
committed
Implement PackedGuid
Not actually tested yet, so could have mistakes
1 parent 14f959e commit 8ad5af3

7 files changed

Lines changed: 110 additions & 14 deletions

File tree

src/libs/protocol/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ set(SERVER_MESSAGES
7575
include/protocol/server/NewWorld.h
7676
)
7777

78+
set(TYPE_HEADERS
79+
include/protocol/types/PackedGuid.h
80+
)
81+
7882
set(CORE_HEADERS
7983
include/protocol/Deserialise.h
8084
include/protocol/Opcodes.h
@@ -92,6 +96,7 @@ set(CORE_HEADERS
9296
set(HEADERS
9397
${CLIENT_MESSAGES}
9498
${SERVER_MESSAGES}
99+
${TYPE_HEADERS}
95100
${CORE_HEADERS}
96101
)
97102

src/libs/protocol/include/protocol/server/GenericMove.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
#include <protocol/StreamResult.h>
1313
#include <protocol/ResultCodes.h>
1414
#include <protocol/MovementInfo.h>
15+
#include <protocol/types/PackedGuid.h>
1516
#include <stdexcept>
1617
#include <cstdint>
1718

1819
namespace ember::protocol::server {
1920

2021
struct GenericMove final {
21-
std::uint64_t guid;
22+
PackedGuid guid;
2223
MovementInfo info;
2324

2425
StreamResult read_from_stream(le_stream auto& stream) {

src/libs/protocol/include/protocol/server/MoveFallLand.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
#include <protocol/StreamResult.h>
1313
#include <protocol/ResultCodes.h>
1414
#include <protocol/MovementInfo.h>
15+
#include <protocol/types/PackedGuid.h>
1516
#include <stdexcept>
1617
#include <cstdint>
1718

1819
namespace ember::protocol::server {
1920

2021
struct MoveFallLand final {
21-
std::uint64_t guid;
22+
PackedGuid guid;
2223
MovementInfo info;
2324

2425
StreamResult read_from_stream(le_stream auto& stream) {

src/libs/protocol/include/protocol/server/MoveTimeSkipped.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
#include <protocol/Concepts.h>
1212
#include <protocol/StreamResult.h>
1313
#include <protocol/ResultCodes.h>
14+
#include <protocol/types/PackedGuid.h>
1415
#include <stdexcept>
1516
#include <cstdint>
1617

1718
namespace ember::protocol::server {
1819

1920
struct MoveTimeSkipped final {
20-
std::uint64_t guid;
21+
PackedGuid guid;
2122
std::uint32_t lag;
2223

2324
StreamResult read_from_stream(le_stream auto& stream) {

src/libs/protocol/include/protocol/server/SplineMoveSetWalkMode.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
#include <protocol/Concepts.h>
1212
#include <protocol/StreamResult.h>
1313
#include <protocol/ResultCodes.h>
14+
#include <protocol/types/PackedGuid.h>
1415
#include <array>
1516
#include <stdexcept>
1617
#include <cstdint>
1718

1819
namespace ember::protocol::server {
1920

2021
struct SplineMoveSetWalkMode final {
21-
std::uint64_t guid;
22+
PackedGuid guid;
2223

2324
StreamResult read_from_stream(le_stream auto& stream) {
2425
stream >> guid;
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Copyright (c) 2026 Ember
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+
*/
8+
9+
#pragma once
10+
11+
#include <bit>
12+
#include <climits>
13+
#include <cstdint>
14+
15+
namespace ember::protocol {
16+
17+
using Guid = std::uint64_t; // temp
18+
19+
struct PackedGuid {
20+
Guid guid = 0;
21+
22+
PackedGuid() = default;
23+
24+
explicit PackedGuid(Guid value)
25+
: guid(value) {}
26+
27+
PackedGuid& operator=(Guid value) {
28+
guid = value;
29+
return *this;
30+
}
31+
32+
auto& operator<<(auto& stream) const {
33+
// produce the mask
34+
std::uint8_t mask = 0;
35+
std::uint8_t set = 0;
36+
37+
for(auto i = 0; i < sizeof(std::uint64_t); ++i) {
38+
const auto seg_mask = static_cast<std::uint64_t>(0xff) << (i * CHAR_BIT);
39+
40+
if(guid & seg_mask) {
41+
mask |= (1 << i);
42+
++set;
43+
}
44+
}
45+
46+
stream << mask;
47+
48+
// send the set bytes
49+
std::uint8_t sent = 0;
50+
51+
for(auto i = 0; i < sizeof(std::uint64_t); ++i) {
52+
const auto byte = static_cast<std::uint8_t>((guid >> (i * CHAR_BIT)) & 0xff);
53+
54+
if(!byte) {
55+
continue;
56+
}
57+
58+
stream << byte;
59+
60+
if(++sent == set) {
61+
break;
62+
}
63+
}
64+
65+
return stream;
66+
}
67+
68+
auto& operator>>(auto& stream) {
69+
const std::uint8_t mask;
70+
stream >> mask;
71+
72+
const auto count = std::popcount(mask);
73+
74+
if(count == CHAR_BIT) {
75+
stream >> guid;
76+
return stream;
77+
}
78+
79+
std::uint8_t bits_set = 0;
80+
81+
for(auto i = 0; i < CHAR_BIT; ++i) {
82+
if(mask & (1 << i)) {
83+
std::uint8_t byte;
84+
stream >> byte;
85+
guid |= (static_cast<std::uint64_t>(byte) << (i * CHAR_BIT));
86+
87+
if(++bits_set == count) {
88+
break;
89+
}
90+
}
91+
}
92+
93+
return stream;
94+
}
95+
};
96+
97+
} // protocol, ember

src/realm/states/WorldEnter.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,6 @@ void handle_move_fall_land(ClientContext& ctx) {
227227
if(auto result = protocol::deserialise(packet, ctx.stream()); !result) {
228228
return ctx.stream_err(result);
229229
}
230-
231-
protocol::move_fall_land_s response;
232-
response->guid = packed_guid;
233-
response->info = packet->info;
234-
ctx.send(response);
235230
}
236231

237232
void handle_move_set_facing(ClientContext& ctx) {
@@ -240,11 +235,6 @@ void handle_move_set_facing(ClientContext& ctx) {
240235
if(auto result = protocol::deserialise(packet, ctx.stream()); !result) {
241236
return ctx.stream_err(result);
242237
}
243-
244-
protocol::msg_move_set_facing_s response;
245-
response->guid = packed_guid;
246-
response->info = packet->info;
247-
ctx.send(response);
248238
}
249239

250240
void handle_zone_update(ClientContext& ctx) {

0 commit comments

Comments
 (0)