prop origin fixes, version 2

This commit is contained in:
NotAKidoS 2022-10-29 09:07:27 -05:00
parent 9fee74f587
commit 7f860f4fc2
3 changed files with 107 additions and 20 deletions

View file

@ -1,42 +1,37 @@
using ABI_RC.Core; using ABI_RC.Core;
using ABI_RC.Core.EventSystem;
using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.InteractionSystem;
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.Util.Object_Behaviour; using ABI_RC.Core.Util.Object_Behaviour;
using ABI_RC.Systems.MovementSystem; using ABI_RC.Systems.Camera;
using ABI_RC.Core.EventSystem;
using ABI_RC.Systems.IK.SubSystems; using ABI_RC.Systems.IK.SubSystems;
using ABI_RC.Systems.MovementSystem;
using DesktopVRSwitch.Patches;
using HarmonyLib;
using MelonLoader; using MelonLoader;
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;
//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();
//nvm that resets the RichPresence clock- i want people to know how long ive wasted staring at mirror //nvm that resets the RichPresence clock- i want people to know how long ive wasted staring at mirror
namespace DesktopVRSwitch; namespace DesktopVRSwitch;
public class DesktopVRSwitch : MelonMod public class DesktopVRSwitch : MelonMod
{ {
private static MelonPreferences_Category m_categoryDesktopVRSwitch; private static MelonPreferences_Category m_categoryDesktopVRSwitch;
private static MelonPreferences_Entry<bool> m_entryReloadInstance;
private static MelonPreferences_Entry<bool> m_entryTimedErrorCatch; private static MelonPreferences_Entry<bool> m_entryTimedErrorCatch;
public override void OnApplicationStart() public override void OnInitializeMelon()
{ {
m_categoryDesktopVRSwitch = MelonPreferences.CreateCategory(nameof(DesktopVRSwitch)); m_categoryDesktopVRSwitch = MelonPreferences.CreateCategory(nameof(DesktopVRSwitch));
//m_entryReloadInstance = m_categoryDesktopVRSwitch.CreateEntry<bool>("Rejoin Instance", false, description: "Rejoin instance on switch.");
m_entryTimedErrorCatch = m_categoryDesktopVRSwitch.CreateEntry<bool>("Timed Error Catch", true, description: "Attempt to switch back if an error is found after 10 seconds."); m_entryTimedErrorCatch = m_categoryDesktopVRSwitch.CreateEntry<bool>("Timed Error Catch", true, description: "Attempt to switch back if an error is found after 10 seconds.");
m_categoryDesktopVRSwitch.SaveToFile(false); m_categoryDesktopVRSwitch.SaveToFile(false);
} }
@ -93,6 +88,7 @@ public class DesktopVRSwitch : MelonMod
InitializeSteamVR(VRMode); InitializeSteamVR(VRMode);
CloseMenuElements(VRMode); CloseMenuElements(VRMode);
DisableMirrorCanvas();
yield yield
return new WaitForEndOfFrame(); return new WaitForEndOfFrame();
@ -107,12 +103,13 @@ public class DesktopVRSwitch : MelonMod
UpdateCameraFacingObject(); UpdateCameraFacingObject();
RepositionCohtmlHud(VRMode); RepositionCohtmlHud(VRMode);
UpdateHudOperations(VRMode); UpdateHudOperations(VRMode);
SwitchPickupOrigins();
yield yield
return new WaitForEndOfFrame(); return new WaitForEndOfFrame();
//needs to come after SetMovementSystem //needs to come after SetMovementSystem
//UpdateGestureReconizerCam(); UpdateGestureReconizerCam();
yield yield
return new WaitForEndOfFrame(); return new WaitForEndOfFrame();
@ -193,7 +190,6 @@ public class DesktopVRSwitch : MelonMod
{ {
MelonLogger.Msg("Closed MainMenu Instance."); MelonLogger.Msg("Closed MainMenu Instance.");
ViewManager.Instance.UiStateToggle(false); ViewManager.Instance.UiStateToggle(false);
ViewManager.Instance.VrInputChanged(isVR);
} }
else else
{ {
@ -267,7 +263,7 @@ 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;
//sets hud position, rotation, and scale based on MetaPort isUsingVr //sets hud position, rotation, ~~and scale~~ based on MetaPort isUsingVr
CVRTools.ConfigureHudAffinity(); CVRTools.ConfigureHudAffinity();
CohtmlHud.Instance.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f); CohtmlHud.Instance.gameObject.transform.localScale = new Vector3(1.2f, 1f, 1.2f);
} }
@ -339,14 +335,13 @@ public class DesktopVRSwitch : MelonMod
} }
} }
//this doesnt seem to work private static void DisableMirrorCanvas()
private static void UpdateGestureReconizerCam()
{ {
try try
{ {
MelonLogger.Msg("Set GestureReconizerCam camera to Camera.main."); //tell the game we are in mirror mode so itll disable it (if enabled)
Camera cam = Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").GetValue() as Camera; PortableCamera.Instance.mode = MirroringMode.Mirror;
cam = PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>(); PortableCamera.Instance.ChangeMirroring();
} }
catch (Exception) catch (Exception)
{ {
@ -354,4 +349,37 @@ public class DesktopVRSwitch : MelonMod
throw; throw;
} }
} }
private static void UpdateGestureReconizerCam()
{
try
{
MelonLogger.Msg("Set GestureReconizerCam camera to active camera.");
Traverse.Create(CVRGestureRecognizer.Instance).Field("_camera").SetValue(PlayerSetup.Instance.GetActiveCamera().GetComponent<Camera>());
}
catch (Exception)
{
MelonLogger.Error("Error updating CVRGestureRecognizer camera!");
throw;
}
}
private static void SwitchPickupOrigins()
{
try
{
MelonLogger.Msg("Switched pickup origins.");
CVRPickupObjectTracker[] pickups = Object.FindObjectsOfType<CVRPickupObjectTracker>();
for (int i = 0; i < pickups.Count(); i++)
{
pickups[i].OnSwitch();
}
}
catch (Exception)
{
MelonLogger.Error("Error switching pickup origins!");
throw;
}
}
} }

View file

@ -0,0 +1,59 @@
using ABI.CCK.Components;
using ABI_RC.Core.Savior;
using HarmonyLib;
using MelonLoader;
using UnityEngine;
//Thanks Ben! I was scared of transpiler so I reworked a bit...
namespace DesktopVRSwitch.Patches;
[HarmonyPatch]
internal class CVRPickupObject_Patch
{
[HarmonyPrefix]
[HarmonyPatch(typeof(CVRPickupObject), "Start")]
private static void CVRPickupObject_Start_Prefix(ref CVRPickupObject __instance)
{
Transform desktopOrigin = __instance.gripOrigin.Find("[Desktop]");
if (desktopOrigin == null) return;
var pickupTracker = __instance.GetComponent<CVRPickupObjectTracker>();
if (pickupTracker != null) return;
__instance.gameObject.AddComponent<CVRPickupObjectTracker>();
StorePreviousPosition(__instance, (!MetaPort.Instance.isUsingVr) ? __instance.gripOrigin : desktopOrigin);
}
private static void StorePreviousPosition(CVRPickupObject pickupObject, Transform gripOrigin)
{
MelonLogger.Msg("Storing previous gripOrigin.");
CVRPickupObjectTracker.previousGripOrigin[pickupObject] = gripOrigin;
}
}
public class CVRPickupObjectTracker : MonoBehaviour
{
//maybe i should store both transforms instead and getcomponent for CVRPickupObject..?
public static Dictionary<CVRPickupObject, Transform> previousGripOrigin = new();
public void OnSwitch()
{
var pickupObject = GetComponent<CVRPickupObject>();
if (pickupObject != null)
{
if (pickupObject.IsGrabbedByMe()) pickupObject.Drop();
(previousGripOrigin[pickupObject], pickupObject.gripOrigin) = (pickupObject.gripOrigin, previousGripOrigin[pickupObject]);
}
}
private void OnDestroy()
{
var pickupObject = GetComponent<CVRPickupObject>();
if (pickupObject != null)
previousGripOrigin.Remove(pickupObject);
}
}

View file

@ -25,6 +25,6 @@ using System.Reflection;
namespace DesktopVRSwitch.Properties; namespace DesktopVRSwitch.Properties;
internal static class AssemblyInfoParams internal static class AssemblyInfoParams
{ {
public const string Version = "1.0.0"; public const string Version = "2.0.0";
public const string Author = "NotAKidoS"; public const string Author = "NotAKidoS";
} }