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 1
/
AstralESP.cs
168 lines (136 loc) · 5.07 KB
/
AstralESP.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MelonLoader;
using UnityEngine;
using UnityEngine.SceneManagement;
using VRC.SDKBase;
[assembly: MelonInfo(typeof(Astrum.AstralESP), "AstralESP", "0.4.0", downloadLink: "github.com/Astrum-Project/AstralESP")]
[assembly: MelonGame("VRChat", "VRChat")]
[assembly: MelonColor(ConsoleColor.DarkMagenta)]
[assembly: MelonOptionalDependencies("AstralTags")]
namespace Astrum
{
public partial class AstralESP : MelonMod
{
private List<GameObject> pickups = new List<GameObject>();
private readonly GUIStyle style = new GUIStyle()
{
fontSize = 20,
alignment = TextAnchor.MiddleCenter,
richText = true,
normal = new GUIStyleState
{
textColor = Color.white,
}
};
public override void OnApplicationStart()
{
Outlines.Initialize(HarmonyInstance);
if (AppDomain.CurrentDomain.GetAssemblies().Any(x => x.GetName().Name == "AstralTags"))
Extern.SetupTags();
Config.Initialize();
}
public override void OnSceneWasLoaded(int index, string name)
{
if (index != -1) return;
MelonCoroutines.Start(FindPickups(name));
}
public override void OnSceneWasUnloaded(int index, string _)
{
if (index != -1) return;
pickups.Clear();
OnGUIAction -= DrawPickups;
}
public System.Collections.IEnumerator FindPickups(string name)
{
Scene scene = SceneManager.GetSceneByName(name);
while (Networking.LocalPlayer is null) yield return null;
pickups = UnityEngine.Object.FindObjectsOfType<VRC_Pickup>().Select(f => f.gameObject).ToList();
OnGUIAction += DrawPickups;
}
public override void OnGUI() => OnGUIAction();
private Action OnGUIAction = new Action(() => { });
private void DrawPickups()
{
if (!Config.pickupsEnabled.Value) return;
if (Networking.LocalPlayer is null) return;
foreach (GameObject pickup in pickups)
{
if (pickup is null)
{
pickups.Remove(pickup);
continue;
}
Vector3 p = Camera.main.WorldToScreenPoint(pickup.transform.position);
if (p.z < 0 || p.z > Config.pickupsMaxDistance.Value) continue;
StringBuilder builder = new StringBuilder();
if (Config.pickupsOwner.Value)
{
builder.Append(Networking.GetOwner(pickup).displayName);
builder.Append(" | ");
}
builder.Append(pickup.name);
if (Config.pickupsDistance.Value)
{
builder.Append(" | ");
builder.Append(p.z.ToString("0.00"));
}
GUI.Label(new Rect(p.x, Screen.height - p.y, 0, 0), builder.ToString(), style);
}
}
internal class Extern
{
public static void SetupTags()
{
MelonCoroutines.Start(RefreshTag(
new AstralTags.Tag(_player =>
{
VRC.Player player = (VRC.Player)_player.Inner;
return new AstralTags.TagData()
{
enabled = true,
text = FPS(player._playerNet.field_Private_Byte_0) + " | " + Ping(player._playerNet.field_Private_Int16_0),
textColor = Color.white,
background = Color.black,
};
}, 1000000)
));
}
private static string FPS(byte f)
{
if (f == 0) return "\u221E";
int fps = 1000 / f;
return (fps >= 60
? "<color=#0f0>"
: fps >= 45
? "<color=#008000>"
: fps >= 30
? "<color=#ffff00>"
: fps >= 15
? "<color=#ffa500>"
: "<color=#ff0000>")
+ fps + "</color>";
}
public static string Ping(int ping) =>
(ping <= 75
? "<color=#00ff00>"
: ping <= 125
? "<color=#008000>"
: ping <= 175
? "<color=#ffff00>"
: ping <= 225
? "<color=#ffa500>"
: "<color=#ff0000>") + ping + "</color>ms";
private static System.Collections.IEnumerator RefreshTag(AstralTags.Tag tag)
{
for (;;)
{
tag.CalculateAll();
yield return new WaitForSeconds(0.1f);
}
}
}
}
}