-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
83 lines (64 loc) · 2.81 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using BuildSoft.VRChat.Osc;
using Libraries;
using static Libraries.WebAPIHelper;
using System.Net;
using BuildSoft.VRChat.Osc.Avatar;
using Newtonsoft.Json;
namespace Kanna_Protecc_OSC
{
internal class Program
{
private static WebAPIHelper Helper;
static async Task Main(string[] args)
{
OscUtility.Initialize();
OscParameter.ValueChanged += OscParameterOnValueChanged;
Helper = new WebAPIHelper(HandleData, "protecc", 3456);
Console.WriteLine("Kanna Protecc OSC Helper is now ready. You can now select write keys in Unity within Kanna Protecc and this will save the keys, and apply them back automatically whenever you reset avatar.");
await Task.Delay(Timeout.Infinite);
}
public class KannaProteccKeysData
{
public string AvatarID = "Invalid";
public Dictionary<string, object> Values = new Dictionary<string, object>();
}
public class Configuration
{
public List<KannaProteccKeysData> ProtecctedAvatarsData = new List<KannaProteccKeysData>();
}
private static ConfigLib<Configuration> Config = new ConfigLib<Configuration>(Environment.CurrentDirectory + "\\Config.json");
private static async void HandleData(string Data, RequestType requestType, HttpListenerContext context)
{
if (requestType == RequestType.POST)
{
Helper.SendResponse(context, "OK", HttpStatusCode.OK);
var KannaData = JsonConvert.DeserializeObject<KannaProteccKeysData>(Data);
if (KannaData == null)
{
return;
}
var index = Config.InternalConfig.ProtecctedAvatarsData.FindIndex(o => o.AvatarID == KannaData.AvatarID);
if (index == -1)
{
Config.InternalConfig.ProtecctedAvatarsData.Add(KannaData);
}
else
{
Config.InternalConfig.ProtecctedAvatarsData[index] = KannaData;
}
Console.WriteLine($"Received And Saved OSC Settings For {KannaData.AvatarID}");
}
}
private static void OscParameterOnValueChanged(IReadOnlyOscParameterCollection sender, ParameterChangedEventArgs e)
{
if (e.ValueSource != ValueSource.VRChat) return;
var paramname = e.Address.Replace("/avatar/parameters/", "");
if (paramname == "TrackingType" && e.NewValue is 2)
{
foreach (var AvatarData in Config.InternalConfig.ProtecctedAvatarsData)
foreach (var Parse in AvatarData.Values)
OscParameter.SendAvatarParameter(Parse.Key, Parse.Value);
}
}
}
}