

This plugin offers an easy-to-use solution for Netcode's NetworkBehaviour class, streamlining the approach to networking mods with Server and Client RPCs. By utilizing the CustomMessagingHandler of Netcode, it networks RPCs and their System.Serializable (Marked with [Serializable]) or INetworkSerializable parameters. While this is currently only in the Lethal Company directory, it can be expanded to other games upon request. Please reach out on Discord or via an issue here on Github for questions or contact.
To integrate Runtime Unity Netcode Patcher in your Unity project, follow these steps:
[BepInDependency(RuntimeNetcodeRPCValidator.PluginInfo.GUID)] attribute to your [BepInPlugin].NetcodeValidator && call NetcodeValidator.PatchAll(). When you wish to revert any patches applied, simply call Dispose(), or UnpatchSelf() if you want to keep the instance, on the instance. A new instance can then be created to reapply the netcode patching.// Example of using NetcodeValidator
namespace SomePlugin {
public class MyPlugin : BaseUnityPlugin {
private NetcodeValidator netcodeValidator;
private void Awake()
{
netcodeValidator = new NetcodeValidator(this);
netcodeValidator.PatchAll();
}
// [[OPTIONAL DISPOSE TO UNPATCH]]
private void OnDestroy()
{
netcodeValidator.Dispose();
}
}
}
// Example of using Server or Client RPCs. Naming conventions require the method to end with the corresponding attribute name.
namespace SomePlugin {
// This assumes you've declared a BaseUnityPlugin and Harmony instance elsewhere. Including the previous snippet about NetcodeValidator.
[HarmonyPatch(typeof(Terminal), "Start")]
private static class Patch {
[HarmonyPrefix]
private static void AddToTerminalObject(Terminal __instance) {
__instance.gameObject.AddComponent<PluginNetworkingInstance>();
}
}
public class PluginNetworkingInstance : NetworkBehaviour {
[ServerRpc]
public void SendPreferredNameServerRpc(string name) {
Debug.Log(name);
TellAllOtherClients(NetworkBehaviourExtensions.LastSenderId, name);
}
[ClientRpc]
public void TellEveryoneClientRpc(ulong senderId, string name) {
Debug.Log(StartOfRound.Instance.allPlayerScripts.First(playerController => playerController.actualClientId == senderId).playerUsername + " is now " + name);
}
[ClientRpc]
public void RunClientRpc() {
SendPreferredNameServerRpc("Nicki");
}
public void Awake()
{
if (NetworkManager.Instance.IsHost)
RunClientRpc();
}
}
}
Ensure you have the following components within the environment:
Utilize the NetworkBehaviourExtensions.LastSenderId property to retrieve the ID of the last RPC sender. This will always be NetworkManager.ServerClientId on the clients.
We welcome contributions! If you would like to help improve the Runtime Unity Netcode Patcher, please submit pull requests, and report bugs or suggestions in the issues section of this repository.