using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using Unity.XR.OpenVR; using UnityEngine; using UnityEngine.Events; using UnityEngine.Rendering; using UnityEngine.UI; using UnityEngine.XR.Management; using UnityEngine.XR.OpenXR; using Uuvr.UnityTypesHelper; using Uuvr.VrCamera; using Uuvr.VrTogglers; using Uuvr.VrUi; using Uuvr.VrUi.PatchModes; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = "")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.0")] [module: UnverifiableCode] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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; } } } namespace Uuvr { public class FollowTarget : UuvrBehaviour { public Transform? Target; public Vector3 LocalPosition = Vector3.zero; public Quaternion LocalRotation = Quaternion.identity; protected override void OnBeforeRender() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)Target == (Object)null)) { ((Component)this).transform.position = Target.TransformPoint(LocalPosition); ((Component)this).transform.rotation = Target.rotation * LocalRotation; } } } public class KeyboardKey { public enum KeyCode { F2 = 113, F3, F4, F5 } private bool _previousIsKeyPressed; private bool _isKeyPressed; private readonly KeyCode _keyCode; public KeyboardKey(KeyCode keyCode) { _keyCode = keyCode; } public bool UpdateIsDown() { _previousIsKeyPressed = _isKeyPressed; _isKeyPressed = ((ushort)GetKeyState((int)_keyCode) & 0x8000) != 0; return !_previousIsKeyPressed && _isKeyPressed; } [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] private static extern short GetKeyState(int keyCode); } public static class LayerHelper { private static int _freeLayer = -1; private static int FindFreeLayer() { for (int num = 31; num >= 0; num--) { if (LayerMask.LayerToName(num).Length == 0) { Debug.Log((object)$"Found free layer: {num}"); return num; } } Debug.LogWarning((object)"Failed to find a free layer to use for VR UI. Falling back to last layer."); return 31; } private static int GetFreeLayerCached() { if (_freeLayer == -1) { _freeLayer = FindFreeLayer(); } return _freeLayer; } public static int GetVrUiLayer() { int value = ModConfiguration.Instance.VrUiLayerOverride.Value; return (value > -1) ? value : GetFreeLayerCached(); } public static void SetLayerRecursive(Transform transform, int layer) { for (int i = 0; i < transform.childCount; i++) { Transform child = transform.GetChild(i); SetLayerRecursive(child, layer); ((Component)transform).gameObject.layer = layer; } } } public class ModConfiguration { public enum CameraTrackingMode { [Description("Absolute")] Absolute, [Description("Relative matrix")] RelativeMatrix, [Description("Relative Transform")] RelativeTransform, [Description("Child")] Child } public enum VrApi { [Description("OpenVR")] OpenVr, [Description("OpenXR")] OpenXr } public enum ScreenSpaceCanvasType { [Description("None")] None, [Description("Not rendering to texture")] NotToTexture, [Description("All")] All } public enum UiRenderMode { [Description("Overlay camera (draws on top of everything)")] OverlayCamera, [Description("In world (can be occluded)")] InWorld } public enum UiPatchMode { [Description("Don't touch UI")] None, [Description("Mirror flat screen (game not mirrored)")] Mirror, [Description("Patch Canvas objects")] CanvasRedirect } public static ModConfiguration Instance; public readonly ConfigFile Config; public readonly ConfigEntry CameraTracking; public readonly ConfigEntry RelativeCameraSetStereoView; public readonly ConfigEntry VrCameraDepth; public readonly ConfigEntry VrUiLayerOverride; public readonly ConfigEntry VrUiPosition; public readonly ConfigEntry VrUiScale; public readonly ConfigEntry VrUiShader; public readonly ConfigEntry VrUiRenderQueue; public readonly ConfigEntry AlignCameraToHorizon; public readonly ConfigEntry CameraPositionOffsetX; public readonly ConfigEntry CameraPositionOffsetY; public readonly ConfigEntry CameraPositionOffsetZ; public readonly ConfigEntry OverrideDepth; public readonly ConfigEntry PhysicsMatchHeadsetRefreshRate; public readonly ConfigEntry PreferredUiPatchMode; public readonly ConfigEntry PreferredUiRenderMode; public readonly ConfigEntry ScreenSpaceCanvasTypesToPatch; public readonly ConfigEntry ObjectsToDeactivateByComponent; public readonly ConfigEntry ComponentsToDisable; public readonly ConfigEntry ComponentSearchInterval; public readonly ConfigEntry PreferredVrApi; public ModConfiguration(ConfigFile config) { //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Expected O, but got Unknown //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Expected O, but got Unknown //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_0230: Expected O, but got Unknown //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e1: Expected O, but got Unknown Instance = this; Config = config; PreferredVrApi = config.Bind("General", "Preferred VR APi", VrApi.OpenXr, "VR API to use. Depending on the game, some APIs might be unavailable, so UUVR will fall back to one that works."); CameraTracking = config.Bind("Camera", "Camera Tracking Mode", CameraTrackingMode.RelativeTransform, "Defines how camera tracking is done. Relative is usually preferred, but not all games support it. Changing this might require restarting the level."); RelativeCameraSetStereoView = config.Bind("Relative Camera", "Use SetStereoView for Relative Camera", false, "Some games are better with this on, some are better with this off. Just try it and see which one is better. Changing this might require restarting the level."); AlignCameraToHorizon = config.Bind("Camera", "Align To Horizon", false, "Prevents pitch and roll changes on the camera, allowing only yaw changes."); CameraPositionOffsetX = config.Bind("Camera", "Camera Position Offset X", 0f, "Changes position of tracked VR cameras"); CameraPositionOffsetY = config.Bind("Camera", "Camera Position Offset Y", 0f, "Changes position of tracked VR cameras"); CameraPositionOffsetZ = config.Bind("Camera", "Camera Position Offset Z", 0f, "Changes position of tracked VR cameras"); OverrideDepth = config.Bind("Camera", "Override Depth", false, "In some games, the VR camera won't display anything unless we override the camera depth value."); VrCameraDepth = config.Bind("Camera", "Depth Value", 1, new ConfigDescription("Requires enabling 'Override Depth'. Range is -100 to 100, but you should try to find the lowest value that fixes visibility.", (AcceptableValueBase)(object)new AcceptableValueRange(-100, 100), Array.Empty())); PhysicsMatchHeadsetRefreshRate = config.Bind("General", "Force physics rate to match headset refresh rate", false, "Can help fix jiterriness in games that rely a lot on physics. Might break a lot of games too."); PreferredUiPatchMode = config.Bind("UI", "UI Patch Mode", UiPatchMode.Mirror, "Method to use for patching UI for VR."); VrUiLayerOverride = config.Bind("UI", "VR UI Layer Override", -1, new ConfigDescription("Layer to use for VR UI. By default (value -1) UUVR falls back to an unused (unnamed) layer.", (AcceptableValueBase)(object)new AcceptableValueRange(-1, 31), Array.Empty())); VrUiPosition = config.Bind("UI", "VR UI Position", Vector3.forward * 1f, "Position of the VR UI projection relative to the camera."); VrUiScale = config.Bind("UI", "VR UI Scale", 1f, "Scale of the VR UI projection."); VrUiShader = config.Bind("UI", "VR UI Shader", "", "Name of shader to use for the VR UI projection (passed to Unity's Shader.Find). Leave empty to let UUVR pick for you."); VrUiRenderQueue = config.Bind("UI", "VR UI Render Queue", 5000, new ConfigDescription("Render queue to use for the VR UI projection. Default is 5000, which is the same as Unity's default canvas material.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 5000), Array.Empty())); ScreenSpaceCanvasTypesToPatch = config.Bind("UI", "Screen-space UI Elements to Patch", ScreenSpaceCanvasType.NotToTexture, "Screen-space UI elements are already visible in VR with no patches. But in some games, they are difficult to see in VR. So you can choose to patch some (or all) of them to be rendered in the VR UI screen."); PreferredUiRenderMode = config.Bind("UI", "Preferred UI Plane Render Mode", UiRenderMode.InWorld, "How to render the VR UI Plane. Overlay is usually better, but doesn't work in every game."); ObjectsToDeactivateByComponent = config.Bind("Fixes", "Objects to Deactivate by Component", "", "Any objects that contains one of these components gets deactivated. List of fully qualified C# type names, separated by /. Example: 'Canvas, UnityEngine/HUD, Assembly-CSharp'"); ComponentsToDisable = config.Bind("Fixes", "Components to Disable.", "", "Names of components to disable. List of fully qualified C# type names, separated by /. Example: 'Canvas, UnityEngine/HUD, Assembly-CSharp'"); ComponentSearchInterval = config.Bind("Fixes", "Component Search Interval", 1f, new ConfigDescription("Value in seconds, the interval between searches for components to disable.", (AcceptableValueBase)(object)new AcceptableValueRange(0.5f, 30f), Array.Empty())); } } [HarmonyPatch] public static class Patches { public static Vector3 hehe = Vector3.one * 0.5f; [HarmonyPrefix] [HarmonyPatch(typeof(Camera), "set_fieldOfView")] private static bool PreventChangingFov() { return false; } } public class ThingDisabler : UuvrBehaviour { private float _previousSearchTime; protected override void Awake() { base.Awake(); OnSettingChanged(); } private void Update() { if (!(Time.unscaledTime < _previousSearchTime + ModConfiguration.Instance.ComponentSearchInterval.Value)) { _previousSearchTime = Time.unscaledTime; SearchAndDisableComponents(); } } private static void SearchAndDisableComponents() { try { DeactivateObjectsByComponent(); DisableComponents(); } catch (Exception ex) { Debug.LogError((object)("[ThingDisabler] Error during component search: " + ex.Message)); } } private static IEnumerable? FindObjects(string componentNamesString) { if (Utility.IsNullOrWhiteSpace(componentNamesString)) { return null; } return (from name in componentNamesString.Split('/') select name.Trim() into name where !string.IsNullOrEmpty(name) select name).SelectMany(delegate(string name) { Type type = Type.GetType(name); return Object.FindObjectsOfType(type); }); } private static void DeactivateObjectsByComponent() { //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Expected O, but got Unknown IEnumerable enumerable = FindObjects(ModConfiguration.Instance.ObjectsToDeactivateByComponent.Value); if (enumerable == null) { return; } foreach (Object item in enumerable) { PropertyInfo property = ((object)item).GetType().GetProperty("gameObject", BindingFlags.Instance | BindingFlags.Public); if (!(property == null)) { GameObject val = (GameObject)property.GetValue(item); if (!((Object)(object)val == (Object)null)) { val.SetActive(false); } } } } private static void DisableComponents() { IEnumerable enumerable = FindObjects(ModConfiguration.Instance.ComponentsToDisable.Value); if (enumerable == null) { return; } foreach (Object item in enumerable) { Type type = ((object)item).GetType(); PropertyInfo property = type.GetProperty("enabled", BindingFlags.Instance | BindingFlags.Public); if (property == null || !property.CanWrite || property.PropertyType != typeof(bool)) { break; } property.SetValue(item, false); } } } public static class TypeExtensions { private const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static MemberInfo? GetAnyMember(this Type type, string name) { return type.GetMember(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault() ?? type.BaseType?.GetMember(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault() ?? type.BaseType?.BaseType?.GetMember(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(); } public static T? GetValue(this object obj, string name) { MemberInfo anyMember = obj.GetType().GetAnyMember(name); if (!(anyMember is FieldInfo fieldInfo)) { if (anyMember is PropertyInfo propertyInfo) { return (T)propertyInfo.GetValue(obj, null); } return default(T); } return (T)fieldInfo.GetValue(obj); } public static void SetValue(this object obj, string name, object value) { MemberInfo anyMember = obj.GetType().GetAnyMember(name); MemberInfo memberInfo = anyMember; if (!(memberInfo is FieldInfo fieldInfo)) { if (memberInfo is PropertyInfo propertyInfo) { propertyInfo.SetValue(obj, value, null); } } else { fieldInfo.SetValue(obj, value); } } } public class UuvrBehaviour : MonoBehaviour { public static T Create(Transform parent) where T : UuvrBehaviour { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(typeof(T).Name); val.transform.parent = parent; val.transform.localPosition = Vector3.zero; val.transform.localRotation = Quaternion.identity; return val.AddComponent(); } protected virtual void Awake() { } protected virtual void OnEnable() { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown Application.onBeforeRender += new UnityAction(OnBeforeRender); RenderPipelineManager.beginFrameRendering += OnBeginFrameRendering; RenderPipelineManager.endFrameRendering += OnEndFrameRendering; ModConfiguration.Instance.Config.SettingChanged += ConfigOnSettingChanged; } protected virtual void OnDisable() { //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown Application.onBeforeRender -= new UnityAction(OnBeforeRender); RenderPipelineManager.beginFrameRendering -= OnBeginFrameRendering; RenderPipelineManager.endFrameRendering -= OnEndFrameRendering; ModConfiguration.Instance.Config.SettingChanged -= ConfigOnSettingChanged; } private void ConfigOnSettingChanged(object sender, SettingChangedEventArgs e) { OnSettingChanged(); } protected virtual void OnBeforeRender() { } protected virtual void OnSettingChanged() { } private void OnBeginFrameRendering(ScriptableRenderContext arg1, Camera[] arg2) { OnBeginFrameRendering(); } private void OnEndFrameRendering(ScriptableRenderContext arg1, Camera[] arg2) { OnEndFrameRendering(); } protected virtual void OnBeginFrameRendering() { } protected virtual void OnEndFrameRendering() { } } public class UuvrCore : MonoBehaviour { private float _originalFixedDeltaTime; private VrUiManager? _vrUi; private ThingDisabler? _thingDisabler; private PropertyInfo? _refreshRateProperty; private VrTogglerManager? _vrTogglerManager; private static bool _isQuitting; public static void Create() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) new GameObject("UUVR").AddComponent(); } private void Awake() { Application.quitting -= OnApplicationQuitting; Application.quitting += OnApplicationQuitting; Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject); ((Component)this).gameObject.AddComponent(); } private static void OnApplicationQuitting() { _isQuitting = true; } private void OnDestroy() { if (!_isQuitting) { Debug.Log((object)"UUVR has been destroyed. This shouldn't have happened. Recreating..."); Create(); } } private void Start() { _refreshRateProperty = (Type.GetType("UnityEngine.XR.XRDevice, UnityEngine.XRModule") ?? Type.GetType("UnityEngine.XR.XRDevice, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.VRDevice, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.VRDevice, UnityEngine"))?.GetProperty("refreshRate"); _vrUi = UuvrBehaviour.Create(((Component)this).transform); _thingDisabler = UuvrBehaviour.Create(((Component)this).transform); _vrTogglerManager = new VrTogglerManager(); SetPositionTrackingEnabled(positionTrackingEnabled: false); } private void Update() { UpdatePhysicsRate(); } private void UpdatePhysicsRate() { if (_originalFixedDeltaTime == 0f) { _originalFixedDeltaTime = Time.fixedDeltaTime; } if (_refreshRateProperty == null) { return; } float num = (float)_refreshRateProperty.GetValue(null, null); if (!(num <= 0f)) { if (ModConfiguration.Instance.PhysicsMatchHeadsetRefreshRate.Value) { Time.fixedDeltaTime = 1f / (float)_refreshRateProperty.GetValue(null, null); } else { Time.fixedDeltaTime = _originalFixedDeltaTime; } } } private static void SetPositionTrackingEnabled(bool positionTrackingEnabled) { Type type = Type.GetType("UnityEngine.XR.InputTracking, UnityEngine.XRModule") ?? Type.GetType("UnityEngine.XR.InputTracking, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.InputTracking, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.InputTracking, UnityEngine"); if (type != null) { PropertyInfo property = type.GetProperty("disablePositionalTracking"); if (property != null) { property.SetValue(null, !positionTrackingEnabled, null); } else { Debug.LogWarning((object)"Failed to get property disablePositionalTracking"); } } else { Debug.LogWarning((object)"Failed to get type UnityEngine.XR.InputTracking"); } } } [BepInPlugin("raicuparta.uuvr-modern", "UUVR", "0.4.0")] public class UuvrPlugin : BaseUnityPlugin { private static UuvrPlugin _instance; public static string ModFolderPath { get; private set; } private void Awake() { _instance = this; ModFolderPath = Path.GetDirectoryName(Assembly.GetAssembly(typeof(UuvrPlugin)).Location); new ModConfiguration(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null); UuvrCore.Create(); } } public class UuvrPoseDriver : UuvrBehaviour { private MethodInfo? _trackingRotationMethod; private readonly object[] _trackingRotationMethodArgs = new object[1] { 2 }; protected override void Awake() { base.Awake(); _trackingRotationMethod = (Type.GetType("UnityEngine.XR.InputTracking, UnityEngine.XRModule") ?? Type.GetType("UnityEngine.XR.InputTracking, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.InputTracking, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.InputTracking, UnityEngine"))?.GetMethod("GetLocalRotation"); if (_trackingRotationMethod == null) { Debug.LogError((object)"Failed to find InputTracking.GetLocalRotation. Destroying UUVR Pose Driver."); Object.Destroy((Object)(object)this); } else { DisableCameraAutoTracking(); } } protected override void OnBeforeRender() { base.OnBeforeRender(); UpdateTransform(); } private void Update() { UpdateTransform(); } private void LateUpdate() { UpdateTransform(); } private void UpdateTransform() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (_trackingRotationMethod != null) { ((Component)this).transform.localRotation = (Quaternion)_trackingRotationMethod.Invoke(null, _trackingRotationMethodArgs); } } private void DisableCameraAutoTracking() { Camera component = ((Component)this).GetComponent(); if (Object.op_Implicit((Object)(object)component)) { MethodInfo methodInfo = UuvrXrDevice.XrDeviceType?.GetMethod("DisableAutoXRCameraTracking"); if (methodInfo != null) { methodInfo.Invoke(null, new object[2] { component, true }); } else { Debug.LogWarning((object)"Failed to find DisableAutoXRCameraTracking method. Using SetStereoViewMatrix, which also prevents Unity from auto-tracking cameras, but can cause other issues."); } } } } } namespace Uuvr.VrUi { public class UiOverlayRenderMode : UuvrBehaviour { private Camera? _uiSceneCamera; protected override void OnSettingChanged() { base.OnSettingChanged(); _uiSceneCamera.cullingMask = 1 << LayerHelper.GetVrUiLayer(); } private new void Awake() { _uiSceneCamera = ((Component)UuvrBehaviour.Create(((Component)this).transform)).gameObject.AddComponent(); Uuvr.VrCamera.VrCamera.IgnoredCameras.Add(_uiSceneCamera); _uiSceneCamera.clearFlags = (CameraClearFlags)3; _uiSceneCamera.depth = 100f; _uiSceneCamera.cullingMask = 1 << LayerHelper.GetVrUiLayer(); } } public static class UiSorting { public const int ScreenOrder = 32765; private static int? _lastLayerId; public static int LastLayerId { get { if (!_lastLayerId.HasValue) { SortingLayer[] layers = SortingLayer.layers; _lastLayerId = ((layers.Length != 0) ? ((SortingLayer)(ref layers[^1])).id : 0); } return _lastLayerId.Value; } } public static void DrawLast(Renderer renderer, int ordersAfterScreen = 0) { renderer.sortingLayerID = LastLayerId; renderer.sortingOrder = 32765 + Mathf.Clamp(ordersAfterScreen, 0, 2); } } public class VrUiCursor : UuvrBehaviour { private Texture2D _texture; private Vector2 _offset = new Vector2(22f, 2f); private void Start() { //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Expected O, but got Unknown //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Unknown result type (might be due to invalid IL or missing references) byte[] array = File.ReadAllBytes(Path.Combine(UuvrPlugin.ModFolderPath, "Assets\\cursor.bmp")); int num = array[18] + (array[19] << 8); int num2 = array[22] + (array[23] << 8); Color32[] array2 = (Color32[])(object)new Color32[num * num2]; _texture = new Texture2D(num, num2, (TextureFormat)14, false); for (int i = 0; i < array2.Length; i++) { array2[i] = new Color32(array[i * 4 + 54], array[i * 4 + 55], array[i * 4 + 56], array[i * 4 + 57]); } _texture.SetPixels32(array2); _texture.Apply(); } private void Update() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)_texture == (Object)null)) { Cursor.SetCursor(_texture, _offset, (CursorMode)1); } } } public class VrUiManager : UuvrBehaviour { public const float ScreenWidthPerScale = 1.8f; private RenderTexture? _uiTexture; private GameObject? _vrUiQuad; private Renderer? _vrUiRenderer; private GameObject? _uiContainer; private CanvasRedirectPatchMode? _canvasRedirectPatchMode; private ScreenMirrorPatchMode? _screenMirrorPatchMode; private FollowTarget? _worldRenderModeFollowTarget; private UiOverlayRenderMode? _uiOverlayRenderMode; private void Start() { SetUpUi(); OnSettingChanged(); UuvrBehaviour.Create(((Component)this).transform); } protected override void OnSettingChanged() { //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0099: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a9: Unknown result type (might be due to invalid IL or missing references) //IL_01c9: Unknown result type (might be due to invalid IL or missing references) base.OnSettingChanged(); int vrUiLayer = LayerHelper.GetVrUiLayer(); _vrUiQuad.layer = vrUiLayer; ((Component)_uiOverlayRenderMode).gameObject.SetActive(ModConfiguration.Instance.PreferredUiRenderMode.Value == ModConfiguration.UiRenderMode.OverlayCamera); ((Behaviour)_worldRenderModeFollowTarget).enabled = ModConfiguration.Instance.PreferredUiRenderMode.Value == ModConfiguration.UiRenderMode.InWorld; if (ModConfiguration.Instance.PreferredUiRenderMode.Value != ModConfiguration.UiRenderMode.InWorld) { ((Component)_worldRenderModeFollowTarget).transform.localPosition = Vector3.zero; ((Component)_worldRenderModeFollowTarget).transform.localRotation = Quaternion.identity; } ((Behaviour)_screenMirrorPatchMode).enabled = ModConfiguration.Instance.PreferredUiPatchMode.Value == ModConfiguration.UiPatchMode.Mirror; ((Behaviour)_canvasRedirectPatchMode).enabled = ModConfiguration.Instance.PreferredUiPatchMode.Value == ModConfiguration.UiPatchMode.CanvasRedirect; float num = (float)((Texture)_uiTexture).height / (float)((Texture)_uiTexture).width; float num2 = 1.8f * ModConfiguration.Instance.VrUiScale.Value; float num3 = num2 * num; _vrUiQuad.transform.localScale = new Vector3(num2, num3, 1f); float num4 = Mathf.Abs(_vrUiQuad.transform.localScale.y); if (ModConfiguration.Instance.PreferredUiPatchMode.Value == ModConfiguration.UiPatchMode.Mirror) { num4 *= -1f; } _vrUiQuad.transform.localScale = new Vector3(_vrUiQuad.transform.localScale.x, num4, _vrUiQuad.transform.localScale.z); _vrUiQuad.transform.localPosition = ModConfiguration.Instance.VrUiPosition.Value; if ((Object)(object)_vrUiRenderer != (Object)null) { _vrUiRenderer.material.shader = GetVrUiShader(); _vrUiRenderer.material.renderQueue = ModConfiguration.Instance.VrUiRenderQueue.Value; UiSorting.DrawLast(_vrUiRenderer); } UpdateFollowTarget(); } private static Shader GetVrUiShader() { if (Utility.IsNullOrWhiteSpace(ModConfiguration.Instance.VrUiShader.Value)) { return Canvas.GetDefaultCanvasMaterial().shader; } Shader val = Shader.Find(ModConfiguration.Instance.VrUiShader.Value); return ((Object)(object)val != (Object)null) ? val : Canvas.GetDefaultCanvasMaterial().shader; } private void SetUpUi() { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected O, but got Unknown //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_00a6: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Expected O, but got Unknown _uiTexture = new RenderTexture(Screen.width, Screen.height, 16, (RenderTextureFormat)0); GameObject val = new GameObject("VrUiContainer"); val.transform.parent = ((Component)this).transform; _uiContainer = val; _vrUiQuad = GameObject.CreatePrimitive((PrimitiveType)5); Object.Destroy((Object)(object)_vrUiQuad.GetComponent("Collider")); ((Object)_vrUiQuad).name = "VrUiQuad"; _vrUiQuad.transform.parent = _uiContainer.transform; _vrUiRenderer = _vrUiQuad.GetComponent(); _vrUiRenderer.material = new Material(Canvas.GetDefaultCanvasMaterial()) { mainTexture = (Texture)(object)_uiTexture }; _canvasRedirectPatchMode = ((Component)this).gameObject.AddComponent(); _canvasRedirectPatchMode.SetUpTargetTexture(_uiTexture); _screenMirrorPatchMode = ((Component)this).gameObject.AddComponent(); _screenMirrorPatchMode.SetUpTargetTexture(_uiTexture); _uiOverlayRenderMode = UuvrBehaviour.Create(((Component)this).transform); _worldRenderModeFollowTarget = _uiContainer.AddComponent(); } private void Update() { if ((Object)(object)_uiTexture == (Object)null) { SetUpUi(); } if ((Object)(object)Uuvr.VrCamera.VrCamera.HighestDepthVrCamera != (Object)null && (Object)(object)Uuvr.VrCamera.VrCamera.HighestDepthVrCamera.ParentCamera != (Object)null && (Object)(object)_uiContainer != (Object)null && (Object)(object)_uiContainer.transform.parent != (Object)(object)((Component)Uuvr.VrCamera.VrCamera.HighestDepthVrCamera.ParentCamera).transform && (Object)(object)_worldRenderModeFollowTarget != (Object)null) { UpdateFollowTarget(); } } private void UpdateFollowTarget() { if (!((Object)(object)Uuvr.VrCamera.VrCamera.HighestDepthVrCamera == (Object)null) && !((Object)(object)Uuvr.VrCamera.VrCamera.HighestDepthVrCamera.ParentCamera == (Object)null)) { _worldRenderModeFollowTarget.Target = ((ModConfiguration.Instance.PreferredUiRenderMode.Value == ModConfiguration.UiRenderMode.InWorld) ? ((Component)Uuvr.VrCamera.VrCamera.HighestDepthVrCamera.ParentCamera).transform : null); } } } } namespace Uuvr.VrUi.PatchModes { public class CanvasRedirect : UuvrBehaviour { private Canvas _canvas; private Camera _uiCaptureCamera; private bool _isPatched; private RenderMode _originalRenderMode; private Camera _originalWorldCamera; private float _originalPlaneDistance; private int _originalLayer; public static void Create(Canvas _canvas, Camera uiCaptureCamera) { CanvasRedirect canvasRedirect = ((Component)_canvas).gameObject.AddComponent(); canvasRedirect._canvas = _canvas; canvasRedirect._uiCaptureCamera = uiCaptureCamera; } private void Start() { OnSettingChanged(); } protected override void OnSettingChanged() { bool flag = ShouldPatchCanvas(); if (flag && !_isPatched) { Patch(); } else if (!flag && _isPatched) { UndoPatch(); } } private bool ShouldPatchCanvas() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Invalid comparison between Unknown and I4 if (ModConfiguration.Instance.PreferredUiPatchMode.Value != ModConfiguration.UiPatchMode.CanvasRedirect) { return false; } bool flag = (int)_originalRenderMode == 1; bool result; switch (ModConfiguration.Instance.ScreenSpaceCanvasTypesToPatch.Value) { case ModConfiguration.ScreenSpaceCanvasType.None: result = !flag; break; case ModConfiguration.ScreenSpaceCanvasType.NotToTexture: { int num; if (flag) { if (flag) { Camera worldCamera = _canvas.worldCamera; num = (((Object)(object)((worldCamera != null) ? worldCamera.targetTexture : null) == (Object)null) ? 1 : 0); } else { num = 0; } } else { num = 1; } result = (byte)num != 0; break; } case ModConfiguration.ScreenSpaceCanvasType.All: result = true; break; default: throw new ArgumentOutOfRangeException(); } return result; } private void Patch() { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Invalid comparison between Unknown and I4 LayerHelper.SetLayerRecursive(((Component)this).transform, LayerHelper.GetVrUiLayer()); _originalRenderMode = _canvas.renderMode; _originalWorldCamera = _canvas.worldCamera; _originalPlaneDistance = _canvas.planeDistance; _originalLayer = ((Component)_canvas).gameObject.layer; _canvas.renderMode = (RenderMode)1; _canvas.worldCamera = _uiCaptureCamera; if ((int)_originalRenderMode == 1) { if (_originalPlaneDistance < _uiCaptureCamera.nearClipPlane) { _uiCaptureCamera.nearClipPlane = Mathf.Max(0.01f, _originalPlaneDistance - 0.1f); } if (_originalPlaneDistance > _uiCaptureCamera.farClipPlane) { _uiCaptureCamera.farClipPlane = _originalPlaneDistance + 0.1f; } } else { _canvas.planeDistance = 1f; } _isPatched = true; } private void UndoPatch() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) LayerHelper.SetLayerRecursive(((Component)this).transform, _originalLayer); _canvas.renderMode = _originalRenderMode; _canvas.worldCamera = _originalWorldCamera; _canvas.planeDistance = _originalPlaneDistance; _isPatched = false; } } public class CanvasRedirectPatchMode : UuvrBehaviour, VrUiPatchMode { private readonly List _ignoredCanvases = new List { "unityexplorer", "universelib" }; private Camera? _uiCaptureCamera; private static readonly FieldInfo? GraphicsField = typeof(GraphicRegistry).GetField("m_Graphics", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); protected override void OnSettingChanged() { base.OnSettingChanged(); _uiCaptureCamera.cullingMask = 1 << LayerHelper.GetVrUiLayer(); } private void Start() { OnSettingChanged(); } protected override void OnEnable() { base.OnEnable(); ((Behaviour)_uiCaptureCamera).enabled = true; } protected override void OnDisable() { base.OnEnable(); ((Behaviour)_uiCaptureCamera).enabled = false; } private new void Awake() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) _uiCaptureCamera = new GameObject("VrUiCaptureCamera").AddComponent(); Uuvr.VrCamera.VrCamera.IgnoredCameras.Add(_uiCaptureCamera); ((Component)_uiCaptureCamera).transform.parent = ((Component)this).transform; _uiCaptureCamera.clearFlags = (CameraClearFlags)2; _uiCaptureCamera.backgroundColor = Color.clear; _uiCaptureCamera.depth = 100f; } public void SetUpTargetTexture(RenderTexture targetTexture) { _uiCaptureCamera.targetTexture = targetTexture; } private void Update() { //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) if (GraphicRegistry.instance == null || !(GraphicsField?.GetValue(GraphicRegistry.instance) is IDictionary dictionary)) { return; } foreach (object key in dictionary.Keys) { PatchCanvas((Canvas)((key is Canvas) ? key : null)); } ((Component)_uiCaptureCamera).transform.localPosition = Vector3.right * 10f; } private void PatchCanvas(Canvas canvas) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Invalid comparison between Unknown and I4 if (!((Object)(object)canvas == (Object)null) && !((Object)(object)_uiCaptureCamera == (Object)null) && (int)canvas.renderMode != 2) { if (!canvas.isRootCanvas) { PatchCanvas(canvas.rootCanvas); } else if (!_ignoredCanvases.Any((string ignoredCanvas) => ((Object)canvas).name.ToLower().Contains(ignoredCanvas.ToLower())) && !Object.op_Implicit((Object)(object)((Component)canvas).GetComponent())) { CanvasRedirect.Create(canvas, _uiCaptureCamera); } } } } public class ScreenMirrorPatchMode : UuvrBehaviour, VrUiPatchMode { private CommandBuffer? _commandBuffer; private Camera? _clearCamera; private float _scale = 2f; private RenderTexture _targetTexture; private Coroutine _endOfFrameCoroutine; protected override void OnEnable() { base.OnEnable(); SetXrMirror(mirror: false); _endOfFrameCoroutine = ((MonoBehaviour)this).StartCoroutine(EndOfFrameCoroutine()); } protected override void OnDisable() { base.OnDisable(); SetXrMirror(mirror: true); ((MonoBehaviour)this).StopCoroutine(_endOfFrameCoroutine); Reset(); } private new void Awake() { //IL_005b: Unknown result type (might be due to invalid IL or missing references) Debug.Log((object)"mirror mode Start"); _clearCamera = ((Component)this).gameObject.AddComponent(); _clearCamera.stereoTargetEye = (StereoTargetEyeMask)0; _clearCamera.depth = -100f; _clearCamera.cullingMask = 0; _clearCamera.clearFlags = (CameraClearFlags)2; _clearCamera.backgroundColor = Color.clear; _clearCamera.allowHDR = false; _clearCamera.allowMSAA = false; AdditionalCameraData additionalCameraData = AdditionalCameraData.Create(_clearCamera); if ((Object)(object)additionalCameraData != (Object)null) { additionalCameraData.SetAllowXrRendering(allowXrRendering: false); } } public void SetUpTargetTexture(RenderTexture targetTexture) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) _targetTexture = targetTexture; if (((Behaviour)this).enabled) { _commandBuffer = CreateCommandBuffer(); _commandBuffer.name = "UUVR UI"; _commandBuffer.Blit(RenderTargetIdentifier.op_Implicit((BuiltinRenderTextureType)2), RenderTargetIdentifier.op_Implicit((Texture)(object)targetTexture)); } } private static CommandBuffer CreateCommandBuffer() { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown Type typeFromHandle = typeof(CommandBuffer); ConstructorInfo constructor = typeFromHandle.GetConstructor(Type.EmptyTypes); return (CommandBuffer)constructor.Invoke(null); } private void Reset() { if (_commandBuffer != null) { _commandBuffer.Dispose(); _commandBuffer = null; } } private void SetXrMirror(bool mirror) { Type type = Type.GetType("UnityEngine.XR.XRSettings, UnityEngine.XRModule") ?? Type.GetType("UnityEngine.XR.XRSettings, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.VRSettings, UnityEngine"); type.GetProperty("showDeviceView").SetValue(null, mirror, null); } private IEnumerator EndOfFrameCoroutine() { while (true) { if ((Object)(object)_targetTexture != (Object)null && (_commandBuffer == null || Screen.width != ((Texture)_targetTexture).width || Screen.height != ((Texture)_targetTexture).height)) { SetUpTargetTexture(_targetTexture); } yield return (object)new WaitForEndOfFrame(); if (_commandBuffer != null && (Object)(object)_targetTexture != (Object)null) { Graphics.ExecuteCommandBuffer(_commandBuffer); } } } } public interface VrUiPatchMode { void SetUpTargetTexture(RenderTexture targetTexture); } } namespace Uuvr.VrTogglers { public class LegacyOpenVrToggler : VrToggler { private static Type? _xrSettingsType; private static PropertyInfo? _xrEnabledProperty; protected override bool SetUp() { _xrSettingsType = Type.GetType("UnityEngine.XR.XRSettings, UnityEngine.XRModule") ?? Type.GetType("UnityEngine.XR.XRSettings, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.VRSettings, UnityEngine"); _xrEnabledProperty = _xrSettingsType.GetProperty("enabled"); return true; } protected override bool EnableVr() { _xrEnabledProperty.SetValue(null, true, null); return true; } protected override bool DisableVr() { _xrEnabledProperty.SetValue(null, false, null); return true; } } public abstract class VrToggler { private bool _isSetUp; public bool IsVrEnabled { get; private set; } protected abstract bool SetUp(); protected abstract bool EnableVr(); protected abstract bool DisableVr(); public void SetVrEnabled(bool nextVrEnabled) { if (!_isSetUp) { _isSetUp = SetUp(); } if (nextVrEnabled) { IsVrEnabled = EnableVr(); } else if (DisableVr()) { IsVrEnabled = false; } } } public class VrTogglerManager { private VrToggler _toggler; public VrTogglerManager() { SetUpToggler(); _toggler?.SetVrEnabled(nextVrEnabled: true); } private void SetUpToggler() { if (_toggler != null) { _toggler.SetVrEnabled(nextVrEnabled: false); } switch (ModConfiguration.Instance.PreferredVrApi.Value) { case ModConfiguration.VrApi.OpenVr: _toggler = new XrPluginOpenVrToggler(); break; case ModConfiguration.VrApi.OpenXr: _toggler = new XrPluginOpenXrToggler(); break; default: throw new ArgumentOutOfRangeException(); } } public void ToggleVr() { _toggler.SetVrEnabled(!_toggler.IsVrEnabled); } } public class XrPluginOpenVrToggler : XrPluginToggler { protected override XRLoader CreateLoader() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) OpenVRLoader val = ScriptableObject.CreateInstance(); ((XRLoader)val).Initialize(); OpenVRSettings settings = OpenVRSettings.GetSettings(true); if ((Object)(object)settings == (Object)null) { throw new Exception("OpenVRSettings instance is null"); } settings.EditorAppKey = "uuvr"; settings.InitializationType = (InitializationTypes)1; settings.StereoRenderingMode = (StereoRenderingModes)0; settings.SetMirrorViewMode((MirrorViewModes)2); return (XRLoader)(object)val; } } public class XrPluginOpenXrToggler : XrPluginToggler { protected override XRLoader CreateLoader() { OpenXRLoader result = ScriptableObject.CreateInstance(); OpenXRSettings.Instance.renderMode = (RenderMode)0; return (XRLoader)(object)result; } } public abstract class XrPluginToggler : VrToggler { protected XRGeneralSettings _generalSettings; protected XRManagerSettings _managerSetings; protected override bool SetUp() { _generalSettings = ScriptableObject.CreateInstance(); _managerSetings = ScriptableObject.CreateInstance(); _generalSettings.Manager = _managerSetings; _managerSetings.loaders.Add(CreateLoader()); _managerSetings.InitializeLoaderSync(); if ((Object)(object)_managerSetings.activeLoader == (Object)null) { throw new Exception("Cannot initialize OpenXR Loader. Maybe The VR headset wasn't ready?"); } return true; } protected override bool EnableVr() { _managerSetings.StartSubsystems(); bool flag = _managerSetings.activeLoader.Initialize(); bool flag2 = _managerSetings.activeLoader.Start(); return flag && flag2; } protected override bool DisableVr() { bool flag = _managerSetings.activeLoader.Stop(); bool flag2 = _managerSetings.activeLoader.Deinitialize(); return flag && flag2; } protected abstract XRLoader CreateLoader(); } } namespace Uuvr.VrCamera { public class AdditionalCameraData : MonoBehaviour { private const int RenderTypeBase = 0; private const int RenderTypeOverlay = 1; private static Type? _additionalCameraDataType; private static PropertyInfo? _renderTypeProperty; private static PropertyInfo? _cameraStackProperty; private static PropertyInfo? _allowXrRenderingProperty; private object? _additionalCameraData; public static AdditionalCameraData Create(Camera camera) { if (_additionalCameraDataType == null) { _additionalCameraDataType = Type.GetType("UnityEngine.Rendering.Universal.UniversalAdditionalCameraData, Unity.RenderPipelines.Universal.Runtime"); _renderTypeProperty = _additionalCameraDataType?.GetProperty("renderType"); _cameraStackProperty = _additionalCameraDataType?.GetProperty("cameraStack"); _allowXrRenderingProperty = _additionalCameraDataType?.GetProperty("allowXRRendering"); } if (_additionalCameraDataType == null) { return null; } return ((Component)camera).gameObject.GetComponent() ?? ((Component)camera).gameObject.AddComponent(); } private void Awake() { _additionalCameraData = ((Component)this).gameObject.GetComponent(_additionalCameraDataType) ?? ((Component)this).gameObject.AddComponent(_additionalCameraDataType); } public void SetRenderTypeBase() { _renderTypeProperty?.SetValue(_additionalCameraData, 0); } public void SetRenderTypeOverlay() { _renderTypeProperty?.SetValue(_additionalCameraData, 1); } public bool IsOverlay() { return (int)_renderTypeProperty.GetValue(_additionalCameraData) == 1; } public List GetCameraStack() { return (List)_cameraStackProperty.GetValue(_additionalCameraData); } public void SetAllowXrRendering(bool allowXrRendering) { _allowXrRenderingProperty.SetValue(_additionalCameraData, allowXrRendering); } } public class VrCamera : UuvrBehaviour { public static readonly HashSet VrCameras = new HashSet(); public static readonly HashSet IgnoredCameras = new HashSet(); public static bool LookWhereGameCameraLooks; private Quaternion _rotationBeforeRender; private UuvrPoseDriver? _parentCameraPoseDriver; private Camera? _childCamera; private UuvrPoseDriver? _childCameraPoseDriver; private LineRenderer _forwardLine; public static VrCamera? HighestDepthVrCamera { get; private set; } public Camera? ParentCamera { get; private set; } public Camera? CameraInUse => (ModConfiguration.Instance.CameraTracking.Value == ModConfiguration.CameraTrackingMode.Child) ? _childCamera : ParentCamera; protected override void Awake() { base.Awake(); ParentCamera = ((Component)this).GetComponent(); VrCameras.Add(ParentCamera); } protected override void OnBeginFrameRendering() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) base.OnBeginFrameRendering(); if (ModConfiguration.Instance.CameraTracking.Value == ModConfiguration.CameraTrackingMode.RelativeTransform) { _rotationBeforeRender = ((Component)this).transform.rotation; ((Component)this).transform.rotation = (LookWhereGameCameraLooks ? (_rotationBeforeRender * HeadRoll(((Component)_childCameraPoseDriver).transform.localRotation)) : ((Component)_childCamera).transform.rotation); } } private static Quaternion HeadRoll(Quaternion head) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) Vector3 val = head * Vector3.forward; Vector3 val2 = Vector3.ProjectOnPlane(Vector3.up, val); if (((Vector3)(ref val2)).sqrMagnitude < 1E-06f) { return Quaternion.identity; } float num = Vector3.SignedAngle(val2, head * Vector3.up, val); return Quaternion.AngleAxis(num, Vector3.forward); } protected override void OnEndFrameRendering() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) if (ModConfiguration.Instance.CameraTracking.Value == ModConfiguration.CameraTrackingMode.RelativeTransform) { ((Component)this).transform.rotation = _rotationBeforeRender; } } private void OnDestroy() { VrCameras.Remove(ParentCamera); } private void Start() { VrCameraOffset vrCameraOffset = UuvrBehaviour.Create(((Component)this).transform); _parentCameraPoseDriver = ((Component)ParentCamera).gameObject.AddComponent(); _childCameraPoseDriver = UuvrBehaviour.Create(((Component)vrCameraOffset).transform); ((Object)_childCameraPoseDriver).name = "VrChildCamera"; _childCamera = ((Component)_childCameraPoseDriver).gameObject.AddComponent(); IgnoredCameras.Add(_childCamera); _childCamera.CopyFrom(ParentCamera); } protected override void OnBeforeRender() { UpdateRelativeMatrix(); } private void OnPreCull() { UpdateRelativeMatrix(); } private void OnPreRender() { UpdateRelativeMatrix(); } private void LateUpdate() { UpdateRelativeMatrix(); } private void Update() { //IL_0093: Unknown result type (might be due to invalid IL or missing references) if (ModConfiguration.Instance.OverrideDepth.Value) { ParentCamera.depth = ModConfiguration.Instance.VrCameraDepth.Value; } ModConfiguration.CameraTrackingMode value = ModConfiguration.Instance.CameraTracking.Value; ((Behaviour)_parentCameraPoseDriver).enabled = value == ModConfiguration.CameraTrackingMode.Absolute; ((Component)_childCameraPoseDriver).gameObject.SetActive(value != ModConfiguration.CameraTrackingMode.Absolute); if (value == ModConfiguration.CameraTrackingMode.Child) { _childCamera.cullingMask = ParentCamera.cullingMask; _childCamera.clearFlags = ParentCamera.clearFlags; _childCamera.depth = ParentCamera.depth; } else { _childCamera.cullingMask = 0; _childCamera.clearFlags = (CameraClearFlags)4; _childCamera.depth = -100f; } if (IsRendering(this) && (!IsRendering(HighestDepthVrCamera) || ParentCamera.depth > HighestDepthVrCamera.CameraInUse.depth)) { HighestDepthVrCamera = this; } } private static bool IsRendering(VrCamera? vrCamera) { return (Object)(object)vrCamera != (Object)null && ((Behaviour)vrCamera).isActiveAndEnabled && (Object)(object)vrCamera.ParentCamera != (Object)null && ((Behaviour)vrCamera.ParentCamera).isActiveAndEnabled; } private void UpdateRelativeMatrix() { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) if (ModConfiguration.Instance.CameraTracking.Value == ModConfiguration.CameraTrackingMode.RelativeMatrix) { StereoscopicEye val = (StereoscopicEye)(((int)ParentCamera.stereoActiveEye != 0) ? 1 : 0); ParentCamera.worldToCameraMatrix = _childCamera.GetStereoViewMatrix(val); if (ModConfiguration.Instance.RelativeCameraSetStereoView.Value) { ParentCamera.SetStereoViewMatrix(val, ParentCamera.worldToCameraMatrix); } } } } public class VrCameraManager : MonoBehaviour { private Camera[] _allCameras; private void Update() { //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Invalid comparison between Unknown and I4 if (_allCameras == null || _allCameras.Length < Camera.allCamerasCount) { _allCameras = (Camera[])(object)new Camera[Camera.allCamerasCount]; } Camera.GetAllCameras(_allCameras); for (int i = 0; i < Camera.allCamerasCount; i++) { Camera val = _allCameras[i]; if (!((Object)(object)val == (Object)null) && !((Object)(object)val.targetTexture != (Object)null) && (int)val.stereoTargetEye != 0 && !VrCamera.VrCameras.Contains(val) && !VrCamera.IgnoredCameras.Contains(val)) { Debug.Log((object)("creating vr camera " + ((Object)val).name)); ((Component)val).gameObject.AddComponent(); } } } } public class VrCameraOffset : UuvrBehaviour { public static Quaternion RecenterRotation = Quaternion.identity; protected override void OnBeforeRender() { base.OnBeforeRender(); UpdateTransform(); } protected override void OnSettingChanged() { //IL_0035: Unknown result type (might be due to invalid IL or missing references) base.OnSettingChanged(); ModConfiguration instance = ModConfiguration.Instance; ((Component)this).transform.localPosition = new Vector3(instance.CameraPositionOffsetX.Value, instance.CameraPositionOffsetY.Value, instance.CameraPositionOffsetZ.Value); } private void Update() { UpdateTransform(); } private void LateUpdate() { UpdateTransform(); } private void UpdateTransform() { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) if (ModConfiguration.Instance.AlignCameraToHorizon.Value) { Vector3 val = Vector3.ProjectOnPlane(((Component)this).transform.parent.forward, Vector3.up); ((Component)this).transform.LookAt(((Component)this).transform.position + val, Vector3.up); Transform transform = ((Component)this).transform; transform.rotation *= RecenterRotation; } else { ((Component)this).transform.localRotation = RecenterRotation; } } } } namespace Uuvr.UnityTypesHelper { public static class UuvrXrDevice { public static readonly Type? XrDeviceType = Type.GetType("UnityEngine.XR.XRDevice, UnityEngine.XRModule") ?? Type.GetType("UnityEngine.XR.XRDevice, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.VRDevice, UnityEngine.VRModule") ?? Type.GetType("UnityEngine.VR.VRDevice, UnityEngine"); public static readonly PropertyInfo? RefreshRateProperty = XrDeviceType?.GetProperty("refreshRate"); } }