A simple, straightforward OSC library for VRChat created in .NET Core 6, CSharp
Usage
These examples are for usage demonstrations... do not just copy-paste.
Or do. I am a programmer, not a cop.
Namespace
usingVRChatOSCLib;
Initializing
You can use any of these methods to initialize the class.
VRChatOSCvrcOsc=newVRChatOSC();// Doesn't connect, use .Connect() after
.... =newVRChatOSC(true);// Connect and use default remote port 9000
.... =newVRChatOSC(8901);// Connect and use custom remote port
.... =newVRChatOSC("192.168.1.X",9000);// Connect and Use custom IP from string and custom port
.... =newVRChatOSC(IPAddressipAddress,9000);// Connect and Use custom IP from IPAddress class// If no parameters are passed to the constructor, you will need to connect the client manually. You can do this using the .Connect() method.vrcOsc.Connect();// Uses default remote port 9000vrcOsc.Connect(8901);// Use custom remote portvrcOsc.Connect("192.168.1.X",9000);// Use custom IP from string and custom portvrcOsc.Connect(IPAddressipAddress,9000);// Use custom IP from IPAddress class
Examples
usingVRChatOSCLib;internalclassProgram{staticVRChatOSCosc=newVRChatOSC();staticasyncTaskMain(string[]args){// Connect. Port number is optionalosc.Connect(9000);// Asyncn't// Send to a specific addressosc.SendTo("/test/lib/float",0.5f);// Send to an avatar parameter// This will automatically send it to the proper pathosc.SendParameter("GlassesToggle",true);// Boolean sent as "/avatar/parameters/GlassesToggle"osc.SendParameter("GlassesColor",0.5f);// Float sent as "/avatar/parameters/GlassesColor"osc.SendParameter("UltimateAnswer",42);// Integer sent as "/avatar/parameters/UltimateAnswer"// Send supported inputs like buttons and Axes to VRChatosc.SendInput(VRCButton.Jump,true);// Jump sent as "/input/Jump/" 1osc.SendInput(VRCButton.Jump,false);// Jump sent as "/input/Jump/" 0osc.SendInput(VRCAxes.Vertical,0.42f);// Vertical Axes sent as "/input/Vertical/" 0.42f// Send Chatbox Messagesosc.SendChatbox("Hello World");// Sends the ASCII string to the Keyboardosc.SendChatbox("Hello World",true);// Bypass keyboard and sends string to Chatboxosc.SendChatbox(true);// Set typing indicator ONosc.SendChatbox(false);// Set typing indicator OFF// Async aka Awaitable methodsawaitosc.SendToAsync("/test/lib/async",true);awaitosc.SendParameterAsync("AsyncRocks",true);awaitosc.SendInputAsync(VRCButton.Run,true);awaitosc.SendChatboxAsync("Hello World",true);// Listen for incoming messagesosc.Listen();// Listen on default port 9001osc.Listen(9042);// Listen on custom portosc.Listen(9001,1024);// Use custom port and custom buffer length// Subscribe to incoming messagesosc.OnMessage+=OnMessageReceived;Console.ReadKey(true);// :P}staticvoidOnMessageReceived(object?source,VRCMessagemessage){// Full address from message, example "/avatar/parameters/CatToggle"stringaddress=message.Address;// Shortened path from the address, example "/avatar/parameters/"stringpath=message.Path;// True if this message is an avatar parameter of any kindboolisParameter=message.IsParameter;// Message type (Unknown|DefaultParameter|AvatarParameter|AvatarChange)VRCMessage.MessageTypemessageType=message.Type;// Retrieve the first value object contained in this messageobject?value=message.GetValue();// Can return defaultfloatval=message.GetValue<float>();// Alternative with generic typeval=message.GetValueAt<float>(0);// Get argument value by indexvalue=message[0];// Same with indexer// Print this message with fancy colors for debuggingmessage.Print();}}
There's probably many libraries out there for VRC, also give them a try. This was originally a personal project for personal use, but I decided to share it.