Advertisement
Guest User

Retroarch.sh

a guest
May 26th, 2024
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.56 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. # This file is part of The RetroPie Project
  4. #
  5. # The RetroPie Project is the legal property of its developers, whose names are
  6. # too numerous to list here. Please refer to the COPYRIGHT.md file distributed with this source.
  7. #
  8. # See the LICENSE.md file at the top-level directory of this distribution and
  9. # at https://raw.githubusercontent.com/RetroPie/RetroPie-Setup/master/LICENSE.md
  10. #
  11.  
  12. rp_module_id="retroarch"
  13. rp_module_desc="RetroArch - frontend to the libretro emulator cores - required by all lr-* emulators"
  14. rp_module_licence="GPL3 https://raw.githubusercontent.com/libretro/RetroArch/master/COPYING"
  15. rp_module_repo="git https://github.com/retropie/RetroArch.git retropie-v1.18.0"
  16. rp_module_section="core"
  17.  
  18. function depends_retroarch() {
  19. local depends=(libudev-dev libxkbcommon-dev libsdl2-dev libasound2-dev libusb-1.0-0-dev)
  20. isPlatform "rpi" && depends+=(libraspberrypi-dev)
  21. isPlatform "gles" && ! isPlatform "vero4k" && depends+=(libgles2-mesa-dev)
  22. isPlatform "mesa" && depends+=(libx11-xcb-dev)
  23. isPlatform "mali" && depends+=(mali-fbdev)
  24. isPlatform "x11" && depends+=(libx11-xcb-dev libpulse-dev)
  25. isPlatform "vulkan" && depends+=(libvulkan-dev mesa-vulkan-drivers)
  26. isPlatform "vero4k" && depends+=(vero3-userland-dev-osmc zlib1g-dev libfreetype6-dev)
  27. isPlatform "kms" && depends+=(libgbm-dev)
  28.  
  29. if [[ "$__os_debian_ver" -ge 9 ]]; then
  30. depends+=(libavcodec-dev libavformat-dev libavdevice-dev)
  31. fi
  32.  
  33. getDepends "${depends[@]}"
  34. }
  35.  
  36. function sources_retroarch() {
  37. gitPullOrClone
  38. }
  39.  
  40. function build_retroarch() {
  41. local params=(--disable-sdl --enable-sdl2 --disable-oss --disable-al --disable-jack --disable-qt)
  42. if ! isPlatform "x11"; then
  43. params+=(--disable-pulse)
  44. ! isPlatform "mesa" && params+=(--disable-x11)
  45. fi
  46. if [[ "$__os_debian_ver" -lt 9 ]]; then
  47. params+=(--disable-ffmpeg)
  48. fi
  49. isPlatform "gles" && params+=(--enable-opengles)
  50. if isPlatform "gles3"; then
  51. params+=(--enable-opengles3)
  52. isPlatform "gles31" && params+=(--enable-opengles3_1)
  53. isPlatform "gles32" && params+=(--enable-opengles3_2)
  54. fi
  55. isPlatform "videocore" && params+=(--disable-crtswitchres)
  56. isPlatform "rpi" && isPlatform "mesa" && params+=(--disable-videocore)
  57. # Temporarily block dispmanx support for fkms until upstream support is fixed
  58. isPlatform "dispmanx" && ! isPlatform "kms" && params+=(--enable-dispmanx --disable-opengl1)
  59. isPlatform "mali" && params+=(--enable-mali_fbdev)
  60. isPlatform "kms" && params+=(--enable-kms --enable-egl)
  61. isPlatform "arm" && params+=(--enable-floathard)
  62. isPlatform "neon" && params+=(--enable-neon)
  63. isPlatform "vulkan" && params+=(--enable-vulkan)
  64. ! isPlatform "x11" && params+=(--disable-wayland)
  65. isPlatform "vero4k" && params+=(--enable-mali_fbdev --with-opengles_libs='-L/opt/vero3/lib')
  66. ./configure --prefix="$md_inst" "${params[@]}"
  67. make clean
  68. make
  69. md_ret_require="$md_build/retroarch"
  70. }
  71.  
  72. function install_retroarch() {
  73. make install
  74. md_ret_files=(
  75. 'retroarch.cfg'
  76. )
  77. }
  78.  
  79. function update_shaders_retroarch() {
  80. local dir="$configdir/all/retroarch/shaders"
  81. local branch=""
  82. isPlatform "rpi" && branch="rpi"
  83. # remove if not git repository for fresh checkout
  84. [[ ! -d "$dir/.git" ]] && rm -rf "$dir"
  85. gitPullOrClone "$dir" https://github.com/RetroPie/common-shaders.git "$branch"
  86. chown -R $user:$user "$dir"
  87. }
  88.  
  89. function update_overlays_retroarch() {
  90. local dir="$configdir/all/retroarch/overlay"
  91. # remove if not a git repository for fresh checkout
  92. [[ ! -d "$dir/.git" ]] && rm -rf "$dir"
  93. gitPullOrClone "$dir" https://github.com/libretro/common-overlays.git
  94. chown -R $user:$user "$dir"
  95. }
  96.  
  97. function update_joypad_autoconfigs_retroarch() {
  98. gitPullOrClone "$md_build/autoconfigs" https://github.com/libretro/retroarch-joypad-autoconfig.git
  99. cp -a "$md_build/autoconfigs/." "$md_inst/autoconfig-presets/"
  100. }
  101.  
  102. function update_assets_retroarch() {
  103. local dir="$configdir/all/retroarch/assets"
  104. # remove if not a git repository for fresh checkout
  105. [[ ! -d "$dir/.git" ]] && rm -rf "$dir"
  106. gitPullOrClone "$dir" https://github.com/libretro/retroarch-assets.git
  107. chown -R $user:$user "$dir"
  108. }
  109.  
  110. function update_core_info_retroarch() {
  111. local dir="$configdir/all/retroarch/cores"
  112. # remove if not a git repository and do a fresh checkout
  113. [[ ! -d "$dir/.git" ]] && rm -fr "$dir"
  114. # remove our locally generated `.info` files, just in case upstream adds them
  115. [[ -d "$dir/.git" ]] && git -C "$dir" clean -q -f "*.info"
  116. gitPullOrClone "$dir" https://github.com/libretro/libretro-core-info.git
  117. # add our info files for cores not included in the upstream repo
  118. cp --update "$md_data"/*.info "$dir"
  119. chown -R $user:$user "$dir"
  120. }
  121.  
  122. function install_minimal_assets_retroarch() {
  123. local dir="$configdir/all/retroarch/assets"
  124. [[ -d "$dir/.git" ]] && return
  125. [[ ! -d "$dir" ]] && mkUserDir "$dir"
  126. downloadAndExtract "$__binary_base_url/retroarch-minimal-assets.tar.gz" "$dir"
  127. chown -R $user:$user "$dir"
  128. }
  129.  
  130. function _package_minimal_assets_retroarch() {
  131. gitPullOrClone "$md_build/assets" https://github.com/libretro/retroarch-assets.git
  132. mkdir -p "$__tmpdir/archives"
  133. local archive="$__tmpdir/archives/retroarch-minimal-assets.tar.gz"
  134. rm -f "$archive"
  135. tar cvzf "$archive" -C "$md_build/assets" ozone menu_widgets xmb/monochrome
  136. }
  137.  
  138. function configure_retroarch() {
  139. [[ "$md_mode" == "remove" ]] && return
  140.  
  141. addUdevInputRules
  142.  
  143. # move / symlink the retroarch configuration
  144. moveConfigDir "$home/.config/retroarch" "$configdir/all/retroarch"
  145.  
  146. # move / symlink our old retroarch-joypads folder
  147. moveConfigDir "$configdir/all/retroarch-joypads" "$configdir/all/retroarch/autoconfig"
  148.  
  149. # move / symlink old assets / overlays and shader folder
  150. moveConfigDir "$md_inst/assets" "$configdir/all/retroarch/assets"
  151. moveConfigDir "$md_inst/overlays" "$configdir/all/retroarch/overlay"
  152. moveConfigDir "$md_inst/shader" "$configdir/all/retroarch/shaders"
  153.  
  154. # install shaders by default
  155. update_shaders_retroarch
  156.  
  157. # install minimal assets
  158. install_minimal_assets_retroarch
  159.  
  160. # install core info files
  161. update_core_info_retroarch
  162.  
  163. # install joypad autoconfig presets
  164. update_joypad_autoconfigs_retroarch
  165.  
  166. local config="$(mktemp)"
  167.  
  168. cp "$md_inst/retroarch.cfg" "$config"
  169.  
  170. # query ES A/B key swap configuration
  171. local es_swap="false"
  172. getAutoConf "es_swap_a_b" && es_swap="true"
  173.  
  174. # configure default options
  175. iniConfig " = " '"' "$config"
  176. iniSet "cache_directory" "/tmp/retroarch"
  177. iniSet "system_directory" "$biosdir"
  178. iniSet "config_save_on_exit" "false"
  179. iniSet "video_aspect_ratio_auto" "true"
  180. if ! isPlatform "x86"; then
  181. iniSet "video_threaded" "true"
  182. fi
  183.  
  184. iniSet "video_font_size" "24"
  185. iniSet "core_options_path" "$configdir/all/retroarch-core-options.cfg"
  186. iniSet "global_core_options" "true"
  187. isPlatform "x11" && iniSet "video_fullscreen" "true"
  188. isPlatform "mesa" && iniSet "video_fullscreen" "true"
  189.  
  190. # set default render resolution to 640x480 for rpi1
  191. if isPlatform "videocore" && isPlatform "rpi1"; then
  192. iniSet "video_fullscreen_x" "640"
  193. iniSet "video_fullscreen_y" "480"
  194. fi
  195.  
  196. # enable hotkey ("select" button)
  197. iniSet "input_enable_hotkey" "nul"
  198. iniSet "input_exit_emulator" "escape"
  199.  
  200. # enable and configure rewind feature
  201. iniSet "rewind_enable" "false"
  202. iniSet "rewind_buffer_size" "10"
  203. iniSet "rewind_granularity" "2"
  204. iniSet "input_rewind" "r"
  205.  
  206. # enable gpu screenshots
  207. iniSet "video_gpu_screenshot" "true"
  208.  
  209. # enable and configure shaders
  210. iniSet "input_shader_next" "m"
  211. iniSet "input_shader_prev" "n"
  212.  
  213. # configure keyboard mappings
  214. iniSet "input_player1_a" "x"
  215. iniSet "input_player1_b" "z"
  216. iniSet "input_player1_y" "a"
  217. iniSet "input_player1_x" "s"
  218. iniSet "input_player1_start" "enter"
  219. iniSet "input_player1_select" "rshift"
  220. iniSet "input_player1_l" "q"
  221. iniSet "input_player1_r" "w"
  222. iniSet "input_player1_left" "left"
  223. iniSet "input_player1_right" "right"
  224. iniSet "input_player1_up" "up"
  225. iniSet "input_player1_down" "down"
  226.  
  227. # input settings
  228. iniSet "input_autodetect_enable" "true"
  229. iniSet "auto_remaps_enable" "true"
  230. iniSet "input_joypad_driver" "udev"
  231. iniSet "all_users_control_menu" "true"
  232. iniSet "remap_save_on_exit" "false"
  233.  
  234. # rgui by default
  235. iniSet "menu_driver" "rgui"
  236. iniSet "rgui_aspect_ratio_lock" "2"
  237. iniSet "rgui_browser_directory" "$romdir"
  238. iniSet "rgui_switch_icons" "false"
  239. iniSet "menu_rgui_shadows" "true"
  240. iniSet "rgui_menu_color_theme" "29" # Tango Dark theme
  241.  
  242. # hide online updater menu options and the restart option
  243. iniSet "menu_show_core_updater" "false"
  244. iniSet "menu_show_online_updater" "false"
  245. iniSet "menu_show_restart_retroarch" "false"
  246. # disable the search action
  247. iniSet "menu_disable_search_button" "true"
  248.  
  249. # remove some rarely used entries from the quick menu
  250. iniSet "quick_menu_show_close_content" "false"
  251. iniSet "quick_menu_show_add_to_favorites" "false"
  252. iniSet "quick_menu_show_replay" "false"
  253. iniSet "quick_menu_show_start_recording" "false"
  254. iniSet "quick_menu_show_start_streaming" "false"
  255. iniSet "menu_show_overlays" "false"
  256.  
  257. # disable the load notification message with core and game info
  258. iniSet "menu_show_load_content_animation" "false"
  259. # disable core cache file
  260. iniSet "core_info_cache_enable" "false"
  261. # disable game runtime logging
  262. iniSet "content_runtime_log" "false"
  263.  
  264. # disable unnecessary xmb menu tabs
  265. iniSet "xmb_show_add" "false"
  266. iniSet "xmb_show_history" "false"
  267. iniSet "xmb_show_images" "false"
  268. iniSet "xmb_show_music" "false"
  269.  
  270. # disable xmb menu driver icon shadows
  271. iniSet "xmb_shadows_enable" "false"
  272.  
  273. # swap A/B buttons based on ES configuration
  274. iniSet "menu_swap_ok_cancel_buttons" "$es_swap"
  275.  
  276. # enable menu_unified_controls by default (see below for more info)
  277. iniSet "menu_unified_controls" "true"
  278.  
  279. # disable 'press twice to quit'
  280. iniSet "quit_press_twice" "false"
  281.  
  282. # enable video shaders
  283. iniSet "video_shader_enable" "true"
  284.  
  285. # enable overlays by default
  286. iniSet "input_overlay_enable" "true"
  287.  
  288. # disable save paths under sub-folders
  289. iniSet "sort_savestates_enable" "false"
  290. iniSet "sort_savefiles_enable" "false"
  291.  
  292. copyDefaultConfig "$config" "$configdir/all/retroarch.cfg"
  293. rm "$config"
  294.  
  295. # if no menu_driver is set, force RGUI, as the default has now changed to XMB.
  296. _set_config_option_retroarch "menu_driver" "rgui"
  297.  
  298. # set RGUI aspect ratio to "Integer Scaling" to prevent stretching
  299. _set_config_option_retroarch "rgui_aspect_ratio_lock" "2"
  300.  
  301. # if no menu_unified_controls is set, force it on so that keyboard player 1 can control
  302. # the RGUI menu which is important for arcade sticks etc that map to keyboard inputs
  303. _set_config_option_retroarch "menu_unified_controls" "true"
  304.  
  305. # disable `quit_press_twice` on existing configs
  306. _set_config_option_retroarch "quit_press_twice" "false"
  307.  
  308. # enable video shaders on existing configs
  309. _set_config_option_retroarch "video_shader_enable" "true"
  310.  
  311. # (compat) keep all core options in a single file
  312. _set_config_option_retroarch "global_core_options" "true"
  313.  
  314. # disable the content load info popup with core and game info
  315. _set_config_option_retroarch "menu_show_load_content_animation" "false"
  316.  
  317. # disable search action
  318. _set_config_option_retroarch "menu_disable_search_button" "true"
  319.  
  320. # don't save input remaps by default
  321. _set_config_option_retroarch "remap_save_on_exit" "false"
  322.  
  323. # enable overlays by default on upgrades
  324. _set_config_option_retroarch "input_overlay_enable" "true"
  325.  
  326. # don't sort save files in sub-folders
  327. _set_config_option_retroarch "sort_savefiles_enable" "false"
  328. _set_config_option_retroarch "sort_savestates_enable" "false"
  329.  
  330. # remapping hack for old 8bitdo firmware
  331. addAutoConf "8bitdo_hack" 0
  332. }
  333.  
  334. function keyboard_retroarch() {
  335. if [[ ! -f "$configdir/all/retroarch.cfg" ]]; then
  336. printMsgs "dialog" "No RetroArch configuration file found at $configdir/all/retroarch.cfg"
  337. return
  338. fi
  339. local input
  340. local options
  341. local i=1
  342. local key=()
  343. while read input; do
  344. local parts=($input)
  345. key+=("${parts[0]}")
  346. options+=("${parts[0]}" $i 2 "${parts[*]:2}" $i 26 16 0)
  347. ((i++))
  348. done < <(grep "^[[:space:]]*input_player[0-9]_[a-z]*" "$configdir/all/retroarch.cfg")
  349. local cmd=(dialog --backtitle "$__backtitle" --form "RetroArch keyboard configuration" 22 48 16)
  350. local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  351. if [[ -n "$choice" ]]; then
  352. local value
  353. local values
  354. readarray -t values <<<"$choice"
  355. iniConfig " = " '"' "$configdir/all/retroarch.cfg"
  356. i=0
  357. for value in "${values[@]}"; do
  358. iniSet "${key[$i]}" "$value" >/dev/null
  359. ((i++))
  360. done
  361. fi
  362. }
  363.  
  364. function hotkey_retroarch() {
  365. iniConfig " = " '"' "$configdir/all/retroarch.cfg"
  366. local cmd=(dialog --backtitle "$__backtitle" --menu "Choose the desired hotkey behaviour." 22 76 16)
  367. local options=(1 "Hotkeys enabled. (default)"
  368. 2 "Press ALT to enable hotkeys."
  369. 3 "Hotkeys disabled. Press ESCAPE to open RGUI.")
  370. local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  371. if [[ -n "$choice" ]]; then
  372. case "$choice" in
  373. 1)
  374. iniSet "input_enable_hotkey" "nul"
  375. iniSet "input_exit_emulator" "escape"
  376. iniSet "input_menu_toggle" "F1"
  377. ;;
  378. 2)
  379. iniSet "input_enable_hotkey" "alt"
  380. iniSet "input_exit_emulator" "escape"
  381. iniSet "input_menu_toggle" "F1"
  382. ;;
  383. 3)
  384. iniSet "input_enable_hotkey" "escape"
  385. iniSet "input_exit_emulator" "nul"
  386. iniSet "input_menu_toggle" "escape"
  387. ;;
  388. esac
  389. fi
  390. }
  391.  
  392. function gui_retroarch() {
  393. while true; do
  394. local names=(shaders overlays assets)
  395. local dirs=(shaders overlay assets)
  396. local options=()
  397. local name
  398. local dir
  399. local i=1
  400. for name in "${names[@]}"; do
  401. if [[ -d "$configdir/all/retroarch/${dirs[i-1]}/.git" ]]; then
  402. options+=("$i" "Manage $name (installed)")
  403. else
  404. options+=("$i" "Manage $name (not installed)")
  405. fi
  406. ((i++))
  407. done
  408. options+=(
  409. 4 "Configure keyboard for use with RetroArch"
  410. 5 "Configure keyboard hotkey behaviour for RetroArch"
  411. )
  412. local cmd=(dialog --backtitle "$__backtitle" --menu "Choose an option" 22 76 16)
  413. local choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  414. case "$choice" in
  415. 1|2|3)
  416. name="${names[choice-1]}"
  417. dir="${dirs[choice-1]}"
  418. options=(1 "Install/Update $name" 2 "Uninstall $name" )
  419. cmd=(dialog --backtitle "$__backtitle" --menu "Choose an option for $dir" 12 40 06)
  420. choice=$("${cmd[@]}" "${options[@]}" 2>&1 >/dev/tty)
  421.  
  422. case "$choice" in
  423. 1)
  424. "update_${name}_retroarch"
  425. ;;
  426. 2)
  427. rm -rf "$configdir/all/retroarch/$dir"
  428. [[ "$dir" == "assets" ]] && install_xmb_monochrome_assets_retroarch
  429. ;;
  430. *)
  431. continue
  432. ;;
  433.  
  434. esac
  435. ;;
  436. 4)
  437. keyboard_retroarch
  438. ;;
  439. 5)
  440. hotkey_retroarch
  441. ;;
  442. *)
  443. break
  444. ;;
  445. esac
  446.  
  447. done
  448. }
  449.  
  450. # adds a retroarch global config option in `$configdir/all/retroarch.cfg`, if not already set
  451. function _set_config_option_retroarch()
  452. {
  453. local option="$1"
  454. local value="$2"
  455. iniConfig " = " '"' "$configdir/all/retroarch.cfg"
  456. iniGet "$option"
  457. if [[ -z "$ini_value" ]]; then
  458. iniSet "$option" "$value"
  459. fi
  460. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement