-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuroraGSIPlugin.cs
52 lines (43 loc) · 2.29 KB
/
AuroraGSIPlugin.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
using Newtonsoft.Json;
using OsuRTDataProvider;
using Sync.Plugins;
using System;
using System.Linq;
using System.Net.Http;
namespace OsuAuroraMod {
[SyncRequirePlugin(typeof(OsuRTDataProviderPlugin))]
public class AuroraGSIPlugin : Plugin {
// Meta-data
public const string PLUGIN_NAME = "AuroraGSI";
public const string PLUGIN_AUTHOR = "Wibble199";
public const string VERSION = "1.0.0";
// HTTP/GSI variables
private HttpClient client = new HttpClient();
private RootGSINode gsiNode = new RootGSINode();
// Required constructor
public AuroraGSIPlugin() : base(PLUGIN_NAME, PLUGIN_AUTHOR) { }
public override void OnEnable() {
try {
// Get a reference to the OsuRTDataProviderPlugin and it's ListenerManager
var dp = (OsuRTDataProviderPlugin)getHoster().EnumPluings().First(plugin => plugin.Name == "OsuRTDataProvider");
var lm = dp.ListenerManager;
// Add events and update the payload
lm.OnStatusChanged += (_, status) => { gsiNode.game.status = status.ToString(); SendUpdate(); };
lm.OnAccuracyChanged += acc => { gsiNode.game.accuracy = acc; SendUpdate(); };
lm.OnHealthPointChanged += hp => { gsiNode.game.hp = hp; SendUpdate(); };
lm.OnComboChanged += combo => { gsiNode.game.combo = combo; SendUpdate(); };
lm.OnCount50Changed += count => { gsiNode.game.count50 = count; SendUpdate(); };
lm.OnCount100Changed += count => { gsiNode.game.count100 = count; SendUpdate(); };
lm.OnCount300Changed += count => { gsiNode.game.count300 = count; SendUpdate(); };
lm.OnCountKatuChanged += count => { gsiNode.game.countKatu = count; SendUpdate(); };
lm.OnCountGekiChanged += count => { gsiNode.game.countGeki = count; SendUpdate(); };
lm.OnCountMissChanged += count => { gsiNode.game.countMiss = count; SendUpdate(); };
} catch { }
}
// Serialize and send the updates to Aurora
private void SendUpdate() {
string json = JsonConvert.SerializeObject(gsiNode);
client.PostAsync("http://localhost:9088/", new StringContent(json));
}
}
}