Add limited support for testing Sunshine

This commit is contained in:
Cameron Gutman 2023-05-27 22:18:31 -05:00
parent 307623914b
commit 1e1d347052

View File

@ -238,7 +238,28 @@ bool ExecuteCommand(PCSTR command, PCHAR outputBuffer, DWORD outputBufferLength)
return true; return true;
} }
bool IsGameStreamEnabled() bool IsSunshineRunning()
{
bool ret = false;
HANDLE processSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
Process32First(processSnapshot, &procEntry);
do {
if (_stricmp(procEntry.szExeFile, "sunshine.exe") == 0) {
ret = true;
break;
}
} while (Process32Next(processSnapshot, &procEntry));
CloseHandle(processSnapshot);
return ret;
}
bool IsGameStreamEnabled(bool sunshineRunning)
{ {
DWORD error; DWORD error;
DWORD enabled; DWORD enabled;
@ -248,8 +269,10 @@ bool IsGameStreamEnabled()
error = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation\\NvStream", 0, KEY_READ | KEY_WOW64_64KEY, &key); error = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\NVIDIA Corporation\\NvStream", 0, KEY_READ | KEY_WOW64_64KEY, &key);
if (error != ERROR_SUCCESS) { if (error != ERROR_SUCCESS) {
fprintf(LOG_OUT, "RegOpenKeyEx() failed: %d\n", error); fprintf(LOG_OUT, "RegOpenKeyEx() failed: %d\n", error);
DisplayMessage("GeForce Experience was not detected on this PC. Make sure you're installing this utility on your GeForce GameStream-compatible PC, not the device running Moonlight.", if (!sunshineRunning) {
"https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide"); DisplayMessage("Neither GeForce Experience nor Sunshine are running on this PC. Make sure you're installing this utility on your host PC, not the device running Moonlight.",
"https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide");
}
return false; return false;
} }
@ -261,8 +284,10 @@ bool IsGameStreamEnabled()
if (error != ERROR_SUCCESS) { if (error != ERROR_SUCCESS) {
fprintf(LOG_OUT, "RegQueryValueExA() failed: %d\n", error); fprintf(LOG_OUT, "RegQueryValueExA() failed: %d\n", error);
} }
DisplayMessage("GameStream is not enabled in GeForce Experience. Please open GeForce Experience settings, navigate to the Shield tab, and turn GameStream on.", if (!sunshineRunning) {
"https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide"); DisplayMessage("GameStream is not enabled in GeForce Experience. Please open GeForce Experience settings, navigate to the Shield tab, and turn GameStream on.",
"https://github.com/moonlight-stream/moonlight-docs/wiki/Setup-Guide");
}
return false; return false;
} }
else { else {
@ -1324,9 +1349,19 @@ int main(int argc, char* argv[])
fprintf(CONSOLE_OUT, "Checking if GameStream is enabled...\n"); fprintf(CONSOLE_OUT, "Checking if GameStream is enabled...\n");
// First check if GameStream is enabled bool sunshineRunning = IsSunshineRunning();
if (!IsGameStreamEnabled()) { bool gfeGameStreamRunning = true;
return -1; if (!IsGameStreamEnabled(sunshineRunning)) {
if (sunshineRunning) {
DisplayMessage("The Moonlight Internet Hosting Tool is not designed for use with Sunshine.\n\n"
"To stream over the Internet with Sunshine, simply enable the UPnP option in the Sunshine Web UI.\n\n"
"Test results WILL be inaccurate if the Port option in Sunshine has been adjusted from the default value of 47989!",
nullptr, MpWarn, false);
gfeGameStreamRunning = false;
}
else {
return -1;
}
} }
if (IsCurrentlyStreaming()) { if (IsCurrentlyStreaming()) {
@ -1335,7 +1370,7 @@ int main(int argc, char* argv[])
return -1; return -1;
} }
if (!IsConsoleSessionActive()) { if (gfeGameStreamRunning && !IsConsoleSessionActive()) {
DisplayMessage("The system display is currently locked. You must sign in to your PC again to use GameStream.\n\n" DisplayMessage("The system display is currently locked. You must sign in to your PC again to use GameStream.\n\n"
"This is most often due to Microsoft Remote Desktop locking the screen. Use an alternate GameStream-compatible remote desktop solution like Chrome Remote Desktop or TeamViewer to unlock the PC and prevent this error in the future.", "This is most often due to Microsoft Remote Desktop locking the screen. Use an alternate GameStream-compatible remote desktop solution like Chrome Remote Desktop or TeamViewer to unlock the PC and prevent this error in the future.",
"https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#display-locked-error"); "https://github.com/moonlight-stream/moonlight-docs/wiki/Internet-Streaming-Errors#display-locked-error");
@ -1403,8 +1438,15 @@ int main(int argc, char* argv[])
sin.sin_addr = in4addr_loopback; sin.sin_addr = in4addr_loopback;
fprintf(LOG_OUT, "Testing GameStream ports via loopback\n"); fprintf(LOG_OUT, "Testing GameStream ports via loopback\n");
if (!TestAllPorts(&ss, nullptr, portMsgBuf, sizeof(portMsgBuf), false, true)) { if (!TestAllPorts(&ss, nullptr, portMsgBuf, sizeof(portMsgBuf), false, true)) {
snprintf(msgBuf, sizeof(msgBuf), if (gfeGameStreamRunning) {
"Local GameStream connectivity check failed.\n\nFirst, try reinstalling GeForce Experience. If that doesn't resolve the problem, try temporarily disabling your antivirus and firewall."); snprintf(msgBuf, sizeof(msgBuf),
"Local GameStream connectivity check failed.\n\nFirst, try reinstalling GeForce Experience. If that doesn't resolve the problem, try temporarily disabling your antivirus and firewall.");
}
else {
snprintf(msgBuf, sizeof(msgBuf),
"Local GameStream connectivity check failed.\n\nFirst, try restarting Sunshine. If that doesn't resolve the problem, try temporarily disabling your antivirus and firewall.\n\nNOTE: Sunshine must be configured to use the default 47989 port to test with this tool.");
}
DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting"); DisplayMessage(msgBuf, "https://github.com/moonlight-stream/moonlight-docs/wiki/Troubleshooting");
return -1; return -1;
} }