This repository has been archived by the owner on Jul 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NetworkManagerHooks.cs
57 lines (46 loc) · 1.64 KB
/
NetworkManagerHooks.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
using System;
using VRC;
using VRC.Core;
namespace OGTrustRanks
{
internal static class NetworkManagerHooks
{
private static bool _isInitialized;
private static bool _seenFire;
private static bool _aFiredFirst;
public static event Action<Player> OnJoin;
public static event Action<Player> OnLeave;
public static void EventHandlerA(Player player)
{
if (!_seenFire)
{
_aFiredFirst = true;
_seenFire = true;
}
(_aFiredFirst ? OnJoin : OnLeave)?.Invoke(player);
}
public static void EventHandlerB(Player player)
{
if (!_seenFire)
{
_aFiredFirst = false;
_seenFire = true;
}
(_aFiredFirst ? OnLeave : OnJoin)?.Invoke(player);
}
public static void Initialize()
{
if (_isInitialized) return;
if (ReferenceEquals(NetworkManager.field_Internal_Static_NetworkManager_0, null)) return;
var field0 = NetworkManager.field_Internal_Static_NetworkManager_0.field_Internal_VRCEventDelegate_1_Player_0;
var field1 = NetworkManager.field_Internal_Static_NetworkManager_0.field_Internal_VRCEventDelegate_1_Player_1;
AddDelegate(field0, EventHandlerA);
AddDelegate(field1, EventHandlerB);
_isInitialized = true;
}
private static void AddDelegate(VRCEventDelegate<Player> field, Action<Player> eventHandlerA)
{
field.field_Private_HashSet_1_UnityAction_1_T_0.Add(eventHandlerA);
}
}
}