This repository contains scripts to manage the setup and teardown of a game streaming session using the Sunshine server on your host PC. The scripts automate system changes, such as enabling a virtual display, adjusting resolution, refresh rate, HDR, G-Sync, and FPS limits for optimal streaming.
This setup assumes that you have already installed:
- Sunshine on your host PC for game streaming.
- Moonlight on your client device to connect to your host.
Follow the links above for installation instructions if these are not yet set up.
Important Notes:
- These scripts are tailored for PCs with NVIDIA graphics cards and G-Sync or G-Sync compatible monitors.
- If you have an AMD setup and there’s enough interest, I might provide AMD-compatible versions of these scripts in the future. I'm open to contributions if you want to help with that. Please refer to the AMD support issue for more information.
All required tools, except the virtual display driver, are bundled and available for download in the binaries folder for convenience. A malware scan result is included. Alternatively, you can download the tools manually from their official sources if preferred. Note: The tools must be placed in the C:\Tools
folder for the scripts to function correctly.
- Virtual-Display-Driver - A virtual display driver that enables a virtual monitor for streaming. Follow the installation instructions on their GitHub page. Important: Ensure the provided option.txt file is placed at
C:\IddSampleDriver\options.txt
before installing. - QRes - A tool to set display resolution and refresh rate.
- HDRTray - A command-line tool for toggling HDR.
- gsync-toggle - A tool for toggling G-Sync on and off.
- frl-toggle - A tool to set the frame rate limit (FRL) for NVIDIA GPUs.
Disclaimer: I am not the author of these tools and cannot guarantee their safety or functionality. Use them at your own risk.
- RTSS (RivaTuner Statistics Server) - Used for managing FPS limits and on-screen overlays. This is optional, as the NVIDIA frame limiter will be set via
frl-toggle
even without RTSS. - rtss-cli - Command-line interface for RTSS to manage FPS limits and overlays from scripts.
In both scripts (start_streaming
and stop_streaming
), an extra environment variable controls whether RTSS settings are applied. If you don’t have RTSS installed, set this variable to false
.
To fully automate the process, download the scripts from this repository and place them in the C:\Tools\sunshine-scripts
folder. Then, configure these scripts in the Sunshine web interface:
-
Go to Configuration > General > Command Preparations.
-
Set the Do Command to:
cmd /c C:\Tools\sunshine-scripts\start_streaming.bat
See start_streaming to learn all the additional parameters that can be passed to this script.
-
Set the Undo Command to:
cmd /c C:\Tools\sunshine-scripts\stop_streaming.bat -WIDTH 1920 -HEIGHT 1080 -REFRESH 60 -HDR false
Important: Edit the
WIDTH
,HEIGHT
,REFRESH
andHDR
values to match your monitor’s resolution, refresh rate and HDR preference for regular desktop use, when the streaming session ends.See stop_streaming to learn all the additional parameters that can be passed to this script.
-
Check the Run As Admin box for both commands.
This setup will automate the execution of the scripts whenever Moonlight starts or stops a streaming session.
After installing the Virtual Display Driver, you will need to set the virtual display as your main display in Windows Display Settings. This step ensures that Windows automatically switches between the virtual display (during streaming) and your primary display (when not streaming). This setup is only needed once.
To set the virtual display as the main display:
- Open Settings > System > Display.
- Scroll down to Multiple Displays.
- Select the virtual display, and check Make this my main display.
Windows will now automatically switch between displays when starting or stopping a stream.
You can configure a task in Windows Task Scheduler to revert your system to its default settings if something goes wrong during streaming or if you forget to stop the stream. This task will run the stop_streaming.bat
script at login, ensuring your computer reverts to its normal settings after a restart.
-
Download the stop_streaming_task.xml file, which is preconfigured to run
stop_streaming.bat
at login. -
Import the task into Windows Task Scheduler:
- Open Task Scheduler in Windows.
- In the right-hand pane, click on Import Task.
- Browse and select the
stop_streaming_task.xml
file. - Check the option to "Run with highest privileges", in order to avoid seeing a UAC prompt.
- Review the settings and click OK to import the task.
-
(Optional) Test the task by restarting your computer to ensure that the
stop_streaming.bat
script runs automatically and your settings revert to normal.
This script prepares your system for streaming by enabling a virtual display, setting resolution, refresh rate, toggling HDR, disabling G-Sync, and adjusting FPS limits.
This script is automatically triggered by the Sunshine server when Moonlight starts streaming. It uses environment variables provided by Sunshine based on the settings received from the Moonlight client. No manual editing of variables is required.
- Enables the virtual display.
- Sets the resolution and refresh rate with
QRes
based on the Moonlight client’s settings. - Toggles HDR on/off using
HDRTray
. - Disables G-Sync for the streaming session using
gsync-toggle
. - Sets the global FPS limit in the Nvidia Control Panel using
frl-toggle
. - If enabled via
USE_RTSS
, sets the global FPS limit usingRTSS
and disables its overlay while streaming.
- WIDTH - The width of the virtual display. Default: 1920, or the width passed by the Moonlight client.
- HEIGHT - The height of the virtual display. Default: 1080, or the height passed by the Moonlight client.
- REFRESH - The refresh rate of the virtual display. Default: 60, or the target FPS passed by the Moonlight client.
- FPS - The FPS limit for the stream. Default: 60, or the target FPS passed by the Moonlight client.
- HDR - Whether to enable HDR. Default: false, or the HDR setting passed by the Moonlight client.
- USE_RTSS - Whether to use RTSS for FPS limiting and turn off its overlay while streaming. Default: false.
- DEBUG - Whether to enable debug mode and view additional information. Default: false.
This script restores your system to its normal desktop configuration after streaming has ended.
This script is automatically triggered by the Sunshine server when Moonlight stops streaming. The necessary variables are passed through the Undo Command configuration, so no manual editing of the script is required.
- Disables the virtual display.
- Restores the resolution and refresh rate for your primary display.
- Toggles HDR off using
HDRTray
. - Re-enables G-Sync using
gsync-toggle
. - Resets the global FPS limit in the Nvidia Control Panel using
frl-toggle
. - If enabled via
USE_RTSS
, restores the FPS limit set in RTSS. The overlay remains disabled regardless of the parameter value.
- WIDTH - The width of the primary display. Default: 1920.
- HEIGHT - The height of the primary display. Default: 1080.
- REFRESH - The refresh rate of the primary display. Default: 60.
- FPS - The FPS limit for non-streaming gameplay. Default: Refresh rate - 3, as recommended for variable refresh rate displays.
- HDR - Whether to enable HDR. Default: false.
- USE_RTSS - Whether to restore the FPS limit set in RTSS. Keeps the overlay disabled regardless of the parameter value. Default: false.
- DEBUG - Whether to enable debug mode and view additional information. Default: false.
This file defines the supported resolutions and refresh rates for the virtual display used during streaming. Ensure it is placed at C:\IddSampleDriver\options.txt
before installing the Virtual Display Driver. You may edit the file as needed to match your client device's supported resolutions and refresh rates. Some common resolutions and refresh rates are already included for convenience.
This project heavily relies on the following open-source tools and utilities:
- Virtual-Display-Driver - For creating a virtual display.
- QRes - For managing display resolution.
- HDRTray - For controlling HDR settings.
- gsync-toggle - For toggling G-Sync on and off.
- frl-toggle - For setting the NVIDIA frame rate limit.
- rtss-cli - For controlling RTSS settings from the command line.
And of course:
- Sunshine - For enabling game streaming on any PC.
- Moonlight - For connecting to the Sunshine server from virtually any device.
- RTSS (RivaTuner Statistics Server) - For providing a universal tool for managing FPS limits and on-screen overlays.
Without these excellent tools, this project would not be possible. I’m merely providing the glue that makes these tools work together for an enhanced game streaming experience.