Advertisement
TheGreenTriangle

Steam deck controller fix (Disable Steam Input)

Feb 16th, 2025
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 6.10 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. # Log file for debugging
  4. LOG_FILE="$HOME/.local/share/Steam/userdata/controller_settings.log"
  5.  
  6. log() {
  7.     echo "$(date +'%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
  8. }
  9.  
  10. # Check if protontricks is installed
  11. if ! command -v flatpak run com.github.Matoking.protontricks &>/dev/null; then
  12.     kdialog --error "Protontricks is required but not installed. Please install it and try again."
  13.     exit 1
  14. fi
  15.  
  16. # Get the list of Non-Steam games
  17. games=$(flatpak run com.github.Matoking.protontricks -l | grep "Non-Steam shortcut: " | sed 's/Non-Steam shortcut: //')
  18.  
  19. if [[ -z "$games" ]]; then
  20.     kdialog --error "No Non-Steam games found."
  21.     exit 1
  22. fi
  23.  
  24. # Build an array of games (each with game name and AppID)
  25. declare -a game_list
  26. while IFS= read -r line; do
  27.     game_list+=("$line")
  28. done <<< "$games"
  29.  
  30. # Build the kdialog menu parameters.
  31. # kdialog expects key-value pairs: key1 value1 key2 value2 ...
  32. menu_params=()
  33. for i in "${!game_list[@]}"; do
  34.     # Extract the game name (remove the AppID portion)
  35.     display_name=$(echo "${game_list[i]}" | sed -E 's/\s\([0-9]+\)//')
  36.     key=$((i+1))
  37.     menu_params+=("$key" "$display_name")
  38. done
  39.  
  40. # Define the userdata directory (for backups)
  41. STEAM_CONFIG_DIR="$HOME/.local/share/Steam/userdata"
  42.  
  43. # Check if any backup files exist (looking in any userdata/config folder)
  44. backup_exist=$(find "$STEAM_CONFIG_DIR" -type f -name "localconfig_backup_*.vdf" | head -n 1)
  45. if [[ -n "$backup_exist" ]]; then
  46.     # Add restore option at the bottom.
  47.     restore_key=$(( ${#game_list[@]} + 1 ))
  48.     menu_params+=("$restore_key" "[[ Restore Backup ]]")
  49. fi
  50.  
  51. # Present the menu using kdialog
  52. selection=$(kdialog --menu "Select a game to modify controller settings:" "${menu_params[@]}")
  53. if [[ -z "$selection" ]]; then
  54.     kdialog --error "No selection made. Exiting."
  55.     exit 1
  56. fi
  57.  
  58. # If the selection equals the restore option key, perform backup restoration.
  59. if [[ -n "$restore_key" && "$selection" -eq "$restore_key" ]]; then
  60.     # Find all backups matching our naming pattern
  61.     backups=$(find "$STEAM_CONFIG_DIR" -type f -name "localconfig_backup_*.vdf")
  62.     if [[ -z "$backups" ]]; then
  63.         kdialog --error "No backups found."
  64.         exit 1
  65.     fi
  66.     # Build the restore menu parameters.
  67.     backup_menu=()
  68.     count=1
  69.     declare -A backup_map
  70.     while IFS= read -r backup; do
  71.         # Extract a cleaned-up name: remove the prefix and the .vdf suffix.
  72.         filename=$(basename "$backup")
  73.         display_backup=${filename#localconfig_backup_}
  74.         display_backup=${display_backup%.vdf}
  75.         backup_menu+=("$count" "$display_backup")
  76.         backup_map["$count"]="$backup"
  77.         ((count++))
  78.     done <<< "$backups"
  79.     backup_choice=$(kdialog --menu "Select a backup to restore:" "${backup_menu[@]}")
  80.     if [[ -n "$backup_choice" ]]; then
  81.         selected_backup=${backup_map["$backup_choice"]}
  82.         # Restore the selected backup to all userdata folders that contain a localconfig.vdf.
  83.         for USER_FOLDER in $(find "$STEAM_CONFIG_DIR" -maxdepth 1 -type d -regex '.*/[0-9]+'); do
  84.             CONFIG_FILE="$USER_FOLDER/config/localconfig.vdf"
  85.             if [[ -f "$CONFIG_FILE" ]]; then
  86.                 cp "$selected_backup" "$CONFIG_FILE"
  87.                 log "Backup restored from $selected_backup for user $USER_FOLDER."
  88.                 kdialog --msgbox "Backup restored from $selected_backup for user $USER_FOLDER."
  89.             fi
  90.         done
  91.     fi
  92.     exit 0
  93. fi
  94.  
  95. # Otherwise, process the selected game.
  96. # Array indices are 0-based.
  97. selected_entry="${game_list[selection-1]}"
  98.  
  99. # Extract AppID and game name.
  100. app_id=$(echo "$selected_entry" | grep -oE '[0-9]+')
  101. game_name=$(echo "$selected_entry" | sed -E 's/\s\([0-9]+\)//')
  102.  
  103. # Calculate Short ID as a signed 32-bit integer.
  104. short_id=$((app_id & 0xFFFFFFFF))
  105. if (( short_id > 2147483647 )); then
  106.     short_id=$((short_id - 4294967296))
  107. fi
  108.  
  109. log "Selected Game: $game_name | AppID: $app_id | Short ID: $short_id"
  110. kdialog --msgbox "Selected Game: $game_name\nAppID: $app_id\nShort ID: $short_id"
  111.  
  112. # Process each userdata folder.
  113. USERDATA_FOLDERS=$(find "$STEAM_CONFIG_DIR" -maxdepth 1 -type d -regex '.*/[0-9]+')
  114. if [[ -z "$USERDATA_FOLDERS" ]]; then
  115.     kdialog --error "No Steam user data folders found!"
  116.     exit 1
  117. fi
  118.  
  119. for USER_FOLDER in $USERDATA_FOLDERS; do
  120.     CONFIG_FILE="$USER_FOLDER/config/localconfig.vdf"
  121.     if [[ ! -f "$CONFIG_FILE" ]]; then
  122.         log "Skipping user folder: $USER_FOLDER (no localconfig.vdf found)"
  123.         continue
  124.     fi
  125.     TIMESTAMP=$(date +'%Y-%m-%dT%H-%M-%S')
  126.     BACKUP_FILE="$USER_FOLDER/config/localconfig_backup_${game_name}_${TIMESTAMP}.vdf"
  127.     cp "$CONFIG_FILE" "$BACKUP_FILE"
  128.     log "Backup created: $BACKUP_FILE for user $USER_FOLDER"
  129.  
  130.     # Create a temporary file and insert our new settings inside the "apps" section.
  131.     temp_file=$(mktemp)
  132.     inside_apps=0
  133.     while IFS= read -r line; do
  134.         echo "$line" >> "$temp_file"
  135.         # Detect the start of the "apps" section.
  136.         if [[ "$line" =~ \"apps\" ]]; then
  137.             inside_apps=1
  138.         fi
  139.         # After the opening brace of "apps", insert our new settings (only once).
  140.         if [[ $inside_apps -eq 1 && "$line" =~ \{ ]]; then
  141.             inside_apps=0
  142.             # Use printf to generate text with literal tab characters.
  143.             insert_text=$(printf "\t\t\t\"%s\"\n\t\t\t{\n\t\t\t\t\"UseSteamControllerConfig\"\t\t\t\"0\"\n\t\t\t\t\"SteamControllerRumble\"\t\t\t\"-1\"\n\t\t\t\t\"SteamControllerRumbleIntensity\"\t\t\t\"320\"\n\t\t\t}\n" "$short_id")
  144.             echo "$insert_text" >> "$temp_file"
  145.         fi
  146.     done < "$CONFIG_FILE"
  147.  
  148.     mv "$temp_file" "$CONFIG_FILE"
  149.  
  150.     if grep -q "\"$short_id\"" "$CONFIG_FILE"; then
  151.         log "Successfully added controller settings for $game_name (User: $USER_FOLDER)."
  152.         kdialog --msgbox "Settings updated successfully for user: $USER_FOLDER"
  153.     else
  154.         log "Verification failed for user $USER_FOLDER! Restoring backup."
  155.         cp "$BACKUP_FILE" "$CONFIG_FILE"
  156.         kdialog --error "Error: Changes could not be verified for user $USER_FOLDER. Backup restored."
  157.     fi
  158. done
  159.  
Tags: Steam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement