NicholaScott.BepInEx.RuntimeNetcodeRPCValidator 0.1.8

There is a newer version of this package available.
See the version list below for details.
dotnet add package NicholaScott.BepInEx.RuntimeNetcodeRPCValidator --version 0.1.8                
NuGet\Install-Package NicholaScott.BepInEx.RuntimeNetcodeRPCValidator -Version 0.1.8                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NicholaScott.BepInEx.RuntimeNetcodeRPCValidator" Version="0.1.8" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NicholaScott.BepInEx.RuntimeNetcodeRPCValidator --version 0.1.8                
#r "nuget: NicholaScott.BepInEx.RuntimeNetcodeRPCValidator, 0.1.8"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install NicholaScott.BepInEx.RuntimeNetcodeRPCValidator as a Cake Addin
#addin nuget:?package=NicholaScott.BepInEx.RuntimeNetcodeRPCValidator&version=0.1.8

// Install NicholaScott.BepInEx.RuntimeNetcodeRPCValidator as a Cake Tool
#tool nuget:?package=NicholaScott.BepInEx.RuntimeNetcodeRPCValidator&version=0.1.8                

Runtime Unity Netcode Patcher

Build

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.

Table of Contents

Getting Started

To integrate Runtime Unity Netcode Patcher in your Unity project, follow these steps:

  1. Reference the Output DLL: Include the output DLL in your project and add an [BepInDependency(RuntimeNetcodeRPCValidator.PluginInfo.GUID)] attribute to your [BepInPlugin].
  2. Instantiate NetcodeValidator: Create and maintain a reference to an instance of 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.
  3. Define and Use RPCs: Ensure your Remote Procedure Calls on your NetworkBehaviours have the correct attribute and end their name with ServerRpc/ClientRpc.

Examples

// Example of using NetcodeValidator
namespace SomePlugin {
    [BepInPlugin("My.Plugin.Guid", "My Plugin Name", "0.1.1")]
    [BepInDependency(RuntimeNetcodeRPCValidator.MyPluginInfo.PLUGIN_GUID, RuntimeNetcodeRPCValidator.MyPluginInfo.PLUGIN_VERSION)]
    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 (IsHost)
                RunClientRpc();
        }
    }
}

Prerequisites

Ensure you have the following components within the environment:

Notes

Utilize the NetworkBehaviourExtensions.LastSenderId property to retrieve the ID of the last RPC sender. This will always be NetworkManager.ServerClientId on the clients.

Built With

Acknowledgments

  • @Lordfirespeed for invaluable support and insights throughout the development.

Contributing

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.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.4 138 1/6/2024
0.2.3 123 1/6/2024
0.2.2 92 1/5/2024
0.2.1 87 1/4/2024
0.2.0 72 1/4/2024
0.1.8 80 1/2/2024
0.1.7 86 1/2/2024
0.1.6 86 1/2/2024