kind of error catch, other fixes

This commit is contained in:
NotAKidoS 2022-09-27 00:44:13 -05:00
parent 517aa7c51b
commit 43d100f37e
2 changed files with 93 additions and 46 deletions

View file

@ -33,6 +33,9 @@
<Reference Include="SteamVR"> <Reference Include="SteamVR">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\SteamVR.dll</HintPath> <HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\SteamVR.dll</HintPath>
</Reference> </Reference>
<Reference Include="Unity.TextMeshPro">
<HintPath>..\..\..\DakyModsCVR\ManagedLibs\Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule"> <Reference Include="UnityEngine.AnimationModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll</HintPath> <HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
</Reference> </Reference>

View file

@ -2,6 +2,8 @@
using ABI_RC.Core.Player; using ABI_RC.Core.Player;
using ABI_RC.Core.Savior; using ABI_RC.Core.Savior;
using ABI_RC.Core.UI; using ABI_RC.Core.UI;
using ABI_RC.Core;
using ABI_RC.Core.Util.Object_Behaviour;
using ABI_RC.Systems.MovementSystem; using ABI_RC.Systems.MovementSystem;
using MelonLoader; using MelonLoader;
using RootMotion.FinalIK; using RootMotion.FinalIK;
@ -17,6 +19,7 @@ public class DesktopVRSwitch : MelonMod
{ {
private static bool isAttemptingSwitch = false; private static bool isAttemptingSwitch = false;
private static float timedSwitch = 0f; private static float timedSwitch = 0f;
private static bool CurrentMode;
public override void OnUpdate() public override void OnUpdate()
{ {
@ -26,6 +29,7 @@ public class DesktopVRSwitch : MelonMod
//start attempt //start attempt
isAttemptingSwitch = true; isAttemptingSwitch = true;
MelonCoroutines.Start( AttemptPlatformSwitch() ); MelonCoroutines.Start( AttemptPlatformSwitch() );
//how long we wait until we assume an error occured //how long we wait until we assume an error occured
timedSwitch = Time.time + 10f; timedSwitch = Time.time + 10f;
} }
@ -33,17 +37,59 @@ public class DesktopVRSwitch : MelonMod
//catch if coroutine just decided to not finish... which happens? //catch if coroutine just decided to not finish... which happens?
if (isAttemptingSwitch && Time.time > timedSwitch) if (isAttemptingSwitch && Time.time > timedSwitch)
{ {
isAttemptingSwitch = false;
MelonLogger.Error("Timer exceeded. Something is wrong and coroutine failed partway."); MelonLogger.Error("Timer exceeded. Something is wrong and coroutine failed partway.");
MelonCoroutines.Start( AttemptPlatformSwitch(true) );
} }
} }
private static IEnumerator AttemptPlatformSwitch() private static IEnumerator AttemptPlatformSwitch(bool forceMode = false)
{ {
bool toVR = !MetaPort.Instance.isUsingVr; //forceMode will attempt to backtrack to last working mode
CurrentMode = forceMode ? CurrentMode : MetaPort.Instance.isUsingVr;
bool VRMode = forceMode ? CurrentMode : !CurrentMode;
//load or unload SteamVR //load or unload SteamVR
if (toVR) InitializeSteamVR(VRMode);
CloseMenuElements(VRMode);
yield return new WaitForEndOfFrame();
SetMetaPort(VRMode);
yield return new WaitForEndOfFrame();
SetPlayerSetup(VRMode);
SwitchActiveCameraRigs(VRMode);
UpdateCameraFacingObject();
CreateTempVRIK(VRMode);
QuickCalibrate(VRMode);
RepositionCohtmlHud(VRMode);
UpdateHudOperations(VRMode);
yield return new WaitForEndOfFrame();
SetMovementSystem(VRMode);
yield return new WaitForEndOfFrame();
//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);
Recalibrate();
yield return null;
isAttemptingSwitch = false;
}
//shitton of try catch below
private static void InitializeSteamVR(bool isVR)
{
if (isVR)
{ {
//force SteamVR to fully initialize, this does all and more than what i did with LoadDevice() //force SteamVR to fully initialize, this does all and more than what i did with LoadDevice()
SteamVR.Initialize(true); SteamVR.Initialize(true);
@ -74,45 +120,9 @@ public class DesktopVRSwitch : MelonMod
//what even does this do that is actually important? //what even does this do that is actually important?
SteamVR.SafeDispose(); SteamVR.SafeDispose();
} }
CloseMenuElements(toVR);
yield return new WaitForEndOfFrame();
SetMetaPort(toVR);
yield return new WaitForEndOfFrame();
SetPlayerSetup(toVR);
SwitchActiveCameraRigs(toVR);
CreateTempVRIK(toVR);
QuickCalibrate(toVR);
RepositionCohtmlHud(toVR);
yield return new WaitForEndOfFrame();
SetMovementSystem(toVR);
yield return new WaitForEndOfFrame();
//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);
Recalibrate();
yield return null;
isAttemptingSwitch = false;
} }
//shitton of try catch below
// shouldn't be that important, right? // shouldn't be that important, right?
private static void CloseMenuElements(bool isVR) private static void CloseMenuElements(bool isVR)
{ {
@ -234,9 +244,9 @@ public class DesktopVRSwitch : MelonMod
{ {
MelonLogger.Msg("Parented CohtmlHud to active camera."); MelonLogger.Msg("Parented CohtmlHud to active camera.");
CohtmlHud.Instance.gameObject.transform.parent = isVR ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.desktopCamera.transform; CohtmlHud.Instance.gameObject.transform.parent = isVR ? PlayerSetup.Instance.vrCamera.transform : PlayerSetup.Instance.desktopCamera.transform;
//i think the VR offset may be different between headsets, but i cannot find where in games code they are set
CohtmlHud.Instance.gameObject.transform.localPosition = isVR ? new Vector3(-0.2f, -0.391f, 1.244f) : new Vector3(0f, 0f, 1.3f); //sets hud position, rotation, and scale based on MetaPort isUsingVr
CohtmlHud.Instance.gameObject.transform.localRotation = Quaternion.Euler(new Vector3(0f, 180f, 0f)); CVRTools.ConfigureHudAffinity();
} }
catch (Exception) catch (Exception)
{ {
@ -301,4 +311,38 @@ public class DesktopVRSwitch : MelonMod
throw; throw;
} }
} }
//every nameplate canvas uses CameraFacingObject :stare:
//might need to use actual Desktop/VR cam instead of Camera.main
private static void UpdateCameraFacingObject()
{
try
{
CameraFacingObject[] camfaceobjs = Object.FindObjectsOfType<CameraFacingObject>();
for (int i = 0; i < camfaceobjs.Count(); i++)
{
camfaceobjs[i].m_Camera = Camera.main;
}
}
catch (Exception)
{
MelonLogger.Error("Error updating CameraFacingObject objects! Nameplates will be wonk...");
throw;
}
}
private static void UpdateHudOperations(bool isVR)
{
try
{
HudOperations.Instance.worldLoadingItem = isVR ? HudOperations.Instance.worldLoadingItemVr : HudOperations.Instance.worldLoadingItemDesktop;
HudOperations.Instance.worldLoadStatus = isVR ? HudOperations.Instance.worldLoadStatusVr : HudOperations.Instance.worldLoadStatusDesktop;
}
catch (Exception)
{
MelonLogger.Error("Error updating HudOperations LoadingItem & LoadStatus!");
throw;
}
}
} }