Skip to content

Commit b02db70

Browse files
committed
feat: improve sar_quickhud and sar_crosshair
1 parent 0b173d1 commit b02db70

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

src/Features/Hud/Crosshair.cpp

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@ Variable cl_crosshair_t("cl_crosshair_t", "0",
2929
"Removes the top line from the crosshair :"
3030
"0: normal crosshair,"
3131
"1: crosshair without top.\n");
32-
Variable cl_crosshairgap("cl_crosshairgap", "5", 0, "Changes the distance of the crosshair lines from the center of screen.\n");
33-
Variable cl_crosshaircolor_r("cl_crosshaircolor_r", "0", 0, 255, "Changes the color of the crosshair.\n");
32+
Variable cl_crosshairgap("cl_crosshairgap", "9", 0, "Changes the distance of the crosshair lines from the center of screen.\n");
33+
Variable cl_crosshaircolor_r("cl_crosshaircolor_r", "255", 0, 255, "Changes the color of the crosshair.\n");
3434
Variable cl_crosshaircolor_g("cl_crosshaircolor_g", "255", 0, 255, "Changes the color of the crosshair.\n");
35-
Variable cl_crosshaircolor_b("cl_crosshaircolor_b", "0", 0, 255, "Changes the color of the crosshair.\n");
36-
Variable cl_crosshairsize("cl_crosshairsize", "5", -100, "Changes the size of the crosshair.\n");
35+
Variable cl_crosshaircolor_b("cl_crosshaircolor_b", "255", 0, 255, "Changes the color of the crosshair.\n");
36+
Variable cl_crosshairsize("cl_crosshairsize", "1", -100, "Changes the size of the crosshair.\n");
3737
Variable cl_crosshairthickness("cl_crosshairthickness", "0", 0, "Changes the thinkness of the crosshair lines.\n");
3838
Variable cl_crosshairalpha("cl_crosshairalpha", "255", 0, 255, "Change the amount of transparency.\n");
3939
Variable cl_crosshairdot("cl_crosshairdot", "1", "Decides if there is a dot in the middle of the crosshair\n");
4040

41-
Variable cl_quickhud_x("sar_quickhud_x", "45", -1000, "Horizontal distance of the custom quickhud.\n");
42-
Variable cl_quickhud_y("sar_quickhud_y", "0", -1000, "Vertical distance of the custom quickhud.\n");
43-
Variable cl_quickhud_size("sar_quickhud_size", "15", -100, "Size of the custom quickhud.\n");
4441
Variable cl_quickhudleftcolor_r("cl_quickhudleftcolor_r", "255", 0, 255, "Changes the color of the left quickhud.\n");
4542
Variable cl_quickhudleftcolor_g("cl_quickhudleftcolor_g", "184", 0, 255, "Changes the color of the left quickhud.\n");
4643
Variable cl_quickhudleftcolor_b("cl_quickhudleftcolor_b", "86", 0, 255, "Changes the color of the left quickhud.\n");
@@ -52,7 +49,7 @@ Variable cl_quickhud_alpha("cl_quickhud_alpha", "255", 0, 255, "Change the amoun
5249
Crosshair crosshair;
5350

5451
Crosshair::Crosshair()
55-
: Hud(HudType_InGame, true)
52+
: Hud(HudType_InGame, false)
5653
, crosshairTextureID(0)
5754
, quickhudTextureID{-1, -1, -1, -1}
5855
, isCustomCrosshairReady(false)
@@ -109,7 +106,9 @@ bool Crosshair::IsSurfacePortalable() {
109106

110107
int Crosshair::GetPortalUpgradeState() {
111108
if (server->portalGun != nullptr) {
112-
return SE(server->portalGun)->field<bool>("m_bCanFirePortal1") + SE(server->portalGun)->field<bool>("m_bCanFirePortal2");
109+
bool prim = SE(server->portalGun)->field<bool>("m_bCanFirePortal1");
110+
bool sec = SE(server->portalGun)->field<bool>("m_bCanFirePortal2");
111+
return prim | (sec << 1);
113112
}
114113

115114
return 0;
@@ -167,8 +166,6 @@ void Crosshair::Paint(int slot) {
167166
return;
168167
}
169168

170-
surface->StartDrawing(surface->matsurface->ThisPtr());
171-
172169
int xScreen, yScreen, xCenter, yCenter;
173170
engine->GetScreenSize(nullptr, xScreen, yScreen);
174171

@@ -224,18 +221,18 @@ void Crosshair::Paint(int slot) {
224221
Color cl(cl_quickhudleftcolor_r.GetInt(), cl_quickhudleftcolor_g.GetInt(), cl_quickhudleftcolor_b.GetInt(), cl_quickhud_alpha.GetInt());
225222
Color cr(cl_quickhudrightcolor_r.GetInt(), cl_quickhudrightcolor_g.GetInt(), cl_quickhudrightcolor_b.GetInt(), cl_quickhud_alpha.GetInt());
226223

227-
int x1 = xCenter - cl_quickhud_x.GetInt();
228-
int x2 = xCenter + cl_quickhud_x.GetInt();
229-
int y1 = yCenter + cl_quickhud_y.GetInt();
230-
int size = cl_quickhud_size.GetInt();
224+
int x1 = xCenter - 0;//cl_quickhud_x.GetInt();
225+
int x2 = xCenter + 0;//cl_quickhud_x.GetInt();
226+
int y1 = yCenter + 0;//cl_quickhud_y.GetInt();
227+
int size = 10;//cl_quickhud_size.GetInt();
231228

232229
if (bluePortalState) {
233230
surface->DrawFilledCircle(x1, y1, size, cr);
234231
} else {
235232
surface->DrawCircle(x1, y1, size, cr);
236233
}
237234

238-
if (portalGunUpgradeState == 2) {
235+
if (portalGunUpgradeState & 2) {
239236
if (orangePortalState) {
240237
surface->DrawFilledCircle(x2, y1, size, cl);
241238
} else {
@@ -244,22 +241,34 @@ void Crosshair::Paint(int slot) {
244241
}
245242

246243
} else if ((sar_quickhud_mode.GetInt() == 2 || sar_crosshair_P1.GetBool()) && this->isCustomQuickHudReady && portalGunUpgradeState) { // Quickhud from .png
244+
int width, height;
247245

248-
surface->DrawSetColor(surface->matsurface->ThisPtr(), 255, 255, 255, cl_quickhud_alpha.GetInt());
249-
int halfSize = cl_quickhud_size.GetInt() / 2;
250-
int xOffset = cl_quickhud_x.GetInt();
251-
int yOffset = cl_quickhud_y.GetInt();
246+
Color blue { 111, 184, 255 };
247+
Color orange { 255, 184, 86 };
248+
Color atlas_prim { 32, 128, 210 };
249+
Color atlas_sec { 16, 0, 210 };
250+
Color pbody_prim { 255, 180, 32 };
251+
Color pbody_sec { 58, 3, 3 };
252252

253-
surface->DrawSetTexture(surface->matsurface->ThisPtr(), this->quickhudTextureID[bluePortalState]); //Blue
254-
surface->DrawTexturedRect(surface->matsurface->ThisPtr(), xCenter - halfSize * 2 - xOffset, yCenter - halfSize - yOffset, xCenter - xOffset, yCenter + halfSize - yOffset);
253+
Color real_prim = engine->IsOrange() ? pbody_prim : engine->IsCoop() ? atlas_prim : blue;
254+
Color real_sec = engine->IsOrange() ? pbody_sec : engine->IsCoop() ? atlas_sec : orange;
255255

256-
if (portalGunUpgradeState) {
257-
surface->DrawSetTexture(surface->matsurface->ThisPtr(), this->quickhudTextureID[orangePortalState + 2]); //Orange
258-
surface->DrawTexturedRect(surface->matsurface->ThisPtr(), xCenter + xOffset, yCenter - halfSize - yOffset, xCenter + halfSize * 2 + xOffset, yCenter + halfSize - yOffset);
259-
}
260-
}
256+
Color prim = (portalGunUpgradeState & 1) ? real_prim : real_sec;
257+
Color sec = (portalGunUpgradeState & 2) ? real_sec : real_prim;
261258

262-
surface->FinishDrawing();
259+
bool prim_state = (portalGunUpgradeState & 1) ? bluePortalState : orangePortalState;
260+
bool sec_state = (portalGunUpgradeState & 2) ? orangePortalState : bluePortalState;
261+
262+
surface->DrawGetTextureSize(surface->matsurface->ThisPtr(), this->quickhudTextureID[prim_state], width, height);
263+
surface->DrawSetTexture(surface->matsurface->ThisPtr(), this->quickhudTextureID[prim_state]);
264+
surface->DrawSetColor(surface->matsurface->ThisPtr(), prim.r, prim.g, prim.b, cl_quickhud_alpha.GetInt());
265+
surface->DrawTexturedRect(surface->matsurface->ThisPtr(), xCenter - width/2, yCenter - height/2, xCenter + width/2, yCenter + height/2);
266+
267+
surface->DrawGetTextureSize(surface->matsurface->ThisPtr(), this->quickhudTextureID[sec_state + 2], width, height);
268+
surface->DrawSetTexture(surface->matsurface->ThisPtr(), this->quickhudTextureID[sec_state + 2]);
269+
surface->DrawSetColor(surface->matsurface->ThisPtr(), sec.r, sec.g, sec.b, cl_quickhud_alpha.GetInt());
270+
surface->DrawTexturedRect(surface->matsurface->ThisPtr(), xCenter - width/2, yCenter - height/2, xCenter + width/2, yCenter + height/2);
271+
}
263272
}
264273

265274
int Crosshair::SetCrosshairTexture(const std::string filename) {

src/Modules/Server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ DETOUR(Server::PlayerMove) {
170170
auto mv = *reinterpret_cast<const CHLMoveData **>((uintptr_t)thisptr + Offsets::mv);
171171

172172
if (sar_crosshair_mode.GetBool() || sar_quickhud_mode.GetBool() || sar_crosshair_P1.GetBool()) {
173-
server->portalGun = entityList->LookupEntity(SE(player)->active_weapon());
173+
int slot = server->GetSplitScreenPlayerSlot(player);
174+
if (slot == 0 || engine->IsOrange()) {
175+
server->portalGun = entityList->LookupEntity(SE(player)->active_weapon());
176+
}
174177
}
175178

176179
auto m_fFlags = SE(player)->field<int>("m_fFlags");

0 commit comments

Comments
 (0)