initial shitshow

works sometimes

desktop to vr is reliable enough.. vr to desktop is struggling
cannot get steamvr to let go of chillout after loading openvr device : think :
This commit is contained in:
NotAKidoS 2022-09-24 23:18:31 -05:00
parent 26b489d130
commit db5d7d91a7
4 changed files with 297 additions and 0 deletions

View file

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Assembly-CSharp-firstpass">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
</Reference>
<Reference Include="cohtml.Net">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\cohtml.Net.dll</HintPath>
</Reference>
<Reference Include="Cohtml.Runtime">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll</HintPath>
</Reference>
<Reference Include="Giamoz">
<HintPath>..\..\Giamoz\Giamoz\bin\Debug\net472\Giamoz.dll</HintPath>
</Reference>
<Reference Include="MelonLoader">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll</HintPath>
</Reference>
<Reference Include="SteamVR">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\SteamVR.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AnimationModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.PhysicsModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.PhysicsModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.VRModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.VRModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.XRModule">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.XRModule.dll</HintPath>
</Reference>
</ItemGroup>
<Target Name="Deploy" AfterTargets="Build">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" />
<Message Text="Copied $(TargetPath) to C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\Mods\" Importance="high" />
</Target>
</Project>

View file

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32630.192
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopVRSwitch", "DesktopVRSwitch.csproj", "{4008E6D1-32F9-449B-8820-80ACF0ED8233}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4008E6D1-32F9-449B-8820-80ACF0ED8233}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4008E6D1-32F9-449B-8820-80ACF0ED8233}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4008E6D1-32F9-449B-8820-80ACF0ED8233}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4008E6D1-32F9-449B-8820-80ACF0ED8233}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3C86465A-87F5-49EF-915C-5B5F568A8815}
EndGlobalSection
EndGlobal

181
DesktopVRSwitch/Main.cs Normal file
View file

@ -0,0 +1,181 @@
using HarmonyLib;
using MelonLoader;
using UnityEngine;
using RootMotion.FinalIK;
using ABI_RC.Core.Player;
using ABI_RC.Core.Savior;
using ABI.CCK.Components;
using ABI_RC.Core.InteractionSystem;
using ABI_RC.Systems.MovementSystem;
using ABI_RC.Core.UI;
using System.Reflection;
using cohtml;
using ABI_RC.Core.IO;
using System.Collections;
using System;
using UnityEngine.XR;
using Valve.VR;
namespace DesktopVRSwitch;
public class DesktopVRSwitch : MelonMod
{
private static MelonPreferences_Category m_categoryDesktopVRSwitch;
private static MelonPreferences_Entry<bool> m_entryEnabled;
private static System.Object melon;
public override void OnApplicationStart()
{
m_categoryDesktopVRSwitch = MelonPreferences.CreateCategory(nameof(DesktopVRSwitch));
m_entryEnabled = m_categoryDesktopVRSwitch.CreateEntry<bool>("Start SteamVR", false, description: "Launch SteamVR");
m_entryEnabled.OnValueChangedUntyped += UpdateSettings;
}
private static void UpdateSettings()
{
melon = MelonCoroutines.Start(AttemptPlatformSwitch());
}
static IEnumerator AttemptPlatformSwitch()
{
if (MetaPort.Instance.isUsingVr)
{
//close the UI cause cohtml can get grumpy
ViewManager.Instance.UiStateToggle(false);
CVR_MenuManager.Instance.ToggleQuickMenu(false);
MelonLogger.Msg("Closed ChilloutVR UI.");
MetaPort.Instance.isUsingVr = false;
MelonLogger.Msg("Set MetaPort isUsingVr to false.");
SteamVR_Behaviour.instance.enabled = false;
SteamVR_Render.instance.enabled = false;
yield return new WaitForEndOfFrame();
PlayerSetup.Instance._inVr = false;
PlayerSetup.Instance.Invoke("CalibrateAvatar", 0f);
MelonLogger.Msg("Invoked CalibrateAvatar() on PlayerSetup.Instance.");
PlayerSetup.Instance.desktopCameraRig.SetActive(true);
PlayerSetup.Instance.vrCameraRig.SetActive(false);
CohtmlHud.Instance.gameObject.transform.parent = PlayerSetup.Instance.desktopCamera.transform;
MelonLogger.Msg("Enabled Desktop camera rig.");
MelonLogger.Msg("Set PlayerSetup _inVr to false.");
yield return new WaitForEndOfFrame();
MovementSystem.Instance.isVr = false;
MelonLogger.Msg("Set MovementSystem isVr to false.");
//CVR_MovementSystem.Instance.isVr = true;
//MelonLogger.Msg("Set CVR_MovementSystem isVR to false.");
yield return new WaitForSeconds(0.5f);
CVRInputManager.Instance.reload = true;
//CVRInputManager.Instance.inputEnabled = true;
//CVRInputManager.Instance.blockedByUi = false;
//CVRInputManager.Instance.independentHeadToggle = false;
//MelonLogger.Msg("Set CVRInputManager reload to true. Input should reload next frame...");
yield return new WaitForSeconds(1f);
CVRInputManager.Instance.reload = true;
yield return new WaitForSeconds(0.5f);
XRSettings.enabled = false;
PlayerSetup.Instance.Invoke("CalibrateAvatar", 0f);
MelonLogger.Msg("Invoked CalibrateAvatar() on PlayerSetup.Instance.");
//ViewManager.Instance.VrInputChanged(true);
}
else
{
//close the UI cause cohtml can get grumpy
ViewManager.Instance.UiStateToggle(false);
CVR_MenuManager.Instance.ToggleQuickMenu(false);
MelonLogger.Msg("Closed ChilloutVR UI.");
MelonCoroutines.Start(LoadDevice("OpenVR"));
MelonLogger.Msg("OpenVR device loaded!");
yield return new WaitForSeconds(3);
MelonLogger.Msg("Set MetaPort isUsingVr to true.");
MetaPort.Instance.isUsingVr = true;
yield return new WaitForEndOfFrame();
VRIK ik = (VRIK)PlayerSetup.Instance._avatar.GetComponent(typeof(VRIK));
if (ik == null)
{
ik = PlayerSetup.Instance._avatar.AddComponent<VRIK>();
}
ik.solver.IKPositionWeight = 0f;
ik.enabled = false;
PlayerSetup.Instance._inVr = true;
PlayerSetup.Instance.Invoke("CalibrateAvatar", 0f);
MelonLogger.Msg("Invoked CalibrateAvatar() on PlayerSetup.Instance.");
PlayerSetup.Instance.desktopCameraRig.SetActive(false);
PlayerSetup.Instance.vrCameraRig.SetActive(true);
CohtmlHud.Instance.gameObject.transform.parent = PlayerSetup.Instance.vrCamera.transform;
MelonLogger.Msg("Disabled Desktop camera rig.");
MelonLogger.Msg("Set PlayerSetup _inVr to true.");
yield return new WaitForEndOfFrame();
MovementSystem.Instance.isVr = true;
MelonLogger.Msg("Set MovementSystem isVr to false.");
//CVR_MovementSystem.Instance.isVr = true;
//MelonLogger.Msg("Set CVR_MovementSystem isVR to false.");
yield return new WaitForSeconds(0.5f);
CVRInputManager.Instance.reload = true;
//CVRInputManager.Instance.inputEnabled = true;
//CVRInputManager.Instance.blockedByUi = false;
//CVRInputManager.Instance.independentHeadToggle = false;
//MelonLogger.Msg("Set CVRInputManager reload to true. Input should reload next frame...");
yield return new WaitForSeconds(1f);
CVRInputManager.Instance.reload = true;
//PlayerSetup.Instance.Invoke("CalibrateAvatar", 0f);
//MelonLogger.Msg("Invoked CalibrateAvatar() on PlayerSetup.Instance.");
//ViewManager.Instance.VrInputChanged(true);
}
yield return null;
}
static IEnumerator LoadDevice(string newDevice)
{
if (String.Compare(XRSettings.loadedDeviceName, newDevice, true) != 0)
{
XRSettings.LoadDeviceByName(newDevice);
yield return null;
XRSettings.enabled = true;
if (SteamVR_Behaviour.instance.enabled == false)
{
SteamVR_Behaviour.instance.enabled = true;
SteamVR_Render.instance.enabled = true;
}
}
else
{
MelonLogger.Msg("OpenVR device already loaded!");
MelonCoroutines.Stop(melon);
yield return null;
XRSettings.enabled = true;
if (SteamVR_Behaviour.instance.enabled == false)
{
SteamVR_Behaviour.instance.enabled = true;
SteamVR_Render.instance.enabled = true;
}
}
}
}

View file

@ -0,0 +1,30 @@
using MelonLoader;
using DesktopVRSwitch.Properties;
using System.Reflection;
[assembly: AssemblyVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)]
[assembly: AssemblyTitle(nameof(DesktopVRSwitch))]
[assembly: AssemblyCompany(AssemblyInfoParams.Author)]
[assembly: AssemblyProduct(nameof(DesktopVRSwitch))]
[assembly: MelonInfo(
typeof(DesktopVRSwitch.DesktopVRSwitch),
nameof(DesktopVRSwitch),
AssemblyInfoParams.Version,
AssemblyInfoParams.Author,
downloadLink: "https://github.com/NotAKidOnSteam/DesktopVRSwitch"
)]
[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")]
[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)]
[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)]
namespace DesktopVRSwitch.Properties;
internal static class AssemblyInfoParams
{
public const string Version = "1.0.0";
public const string Author = "NotAKidoS";
}