Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Drop SteamAppId for non-Steam shortcuts

NotProtonNotcfe01945362d
diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.sh
index ce44478..d1c6703 100755
--- a/dylib/feats/compat_run.sh
+++ b/dylib/feats/compat_run.sh
@@ -237,13 +237,37 @@ case "$app_id" in ''|0) app_id=$(basename "$STEAM_COMPAT_DATA_PATH" 2>/dev/null)
case "$app_id" in ''|*[!0-9]*) app_id=0 ;; esac
echo "app_id=$app_id (STEAM_COMPAT_APP_ID=$STEAM_COMPAT_APP_ID)" >> "$log" 2>&1 || true
+# Steam gives every non-Steam shortcut a game ID ending in 0x02000000.
+shortcut_game_id() {
+ case "$1" in ''|*[!0-9]*) return 1 ;; esac
+ [ "${#1}" -le 20 ] || return 1
+ high=0
+ low="$1"
+ if [ "${#1}" -gt 10 ]; then
+ high="${1%??????????}"
+ low="${1#"$high"}"
+ fi
+ high="${high#"${high%%[!0]*}"}"
+ low="${low#"${low%%[!0]*}"}"
+ [ $(( (${high:-0} % 4294967296 * 1410065408 + ${low:-0}) % 4294967296 )) = 33554432 ]
+}
+
# Steam does not set SteamAppId or SteamGameId for helpers like the install-script
# evaluator. If they are set, SteamAPI_Init registers the helper as the running game so the
# real launch fails with AppError_16. Not applicable to non-Steam shortcuts, which come in
# as waitforexitandrun.
case "$verb" in
waitforexitandrun)
- [ -n "$SteamAppId" ] || export SteamAppId="$app_id"
+ # Some games are poorly engineered and treat a shortcut's SteamAppID as if it were a real
+ # Steam appid. Those games immediately fail Steam ownership checks rather than looking
+ # inward and realizing that the actual game build that is running is a version that was
+ # sold outside of Steam and that the applicable ownership checks should be performed (not
+ # the Steam ones). Rockstar: do better?
+ if shortcut_game_id "$SteamGameId"; then
+ unset SteamAppId
+ else
+ [ -n "$SteamAppId" ] || export SteamAppId="$app_id"
+ fi
[ -n "$SteamGameId" ] || export SteamGameId="$app_id"
;;
esac
diff --git a/dylib/tests/routecheck.sh b/dylib/tests/routecheck.sh
index 0f59f98..5a9713c 100755
--- a/dylib/tests/routecheck.sh
+++ b/dylib/tests/routecheck.sh
@@ -87,6 +87,19 @@ is "a helper is not, or the shim reports it to Steam as a running app" \
unset "$(gameid run)"
is "and neither is runinprefix" unset "$(gameid runinprefix)"
+appid() {
+ env -u SteamAppId -u SteamGameId verb=waitforexitandrun STEAM_COMPAT_APP_ID=0 \
+ SteamAppId="$1" SteamGameId="$2" log=/dev/null ids="$ids" \
+ sh -ec 'eval "$ids"; echo "${SteamAppId-unset} $SteamGameId"'
+}
+is "a shortcut does not pass its ID off as a Steam app" \
+ "unset 11332531184899981312" "$(appid 2638560530 11332531184899981312)"
+is "the largest shortcut ID is still a shortcut" \
+ "unset 18446744069448138752" "$(appid 4294967295 18446744069448138752)"
+is "a Steam app keeps its app ID" "1222670 1222670" "$(appid 1222670 1222670)"
+is "a mod is not a shortcut" "1222670 11332531184884426766" "$(appid 1222670 11332531184884426766)"
+is "a game ID that is not a number is left alone" "7 bogus" "$(appid 7 bogus)"
+
if [ "$fails" -eq 0 ]; then
echo "==> routecheck: all assertions hold"
else