FreyritTeam-REPO_SteamNetworking_Lib icon

REPO SteamNetworking Lib

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

Last updated 12 hours ago
Total downloads 45
Total rating 1 
Categories Mods Libraries
Dependency string FreyritTeam-REPO_SteamNetworking_Lib-0.1.3
Dependants 0 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.

Original project and library created by Rune580. This is a community update of Rune580's work; all original rights and the LGPL-3.0-or-later license are retained.

The current source supports R.E.P.O. v0.5.0 and keeps compatibility with earlier builds that use SteamManager. The project uses the latest published R.E.P.O.GameLibs.Steam reference package; the game’s Steam lobby hooks are resolved at runtime so the same build can target both lobby manager class names.

[!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);