Skip to content

Commit

Permalink
Add a bunch of QoL/cheat features to imgui
Browse files Browse the repository at this point in the history
- Add QoL & cheat tab

- Add IHUD/JHUD tabs in addition to text HUD tab

- Add misc section to drawing tab

- Add RTA time to timer feature
  • Loading branch information
UncraftedName committed Sep 20, 2024
1 parent 66d820d commit 7b8da01
Show file tree
Hide file tree
Showing 28 changed files with 607 additions and 68 deletions.
12 changes: 12 additions & 0 deletions spt/features/autojump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "dbg.h"
#include "signals.hpp"
#include "game_detection.hpp"
#include "visualizations\imgui\imgui_interface.hpp"

#ifdef OE
#include "mathlib.h"
Expand Down Expand Up @@ -187,6 +188,15 @@ void AutojumpFeature::LoadFeature()
else
// dmomm
off_player_ptr = 4;

SptImGuiGroup::Cheats_Jumping.RegisterUserCallback(
[]()
{
SptImGui::CvarCheckbox(y_spt_autojump, "##checkbox_autojump");
SptImGui::CvarCheckbox(_y_spt_autojump_ensure_legit, "##checkbox_legit");
const char* opts[] = {"Default", "ABH jumpboost", "OE jumpboost", "No jumpboost"};
SptImGui::CvarCombo(y_spt_jumpboost, "jumpboost type", opts, ARRAYSIZE(opts));
});
}
else
{
Expand All @@ -202,6 +212,8 @@ void AutojumpFeature::LoadFeature()
if (utils::DoesGameLookLikePortal() && ORIG_CGameMovement__AirMove && ORIG_CPortalGameMovement__AirMove)
{
InitConcommandBase(y_spt_aircontrol);
SptImGuiGroup::Cheats_HL2AirControl.RegisterUserCallback(
[]() { SptImGui::CvarCheckbox(y_spt_aircontrol, "##checkbox"); });
}
}

Expand Down
12 changes: 12 additions & 0 deletions spt/features/boog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "playerio.hpp"
#include "signals.hpp"
#include "game_detection.hpp"
#include "visualizations\imgui\imgui_interface.hpp"

ConVar y_spt_hud_edgebug("y_spt_hud_edgebug",
"0",
Expand Down Expand Up @@ -177,6 +178,17 @@ void BoogFeature::LoadFeature()
{
InitConcommandBase(y_spt_hud_edgebug);
InitConcommandBase(y_spt_hud_edgebug_sec);

SptImGui::RegisterHudCvarCallback(
y_spt_hud_edgebug,
[](ConVar& var)
{
SptImGui::CvarCheckbox(y_spt_hud_edgebug, "##checkbox");
SptImGui::CvarFloat(y_spt_hud_edgebug_sec,
"edgebug display time",
"enter time in seconds");
},
true);
}
}
}
Expand Down
48 changes: 38 additions & 10 deletions spt/features/collision_group.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
#include "stdafx.hpp"
#include "ent_utils.hpp"
#include "..\feature.hpp"
#include "visualizations\imgui\imgui_interface.hpp"

namespace patterns
{
PATTERNS(SetCollisionGroup,
"4044",
"8B 54 24 ?? 8B 81 ?? ?? ?? ?? 3B C2",
"5135",
"56 8B F1 8B 86 ?? ?? ?? ?? 3B 44 24 08 8D",
"7467727",
"55 8B EC 53 8B 5D ?? 56 57 8B F9 39 9F ?? ?? ?? ?? 74 ?? 8B ?? ?? ?? ?? ?? 8D",
"BMS-Retail",
"55 8B EC 53 8B D9 56 57 8B 7D ?? 39 BB ?? ?? ?? ?? 74 ?? 80 79 ?? 00");
"4044",
"8B 54 24 ?? 8B 81 ?? ?? ?? ?? 3B C2",
"5135",
"56 8B F1 8B 86 ?? ?? ?? ?? 3B 44 24 08 8D",
"7467727",
"55 8B EC 53 8B 5D ?? 56 57 8B F9 39 9F ?? ?? ?? ?? 74 ?? 8B ?? ?? ?? ?? ?? 8D",
"BMS-Retail",
"55 8B EC 53 8B D9 56 57 8B 7D ?? 39 BB ?? ?? ?? ?? 74 ?? 80 79 ?? 00");
}

class CollisionGroup : public FeatureWrapper<CollisionGroup>
{
public:
DECL_MEMBER_THISCALL(void, SetCollisionGroup, void*, int collisionGroup);

protected:
virtual bool ShouldLoadFeature() override
{
Expand All @@ -37,18 +39,26 @@ class CollisionGroup : public FeatureWrapper<CollisionGroup>

CollisionGroup spt_collisiongroup;

CON_COMMAND_F(y_spt_set_collision_group, "Set player's collision group\nUsually:\n- 5 is normal collisions\n- 10 is quickclip\n", FCVAR_CHEAT)
CON_COMMAND_F(y_spt_set_collision_group,
"Set player's collision group\nUsually:\n- 5 is normal collisions\n- 10 is quickclip\n",
FCVAR_CHEAT)
{
if (!spt_collisiongroup.ORIG_SetCollisionGroup)
return;

if (args.ArgC() < 2)
{
Warning("Format: spt_set_collision_group <collision group index>\nUsually:\n- 5 is normal collisions\n- 10 is quickclip\n");
Warning(
"Format: spt_set_collision_group <collision group index>\nUsually:\n- 5 is normal collisions\n- 10 is quickclip\n");
return;
}

auto playerPtr = utils::GetServerPlayer();
if (!playerPtr)
{
Warning("Server player not available\n");
return;
}
int collide = atoi(args.Arg(1));

spt_collisiongroup.ORIG_SetCollisionGroup(playerPtr, collide);
Expand All @@ -57,7 +67,25 @@ CON_COMMAND_F(y_spt_set_collision_group, "Set player's collision group\nUsually:
void CollisionGroup::LoadFeature()
{
if (ORIG_SetCollisionGroup)
{
InitCommand(y_spt_set_collision_group);
SptImGuiGroup::Cheats_PlayerCollisionGroup.RegisterUserCallback(
[]()
{
static long long val = 5;
SptImGui::InputTextInteger("value", "enter integer", val, 10);
ImGui::SameLine();
auto playerPtr = utils::GetServerPlayer();
ImGui::BeginDisabled(!playerPtr);
if (ImGui::Button("set"))
spt_collisiongroup.ORIG_SetCollisionGroup(playerPtr, (int)val);
ImGui::EndDisabled();
if (!playerPtr)
ImGui::SetItemTooltip("server player not available");
ImGui::SameLine();
SptImGui::CmdHelpMarkerWithName(y_spt_set_collision_group_command);
});
}
}

void CollisionGroup::UnloadFeature() {}
3 changes: 3 additions & 0 deletions spt/features/con_notify.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "stdafx.hpp"
#include "..\feature.hpp"
#include "visualizations\imgui\imgui_interface.hpp"

ConVar spt_con_notify_cvar("spt_con_notify",
"0",
Expand Down Expand Up @@ -69,6 +70,8 @@ void ConNotifyFeature::LoadFeature()
return;

InitConcommandBase(spt_con_notify_cvar);
SptImGuiGroup::QoL_ConNotify.RegisterUserCallback(
[]() { SptImGui::CvarCheckbox(spt_con_notify_cvar, "##checkbox"); });
}

// just turn on developer before entering these functions
Expand Down
9 changes: 8 additions & 1 deletion spt/features/demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "..\scripts\srctas_reader.hpp"
#include "..\sptlib-wrapper.hpp"
#include "..\utils\game_detection.hpp"
#include "dbg.h"
#include "visualizations\imgui\imgui_interface.hpp"

DemoStuff spt_demostuff;

Expand Down Expand Up @@ -360,4 +360,11 @@ void DemoStuff::LoadFeature()
{
InitConcommandBase(y_spt_demo_block_cmd);
}

SptImGuiGroup::QoL_Demo.RegisterUserCallback(
[]()
{
SptImGui::CvarCheckbox(y_spt_demo_block_cmd, "##checkbox");
SptImGui::CvarInputTextInteger(y_spt_pause_demo_on_tick, "pause demo on tick", "enter tick value");
});
}
14 changes: 8 additions & 6 deletions spt/features/game_fixes/fastload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "..\feature.hpp"
#include "..\generic.hpp"
#include "signals.hpp"

#include "..\visualizations\imgui\imgui_interface.hpp"

ConVar y_spt_fast_loads(
"y_spt_fast_loads",
Expand Down Expand Up @@ -42,11 +42,13 @@ bool FastLoads::ShouldLoadFeature()

void FastLoads::LoadFeature()
{
if (SetSignonStateSignal.Works)
{
InitConcommandBase(y_spt_fast_loads);
SetSignonStateSignal.Connect(this, &FastLoads::OnLoad);
}
if (!SetSignonStateSignal.Works)
return;
InitConcommandBase(y_spt_fast_loads);
SetSignonStateSignal.Connect(this, &FastLoads::OnLoad);

SptImGuiGroup::QoL_FastLoads.RegisterUserCallback(
[]() { SptImGui::CvarInputTextInteger(y_spt_fast_loads, "fast loads value", "fps_max value"); });
}

void FastLoads::OnLoad(void* thisptr, int state)
Expand Down
6 changes: 4 additions & 2 deletions spt/features/game_fixes/free_oob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
#include "convar.hpp"
#include "..\autojump.hpp"
#include "interfaces.hpp"
#include "..\visualizations\imgui\imgui_interface.hpp"

#ifndef OE
#ifndef OE

static void FreeOOBCVarCallback(IConVar* pConVar, const char* pOldValue, float flOldValue);

Expand Down Expand Up @@ -111,6 +112,8 @@ void FreeOobFeature::LoadFeature()
INIT_BYTE_REPLACE(SecondJump, cur);

InitConcommandBase(y_spt_free_oob);
SptImGuiGroup::Cheats_FreeOob.RegisterUserCallback(
[]() { SptImGui::CvarCheckbox(y_spt_free_oob, "##checkbox"); });
return;
}

Expand Down Expand Up @@ -139,4 +142,3 @@ void FreeOobFeature::Toggle(bool enabled)
}
}
#endif // ! OE

65 changes: 61 additions & 4 deletions spt/features/game_fixes/multi_instance.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
#include "stdafx.hpp"
#ifdef _WIN32

#include "..\feature.hpp"
#include "signals.hpp"
#include "..\visualizations\imgui\imgui_interface.hpp"
#include <Windows.h>

CON_COMMAND(y_spt_release_mutex, "Releases \"hl2_singleton_mutex\" to enable running multiple instances.")
static bool SptReleaseMutexImpl(const char** msg)
{
HANDLE handle = OpenMutexA(SYNCHRONIZE, false, "hl2_singleton_mutex");
if (handle)
{
if (ReleaseMutex(handle))
Msg("Released hl2_singleton_mutex. You can start another instance now.\n");
{
*msg = "Released hl2_singleton_mutex. You can start another instance now.";
return true;
}
else
Warning("Failed to release hl2_singleton_mutex.\n");
{
*msg = "Failed to release hl2_singleton_mutex.";
return false;
}
CloseHandle(handle);
}
else
Warning("Failed to obtain hl2_singleton_mutex handle.\n");
{
*msg = "Failed to obtain hl2_singleton_mutex handle.";
return false;
}
}

CON_COMMAND(y_spt_release_mutex, "Releases \"hl2_singleton_mutex\" to enable running multiple instances.")
{
const char* msg;
if (SptReleaseMutexImpl(&msg))
Msg("%s\n", msg);
else
Warning("%s\n", msg);
}

// spt_release_mutex
class MultiInstance : public FeatureWrapper<MultiInstance>
{
public:
// I don't really understand why, but trying to release the mutex from
// within the ImGui callback doesn't work - do it from FrameSignal instead.
inline static const char* lastMsg = "N/A";
inline static bool lastResult = true;
inline static bool tryRelease = false;

protected:
virtual bool ShouldLoadFeature() override;

Expand All @@ -30,6 +57,9 @@ class MultiInstance : public FeatureWrapper<MultiInstance>
virtual void LoadFeature() override;

virtual void UnloadFeature() override;

private:
void OnFrameSignal();
};

static MultiInstance spt_multi_instance;
Expand All @@ -44,6 +74,33 @@ void MultiInstance::InitHooks() {}
void MultiInstance::LoadFeature()
{
InitCommand(y_spt_release_mutex);

bool imguiEnabled = SptImGuiGroup::QoL_MultiInstance.RegisterUserCallback(
[]()
{
if (ImGui::Button("Release HL2 mutex"))
tryRelease = true;
ImGui::SameLine();
SptImGui::HelpMarker("Help text for %s:\n\n%s",
WrangleLegacyCommandName(y_spt_release_mutex_command.GetName(), true, nullptr),
y_spt_release_mutex_command.GetHelpText());
ImGui::Text("Last result:");
ImGui::SameLine();
if (lastResult)
ImGui::Text("%s", lastMsg);
else
ImGui::TextColored(SPT_IMGUI_WARN_COLOR_YELLOW, "%s", lastMsg);
});

if (imguiEnabled)
FrameSignal.Connect(this, &MultiInstance::OnFrameSignal);
}

void MultiInstance::OnFrameSignal()
{
if (tryRelease)
lastResult = SptReleaseMutexImpl(&lastMsg);
tryRelease = false;
}

void MultiInstance::UnloadFeature() {}
Expand Down
12 changes: 12 additions & 0 deletions spt/features/game_fixes/noclip_fixes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "signals.hpp"
#include "..\autojump.hpp"
#include "SDK\hl_movedata.h"
#include "..\visualizations\imgui\imgui_interface.hpp"

#ifdef OE
static void NoclipNofixCVarCallback(ConVar* pConVar, const char* pOldValue);
Expand Down Expand Up @@ -201,6 +202,17 @@ void NoclipFixesFeature::LoadFeature()
}
}
}

SptImGuiGroup::QoL_Noclip.RegisterUserCallback(
[]()
{
SptImGui::CvarCheckbox(y_spt_noclip_nofix, "##checkbox_nofix");
SptImGui::CvarCheckbox(spt_noclip_noslowfly, "##checkbox_noslowfly");
SptImGui::CvarCheckbox(spt_noclip_persist, "##checkbox_persist");
// whoever decided to put this in a different file deserves stale bread
extern ConVar y_spt_portal_no_ground_snap;
SptImGui::CvarCheckbox(y_spt_portal_no_ground_snap, "##checkbox_no_ground_snap");
});
}

void NoclipFixesFeature::OnTick()
Expand Down
3 changes: 3 additions & 0 deletions spt/features/game_fixes/nosleep.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "stdafx.hpp"
#include "..\feature.hpp"
#include "convar.hpp"
#include "..\visualizations\imgui\imgui_interface.hpp"

ConVar y_spt_focus_nosleep("y_spt_focus_nosleep", "0", 0, "Improves FPS while alt-tabbed.");

Expand Down Expand Up @@ -47,6 +48,8 @@ void NoSleepFeature::LoadFeature()
if (ORIG_CInputSystem__SleepUntilInput)
{
InitConcommandBase(y_spt_focus_nosleep);
SptImGuiGroup::QoL_NoSleep.RegisterUserCallback(
[]() { SptImGui::CvarCheckbox(y_spt_focus_nosleep, "##checkbox"); });
}
}

Expand Down
Loading

0 comments on commit 7b8da01

Please sign in to comment.