This repository was archived by the owner on Jan 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathHighlightsComponent.cs
More file actions
143 lines (118 loc) · 5.13 KB
/
Copy pathHighlightsComponent.cs
File metadata and controls
143 lines (118 loc) · 5.13 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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using ReMod.Core;
using ReMod.Core.Managers;
using ReMod.Core.UI.QuickMenu;
using ReMod.Core.UI.Wings;
using ReMod.Core.Unity;
using ReMod.Core.VRChat;
using ReModCE.Managers;
using UnityEngine;
using UnityEngine.UI;
using VRC;
using VRC.Core;
namespace ReModCE.Components
{
internal class HighlightsComponent : ModComponent
{
private HighlightsFXStandalone _friendsHighlights;
private HighlightsFXStandalone _othersHighlights;
private ConfigValue<Color> FriendsColor;
private ConfigValue<Color> OthersColor;
private ConfigValue<bool> ESPEnabled;
private ConfigValue<KeyCode> ESPHotkey;
private ReMirroredWingToggle _espMirroredToggle;
private ReMenuToggle _espToggle;
private ReMenuButton _friendsColorButton;
private ReMenuButton _othersColorButton;
public HighlightsComponent()
{
FriendsColor = new ConfigValue<Color>(nameof(FriendsColor), Color.yellow);
OthersColor = new ConfigValue<Color>(nameof(OthersColor), Color.magenta);
ESPEnabled = new ConfigValue<bool>(nameof(ESPEnabled), false);
ESPEnabled.OnValueChanged += () => _espToggle.Toggle(ESPEnabled);
ESPHotkey = new ConfigValue<KeyCode>(nameof(ESPHotkey), KeyCode.E);
RiskyFunctionsManager.Instance.OnRiskyFunctionsChanged += allowed =>
{
if (_espToggle != null)
{
_espToggle.Interactable = allowed;
}
if(_espMirroredToggle != null)
{
_espMirroredToggle.Interactable = allowed;
}
if (!allowed)
ESPEnabled.SetValue(false);
};
}
public override void OnUiManagerInitEarly()
{
var highlightsFx = HighlightsFX.field_Private_Static_HighlightsFX_0;
_friendsHighlights = highlightsFx.gameObject.AddComponent<HighlightsFXStandalone>();
_friendsHighlights.highlightColor = FriendsColor;
_othersHighlights = highlightsFx.gameObject.AddComponent<HighlightsFXStandalone>();
_othersHighlights.highlightColor = OthersColor;
}
public override void OnUiManagerInit(UiManager uiManager)
{
var menu = uiManager.MainMenu.GetCategoryPage("Visuals").GetCategory("ESP/Highlights");
_espToggle = menu.AddToggle("ESP/Highlights", "Enable ESP (Highlight players through walls)", b =>
{
ESPEnabled.SetValue(b);
ToggleESP(b);
}, ESPEnabled);
_espMirroredToggle = ReModCE.WingMenu.AddToggle("ESP", "Enable/Disable ESP", ESPEnabled.SetValue, ESPEnabled);
_friendsColorButton = menu.AddButton($"<color=#{FriendsColor.Value.ToHex()}>Friends</color> Color",
$"Set your <color=#{FriendsColor.Value.ToHex()}>friends</color> highlight color",
() =>
{
VRCUiPopupManager.prop_VRCUiPopupManager_0.ShowColorInputPopup(_friendsColorButton, "Friends", FriendsColor);
}, ResourceManager.GetSprite("remodce.palette"));
_othersColorButton = menu.AddButton($"<color=#{OthersColor.Value.ToHex()}>Others</color> Color",
$"Set <color=#{OthersColor.Value.ToHex()}>other</color> peoples highlight color",
() =>
{
VRCUiPopupManager.prop_VRCUiPopupManager_0.ShowColorInputPopup(_othersColorButton, "Others", OthersColor);
}, ResourceManager.GetSprite("remodce.palette"));
}
private void ToggleESP(bool enabled)
{
var playerManager = PlayerManager.field_Private_Static_PlayerManager_0;
if (playerManager == null)
return;
foreach (var player in playerManager.GetPlayers())
{
HighlightPlayer(player, enabled);
}
}
private void HighlightPlayer(Player player, bool highlighted)
{
if (!RiskyFunctionsManager.Instance.RiskyFunctionAllowed)
return;
if (player.field_Private_APIUser_0.IsSelf)
return;
var selectRegion = player.transform.Find("SelectRegion");
if (selectRegion == null)
return;
GetHighlightsFX(player.field_Private_APIUser_0).Method_Public_Void_Renderer_Boolean_0(selectRegion.GetComponent<Renderer>(), highlighted);
}
public override void OnUpdate()
{
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(ESPHotkey))
{
ESPEnabled.SetValue(!ESPEnabled);
}
}
public override void OnPlayerJoined(Player player)
{
if (!ESPEnabled)
return;
HighlightPlayer(player, ESPEnabled);
}
private HighlightsFXStandalone GetHighlightsFX(APIUser apiUser)
{
if (APIUser.IsFriendsWith(apiUser.id))
return _friendsHighlights;
return _othersHighlights;
}
}
}