#!/usr/bin/env python3 """macOS: Dock / Cmd-Tab / menu bar show the game as "wine" (the loader's file name). This makes a copy of Wine's loader lib/wine/x86_64-unix/wine named "OldEraMT2" whose embedded __TEXT,__info_plist names the app "OldEraMT2" (bundle id com.olderamt2.client.game). oldera-wine.sh starts the game through this copy when it exists; Wine's helper processes keep using "wine". Only the embedded plist text changes (same byte length, padded with XML whitespace); the copy is re-signed by build-macos.sh. Modification of an LGPL binary: noted in THIRD-PARTY-NOTICES. usage: make-game-loader.py WINE_DIR""" import struct, sys, pathlib MH_MAGIC_64, LC_SEGMENT_64 = 0xfeedfacf, 0x19 def info_plist_range(b): magic, _, _, _, ncmds, _, _, _ = struct.unpack_from('wine', b'OldEraMT2') .replace(b'org.winehq.wine', b'com.olderamt2.client.game') .replace(b'Wine', b'OldEraMT2')) assert new.count(b'OldEraMT2') == 2 and b'olderamt2.client.game' in new, 'unexpected plist' new = b'\n'.join(line.strip() for line in new.split(b'\n')) # drop indentation to keep the size assert len(new) <= size, (len(new), size) b[off:off + size] = new + b'\n' * (size - len(new) - 1) + b'\0' if len(new) < size else new dst.write_bytes(bytes(b)); dst.chmod(0o755) print('%s: plist %d/%d bytes' % (dst, len(new), size)) if __name__ == '__main__': main(sys.argv[1])