Skip to content

Commit 2c4f628

Browse files
ThisAMJmlugg
authored andcommitted
fix: errors on srm fast load preset
1 parent 27fce95 commit 2c4f628

File tree

4 files changed

+49
-37
lines changed

4 files changed

+49
-37
lines changed

src/Cheats.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,41 @@ CON_COMMAND_COMPLETION(sar_fast_load_preset, "set_fast_load_preset <preset> - se
102102

103103
#define CMD(x) engine->ExecuteCommand(x)
104104
if (!strcmp(preset, "none")) {
105-
CMD("ui_loadingscreen_transition_time 1.0");
106-
CMD("ui_loadingscreen_fadein_time 1.0");
107-
CMD("ui_loadingscreen_mintransition_time 0.5");
105+
if (!Game::isSpeedrunMod()) {
106+
CMD("ui_loadingscreen_transition_time 1.0");
107+
CMD("ui_loadingscreen_fadein_time 1.0");
108+
CMD("ui_loadingscreen_mintransition_time 0.5");
109+
}
108110
CMD("sar_disable_progress_bar_update 0");
109111
CMD("sar_prevent_mat_snapshot_recompute 0");
110112
CMD("sar_loads_uncap 0");
111113
CMD("sar_loads_norender 0");
112114
} else if (!strcmp(preset, "sla")) {
113-
CMD("ui_loadingscreen_transition_time 0.0");
114-
CMD("ui_loadingscreen_fadein_time 0.0");
115-
CMD("ui_loadingscreen_mintransition_time 0.0");
115+
if (!Game::isSpeedrunMod()) {
116+
CMD("ui_loadingscreen_transition_time 0.0");
117+
CMD("ui_loadingscreen_fadein_time 0.0");
118+
CMD("ui_loadingscreen_mintransition_time 0.0");
119+
}
116120
CMD("sar_disable_progress_bar_update 1");
117121
CMD("sar_prevent_mat_snapshot_recompute 1");
118122
CMD("sar_loads_uncap 0");
119123
CMD("sar_loads_norender 0");
120124
} else if (!strcmp(preset, "normal")) {
121-
CMD("ui_loadingscreen_transition_time 0.0");
122-
CMD("ui_loadingscreen_fadein_time 0.0");
123-
CMD("ui_loadingscreen_mintransition_time 0.0");
125+
if (!Game::isSpeedrunMod()) {
126+
CMD("ui_loadingscreen_transition_time 0.0");
127+
CMD("ui_loadingscreen_fadein_time 0.0");
128+
CMD("ui_loadingscreen_mintransition_time 0.0");
129+
}
124130
CMD("sar_disable_progress_bar_update 1");
125131
CMD("sar_prevent_mat_snapshot_recompute 1");
126132
CMD("sar_loads_uncap 1");
127133
CMD("sar_loads_norender 0");
128134
} else if (!strcmp(preset, "full")) {
129-
CMD("ui_loadingscreen_transition_time 0.0");
130-
CMD("ui_loadingscreen_fadein_time 0.0");
131-
CMD("ui_loadingscreen_mintransition_time 0.0");
135+
if (!Game::isSpeedrunMod()) {
136+
CMD("ui_loadingscreen_transition_time 0.0");
137+
CMD("ui_loadingscreen_fadein_time 0.0");
138+
CMD("ui_loadingscreen_mintransition_time 0.0");
139+
}
132140
CMD("sar_disable_progress_bar_update 2");
133141
CMD("sar_prevent_mat_snapshot_recompute 1");
134142
CMD("sar_loads_uncap 1");

src/Features/ConfigPlus.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -347,30 +347,6 @@ static void FreeCondition(Condition *c) {
347347
free(c);
348348
}
349349

350-
static bool isSpeedrunMod() {
351-
static bool checked = false;
352-
static bool srm = false;
353-
354-
if (!checked) {
355-
auto serverPlugin = (uintptr_t)(engine->s_ServerPlugin->ThisPtr());
356-
auto count = *(int *)(serverPlugin + 16); // CServerPlugin::m_Size
357-
if (count > 0) {
358-
auto plugins = *(uintptr_t *)(serverPlugin + 4); // CServerPlugin::m_Plugins
359-
for (int i = 0; i < count; ++i) {
360-
auto ptr = *(CPlugin **)(plugins + i * sizeof (uintptr_t));
361-
if (!strcmp(ptr->m_szName, "Speedrun Mod was a mistake.")) {
362-
srm = true;
363-
break;
364-
}
365-
}
366-
}
367-
368-
checked = true;
369-
}
370-
371-
return srm;
372-
}
373-
374350
static const char *gameName() {
375351
switch (sar.game->GetVersion()) {
376352
case SourceGame_ApertureTag:
@@ -382,7 +358,7 @@ static const char *gameName() {
382358
case SourceGame_PortalReloaded:
383359
return "reloaded";
384360
case SourceGame_Portal2:
385-
return isSpeedrunMod() ? "srm" : "portal2";
361+
return Game::isSpeedrunMod() ? "srm" : "portal2";
386362
default:
387363
return "other";
388364
}

src/Game.cpp

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

33
#include "Command.hpp"
4+
#include "Modules/Engine.hpp"
45
#include "Utils.hpp"
56

67
#include <cstring>
@@ -94,3 +95,28 @@ std::string Game::VersionToString(int version) {
9495
}
9596
return games;
9697
}
98+
99+
bool Game::isSpeedrunMod() {
100+
static bool checked = false;
101+
static bool srm = false;
102+
103+
if (!checked) {
104+
auto serverPlugin = (uintptr_t)(engine->s_ServerPlugin->ThisPtr());
105+
auto count = *(int *)(serverPlugin + 16); // CServerPlugin::m_Size
106+
if (count > 0) {
107+
auto plugins = *(uintptr_t *)(serverPlugin + 4); // CServerPlugin::m_Plugins
108+
for (int i = 0; i < count; ++i) {
109+
auto ptr = *(CPlugin **)(plugins + i * sizeof (uintptr_t));
110+
if (!strcmp(ptr->m_szName, "Speedrun Mod was a mistake.")) {
111+
srm = true;
112+
break;
113+
}
114+
}
115+
}
116+
117+
checked = true;
118+
}
119+
120+
return srm;
121+
}
122+

src/Game.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ class Game {
3232

3333
static std::string VersionToString(int version);
3434
static std::vector<std::string> mapNames;
35+
36+
static bool isSpeedrunMod();
3537
};

0 commit comments

Comments
 (0)