This repository has been archived by the owner on Nov 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
DiscordLoader.cs
99 lines (86 loc) · 3.45 KB
/
DiscordLoader.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System.Threading;
using UnityEngine;
using VRC.Core;
using static VRC.Core.ApiWorldInstance;
namespace VRCTools
{
public abstract class DiscordLoader
{
private static DiscordRpc.RichPresence presence;
public static ApiWorld CurrentWorld { get; private set; }
public static void Init()
{
VRCToolsLogger.Info("[DRPC] Initialising...");
DiscordRpc.EventHandlers eh = new DiscordRpc.EventHandlers();
presence.state = "Not in a world";
presence.partySize = 0;
presence.partyMax = 0;
presence.details = "Not logged in" + " (" + (DeobfGetters.IsVRLaunched() ? "VR" : "Desktop") + ")";
presence.largeImageKey = "logo";
presence.partyId = "";
Thread t = new Thread(new ThreadStart(() => {
DiscordRpc.Initialize("404400696171954177", ref eh, true, null);
while (true)
{
Update();
Thread.Sleep(5000);
}
}));
t.Name = "Discord-RPC update thread";
t.IsBackground = true;
t.Start();
VRCToolsLogger.Info("[DRPC] Done !");
}
public static void Update()
{
ApiWorld world = RoomManager.currentRoom;
if (world != CurrentWorld)
{
CurrentWorld = world;
if (world != null)
{
if (world.currentInstanceAccess == AccessType.InviteOnly || world.currentInstanceAccess == AccessType.InvitePlus)
{
presence.state = "in a private world";
presence.partyId = "";
}
else
{
presence.state = "in " + world.name + " " + (
world.currentInstanceAccess == AccessType.FriendsOfGuests ? "[Friends+]" :
world.currentInstanceAccess == AccessType.FriendsOnly ? "[Friends]" :
world.currentInstanceAccess == AccessType.Public ? "" :
"[Unknown]"
);
presence.partyId = world.currentInstanceIdOnly;
VRCToolsLogger.Info("WorldInstanceId: " + world.currentInstanceIdOnly);
}
}
else
{
presence.state = "Not in a world";
presence.partyId = "";
}
if (APIUser.CurrentUser != null)
{
presence.details = "as " + APIUser.CurrentUser.displayName + " (" + (DeobfGetters.IsVRLaunched() ? "VR" : "Desktop") + ")";
}
else
{
presence.details = "Not logged in" + " (" + (DeobfGetters.IsVRLaunched() ? "VR" : "Desktop") + ")";
}
}
if(world != null && world.currentInstanceAccess != AccessType.InviteOnly && world.currentInstanceAccess != AccessType.InvitePlus)
{
presence.partySize = VRC.PlayerManager.GetAllPlayers().Length;
presence.partyMax = world.capacity;
}
else
{
presence.partySize = 0;
presence.partyMax = 0;
}
DiscordRpc.UpdatePresence(ref presence);
}
}
}