
YAPYAP
You are viewing a potentially older version of this package. View Latest Version

Utility BepInEx Mod that allows modders to insert and use new NetworkActions (Commands, ClientRpcs, and TargetRpcs)
Note: These steps assume you have some prior Unity modding knowledge.
If you do not need a background on Mirror Networking and just wnat to know how to use this utility, skip to Using MirrorPlumber for your NetworkBehaviour
Networkidentity component.
Networkidentity component at runtime because the assetId property will not be set properly.NetworkIdentity component, build it into an asset bundle.NetworkClient.RegisterPrefab on your game object.
GetComponent<NetworkIdentity>().assetId after you've registered your prefab.NetworkServer.Spawn on the copy with your cached assetId. internal static ManualLogSource Log { get; private set; } = null!;
internal static GameObject Networker = null!;
internal static uint NetworkerID = default!;
private void Awake()
{
Log = Logger;
Log.LogInfo($"Plugin {Name} is loaded!");
//Networker Bundle
string networkAsset = Path.Combine(Path.GetDirectoryName(Info.Location), "networker");
AssetBundle networker = AssetBundle.LoadFromFile(networkAsset);
Networker = networker.LoadAsset<GameObject>("Networker");
Networker.AddComponent<NetworkingTestWithPlumbing>();
GameManager.OnPlayerSpawned += OnPawnSpawn;
}
private void Start()
{
Log.LogMessage("Registering network prefabs");
NetworkClient.RegisterPrefab(Networker);
NetworkerID = Networker.GetComponent<NetworkIdentity>().assetId;
Log.LogDebug($"NetworkerID - {NetworkerID}");
}
private static void OnPawnSpawn(Pawn pawn)
{
Log.LogMessage($"Pawn spawned {pawn.PlayerName}");
if (!pawn.isLocalPlayer)
return;
if (pawn.isServer)
{
Log.LogDebug("Spawning networker");
var networker = Object.Instantiate(Networker);
NetworkServer.Spawn(networker, NetworkerID);
}
}
In the above example:
NetworkingTestWithPlumbing is added to the Networker GameObject at Plugin Awake[ClientRpc], [Command], etc. are not actually utilizing Mirror to send the information across the network.RemoteProcedureCalls.RegisterDelegate or RemoteProcedureCalls.RegisterRpc or RemoteProcedureCalls.RegisterCommand
internal static Plumber GeneratedCommand = null!;
internal static Plumber<string, int> GeneratedRPC = null!;
System.Type netBehaviour You'll provide this by converting your NetworkBehaviour to a System.Type - ie: typeof(MyNetworkBehaviour)string methodName This is the name of the Method you are performing plumbing for - ie: nameof(MyNetworkedMethod)NetType netType This is an enum created by MirrorPlumber to help identify what kind of NetworkAction you are requesting plumbing for.bool requiresAuthority = false (Optional) This bool determines if the NetworkAction requires ownership of the Network Prefab before being used.AddListener.
private void Awake()
{
GeneratedCommand = new(typeof(NetworkingTestWithPlumbing), nameof(CmdSendHello), PlumberBase.NetType.Command);
GeneratedCommand.AddListener(RpcShowHelloMessage);
GeneratedRPC = new(typeof(NetworkingTestWithPlumbing), nameof(RpcShowHelloMessage), PlumberBase.NetType.TargetRpc);
GeneratedRPC.AddListener(HelloFromTheNetwork);
}
TSource instance This is the instance of your NetworkBehaviour that is calling this method.NetworkConnection target = null! (OPTIONAL) If your NetworkAction is a TargetRpc, you'll need to set this to the client you wish to send the NetworkAction to.TParam param or TParam1 param1 or TParam2 param2 All of these potential parameters are values of the parameter types you are sending to other clients.GeneratedCommand?.Invoke(this); GeneratedRPC?.Invoke(this, "Hello World from the network!", 1337, NetworkServer.connections[0]);
NetworkingTestWithPlumbing