mirror of
https://github.com/NotAKidoS/NAK_CVR_Mods.git
synced 2025-09-02 06:19:22 +00:00
WIP update
This commit is contained in:
parent
8a5b8010ca
commit
4d42c67049
1 changed files with 74 additions and 44 deletions
|
@ -5,14 +5,24 @@ using ABI_RC.Core.Savior;
|
||||||
using ABI_RC.Core.UI;
|
using ABI_RC.Core.UI;
|
||||||
using ABI_RC.Core.Util.Object_Behaviour;
|
using ABI_RC.Core.Util.Object_Behaviour;
|
||||||
using ABI_RC.Systems.MovementSystem;
|
using ABI_RC.Systems.MovementSystem;
|
||||||
|
using ABI_RC.Core.EventSystem;
|
||||||
using MelonLoader;
|
using MelonLoader;
|
||||||
using RootMotion.FinalIK;
|
using RootMotion.FinalIK;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.XR;
|
using UnityEngine.XR;
|
||||||
using Valve.VR;
|
using Valve.VR;
|
||||||
|
using HarmonyLib;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
//Remove VRIK on VR to Desktop
|
||||||
|
//Remove LookAtIK on Desktop to VR
|
||||||
|
|
||||||
|
//Set Desktop camera to head again...?
|
||||||
|
//Recenter collision position (in VR it shifts around)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace DesktopVRSwitch;
|
namespace DesktopVRSwitch;
|
||||||
|
|
||||||
public class DesktopVRSwitch : MelonMod
|
public class DesktopVRSwitch : MelonMod
|
||||||
|
@ -64,30 +74,51 @@ public class DesktopVRSwitch : MelonMod
|
||||||
SetPlayerSetup(VRMode);
|
SetPlayerSetup(VRMode);
|
||||||
SwitchActiveCameraRigs(VRMode);
|
SwitchActiveCameraRigs(VRMode);
|
||||||
UpdateCameraFacingObject();
|
UpdateCameraFacingObject();
|
||||||
CreateTempVRIK(VRMode);
|
|
||||||
QuickCalibrate(VRMode);
|
|
||||||
RepositionCohtmlHud(VRMode);
|
RepositionCohtmlHud(VRMode);
|
||||||
UpdateHudOperations(VRMode);
|
UpdateHudOperations(VRMode);
|
||||||
|
|
||||||
yield
|
yield
|
||||||
return new WaitForEndOfFrame();
|
return new WaitForEndOfFrame();
|
||||||
|
|
||||||
|
RemoveComponents(VRMode);
|
||||||
|
|
||||||
|
yield
|
||||||
|
return new WaitForEndOfFrame();
|
||||||
|
|
||||||
SetMovementSystem(VRMode);
|
SetMovementSystem(VRMode);
|
||||||
|
|
||||||
yield
|
yield
|
||||||
return new WaitForEndOfFrame();
|
return new WaitForEndOfFrame();
|
||||||
|
|
||||||
//needs to come after SetMovementSystem
|
//needs to come after SetMovementSystem
|
||||||
//UpdateGestureReconizerCam();
|
UpdateGestureReconizerCam();
|
||||||
|
|
||||||
|
yield
|
||||||
|
return new WaitForSeconds(0.5f);
|
||||||
|
|
||||||
//right here is the fucker most likely to break
|
//right here is the fucker most likely to break
|
||||||
ReloadCVRInputManager();
|
ReloadCVRInputManager();
|
||||||
|
|
||||||
//some menus have 0.5s wait(), so to be safe
|
//some menus have 0.5s wait(), so to be safe
|
||||||
yield
|
yield
|
||||||
return new WaitForSeconds(1f);
|
return new WaitForSeconds(0.5f);
|
||||||
|
|
||||||
Recalibrate();
|
//I am setting the collision center to the avatars position so the collision is set in the same place as where it was after the player moved roomscale in VR
|
||||||
|
|
||||||
|
//need to recenter player avatar as VRIK locomotion moves that directly
|
||||||
|
Vector3 roomscalePos = PlayerSetup.Instance._avatar.transform.position;
|
||||||
|
Quaternion roomscaleRot = PlayerSetup.Instance._avatar.transform.rotation;
|
||||||
|
|
||||||
|
MovementSystem.Instance.enabled = false;
|
||||||
|
MovementSystem.Instance.transform.position = roomscalePos;
|
||||||
|
MovementSystem.Instance.transform.rotation = roomscaleRot;
|
||||||
|
MovementSystem.Instance.enabled = true;
|
||||||
|
|
||||||
|
//collision center is set to match headpos in VR, but desktop doesnt reset it
|
||||||
|
//MovementSystem.Instance.proxyCollider.center = Vector3.zero; //not sure why UpdateColliderCenter doesnt do this
|
||||||
|
MovementSystem.Instance.UpdateColliderCenter(roomscalePos);
|
||||||
|
|
||||||
|
//AssetManagement.Instance.LoadLocalAvatar(this.avatarId);
|
||||||
|
|
||||||
//tell the game to change VRMode/DesktopMode for Steam/Discord presence
|
//tell the game to change VRMode/DesktopMode for Steam/Discord presence
|
||||||
//RichPresence.PopulatePresence();
|
//RichPresence.PopulatePresence();
|
||||||
|
@ -190,24 +221,39 @@ public class DesktopVRSwitch : MelonMod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateTempVRIK(bool isVR)
|
private static void RemoveComponents(bool isVR)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (isVR)
|
if (!isVR)
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Creating temp VRIK component.");
|
MelonLogger.Msg("VRIK component is not needed. Removing.");
|
||||||
VRIK ik = (VRIK)PlayerSetup.Instance._avatar.GetComponent(typeof(VRIK));
|
VRIK ik = (VRIK)PlayerSetup.Instance._avatar.GetComponent(typeof(VRIK));
|
||||||
if (ik == null)
|
if (ik != null)
|
||||||
{
|
{
|
||||||
ik = PlayerSetup.Instance._avatar.AddComponent<VRIK>();
|
UnityEngine.Object.Destroy(ik);
|
||||||
}
|
}
|
||||||
ik.solver.IKPositionWeight = 0f;
|
|
||||||
ik.enabled = false;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Temp VRIK component is not needed. Ignoring.");
|
MelonLogger.Msg("LookIK component is not needed. Removing.");
|
||||||
|
LookAtIK ik = (LookAtIK)PlayerSetup.Instance._avatar.GetComponent(typeof(LookAtIK));
|
||||||
|
if (ik != null)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(ik);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MelonLogger.Msg("Removing Viseme and Eye controllers.");
|
||||||
|
CVRVisemeController cvrvisemeController = (CVRVisemeController)PlayerSetup.Instance._avatar.GetComponent(typeof(CVRVisemeController));
|
||||||
|
if (cvrvisemeController != null)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(cvrvisemeController);
|
||||||
|
}
|
||||||
|
CVREyeController cvreyeController = (CVREyeController)PlayerSetup.Instance._avatar.GetComponent(typeof(CVREyeController));
|
||||||
|
if (cvreyeController != null)
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(cvreyeController);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
|
@ -218,22 +264,6 @@ public class DesktopVRSwitch : MelonMod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void QuickCalibrate(bool isVR)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
//we invoke calibrate to get VRIK and calibrator instance set up, faster than full recalibrate
|
|
||||||
MelonLogger.Msg("Called CalibrateAvatar() on PlayerSetup.Instance. Expect a few errors from PlayerSetup Update() and LateUpdate().");
|
|
||||||
PlayerSetup.Instance.CalibrateAvatar();
|
|
||||||
}
|
|
||||||
catch (Exception)
|
|
||||||
{
|
|
||||||
MelonLogger.Error("CalibrateAvatar() failed. Is PlayerSetup.Instance invalid?");
|
|
||||||
MelonLogger.Msg("PlayerSetup.Instance: " + PlayerSetup.Instance);
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SwitchActiveCameraRigs(bool isVR)
|
private static void SwitchActiveCameraRigs(bool isVR)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -315,7 +345,7 @@ public class DesktopVRSwitch : MelonMod
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MelonLogger.Msg("Called ReCalibrateAvatar() on PlayerSetup.Instance. Will take a second...");
|
MelonLogger.Msg("Called ReCalibrateAvatar() on PlayerSetup.Instance. Will take a second...");
|
||||||
PlayerSetup.Instance.ReCalibrateAvatar();
|
PlayerSetup.Instance.CalibrateAvatar();
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
|
@ -385,18 +415,18 @@ public class DesktopVRSwitch : MelonMod
|
||||||
}
|
}
|
||||||
|
|
||||||
//i suck at traverse
|
//i suck at traverse
|
||||||
//private static void UpdateGestureReconizerCam()
|
private static void UpdateGestureReconizerCam()
|
||||||
//{
|
{
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// MelonLogger.Msg("Set GestureReconizerCam camera to Camera.main.");
|
MelonLogger.Msg("Set GestureReconizerCam camera to Camera.main.");
|
||||||
// Camera _camera = Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").GetValue<Camera>();
|
Camera cam = Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").GetValue() as Camera;
|
||||||
// _camera = Camera.main;
|
cam = Camera.main;
|
||||||
// }
|
}
|
||||||
// catch (Exception)
|
catch (Exception)
|
||||||
// {
|
{
|
||||||
// MelonLogger.Error("Error updating CVRGestureRecognizer camera!");
|
MelonLogger.Error("Error updating CVRGestureRecognizer camera!");
|
||||||
// throw;
|
throw;
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue