using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using BepInEx; using BepInEx.Core.Logging.Interpolation; using BepInEx.Logging; using BepInEx.Preloader.Core.Patching; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")] [assembly: AssemblyCompany("BigWalkVR.Preloader")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+8ad43dab13c94973d321313b5f4f4c5eb9463976")] [assembly: AssemblyProduct("BigWalkVR.Preloader")] [assembly: AssemblyTitle("BigWalkVR.Preloader")] [assembly: AssemblyVersion("1.0.0.0")] namespace BigWalkVR { internal static class BigWalkVrLaunch { internal const string VrArgument = "-bigwalkvr-vr"; internal const string NonVrArgument = "-bigwalkvr-non-vr"; internal static bool IsVrMode(string[] arguments) { if (HasArgument(arguments, "-bigwalkvr-vr")) { return true; } if (HasArgument(arguments, "-bigwalkvr-non-vr")) { return false; } return Process.GetProcessesByName("vrserver").Length != 0; } internal static bool HasArgument(string[] arguments, string expected) { return arguments.Any((string argument) => string.Equals(argument, expected, StringComparison.OrdinalIgnoreCase)); } } internal static class BigWalkVrVersion { internal const string Value = "1.0.14"; } } namespace BigWalkVR.Preloader { [PatcherPluginInfo("com.circuit.bigwalkvr.preloader", "Big Walk VR Preloader", "1.0.14")] public sealed class BigWalkVrPreloader : BasePatcher { private const string RelaunchGuard = "BIGWALKVR_FORCE_D3D11_RELAUNCHED"; public override void Initialize() { EnsureDirectX11(); DeployRuntime(); ((BasePatcher)this).Log.LogInfo((object)"Big Walk VR runtime deployed."); } private void EnsureDirectX11() { //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Expected O, but got Unknown string[] commandLineArgs = Environment.GetCommandLineArgs(); if (!BigWalkVrLaunch.IsVrMode(commandLineArgs) || BigWalkVrLaunch.HasArgument(commandLineArgs, "-force-d3d11")) { return; } if (Environment.GetEnvironmentVariable("BIGWALKVR_FORCE_D3D11_RELAUNCHED") == "1") { ((BasePatcher)this).Log.LogWarning((object)"-force-d3d11 missing after relaunch; continuing on the current graphics API."); return; } string text = Process.GetCurrentProcess().MainModule?.FileName ?? commandLineArgs[0]; ProcessStartInfo processStartInfo = new ProcessStartInfo(); processStartInfo.FileName = text; processStartInfo.WorkingDirectory = Path.GetDirectoryName(text) ?? "."; processStartInfo.UseShellExecute = false; processStartInfo.EnvironmentVariables.Remove("DOORSTOP_DISABLE"); processStartInfo.EnvironmentVariables.Remove("DOORSTOP_INITIALIZED"); processStartInfo.EnvironmentVariables["BIGWALKVR_FORCE_D3D11_RELAUNCHED"] = "1"; processStartInfo.Arguments = BuildArguments(commandLineArgs.Skip(1).Append("-force-d3d11")); ManualLogSource log = ((BasePatcher)this).Log; bool flag = default(bool); BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(43, 1, ref flag); if (flag) { ((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Relaunching with -force-d3d11 for VR mode: "); ((BepInExLogInterpolatedStringHandler)val).AppendFormatted(text); } log.LogWarning(val); Process.Start(processStartInfo); Environment.Exit(0); } private static string BuildArguments(IEnumerable arguments) { StringBuilder stringBuilder = new StringBuilder(); foreach (string argument in arguments) { if (argument.IndexOfAny(new char[3] { ' ', '\t', '"' }) < 0) { stringBuilder.Append(argument); stringBuilder.Append(' '); continue; } stringBuilder.Append('"'); for (int i = 0; i < argument.Length; i++) { int num = 0; for (; i < argument.Length && argument[i] == '\\'; i++) { num++; } if (i == argument.Length) { stringBuilder.Append('\\', num * 2); break; } if (argument[i] == '"') { stringBuilder.Append('\\', num * 2 + 1); stringBuilder.Append('"'); } else { stringBuilder.Append('\\', num); stringBuilder.Append(argument[i]); } } stringBuilder.Append("\" "); } return stringBuilder.ToString().TrimEnd(); } private static void DeployRuntime() { string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "BigWalkVR.Runtime"); string[] files = Directory.GetFiles(text, "*", SearchOption.AllDirectories); foreach (string text2 in files) { string relativePath = Path.GetRelativePath(text, text2); string text3 = Path.Combine(Paths.GameRootPath, relativePath); Directory.CreateDirectory(Path.GetDirectoryName(text3)); if (!FilesMatch(text2, text3)) { File.Copy(text2, text3, overwrite: true); } } } private static bool FilesMatch(string sourcePath, string destinationPath) { if (!File.Exists(destinationPath)) { return false; } byte[] first = File.ReadAllBytes(sourcePath); byte[] second = File.ReadAllBytes(destinationPath); return first.SequenceEqual(second); } } }