Started restructuring of the game launcher function. This included splitting it into 3 functions as well as redoing the way games are read from the games.conf file. There very well may be bugs.

This commit is contained in:
Storm Dragon 2024-09-12 01:35:58 -04:00
parent 9ce0c4c1e3
commit f459791fda

View File

@ -834,11 +834,132 @@ kill_game() {
exit 0
}
# for games that require custom scripts before launch or custom launch parameters
custom_launch_parameters() {
if [[ "${game[0]}" == "dragon-pong" ]]; then
"${0%/*}/speech/speak_window_title.sh" DragonPong.exe &
pushd "$(winepath "$winePath")"
wine "$wineExec"
popd
exit 0
fi
if [[ "${game[0]}" == "executioner's-rage" ]]; then
find "${WINEPREFIX}/drive_c/Program Files" -type f -name 'nvdaControllerClient64.dll' -exec cp -v "${cache}/nvda2speechd64.dll" "{}" \;
fi
if [[ "${game[0]}" == "haunted-party" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "${game[0]}" == "laser-breakout" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
"${0%/*}/speech/speak_window_title.sh" play.exe &
fi
if [[ "${game[0]}" == "light-battles" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "${game[0]}" == "mist-world" ]]; then
"${0%/*}/speech/speak_window_title.sh" mw.exe &
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "${game[0]}" == "oh-shit" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "${game[0]}" == "bokurano-daibouken-2" ]]; then
"${0%/*}/speech/clipboard_translator.sh" play.exe bokurano-daibouken2 &
fi
if [[ "${game[0]}" == "bokurano-daibouken" ]]; then
"${0%/*}/speech/clipboard_translator.sh" play.exe bokurano-daibouken &
fi
if [[ "${game[0]}" =~ "bokurano-daibouken-3" ]]; then
dictPath="$(winepath "${winePath}")"
if [[ -r "${cache}/bk3-dict.dat" ]] && [[ ! -d "${dictPath}/dict" ]]; then
cp "${cache}/bk3-dict.dat" "${dictPath}/dict.dat"
fi
if [[ -d "${dictPath}/dict" ]]; then
if [[ ! -e "${dictPath}/data/nvdaControllerClient.dll" ]]; then
cp "${cache}/nvda2speechd32.dll" "${dictPath}/data/nvdaControllerClient.dll"
fi
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ ! -d "${dictPath}/dict" ]] && [[ ! -r "${cache}/bk3-dict.dat" ]]; then
find "${WINEPREFIX}/drive_c/nyanchangame/bk3" -type f -name 'nvdaControllerClient.dll' -exec rm -v "{}" \;
"${0%/*}/speech/clipboard_translator.sh" play.exe bokurano-daibouken3 &
fi
fi
if [[ "${game[0]}" == "bop-it-emulator" ]]; then
"${0%/*}/speech/speak_window_title.sh" bop.exe &
fi
if [[ "${game[0]}" == "breu2-shadow-hunt" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "${game[0]}" == "road-to-rage" ]]; then
"${0%/*}/speech/speak_window_title.sh" trtr.exe &
fi
if [[ "${game[0]}" == "sequence-storm" ]]; then
"${0%/*}/speech/clipboard_reader.sh" SequenceStorm &
fi
if [[ "${game[0]}" == "shadow-line" ]]; then
find "${WINEPREFIX}/drive_c/" -type f -name 'nvdaControllerClient.dll' -exec rm -v "{}" \;
"${0%/*}/speech/clipboard_translator.sh" play_sr.exe shadow-line &
fi
if [[ "${game[0]}" == "sketchbook" ]]; then
find "${WINEPREFIX}" -type f -name 'nvdaControllerClient32.dll' -exec cp -v "${cache}/nvdaControllerClient32.dll" "{}" \;
fi
if [[ "${game[0]}" == "audiodisc" ]]; then
wine "$winePath\\$wineExec"
exit 0
fi
if [[ "${game[0]}" == "audioquake" ]]; then
wine "$winePath\\$wineExec"
exit 0
fi
if [[ "${game[0]}" == "screaming-strike-2" ]]; then
pushd "$(winepath "$winePath")"
${wine} "$wineExec"
popd
exit 0
fi
if [[ "${game[0]}" == "warsim" ]]; then
pushd "$(winepath "$winePath")"
wine "$wineExec"
popd
exit 0
fi
if [[ "${game[0]}" == "interceptor" ]]; then
pushd "$(winepath "$winePath")"
wine "$wineExec"
popd
exit 0
fi
if [[ "${game[0]}" == "vip-mud" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ -d "${WINEPREFIX}/drive_c/windows/syswow64" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
# switch to wine64 for 64 bit prefix.
[[ "${wine}" == "wine" ]] && export wine="wine64"
fi
if [[ "${game[0]}" == "the-great-toy-robbery" ]] ; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
}
create_game_array() {
# Game array 0 bottle, 1 path, 2 title, 3+ flags
for i in "${lines[@]}" ; do
if [[ "${game}" =~ ^${i} ]]; then
# This is weird. Why do I have to set game to i before making the array?
game="$i"
IFS='|' read -ra game <<< "$i"
break
fi
done
}
# launch games that are installed
game_launcher() {
# For use by update scripts that want to source functions in this file.
[[ "$agmNoLaunch" == "true" ]] && return
mapfile -t lines < <(sed '/^$/d' "${configFile}" 2> /dev/null)
mapfile -t lines < <(sed -e '/^$/d' -e '/^ *#/d' "${configFile}" 2> /dev/null)
if [[ ${#lines} -eq 0 ]]; then
echo "Install some games first."
exit 0
@ -847,7 +968,8 @@ game_launcher() {
# Create the menu of installed games
declare -a menuList
for i in "${lines[@]}" ; do
menuList+=("${i%|*}" "${i##*|}")
IFS='|' read -ra gameInfo <<< "$i"
menuList+=("${gameInfo[0]}|${gameInfo[1]}" "${gameInfo[2]}")
done
menuList+=("Donate" "Donate")
menuList+=("Become a Patron" "Become a Patron")
@ -864,156 +986,46 @@ game_launcher() {
elif [[ $menuCode -eq 3 ]]; then
documentation "$game" "$(echo "$game" | cut -d '|' -f2)"
fi
create_game_array
else
local game="$(grep "^${1}|" "${configFile}" 2> /dev/null)"
game="${game%|*}"
create_game_array
if [[ -z "$game" ]]; then
echo "Game $1 not found."
exit 1
fi
fi
if [[ ${#game} -gt 0 ]]; then
if [[ "$game" == "Donate" ]]; then
if [[ ${#game[@]} -gt 0 ]]; then
if [[ "${game[0]}" == "Donate" ]]; then
open_url "https://ko-fi.com/stormux"
exit 0
fi
if [[ "$game" == "Become a Patron" ]]; then
if [[ "${game[0]}" == "Become a Patron" ]]; then
open_url "https://2mb.games/product/2mb-patron/"
exit 0
fi
get_bottle "$game"
get_bottle "${game[0]}"
# make sure wine is actually set to something
export wine="${wine:-wine}"
echo -n "launching "
${wine} --version
local winePath="${game#*|}"
winePath="${winePath%\\*.exe}"
local wineExec="${game#*|}"
wineExec="${wineExec%|*}"
wineExec="${wineExec##*\\}"
# kill any previous existing wineservers for this prefix in case they didn't shut down properly.
${wine}server -k
# launch the game
if command -v qjoypad &> /dev/null ; then
mkdir -p ~/.qjoypad3
touch "${HOME}/.qjoypad3/${game%|*}.lyt"
touch "${HOME}/.qjoypad3/${game[2]}.lyt"
# A | separated list of games that should not start with qjoypad.
noQjoypadGames="a-hero's-call"
if [[ "${noqjoypad}" != "true" ]] && ! [[ "${game}" =~ ${noQjoypadGames} ]]; then
noQjoypadGames="A Hero's Call"
if [[ "${noqjoypad}" != "true" ]] && ! [[ "${game[2]}" =~ ${noQjoypadGames} ]]; then
if pgrep qjoypad &> /dev/null ; then
qjoypad -T "${game%|*}" 2> /dev/null
qjoypad -T "${game[2]}" 2> /dev/null
else
qjoypad -T "${game%|*}" 2> /dev/null &
qjoypad -T "${game[2]}" 2> /dev/null &
fi
fi
fi
# for games that require custom scripts before launch or custom launch parameters
if [[ "$game" =~ dragon-pong ]]; then
"${0%/*}/speech/speak_window_title.sh" DragonPong.exe &
pushd "$(winepath "$winePath")"
wine "$wineExec"
popd
exit 0
fi
if [[ "$game" =~ executioner\'s ]]; then
find "${WINEPREFIX}/drive_c/Program Files" -type f -name 'nvdaControllerClient64.dll' -exec cp -v "${cache}/nvda2speechd64.dll" "{}" \;
fi
if [[ "$game" =~ haunted-party ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "$game" =~ laser-breakout ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
"${0%/*}/speech/speak_window_title.sh" play.exe &
fi
if [[ "$game" =~ light-battles ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "$game" =~ mist-world ]]; then
"${0%/*}/speech/speak_window_title.sh" mw.exe &
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "$game" =~ oh-shit ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "$game" =~ ^bokurano-daibouken-2\| ]]; then
"${0%/*}/speech/clipboard_translator.sh" play.exe bokurano-daibouken2 &
fi
if [[ "$game" =~ ^bokurano-daibouken\| ]]; then
"${0%/*}/speech/clipboard_translator.sh" play.exe bokurano-daibouken &
fi
if [[ "$game" =~ bokurano-daibouken-3 ]]; then
dictPath="$(winepath "${winePath}")"
if [[ -r "${cache}/bk3-dict.dat" ]] && [[ ! -d "${dictPath}/dict" ]]; then
cp "${cache}/bk3-dict.dat" "${dictPath}/dict.dat"
fi
if [[ -d "${dictPath}/dict" ]]; then
if [[ ! -e "${dictPath}/data/nvdaControllerClient.dll" ]]; then
cp "${cache}/nvda2speechd32.dll" "${dictPath}/data/nvdaControllerClient.dll"
fi
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ ! -d "${dictPath}/dict" ]] && [[ ! -r "${cache}/bk3-dict.dat" ]]; then
find "${WINEPREFIX}/drive_c/nyanchangame/bk3" -type f -name 'nvdaControllerClient.dll' -exec rm -v "{}" \;
"${0%/*}/speech/clipboard_translator.sh" play.exe bokurano-daibouken3 &
fi
fi
if [[ "$game" =~ bop-it-emulator ]]; then
"${0%/*}/speech/speak_window_title.sh" bop.exe &
fi
if [[ "$game" =~ breu2-shadow-hunt ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ "$game" =~ road-to-rage\| ]]; then
"${0%/*}/speech/speak_window_title.sh" trtr.exe &
fi
if [[ "$game" =~ sequence-storm ]]; then
"${0%/*}/speech/clipboard_reader.sh" SequenceStorm &
fi
if [[ "$game" =~ shadow-line ]]; then
find "${WINEPREFIX}/drive_c/" -type f -name 'nvdaControllerClient.dll' -exec rm -v "{}" \;
"${0%/*}/speech/clipboard_translator.sh" play_sr.exe shadow-line &
fi
if [[ "$game" =~ sketchbook ]]; then
find "${WINEPREFIX}" -type f -name 'nvdaControllerClient32.dll' -exec cp -v "${cache}/nvdaControllerClient32.dll" "{}" \;
fi
if [[ "$game" =~ audiodisc ]]; then
wine "$winePath\\$wineExec"
exit 0
fi
if [[ "$game" =~ audioquake ]]; then
wine "$winePath\\$wineExec"
exit 0
fi
if [[ "$game" =~ screaming-strike-2 ]]; then
pushd "$(winepath "$winePath")"
${wine} "$wineExec"
popd
exit 0
fi
if [[ "$game" =~ warsim ]]; then
pushd "$(winepath "$winePath")"
wine "$wineExec"
popd
exit 0
fi
if [[ "$game" =~ interceptor ]]; then
pushd "$(winepath "$winePath")"
wine "$wineExec"
popd
exit 0
fi
if [[ "$game" =~ vip-mud ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
if [[ -d "${WINEPREFIX}/drive_c/windows/syswow64" ]]; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
# switch to wine64 for 64 bit prefix.
[[ "${wine}" == "wine" ]] && export wine="wine64"
fi
if [[ "$game" =~ the-great-toy-robbery ]] ; then
pgrep -u "$USER" nvda2speechd &> /dev/null || ${XDG_DATA_HOME:-$HOME/.local/share}/audiogame-manager/nvda2speechd &
fi
${wine:-wine} start /d "${winePath}" "$wineExec" /realtime
custom_launch_parameters
${wine:-wine} start /d "${game[1]%\\*}" "${game[1]##*\\}" /realtime
fi
exit 0
}