-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvatarNetworking.cs
More file actions
74 lines (55 loc) · 1.85 KB
/
Copy pathAvatarNetworking.cs
File metadata and controls
74 lines (55 loc) · 1.85 KB
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
using Il2CppExitGames.Client.Photon;
using Il2CppPhoton.Pun;
using Il2CppPhoton.Realtime;
namespace CustomAvatars;
public static class AvatarNetworking
{
public static void UpdateLocalParams()
{
if (!PhotonNetwork.InRoom) return;
var props = new Hashtable();
props[CAParams.Visibility.Key] = Main.instance.LetOthersSeeMyAvatar.Value;
props[CAParams.Version.Key] = BuildInfo.Version;
// Avatar param bitmask
int mask = 0;
var rig = Main.LocalPlayer.Controller.GetComponent<CustomRig>();
if (rig != null && rig.config != null)
{
var parameters = rig.config.parameters;
for (int i = 0; i < parameters.Count; i++)
{
var param = parameters[i];
if (!param.networked) continue;
// Will figure this out later
bool value = param.defaultToggle;
if (value)
mask |= (1 << i);
}
}
props[CAParams.Params.Key] = mask;
// ------------------------------------------------
PhotonNetwork.LocalPlayer.SetCustomProperties(props);
}
}
public static class CAParams
{
public static readonly Param<bool> Visibility = new("CA:visibility", false);
public static readonly Param<string> Version = new("CA:version", null);
public static readonly Param<int> Params = new("CA:params", 0);
}
public class Param<T>(string key, T def)
{
public string Key = key;
public T Default = def;
public T Get(Player player)
{
if (player?.CustomProperties.TryGetValue(Key, out var val) ?? false)
{
if (val is T t)
return t;
if (typeof(T) == typeof(string))
return (T)(object)val.ToString();
}
return Default;
}
}