xilophor-StaticNetcodeLib icon

StaticNetcodeLib

A library/patcher for NGO in a static context.

Last updated 2 months ago
Total downloads 1417
Total rating 3 
Categories Libraries BepInEx Client-side Server-side
Dependency string xilophor-StaticNetcodeLib-1.0.3
Dependants 3 other packages depend on this package

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100
Lordfirespeed-OdinSerializer-2022.11.9 icon
Lordfirespeed-OdinSerializer

Fast, robust, powerful and extendible .NET serializer built for Unity

Preferred version: 2022.11.9

README

StaticNetcodeLib

Build Latest Version Thunderstore Downloads NuGet Version

This lib allows BepInEx mods to use Netcode for GameObjects in a static context.

Usage

Add the appropriate BepInDependency attribute to your plugin class, like so:

[BepInDependency(StaticNetcodeLib.Guid, DependencyFlags.HardDependency)]
public class ExampleMod : BaseUnityPlugin

Then add the StaticNetcode attribute to any classes that have static rpcs.

[StaticNetcode]
public class ExampleNetworkingClass

After that, you can simply use Server & Client Rpcs as you normally would (even outside NetworkBehaviours), but in a static context, like so:

[ClientRpc]
public static void ExampleClientRpc(string exampleString)
{
    ExampleMod.Logger.LogDebug(exampleString);
}

/* ... */

ExampleClientRpc("Hello, world!");

Note: The Rpc attribute params are not respected for this. For example, ServerRpcs are static and thus cannot have an owner, and are used as if it had the RequireOwnership = false parameter.

Acknowledgements

Thank you @Lordfirespeed for being my rubber ducky.