Project Structure
The codebase is organized into several key projects:Core Components
Nitrox.Launcher
Desktop application built with Avalonia UI that manages game installation, server launching, and configuration. Serves as the entry point for users.
NitroxPatcher
Harmony-based patching system that modifies Subnautica’s runtime behavior. Injects into the game process and applies both persistent and dynamic patches.
NitroxClient
Client-side multiplayer logic including networking, game state synchronization, and player interaction handling.
Nitrox.Server.Subnautica
Dedicated server application that manages multiplayer sessions, world state, and player coordination.
Shared Libraries
Nitrox.Model
Core data structures, networking primitives, and shared abstractions used across all components.
Nitrox.Model.Subnautica
Subnautica-specific packet definitions, game logic models, and data structures.
Component Relationships
The components interact in a layered architecture:Initialization Flow
Launcher Starts
User launches Nitrox.Launcher, which validates the Subnautica installation and configuration.
Game Process Injection
Launcher starts Subnautica with
--nitrox parameter pointing to Nitrox libraries location.Patcher Execution
NitroxPatcher’s
Main.Execute() is called as the game’s entry point (NitroxPatcher/Main.cs:60).Dependency Resolution
Custom AssemblyResolve handler loads Nitrox DLLs from the launcher directory (NitroxPatcher/Main.cs:150).
Patch Application
Persistent patches are applied immediately; dynamic patches wait for multiplayer session start (NitroxPatcher/Patcher.cs:122).
Data Flow
Client to Server Communication
- Player deconstructs a base piece in Subnautica
BaseDeconstructable_Deconstruct_Patchintercepts the call (NitroxPatcher/Patches/Dynamic/BaseDeconstructable_Deconstruct_Patch.cs:67)- Patch creates
PieceDeconstructedpacket with base ID and piece identifier - Packet is serialized using BinaryPack and sent via UDP
- Server receives packet, updates world state, and broadcasts to other players
Server to Client Communication
- Server receives chat message from player A
- Server creates
ChatMessagepacket (Nitrox.Model.Subnautica/Packets/ChatMessage.cs:7) - Packet is broadcast to all connected clients
- Each client’s
PacketReceiverqueues the packet (NitroxClient/Communication/PacketReceiver.cs) - Corresponding packet processor updates the UI with the new message
Dependency Injection
Nitrox uses Autofac for dependency injection:- NitroxPatcher: Uses
NitroxPatchesModulefor patch discovery (NitroxPatcher/Patcher.cs:147) - NitroxClient: Uses
ClientAutoFacRegistrarfor service registration (NitroxPatcher/Patcher.cs:105) - Server: Uses
SubnauticaServerAutoFacRegistrarfor server-side services
Resolve<T>() method:
Dependency injection is initialized in
Patcher.Initialize() before any patches are applied, ensuring all components have access to required services.Project References
The dependency graph prevents circular references:Build Configuration
All projects share common build properties via:- Directory.Build.props: Shared MSBuild properties (C# version, nullable reference types, etc.)
- Directory.Build.targets: Custom build targets including Subnautica DLL references
- Directory.Packages.props: Centralized NuGet package version management
- Nitrox.Shared.props & Nitrox.Shared.targets: Nitrox-specific build configuration
Next Steps
Patching System
Learn how Harmony patches modify Subnautica’s behavior
Networking
Understand the UDP-based packet system
