#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# shellcheck source=config.sh
source "${SCRIPT_DIR}/config.sh"

MODE="${1:-sdl-on}"
export_wine_env

case "$MODE" in
  sdl-on)
    "${WINE64}" reg add 'HKLM\System\CurrentControlSet\Services\winebus' /v DisableHidraw /t REG_DWORD /d 1 /f >/dev/null
    "${WINE64}" reg add 'HKLM\System\CurrentControlSet\Services\winebus' /v 'Enable SDL' /t REG_DWORD /d 1 /f >/dev/null
    echo "WineBus SDL ON"
    ;;
  sdl-off)
    "${WINE64}" reg add 'HKLM\System\CurrentControlSet\Services\winebus' /v DisableHidraw /t REG_DWORD /d 0 /f >/dev/null
    "${WINE64}" reg add 'HKLM\System\CurrentControlSet\Services\winebus' /v 'Enable SDL' /t REG_DWORD /d 0 /f >/dev/null
    echo "WineBus SDL OFF"
    ;;
  show)
    "${WINE64}" reg query 'HKLM\System\CurrentControlSet\Services\winebus' /v DisableHidraw || true
    "${WINE64}" reg query 'HKLM\System\CurrentControlSet\Services\winebus' /v 'Enable SDL' || true
    ;;
  *)
    echo "Usage: $(basename "$0") [sdl-on|sdl-off|show]"; exit 1
    ;;
esac
