This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXDCMod.cs
241 lines (191 loc) · 7.17 KB
/
XDCMod.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
using MelonLoader;
using UnityEngine;
using XDClient.Feature;
namespace XDClient
{
// ReSharper disable once InconsistentNaming
public class XDCMod : MelonMod
{
private static bool _showMenu;
private static bool _espEnabled;
private static GUIStyle? _mainBoxStyle;
private static GUIStyle? _labelStyle;
private static GUIStyle? _headerStyle;
private static GUIStyle? _toggleStyle;
private static GUIStyle? _buttonStyle;
private static GUIStyle? _tabButtonStyle;
private static GUIStyle? _activeTabStyle;
private readonly PointsEditor _pointsEditor = new();
private readonly EspOverlay _espOverlay = new();
private readonly HarmonyLib.Harmony _harmony = new("XDClient");
private enum Tab
{
Main,
PointEditor
}
private Tab _currentTab = Tab.Main;
private Rect _windowPosition = new Rect(10, 10, 400, 300);
private bool _isDragging;
public override void OnInitializeMelon()
{
_harmony.PatchAll();
LoggerInstance.Msg("[XDClient] Started");
}
public override void OnUpdate()
{
if (Input.GetKeyDown(KeyCode.F5))
{
_showMenu = !_showMenu;
}
}
public override void OnGUI()
{
if (_espEnabled)
{
_espOverlay.Render();
}
RenderMenu();
}
private static Texture2D MakeTex(int width, int height, Color col)
{
Color[] pix = new Color[width * height];
for (int i = 0; i < pix.Length; ++i) pix[i] = col;
Texture2D result = new Texture2D(width, height);
result.SetPixels(pix);
result.Apply();
return result;
}
private void RenderMenu()
{
if (!_showMenu) return;
if (_mainBoxStyle == null)
{
_mainBoxStyle = new GUIStyle(GUI.skin.box);
_mainBoxStyle.normal.background = MakeTex(2, 2, new Color(0f, 0f, 0f, 0.8f));
}
if (_labelStyle == null)
{
_labelStyle = new GUIStyle(GUI.skin.label);
_labelStyle.fontSize = 16;
_labelStyle.normal.textColor = Color.white;
}
if (_buttonStyle == null)
{
_buttonStyle = new GUIStyle(GUI.skin.button);
_buttonStyle.fontSize = 16;
}
if (_toggleStyle == null)
{
_toggleStyle = new GUIStyle(GUI.skin.toggle);
_toggleStyle.onNormal.textColor = Color.white;
_toggleStyle.fontSize = 16;
}
if (_tabButtonStyle == null)
{
_tabButtonStyle = new GUIStyle(GUI.skin.button);
_tabButtonStyle.fontSize = 14;
_tabButtonStyle.fixedWidth = 120;
_tabButtonStyle.fixedHeight = 35;
}
if (_activeTabStyle == null)
{
_activeTabStyle = new GUIStyle(_tabButtonStyle);
_activeTabStyle.normal.textColor = Color.white;
}
GUI.BeginGroup(_windowPosition, "", _mainBoxStyle);
DrawHud();
HandleDrag(new Rect(0, 0, _windowPosition.width, 30));
GUILayout.BeginArea(new Rect(10, 40, _windowPosition.width - 20, 40));
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Main", _currentTab == Tab.Main ? _activeTabStyle : _tabButtonStyle))
{
_currentTab = Tab.Main;
}
GUILayout.Space(10);
if (GUILayout.Button("PointEditor", _currentTab == Tab.PointEditor ? _activeTabStyle : _tabButtonStyle))
{
_currentTab = Tab.PointEditor;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndArea();
switch (_currentTab)
{
case Tab.Main:
DrawMainTab(new Rect(10, 90, _windowPosition.width - 20, _windowPosition.height - 100));
break;
case Tab.PointEditor:
DrawPointEditorTab(new Rect(10, 90, _windowPosition.width - 20, _windowPosition.height - 100));
break;
}
GUI.EndGroup();
}
private void DrawHud()
{
if (_headerStyle == null)
{
_headerStyle = new GUIStyle(GUI.skin.box);
_headerStyle.normal.background = MakeTex(2, 2, Color.black);
_headerStyle.normal.textColor = Color.white;
_headerStyle.fontSize = 16;
_headerStyle.alignment = TextAnchor.MiddleCenter;
}
GUI.Box(new Rect(0, 0, _windowPosition.width, 30), $"XDClient | by Petrosan", _headerStyle);
}
private void HandleDrag(Rect headerRect)
{
Event e = Event.current;
Vector2 mousePosition = e.mousePosition;
if (e.type == EventType.MouseDown && e.button == 0 && headerRect.Contains(mousePosition))
{
_isDragging = true;
e.Use();
}
if (e.type == EventType.MouseUp && e.button == 0)
{
_isDragging = false;
}
if (_isDragging && e.type == EventType.MouseDrag && e.button == 0)
{
_windowPosition.x += e.delta.x;
_windowPosition.y += e.delta.y;
_windowPosition.x = Mathf.Clamp(_windowPosition.x, 0, Screen.width - _windowPosition.width);
_windowPosition.y = Mathf.Clamp(_windowPosition.y, 0, Screen.height - _windowPosition.height);
e.Use();
}
}
private void DrawMainTab(Rect contentRect)
{
GUILayout.BeginArea(contentRect);
GUILayout.BeginVertical();
_espEnabled = GUILayout.Toggle(_espEnabled, " ESP", _toggleStyle);
GUILayout.EndVertical();
GUILayout.EndArea();
}
private void DrawPointEditorTab(Rect contentRect)
{
GUILayout.BeginArea(contentRect);
GUILayout.BeginVertical();
if (GUILayout.Button(" +500", _buttonStyle))
{
_pointsEditor.AddPoints(1000);
}
if (GUILayout.Button(" +1000", _buttonStyle))
{
_pointsEditor.AddPoints(1000);
}
GUILayout.Space(10);
if (GUILayout.Button(" -500", _buttonStyle))
{
_pointsEditor.RemovePoints(500);
}
if (GUILayout.Button(" -1000", _buttonStyle))
{
_pointsEditor.RemovePoints(1000);
}
GUILayout.EndVertical();
GUILayout.EndArea();
}
}
}