Getting Started
This guide walks you through setting up SteamNetworkLib in a Unity game mod using MelonLoader and implementing the minimal loop.
Installation
Prerequisites
- MelonLoader installed on the target Unity game
- Steam client running
- Unity game with Steam integration
- Basic C# and MelonLoader modding knowledge
- Visual Studio or VS Code
Add SteamNetworkLib to Your Mod Project
Target .NET Standard 2.1 (works for Mono and Il2Cpp) and reference SteamNetworkLib:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AssemblyTitle>YourAwesomeMod</AssemblyTitle>
<AssemblyVersion>1.0.0</AssemblyVersion>
</PropertyGroup>
</Project>
Add references to:
- MelonLoader.dll
- UnityEngine.dll
- Assembly-CSharp.dll
- SteamNetworkLib.dll
Minimal mod setup
using MelonLoader;
using SteamNetworkLib;
public class YourAwesomeModMain : MelonMod
{
private SteamNetworkClient client;
public override void OnInitializeMelon()
{
client = new SteamNetworkClient();
if (client.Initialize())
{
// Optional: subscribe to events
client.OnLobbyCreated += (s, e) => MelonLogger.Msg($"Lobby: {e.Lobby.LobbyId}");
}
}
public override void OnUpdate()
{
client?.ProcessIncomingMessages();
}
public override void OnDeinitializeMelon()
{
client?.Dispose();
}
}
From here, pick the guide you need next:
- Lobby Management: create/join/leave/invite
- Data Synchronization: lobby and member data
- P2P Messaging: typed messages, files, channels
- Events and Errors: event model and exceptions
- Recipes: copy-paste snippets for common tasks