ModMessage Class - PULSAR-Modders/pulsar-mod-loader GitHub Wiki

ModMessages are used as RPCs (Remote Procedure Call) to send messages between clients. They call pre-compiled functions on other clients with given arguments.

Creating ModMessages

Each ModMessage class will inherit from PulsarModLoader.ModMessage, and override the function HandleRPC(Object[], PhotonMessageInfo). Arguments are passed through as an object array containing serializable classes. In the example below, an integer and string have been passed through as arguments. The PhotonMessageInfo object is from the photon network api and includes the PhotonPlayer who sent the message, allowing for verification of sender for security and functionality purposes.

namespace MyNamespace
{
    class MyModMessage : PulsarModLoader.ModMessage
    {
        public override void HandleRPC(object[] arguments, PhotonMessageInfo sender)
        {
            int arg0 = (int)arguments[0];
            string arg1 = (string)arguments[1];
            //Your code here...
        }
    }
}

Calling ModMessages

Send a call to your RPC by using PulsarModLoader.ModMessage.SendRPC(). This method takes 4 arguments: the mod's harmonyIdentifier, the handlerIdentifier, the target PhotonPlayer or PhotonTargets, and arguments.

The 'harmonyIdentifier' is the identifier for the PulsarMod class (required for mods to be loaded). Simply use a matching string.

The 'handlerIdentifier' is a combination of the ModMessage namespace and class name.

The targeted PhotonPlayer or PhotonTargets is who your RPC will be sent to. Sending to PhotonPlayers goes directly to a given user. PhotonTargets are an Enum provided in the Assembly-CSharp representing several optional targets, including the masterclient, other clients, or all clients.

'arguments' is an object array containing serializable objects for the targeted ModMessage.

ModMessage.SendRPC("MyAuther.MyModName", "MyNamespace.MyModMessage", PhotonTargets.MasterClient, new object[] { 10, "ArgumentIndex1" });