-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvoidanceVis.cs
More file actions
179 lines (129 loc) · 5.83 KB
/
AvoidanceVis.cs
File metadata and controls
179 lines (129 loc) · 5.83 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
using Clio.Utilities;
using ff14bot.AClasses;
using ff14bot.Managers;
using ff14bot.Overlay3D;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Reflection;
namespace FoxDen.Plugin.AvoidShit
{
class AvoidanceVis : BotPlugin
{
internal static PropertyInfo HeightFieldProperty;
internal static Type CompactHeightFieldType;
internal static PropertyInfo SpansProp;
internal static PropertyInfo CellProp;
internal static PropertyInfo CellSize;
internal static PropertyInfo CellHeight;
internal static PropertyInfo NumCellsZ;
internal static PropertyInfo NumCellsX;
internal static PropertyInfo Bounds;
internal static Type CellType;
internal static Type SpansType;
internal static MethodInfo GetCell;
//cell types
internal static PropertyInfo CellIndexProp;
internal static PropertyInfo CellCountProp;
//spans Type
internal static PropertyInfo SpansAreaProp;
internal static FieldInfo SpansBottomField;
public override string Author => "Fox Den";
public override string Name => "Avoidance Visualization";
public override Version Version => new Version(1,0,0,0);
static AvoidanceVis()
{
HeightFieldProperty = typeof(AvoidanceManager).GetProperty("Heightfield", BindingFlags.Static | BindingFlags.NonPublic);
CompactHeightFieldType = HeightFieldProperty.PropertyType;
SpansProp = CompactHeightFieldType.GetProperty("Spans");
CellProp = CompactHeightFieldType.GetProperty("Cells");
CellSize = CompactHeightFieldType.GetProperty("CellSize");
CellHeight = CompactHeightFieldType.GetProperty("CellHeight");
NumCellsZ = CompactHeightFieldType.GetProperty("NumCellsZ");
NumCellsX = CompactHeightFieldType.GetProperty("NumCellsX");
Bounds = CompactHeightFieldType.GetProperty("Bounds");
CellType = CellProp.PropertyType.GetElementType();
SpansType = SpansProp.PropertyType.GetElementType();
GetCell = CompactHeightFieldType.GetMethods()
.First(i => i.ReturnType == CellType && i.GetParameters().Length == 2);
CellIndexProp = CellType.GetProperty("Index");
CellCountProp = CellType.GetProperty("Count");
SpansAreaProp = SpansType.GetProperty("Area");
SpansBottomField = SpansType.GetFields().First(i => i.FieldType == typeof(ushort));
}
public override void OnEnabled()
{
Overlay3D.Drawing += Draw;
}
public override void OnDisabled()
{
Overlay3D.Drawing -= Draw;
}
void Draw(object sender, DrawingEventArgs e)
{
if (HeightFieldProperty.GetValue(null) == null)
return;
var dd = e.Drawer;
var heightField = HeightFieldProperty.GetValue(null);
float cs = (float)CellSize.GetValue(heightField);
float ch = (float)CellHeight.GetValue(heightField);
Array Spans = (Array)SpansProp.GetValue(heightField);
BoundingBox3 bounds = (BoundingBox3)Bounds.GetValue(heightField);
//var cpl = Core.Player.Location;
var td = new Dictionary<Color, List<Vector3>>();
for (int y = 0; y < (int)NumCellsZ.GetValue(heightField); ++y)
{
for (int x = 0; x < (int)NumCellsX.GetValue(heightField); ++x)
{
float fx = bounds.Min.X + x * cs;
float fz = bounds.Min.Z + y * cs;
var c = GetCell.Invoke(heightField, new object[] { x, y }); // chf.GetCell(x, y);
uint Index = (uint)CellIndexProp.GetValue(c);
uint Count = (uint)CellCountProp.GetValue(c);
for (uint i = Index, ni = Index + Count; i < ni; ++i)
{
var s = Spans.GetValue(i);
var area = (byte)SpansAreaProp.GetValue(s);
ushort bottom = (ushort)SpansBottomField.GetValue(s);
Color color;
if (area == 1)
color = Color.FromArgb(128, 128, 255, 64);
else if (area == 0)
color = Color.FromArgb(128, 0, 0, 64);
else
color = duIntToCol(area, 64);
float fy = bounds.Min.Y + (bottom + 1) * ch;
if (!td.TryGetValue(color, out var tl))
{
tl = new List<Vector3>();
td[color] = tl;
}
tl.AddRange(new[]
{
new Vector3(fx, fy, fz),
new Vector3(fx, fy, fz + cs),
new Vector3(fx + cs, fy, fz + cs),
new Vector3(fx + cs, fy, fz + cs),
new Vector3(fx + cs, fy, fz),
new Vector3(fx, fy, fz)
});
}
}
}
foreach(var k in td)
dd.DrawTriangles(k.Value.ToArray(), k.Key);
}
static int bit(int a, int b)
{
return (a & (1 << b)) >> b;
}
private static Color duIntToCol(byte i, int a)
{
var r = bit(i, 1) + bit(i, 3) * 2 + 1;
var g = bit(i, 2) + bit(i, 4) * 2 + 1;
var b = bit(i, 0) + bit(i, 5) * 2 + 1;
return Color.FromArgb(r * 63, g * 63, b * 63, a);
}
}
}