the files

This commit is contained in:
niko
2026-10-14 06:59:51 +02:00
parent f6175893fc
commit 2040419525
1855 changed files with 6735668 additions and 0 deletions
@@ -0,0 +1,65 @@
diff --git a/include/lnl/net_manager.h b/include/lnl/net_manager.h
index c1ec872..e96dbf5 100644
--- a/include/lnl/net_manager.h
+++ b/include/lnl/net_manager.h
@@ -4,6 +4,8 @@
#include <optional>
#include <thread>
#include <unordered_map>
+#include <functional>
+#include <vector>
#ifdef WIN32
@@ -80,6 +82,13 @@ namespace lnl {
bool disconnect_on_unreachable = false;
std::string name;
+ // Optional datagram transform layers (a generic hook, equivalent to the C# PacketLayerBase).
+ // outbound_layer: given the packet about to be sent, fill `out` with the bytes to put on the
+ // wire and return their length. inbound_layer: mutate a freshly received datagram in place
+ // and return the new length, or 0 to drop it. Used by Tachyon for the RecRoom 0x11 marker.
+ std::function<size_t(const uint8_t* data, size_t length, std::vector<uint8_t>& out)> outbound_layer;
+ std::function<size_t(uint8_t* data, size_t length)> inbound_layer;
+
explicit net_manager(net_event_listener* listener);
~net_manager();
diff --git a/src/lnl/net_manager.cpp b/src/lnl/net_manager.cpp
index 0cfe2a7..fa23eef 100644
--- a/src/lnl/net_manager.cpp
+++ b/src/lnl/net_manager.cpp
@@ -219,6 +219,15 @@ void lnl::net_manager::receive_logic() {
packet->resize(size);
+ if (inbound_layer) {
+ size_t newLen = inbound_layer(packet->data(), (size_t) size);
+ if (newLen == 0) { // layer dropped the datagram (unknown/undecryptable marker)
+ pool_recycle(packet);
+ continue;
+ }
+ packet->resize(newLen);
+ }
+
on_message_received(packet, addr);
}
}
@@ -517,8 +526,16 @@ int32_t lnl::net_manager::send_raw(const uint8_t* data, size_t offset, size_t le
return 0;
}
+ const uint8_t* sendData = &data[offset];
+ size_t sendLen = length;
+ if (outbound_layer) {
+ thread_local std::vector<uint8_t> layerBuf;
+ sendLen = outbound_layer(&data[offset], length, layerBuf);
+ sendData = layerBuf.data();
+ }
+
auto result = sendto(m_socket,
- (const char*) &data[offset], (int) length,
+ (const char*) sendData, (int) sendLen,
0,
(sockaddr*) &endpoint.raw, sizeof(sockaddr_in));
+45
View File
@@ -0,0 +1,45 @@
# Patches applied to vendored submodules
## `0001-tachyon-packet-layer-hook.patch` → `vendor/LiteNetLibPP`
Applies to: LiteNetLibPP @ `c6625b0652c5930046b75b495db314456c8bc411`
(https://github.com/Revan600/LiteNetLibPP), the pinned submodule under `vendor/LiteNetLibPP`.
### Why
Upstream has no packet-layer abstraction, but the Rec Room client wraps every datagram in a
trailing-marker "encrypt" layer (a `0x11` byte on the plaintext path). This patch adds a generic
datagram-transform hook — the equivalent of the C# LiteNetLib `PacketLayerBase` — so Tachyon can
install the marker without forking the library wholesale. It is deliberately generic (not
RecRoom-specific) so it could be submitted upstream unchanged.
### What it changes
- `include/lnl/net_manager.h` — two public `std::function` members, `outbound_layer` and
`inbound_layer` (both default null → stock behaviour), plus `<functional>`/`<vector>` includes.
- `src/lnl/net_manager.cpp`
- `send_raw()` — if `outbound_layer` is set, transform the bytes just before `sendto`.
- `receive_logic()` — if `inbound_layer` is set, transform/drop each datagram just after
`recvfrom`, before `on_message_received`.
Tachyon installs the `0x11` marker through these hooks in `src/main.cpp`.
### How it is applied
The top-level `CMakeLists.txt` applies this patch to the submodule working tree at configure time,
idempotently (`git apply --reverse --check` detects an already-patched tree and skips). This leaves
the submodule showing as "dirty" in `git status` — that is expected. To reset it:
`git -C vendor/LiteNetLibPP checkout .`
### Regenerating the patch (if the pin is bumped)
```sh
# from a pristine checkout of the new upstream commit, with the two files edited:
git -C <litenetlibpp> diff > patches/0001-tachyon-packet-layer-hook.patch
```
### Known limitation
The outbound hook appends its marker *after* LiteNetLibPP's MTU/fragmentation math, without
reserving space the way the C# `ExtraPacketSizeForLayer` did. Safe here because every packet the
server *sends* is far below the MTU; revisit if the server ever sends reliable data near the MTU.