mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-07 06:56:04 +02:00
Updates and fixes
This commit is contained in:
@@ -147,25 +147,6 @@ namespace VRCX
|
||||
VRCXVR.Instance.Restart();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of arrays containing information about the connected VR devices.
|
||||
/// Each sub-array contains the type of device and its current state
|
||||
/// </summary>
|
||||
/// <returns>An array of arrays containing information about the connected VR devices.</returns>
|
||||
public string[][] GetVRDevices()
|
||||
{
|
||||
return VRCXVR.Instance.GetDevices();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current CPU usage as a percentage.
|
||||
/// </summary>
|
||||
/// <returns>The current CPU usage as a percentage.</returns>
|
||||
public float CpuUsage()
|
||||
{
|
||||
return CpuMonitor.Instance.CpuUsage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves an image from the VRChat API and caches it for future use. The function will return the cached image if it already exists.
|
||||
/// </summary>
|
||||
@@ -352,19 +333,6 @@ namespace VRCX
|
||||
WinformThemer.DoFunny();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of milliseconds that the system has been running.
|
||||
/// </summary>
|
||||
/// <returns>The number of milliseconds that the system has been running.</returns>
|
||||
public double GetUptime()
|
||||
{
|
||||
using (var uptime = new PerformanceCounter("System", "System Up Time"))
|
||||
{
|
||||
uptime.NextValue();
|
||||
return TimeSpan.FromSeconds(uptime.NextValue()).TotalMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a color value derived from the given user ID.
|
||||
/// This is, essentially, and is used for, random colors.
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using CefSharp;
|
||||
|
||||
namespace VRCX
|
||||
{
|
||||
public class AppApiVr
|
||||
{
|
||||
public static readonly AppApiVr Instance;
|
||||
|
||||
static AppApiVr()
|
||||
{
|
||||
Instance = new AppApiVr();
|
||||
}
|
||||
|
||||
public void VrInit()
|
||||
{
|
||||
if (MainForm.Instance?.Browser != null && !MainForm.Instance.Browser.IsLoading && MainForm.Instance.Browser.CanExecuteJavascriptInMainFrame)
|
||||
MainForm.Instance.Browser.ExecuteScriptAsync("$app.vrInit", "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current CPU usage as a percentage.
|
||||
/// </summary>
|
||||
/// <returns>The current CPU usage as a percentage.</returns>
|
||||
public float CpuUsage()
|
||||
{
|
||||
return CpuMonitor.Instance.CpuUsage;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an array of arrays containing information about the connected VR devices.
|
||||
/// Each sub-array contains the type of device and its current state
|
||||
/// </summary>
|
||||
/// <returns>An array of arrays containing information about the connected VR devices.</returns>
|
||||
public string[][] GetVRDevices()
|
||||
{
|
||||
return VRCXVR.Instance.GetDevices();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of milliseconds that the system has been running.
|
||||
/// </summary>
|
||||
/// <returns>The number of milliseconds that the system has been running.</returns>
|
||||
public double GetUptime()
|
||||
{
|
||||
using var uptime = new PerformanceCounter("System", "System Up Time");
|
||||
uptime.NextValue();
|
||||
return TimeSpan.FromSeconds(uptime.NextValue()).TotalMilliseconds;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current language of the operating system.
|
||||
/// </summary>
|
||||
/// <returns>The current language of the operating system.</returns>
|
||||
public string CurrentCulture()
|
||||
{
|
||||
return CultureInfo.CurrentCulture.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,51 +58,52 @@ namespace VRCX
|
||||
/// Starts the VRChat game process with the specified command-line arguments.
|
||||
/// </summary>
|
||||
/// <param name="arguments">The command-line arguments to pass to the VRChat game.</param>
|
||||
public void StartGame(string arguments)
|
||||
public bool StartGame(string arguments)
|
||||
{
|
||||
// try stream first
|
||||
try
|
||||
{
|
||||
using (var key = Registry.ClassesRoot.OpenSubKey(@"steam\shell\open\command"))
|
||||
using var key = Registry.ClassesRoot.OpenSubKey(@"steam\shell\open\command");
|
||||
// "C:\Program Files (x86)\Steam\steam.exe" -- "%1"
|
||||
var match = Regex.Match(key.GetValue(string.Empty) as string, "^\"(.+?)\\\\steam.exe\"");
|
||||
if (match.Success)
|
||||
{
|
||||
// "C:\Program Files (x86)\Steam\steam.exe" -- "%1"
|
||||
var match = Regex.Match(key.GetValue(string.Empty) as string, "^\"(.+?)\\\\steam.exe\"");
|
||||
if (match.Success)
|
||||
{
|
||||
var path = match.Groups[1].Value;
|
||||
// var _arguments = Uri.EscapeDataString(arguments);
|
||||
Process.Start(new ProcessStartInfo
|
||||
var path = match.Groups[1].Value;
|
||||
// var _arguments = Uri.EscapeDataString(arguments);
|
||||
Process.Start(new ProcessStartInfo
|
||||
{
|
||||
WorkingDirectory = path,
|
||||
FileName = $"{path}\\steam.exe",
|
||||
UseShellExecute = false,
|
||||
Arguments = $"-applaunch 438100 {arguments}"
|
||||
}).Close();
|
||||
return;
|
||||
}
|
||||
})
|
||||
?.Close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
logger.Warn("Failed to start VRChat from Steam");
|
||||
}
|
||||
|
||||
// fallback
|
||||
try
|
||||
{
|
||||
using (var key = Registry.ClassesRoot.OpenSubKey(@"VRChat\shell\open\command"))
|
||||
using var key = Registry.ClassesRoot.OpenSubKey(@"VRChat\shell\open\command");
|
||||
// "C:\Program Files (x86)\Steam\steamapps\common\VRChat\launch.exe" "%1" %*
|
||||
var match = Regex.Match(key.GetValue(string.Empty) as string, "(?!\")(.+?\\\\VRChat.*)(!?\\\\launch.exe\")");
|
||||
if (match.Success)
|
||||
{
|
||||
// "C:\Program Files (x86)\Steam\steamapps\common\VRChat\launch.exe" "%1" %*
|
||||
var match = Regex.Match(key.GetValue(string.Empty) as string, "(?!\")(.+?\\\\VRChat.*)(!?\\\\launch.exe\")");
|
||||
if (match.Success)
|
||||
{
|
||||
var path = match.Groups[1].Value;
|
||||
StartGameFromPath(path, arguments);
|
||||
}
|
||||
var path = match.Groups[1].Value;
|
||||
return StartGameFromPath(path, arguments);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
logger.Warn("Failed to start VRChat from registry");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -116,7 +117,7 @@ namespace VRCX
|
||||
if (!path.EndsWith(".exe"))
|
||||
path = Path.Combine(path, "launch.exe");
|
||||
|
||||
if (!File.Exists(path))
|
||||
if (!path.EndsWith("launch.exe") || !File.Exists(path))
|
||||
return false;
|
||||
|
||||
Process.Start(new ProcessStartInfo
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
using System;
|
||||
using CefSharp;
|
||||
|
||||
namespace VRCX
|
||||
{
|
||||
public static class Util
|
||||
public static class JavascriptBindings
|
||||
{
|
||||
public static void ApplyJavascriptBindings(IJavascriptObjectRepository repository)
|
||||
public static void ApplyAppJavascriptBindings(IJavascriptObjectRepository repository)
|
||||
{
|
||||
repository.NameConverter = null;
|
||||
repository.Register("AppApi", AppApi.Instance);
|
||||
@@ -17,5 +16,11 @@ namespace VRCX
|
||||
repository.Register("Discord", Discord.Instance);
|
||||
repository.Register("AssetBundleCacher", AssetBundleCacher.Instance);
|
||||
}
|
||||
|
||||
public static void ApplyVrJavascriptBindings(IJavascriptObjectRepository repository)
|
||||
{
|
||||
repository.NameConverter = null;
|
||||
repository.Register("AppApiVr", AppApiVr.Instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -63,7 +63,7 @@ namespace VRCX
|
||||
Browser.ShowDevTools();
|
||||
};
|
||||
|
||||
Util.ApplyJavascriptBindings(Browser.JavascriptObjectRepository);
|
||||
JavascriptBindings.ApplyAppJavascriptBindings(Browser.JavascriptObjectRepository);
|
||||
Browser.ConsoleMessage += (_, args) =>
|
||||
{
|
||||
jslogger.Debug(args.Message + " (" + args.Source + ":" + args.Line + ")");
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace VRCX
|
||||
Size = new System.Drawing.Size(width, height);
|
||||
RenderHandler = this;
|
||||
|
||||
Util.ApplyJavascriptBindings(JavascriptObjectRepository);
|
||||
JavascriptBindings.ApplyVrJavascriptBindings(JavascriptObjectRepository);
|
||||
}
|
||||
|
||||
public new void Dispose()
|
||||
|
||||
@@ -45,8 +45,8 @@ namespace VRCX
|
||||
Dock = DockStyle.Fill
|
||||
};
|
||||
|
||||
Util.ApplyJavascriptBindings(_browser1.JavascriptObjectRepository);
|
||||
Util.ApplyJavascriptBindings(_browser2.JavascriptObjectRepository);
|
||||
JavascriptBindings.ApplyVrJavascriptBindings(_browser1.JavascriptObjectRepository);
|
||||
JavascriptBindings.ApplyVrJavascriptBindings(_browser2.JavascriptObjectRepository);
|
||||
|
||||
panel1.Controls.Add(_browser1);
|
||||
panel2.Controls.Add(_browser2);
|
||||
|
||||
@@ -13,26 +13,41 @@ namespace VRCX
|
||||
{
|
||||
public class WorldDBManager
|
||||
{
|
||||
public static WorldDBManager Instance;
|
||||
public static readonly WorldDBManager Instance;
|
||||
private readonly HttpListener listener;
|
||||
private readonly WorldDatabase worldDB;
|
||||
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
||||
private const string WorldDBServerUrl = "http://127.0.0.1:22500/";
|
||||
|
||||
private string lastError = null;
|
||||
private bool debugWorld = false;
|
||||
|
||||
public WorldDBManager(string url)
|
||||
static WorldDBManager()
|
||||
{
|
||||
Instance = new WorldDBManager();
|
||||
}
|
||||
|
||||
public WorldDBManager()
|
||||
{
|
||||
Instance = this;
|
||||
// http://localhost:22500
|
||||
listener = new HttpListener();
|
||||
listener.Prefixes.Add(url);
|
||||
listener.Prefixes.Add(WorldDBServerUrl);
|
||||
|
||||
worldDB = new WorldDatabase(Path.Combine(Program.AppDataDirectory, "VRCX-WorldData.db"));
|
||||
|
||||
}
|
||||
|
||||
public async Task Start()
|
||||
public void Init()
|
||||
{
|
||||
if (VRCXStorage.Instance.Get("VRCX_DisableWorldDatabase") == "true")
|
||||
{
|
||||
logger.Info("World database is disabled. Not starting.");
|
||||
return;
|
||||
}
|
||||
|
||||
Task.Run(Start);
|
||||
}
|
||||
|
||||
private async Task Start()
|
||||
{
|
||||
// typing this in vr gonna kms
|
||||
try
|
||||
@@ -223,9 +238,13 @@ namespace VRCX
|
||||
}
|
||||
|
||||
var worldOverride = request.QueryString["world"];
|
||||
if (worldOverride == "global")
|
||||
{
|
||||
TryInitializeWorld(worldOverride, out connectionKey);
|
||||
}
|
||||
if (worldOverride != null && worldId != worldOverride)
|
||||
{
|
||||
var allowed = worldDB.GetWorldAllowExternalRead(worldOverride);
|
||||
var allowed = worldDB.GetWorldAllowExternalRead(worldOverride) || worldOverride == "global";
|
||||
if (!allowed)
|
||||
{
|
||||
return ConstructSuccessResponse(null, connectionKey);
|
||||
@@ -262,9 +281,13 @@ namespace VRCX
|
||||
}
|
||||
|
||||
var worldOverride = request.QueryString["world"];
|
||||
if (worldOverride == "global")
|
||||
{
|
||||
TryInitializeWorld(worldOverride, out connectionKey);
|
||||
}
|
||||
if (worldOverride != null && worldId != worldOverride)
|
||||
{
|
||||
var allowed = worldDB.GetWorldAllowExternalRead(worldOverride);
|
||||
var allowed = worldDB.GetWorldAllowExternalRead(worldOverride) || worldOverride == "global";
|
||||
if (!allowed)
|
||||
{
|
||||
return ConstructSuccessResponse(null, connectionKey);
|
||||
@@ -319,9 +342,13 @@ namespace VRCX
|
||||
}
|
||||
|
||||
var worldOverride = request.QueryString["world"];
|
||||
if (worldOverride == "global")
|
||||
{
|
||||
TryInitializeWorld(worldOverride, out connectionKey);
|
||||
}
|
||||
if (worldOverride != null && worldId != worldOverride)
|
||||
{
|
||||
var allowed = worldDB.GetWorldAllowExternalRead(worldOverride);
|
||||
var allowed = worldDB.GetWorldAllowExternalRead(worldOverride) || worldOverride == "global";
|
||||
if (!allowed)
|
||||
{
|
||||
return ConstructSuccessResponse(null, connectionKey);
|
||||
@@ -526,8 +553,6 @@ namespace VRCX
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Make sure the connection key is a valid GUID. No point in doing anything else if it's not.
|
||||
if (!debugWorld && !Guid.TryParse(request.ConnectionKey, out Guid _))
|
||||
{
|
||||
@@ -539,6 +564,12 @@ namespace VRCX
|
||||
|
||||
// Get the world ID from the connection key
|
||||
string worldId = worldDB.GetWorldByConnectionKey(request.ConnectionKey);
|
||||
|
||||
// Global override
|
||||
if (request.ConnectionKey == "global")
|
||||
{
|
||||
worldId = "global";
|
||||
}
|
||||
|
||||
// World ID is null, which means the connection key is invalid (or someone just deleted a world from the DB while VRCX was running lol).
|
||||
if (worldId == null)
|
||||
|
||||
+3
-5
@@ -135,16 +135,14 @@ namespace VRCX
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
logger.Info("{0} Starting...", Version);
|
||||
|
||||
// I'll re-do this whole function eventually I swear
|
||||
var worldDBServer = new WorldDBManager("http://127.0.0.1:22500/");
|
||||
Task.Run(worldDBServer.Start);
|
||||
|
||||
|
||||
ProcessMonitor.Instance.Init();
|
||||
SQLiteLegacy.Instance.Init();
|
||||
VRCXStorage.Load();
|
||||
CpuMonitor.Instance.Init();
|
||||
Discord.Instance.Init();
|
||||
WorldDBManager.Instance.Init();
|
||||
WebApi.Instance.Init();
|
||||
LogWatcher.Instance.Init();
|
||||
AutoAppLaunchManager.Instance.Init();
|
||||
@@ -161,7 +159,7 @@ namespace VRCX
|
||||
AutoAppLaunchManager.Instance.Exit();
|
||||
LogWatcher.Instance.Exit();
|
||||
WebApi.Instance.Exit();
|
||||
worldDBServer.Stop();
|
||||
WorldDBManager.Instance.Stop();
|
||||
|
||||
Discord.Instance.Exit();
|
||||
CpuMonitor.Instance.Exit();
|
||||
|
||||
Reference in New Issue
Block a user