Skip to content

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

C++

Stop the MFC walk once it has found what it looks for

Leonardo Lobato59c771a2edf9
diff --git a/src/runtime/game_probe.cpp b/src/runtime/game_probe.cpp
index 408f88a..6c31716 100644
--- a/src/runtime/game_probe.cpp
+++ b/src/runtime/game_probe.cpp
@@ -279,9 +279,19 @@ bool MfcLibrary(const std::string& lower) {
return (lower.rfind("mfc140", 0) == 0 || lower.rfind("mfcm140", 0) == 0) && EndsWith(lower, ".dll");
}
+bool MfcScanDone(const MfcImports& out) {
+ return out.truncated || (!out.x86_program.empty() && !out.x64_program.empty());
+}
+
void ScanMfc(const fs::path& root, const std::string& relative, int depth, MfcImports* out, std::size_t* seen) {
+ if (out->folders >= kMfcScanFolders) {
+ out->truncated = true;
+ return;
+ }
+ ++out->folders;
const auto entries = Entries(relative.empty() ? root : root / relative);
for (const auto& [name, directory] : entries) {
+ if (MfcScanDone(*out)) return;
if (directory) continue;
const auto lower = Lower(name);
if (!EndsWith(lower, ".exe") && !EndsWith(lower, ".dll")) continue;
@@ -300,7 +310,7 @@ void ScanMfc(const fs::path& root, const std::string& relative, int depth, MfcIm
}
if (depth >= kMfcScanDepth) return;
for (const auto& [name, directory] : entries)
- if (directory && !out->truncated) ScanMfc(root, relative.empty() ? name : relative + "/" + name, depth + 1, out, seen);
+ if (directory && !MfcScanDone(*out)) ScanMfc(root, relative.empty() ? name : relative + "/" + name, depth + 1, out, seen);
}
} // namespace
diff --git a/src/runtime/game_probe.h b/src/runtime/game_probe.h
index d5105e2..3a30db2 100644
--- a/src/runtime/game_probe.h
+++ b/src/runtime/game_probe.h
@@ -38,16 +38,19 @@ GameProbe ProbeGame(const std::string& install_root, const std::string& executab
// Which of a game's programs and libraries import Microsoft's MFC library (mfc140*.dll, mfcm140*.dll, directly
// or delay-loaded), which Wine doesn't provide: Playden installs Microsoft's own into the game's bottle. Every
-// .exe and .dll of the game folder is read, kMfcScanDepth folders deep and at most kMfcScanPrograms of them
-// (headers only), without following links. The first program found per architecture, relative to the root.
+// .exe and .dll of the game folder is read, kMfcScanDepth folders deep, at most kMfcScanPrograms of them (headers
+// only) in at most kMfcScanFolders folders, without following links; the walk ends once both architectures are
+// found. The first program found per architecture, relative to the root.
struct MfcImports {
std::string x86_program; // a PE32 one
std::string x64_program; // a PE32+ one
std::size_t programs = 0; // programs read
- bool truncated = false; // stopped at kMfcScanPrograms
+ std::size_t folders = 0; // folders listed
+ bool truncated = false; // stopped at kMfcScanPrograms or kMfcScanFolders
};
inline constexpr int kMfcScanDepth = 6;
inline constexpr std::size_t kMfcScanPrograms = 4096;
+inline constexpr std::size_t kMfcScanFolders = 4096;
MfcImports FindMfcImports(const std::string& install_root);
// How a game without a shipped recipe starts, from its probe.
diff --git a/tests/game_probe_test.cpp b/tests/game_probe_test.cpp
index 038edee..ecf9f30 100644
--- a/tests/game_probe_test.cpp
+++ b/tests/game_probe_test.cpp
@@ -536,6 +536,14 @@ int main() {
CHECK(found.x86_program.empty() && found.x64_program.empty());
WritePe(plain / "a/b/c/d/e/f/Six.dll", {true, {"mfc140.dll"}});
CHECK(FindMfcImports(plain.string()).x64_program == "a/b/c/d/e/f/Six.dll");
+ // Once both are found the walk ends: the folder after them isn't listed.
+ const auto both = fresh();
+ WritePe(both / "A.dll", {true, {"mfc140u.dll"}});
+ WritePe(both / "B.dll", {false, {"mfc140u.dll"}});
+ WritePe(both / "later/C.dll", {true, {"KERNEL32.dll"}});
+ found = FindMfcImports(both.string());
+ CHECK(!found.x86_program.empty() && !found.x64_program.empty() && found.folders == 1 && found.programs == 2);
+ CHECK(!found.truncated);
}
// The player's words for what was found.