Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More stuff for the ImGui text HUD tab #345

Merged
merged 5 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion spt/features/ent_props.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "string_utils.hpp"
#include "spt\utils\portal_utils.hpp"
#include "SPTLib\patterns.hpp"
#include "visualizations/imgui/imgui_interface.hpp"

#include <string>
#include <unordered_map>

Expand Down Expand Up @@ -445,14 +447,17 @@ void EntProps::LoadFeature()
#if defined(SPT_HUD_ENABLED) && defined(SPT_PORTAL_UTILS)
if (utils::DoesGameLookLikePortal())
{
AddHudCallback(
bool hudEnabled = AddHudCallback(
"portal_bubble",
[this](std::string)
{
int in_bubble = GetEnvironmentPortal() != NULL;
spt_hud_feat.DrawTopHudElement(L"portal bubble: %d", in_bubble);
},
y_spt_hud_portal_bubble);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_portal_bubble);
}
#endif

Expand Down
6 changes: 6 additions & 0 deletions spt/features/hud.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class HUDFeature : public FeatureWrapper<HUDFeature>
virtual bool ShouldLoadFeature() override;
bool GetFont(const std::string& fontName, vgui::HFont& fontOut);

// call from LoadFeature or later
bool LoadingSuccessful() const
{
return loadingSuccessful;
}

protected:
virtual void InitHooks() override;
virtual void PreHook() override;
Expand Down
211 changes: 146 additions & 65 deletions spt/features/playerio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "spt\utils\portal_utils.hpp"
#include "spt\utils\convar.hpp"
#include "..\strafe\strafestuff.hpp"
#include "visualizations/imgui/imgui_interface.hpp"

#ifdef SSDK2007
#include "mathlib\vmatrix.h"
Expand Down Expand Up @@ -901,7 +902,7 @@ void PlayerIOFeature::LoadFeature()
{
TickSignal.Connect(this, &PlayerIOFeature::OnTick);

AddHudCallback(
bool hudEnabled = AddHudCallback(
"accel",
[this](std::string)
{
Expand All @@ -913,76 +914,115 @@ void PlayerIOFeature::LoadFeature()
spt_hud_feat.DrawTopHudElement(L"accel(xy): %.3f", accel.Length2D());
},
y_spt_hud_accel);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_accel);
}

AddHudCallback(
"position",
[this](std::string args)
{
int mode = (args == "") ? spt_hud_position.GetInt() : std::stoi(args);
Vector pos = (mode == 1) ? m_vecAbsOrigin.GetValue() + m_vecViewOffset.GetValue()
: m_vecAbsOrigin.GetValue();
int precision = (mode == 1) ? 2 : mode;

spt_hud_feat.DrawTopHudElement(L"pos: %.*f %.*f %.*f",
precision,
pos.x,
precision,
pos.y,
precision,
pos.z);
},
spt_hud_position);
{
bool hudEnabled = AddHudCallback(
"position",
[this](std::string args)
{
int mode = (args == "") ? spt_hud_position.GetInt() : std::stoi(args);
Vector pos = (mode == 1) ? m_vecAbsOrigin.GetValue() + m_vecViewOffset.GetValue()
: m_vecAbsOrigin.GetValue();
int precision = (mode == 1) ? 2 : mode;

spt_hud_feat.DrawTopHudElement(L"pos: %.*f %.*f %.*f",
precision,
pos.x,
precision,
pos.y,
precision,
pos.z);
},
spt_hud_position);

AddHudCallback(
"angles",
[this](std::string args)
{
int mode = (args == "") ? spt_hud_angles.GetInt() : std::stoi(args);
QAngle ang = utils::GetPlayerEyeAngles();
int precision = (mode < 2) ? 2 : mode;

spt_hud_feat.DrawTopHudElement(L"ang: %.*f %.*f %.*f",
precision,
ang.x,
precision,
ang.y,
precision,
ang.z);
},
spt_hud_angles);
if (hudEnabled)
{
SptImGui::RegisterHudCvarCallback(
spt_hud_position,
[](ConVar& cv)
{
const char* opts[] = {
"Disabled",
"Eye position",
"Player position (high precision)",
};
SptImGui::CvarCombo(cv, "##pos", opts, ARRAYSIZE(opts));
},
false);
}
}

AddHudCallback(
"velocity",
[this](std::string args)
{
int mode = (args == "") ? y_spt_hud_velocity.GetInt() : std::stoi(args);
Vector currentVel = GetPlayerVelocity();
if (mode != 2)
spt_hud_feat.DrawTopHudElement(L"vel(xyz): %.3f %.3f %.3f",
currentVel.x,
currentVel.y,
currentVel.z);
if (mode != 3)
spt_hud_feat.DrawTopHudElement(L"vel(xy): %.3f", currentVel.Length2D());
},
y_spt_hud_velocity);
{
bool hudEnabled = AddHudCallback(
"angles",
[this](std::string args)
{
int mode = (args == "") ? spt_hud_angles.GetInt() : std::stoi(args);
QAngle ang = utils::GetPlayerEyeAngles();
int precision = (mode < 2) ? 2 : mode;

spt_hud_feat.DrawTopHudElement(L"ang: %.*f %.*f %.*f",
precision,
ang.x,
precision,
ang.y,
precision,
ang.z);
},
spt_hud_angles);

AddHudCallback(
"velocity_angles",
[this](std::string)
{
Vector currentVel = GetPlayerVelocity();
QAngle angles;
VectorAngles(currentVel, Vector(0, 0, 1), angles);
spt_hud_feat.DrawTopHudElement(L"vel(p/y/r): %.3f %.3f %.3f", angles.x, angles.y, angles.z);
},
y_spt_hud_velocity_angles);
if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(spt_hud_angles);
}

{
bool hudEnabled = AddHudCallback(
"velocity",
[this](std::string args)
{
int mode = (args == "") ? y_spt_hud_velocity.GetInt() : std::stoi(args);
Vector currentVel = GetPlayerVelocity();
if (mode != 2)
spt_hud_feat.DrawTopHudElement(L"vel(xyz): %.3f %.3f %.3f",
currentVel.x,
currentVel.y,
currentVel.z);
if (mode != 3)
spt_hud_feat.DrawTopHudElement(L"vel(xy): %.3f", currentVel.Length2D());
},
y_spt_hud_velocity);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_velocity);
}

{
bool hudEnabled = AddHudCallback(
"velocity_angles",
[this](std::string)
{
Vector currentVel = GetPlayerVelocity();
QAngle angles;
VectorAngles(currentVel, Vector(0, 0, 1), angles);
spt_hud_feat.DrawTopHudElement(L"vel(p/y/r): %.3f %.3f %.3f",
angles.x,
angles.y,
angles.z);
},
y_spt_hud_velocity_angles);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_velocity_angles);
}

#ifdef SPT_PORTAL_UTILS
if (utils::DoesGameLookLikePortal())
{
AddHudCallback(
bool hudEnabled = AddHudCallback(
"ag_sg_tester",
[this](std::string)
{
Expand All @@ -992,6 +1032,9 @@ void PlayerIOFeature::LoadFeature()
spt_hud_feat.DrawTopHudElement(L"ag sg: %s", result.c_str());
},
y_spt_hud_ag_sg_tester);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_ag_sg_tester);
}
#endif
#endif
Expand Down Expand Up @@ -1027,43 +1070,81 @@ void PlayerIOFeature::LoadFeature()
y_spt_hud_flags);

if (hasHudFlags)
{
InitCommand(y_spt_hud_flags_filter);

SptImGui::RegisterHudCvarCallback(
y_spt_hud_flags,
[](ConVar& cv)
{
ImGui::BeginDisabled(!SptImGui::CvarCheckbox(y_spt_hud_flags, "enabled"));
ImGui::TextUnformatted("Flag filter");
ImGui::SameLine();
SptImGui::HelpMarker("Can be set with %s.",
WrangleLegacyCommandName(y_spt_hud_flags_filter_command
.GetName(),
true,
nullptr));
if (ImGui::Button("Enable all"))
hud_flags_filter = ~((decltype(hud_flags_filter))0);
ImGui::SameLine();
if (ImGui::Button("Disable all"))
hud_flags_filter = 0;
for (size_t i = 0; i < ARRAYSIZE(FLAGS); i++)
{
bool flag = hud_flags_filter & (1 << i);
if (ImGui::Checkbox(FLAGS[i], &flag))
hud_flags_filter = (hud_flags_filter & ~(1 << i)) | (flag << i);
}
ImGui::EndDisabled();
},
true);
}
}

if (m_MoveType.Found())
{
AddHudCallback(
bool hudEnabled = AddHudCallback(
"moveflags",
[this](std::string)
{
int flags = spt_playerio.m_MoveType.GetValue();
DrawFlagsHud(L"Move type", MOVETYPE_FLAGS, ARRAYSIZE(MOVETYPE_FLAGS), flags);
},
y_spt_hud_moveflags);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_moveflags);
}

if (m_CollisionGroup.Found())
{
AddHudCallback(
bool hudEnabled = AddHudCallback(
"collisionflags",
[this](std::string)
{
int flags = spt_playerio.m_CollisionGroup.GetValue();
DrawFlagsHud(L"Collision group", COLLISION_GROUPS, ARRAYSIZE(COLLISION_GROUPS), flags);
},
y_spt_hud_collisionflags);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_collisionflags);
}

if (m_MoveCollide.Found())
{
AddHudCallback(
bool hudEnabled = AddHudCallback(
"movecollideflags",
[this](std::string)
{
int flags = spt_playerio.m_MoveCollide.GetValue();
DrawFlagsHud(L"Move collide", MOVECOLLIDE_FLAGS, ARRAYSIZE(MOVECOLLIDE_FLAGS), flags);
},
y_spt_hud_movecollideflags);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_movecollideflags);
}
#endif
}
8 changes: 7 additions & 1 deletion spt/features/saveloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include "signals.hpp"
#include "convar.hpp"
#include "..\features\afterticks.hpp"
#include "spt\features\hud.hpp"
#include "visualizations/imgui/imgui_interface.hpp"

#include <format>

static std::vector<const char*> _saveloadTypes = {"segment", "execute", "render"};
Expand Down Expand Up @@ -134,7 +137,7 @@ void SaveloadsFeature::LoadFeature()
InitCommand(y_spt_saveloads_stop);

#ifdef SPT_HUD_ENABLED
AddHudCallback(
bool hudEnabled = AddHudCallback(
"saveloads_showcurindex",
[this](std::string)
{
Expand All @@ -147,6 +150,9 @@ void SaveloadsFeature::LoadFeature()
spt_hud_feat.DrawTopHudElement(L"SAVELOADS: Not executing");
},
y_spt_hud_saveloads_showcurindex);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_saveloads_showcurindex);
#endif

SetSignonStateSignal.Connect(this, &SaveloadsFeature::OnSetSignonState);
Expand Down
6 changes: 5 additions & 1 deletion spt/features/shadow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ent_utils.hpp"
#include "ent_props.hpp"
#include "playerio.hpp"
#include "visualizations/imgui/imgui_interface.hpp"

ConVar y_spt_hud_shadow_info("y_spt_hud_shadow_info",
"0",
Expand Down Expand Up @@ -73,7 +74,7 @@ void ShadowPosition::LoadFeature()
if (ORIG_GetShadowPosition)
{
#ifdef SPT_HUD_ENABLED
AddHudCallback(
bool hudEnabled = AddHudCallback(
"shadow_info",
[this](std::string)
{
Expand All @@ -83,6 +84,9 @@ void ShadowPosition::LoadFeature()
spt_hud_feat.DrawTopHudElement(L"shadow ang (pyr): %.3f %.3f %.3f", ang.x, ang.y, ang.z);
},
y_spt_hud_shadow_info);

if (hudEnabled)
SptImGui::RegisterHudCvarCheckbox(y_spt_hud_shadow_info);
#endif
}

Expand Down
Loading