LizardByte / Sunshine

Self-hosted game stream host for Moonlight.
http://app.lizardbyte.dev/Sunshine/
GNU General Public License v3.0
17.62k stars 852 forks source link

Environment Variables are not parsed correctly in the global preparation command. #2842

Closed gongfuture closed 3 weeks ago

gongfuture commented 1 month ago

Is there an existing issue for this?

Is your issue described in the documentation?

Is your issue present in the latest beta/pre-release?

None

Describe the Bug

Use environment variables in global preparation command. For example, change the virtual display resolution in register. It will only move like %SUNSHINE_CLIENT_HEIGHT% into the register.

Expected Behavior

It can correctly parse the variables to value.

Additional Context

Maybe it can work past, but I'm not sure. I haven't use sunshine for a time, and these days I reuse this and update it.

Host Operating System

Windows

Operating System Version

版本 Windows 10 Professional 专业版 版本号 22H2 安装日期 ‎2023/‎1/‎13 操作系统内部版本 19045.4598 体验 Windows Feature Experience Pack 1000.19060.1000.0

Architecture

64 bit

Sunshine commit or version

Version v0.23.1

Package

Windows - installer

GPU Type

Nvidia

GPU Model

NVIDIA GeForce RTX 3060 Laptop GPU

GPU Driver/Mesa Version

556.12

Capture Method

None

Config

min_log_level = 1
gamepad = x360
address_family = both
fps = [30,60,90,120]
global_prep_cmd = [{"do":"reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WUDF\\Services\\usbmmIdd\\Parameters\\Monitors\" /v 0 /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f","undo":"","elevated":"true"},{"do":"reg add \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\WUDF\\Services\\usbmmIdd\\Parameters\\Monitors\" /ve /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f","undo":"","elevated":"true"},{"do":"\"D:\\Program Files (x86)\\single\\usbmmidd_v2\\deviceinstaller64.exe\" enableidd 1","undo":"\"D:\\Program Files (x86)\\single\\usbmmidd_v2\\deviceinstaller64.exe\" enableidd 0","elevated":"true"}]
key_rightalt_to_key_win = enabled
resolutions = [
    1280x720,
    1920x1080,
    1920x1200,
    2560x1600
]
upnp = enabled
log_path = E:\Program Files\Sunshine\log\sunshine.log
locale = zh

Apps

No response

Relevant log output

[2024:07:13:17:05:49]: Debug: Parsed target [reg] from command [reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors" /v 0 /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f]
[2024:07:13:17:05:49]: Debug: Resolved target [reg] to path ["C:\Windows\system32\reg.exe"]
[2024:07:13:17:05:49]: Info: Executing Do Cmd: [reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors" /v 0 /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f]
[2024:07:13:17:05:49]: Info: reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors" /v 0 /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f running with PID 2144
[2024:07:13:17:05:49]: Debug: Parsed target [reg] from command [reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors" /ve /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f]
[2024:07:13:17:05:49]: Debug: Resolved target [reg] to path ["C:\Windows\system32\reg.exe"]
[2024:07:13:17:05:49]: Info: Executing Do Cmd: [reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors" /ve /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f]
[2024:07:13:17:05:49]: Info: reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WUDF\Services\usbmmIdd\Parameters\Monitors" /ve /t REG_SZ /d %SUNSHINE_CLIENT_WIDTH%,%SUNSHINE_CLIENT_HEIGHT% /f running with PID 34588
[2024:07:13:17:05:49]: Debug: Parsed target [D:\Program Files (x86)\single\usbmmidd_v2\deviceinstaller64.exe] from command ["D:\Program Files (x86)\single\usbmmidd_v2\deviceinstaller64.exe" enableidd 1]
[2024:07:13:17:05:49]: Debug: Resolved target [D:\Program Files (x86)\single\usbmmidd_v2\deviceinstaller64.exe] to path ["D:\Program Files (x86)\single\usbmmidd_v2\deviceinstaller64.exe"]
[2024:07:13:17:05:49]: Info: Executing Do Cmd: ["D:\Program Files (x86)\single\usbmmidd_v2\deviceinstaller64.exe" enableidd 1]
[2024:07:13:17:05:49]: Info: "D:\Program Files (x86)\single\usbmmidd_v2\deviceinstaller64.exe" enableidd 1 running with PID 34116
gongfuture commented 1 month ago

I seems found this part of code? https://github.com/LizardByte/Sunshine/blob/master/src/process.cpp#L155-L177 So it's just works in the app execution? Can we change its area of influence to the whole Sunshine? Or just all writable commands.

ReenigneArcher commented 1 month ago

I seems found this part of code? https://github.com/LizardByte/Sunshine/blob/master/src/process.cpp#L155-L177 So it's just works in the app execution? Can we change its area of influence to the whole Sunshine? Or just all writable commands.

You can submit a PR adjusting them to work with global prep commands.

gongfuture commented 1 month ago

I seems found this part of code? https://github.com/LizardByte/Sunshine/blob/master/src/process.cpp#L155-L177 So it's just works in the app execution? Can we change its area of influence to the whole Sunshine? Or just all writable commands.

You can submit a PR adjusting them to work with global prep commands.

I want, but I have no C++ programming experience :(

Nonary commented 3 weeks ago

I seems found this part of code? https://github.com/LizardByte/Sunshine/blob/master/src/process.cpp#L155-L177 So it's just works in the app execution? Can we change its area of influence to the whole Sunshine? Or just all writable commands.

You can submit a PR adjusting them to work with global prep commands.

No need, can confirm it already works with global prep commands because all of my scripts rely on that and can read the environment variables just fine.

ReenigneArcher commented 3 weeks ago

In that case, probably need to prefix the commands with cmd /c

gongfuture commented 3 weeks ago

I seems found this part of code? https://github.com/LizardByte/Sunshine/blob/master/src/process.cpp#L155-L177 So it's just works in the app execution? Can we change its area of influence to the whole Sunshine? Or just all writable commands.

You can submit a PR adjusting them to work with global prep commands.

No need, can confirm it already works with global prep commands because all of my scripts rely on that and can read the environment variables just fine.

Did the latest release v0.23.1 had supported this? Or just newer pre-release had added this? If pre-release added, I will have a try. But if latest release had this feature, why the environment variables didn't parsed in my command of adding registry? I'm very confused.

upd: So it's just need to add cmd /c, I'm so stupid

gongfuture commented 3 weeks ago

In that case, probably need to prefix the commands with cmd /c

Thank you so much