This repository was archived by the owner on Feb 21, 2025. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathPlugin.cs
More file actions
292 lines (202 loc) · 12.3 KB
/
Copy pathPlugin.cs
File metadata and controls
292 lines (202 loc) · 12.3 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
using System.Collections.Generic;
using System.Runtime.Serialization.Formatters;
using BepInEx;
using HarmonyLib;
using HumanAPI;
using UnityEngine;
namespace spsp
{
[BepInPlugin("com.kirisoup.hff.spsp", PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
[BepInProcess("Human.exe")]
public partial class Plugin : BaseUnityPlugin {
readonly Harmony harmony = new("com.kirisoup.hff.spsp");
public static bool isEnabled;
// public void Awake() => harmony.PatchAll();
// public void OnDestroy() => harmony.UnpatchSelf();
public void Start() {
Command.Register();
}
public void Update() {
if (!Input.GetKey(KeyCode.P)) return;
if (Input.GetKeyDown(KeyCode.L)) CreateSphereSample(Human.Localplayer.transform.position, type: AnchorType.localplayer);
if (Input.GetKeyDown(KeyCode.N)) CreateSphereSample(Human.Localplayer.transform.position);
if (Input.GetKeyDown(KeyCode.C)) ClearSphereSamples();
}
public void OnGUI() {
DrawSphereSamples();
}
static void DrawSphereSamples() {
if (SphereSamples.Count == 0) return;
List<Collider> objs = new();
List<Vector3> points = new();
foreach (var sample in SphereSamples) foreach (var hitgroup in sample.HitGroups) {
foreach (var hit in hitgroup.Key) {
Vector2 pos = Camera.main.WorldToScreenPoint(hit.Pos);
Rect rect = new(pos.x, - pos.y + Screen.height, 100, 100);
Color color = hitgroup.Value switch {
ColType.standard => Color.white,
ColType.rigidbody => Color.cyan,
ColType.invisible => Color.blue,
ColType.trigger => Color.magenta,
ColType.checkpoint => new(1, 0.66f, 0),
ColType.passtrigger => Color.green,
ColType.falltrigger => Color.red,
_ => Color.white,
};
GUIStyle style = new();
style.normal.textColor = color;
GUI.Label(rect, "+", style);
}
}
}
public static List<SphereSample> SphereSamples = new();
public static void CreateSphereSample(Vector3 origin, float? radius = null, int? count = null, AnchorType type = AnchorType.stationary) {
var sample = new SphereSample() { Origin = origin, Type = type };
if (radius is not null) sample.Radius = (float)radius;
if (count is not null) sample.Count = (int)count;
SphereSamples.Add(sample);
}
public static void ClearSphereSamples() => SphereSamples = new();
public class SphereSample {
Vector3 origin;
Vector3[] ends;
EspHit[] hits;
EspLine[] lines;
Dictionary<EspHit[], ColType> hitGroups;
public float Radius { get; set; } = 7.5f;
public int Count { get; set; } = 8;
public bool SampleInvisible { get; set; } = true;
public bool SampleRigid { get; set; } = true;
public bool SampleMiscColli { get; set; } = true;
public bool SampleCP { get; set; } = true;
public bool SamplePTrig { get; set; } = true;
public bool SampleFTrig { get; set; } = true;
public bool SampleMiscTrig { get; set; } = true;
public AnchorType Type { get; set; } = AnchorType.localplayer;
Vector3 PlayerPos { get => Human.Localplayer.transform.position + Vector3.up; }
Vector3 syncOrigin = new();
bool shouldSync { get => Origin == syncOrigin; }
public Vector3 Origin {
get => Type switch {
AnchorType.stationary => origin,
AnchorType.localplayer => origin = (Vector3.Distance(PlayerPos, syncOrigin) < 1) ? PlayerPos : syncOrigin = PlayerPos,
_ => new(),
};
set => origin = value;
}
Vector3[] Ends {
// get => Type switch {
// AnchorType.stationary => ends ??= GenEnds(),
// AnchorType.localplayer => ends = shouldSync ? GenEnds() : ends ?? GenEnds(),
// _ => new Vector3[0],
// };
get => Type switch {
AnchorType.stationary => ends ??= GenEnds(),
AnchorType.localplayer => ends = GenEnds(),
_ => new Vector3[0],
};
}
EspHit[] Hits {
// get => Type switch {
// AnchorType.stationary => hits ??= GenHits(),
// AnchorType.localplayer => hits = shouldSync ? GenHits() : hits ?? GenHits(),
// _ => new EspHit[0],
// };
get => Type switch {
AnchorType.stationary => hits ??= GenHits(),
AnchorType.localplayer => hits = GenHits(),
_ => new EspHit[0],
};
}
public Dictionary<EspHit[], ColType> HitGroups {
get => Type switch {
AnchorType.stationary => hitGroups ??= GroupHits(),
AnchorType.localplayer => hitGroups = shouldSync ? GroupHits() : hitGroups ?? GroupHits(),
_ => new(),
};
}
Vector3[] GenEnds() {
List<Vector3> points = new();
for (int i = 0; i < Count; i++) {
Vector3 p = DistriPointOnSphere(Origin, Radius, i, Count);
points.Add(p);
}
return points.ToArray();
}
EspHit[] GenHits() {
List<EspHit> hitlist = new();
foreach (var end in Ends) {
foreach (var hit in Physics.RaycastAll(Origin, end - Origin, Radius)) {
if (hit.collider.transform.IsChildOf(Human.Localplayer.transform)) continue;
if (Camera.main.WorldToScreenPoint(hit.point).z < 0) continue;
hitlist.Add(new EspHit() { Pos = hit.point, Obj = hit.collider.gameObject });
}
}
return hitlist.ToArray();
}
Dictionary<EspHit[], ColType> GroupHits() {
Dictionary<GameObject,List<EspHit>> dict = new();
Dictionary<EspHit[], ColType> groups = new();
foreach (var hit in Hits) {
if (dict.ContainsKey(hit.Obj)) dict[hit.Obj].Add(hit);
else dict.Add(hit.Obj, new() { hit });
}
foreach (var item in dict) {
ColType type;
if (!item.Key.GetComponent<Collider>().isTrigger) {
if (item.Key.gameObject.GetComponent<Rigidbody>() is not null) type = ColType.rigidbody;
else if (item.Key.gameObject.GetComponent<Renderer>() is not null) type = ColType.standard;
else type = ColType.invisible;
} else {
if (item.Key.gameObject.GetComponent<Checkpoint>() is not null) type = ColType.checkpoint;
else if (item.Key.gameObject.GetComponent<LevelPassTrigger>() is not null) type = ColType.passtrigger;
else if (item.Key.gameObject.GetComponent<FallTrigger>() is not null) type = ColType.falltrigger;
else type = ColType.trigger;
}
if (type!=ColType.standard) continue;
// NOTE: plcc said this approach might cause issue :|
// else color = hit.collider.gameObject.GetComponent<MonoBehaviour>() switch {
// Checkpoint => new Color(1, 0.66f, 0),
// LevelPassTrigger => Color.green,
// FallTrigger => Color.red,
// _ => Color.magenta,
// };
groups.Add(item.Value.ToArray(), type);
}
return groups;
}
static Vector3 DistriPointOnSphere(Vector3 o, float r, int i, int n) {
float epsilon = 3.33f;
float goldenRatio = (1 + Mathf.Sqrt(5)) / 2;
float phi = Mathf.Acos(1 - 2 * (i + epsilon) / (n - 1 + 2 * epsilon));
float theta = 2 * Mathf.PI * i / goldenRatio;
float x = r * Mathf.Cos(theta) * Mathf.Sin(phi);
float y = r * Mathf.Sin(theta) * Mathf.Sin(phi);
float z = r * Mathf.Cos(phi);
return new Vector3(x, y, z) + o;
}
}
public struct EspHit {
public Vector3 Pos;
public GameObject Obj;
}
public struct EspLine {
Vector3 p1;
Vector3 p2;
ColType color;
}
public enum AnchorType {
stationary,
localplayer,
}
public enum ColType {
standard,
rigidbody,
invisible,
trigger,
checkpoint,
passtrigger,
falltrigger,
}
}
}