Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ rm -rf "$T"
for a in x86_64 arm64; do /usr/bin/python3 -c 'import sys; p=sys.argv[1]; b=open(p,"rb").read(); w=bytes.fromhex("47454d494e49"); n=b.count(w); assert n==1, n; open(p,"wb").write(b.replace(w,w[:3]+b"1"+w[4:]))' "$C/Resources/py/$a/bin/python3.12" || exit 1; done
find "$C/Resources/py" -name '*.pyc' -delete; find "$C/Resources/py" -name __pycache__ -type d -empty -delete
mkdir -p "$C/Resources/bin"; cp "$X/7z/7zz" "$C/Resources/bin/"; cp "$X/7z/License.txt" "$C/Resources/bin/7zz-License.txt"
# 32-bit system libraries older games use without shipping them (msvcr80/90, d3dx9_NN), from Microsoft's redistributables
# (tools/fetch_sys32.sh); a DAISY_SYS that already holds x86/ keeps its own
[ -f "$C/Resources/kit/sys/x86/msvcr80.dll" ] || DAISY_7ZZ="$C/Resources/bin/7zz" "$H/tools/fetch_sys32.sh" "$C/Resources/kit/sys/x86" >/dev/null || { echo "could not fetch the 32-bit system libraries" >&2; exit 1; }
cat > "$C/Info.plist" <<'P'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Expand Down
25 changes: 18 additions & 7 deletions app/convert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
R="$(cd "$(dirname "$0")" && pwd)"; K="$HOME/Library/Application Support/DAISY"; OUT="${DAISY_GAMES:-$HOME/Library/Application Support/DAISY/Games}"
# the app goes where Mac software goes, so Launchpad and Spotlight list it; the program's own files (game data,
# saves it writes, learned shaders) stay in Application Support, named by Contents/Resources/daisy-root
# macOS asks before a program sends to the local network (LAN games: broadcasts are refused with "no route to host"
# until the user allows it); the prompt shows this reason
LNET="Lets the game find and join games on your local network (LAN play)."
APPS="${DAISY_APPS:-/Applications}"; [ -w "$APPS" ] || APPS="$HOME/Applications"
[ -n "$DAISY_TMP" ] && export TMPDIR="$DAISY_TMP/" # the compiler's own temporary files go with the build, not to the system disk
install_app() { # install_app <title> <work folder>: the .app in $1.app moves to $APPS, signed in place
Expand Down Expand Up @@ -218,7 +221,7 @@ if [ -d "$MA/Contents/MacOS" ]; then
/usr/libexec/PlistBuddy -c "Delete :LSRequiresCarbon" "$B/$n.app/Contents/Info.plist" >/dev/null 2>&1
else
cp -R "$MA/Contents/Resources/." "$B/data/" 2>/dev/null
printf '<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleExecutable</key><string>%s</string><key>CFBundleIdentifier</key><string>daisy.%s</string><key>CFBundleName</key><string>%s</string><key>CFBundlePackageType</key><string>APPL</string><key>LSMinimumSystemVersion</key><string>13.0</string><key>NSHighResolutionCapable</key><false/></dict></plist>' "$n" "$n" "$n" > "$B/$n.app/Contents/Info.plist"
printf '<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleExecutable</key><string>%s</string><key>CFBundleIdentifier</key><string>daisy.%s</string><key>CFBundleName</key><string>%s</string><key>CFBundlePackageType</key><string>APPL</string><key>LSMinimumSystemVersion</key><string>13.0</string><key>NSHighResolutionCapable</key><false/><key>NSLocalNetworkUsageDescription</key><string>%s</string></dict></plist>' "$n" "$n" "$n" "$LNET" > "$B/$n.app/Contents/Info.plist"
fi
echo "STAGE Finishing"; echo "PROGRESS 97"
rm -rf "$B/o" "$B/thin" "$B"/lib[0-9]* "$B/build.log" "$W"; [ -d "$D/data" ] && cp -Rn "$D/data/." "$B/data/" 2>/dev/null # files the user added to data are kept
Expand Down Expand Up @@ -249,6 +252,7 @@ fi
# intake says why it stopped (a lone program in Downloads, a DRM-locked program, nothing to unpack); else the general reason
[ $rc = 0 ] && [ -n "$j" ] || { why=$(tail -1 "$W/intake.err" 2>/dev/null); [ -n "$why" ] || why="could not unpack or find the game's program"; echo "FAILED: $why"; exit 1; }
f=$(get folder); exe=$(get exe); bits=$(get bits); top=$(get top); [ -n "$top" ] || top="$f"
largs=$(get args); launcher=$(get launcher) # a launcher's game: the program it runs (exe, maybe in a sub-folder) and its arguments
# A dropped folder is the game's whole folder even when its program sits in a sub-folder (files beside that
# sub-folder belong to the game too); an unpacked archive or installer likewise.
whole="$1"; [ -d "$1" ] || whole="$W/game"; whole=$(cd "$whole" 2>/dev/null && pwd -P); ff=$(cd "$f" 2>/dev/null && pwd -P)
Expand All @@ -268,9 +272,11 @@ fi
t="${DAISY_TITLE:-$in}"; t=$(printf '%s' "$t" | tr -d '/:'); n=$(printf '%s' "$t" | tr -cd 'A-Za-z0-9' | cut -c1-24); [ -n "$n" ] || n=game
case "$t" in ''|.|..|-*|*/*) t="$n";; esac # the folder below is replaced: it must be a plain child of OUT
D="$OUT/$t"; B=$(mktemp -d "${DAISY_TMP:-/tmp}/daisy.XXXXXX") || exit 1
echo "STAGE Rewriting $exe"
[ -n "$launcher" ] && echo "LAUNCHER $launcher runs $exe${largs:+ ($largs)}"
echo "STAGE Rewriting $(basename "$exe")"
# daisy64 prints "@P <stage> <fraction>"; each stage owns a slice of the bar: rewrite 12-50, copy 50-60, compile 60-97
known=$("$PY" -I -B -c 'import json,sys; print(json.load(open(sys.argv[1])).get(sys.argv[2].lower(), ""))' "$K/kit/tools/known.json" "$exe" 2>/dev/null) # start-up settings a known program needs
known=$("$PY" -I -B -c 'import json,sys; print(json.load(open(sys.argv[1])).get(sys.argv[2].lower(), ""))' "$K/kit/tools/known.json" "$(basename "$exe")" 2>/dev/null) # start-up settings a known program needs
[ -n "$known" ] || known="$largs"
# libraries in sub-folders (add-ins the program loads by name: "plugins", Qt "platforms"...) are built in too
plug=""; np=$(find "$top" -mindepth 2 -maxdepth 4 -iname '*.dll' 2>/dev/null | head -400 | wc -l); [ "$np" -gt 0 ] && [ "$np" -lt 400 ] && plug="--plugins"
# Direct3D 12 and the Direct3D 11 stages that go through it (tessellation, geometry shaders): requests a run of the
Expand All @@ -286,14 +292,14 @@ MACOSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET:-13.0} DAISY_HOST=local DAIS
{ print > lf; fflush(lf) }'
else # 32-bit: the program and its libraries are rewritten and linked with the 32-bit runtime; its folder stays whole beside the app
mkdir -p "$B/data" "$B/o32"; echo "STAGE Copying game files"; rsync -a "${f%/}/" "$B/data/" || { echo "FAILED: could not copy the program files"; exit 1; }
echo "PROGRESS 20"; echo "STAGE Rewriting $exe"
MACOSX_DEPLOYMENT_TARGET=13.0 "$PY" -I -B "$K/kit/tools/build.py" "$f" "$B/o32" "$exe" --auto 2>&1 \
echo "PROGRESS 20"; echo "STAGE Rewriting $(basename "$exe")"
MACOSX_DEPLOYMENT_TARGET=13.0 "$PY" -I -B "$K/kit/tools/build.py" "$f" "$B/o32" "$exe" --auto --data "$B/data" ${known:+--args "$known"} 2>&1 \
| /usr/bin/awk -v lf="$B/build.log" '$1 == "@P" { print "PROGRESS " int(($2 == "rewrite" ? 20 : 90) + ($2 == "rewrite" ? 70 : 7) * $3); if ($2 == "compile") print "STAGE Building the Mac app"; fflush(); next }
{ print > lf; fflush(lf) }'
x=$(printf '%s' "${exe%.*}" | tr 'A-Z' 'a-z')
x=$(basename "$exe"); x=$(printf '%s' "${x%.*}" | tr 'A-Z' 'a-z')
if [ -x "$B/o32/$x" ]; then
mkdir -p "$B/$n.app/Contents/MacOS"; cp "$B/o32/$x" "$B/$n.app/Contents/MacOS/$n"
printf '<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleExecutable</key><string>%s</string><key>CFBundleIdentifier</key><string>daisy.%s</string><key>CFBundleName</key><string>%s</string><key>CFBundlePackageType</key><string>APPL</string><key>LSMinimumSystemVersion</key><string>13.0</string><key>NSHighResolutionCapable</key><false/></dict></plist>' "$n" "$n" "$n" > "$B/$n.app/Contents/Info.plist"
printf '<?xml version="1.0"?><plist version="1.0"><dict><key>CFBundleExecutable</key><string>%s</string><key>CFBundleIdentifier</key><string>daisy.%s</string><key>CFBundleName</key><string>%s</string><key>CFBundlePackageType</key><string>APPL</string><key>LSMinimumSystemVersion</key><string>13.0</string><key>NSHighResolutionCapable</key><false/><key>NSLocalNetworkUsageDescription</key><string>%s</string></dict></plist>' "$n" "$n" "$n" "$LNET" > "$B/$n.app/Contents/Info.plist"
mkdir -p "$B/$n.app/Contents/Resources"
fi
rm -rf "$B/o32"
Expand All @@ -304,6 +310,10 @@ cp "$B/build.log" "$K/last-build.log" 2>/dev/null # kept for a failed conversi
# uses for the first time is recorded there, rewritten to Metal source by the tool and compiled by the system, so no
# Metal compiler is needed and nothing has to be learned ahead of time.
mkdir -p "$B/learn/d3d9" "$B/$n.app/Contents/Helpers"; [ -d "$D/learn" ] && cp -R "$D/learn/." "$B/learn/" 2>/dev/null
# Converting again (as after playing, to build the learned shaders ahead) keeps what the player made: profiles, saves
# and settings (the Windows user folders) and the program's registry. The folder below is replaced as a whole.
[ -d "$D/Documents and Settings" ] && cp -Rp "$D/Documents and Settings" "$B/" 2>/dev/null
[ -f "$D/registry.txt" ] && cp -p "$D/registry.txt" "$B/" 2>/dev/null
clang -arch x86_64 -arch arm64 -O1 -w -DDAISY_BUILDER -o "$B/$n.app/Contents/Helpers/shtool" "$K/kit/tools/shtool.c" "$K/kit/runtime/d3d9_shader.c" "$K/kit/runtime/d3d9_ff.c" 2>>"$B/build.log" \
|| { echo "FAILED: could not build the shader tool"; exit 1; }
# Direct3D 11: the same idea. Its shader rewriter is a Python tool, so a program that uses Direct3D 11 also gets the
Expand All @@ -323,6 +333,7 @@ cd "$D" || exit 1
/usr/libexec/PlistBuddy -c "Set :CFBundleName $t" "$t.app/Contents/Info.plist" >/dev/null 2>&1
# the program's own icon, from the .exe's resources; DAISY's only when it has none
ep="$f/$exe"; [ -f "$ep" ] || ep=$(find "$f" -iname "$(basename "$exe")" 2>/dev/null | head -1)
[ -n "$launcher" ] && [ -f "$f/$launcher" ] && ep="$f/$launcher" # a launcher carries the game's icon
"$PY" -I -B "$K/kit/tools/exeicon.py" "$ep" "$t.app/Contents/Resources/AppIcon.icns" 2>>"$D/build-icon.log" || cp "$R/daisy.icns" "$t.app/Contents/Resources/AppIcon.icns" 2>/dev/null
[ -f "$t.app/Contents/Resources/AppIcon.icns" ] && /usr/libexec/PlistBuddy -c 'Add :CFBundleIconFile string AppIcon' "$t.app/Contents/Info.plist" >/dev/null 2>&1
strip -S "$t.app/Contents/MacOS/"* 2>/dev/null; install_app "$t" "$D"
Loading