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.Security; using System.Security.Permissions; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil; using MonoMod.RuntimeDetour; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("DaXcess")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyCopyright("Copyright (c) DaXcess 2025")] [assembly: AssemblyDescription("CWVR Preloader")] [assembly: AssemblyFileVersion("1.2.0.0")] [assembly: AssemblyInformationalVersion("1.2.0+43b532498b65068608dff19c997e64f84668f332")] [assembly: AssemblyProduct("CWVR.Preload")] [assembly: AssemblyTitle("CWVR.Preload")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/DaXcess/CWVR")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace CWVR.Preload { public class BepInExLogger : ILogger { private static ManualLogSource logSource = Logger.CreateLogSource("CWVR.Preload"); public void Log(object message) { logSource.LogInfo(message); } public void LogInfo(object message) { logSource.LogInfo(message); } public void LogWarning(object message) { logSource.LogWarning(message); } public void LogError(object message) { logSource.LogError(message); } public void LogDebug(object message) { logSource.LogDebug(message); } } public class NopLogger : ILogger { public void Log(object message) { } public void LogInfo(object message) { } public void LogWarning(object message) { } public void LogError(object message) { } public void LogDebug(object message) { } } public interface ILogger { void Log(object message); void LogInfo(object message); void LogWarning(object message); void LogError(object message); void LogDebug(object message); } public static class Preload { private const string VR_MANIFEST = "{\n \"name\": \"OpenXR XR Plugin\",\n \"version\": \"1.8.2\",\n \"libraryName\": \"UnityOpenXR\",\n \"displays\": [\n {\n \"id\": \"OpenXR Display\"\n }\n ],\n \"inputs\": [\n {\n \"id\": \"OpenXR Input\"\n }\n ]\n}"; private static Hook _getTypesHook; public static IEnumerable TargetDLLs { get; } = Array.Empty(); private static ILogger Logger { get; set; } = null; private static void PreloadInit() { Logger = new NopLogger(); InitializeMultiLoader(); PatchAssemblyTypeEnumerator(); } private static void Initialize() { Logger = new BepInExLogger(); InitializeMultiLoader(); } private static void InitializeMultiLoader() { Logger.Log("Setting up VR runtime assets"); SetupRuntimeAssets(); Logger.Log("We're done here. Goodbye!"); } private static void SetupRuntimeAssets() { SetupSubsystemAssets(); SetupPluginAssets(); } private static void SetupSubsystemAssets() { string text = Path.Combine(Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "Content Warning_Data"), "UnitySubsystems"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } string text2 = Path.Combine(text, "UnityOpenXR"); if (!Directory.Exists(text2)) { Directory.CreateDirectory(text2); } string path = Path.Combine(text2, "UnitySubsystemsManifest.json"); if (!File.Exists(path)) { File.WriteAllText(path, "{\n \"name\": \"OpenXR XR Plugin\",\n \"version\": \"1.8.2\",\n \"libraryName\": \"UnityOpenXR\",\n \"displays\": [\n {\n \"id\": \"OpenXR Display\"\n }\n ],\n \"inputs\": [\n {\n \"id\": \"OpenXR Input\"\n }\n ]\n}"); } } private static void SetupPluginAssets() { string path = Path.Combine(Path.Combine(Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName), "Content Warning_Data"), "Plugins"); string destFileName = Path.Combine(path, "UnityOpenXR.dll"); string destFileName2 = Path.Combine(path, "openxr_loader.dll"); string? directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string sourceFileName = Path.Combine(directoryName, "RuntimeDeps/UnityOpenXR.dll"); string sourceFileName2 = Path.Combine(directoryName, "RuntimeDeps/openxr_loader.dll"); File.Copy(sourceFileName, destFileName, overwrite: true); File.Copy(sourceFileName2, destFileName2, overwrite: true); } private static void PatchAssemblyTypeEnumerator() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown _getTypesHook = new Hook((MethodBase)typeof(Assembly).GetMethod("GetTypes", BindingFlags.Instance | BindingFlags.Public), typeof(Preload).GetMethod("GetTypesHooked")); } public static Type[] GetTypesHooked(Func orig, Assembly self) { try { return orig(self); } catch (ReflectionTypeLoadException ex) { return ex.Types.Where((Type t) => t != null).ToArray(); } } public static void Patch(AssemblyDefinition assembly) { } } }