This repository was archived by the owner on Jun 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathradar.cpp
More file actions
379 lines (316 loc) · 14.3 KB
/
radar.cpp
File metadata and controls
379 lines (316 loc) · 14.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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#include "radar.h"
#include "globals.h"
#include "config.h"
#include "game_math.hpp"
#include "overlay/imgui/imgui.h"
#include <vector>
#include <cmath>
#define M_PI 3.1415926535
using namespace globals;
using namespace config;
// Helper function for converting vector2 to ImVec2
inline ImVec2 toImVec2(const vector2& vec) {
return ImVec2(static_cast<float>(vec.x), static_cast<float>(vec.y));
}
// Helper function to compute triangle points
std::vector<ImVec2> compute_triangle(const vector2& center, double size, double angle) {
std::vector<ImVec2> points;
// Define the vertices relative to the center
vector2 front = center + vector2(size * cos(angle), size * sin(angle)); // Front vertex
vector2 left = center + vector2(size * cos(angle + M_PI * 0.75), size * sin(angle + M_PI * 0.75)); // Left vertex
vector2 right = center + vector2(size * cos(angle - M_PI * 0.75), size * sin(angle - M_PI * 0.75)); // Right vertex
points.push_back(toImVec2(front));
points.push_back(toImVec2(left));
points.push_back(toImVec2(right));
return points;
}
double CalculateDistanceMetersRadar(const vector3& location1, const vector3& location2) {
double dx = location1.x - location2.x;
double dy = location1.y - location2.y;
double dz = location1.z - location2.z;
return std::sqrt(dx * dx + dy * dy + dz * dz) / 100.0;
}
void radar::draw() {
if (esp_radar) {
// Define scale
const double scaleFactor = 0.05; // Scale to convert world units to radar units
// Calculate radar position based on the config setting
ImVec2 screenSize = ImGui::GetIO().DisplaySize;
// Calculate radar size using esp_radar_scale
double radarSize = screenSize.x * esp_radar_scale; // Scale dynamically based on setting
// Adjust position offsets relative to screen size
double padding = screenSize.x * 0.02; // 2% of screen width for padding
// Calculate radar center based on the user-defined position
vector2 radarCenter;
if (esp_radar_position == "Top Left") {
radarCenter = { radarSize / 2 + padding, radarSize / 2 + padding };
}
else if (esp_radar_position == "Top Middle") {
radarCenter = { screenSize.x / 2.0, radarSize / 2 + padding };
}
else if (esp_radar_position == "Top Right") {
radarCenter = { screenSize.x - radarSize / 2 - padding, radarSize / 2 + padding };
}
else if (esp_radar_position == "Middle Left") {
radarCenter = { radarSize / 2 + padding, screenSize.y / 2.0 };
}
else if (esp_radar_position == "Middle Right") {
radarCenter = { screenSize.x - radarSize / 2 - padding, screenSize.y / 2.0 };
}
else if (esp_radar_position == "Bottom Left") {
radarCenter = { radarSize / 2 + padding, screenSize.y - radarSize / 2 - padding };
}
else if (esp_radar_position == "Bottom Middle") {
radarCenter = { screenSize.x / 2.0, screenSize.y - radarSize / 2 - padding };
}
else if (esp_radar_position == "Bottom Right") {
radarCenter = { screenSize.x - radarSize / 2 - padding, screenSize.y - radarSize / 2 - padding };
}
// Get camera's rotation (from f_minimal_view_info)
f_camera_cache last_frame_cached = local_camera_manager->get_cached_frame_private();
f_minimal_view_info camera_cache = last_frame_cached.pov;
vector3 camera_rotation = camera_cache.rotation; // Get camera rotation (yaw, pitch, roll)
// Normalize yaw (roll)
double camera_yaw = camera_rotation.y; // Roll represents yaw
if (camera_yaw < 0) {
camera_yaw += 360.0; // Normalize to [0, 360)
}
camera_yaw = camera_yaw * (M_PI / 180.0); // Convert degrees to radians
// Get local player's position and rotation
auto local_root = local_mec->get_root_component();
vector3 local_pos = local_root->get_relative_location();
vector3 local_rot = local_root->get_relative_rotation();
// Determine the facing angle dynamically (in radians)
double player_facing_angle = local_rot.z * (M_PI / 180.0); // Convert degrees to radians
// Draw radar background
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(radarCenter), static_cast<float>(radarSize) / 2.0f, IM_COL32(0, 0, 0, 150)); // Semi-transparent black
ImGui::GetForegroundDrawList()->AddCircle(
toImVec2(radarCenter), static_cast<float>(radarSize) / 2.0f, IM_COL32(255, 255, 255, 255), 64, 1.5f); // White outline
// Player dot
float playerDotSize = 5.0f; // Size of the player's dot
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(radarCenter), playerDotSize, IM_COL32(255, 255, 0, 255)); // Bright yellow dot
// Cone to represent the player's POV
double fovAngle = 90.0 * (M_PI / 180.0); // FOV angle (90 degrees converted to radians)
// Calculate curved edge of the FOV cone
double coneRadius = radarSize / 2.0; // Radius of the radar
const int numSegments = 32; // Number of segments for smooth curvature
std::vector<ImVec2> coneVertices;
// Add the cone tip (player position)
coneVertices.push_back(toImVec2(radarCenter));
// Generate points along the curved edge
for (int i = 0; i <= numSegments; ++i) {
double angle = camera_yaw - (fovAngle / 2.0) + (fovAngle * i / numSegments);
vector2 edgePoint = radarCenter + vector2(
coneRadius * cos(angle),
coneRadius * sin(angle)
);
coneVertices.push_back(toImVec2(edgePoint));
}
// Draw the FOV cone as a filled polygon
ImGui::GetForegroundDrawList()->AddConvexPolyFilled(
coneVertices.data(), static_cast<int>(coneVertices.size()), IM_COL32(255, 255, 255, 64)); // White with 25% opacity
// Convert colors from config.h to ImU32
ImU32 employeeColor = ImGui::ColorConvertFloat4ToU32(config::employee_color);
ImU32 ghostEmployeeColor = ImGui::ColorConvertFloat4ToU32(config::ghost_employee_color);
ImU32 dissidentColor = ImGui::ColorConvertFloat4ToU32(config::dissident_color);
ImU32 ghostDissidentColor = ImGui::ColorConvertFloat4ToU32(config::ghost_dissident_color);
ImU32 weaponColor = ImGui::ColorConvertFloat4ToU32(config::weapon_color);
ImU32 gazColor = ImGui::ColorConvertFloat4ToU32(config::gaz_bottle_color);
ImU32 ventColor = ImGui::ColorConvertFloat4ToU32(config::vent_filter_color);
ImU32 riceColor = ImGui::ColorConvertFloat4ToU32(config::rice_color);
ImU32 packageColor = ImGui::ColorConvertFloat4ToU32(config::package_color);
ImU32 sampleColor = ImGui::ColorConvertFloat4ToU32(config::sample_color);
ImU32 containerColor = ImGui::ColorConvertFloat4ToU32(config::container_color);
ImU32 screwColor = ImGui::ColorConvertFloat4ToU32(config::screw_driver_color);
ImU32 batteryColor = ImGui::ColorConvertFloat4ToU32(config::battery_color);
ImU32 fuseColor = ImGui::ColorConvertFloat4ToU32(config::fuse_color);
ImU32 eggColor = ImGui::ColorConvertFloat4ToU32(config::egg_color);
ImU32 defibColor = ImGui::ColorConvertFloat4ToU32(config::defib_color);
ImU32 machinePartColor = ImGui::ColorConvertFloat4ToU32(config::machine_part_color);
ImU32 accessCardColor = ImGui::ColorConvertFloat4ToU32(config::access_card_color);
// Helper function for rotation
auto rotate_point = [](const vector2& point, double angle) {
double cos_a = cos(angle);
double sin_a = sin(angle);
return vector2{
point.x * cos_a - point.y * sin_a,
point.x * sin_a + point.y * cos_a
};
};
// Plot players
if (player_radar) {
for (auto mec : player_cache) {
if (mec != local_mec) {
auto role = mec->get_player_role(); // Get player role
ImU32 playercolor = (role == 4) ? dissidentColor : employeeColor; // Use config colors
auto root_component = mec->get_root_component();
if (!root_component) continue;
auto relative_location = root_component->get_relative_location();
vector3 position = relative_location;
vector3 relativePos = position - local_pos; // Calculate relative position
vector2 radarPos = { relativePos.x * scaleFactor, relativePos.y * scaleFactor }; // Map to radar space
// Rotate radar points based on player facing angle
radarPos = rotate_point(radarPos, player_facing_angle);
// Only draw players within radar bounds
if (radarPos.magnitude() < radarSize / 2) {
vector2 pointPos = radarCenter + radarPos; // Map to radar space
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(pointPos), 3.0f, playercolor); // Use role color
}
}
}
}
// Plot ghosts
if (ghost_radar) {
for (auto mec : player_cache) {
if (mec != local_mec) {
auto role = mec->get_player_role(); // Get player role
ImU32 ghostcolor = (role == 4) ? ghostDissidentColor : ghostEmployeeColor; // Use config colors
auto ghost_root = mec->get_ghost_root();
if (!ghost_root) continue;
auto root_component = mec->get_root_component();
if (!root_component) continue;
auto relative_location = ghost_root->get_relative_location();
auto mec_loc = root_component->get_relative_location();
// Calculate the distance between ghost and player
double ghost_distance = CalculateDistanceMetersRadar(mec_loc, relative_location);
if (ghost_distance > 2) { // If ghost moved away from the body
vector3 position = relative_location;
vector3 relativePos = position - local_pos; // Calculate relative position
vector2 radarPos = { relativePos.x * scaleFactor, relativePos.y * scaleFactor }; // Map to radar space
// Rotate radar points based on player facing angle
radarPos = rotate_point(radarPos, player_facing_angle);
// Only draw players within radar bounds
if (radarPos.magnitude() < radarSize / 2) {
vector2 pointPos = radarCenter + radarPos; // Map to radar space
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(pointPos), 3.0f, ghostcolor); // Use role color
}
}
}
}
}
// Plot weapons
if (weapon_radar) {
for (auto item : world_item_cache) {
if (!item) continue;
auto data = item->get_data();
auto item_name = data->get_name().read_string();
// Check if the item is a weapon
if (item_name == "SHORTY" || item_name == "PISTOL" || item_name == "REVOLVER" ||
item_name == "C4" || item_name == "DETONATOR" || item_name == "KNIFE") {
auto root_component = item->get_root_component();
if (!root_component) continue;
auto relative_location = root_component->get_relative_location();
vector3 position = relative_location;
vector3 relativePos = position - local_pos; // Calculate relative position
vector2 radarPos = { relativePos.x * scaleFactor, relativePos.y * scaleFactor }; // Map to radar space
// Rotate radar points based on player facing angle
radarPos = rotate_point(radarPos, player_facing_angle);
// Only draw items within radar bounds
if (radarPos.magnitude() < radarSize / 2) {
vector2 pointPos = radarCenter + radarPos; // Map to radar space
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(pointPos), 3.0f, weaponColor); // Use weaponColor for weapons
}
}
}
}
// Plot Primary Objects
if (primary_radar) {
for (auto item : world_item_cache) {
if (!item) continue;
auto data = item->get_data();
auto item_name = data->get_name().read_string();
// Check if the item is a weapon
if (item_name == "GAZ BOTTLE" || item_name == "VENT FILTER" || item_name == "RICE" ||
item_name == "PACKAGE" || item_name == "SAMPLE" || item_name == "ACCESS CARD") {
auto root_component = item->get_root_component();
if (!root_component) continue;
auto relative_location = root_component->get_relative_location();
vector3 position = relative_location;
vector3 relativePos = position - local_pos; // Calculate relative position
vector2 radarPos = { relativePos.x * scaleFactor, relativePos.y * scaleFactor }; // Map to radar space
// Rotate radar points based on player facing angle
radarPos = rotate_point(radarPos, player_facing_angle);
ImU32 dotColor = IM_COL32(255, 255, 255, 255);
if (item_name == "GAZ BOTTLE") {
dotColor = gazColor;
}
else if (item_name == "VENT FILTER") {
dotColor = ventColor;
}
else if (item_name == "RICE") {
dotColor = riceColor;
}
else if (item_name == "PACKAGE") {
dotColor = packageColor;
}
else if (item_name == "SAMPLE") {
dotColor = sampleColor;
}
else if (item_name == "ACCESS CARD") {
dotColor = sampleColor;
}
// Only draw items within radar bounds
if (radarPos.magnitude() < radarSize / 2) {
vector2 pointPos = radarCenter + radarPos; // Map to radar space
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(pointPos), 3.0f, dotColor);
}
}
}
}
// Plot Secondary Objects
if (secondary_radar) {
for (auto item : world_item_cache) {
if (!item) continue;
auto data = item->get_data();
auto item_name = data->get_name().read_string();
// Check if the item is a weapon
if (item_name == "BATTERY" || item_name == "FUSE" || item_name == "CONTAINER" ||
item_name == "SCREW DRIVER" || item_name == "EGG" || item_name == "EASTEREGG" ||
item_name == "REZ" || item_name == "DEFIBRILLATOR" || item_name == "MACHINE PART") {
auto root_component = item->get_root_component();
if (!root_component) continue;
auto relative_location = root_component->get_relative_location();
vector3 position = relative_location;
vector3 relativePos = position - local_pos; // Calculate relative position
vector2 radarPos = { relativePos.x * scaleFactor, relativePos.y * scaleFactor }; // Map to radar space
// Rotate radar points based on player facing angle
radarPos = rotate_point(radarPos, player_facing_angle);
ImU32 dotColor = IM_COL32(255, 255, 255, 255);
if (item_name == "BATTERY") {
dotColor = batteryColor;
}
else if (item_name == "FUSE") {
dotColor = fuseColor;
}
else if (item_name == "CONTAINER") {
dotColor = containerColor;
}
else if (item_name == "SCREW DRIVER") {
dotColor = screwColor;
}
else if (item_name == "EGG" || item_name == "EASTEREGG") {
dotColor = eggColor;
}
else if (item_name == "REZ" || item_name == "DEFIBRILLATOR") {
dotColor = defibColor;
}
else if (item_name == "MACHINE PART") {
dotColor = machinePartColor;
}
// Only draw items within radar bounds
if (radarPos.magnitude() < radarSize / 2) {
vector2 pointPos = radarCenter + radarPos; // Map to radar space
ImGui::GetForegroundDrawList()->AddCircleFilled(
toImVec2(pointPos), 3.0f, dotColor);
}
}
}
}
}
}