Skip to content

VRChatOSCSwitch guide

bree edited this page May 20, 2022 · 2 revisions

How the program works

The app will work as a "OSC switch" for the OSC server, something like an Ethernet switch in a local area network.

diagram

Let's make an example to understand the diagram. We have the OSC server, which in this example is VRChat, and we have the OSC clients, VRCFaceTracking and YeelightOSC.

The two OSC clients will fight to take ownership of the OSC server's ports, and once one of the manages to lock on them, the other app will either fail to send and receive events from the server (like YeelightOSC) or completely crash (like VRCFaceTracking).
The OSC switch (VRChatOSCSwitch) will act as a communication route between the OSC server and the OSC client, allowing multiple clients to talk to the same port at the same time.
The switch will connect to the OSC server's input and output ports (So port 9000 and 9001 for the VRChat example), and forward the OSC's server packets to the OSC clients and viceversa.

This switch system will only work if the OSC clients allow you to change the default communication ports. Apps such as VRCFaceTracking and YeelightOSC allow you to do so by specificying an argument in the command line, which are --osc=$InPort$:127.0.0.1:$OutPort$ and InPort=$InPort$ OutPort=$OutPort$ respectively.

The OSC switch can automatically start the OSC clients on boot-up, saving you the time of starting them manually through the command line, with the required arguments too.
Down below, you can find the structure of the settings.json file, used on boot-up by the OSC switch app to prepare itself and the OSC clients for communication.


JSON structure

The JSON is structured in a easy and straightforward way, which should let you understand its basic functionality out of the box.
If you have troubles figuring it out though, you can use this wiki page to learn its structure.

The JSON structure is as follows:

{
  "OutPort": 9000,
  "InPort": 9001,
  "RemoteControlOutPort": 8000,
  "RemoteControlInPort": 8001,
  "HidePublicIP": true,
  "OSCPrograms": [
    {
      "Name": "TargetAppName",
      "ExecutablePath": "C:\\TargetApp.exe",
      "CommandLine": "--osc=$InPort$:127.0.0.1:$OutPort$",
      "FwdOutPort": 10000,
      "FwdInPort": 10001,
      "SeparateConsole": true,
      "Addresses": [
        {
          "Address": "/avatar/parameters",
          "Parameters": [
            "param1",
            "param2"
          ]
        },
        {
          "Address": "/something/else",
          "Parameters": [
            "cpu",
            "ram"
          ]
        }
      ]
    }
  ],
  "GETTargets": [
    {
      "Address": "http://targetwebsite.pop/hello",
      "TargetAddress": "/avatar/parameters/ToWebsite",
      "Vars": [
        {
          "VarName": "constant1",
          "VarType": "int",
          "Value": 100,
          "Constant": true
        },
        {
          "VarName": "constant2",
          "VarType": "int",
          "Value": 100,
          "Constant": true
        },
        {
          "VarName": "oscsas",
          "VarType": "float",
          "MinValue": 2,
          "MaxValue": 5,
          "Constant": false
        }
      ]
    }
  ]
}

Main values

The main values contains the required settings for the OSC switch to run and interface itself with the OSC server.

InPort/OutPort (int)

These values are used to specify to the OSC switch program which UDP ports from the OSC server should be forwarded to the OSC clients hosted by the switch itself.
For example, these ports will be 9000 for OutPort, and 9001 for InPort, if used with VRChat.

RemoteControlInPort/RemoteControlOutPort (int)

These values will be used by the switch program to allow external packets from outside the loopback area.
This is required to allow packets from outside your PC from being picked up by the switch program. If you don't specify them, it will only be able to accept incoming packets from programs running on the switch program's host that are sending data to 127.0.0.1:$InPort$.
These packets will be forwarded automatically to both the OSC server and the OSC clients.

HidePublicIP (bool, defaults to true if not specified)

Setting this to false will show your public IP in the console, when logging on boot-up.
It is set to true by default for security reasons.


OSCPrograms array

The OSCPrograms array contains an array of structs containing all the information required to prepare the OSC client for communication with the OSC switch.
The struct is structured like this:

Name (string)

This is the friendly name of the OSC client, which will be used internally by the OSC switch when logging messages to the console.

ExecutablePath (string, optional)

This is the path to the OSC client's executable, which will be used to start up the program on boot-up.
This parameter is not required for the OSC switch to work. You can run the OSC client manually after starting the OSC switch.

CommandLine (string, optional)

This is the command line that will be passed to the executable on boot-up.
You can use the following parameters in the command line, which will be replaced with the correct values during boot-up:

  • $InPort$, which is the OSC server's input port, will be replaced by the value assigned to FwdOutPort, which is the OSC client's output.
  • $OutPort$, which is the OSC server's output port, will be replaced by the value assigned to FwdInPort, which is the OSC client's input.

FwdInPort/FwdOutPort (int)

These values are used to create the connection between the OSC client and the OSC switch.
The OSC client will communicate with the OSC switch, and then the switch will take care of forwarding the packets from the OSC client to the OSC server and viceversa.

SeparateConsole (bool, optional)

By setting this value to false, the OSC client's console (if there's one) will be displayed on the same console as the OSC switch. Useful to reduce clutter.
If the OSC client accepts input from the console, it is recommended to host it in a separate console window.


Addresses array

The Addresses array contains an array of structs containing the required address and parameters that will be forwarded to the OSC client.
The OSC switch will take care of concatenating the address and params, when registering them.
The struct is structured like this:

Address (string)

The target address containing all the parameters that need to be forwarded to the OSC client. (e.g. /avatar/parameters)

Params (string[])

The parameters contained under the address. (e.g. MouthPout, MouthUpper etc...)


GETTargets array

TBD