Terbin is a C# framework designed to power background services for the Farlands modding ecosystem. It solves the problem of safely routing mod-management commands — installing plugins, managing instances, querying game paths — between a long-running Windows service and any number of client tools, without requiring the service to poll or ask its clients for information it already holds. Communication happens over OS-level named pipes using a compact binary packet protocol, and every command handler is discovered and wired up automatically at startup through a reflection-based dispatcher. The result is a system where adding a new command is as simple as decorating a static method withDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/FarlandsModdingTeam/TerbinProyect/llms.txt
Use this file to discover all available pages before exploring further.
[TerbinExecutable].
Projects at a Glance
Terbin is organized into three C# projects that sit inside theTerbinProyect.sln solution:
-
TerbinLibrary — The core SDK. It contains the communication layer (
TerbinCommunicator), the binary packet types (Header,PacketRequest,IdArray,InfoResponse), the protocol constants (TerbinProtocol), the binary serialization helpers (Serialineitor,BufferWriter,BufferReader), the fragmentation/memory subsystem (TerbinMemory,TerbinMemoryManager), and the entire execution-dispatch pipeline (TerbinExecutableAttribute,TerbinExecutableManager,TerbinExecutor). Almost everything you import in your own project comes from here. -
TerbinService — The background service host. It runs as a .NET Generic Host (
Worker : BackgroundService) and immediately begins listening on a named pipe calledTerbinPipe. It contains a set of Managers that own business logic and mutable state (plugins, instances, games, configuration, the manifest index, the plugin storage), a set of thin Services that act as IPC dispatch handlers delegating to those managers, and Valve helpers (ManagerSteam,ManagerProton,ManagerFarlands) for Steam/Proton integration and Farlands game launching. - SimulateClient — A development and test client. It connects to the running service over the same pipe, registers its own executable handlers, and exposes an interactive command loop that lets you invoke any registered service method by name. It is the primary tool for testing new commands during development.
Design Philosophy
Terbin is built around three ideas:- Managers are self-sufficient. A manager is initialized with everything it needs; it never has to ask a client for information. This keeps the service authoritative and makes it safe to call manager methods from any thread without worrying about round-trip latency.
- Services are thin. A Service class contains only enough code to deserialize the incoming
byte[]payload, call the right manager method, and serialize the result back into anInfoResponse. Business logic lives exclusively in managers. - Named pipes are the IPC layer.
TerbinCommunicatorwrapsNamedPipeServerStream/NamedPipeClientStreamand handles connection, packet queuing, background send/receive loops, fragmentation of large payloads, and timeout-based pending-request tracking — all transparently.
Quickstart
Build and run your first Terbin server and client in five minutes.
Architecture
Deep-dive into projects, layers, and how a packet flows end-to-end.
Communication
Named pipes,
TerbinCommunicator, packet queuing, and fragmentation.Execution
[TerbinExecutable], TerbinExecutableManager, and the dispatch pipeline.Terbin was built specifically for the Farlands modding ecosystem and makes assumptions about paths, plugin layouts, and the BepInEx injector format. However, the IPC layer (
TerbinCommunicator), the binary protocol (TerbinProtocol), and the reflection-based dispatcher (TerbinExecutableManager) are general-purpose and reusable in any C# project that needs a named-pipe command bus.Key Features
- Named-pipe IPC — Bidirectional, asynchronous communication over
NamedPipeServerStream/NamedPipeClientStreamwith a single, consistent pipe name (TerbinPipeby default). - Binary packet protocol — Every message is a
PacketRequestcomposed of a fixed-sizeHeader(request ID, sequence order, status code, memory slot ID), a variable-lengthIdArrayaction key, and a rawbyte[]payload. - Automatic fragmentation — Payloads larger than
MAX_PLD(65,520 bytes /0xFFF0) are automatically split into fragments, uploaded viaTerbinMemoryslots on the receiver, and reassembled before the handler is invoked. The caller never manages this manually. - Reflection-based dispatcher — Decorate any
static async Task<InfoResponse?> Foo(Header, byte[], CancellationToken)method with[TerbinExecutable(byte action)]and callTerbinExecutor.Register(assembly). The dispatcher scans, validates method signatures, and registers handlers with no boilerplate switch statements. - Request/response correlation —
Communicate()returns aTask<PacketRequest>that resolves when the matching response packet arrives, identified by aushortrequest ID. Timeouts are enforced viaMaximumResponseTime(default 8 seconds). - Fire-and-forget sends —
Send()enqueues a packet without registering a pending reply, making it suitable for progress updates and notifications. - Multi-client server — The
OnNewClientConnectevent lets the server spin up a newTerbinCommunicatorinstance for each connecting client, enabling concurrent sessions. - Binary serialization helpers —
Serialineitorprovides static methods for serializing and deserializing primitives, arrays, and enums to/frombyte[].BufferWriterandBufferReadersupply low-levelSpan<byte>-backed read/write helpers used by everyIStructSerializableimplementation (PacketRequest,IdArray) in the protocol layer. - Farlands-aware managers — Built-in managers for plugins, mod instances, game paths, BepInEx injection, Steam/Proton detection, and configuration backed by
config.json.