-
Notifications
You must be signed in to change notification settings - Fork 4
/
HUD.cs
173 lines (132 loc) · 6.61 KB
/
HUD.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
169
170
171
172
173
using System;
using System.Collections.Generic;
using BrokeProtocol.Entities;
using BrokeProtocolClient.settings;
using BrokeProtocolClient.utils;
using HarmonyLib;
using UnityEngine;
namespace BrokeProtocolClient.modules.render
{
class HUD : Module
{
BooleanSetting clientLogo = new BooleanSetting("Client name", true);
BooleanSetting moduleList = new BooleanSetting("Active modules", true);
BooleanSetting fps = new BooleanSetting("FPS", true);
BooleanSetting rainbow = new BooleanSetting("Rainbow", true);
NumberSetting rainbowSpeed = new NumberSetting("Rainbow speed", 0.01, 1, 0.15, 0.01);
NumberSetting rainbowOffset = new NumberSetting("Rainbow offset", 0, 0.1, 0.05, 0.001);
NumberSetting size = new NumberSetting("Size", 10, 100, 16, 1);
NumberSetting offsetX = new NumberSetting("Offset X", 0, 500, 5, 1);
NumberSetting offsetY = new NumberSetting("Offset Y", 0, 2, 0.7, 0.05);
ColorSetting contentColor = new ColorSetting("Color", Color.cyan);
BooleanSetting weaponInfo = new BooleanSetting("Weapon info", true);
BooleanSetting weaponCooldownInfo = new BooleanSetting("Weapon cooldown", true);
NumberSetting weaponInfoHeight = new NumberSetting("Cooldown height", 0, 1, 0.98, 0.01);
ActionSetting notifTest;
InputSetting notifText = new InputSetting("Notification text", 512, "");
NumberSetting notifTime = new NumberSetting("Notification time", 0, 10, 1, 0.5);
int offset = 0;
float framesPerSecond = 0;
public static string ClientLogo = "DARLOGCHEAT BY VADRA";
public HUD() : base(Categories.Render, "HUD", "Displays useful info")
{
addSetting(clientLogo);
addSetting(moduleList);
addSetting(fps);
addSetting(rainbow);
addSetting(contentColor);
addSetting(rainbowSpeed);
addSetting(rainbowOffset);
addSetting(size);
addSetting(offsetX);
addSetting(offsetY);
addSetting(new InfoSetting("Weapon info"));
addSetting(weaponInfo);
addSetting(weaponCooldownInfo);
addSetting(weaponInfoHeight);
notifTest = new ActionSetting("Notification test", Notify);
addSetting(notifTest);
addSetting(notifText);
addSetting(notifTime);
}
public override void onRender()
{
offset = 0;
int originalSize = Render.StringStyle.fontSize;
Render.StringStyle.fontSize = size.getValueInt();
if (clientLogo.isEnabled())
renderLogo();
if (fps.isEnabled())
renderFPS();
if (moduleList.isEnabled())
renderActiveModules();
if (weaponInfo.isEnabled())
renderWeaponInfo();
Render.StringStyle.fontSize = originalSize;
}
public override void onUpdate()
{
framesPerSecond = 1.0f / Time.deltaTime;
}
private Color getRainbow()
{
return Color.HSVToRGB(Mathf.PingPong(Time.time * rainbowSpeed.getValueFloat() + offset * rainbowOffset.getValueFloat(), 1), 1, 1);
}
private void renderActiveModules()
{
List<Module> list = new List<Module>(Modules.instance.getActive());
// Sort list of modules by name width
list.Sort((a, b) => Render.StringStyle.CalcSize(new GUIContent(b.getName())).x.CompareTo(Render.StringStyle.CalcSize(new GUIContent(a.getName())).x));
foreach (Module module in list)
{
var color = rainbow.isEnabled() ? getRainbow() : contentColor.getColor();
var textSize = Render.StringStyle.CalcSize(new GUIContent(module.getName()));
var height = Mathf.CeilToInt(textSize.y * offsetY.getValueFloat());
Render.DrawString(new Vector2(Screen.width - textSize.x - offsetX.getValueFloat(), height * offset), module.getName(), color, false);
offset++;
}
}
private void renderLogo()
{
Render.StringStyle.fontStyle = FontStyle.BoldAndItalic;
var color = rainbow.isEnabled() ? getRainbow() : contentColor.getColor();
var textSize = Render.StringStyle.CalcSize(new GUIContent(ClientLogo));
var height = Mathf.CeilToInt(textSize.y * offsetY.getValueFloat());
Render.DrawString(new Vector2(Screen.width - textSize.x - offsetX.getValueFloat(), height * offset), ClientLogo, color, false);
Render.StringStyle.fontStyle = FontStyle.Normal;
offset++;
}
private void renderFPS()
{
var color = rainbow.isEnabled() ? getRainbow() : contentColor.getColor();
string FPS = framesPerSecond.ToString("0");
var textSize = Render.StringStyle.CalcSize(new GUIContent(FPS));
var height = Mathf.CeilToInt(textSize.y * offsetY.getValueFloat());
Render.DrawString(new Vector2(Screen.width - textSize.x - offsetX.getValueFloat(), height * offset), FPS, color, false);
offset++;
}
AccessTools.FieldRef<ShMountable, float> nextFireTimeRef = AccessTools.FieldRefAccess<ShMountable, float>("nextFire");
private void renderWeaponInfo()
{
var local = getClient().ClManager.myPlayer;
if (!local) return;
ShUsable weapon = local.curEquipable as ShUsable;
if (!weapon) return;
if (weaponCooldownInfo.isEnabled())
{
var holderSize = new Vector2(Screen.width * 0.2f, Screen.height * 0.005f);
var holderPos = new Vector2(Screen.width / 2 - holderSize.x / 2, Screen.height * weaponInfoHeight.getValueFloat());
var fireCooldown = nextFireTimeRef(weapon) - Time.time;
//Log($"fireCooldown: {fireCooldown}");
var useDelayFill = Mathf.Lerp(0, holderSize.x, fireCooldown / weapon.useDelay + fireCooldown);
var contentSize = new Vector2(useDelayFill, holderSize.y);
Render.DrawBox(holderPos, holderSize, Color.black, false);
Render.DrawBox(holderPos, contentSize, Color.cyan, false);
}
}
private void Notify()
{
InfoUtils.Notify(notifText.getValue(), notifTime.getValueFloat());
}
}
}