don't attempt to start steam overlay when vrchat is running with --no-vr

This commit is contained in:
Katie Holly
2020-10-17 09:52:43 +02:00
parent 69ee901dd0
commit e2f732b173
2 changed files with 29 additions and 2 deletions

28
VRCX.cs
View File

@@ -1,4 +1,4 @@
// Copyright(c) 2019 pypy. All rights reserved.
// Copyright(c) 2019-2020 pypy. All rights reserved.
//
// This work is licensed under the terms of the MIT license.
// For a copy, see <https://opensource.org/licenses/MIT>.
@@ -7,6 +7,8 @@ using CefSharp;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Text.RegularExpressions;
using System.Windows.Forms;
@@ -46,7 +48,29 @@ namespace VRCX
public bool IsGameRunning()
{
return WinApi.FindWindow("UnityWndClass", "VRChat") != IntPtr.Zero;
IntPtr hwnd = WinApi.FindWindow("UnityWndClass", "VRChat");
if (hwnd == IntPtr.Zero)
{
return false;
}
String cmdline;
try
{
Int32 pid;
WinApi.GetWindowThreadProcessId(hwnd, out pid);
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + pid))
using (ManagementObjectCollection objects = searcher.Get())
{
cmdline = objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString();
}
}
catch
{
return false;
}
return !cmdline.Contains("--no-vr");
}
public void StartGame(string arguments)

View File

@@ -15,5 +15,8 @@ namespace VRCX
[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", SetLastError = true)]
public static extern UInt32 GetWindowThreadProcessId(IntPtr hWnd, out Int32 lpdwProcessId);
}
}