-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.cpp
More file actions
190 lines (147 loc) · 5.98 KB
/
render.cpp
File metadata and controls
190 lines (147 loc) · 5.98 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
#include "render.hpp"
#include "cheats/Visuals/Visuals.hpp"
#include "cheats/Misc/Misc.hpp"
#include "fonts/andalemono.h"
#include "fonts/arial.h"
#include "fonts/verdana.h"
ImFont* f_Courier;
ImFont* f_Arial;
ImFont* f_Verdana;
ImFont* f_AndaleMono;
ImDrawListSharedData _data;
std::mutex render_mutex;
void Render::Initialize()
{
ImGui::CreateContext();
ImGui_ImplWin32_Init(InputSys::Get().GetMainWindow());
ImGui_ImplDX9_Init(g_D3DDevice9);
draw_list = new ImDrawList(ImGui::GetDrawListSharedData());
draw_list_act = new ImDrawList(ImGui::GetDrawListSharedData());
draw_list_rendering = new ImDrawList(ImGui::GetDrawListSharedData());
InitFonts();
}
void Render::InitFonts()
{
static const ImWchar ranges[] =
{
0x0020, 0x00FF,
0x0400, 0x044F,
0x2005, 0x28FF,
0,
};
f_Arial= ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(arial_compressed_data,
arial_compressed_size,
10.f,
nullptr,
ranges);
f_Verdana = ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(verdana_compressed_data,
verdana_compressed_size,
10.f,
nullptr,
ranges);
f_AndaleMono = ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(andalemono_compressed_data,
andalemono_compressed_size,
12.f,
nullptr,
ranges);
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(andalemono_compressed_data,
andalemono_compressed_size,
10.f,
nullptr,
ranges);
}
void Render::ClearDrawList()
{
render_mutex.lock();
draw_list_act->Clear();
render_mutex.unlock();
}
void Render::BeginScene()
{
draw_list->Clear();
draw_list->PushClipRectFullScreen();
Render::Get().RenderText("Chimphook", ImVec2(10, 5), 12.f, Color(255, 255, 255, 255), false, false, f_Arial);
SniperCrosshair();
WallbangCrosshair();
DebugMode();
SmokeHelper::Get().Draw();
if (g_EngineClient->IsInGame() && g_LocalPlayer)
Visuals::Get().AddToDrawList();
if (g_EngineClient->IsInGame() && g_LocalPlayer && g_LocalPlayer->IsAlive())
GrenadePrediction::Get().Paint();
if (g_EngineClient->IsInGame() && g_LocalPlayer && g_LocalPlayer->SelfOrObs()->IsAlive())
ZeusRange();
render_mutex.lock();
*draw_list_act = *draw_list;
render_mutex.unlock();
}
ImDrawList* Render::RenderScene()
{
if (render_mutex.try_lock())
{
*draw_list_rendering = *draw_list_act;
render_mutex.unlock();
}
return draw_list_rendering;
}
float Render::RenderText(const std::string& text, ImVec2 pos, float size, Color color, bool center, bool outline, ImFont* pFont)
{
ImVec2 textSize = pFont->CalcTextSizeA(size, FLT_MAX, 0.0f, text.c_str());
if (!pFont->ContainerAtlas) return 0.f;
draw_list->PushTextureID(pFont->ContainerAtlas->TexID);
if (center)
pos.x -= textSize.x / 2.0f;
if (outline)
{
draw_list->AddText(pFont, size, ImVec2(pos.x + 1, pos.y + 1), GetU32(Color(0, 0, 0, color.a())), text.c_str());
draw_list->AddText(pFont, size, ImVec2(pos.x - 1, pos.y - 1), GetU32(Color(0, 0, 0, color.a())), text.c_str());
draw_list->AddText(pFont, size, ImVec2(pos.x + 1, pos.y - 1), GetU32(Color(0, 0, 0, color.a())), text.c_str());
draw_list->AddText(pFont, size, ImVec2(pos.x - 1, pos.y + 1), GetU32(Color(0, 0, 0, color.a())), text.c_str());
}
draw_list->AddText(pFont, size, pos, GetU32(color), text.c_str());
draw_list->PopTextureID();
return pos.y + textSize.y;
}
void Render::RenderCircle3D(Vector position, float points, float radius, Color color, int thickness)
{
float step = (float)M_PI * 2.0f / points;
for (float a = 0; a < (M_PI * 2.0f); a += step)
{
Vector start(radius * cosf(a) + position.x, radius * sinf(a) + position.y, position.z);
Vector end(radius * cosf(a + step) + position.x, radius * sinf(a + step) + position.y, position.z);
Vector start2d, end2d;
if (g_DebugOverlay->ScreenPosition(start, start2d) || g_DebugOverlay->ScreenPosition(end, end2d))
return;
RenderLine(start2d.x, start2d.y, end2d.x, end2d.y, color, thickness);
}
}
void Render::Render3DCube(float scalar, QAngle angles, Vector middle_origin, Color outline)
{
Vector forward, right, up;
Math::AngleVectors(angles, forward, right, up);
Vector points[8];
points[0] = middle_origin - (right * scalar) + (up * scalar) - (forward * scalar);
points[1] = middle_origin + (right * scalar) + (up * scalar) - (forward * scalar);
points[2] = middle_origin - (right * scalar) - (up * scalar) - (forward * scalar);
points[3] = middle_origin + (right * scalar) - (up * scalar) - (forward * scalar);
points[4] = middle_origin - (right * scalar) + (up * scalar) + (forward * scalar);
points[5] = middle_origin + (right * scalar) + (up * scalar) + (forward * scalar);
points[6] = middle_origin - (right * scalar) - (up * scalar) + (forward * scalar);
points[7] = middle_origin + (right * scalar) - (up * scalar) + (forward * scalar);
Vector points_screen[8];
for (int i = 0; i < 8; i++)
if (!Math::WorldToScreen(points[i], points_screen[i]))
return;
RenderLine(points_screen[0].x, points_screen[0].y, points_screen[1].x, points_screen[1].y, outline);
RenderLine(points_screen[0].x, points_screen[0].y, points_screen[2].x, points_screen[2].y, outline);
RenderLine(points_screen[3].x, points_screen[3].y, points_screen[1].x, points_screen[1].y, outline);
RenderLine(points_screen[3].x, points_screen[3].y, points_screen[2].x, points_screen[2].y, outline);
RenderLine(points_screen[0].x, points_screen[0].y, points_screen[4].x, points_screen[4].y, outline);
RenderLine(points_screen[1].x, points_screen[1].y, points_screen[5].x, points_screen[5].y, outline);
RenderLine(points_screen[2].x, points_screen[2].y, points_screen[6].x, points_screen[6].y, outline);
RenderLine(points_screen[3].x, points_screen[3].y, points_screen[7].x, points_screen[7].y, outline);
RenderLine(points_screen[4].x, points_screen[4].y, points_screen[5].x, points_screen[5].y, outline);
RenderLine(points_screen[4].x, points_screen[4].y, points_screen[6].x, points_screen[6].y, outline);
RenderLine(points_screen[7].x, points_screen[7].y, points_screen[5].x, points_screen[5].y, outline);
RenderLine(points_screen[7].x, points_screen[7].y, points_screen[6].x, points_screen[6].y, outline);
}