Advertisement
Guest User

CostumeQuest

a guest
May 8th, 2013
679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.32 KB | None | 0 0
  1.    
  2.  
  3.     #!/bin/bash
  4.      
  5.     USER_HOME=$(eval echo ~)
  6.     STEAM_USER_HOME="${USER_HOME}/Steam/" #may need to change this, I had to edit it from the version I found at first
  7.     STEAM_CONFIG_FILE="${STEAM_USER_HOME}config/config.vdf"
  8.     CAVE_CONFIG_FILE="${STEAM_USER_HOME}SteamApps/common/Costume Quest/Data/Config/SDLGamepad.config"
  9.      
  10.     if [ ! -e "${STEAM_CONFIG_FILE}" ]; then
  11.             echo "Could not find Steam user config file."
  12.             exit 1
  13.     fi
  14.      
  15.     if [ ! -e "${CAVE_CONFIG_FILE}" ]; then
  16.             echo "Could not find 'The Cave' SDL Gamepad config file."
  17.             exit 1
  18.     fi
  19.      
  20.     clear
  21.     printf "Steam user data found: '%s'\n" "${STEAM_USER_HOME}"
  22.     printf "Steam config file found: 'config/config.vdf'\n"
  23.     printf "The Cave gamepad file found: 'SteamApps/common/TheCave/Cave.app/Contents/Resources/Data/Config/SDLGamepad.config'\n\n"
  24.      
  25.     SDL_GAMECONTROLLER_STRING=`cat "${STEAM_CONFIG_FILE}" | grep '"SDL_GamepadBind"' | perl -nle 'm/"SDL_GamepadBind"\s*"(.*)"/; print $1'`
  26.     if [ -z "${SDL_GAMECONTROLLER_STRING}" ]; then
  27.             echo "Failed to extract controller key binding.  Did you configure it in Steam's 'Big Picture' mode?"
  28.             exit 1
  29.     fi
  30.      
  31.     OLD_IFS=$IFS
  32.     printf "Controller data:\n"
  33.     IFS=','
  34.     CONTROLLER_DATA=( $SDL_GAMECONTROLLER_STRING )
  35.     CONTROLLER_NAME=${CONTROLLER_DATA[1]}
  36.     CONTROLLER_GUID=${CONTROLLER_DATA[0]}
  37.     printf "\tName = %s\n\tGUID = %s\n" "${CONTROLLER_NAME}" "${CONTROLLER_GUID}"
  38.      
  39.     IFS=':'
  40.     INDEX=0;
  41.     for i in {2..22}; do
  42.             BUTTON_DATA=( ${CONTROLLER_DATA[i]} )
  43.             if [ "${BUTTON_DATA[1]}" = "" ]; then
  44.                     printf "\t%s --> %s\n" "${BUTTON_DATA[0]}" "UNBOUND"  
  45.             elif [ "${BUTTON_DATA[1]:0:1}" = "b" ]; then
  46.                     printf "\t%s --> button %s\n" "${BUTTON_DATA[0]}" "${BUTTON_DATA[1]:1}"
  47.             else
  48.                     printf "\t%s --> axis %s\n" "${BUTTON_DATA[0]}" "${BUTTON_DATA[1]:1}"  
  49.             fi
  50.     done
  51.     IFS=$OLD_IFS
  52.      
  53.     printf "\n"
  54.      
  55.     TEST_FOR_EXACT_EXISTENCE=`grep "${SDL_GAMECONTROLLER_STRING}" "${CAVE_CONFIG_FILE}"`
  56.     if [ -n "${TEST_FOR_EXACT_EXISTENCE}" ]; then
  57.             echo "This exact controller config string is already in the gamepad config file for The Cave."
  58.             exit 0
  59.     fi
  60.      
  61.     TEST_FOR_GUID_EXISTENCE=`grep "${CONTROLLER_GUID}" "${CAVE_CONFIG_FILE}"`
  62.     if [ -n "${TEST_FOR_GUID_EXISTENCE}" ]; then
  63.             echo "This controller ID is already in the gamepad config file for The Cave but the name or button bindings have changed."
  64.      
  65.             # Look for backup of origianl config file
  66.             if [ ! -f "${CAVE_CONFIG_FILE}.orig" ]; then
  67.                     echo "There is no backup file to use.  You must delete the existing string in the config file manually in order to use your new settings."
  68.                     exit 1
  69.             fi
  70.      
  71.             # Is this controller ID in the backup file too
  72.             TEST_FOR_GUID_EXISTENCE2=`grep "${CONTROLLER_GUID}" "${CAVE_CONFIG_FILE}.orig"`
  73.             if [ -n "${TEST_FOR_GUID_EXISTENCE2}" ]; then   # (shit)
  74.                     echo "The backup config file already has this controller ID too."
  75.                     echo "You must manually remove the existing string for this controller in the config file in order to use your new settings."
  76.                     exit 1
  77.             fi
  78.      
  79.             # If user wants to use the new settings then just restore the backup
  80.             while true; do
  81.                     read -p "Do you wish to replace the old name and bindings with the new ones? [y/n]: " yn
  82.                     case $yn in
  83.                             [Yy]* ) cp "${CAVE_CONFIG_FILE}.orig" "${CAVE_CONFIG_FILE}"; break;;
  84.                             [Nn]* ) exit 1;;
  85.                             * ) echo "Please answer yes or no.";;
  86.                     esac
  87.             done
  88.     fi
  89.      
  90.     printf "Backing up original The Cave config file to %s\n" "${CAVE_CONFIG_FILE}.orig"
  91.     cp "${CAVE_CONFIG_FILE}" "${CAVE_CONFIG_FILE}.orig"
  92.      
  93.     printf "Adding controller SDL binding to config file ... "
  94.     printf "\n# Controller configuration extracted from Steam 'config.vdf' file\n%s\n\n" "${SDL_GAMECONTROLLER_STRING}" >> "${CAVE_CONFIG_FILE}"
  95.     printf "Done!\n"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement