fant0men

Mupen64plus script

Jul 22nd, 2019
162
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # This is a launch script for Mupen64Plus in Linux.
  4. # My ROMs are compressed with 'xz' so when a game is launched this is
  5. # what happens:
  6. #
  7. # 1) Copy Mupen64Plus application directory to RAM disk
  8. # 2) Extract ROM file to RAM disk
  9. # 3) Copy save game file(s) (if any) to RAM disk
  10. # 4) Launch the game
  11.  
  12. save="${HOME}/.local/share/mupen64plus/save"
  13. cfgdir="${HOME}/.config/mupen64plus"
  14. cfg='mupen64plus.cfg'
  15. roms='/home/sir/Documents/ROMs/N64'
  16. app='/home/sir/bin/mupen64plus-bundle-linux64-2.0-ubuntu'
  17. ramdisk="/dev/shm/mupen64plus-${USER}"
  18.  
  19. function run {
  20.  
  21.     cp ${cfgdir}/${1}.cfg ${cfgdir}/${cfg}
  22.  
  23.     basename=$(basename "$game")
  24.     newgame="${ramdisk}/${basename/.xz/.z64}"
  25.     newsave="${ramdisk}/save"
  26.     newapp="${ramdisk}"/$(basename "$app")
  27.  
  28.     # Create the RAM disk and save dir in /dev/shm
  29.     if [[ ! -r $ramdisk ]]; then
  30.         mkdir -p -m0700 "$newsave"
  31.     fi
  32.  
  33.     # Copy the Mupen64Plus application directory to RAM
  34.     echo -e "Copying Mupen64Plus to RAM...\n"
  35.     cp -r "$app" "$newapp"
  36.  
  37.     # Extract the ROM file with 'xz'
  38.     echo -e "Extracting ROM file to RAM...\n"
  39.     xz --decompress --stdout "$game" > "$newgame"
  40.  
  41.     cd "$save"
  42.  
  43.     # Copy save game (if there is one) to RAM in the temp save dir.
  44.     echo -e "Copying save game to RAM...\n"
  45.     ls "${basename/.xz/}".* |
  46.     while read line; do
  47.         cp "$line" "$newsave"
  48.     done
  49.  
  50.     cd "$newapp"
  51.     ./mupen64plus "$newgame"
  52.  
  53.     if [[ $1 != 'original' ]]; then
  54.         cp ${cfgdir}/original.cfg ${cfgdir}/${cfg}
  55.     fi
  56.  
  57.     # Sync the temporary save dir in RAM with the static one.
  58.     echo -e "Syncing save game from RAM...\n"
  59.     rsync -av "$newsave"/ "$save"
  60.  
  61.     # Remove the temporary files from RAM.
  62.     rm -r "$ramdisk"
  63.  
  64.     # Make sure that the pending writes to the hard disk get finished
  65.     sync
  66.  
  67.     break
  68. }
  69.  
  70. cd "$roms"
  71.  
  72. select game in *.xz; do
  73.     case "$game" in
  74.         'GoldenEye 007 (U) [!].xz')
  75.             run goldeneye
  76.         ;;
  77.         'Duke Nukem 64 (U) [!].xz')
  78.             run dukenukem
  79.         ;;
  80.         'Perfect Dark (U) (V1.1) [!].xz')
  81.             run goldeneye
  82.         ;;
  83.         '007 - The World is Not Enough (U) [!].xz')
  84.             run goldeneye
  85.         ;;
  86.         *)
  87.             run original
  88.         ;;
  89.     esac
  90. done
RAW Paste Data