Skip to content

Commit

Permalink
feat: challenge stats hud duration
Browse files Browse the repository at this point in the history
@PortalRex
defaults to 3 ticks as that seems to work, can increase before pre if it causes issues
  • Loading branch information
ThisAMJ committed Mar 21, 2024
1 parent 218d16f commit 910f920
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/cvars.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
|sar_demo_portal_interp_fix|1|Fix eye interpolation through portals in demo playback.<br>|
|sar_demo_remove_broken|1|Whether to remove broken frames from demo playback<br>|
|sar_demo_replay|cmd|sar_demo_replay - play the last recorded or played demo<br>|
|<i title="Portal 2">sar_disable_challenge_stats_hud</i>|0|Disables opening the challenge mode stats HUD.<br>|
|<i title="Portal 2">sar_disable_challenge_stats_hud</i>|0|Disables opening the challenge mode stats HUD. Greater than 1 specifies a custom amount of ticks to leave leaderboard open.<br>|
|sar_disable_coop_score_hud|0|Disables the coop score HUD which appears in demo playback.<br>|
|sar_disable_no_focus_sleep|0|Does not yield the CPU when game is not focused.<br>|
|sar_disable_progress_bar_update|0|Disables excessive usage of progress bar.<br>|
Expand Down
2 changes: 1 addition & 1 deletion src/Cheats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Variable sar_jumpboost("sar_jumpboost", "0", 0,
"2 = Pre-OBE.\n");
Variable sar_aircontrol("sar_aircontrol", "0", 0, 2, "Enables more air-control on the server.\n");
Variable sar_duckjump("sar_duckjump", "0", "Allows duck-jumping even when fully crouched, similar to prevent_crouch_jump.\n");
Variable sar_disable_challenge_stats_hud("sar_disable_challenge_stats_hud", "0", "Disables opening the challenge mode stats HUD.\n");
Variable sar_disable_challenge_stats_hud("sar_disable_challenge_stats_hud", "0", 0, "Disables opening the challenge mode stats HUD. Greater than 1 specifies a custom amount of ticks to leave leaderboard open.\n");
Variable sar_disable_steam_pause("sar_disable_steam_pause", "0", "Prevents pauses from steam overlay.\n");
Variable sar_disable_no_focus_sleep("sar_disable_no_focus_sleep", "0", "Does not yield the CPU when game is not focused.\n");
Variable sar_disable_progress_bar_update("sar_disable_progress_bar_update", "0", 0, 2, "Disables excessive usage of progress bar.\n");
Expand Down
6 changes: 3 additions & 3 deletions src/Features/Cvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ void Cvars::Unlock() {

Variable("soundfade").AddFlag(FCVAR_CLIENTCMD_CAN_EXECUTE);
Variable("leaderboard_open").AddFlag(FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_SERVER_CAN_EXECUTE);
Variable("gameui_activate").AddFlag(FCVAR_SERVER_CAN_EXECUTE);
Variable("gameui_allowescape").AddFlag(FCVAR_SERVER_CAN_EXECUTE);
Variable("gameui_preventescape").AddFlag(FCVAR_SERVER_CAN_EXECUTE);
Variable("gameui_activate").AddFlag(FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_SERVER_CAN_EXECUTE);
Variable("gameui_allowescape").AddFlag(FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_SERVER_CAN_EXECUTE);
Variable("gameui_preventescape").AddFlag(FCVAR_CLIENTCMD_CAN_EXECUTE | FCVAR_SERVER_CAN_EXECUTE);
Variable("setpause").AddFlag(FCVAR_SERVER_CAN_EXECUTE);
Variable("snd_ducktovolume").AddFlag(FCVAR_SERVER_CAN_EXECUTE);

Expand Down
25 changes: 15 additions & 10 deletions src/Modules/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ Variable sar_patch_minor_angle_decay("sar_patch_minor_angle_decay", "0", "Patche
REDECL(Client::LevelInitPreEntity);
REDECL(Client::CreateMove);
REDECL(Client::CreateMove2);
REDECL(Client::GetName);
REDECL(Client::ShouldDraw_BasicInfo);
REDECL(Client::ShouldDraw_SaveStatus);
REDECL(Client::MsgFunc_SayText2);
Expand All @@ -68,6 +67,7 @@ REDECL(Client::GetButtonBits);
REDECL(Client::ApplyMouse);
REDECL(Client::SteamControllerMove);
REDECL(Client::playvideo_end_level_transition_callback);
REDECL(Client::openleaderboard_callback);
REDECL(Client::OverrideView);
REDECL(Client::ProcessMovement);
REDECL(Client::DrawTranslucentRenderables);
Expand Down Expand Up @@ -261,10 +261,18 @@ DETOUR(Client::CreateMove2, float flInputSampleTime, CUserCmd *cmd) {
return Client::CreateMove2(thisptr, flInputSampleTime, cmd);
}

// CHud::GetName
DETOUR_T(const char *, Client::GetName) {
if (sar_disable_challenge_stats_hud.GetBool()) return "";
return Client::GetName(thisptr);
DETOUR_COMMAND(Client::openleaderboard) {
Client::openleaderboard_callback(args);

if (args.ArgC() == 2 && !strcmp(args[1], "4")) {
if (sar_disable_challenge_stats_hud.GetBool()) {
auto ticks = 3;
if (sar_disable_challenge_stats_hud.GetInt() > 1) ticks = sar_disable_challenge_stats_hud.GetInt();
Scheduler::InHostTicks(ticks, []() {
engine->ExecuteCommand("-leaderboard");
});
}
}
}

// CHudMultiplayerBasicInfo::ShouldDraw
Expand Down Expand Up @@ -687,11 +695,6 @@ bool Client::Init() {
auto cc_leaderboard_enable = (uintptr_t)leaderboard.ThisPtr()->m_pCommandCallback;
auto GetHud = Memory::Read<_GetHud>(cc_leaderboard_enable + Offsets::GetHud);
auto FindElement = Memory::Read<_FindElement>(cc_leaderboard_enable + Offsets::FindElement);
auto CHUDChallengeStats = FindElement(GetHud(-1), "CHUDChallengeStats");

if (this->g_HUDChallengeStats = Interface::Create(CHUDChallengeStats)) {
this->g_HUDChallengeStats->Hook(Client::GetName_Hook, Client::GetName, Offsets::GetName);
}

auto CHUDQuickInfo = FindElement(GetHud(-1), "CHUDQuickInfo");

Expand Down Expand Up @@ -753,6 +756,7 @@ bool Client::Init() {
}

Command::Hook("playvideo_end_level_transition", Client::playvideo_end_level_transition_callback_hook, Client::playvideo_end_level_transition_callback);
Command::Hook("+leaderboard", Client::openleaderboard_callback_hook, Client::openleaderboard_callback);
}

auto HudProcessInput = this->g_ClientDLL->Original(Offsets::HudProcessInput, readJmp);
Expand Down Expand Up @@ -873,6 +877,7 @@ void Client::Shutdown() {
Interface::Delete(this->g_HudSaveStatus);
Interface::Delete(this->g_GameMovement);
Command::Unhook("playvideo_end_level_transition", Client::playvideo_end_level_transition_callback);
Command::Unhook("leaderboard_open", Client::openleaderboard_callback);
}

Client *client;
4 changes: 1 addition & 3 deletions src/Modules/Client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ class Client : public Module {
DECL_DETOUR(CreateMove, float flInputSampleTime, CUserCmd *cmd);
DECL_DETOUR(CreateMove2, float flInputSampleTime, CUserCmd *cmd);

// CHud::GetName
DECL_DETOUR_T(const char *, GetName);

// CHudMultiplayerBasicInfo::ShouldDraw
DECL_DETOUR_T(bool, ShouldDraw_BasicInfo);

Expand Down Expand Up @@ -129,6 +126,7 @@ class Client : public Module {
DECL_DETOUR_T(void, OverrideView, CViewSetup *m_View);

DECL_DETOUR_COMMAND(playvideo_end_level_transition);
DECL_DETOUR_COMMAND(openleaderboard);

#ifdef _WIN32
// C_Paint_Input::ApplyMouse
Expand Down
3 changes: 0 additions & 3 deletions src/OffsetsData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ OFFSET_DEFAULT(ShouldDraw, 11, 12)
// CGlobalEntityList
OFFSET_DEFAULT(OnRemoveEntity, 1, 1)

// CHud
OFFSET_DEFAULT(GetName, 10, 11)

// CGameEventManager
OFFSET_DEFAULT(AddListener, 3, 4)
OFFSET_DEFAULT(RemoveListener, 5, 6)
Expand Down

0 comments on commit 910f920

Please sign in to comment.