Nitrox uses Harmony (specifically HarmonyX) to modify Subnautica’s behavior at runtime without modifying the game’s original files. This approach allows the mod to intercept, modify, and extend game functionality for multiplayer support.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Papela/Nitrox-Cracked-Mod/llms.txt
Use this file to discover all available pages before exploring further.
How Harmony Patching Works
Harmony patches work by modifying the Common Intermediate Language (CIL) of methods at runtime:- Target Method: Identify a method in Subnautica’s code to patch
- Patch Type: Choose how to modify it (Prefix, Postfix, Transpiler, or Finalizer)
- Patch Application: Harmony rewrites the method’s IL code to include your modifications
- Runtime Execution: When the game calls the method, your patch executes
Harmony patches are non-destructive and can be removed at runtime, making them ideal for dynamic multiplayer features that only need to be active during a session.
Patch Types in Nitrox
Nitrox uses two categories of patches:Persistent Patches
Applied when the game starts and remain active for the entire process lifetime. Used for core functionality that must always be present.NitroxPatcher/Patches/Persistent/
Purpose: Ensures critical Nitrox functionality (like keeping the game running in background for packet processing) is always active.
Dynamic Patches
Applied when a multiplayer session starts and removed when returning to the main menu. Used for multiplayer-specific functionality.NitroxPatcher/Patches/Dynamic/
Purpose: Synchronizes game events across multiple players during active sessions.
NitroxPatcher Architecture
Entry Point
The patcher is injected as Subnautica’s entry point:Patch Discovery and Application
Patches are automatically discovered via dependency injection:Persistent Patches Applied
All classes implementing
IPersistentPatch are discovered and applied when the game initializes.Lifecycle Hooks Registered
Dynamic patches are registered to apply when multiplayer starts and restore when it ends.
Dynamic Patches Applied
When player joins/hosts a session,
Apply() method patches all IDynamicPatch implementations.Patch Method Types
Prefix Patches
Run before the original method. Can prevent the original method from executing.- Prevent certain game actions in multiplayer
- Validate conditions before execution
- Cache data before the original method modifies it
Postfix Patches
Run after the original method completes.- Send packets after game events
- Modify return values
- React to completed actions
Transpiler Patches
Modify the IL code of the method itself. Most powerful but complex.- Insert code in the middle of a method
- Modify local variables
- Complex control flow changes
Finalizer Patches
Run after the method, even if it throws an exception. Used for cleanup.Creating a New Patch
Step 1: Create the Patch Class
Create a new file inNitroxPatcher/Patches/Dynamic/ or Persistent/:
Step 2: Implement Patch Methods
Add your patch logic:Step 3: Automatic Registration
Patches are automatically discovered by theNitroxPatchesModule - no manual registration needed!
The
partial keyword allows Harmony to generate additional code for the patch class. Always use it for patch classes.Patch Best Practices
Name patches clearly
Name patches clearly
Use the format
ClassName_MethodName_Patch so developers can quickly identify what’s being patched.Document why, not what
Document why, not what
Use dependency injection
Use dependency injection
Access services via
Resolve<T>() instead of static references:Handle null cases
Handle null cases
Subnautica’s code may have unexpected null values:
Choose dynamic vs persistent carefully
Choose dynamic vs persistent carefully
- Use persistent for core functionality (logging, assembly loading)
- Use dynamic for multiplayer synchronization (entity updates, player actions)
Debugging Patches
Enable Harmony Logging
Common Issues
Patch not applying
Patch not applying
- Check the
TARGET_METHODis correctly defined - Verify the target method exists in the game version
- Ensure patch class implements
IDynamicPatchorIPersistentPatch - Check logs for Harmony exceptions
Game crashes on patch
Game crashes on patch
- Null reference in patch method
- Type mismatch in parameters
- Transpiler generated invalid IL
- Check if game method signature changed
Patch applies but doesn't work
Patch applies but doesn't work
- Prefix returning true when it should return false
- Wrong method overload targeted
- Timing issue (patch runs too early/late)
Real-World Example
Here’s a complete dynamic patch from the codebase:- Caches data in Prefix before the original method destroys it
- Injects IL code via Transpiler to call custom method at precise locations
- Sends packets to synchronize base deconstruction across all players
- Handles errors gracefully with logging
Next Steps
Architecture
Understand how patches fit into the overall architecture
Networking
Learn how patches send data to the server
