Last active
October 9, 2024 20:57
-
-
Save JustinTArthur/099b20df6b3d2a05663a7be3e1bb358d to your computer and use it in GitHub Desktop.
Script that re-entitles the macOS Valheim app to be moddable with runtime code-injection wrappers like BepInEx. For arm64, you'd probably need to still run the app with an x86_64 emulator like Apple Rosetta 2. You may need to run with sudo to re-sign the App Store version in /Applications.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env sh | |
set -e | |
VALHEIM_APP_PATH=${1:-"${HOME}/Library/Application Support/Steam/SteamApps/common/Valheim/valheim.app"} | |
BEPINEX_FRIENDLY_ENTITLEMENTS='<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"><dict><key>com.apple.security.cs.allow-jit</key><true/><key>com.apple.security.cs.disable-library-validation</key><true/><key>com.apple.security.device.bluetooth</key><true/><key>com.apple.security.device.usb</key><true/><key>com.apple.security.network.client</key><true/><key>com.apple.security.network.server</key><true/><key>com.apple.security.cs.allow-dyld-environment-variables</key><true/></dict></plist>' | |
ENTITLEMENTS_PATH='/tmp/revised_valheim_entitlements.plist' | |
main() { | |
read -p " | |
Re-signing and re-entitling Valheim at | |
$VALHEIM_APP_PATH | |
This will remove any Iron Gate or Coffee Stain signatures and replace them with adhoc signatures | |
that no longer identify the developer or publisher. It does this while entitling the app to have | |
runtime code injected for the sake of modding. The changes will be overwritten when you upgrade | |
or reinstall the app. This will likely be fixed in the official version soon anyway and you should | |
probably just wait. | |
Do you want to continue anyway (y/n)? | |
" choice | |
case "$choice" in | |
y|Y|[yY]es ) re_sign_bins_with_dyld_hacks;; | |
n|N ) exit 0;; | |
* ) echo "didn't understand, exiting" && exit;; | |
esac | |
} | |
re_sign_bins_with_dyld_hacks() { | |
echo $BEPINEX_FRIENDLY_ENTITLEMENTS > "${ENTITLEMENTS_PATH}" | |
contents_path="${VALHEIM_APP_PATH}/Contents" | |
for f in "${contents_path}/Frameworks"/*.dylib "${contents_path}/Plugins"/*.dylib "${contents_path}/Plugins"/*.bundle | |
do re_sign_bin "${f}" | |
done | |
re_sign_bin "${contents_path}/MacOS/Valheim" | |
re_sign_bin "${VALHEIM_APP_PATH}" | |
} | |
re_sign_bin() { | |
echo "Re-signing $1" | |
codesign --sign - -vvvv --force --options runtime --entitlements "${ENTITLEMENTS_PATH}" "$1" | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment