diff --git a/DesktopVRSwitch/Main.cs b/DesktopVRSwitch/Main.cs index b63bce0..35a7e7b 100644 --- a/DesktopVRSwitch/Main.cs +++ b/DesktopVRSwitch/Main.cs @@ -1,17 +1,17 @@ -using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core; +using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using ABI_RC.Core.UI; -using ABI_RC.Core; using ABI_RC.Core.Util.Object_Behaviour; using ABI_RC.Systems.MovementSystem; using MelonLoader; using RootMotion.FinalIK; using System.Collections; using UnityEngine; -using Object = UnityEngine.Object; using UnityEngine.XR; using Valve.VR; +using Object = UnityEngine.Object; namespace DesktopVRSwitch; @@ -28,7 +28,7 @@ public class DesktopVRSwitch : MelonMod { //start attempt isAttemptingSwitch = true; - MelonCoroutines.Start( AttemptPlatformSwitch() ); + MelonCoroutines.Start(AttemptPlatformSwitch()); //how long we wait until we assume an error occured timedSwitch = Time.time + 10f; @@ -38,26 +38,28 @@ public class DesktopVRSwitch : MelonMod if (isAttemptingSwitch && Time.time > timedSwitch) { MelonLogger.Error("Timer exceeded. Something is wrong and coroutine failed partway."); - MelonCoroutines.Start( AttemptPlatformSwitch(true) ); + MelonCoroutines.Start(AttemptPlatformSwitch(true)); } } private static IEnumerator AttemptPlatformSwitch(bool forceMode = false) { - //forceMode will attempt to backtrack to last working mode + //forceMode will attempt to backtrack to last working mode (if you dont like the mess, fix it yourself thx) CurrentMode = forceMode ? CurrentMode : MetaPort.Instance.isUsingVr; bool VRMode = forceMode ? CurrentMode : !CurrentMode; - + //load or unload SteamVR InitializeSteamVR(VRMode); CloseMenuElements(VRMode); - yield return new WaitForEndOfFrame(); + yield + return new WaitForEndOfFrame(); SetMetaPort(VRMode); - yield return new WaitForEndOfFrame(); + yield + return new WaitForEndOfFrame(); SetPlayerSetup(VRMode); SwitchActiveCameraRigs(VRMode); @@ -67,21 +69,33 @@ public class DesktopVRSwitch : MelonMod RepositionCohtmlHud(VRMode); UpdateHudOperations(VRMode); - yield return new WaitForEndOfFrame(); + yield + return new WaitForEndOfFrame(); SetMovementSystem(VRMode); - yield return new WaitForEndOfFrame(); + yield + return new WaitForEndOfFrame(); + + //needs to come after SetMovementSystem + //UpdateGestureReconizerCam(); //right here is the fucker most likely to break ReloadCVRInputManager(); //some menus have 0.5s wait(), so to be safe - yield return new WaitForSeconds(1f); + yield + return new WaitForSeconds(1f); Recalibrate(); - yield return null; + //tell the game to change VRMode/DesktopMode for Steam/Discord presence + //RichPresence.PopulatePresence(); + + //nvm that resets the RichPresence clock- i want people to know how long ive wasted staring at mirror + + yield + return null; isAttemptingSwitch = false; } @@ -122,7 +136,6 @@ public class DesktopVRSwitch : MelonMod } } - // shouldn't be that important, right? private static void CloseMenuElements(bool isVR) { @@ -244,7 +257,7 @@ public class DesktopVRSwitch : MelonMod { MelonLogger.Msg("Parented CohtmlHud to active camera."); CohtmlHud.Instance.gameObject.transform.parent = isVR ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.desktopCamera.transform; - + //sets hud position, rotation, and scale based on MetaPort isUsingVr CVRTools.ConfigureHudAffinity(); } @@ -318,6 +331,7 @@ public class DesktopVRSwitch : MelonMod { try { + MelonLogger.Msg("Updating all CameraFacingObject scripts to face new camera. (this fixes nameplates)"); CameraFacingObject[] camfaceobjs = Object.FindObjectsOfType(); for (int i = 0; i < camfaceobjs.Count(); i++) @@ -332,10 +346,34 @@ public class DesktopVRSwitch : MelonMod } } + //cant fix unless i log the original VR gripOrigins with a patch... + //private static void SetPickupObjectOrigins() + //{ + // try + // { + // CVRPickupObject[] pickups = Object.FindObjectsOfType(); + + // if (pickups.gripOrigin != null) + // { + // Transform x = this.gripOrigin.Find("[Desktop]"); + // if (x != null) + // { + // this.gripOrigin = x; + // } + // } + // } + // catch (Exception) + // { + // MelonLogger.Error("Error updating CameraFacingObject objects! Nameplates will be wonk..."); + // throw; + // } + //} + private static void UpdateHudOperations(bool isVR) { try { + MelonLogger.Msg("Set HudOperations worldLoadingItem and worldLoadStatus to their respective Desktop/Vr parent."); HudOperations.Instance.worldLoadingItem = isVR ? HudOperations.Instance.worldLoadingItemVr : HudOperations.Instance.worldLoadingItemDesktop; HudOperations.Instance.worldLoadStatus = isVR ? HudOperations.Instance.worldLoadStatusVr : HudOperations.Instance.worldLoadStatusDesktop; } @@ -345,4 +383,20 @@ public class DesktopVRSwitch : MelonMod throw; } } + + //i suck at traverse + //private static void UpdateGestureReconizerCam() + //{ + // try + // { + // MelonLogger.Msg("Set GestureReconizerCam camera to Camera.main."); + // Camera _camera = Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").GetValue(); + // _camera = Camera.main; + // } + // catch (Exception) + // { + // MelonLogger.Error("Error updating CVRGestureRecognizer camera!"); + // throw; + // } + //} } \ No newline at end of file diff --git a/DesktopVRSwitch/format.json b/DesktopVRSwitch/format.json index cca5e49..258d342 100644 --- a/DesktopVRSwitch/format.json +++ b/DesktopVRSwitch/format.json @@ -1,23 +1,23 @@ { - "_id": 95, + "_id": -1, "name": "DesktopVRSwitch", - "modversion": "1.1.0", + "modversion": "1.0.0", "gameversion": "2022r168", "loaderversion": "0.5.4", "modtype": "Mod", "author": "NotAKidoS", - "description": "Corrects MM and QM position when avatar is scaled.\nAdditional option to scale player collision.", + "description": "Allows you to switch between Desktop and VR with a keybind.\n**Press Control + F6 to switch.**\n\nWhile this mod is a nice convienence feature to have access to, not every chillout system or mod is built to support it. I cannot possibly cover every edge case or mitigate issues with every mod. **Use at your own discretion.**", "searchtags": [ - "menu", - "scale", - "avatarscale", - "slider" + "desktop", + "vr", + "switch", + "hotswap" ], "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/DesktopVRSwitch/releases/download/r2/DesktopVRSwitch.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/DesktopVRSwitch/releases/download/r1/DesktopVRSwitch.dll", "sourcelink": "https://github.com/NotAKidOnSteam/DesktopVRSwitch/", - "changelog": "Added option to scale player collision. Fixed some VR specific issues.", - "embedcolor": "804221" + "changelog": "Initial Release", + "embedcolor": "3498db" } \ No newline at end of file