Rune580-REPO_SteamNetworking_Lib icon

REPO SteamNetworking Lib

API/Library for networking using Steamworks socket relays. Very much WIP, but still usable, mostly.

Last updated 2 months ago
Total downloads 55344
Total rating 1 
Categories Mods Libraries
Dependency string Rune580-REPO_SteamNetworking_Lib-0.1.1
Dependants 9 other packages depend on this package

This mod requires the following mods to function

BepInEx-BepInExPack-5.4.2100 icon
BepInEx-BepInExPack

BepInEx pack for Mono Unity games. Preconfigured and ready to use.

Preferred version: 5.4.2100

README

API for R.E.P.O that allows for networking using Steamworks.

[!IMPORTANT] This does not allow you to host lobbies using steam or enable local hosting!

This is an API for Mod Developers so they can offload their mods' networking off of the REPO Photon servers to help the REPO devs save bandwidth.

Check the Full Documentation for up-to-date Docs

Basic documentation is as follows

Set version compatibility

Method A

[RSNVersionCompatibility(VersionCompatibility.Strict, optional: false)] // Defaults
[BepInPlugin(...)]
class ExampleModPlugin : BaseUnityPlugin {...}

Method B

class ExampleModPlugin : BaseUnityPlugin 
{
    private void Awake() 
    {
        RepoSteamNetwork.SetVersionCompatibility(VersionCompatibility.Strict, plugin: this);
    }
}

Create network packet

public class ExamplePacket : NetworkPacket<ExamplePacket>
{
    public string ExampleDataString;
    public Vector3 ExampleVector;
    
    protected override void WriteData(SocketMessage socketMessage) 
    {
        socketMessage.Write(ExampleDataString);
        socketMessage.Write(ExampleVector);
    }
    
    protected override void ReadData(SocketMessage socketMessage) 
    {
        ExampleDataString = socketMessage.Read<string>();
        ExampleVector = socketMessage.Read<Vector3>();
    }
}

Register network packet

RepoSteamNetwork.RegisterPacket<ExamplePacket>();

Setup callback

Method A

Register callback

{
    ...
    RepoSteamNetwork.AddCallback<ExamplePacket>(OnExamplePacketReceived);
    ...
}

private static void OnExamplePacketReceived(ExamplePacket packet) 
{
    // Do stuff with your packet data
    
    Debug.Log($"Received ExamplePacket Data: ({packet.ExampleDataString}, {packet.ExampleVector})");
}

Method B

Do your callback in ReadData in your packet

public class ExamplePacket : NetworkPacket<ExamplePacket>
{
    ...
    
    protected override void ReadData(SocketMessage socketMessage) 
    {
        ExampleDataString = socketMessage.Read<string>();
        ExampleVector = socketMessage.Read<Vector3>();
        
        // Do stuff with your data here
        
        Debug.Log($"Received ExamplePacket Data: ({ExampleDataString}, {ExampleVector})");
    }
}

Send Packet

var packet = new ExamplePacket 
{
    ExampleDataString = "Example string here",
    ExampleVector = Vector3.One,
}

// By default sends packet to everyone including the user who sends the packet
RepoSteamNetwork.SendPacket(packet);
// or send it only to the host
RepoSteamNetwork.SendPacket(packet, NetworkDestination.HostOnly);