Skip to content

Commit 715d283

Browse files
ThisAMJmlugg
authored andcommitted
feat: sar_speedrun_skip_cutscenes
also refactored legacy mtrigger customization into cvars
1 parent 45fa47b commit 715d283

File tree

2 files changed

+29
-40
lines changed

2 files changed

+29
-40
lines changed

src/Features/Speedrun/SpeedrunTimer.cpp

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ static int g_coopLastSyncTick;
152152
// Orange only - the tick we synced, as reported by the engine
153153
static int g_coopLastSyncEngineTick;
154154

155-
static std::string g_chatTextFormat = "!seg -> !tt (!st)";
156-
static Color g_chatTextColor = Color{255, 176, 0};
157-
158155
static void handleCoopPacket(const void *data, size_t size) {
159156
if (!engine->IsOrange()) return;
160157

@@ -203,6 +200,15 @@ ON_EVENT_P(SESSION_START, 1000) {
203200
ON_EVENT_P(SESSION_START, -1000) {
204201
g_inDemoLoad = false;
205202
}
203+
ON_EVENT(SESSION_START) {
204+
if (SpeedrunTimer::IsRunning() && sar_speedrun_skip_cutscenes.GetBool() && sar.game->GetVersion() == SourceGame_Portal2 && !Game::isSpeedrunMod()) {
205+
if (g_speedrun.lastMap == "sp_a2_bts6") {
206+
engine->ExecuteCommand("ent_fire @exit_teleport Teleport; ent_fire @transition_script RunScriptCode TransitionFromMap()", true);
207+
} else if (g_speedrun.lastMap == "sp_a3_00") {
208+
engine->ExecuteCommand("ent_fire bottomless_pit_teleport Teleport; ent_fire @transition_script RunScriptCode TransitionFromMap()", true);
209+
}
210+
}
211+
}
206212

207213
static int getCurrentTick() {
208214
if (engine->IsOrange()) {
@@ -283,6 +289,12 @@ int SpeedrunTimer::GetSegmentTicks() {
283289
int ticks = 0;
284290
ticks += g_speedrun.saved;
285291
if (!g_speedrun.isPaused && !g_speedrun.inCoopPause && (!engine->demoplayer->IsPlaying() || engine->demoplayer->IsPlaybackFixReady())) {
292+
293+
if (sar_speedrun_skip_cutscenes.GetBool() && sar.game->GetVersion() == SourceGame_Portal2 && !Game::isSpeedrunMod()) {
294+
if (g_speedrun.lastMap == "sp_a2_bts6") return 3112;
295+
else if (g_speedrun.lastMap == "sp_a3_00") return 4666;
296+
}
297+
286298
ticks += getCurrentTick() - g_speedrun.base;
287299
}
288300

@@ -448,10 +460,12 @@ void SpeedrunTimer::Start() {
448460
g_speedrun.visitedMaps.push_back(map);
449461

450462
sendCoopPacket(PacketType::START);
451-
if (!sar_mtrigger_legacy.GetBool())
463+
if (!sar_mtrigger_legacy.GetBool()) {
452464
toastHud.AddToast(SPEEDRUN_TOAST_TAG, "Speedrun started!");
453-
else
454-
client->Chat(g_chatTextColor, "Speedrun started!");
465+
} else {
466+
auto color = Utils::GetColor(sar_mtrigger_legacy_textcolor.GetString());
467+
client->Chat(color.value_or(Color{255, 176, 0}), "Speedrun started!");
468+
}
455469

456470
ghostLeaderboard.SpeedrunStart(g_speedrun.saved);
457471
}
@@ -642,13 +656,14 @@ void SpeedrunTimer::Split(bool newSplit, std::string segName, bool requested) {
642656
std::string cleanSegName = segName;
643657
replace(cleanSegName, GetCategoryName() + " - ", "");
644658

645-
std::string formattedString = g_chatTextFormat;
659+
std::string formattedString = sar_mtrigger_legacy_format.GetString();
646660
replace(formattedString, "!map", GetCategoryName());
647661
replace(formattedString, "!seg", cleanSegName);
648662
replace(formattedString, "!tt", SpeedrunTimer::Format(totalTime));
649663
replace(formattedString, "!st", SpeedrunTimer::Format(splitTime));
650664

651-
client->Chat(g_chatTextColor, formattedString.c_str());
665+
auto color = Utils::GetColor(sar_mtrigger_legacy_textcolor.GetString());
666+
client->Chat(color.value_or(Color{255, 176, 0}), formattedString.c_str());
652667
}
653668
}
654669
}
@@ -782,6 +797,7 @@ float SpeedrunTimer::UnFormat(const std::string &formated_time) {
782797

783798
// }}}
784799

800+
Variable sar_speedrun_skip_cutscenes("sar_speedrun_skip_cutscenes", "0", "Skip Tube Ride and Long Fall in Portal 2.\n");
785801
Variable sar_speedrun_smartsplit("sar_speedrun_smartsplit", "1", "Only split the speedrun timer a maximum of once per map.\n");
786802
Variable sar_speedrun_time_pauses("sar_speedrun_time_pauses", "0", "Include time spent paused in the speedrun timer.\n");
787803
Variable sar_speedrun_stop_in_menu("sar_speedrun_stop_in_menu", "0", "Automatically stop the speedrun timer when the menu is loaded.\n");
@@ -790,6 +806,8 @@ Variable sar_speedrun_offset("sar_speedrun_offset", "0", 0, "Start speedruns wit
790806
Variable sar_speedrun_autostop("sar_speedrun_autostop", "0", 0, 2, "Automatically stop recording demos when a speedrun finishes. If 2, automatically append the run time to the demo name.\n");
791807

792808
Variable sar_mtrigger_legacy("sar_mtrigger_legacy", "0", 0, 1, "\n");
809+
Variable sar_mtrigger_legacy_format("sar_mtrigger_legacy_format", "!seg -> !tt (!st)", "Formatting of the text that is displayed in the chat (!map - for map name, !seg - for segment name, !tt - for total time, !st - for split time).\n", 0);
810+
Variable sar_mtrigger_legacy_textcolor("sar_mtrigger_legacy_textcolor", "255 176 0", "The color of the text that is displayed in the chat.\n", 0);
793811

794812
CON_COMMAND(sar_speedrun_start, "sar_speedrun_start - start the speedrun timer\n") {
795813
SpeedrunTimer::Start();
@@ -1064,32 +1082,3 @@ ON_EVENT(PRE_TICK) {
10641082
engine->ExecuteCommand("restart_level");
10651083
}
10661084
}
1067-
1068-
CON_COMMAND(sar_mtrigger_legacy_format, "sar_mtrigger_legacy_format <string format> - formatting of the text that is displayed in the chat (!map - for map name, !seg - for segment name, !tt - for total time, !st - for split time). ( def. \"!seg -> !tt (!st)\" )\n") {
1069-
if (args.ArgC() != 2) {
1070-
console->Print(sar_mtrigger_legacy_format.ThisPtr()->m_pszHelpString);
1071-
return;
1072-
}
1073-
1074-
g_chatTextFormat = args[1];
1075-
}
1076-
1077-
CON_COMMAND(sar_mtrigger_legacy_textcolor, "sar_mtrigger_legacy_textcolor <hex code> - the color of the text that is displayed in the chat.\n") {
1078-
if (args.ArgC() != 2) {
1079-
console->Print(sar_mtrigger_legacy_textcolor.ThisPtr()->m_pszHelpString);
1080-
return;
1081-
}
1082-
1083-
const char *color = args[1];
1084-
if (color[0] == '#') {
1085-
++color;
1086-
}
1087-
1088-
int r, g, b;
1089-
int end;
1090-
if (sscanf(color, "%2x%2x%2x%n", &r, &g, &b, &end) != 3 || end != 6) {
1091-
return console->Print("Invalid color code!\n");
1092-
}
1093-
1094-
g_chatTextColor = Color{(uint8_t)r, (uint8_t)g, (uint8_t)b};
1095-
}

src/Features/Speedrun/SpeedrunTimer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace SpeedrunTimer {
3838
void CategoryChanged();
3939
}; // namespace SpeedrunTimer
4040

41+
extern Variable sar_speedrun_skip_cutscenes;
4142
extern Variable sar_speedrun_smartsplit;
4243
extern Variable sar_speedrun_time_pauses;
4344
extern Variable sar_speedrun_stop_in_menu;
@@ -46,6 +47,8 @@ extern Variable sar_speedrun_offset;
4647
extern Variable sar_speedrun_autostop;
4748

4849
extern Variable sar_mtrigger_legacy;
50+
extern Variable sar_mtrigger_legacy_format;
51+
extern Variable sar_mtrigger_legacy_textcolor;
4952

5053
extern Command sar_speedrun_start;
5154
extern Command sar_speedrun_stop;
@@ -55,6 +58,3 @@ extern Command sar_speedrun_resume;
5558
extern Command sar_speedrun_reset;
5659
extern Command sar_speedrun_result;
5760
extern Command sar_speedrun_export;
58-
59-
extern Command sar_mtrigger_legacy_format;
60-
extern Command sar_mtrigger_legacy_textcolor;

0 commit comments

Comments
 (0)