forked from vrcx-team/VRCX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVRChatRPC.cs
63 lines (54 loc) · 1.73 KB
/
VRChatRPC.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
// Copyright(c) 2019-2022 pypy, Natsumi and individual contributors.
// All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace VRCX
{
public class VRChatRPC
{
public static readonly VRChatRPC Instance;
[DllImport("VRChatRPC", CallingConvention = CallingConvention.Cdecl)]
private static extern bool VRChatRPC_000();
[DllImport("VRChatRPC", CallingConvention = CallingConvention.Cdecl)]
private static extern int VRChatRPC_001([Out] byte[] data, int size);
[DllImport("VRChatRPC", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr VRChatRPC_002();
static VRChatRPC()
{
Instance = new VRChatRPC();
}
public bool Update()
{
return VRChatRPC_000();
}
public string GetAuthSessionTicket()
{
var a = new byte[1024];
var n = VRChatRPC_001(a, 1024);
return BitConverter.ToString(a, 0, n).Replace("-", string.Empty);
}
public string GetPersonaName()
{
var ptr = VRChatRPC_002();
if (ptr != IntPtr.Zero)
{
int n = 0;
while (Marshal.ReadByte(ptr, n) != 0)
{
++n;
}
if (n > 0)
{
var a = new byte[n];
Marshal.Copy(ptr, a, 0, a.Length);
return Encoding.UTF8.GetString(a);
}
}
return string.Empty;
}
}
}