Nytra-InterprocessLib icon

InterprocessLib

Library for mods to send data to the renderer and back.

Last updated 3 weeks ago
Total downloads 150
Total rating 0 
Categories Libraries
Dependency string Nytra-InterprocessLib-2.0.1
Dependants 1 other package depends on this package

This mod requires the following mods to function

ResoniteModding-BepisLoader-1.4.1 icon
ResoniteModding-BepisLoader

A mod loader which allows using BepInEx with Resonite

Preferred version: 1.4.1
ResoniteModding-BepisResoniteWrapper-1.0.0 icon
ResoniteModding-BepisResoniteWrapper

Common hooks and events library for BepInEx Resonite mods. Provides essential events like OnEngineReady to simplify mod development.

Preferred version: 1.0.0
ResoniteModding-RenderiteHook-1.1.0 icon
ResoniteModding-RenderiteHook

Allows passing custom command-line arguments to Resonite's Unity renderer process

Preferred version: 1.1.0

README

InterprocessLib

A library for Resonite that allows mods to send data to the renderer and back.

The library only depends on Renderite.Shared, meaning it could work with other mod loaders e.g. MonkeyLoader.

BepisLoader, BepInEx and RML example projects are included in the Tests folder.

Usage

After including the library in your project, all you have to do is create your own instance of the Messenger class. You can do this at any time, even before Resonite starts.

!!! Make sure both processes register with the same name !!!

var messenger = new Messenger("PluginName");

From here you can use the object to send data or to register callbacks to receive data. If you use the object before Resonite starts, the commands will get queued up.

messenger.SendValue<int>("TestValue", 637);

Here's how to receive a value in the other process.

messenger.ReceiveValue<int>("TestValue", (val) =>
{
	Log($"TestValue: {val}");
});

For BepisLoader and BepInEx, if you have a ConfigEntry/ModConfigurationKey in both processes with the same type and name, you can sync them like this:

messenger.SyncConfigEntry(MyConfigEntry);

You can also work with lists.

var list = new List<float>();
list.Add(2f);
list.Add(7f);
list.Add(21f);
messenger.SendValueList("TestValueList", list);
messenger.ReceiveValueList<float>("TestValueList", (list) => 
{
	Log($"TestValueList: {string.Join(",", list!)}");
});

If you want to send more complex data such as custom memory-packable structs and classes, you must register the types when you instantiate the messenger.

There are two lists that can be provided: the first is for IMemoryPackable class types, and the second is for unmanaged value types.

var messenger = new Messenger("UsingCustomTypes", [typeof(TestCommand), typeof(TestNestedPackable), typeof(TestPackable), typeof(RendererInitData)], [typeof(TestStruct), typeof(TestNestedStruct)]);

After doing this you can now send and receive those custom types.

var cmd = new TestCommand();
cmd.Value = 2932;
cmd.Text = "Hello world";
cmd.Time = DateTime.Now;
messenger.SendObject("TestCustomRendererCommand", cmd);

and to receive:

messenger.ReceiveObject<TestCommand>("TestCustomRendererCommand", (recvCmd) =>
{
	Log($"TestCustomRendererCommand: {recvCmd?.Value}, {recvCmd?.Text}, {recvCmd?.Time}");
});

For more examples you can check the tests files:

https://github.com/Nytra/ResoniteInterprocessLib/blob/main/InterprocessLib.Shared/Tests.cs

https://github.com/Nytra/ResoniteInterprocessLib/blob/main/Tests/InterprocessLib.BepInEx.Tests/BepInExTests.cs

https://github.com/Nytra/ResoniteInterprocessLib/blob/main/Tests/InterprocessLib.BepisLoader.Tests/BepisLoaderTests.cs

https://github.com/Nytra/ResoniteInterprocessLib/blob/main/Tests/InterprocessLib.RML.Tests/RML_Tests.cs

Installation (Manual)

  1. Install BepisLoader and BepInExRenderer and RenderiteHook for Resonite.
  2. Download the latest release ZIP file (e.g., Nytra-InterprocessLib-1.0.0.zip) from the Releases page.
  3. Extract the ZIP and copy the plugins folder to your BepInEx folder in your Resonite installation directory and the renderer directory:
    • Default location: C:\Program Files (x86)\Steam\steamapps\common\Resonite\BepInEx\
    • Renderer default location: C:\Program Files (x86)\Steam\steamapps\common\Resonite\Renderer\BepInEx\
  4. Start the game. If you want to verify that the mod is working you can check your BepInEx logs.