Skip to content

Commit 1d5df76

Browse files
ellzieThisAMJ
andauthored
feat: Check for Pause in challenge mode runs of Wakeup (#340)
* added check for game pausing in map Wakeup * fixed runs without pauses being considered runs with pauses * expose g_leaderboardOpen and g_leaderboardWillClose, make wakeup reject feature work with sar_disable_challenge_stats_hud values that are not -1 * refactor: tiny improvements * fix: use the thing --------- Co-authored-by: AMJ <[email protected]>
1 parent 4d488ab commit 1d5df76

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/Features/AutoSubmit.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "AutoSubmit.hpp"
22

33
#include "../Games/Portal2.hpp"
4+
#include "../Modules/Client.hpp"
45
#include "Cheats.hpp"
56
#include "Command.hpp"
67
#include "Event.hpp"
@@ -29,6 +30,7 @@
2930
#define OLD_API_KEY_FILE "autosubmit_key.txt"
3031

3132
bool AutoSubmit::g_cheated = false;
33+
int AutoSubmit::g_paused = 0;
3234
std::string AutoSubmit::g_partner_name = "";
3335

3436
ON_EVENT(SESSION_START) {
@@ -47,10 +49,12 @@ ON_INIT {
4749

4850
ON_EVENT(SESSION_START) {
4951
AutoSubmit::g_cheated = sv_cheats.GetBool();
52+
AutoSubmit::g_paused = 0;
5053
}
5154

5255
ON_EVENT(PRE_TICK) {
5356
if (sv_cheats.GetBool()) AutoSubmit::g_cheated = true;
57+
if (engine->IsGamePaused() && SpeedrunTimer::IsRunning() && !client->g_leaderboardOpen) AutoSubmit::g_paused++;
5458
}
5559

5660
static std::string g_api_base;
@@ -581,6 +585,13 @@ void AutoSubmit::FinishRun(float final_time, const char *demopath, std::optional
581585
return;
582586
}
583587

588+
int allowedPauses = 0;
589+
if (sar_disable_challenge_stats_hud.GetInt() != -1) allowedPauses = 1;
590+
if (AutoSubmit::g_paused > allowedPauses && engine->GetCurrentMapName() == "sp_a1_wakeup") {
591+
console->Print("Pause detected in Wakeup (pause abuse is not allowed in CM); not autosubmitting\nManually submit this demo if you believe this was a mistake\n");
592+
return;
593+
}
594+
584595
#if defined(SAR_DEV_BUILD)
585596
console->Print("Dev SAR build; not autosubmitting\n");
586597
return;

src/Features/AutoSubmit.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace AutoSubmit {
88
extern bool g_cheated;
9+
extern int g_paused;
910
extern std::string g_partner_name;
1011

1112
void LoadApiKey(bool output_nonexist);

src/Modules/Client.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,16 @@ DETOUR_T(const char *, Client::GetName) {
350350
return Client::GetName(thisptr);
351351
}
352352

353-
static bool g_leaderboardOpen = false;
354-
static bool g_leaderboardWillClose = false;
355353
DETOUR_COMMAND(Client::openleaderboard) {
356354
Client::openleaderboard_callback(args);
357355

358356
if (args.ArgC() == 2 && !strcmp(args[1], "4") && client->GetChallengeStatus() == CMStatus::CHALLENGE) {
359-
g_leaderboardOpen = true;
357+
client->g_leaderboardOpen = true;
360358
auto ticks = 6;
361359
if (sar_disable_challenge_stats_hud.GetInt() > 1) ticks = sar_disable_challenge_stats_hud.GetInt();
362360
Scheduler::InHostTicks(ticks, []() {
363-
if (sar.game->Is(SourceGame_Portal2) && sar_disable_challenge_stats_hud.GetInt() > 0 && (!engine->IsCoop() || engine->IsOrange() || g_leaderboardWillClose)) {
364-
g_leaderboardWillClose = false;
361+
if (sar.game->Is(SourceGame_Portal2) && sar_disable_challenge_stats_hud.GetInt() > 0 && (!engine->IsCoop() || engine->IsOrange() || client->g_leaderboardWillClose)) {
362+
client->g_leaderboardWillClose = false;
365363
engine->ExecuteCommand("-leaderboard");
366364
}
367365
});
@@ -466,7 +464,7 @@ ON_INIT {
466464
NetMessage::RegisterHandler(LEADERBOARD_MESSAGE_TYPE, +[](const void *data, size_t size) {
467465
// TODO: Investigate why this sometimes doesn't work - AMJ 2024-04-25
468466
if (sar_disable_challenge_stats_hud_partner.GetBool()) {
469-
g_leaderboardWillClose = true;
467+
client->g_leaderboardWillClose = true;
470468
engine->ExecuteCommand("-leaderboard");
471469
} });
472470
}
@@ -480,8 +478,8 @@ DETOUR_COMMAND(Client::closeleaderboard) {
480478

481479
Client::closeleaderboard_callback(args);
482480

483-
if (g_leaderboardOpen) {
484-
g_leaderboardOpen = false;
481+
if (client->g_leaderboardOpen) {
482+
client->g_leaderboardOpen = false;
485483
NetMessage::SendMsg(LEADERBOARD_MESSAGE_TYPE, 0, 0);
486484
}
487485
}

src/Modules/Client.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class Client : public Module {
7272
int *nNumSPChapters;
7373
int *nNumMPChapters;
7474

75+
bool g_leaderboardOpen = false;
76+
bool g_leaderboardWillClose = false;
77+
7578
std::string lastLevelName;
7679
void **gamerules;
7780

0 commit comments

Comments
 (0)