Skip to content

Commit

Permalink
separate isGameRunning and isGmaeNoVR
Browse files Browse the repository at this point in the history
  • Loading branch information
pypy-vrc committed Oct 25, 2020
1 parent e9f65f4 commit b15cf90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
43 changes: 25 additions & 18 deletions VRCX.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,31 +46,38 @@ public string LoginWithSteam()
: string.Empty;
}

public bool IsGameRunning()
public bool[] CheckGameRunning()
{
IntPtr hwnd = WinApi.FindWindow("UnityWndClass", "VRChat");
if (hwnd == IntPtr.Zero)
{
return false;
}
var isGameRunning = false;
var isGameNoVR = false;

String cmdline;
try
var hwnd = WinApi.FindWindow("UnityWndClass", "VRChat");
if (hwnd != IntPtr.Zero)
{
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())
var cmdline = string.Empty;
try
{
cmdline = objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString();
Int32 pid = 0;
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;
catch
{
}

isGameRunning = true;
isGameNoVR = cmdline.Contains("--no-vr");
}

return !cmdline.Contains("--no-vr");
return new bool[]
{
isGameRunning,
isGameNoVR
};
}

public void StartGame(string arguments)
Expand Down
9 changes: 6 additions & 3 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3272,6 +3272,7 @@ CefSharp.BindObjectAsync(
VRCX,
nextRefresh: 0,
isGameRunning: false,
isGameNoVR: false,
appVersion: 'VRCX 2020.07.13',
latestAppVersion: '',
ossDialog: false,
Expand Down Expand Up @@ -3378,11 +3379,12 @@ CefSharp.BindObjectAsync(
}
this.checkActiveFriends();
this.refreshGameLog();
VRCX.IsGameRunning().then((running) => {
if (running !== this.isGameRunning) {
this.isGameRunning = running;
VRCX.CheckGameRunning().then(([isGameRunning, isGameNoVR]) => {
if (isGameRunning !== this.isGameRunning) {
this.isGameRunning = isGameRunning;
Discord.SetTimestamps(Date.now(), 0);
}
this.isGameNoVR = isGameNoVR;
this.updateDiscord();
this.updateOpenVR();
});
Expand Down Expand Up @@ -5567,6 +5569,7 @@ CefSharp.BindObjectAsync(

$app.methods.updateOpenVR = function () {
if (this.openVR &&
this.isGameNoVR === false &&
(this.isGameRunning || this.openVRAlways)) {
VRCX.StartVR();
} else {
Expand Down

0 comments on commit b15cf90

Please sign in to comment.