StaticNetcodeLib
This lib/patcher is a small patcher that will modify how your static rpcs run, to allow them to be networked. Using this patcher is simple, and requires very little changes to how you typically use RPCs.
WARNING
Currently, only RPC formatting from before NGO version 1.8 are supported (i.e. ServerRpc and ClientRpc). The newer version of RPCs - that driven by attribute paramters - is not (yet) supported by this patcher.
Installation
To intsall this lib, reference the package through NuGet. This can be done in several ways:
- Through your IDE's interface.
- In the command line.
- This can be done with the following command:
$ dotnet add package Xilophor.StaticNetcodeLib- Modifying your
.csprojfile.- Add the following snippet to your project file:
<ItemGroup>
<PackageReference Include="Xilophor.StaticNetcodeLib" Version="1.*" PrivateAssets="all" />
</ItemGroup>Usage
Once StaticNetcodeLib is referenced, add a BepInDependency to "Xilophor.StaticNetcodeLib", or use StaticNetcodeLib.Guid. It should look like so:
[BepInDependency(StaticNetcodeLib.Guid, DependencyFlags.HardDependency)]DANGER
This step is mandatory. If you do not add the dependency, your mod will not be patched.
Next, add the [StaticNetcode] attribute to any classes that will have static RPCs in them. This tells StaticNetcodeLib to search through those classes for RPCs that are static.
Finally, make sure that your RPC is static, like so:
[StaticNetcode]
public class ExampleNetworkingClass
{
[ServerRpc]
public static void ExampleServerRpc(string messageToLog)
{
ExampleMod.Logger.LogDebug(messageToLog);
}
}Differences to NGO RPCs
The major difference, outside of the static environment, to NGO's RPCs is the serialization of data. StaticNetcodeLib uses OdinSerializer to serialize data that is sent across the network. The lib does, however, still support INetworkSerializable, and thus will serialize classes/structs that implement that interface.
WARNING
One of the data types that is not supported by OdinSerializer - and thus will not be serialized - are records.
Limitations
There are not many limitations of what you can do with static RPCs over what you can do with typical RPCs, outside of the static vs instanced nature. One of the few limitations to these static RPCs is that any attribute data you have will be ignored - though this will only appear in specific use cases, such as [ClientRpc(Delivery = RpcDelivery.Unreliable)].
Otherwise, there are no major limitations in what you do differently.