Setting environment variables and injecting libraries using Steam launch options on Mac

A working launch options example from me messing around with RED4ext on Cyberpunk for Mac:

/bin/sh -c "open --env DYLD_INSERT_LIBRARIES=\"$STEAM_DYLD_INSERT_LIBRARIES:@executable_path/../../../red4ext/RED4ext.dylib:@executable_path/../../../red4ext/FridaGadget.dylib\" --env DYLD_FORCE_FLAT_NAMESPACE=1 -nW %command% --args -fullscreen"

Which is roughly equivalent to what you would expect from writing: DYLD_INSERT_LIBRARIES=red4ext/RED4ext.dylib:red4ext/FridaGadget.dylib %command% -fullscreen (which definitely does not work)

Here's a breakdown of all the incantations:

  • The first argument has to be a full path to an executable, so we use /bin/sh and pass everything else as one big string with -c
  • %command% is automatically enclosed in single quotes ('), so the string we pass to -c has to be in double quotes ("), and any double quotes inside it have to be escaped (\")
  • %command% refers to the .app bundle, not an executable, so we have to open it with open rather than running it directly
  • open passes through any environment variables, but the DYLD_ ones are special, so we have to set them with --env (or else they would inject libraries into the open command rather than the game itself)
  • Steam has its own libraries to inject, so we have to include $STEAM_DYLD_INSERT_LIBRARIES (otherwise it breaks the Steam overlay and maybe other stuff too)
  • @executable_path refers to the executable path inside the app bundle (in my case, Cyberpunk2077.app/Contents/MacOS/), so we need that little ../../../ dance to get back up to the game directory. You could also just use absolute paths if you want.
  • I'm not sure if the -nW is actually necessary, but it makes open always launch a new instance of the app and wait until it exits, which I think is probably what Steam expects
  • Anything after --args gets passed to the game directly, ie -fullscreen is a command-line argument to the game itself
添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论