Skip to content

Play your Steam library's Windows games on a jailbroken PS5.

C++

Don't pick a dedicated server as the game's program

Leonardo Lobato05a6916dea6b
diff --git a/src/runtime/game_settings.cpp b/src/runtime/game_settings.cpp
index 97aeb4d..21ca34f 100644
--- a/src/runtime/game_settings.cpp
+++ b/src/runtime/game_settings.cpp
@@ -1829,20 +1829,22 @@ bool DrawsGraphics(const std::string& summary) {
}
// The game program to start instead of a launcher: one that draws and the console may run,
-// in the launcher's folder or below it first, then the largest.
+// in the launcher's folder or below it first, then the largest. A dedicated server or relay comes
+// last (Cry of Fear ships hlds.exe and hltv.exe beside cof.exe).
std::optional<std::string> GameInsteadOf(const std::string& install_root, const std::string& launcher,
const KitCapabilities& kit) {
const auto slash = launcher.rfind('/');
const auto folder = slash == std::string::npos ? std::string() : LowerAscii(launcher.substr(0, slash + 1));
std::optional<std::string> best;
- std::pair<bool, std::uintmax_t> best_rank{false, 0};
+ std::tuple<bool, bool, std::uintmax_t> best_rank{false, false, 0};
for (const auto& program : ListGamePrograms(install_root, kit)) {
if (program.architecture.empty() || !program.refusal.empty() || !DrawsGraphics(program.detected) ||
program.path == launcher || StartsTheGameOnly(program.path, GameProbe{}))
continue;
std::error_code error;
const auto size = std::filesystem::file_size(std::filesystem::path(install_root) / program.path, error);
- const std::pair<bool, std::uintmax_t> rank{LowerAscii(program.path).rfind(folder, 0) == 0, error ? 0 : size};
+ const std::tuple<bool, bool, std::uintmax_t> rank{!steam::IsDedicatedServerProgram(program.path),
+ LowerAscii(program.path).rfind(folder, 0) == 0, error ? 0 : size};
if (!best || rank > best_rank) best = program.path, best_rank = rank;
}
return best;
diff --git a/src/steam/backend/app_info.cpp b/src/steam/backend/app_info.cpp
index 31fd347..db61672 100644
--- a/src/steam/backend/app_info.cpp
+++ b/src/steam/backend/app_info.cpp
@@ -714,6 +714,34 @@ bool BetaKeyMatchesBranch(std::string_view beta_key, std::string_view branch) {
bool BetaKeyMatchesPublic(std::string_view beta_key) { return BetaKeyMatchesBranch(beta_key, "public"); }
+bool IsDedicatedServerProgram(std::string_view executable) {
+ const auto slash = executable.find_last_of("/\\");
+ if (slash != std::string_view::npos) executable.remove_prefix(slash + 1);
+ if (executable.size() > 4 && LowerString(executable.substr(executable.size() - 4)) == ".exe")
+ executable.remove_suffix(4);
+ // Words split at punctuation, digits and case changes: GameServer, HLServer, game_server_x64.
+ const auto upper = [&](std::size_t i) { return i < executable.size() && executable[i] >= 'A' && executable[i] <= 'Z'; };
+ const auto lower = [&](std::size_t i) { return i < executable.size() && executable[i] >= 'a' && executable[i] <= 'z'; };
+ std::vector<std::string> words;
+ std::string word;
+ for (std::size_t i = 0; i <= executable.size(); ++i) {
+ const char c = i < executable.size() ? executable[i] : '\0';
+ const bool letter = upper(i) || lower(i);
+ const bool word_start = upper(i) && i > 0 && (lower(i - 1) || (upper(i - 1) && lower(i + 1)));
+ if (!letter || word_start) {
+ if (!word.empty()) words.push_back(std::move(word));
+ word.clear();
+ }
+ if (letter) word.push_back(Lower(c));
+ }
+ if (words.empty()) return false;
+ // GoldSrc and Source servers and the HLTV relay (Cry of Fear lists hlds.exe and hltv.exe).
+ if (words.front() == "hlds" || words.front() == "hltv" || words.front() == "srcds") return true;
+ for (const std::string& part : words)
+ if (part == "server" || part.find("dedicated") != std::string::npos) return true;
+ return false;
+}
+
bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_apps, std::string_view branch,
std::vector<AppLaunch>* launches, std::string* reason, bool* any_branch) {
const auto eligible_for = [&](bool ignore_branch) {
@@ -735,6 +763,14 @@ bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_a
const bool fallback = eligible.empty();
if (fallback) eligible = eligible_for(true);
if (any_branch != nullptr) *any_branch = fallback && !eligible.empty();
+ // A dedicated server listed without the "server" type is not the game either, unless it is all
+ // Steam lists.
+ const auto server = [](const AppLaunch& launch) {
+ return IsDedicatedServerProgram(launch.executable) ||
+ (launch.description && LowerString(*launch.description).find("dedicated server") != std::string::npos);
+ };
+ if (std::any_of(eligible.begin(), eligible.end(), [&](const AppLaunch& launch) { return !server(launch); }))
+ eligible.erase(std::remove_if(eligible.begin(), eligible.end(), server), eligible.end());
std::set<std::string> ids;
for (const AppLaunch& launch : eligible) ids.insert(launch.id);
if (eligible.empty() || ids.size() != eligible.size()) {
diff --git a/src/steam/backend/app_info.h b/src/steam/backend/app_info.h
index 8fd7793..8152384 100644
--- a/src/steam/backend/app_info.h
+++ b/src/steam/backend/app_info.h
@@ -203,8 +203,13 @@ bool BetaKeyMatchesPublic(std::string_view beta_key);
// (case-insensitively); for the public branch also "public" or "default".
bool BetaKeyMatchesBranch(std::string_view beta_key, std::string_view branch);
+// A dedicated server or relay, by its file name: hlds.exe, hltv.exe, srcds.exe, or a name with the
+// word "server" or "dedicated" (DedicatedServer.exe, game_server.exe; not Observer.exe).
+bool IsDedicatedServerProgram(std::string_view executable);
+
// Windows launch entries usable on `branch` (empty: public), default type first, then by id. When no
-// entry is for that branch, every branch's entries; `any_branch` then says so.
+// entry is for that branch, every branch's entries; `any_branch` then says so. A dedicated server is
+// left out while another entry remains.
bool EligibleLaunches(const AppInfo& app, const std::set<std::uint32_t>& owned_apps, std::string_view branch,
std::vector<AppLaunch>* launches, std::string* reason, bool* any_branch = nullptr);
diff --git a/tests/game_probe_test.cpp b/tests/game_probe_test.cpp
index a22a22b..0e6cb37 100644
--- a/tests/game_probe_test.cpp
+++ b/tests/game_probe_test.cpp
@@ -693,6 +693,23 @@ int main() {
CHECK(GenerateGameRecipe(219890, "Antichamber", {{"", "", "Binaries/Windows/UE3Redist.exe", "", ""}}, udk.string(), &recipe, &reason));
CHECK(recipe.launch_entries[0].executable == "Binaries/Win32/UDK.exe");
}
+ { // Never a dedicated server or relay, even the largest (Cry of Fear lists only CoFLaunchApp.exe, #318).
+ const auto cof = fresh();
+ WritePe(cof / "CoFLaunchApp.exe", {false, {"KERNEL32.dll", "USER32.dll"}});
+ WritePe(cof / "cof.exe", {false, {"KERNEL32.dll", "DDRAW.dll"}, false, false, "opengl32.dll"});
+ WritePe(cof / "hlds.exe", {false, {"KERNEL32.dll", "DDRAW.dll"}, false, false, "opengl32.dll", 0x40000});
+ WritePe(cof / "hltv.exe", {false, {"KERNEL32.dll", "DDRAW.dll"}, false, false, "opengl32.dll", 0x30000});
+ CHECK(GenerateGameRecipe(223710, "Cry of Fear", {{"", "Launch with Console", "CoFLaunchApp.exe", "", ""}},
+ cof.string(), &recipe, &reason));
+ CHECK(recipe.launch_entries.size() == 2 && recipe.launch_entries[0].executable == "cof.exe" &&
+ recipe.launch_entries[0].id == "game" && recipe.launch_entries[1].executable == "CoFLaunchApp.exe");
+ // A server name only ranks last: a game whose own program is named like one is still found.
+ const auto side = fresh();
+ WritePe(side / "Launcher.exe", {false, {"KERNEL32.dll", "USER32.dll"}});
+ WritePe(side / "ServerSide.exe", {false, {"KERNEL32.dll", "d3d9.dll"}});
+ CHECK(GenerateGameRecipe(1, "Server Side", {{"", "", "Launcher.exe", "", ""}}, side.string(), &recipe, &reason));
+ CHECK(recipe.launch_entries.size() == 2 && recipe.launch_entries[0].executable == "ServerSide.exe");
+ }
// A program that draws, or the player's choice, is started as listed.
CHECK(GenerateGameRecipe(1, "Game", {{"", "", "Tools/Viewer.exe", "", ""}}, root.string(), &recipe, &reason));
CHECK(recipe.launch_entries.size() == 1 && recipe.launch_entries[0].executable == "Tools/Viewer.exe");
diff --git a/tests/steam_app_info_test.cpp b/tests/steam_app_info_test.cpp
index 93d2b87..d20d70d 100644
--- a/tests/steam_app_info_test.cpp
+++ b/tests/steam_app_info_test.cpp
@@ -785,6 +785,22 @@ void TestEligibleLaunches() {
CHECK(EligibleLaunches(with_editor, {kApp, 999}, "", &launches, &reason));
CHECK((LaunchIds(launches) == Strings{"10"}));
+ // An untyped dedicated server or relay is left out while the game is listed too (#318), never when it's all there is.
+ for (const char* name : {"hlds.exe", "HLTV.EXE", "bin\\srcds_win64.exe", "DedicatedServer.exe", "Game_Server.exe",
+ "MyGameServer.exe", "HLServer.exe", "server.exe"})
+ CHECK(IsDedicatedServerProgram(name));
+ for (const char* name : {"cof.exe", "hl.exe", "Observer.exe", "hl2.exe", "Serverless Quest.exe", "", ".exe"})
+ CHECK(!IsDedicatedServerProgram(name));
+ AppInfo servers = *app;
+ servers.launches[0].executable = "hlds.exe";
+ servers.launches[1].executable = "hltv.exe";
+ servers.launches[3].description = "Start a Dedicated Server";
+ CHECK(EligibleLaunches(servers, {kApp, 999}, "", &launches, &reason));
+ CHECK((LaunchIds(launches) == Strings{"10"}));
+ servers.launches.resize(1);
+ CHECK(EligibleLaunches(servers, {kApp}, "", &launches, &reason));
+ CHECK((LaunchIds(launches) == Strings{"0"}) && launches[0].executable == "hlds.exe");
+
// Steam's betakey is a comma list of branches.
AppInfo listed = *app;
listed.launches[2].beta_key = "build_debug, Public ,latest\t";