using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using Mono.Cecil; [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 2026")] [assembly: AssemblyDescription("RepoXR Preloader")] [assembly: AssemblyFileVersion("1.2.2.0")] [assembly: AssemblyInformationalVersion("1.2.2+b9a820e6a3701d416b6134275db93f484314aa13")] [assembly: AssemblyProduct("RepoXR.Preload")] [assembly: AssemblyTitle("RepoXR.Preload")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/DaXcess/RepoXR")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.2.2.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 RepoXR.Preload { public static class Preload { private const string VR_MANIFEST = "{\n \"name\": \"OpenXR XR Plugin\",\n \"version\": \"1.10.0\",\n \"libraryName\": \"UnityOpenXR\",\n \"displays\": [\n {\n \"id\": \"OpenXR Display\"\n }\n ],\n \"inputs\": [\n {\n \"id\": \"OpenXR Input\"\n }\n ]\n}"; private static readonly ManualLogSource Logger = Logger.CreateLogSource("RepoXR.Preload"); public static IEnumerable TargetDLLs { get; } = Array.Empty(); public static void Initialize() { SetupRuntimeAssets(); DiscoverGameVersion(); Logger.LogInfo((object)"We're done here. Goodbye!"); } private static void SetupRuntimeAssets() { Logger.LogInfo((object)"Setting up VR runtime assets"); string path = Path.Combine(Paths.GameRootPath, "REPO_Data"); string text = Path.Combine(path, "UnitySubsystems"); if (!Directory.Exists(text)) { Directory.CreateDirectory(text); } string text2 = Path.Combine(text, "UnityOpenXR"); if (!Directory.Exists(text2)) { Directory.CreateDirectory(text2); } string path2 = Path.Combine(text2, "UnitySubsystemsManifest.json"); if (!File.Exists(path2)) { File.WriteAllText(path2, "{\n \"name\": \"OpenXR XR Plugin\",\n \"version\": \"1.10.0\",\n \"libraryName\": \"UnityOpenXR\",\n \"displays\": [\n {\n \"id\": \"OpenXR Display\"\n }\n ],\n \"inputs\": [\n {\n \"id\": \"OpenXR Input\"\n }\n ]\n}"); } string path3 = Path.Combine(path, "Plugins"); string destFileName = Path.Combine(path3, "UnityOpenXR.dll"); string destFileName2 = Path.Combine(path3, "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 DiscoverGameVersion() { using (FileStream fileStream = File.OpenRead(Path.Combine(Paths.GameRootPath, "REPO_Data/sharedassets0.assets"))) { int num = FindOffset(fileStream) - 4; if (num < 0) { throw new ApplicationException("Unknown application version"); } fileStream.Seek(num, SeekOrigin.Begin); using BinaryReader binaryReader = new BinaryReader(fileStream, Encoding.ASCII); int count = binaryReader.ReadInt32(); string @string = Encoding.ASCII.GetString(binaryReader.ReadBytes(count)); if (!@string.StartsWith("Version - ")) { throw new ApplicationException("Unknown application version"); } fileStream.Position = checked(fileStream.Position + 3) & -4; count = binaryReader.ReadInt32(); string string2 = Encoding.ASCII.GetString(binaryReader.ReadBytes(count)); string text = @string.Split(" - ")[1]; Logger.LogInfo((object)("Version: " + text + " " + string2)); Environment.SetEnvironmentVariable("REPO_VERSION", string2); Environment.SetEnvironmentVariable("REPO_BRANCH", text); } static int FindOffset(FileStream stream) { byte[] bytes = Encoding.ASCII.GetBytes("Version - "); long num3 = stream.Length; Span span = stackalloc byte[4160]; Span destination = stackalloc byte[64]; int num4 = 0; while (num3 > 0) { int num5 = (int)Math.Min(4096L, num3); num3 -= num5; stream.Seek(num3, SeekOrigin.Begin); Span span2 = span.Slice(0, num5); stream.Read(span2); if (num4 > 0) { destination.Slice(0, num4).CopyTo(span.Slice(num5)); span2 = span.Slice(0, num5 + num4); } int num6 = LastIndexOf(span2, bytes); if (num6 >= 0) { return (int)num3 + num6; } num4 = Math.Min(bytes.Length - 1, num5); span2.Slice(0, num4).CopyTo(destination); } return -1; } static int LastIndexOf(ReadOnlySpan haystack, ReadOnlySpan needle) { if (needle.Length == 0) { return 0; } for (int num2 = haystack.Length - needle.Length; num2 >= 0; num2--) { while (num2 >= 0) { if (haystack[num2 + needle.Length - 1] == needle[needle.Length - 1]) { break; } num2--; } if (num2 < 0) { break; } if (haystack.Slice(num2, needle.Length).SequenceEqual(needle)) { return num2; } } return -1; } } public static void Patch(AssemblyDefinition assembly) { } } }