Skip to content

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

C++

Keep a game's own steam_api DLL across emulator updates

Leonardo Lobato5840c47ae90e
diff --git a/src/runtime/steamworks.cpp b/src/runtime/steamworks.cpp
index 1810e35..75ec301 100644
--- a/src/runtime/steamworks.cpp
+++ b/src/runtime/steamworks.cpp
@@ -173,6 +173,12 @@ struct Emulator {
std::string sha256;
};
+// Playden's emulator, the current build or a retired one.
+bool IsPlaydenEmulator(const std::string& digest, const std::vector<std::string>& retired) {
+ return digest == kSteamApi32Sha256 || digest == kSteamApi64Sha256 ||
+ std::find(retired.begin(), retired.end(), digest) != retired.end();
+}
+
std::optional<Emulator> LoadEmulator(const std::string& emulator_dir, bool pe64) {
const auto bytes = ReadFile(fs::path(emulator_dir) / (pe64 ? "steam_api64.dll" : "steam_api.dll"), kMaxDllBytes);
if (!bytes) return std::nullopt;
@@ -183,6 +189,11 @@ std::optional<Emulator> LoadEmulator(const std::string& emulator_dir, bool pe64)
} // namespace
+std::vector<std::string> RetiredSteamApiSha256() {
+ return {"4cc9dfcab8b4df0db507fa91d0acec6e58693fd4edd78dc80d39bda8072d08ed", // 2026-10-07, 32-bit
+ "513430ac8b869b0eed258d9e5feba5176a35446b3b61a63d01ab1d87683cdd1b"}; // 2026-10-07, 64-bit
+}
+
std::vector<std::string> FindSteamApi(const std::string& install_root) {
std::vector<std::string> found;
Walk(fs::path(install_root), "", 0, &found);
@@ -233,7 +244,7 @@ std::vector<std::string> SteamInterfaces(std::string_view bytes) {
}
SteamworksResult EmulateSteamworks(const std::string& install_root, const std::string& emulator_dir,
- const SteamworksIdentity& identity) {
+ const SteamworksIdentity& identity, const std::vector<std::string>& retired) {
SteamworksResult result;
const fs::path root(install_root);
result.found = FindSteamApi(install_root);
@@ -252,9 +263,19 @@ SteamworksResult EmulateSteamworks(const std::string& install_root, const std::s
const auto digest = HashArtifactBytes(*current);
if (!digest) return fail("Playden could not check the game's " + relative + ".");
std::string original;
- if (*digest == emulator->sha256) {
+ if (IsPlaydenEmulator(*digest, retired)) {
+ // Playden's own (an earlier build after a Playden update): the game's DLL is the .orig.
const auto kept = IsRegular(orig) ? ReadFile(orig, kMaxDllBytes) : std::nullopt;
if (!kept) return fail("The game's original " + relative + " is missing; verify the download.");
+ // An earlier Playden kept its own emulator as the original. The game's interface versions
+ // are lost with it, and the emulator would hand the game the wrong ones.
+ const auto kept_digest = HashArtifactBytes(*kept);
+ if (!kept_digest || IsPlaydenEmulator(*kept_digest, retired))
+ return fail("An earlier Playden lost the game's own " + relative + "; reinstall the game to get it back.");
+ if (*digest != emulator->sha256) {
+ if (!WriteAtomic(path, emulator->bytes)) return fail("Playden could not set up Steam features for this game.");
+ result.changed.push_back(relative);
+ }
original = *kept;
} else {
if (Architecture(*current) != (pe64 ? "pe64" : "pe32")) continue; // not a Steam API library this name promises
@@ -352,17 +373,21 @@ SteamworksResult RemoveLegacySteam(const std::string& install_root, const std::v
return result;
}
-SteamworksResult RestoreSteamworks(const std::string& install_root) {
+SteamworksResult RestoreSteamworks(const std::string& install_root, const std::vector<std::string>& retired) {
SteamworksResult result;
const fs::path root(install_root);
result.found = FindSteamApi(install_root);
for (const auto& relative : result.found) {
const auto path = root / relative;
- const bool pe64 = Lower(path.filename().string()) == "steam_api64.dll";
const auto current = ReadFile(path, kMaxDllBytes);
const auto digest = current ? HashArtifactBytes(*current) : std::nullopt;
- if (!digest || *digest != (pe64 ? kSteamApi64Sha256 : kSteamApi32Sha256)) continue; // already the game's own
+ if (!digest || !IsPlaydenEmulator(*digest, retired)) continue; // already the game's own
const auto kept = ReadFile(fs::path(path.string() + ".orig"), kMaxDllBytes);
+ const auto kept_digest = kept ? HashArtifactBytes(*kept) : std::nullopt;
+ if (kept_digest && IsPlaydenEmulator(*kept_digest, retired)) {
+ result.message = "An earlier Playden lost the game's own " + relative + "; reinstall the game to get it back.";
+ return result;
+ }
if (!kept || !WriteAtomic(path, *kept)) {
result.message = "Playden could not put back the game's own " + relative + "; verify the download.";
return result;
diff --git a/src/runtime/steamworks.h b/src/runtime/steamworks.h
index 22697e2..9d1119c 100644
--- a/src/runtime/steamworks.h
+++ b/src/runtime/steamworks.h
@@ -15,6 +15,11 @@ namespace playden::runtime {
inline constexpr const char* kSteamApi32Sha256 = "cae4372bceda997d6c73cebc1c14eb27d39b74a7999d8f28384bdfd8d746a79c";
inline constexpr const char* kSteamApi64Sha256 = "70d9826a402d3a78b0c07e9f7ea7c6832468a1113013f31ea570fccaa5445ea9";
+// The emulator builds earlier Playden versions shipped (32-bit, 64-bit). A game they set up
+// still has one as its DLL: it is Playden's, replaced like the current one and never kept as
+// the game's original. Add the outgoing pins here whenever the two above change.
+std::vector<std::string> RetiredSteamApiSha256();
+
// A minimal steam.dll for games from before Steamworks (built from tools/steam-legacy, no imports):
// every call says Steam runs and the game is owned.
inline constexpr const char* kLegacySteamSha256 = "f813075716892ab19ee9b0c06000c328bd5f15e713692384a30ddbcfc9065e57";
@@ -48,13 +53,17 @@ struct SteamworksResult {
std::vector<std::string> FindSteamApi(const std::string& install_root);
// Swaps every found DLL for the emulator and writes its steam_settings/. A DLL that already is
-// the emulator needs its .orig; a DLL that is neither (a newer original from an update)
-// becomes the new .orig. No steam_api DLL: ok with nothing found.
+// the emulator, or an earlier build of it (retired), needs its .orig, which must be the game's
+// own; a DLL that is neither (a newer original from an update) becomes the new .orig. No
+// steam_api DLL: ok with nothing found.
SteamworksResult EmulateSteamworks(const std::string& install_root, const std::string& emulator_dir,
- const SteamworksIdentity& identity);
+ const SteamworksIdentity& identity,
+ const std::vector<std::string>& retired = RetiredSteamApiSha256());
-// Puts each .orig back over a swapped DLL; .orig and steam_settings/ stay.
-SteamworksResult RestoreSteamworks(const std::string& install_root);
+// Puts each .orig back over a swapped DLL (the emulator or a retired build); .orig and
+// steam_settings/ stay.
+SteamworksResult RestoreSteamworks(const std::string& install_root,
+ const std::vector<std::string>& retired = RetiredSteamApiSha256());
// Games from before Steamworks (GUN) load steam.dll from beside their program and quit with "Failed
// to find Steam." without it. For a game with no steam_api DLL, puts the minimal steam.dll
diff --git a/tests/runtime_steamworks_test.cpp b/tests/runtime_steamworks_test.cpp
index ce8b6e8..b7a47da 100644
--- a/tests/runtime_steamworks_test.cpp
+++ b/tests/runtime_steamworks_test.cpp
@@ -1,5 +1,7 @@
#include "runtime/steamworks.h"
+#include "runtime/artifact_hash.h"
+
#include <cstdio>
#include <cstdlib>
#include <filesystem>
@@ -163,6 +165,36 @@ int main(int argc, char** argv) {
CHECK(!ProvideLegacySteam(legacy.string(), fake.string(), programs).ok && !fs::exists(legacy / "steam.dll"));
}
+ { // A Playden update brings a new emulator build; games set up by the earlier one keep their original.
+ const auto game = root / "updated-playden";
+ const auto own = GameDll(false, "own-after-update");
+ const std::string earlier = "an earlier Playden's emulator build";
+ const std::vector<std::string> retired = {*HashArtifactBytes(earlier)};
+ Write(game / "steam_api.dll", earlier);
+ Write(game / "steam_api.dll.orig", own);
+ auto swapped = EmulateSteamworks(game.string(), emulator, identity, retired);
+ CHECK(swapped.ok && (swapped.changed == std::vector<std::string>{"steam_api.dll"}));
+ CHECK(Read(game / "steam_api.dll") == emulator32 && Read(game / "steam_api.dll.orig") == own);
+ CHECK(Read(game / "steam_settings/steam_interfaces.txt") ==
+ "STEAMAPPS_INTERFACE_VERSION008\nSTEAMCONTROLLER_INTERFACE_VERSION\nSteamClient017\nSteamUser021\n");
+ // The game's own mode puts it back from an earlier build too.
+ Write(game / "steam_api.dll", earlier);
+ auto restored = RestoreSteamworks(game.string(), retired);
+ CHECK(restored.ok && Read(game / "steam_api.dll") == own);
+ // An earlier Playden kept its emulator as the original: the game's own is lost, and nothing is
+ // swapped or written over it.
+ Write(game / "steam_api.dll", emulator32);
+ Write(game / "steam_api.dll.orig", earlier);
+ swapped = EmulateSteamworks(game.string(), emulator, identity, retired);
+ CHECK(!swapped.ok && swapped.message.find("reinstall the game") != std::string::npos);
+ CHECK(Read(game / "steam_api.dll.orig") == earlier);
+ restored = RestoreSteamworks(game.string(), retired);
+ CHECK(!restored.ok && restored.message.find("reinstall the game") != std::string::npos);
+ CHECK(Read(game / "steam_api.dll") == emulator32);
+ // The pins Playden ships cover both architectures of every earlier build.
+ CHECK(RetiredSteamApiSha256().size() == 2);
+ }
+
fs::remove_all(root);
fs::remove_all(broken);
std::puts("steamworks tests passed");