ProjectLiberator.NetGen
1.0.0-rc1
dotnet add package ProjectLiberator.NetGen --version 1.0.0-rc1
NuGet\Install-Package ProjectLiberator.NetGen -Version 1.0.0-rc1
<PackageReference Include="ProjectLiberator.NetGen" Version="1.0.0-rc1"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ProjectLiberator.NetGen" Version="1.0.0-rc1" />
<PackageReference Include="ProjectLiberator.NetGen"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ProjectLiberator.NetGen --version 1.0.0-rc1
#r "nuget: ProjectLiberator.NetGen, 1.0.0-rc1"
#:package ProjectLiberator.NetGen@1.0.0-rc1
#addin nuget:?package=ProjectLiberator.NetGen&version=1.0.0-rc1&prerelease
#tool nuget:?package=ProjectLiberator.NetGen&version=1.0.0-rc1&prerelease
UCS NetGen
This source generator replaces the "Net Gen" tool from the Unturned 3 SDK for modules that want to use Unturned's networking.
Enums
Enums decorated with the [NetEnum] attribute will cause extension methods to be generated for NetPakReader and NetPakWriter for reading and writing the enum from a binary buffer.
This enum...
[NetEnum]
public enum PlayerMode
{
Walking,
Running,
Eating,
Driving,
Drinking
}
will result in the following extension methods:
reader.ReadEnum(out PlayerMode mode);
writer.WriteEnum(PlayerMode.Driving);
These methods are generated in the hidden PlayerMode_NetEnum class.
SteamCalls (Receivers)
Methods decorated with the [SteamCall(...)] attribute will cause a method to generate read and write methods for invoking it.
For example, this method...
public static class MyMethods
{
[SteamCall(ESteamCallValidation.ONLY_FROM_SERVER)]
public static void Method(int param1, Vector3 param2) { }
}
Will generate a read and write method in the MyMethods_NetMethods class:
[NetInvokableGeneratedMethodAttribute(
nameof(MyMethods.Method),
ENetInvokableGeneratedMethodPurpose.Read
)]
public static void Method_Read(in ClientInvocationContext context)
{
NetPakReader reader = context.reader;
// read param1, param2
MyMethods.Method(param1, param2);
}
[NetInvokableGeneratedMethodAttribute(
nameof(MyMethods.Method),
ENetInvokableGeneratedMethodPurpose.Write
)]
public static void Method_Write(NetPakWriter writer, int param1, Vector3 param2)
{
// write param1, param2
}
Extensions
The source generator supports extension blocks or classic extension methods to extend in-game classes with instance methods.
public static class PlayerExtensions
{
private static readonly ServerStaticMethod<string> SendAddPlayer
= ServerStaticMethod<string>.Get(ReceiveAddPlayer);
private static readonly ServerInstanceMethod<float> SendFlyRequest
= ServerInstanceMethod<float>.Get(typeof(PlayerExtensions), nameof(ReceiveFlyRequest));
extension(Player player)
{
public void ClientRequestFly(float speed)
{
SendFlyRequest.Invoke(player.GetNetId(), ENetReliability.Unreliable, speed);
}
[SteamCall(ESteamCallValidation.ONLY_FROM_OWNER)]
public void ReceiveFlyRequest(float speed)
{
player.StartFlying(flySpeed: speed);
}
public static void ClientAddPlayer(string name)
{
SendAddPlayer.Invoke(ENetReliability.Reliable, name);
}
[SteamCall(ESteamCallValidation.SERVERSIDE)]
public static void ReceiveAddPlayer(string name)
{
Provider.clients.Add(new Player(name));
}
}
}
For a type to be an instance, it must be registered with a NetId.
To support ONLY_FROM_OWNER validation, it must also either derive from SteamCaller or define an accessible SteamChannel channel property or field.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ProjectLiberator.NetGen:
| Package | Downloads |
|---|---|
|
DanielWillett.UnturnedStandardModuleNetworking
Code and analyzers for USMN. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-rc1 | 107 | 7/10/2026 |
Initial release.