i hate all

holy shit this fucking bug took me two hours to fix
why was the solution so simple... fuck
This commit is contained in:
NotAKidoS 2023-01-03 21:11:16 -06:00
parent 845baee849
commit 4a5527d7de
4 changed files with 38 additions and 126 deletions

View file

@ -78,13 +78,16 @@ internal class HarmonyPatches
}
//hook quickmenu open/close
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(CVR_MenuManager), "ToggleQuickMenu", new Type[] { typeof(bool) })]
private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show)
private static void Postfix_CVR_MenuManager_ToggleQuickMenu(bool show, ref bool ____quickMenuOpen)
{
if (QuickMenuHelper.Instance == null) return;
QuickMenuHelper.Instance.UpdateWorldAnchors();
MSP_MenuInfo.ToggleDesktopInputMethod(show);
if (show != ____quickMenuOpen)
{
QuickMenuHelper.Instance.UpdateWorldAnchors();
MSP_MenuInfo.ToggleDesktopInputMethod(show);
}
QuickMenuHelper.Instance.enabled = show;
}
@ -97,13 +100,16 @@ internal class HarmonyPatches
}
//hook menu open/close
[HarmonyPostfix]
[HarmonyPrefix]
[HarmonyPatch(typeof(ViewManager), "UiStateToggle", new Type[] { typeof(bool) })]
private static void Postfix_ViewManager_UiStateToggle(bool show)
private static void Postfix_ViewManager_UiStateToggle(bool show, ref bool ____gameMenuOpen)
{
if (MainMenuHelper.Instance == null) return;
MainMenuHelper.Instance.UpdateWorldAnchors();
MSP_MenuInfo.ToggleDesktopInputMethod(show);
if (show != ____gameMenuOpen)
{
MainMenuHelper.Instance.UpdateWorldAnchors();
MSP_MenuInfo.ToggleDesktopInputMethod(show);
}
MainMenuHelper.Instance.enabled = show;
}
@ -114,13 +120,4 @@ internal class HarmonyPatches
{
MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform;
}
//only fixes Desktop QM interaction while using independent head input...
//[HarmonyPrefix]
//[HarmonyPatch(typeof(ControllerRay), "LateUpdate")]
//private static void UpdateMenuPositionForInput()
//{
// MainMenuHelper.Instance.UpdateMenuPosition();
// QuickMenuHelper.Instance.UpdateMenuPosition();
//}
}

View file

@ -28,11 +28,6 @@ public class MainMenuHelper : MonoBehaviour
public static MainMenuHelper Instance;
public Transform worldAnchor;
static readonly FieldInfo ms_followAngleY = typeof(MovementSystem).GetField("_followAngleY", BindingFlags.NonPublic | BindingFlags.Instance);
private bool independentHeadTurn = false;
private bool returnIndependentHeadTurn = false;
private bool prevIndependentHeadTurn = false;
void Start()
{
Instance = this;
@ -41,23 +36,10 @@ public class MainMenuHelper : MonoBehaviour
void LateUpdate()
{
MSP_MenuInfo.HandleIndependentLookInput();
UpdateMenuPosition();
}
void OnEnable()
{
independentHeadTurn = false;
returnIndependentHeadTurn = false;
prevIndependentHeadTurn = false;
}
void OnDisable()
{
independentHeadTurn = false;
returnIndependentHeadTurn = false;
prevIndependentHeadTurn = false;
}
public void CreateWorldAnchors()
{
//VR specific anchor
@ -99,39 +81,6 @@ public class MainMenuHelper : MonoBehaviour
HandleVRPosition();
return;
}
float angle = (float)ms_followAngleY.GetValue(MovementSystem.Instance);
bool independentHeadTurnChanged = CVRInputManager.Instance.independentHeadTurn != prevIndependentHeadTurn;
if (independentHeadTurnChanged)
{
prevIndependentHeadTurn = CVRInputManager.Instance.independentHeadTurn;
//if pressing but not already enabled
if (prevIndependentHeadTurn)
{
if (!independentHeadTurn && angle == 0f)
{
UpdateWorldAnchors();
MSP_MenuInfo.ToggleDesktopInputMethod(!prevIndependentHeadTurn);
independentHeadTurn = true;
}
returnIndependentHeadTurn = false;
}
else
{
returnIndependentHeadTurn = true;
}
}
if (returnIndependentHeadTurn)
{
if (angle == 0f)
{
independentHeadTurn = false;
returnIndependentHeadTurn = false;
MSP_MenuInfo.ToggleDesktopInputMethod(!prevIndependentHeadTurn);
}
}
HandleDesktopPosition();
}
@ -139,8 +88,7 @@ public class MainMenuHelper : MonoBehaviour
public void HandleDesktopPosition()
{
if (MSP_MenuInfo.CameraTransform == null || MSP_MenuInfo.DisableMMHelper) return;
Transform activeAnchor = independentHeadTurn ? worldAnchor : MSP_MenuInfo.CameraTransform;
Transform activeAnchor = MSP_MenuInfo.independentHeadTurn ? worldAnchor : MSP_MenuInfo.CameraTransform;
transform.localScale = new Vector3(1.6f * MSP_MenuInfo.ScaleFactor, 0.9f * MSP_MenuInfo.ScaleFactor, 1f);
transform.eulerAngles = activeAnchor.eulerAngles;
transform.position = activeAnchor.position + activeAnchor.forward * 1f * MSP_MenuInfo.ScaleFactor * MSP_MenuInfo.AspectRatio;

View file

@ -27,11 +27,6 @@ public class QuickMenuHelper : MonoBehaviour
public Transform worldAnchor;
public Transform handAnchor;
static readonly FieldInfo ms_followAngleY = typeof(MovementSystem).GetField("_followAngleY", BindingFlags.NonPublic | BindingFlags.Instance);
private bool independentHeadTurn = false;
private bool returnIndependentHeadTurn = false;
private bool prevIndependentHeadTurn = false;
void Start()
{
Instance = this;
@ -40,23 +35,10 @@ public class QuickMenuHelper : MonoBehaviour
void LateUpdate()
{
MSP_MenuInfo.HandleIndependentLookInput();
UpdateMenuPosition();
}
void OnEnable()
{
independentHeadTurn = false;
returnIndependentHeadTurn = false;
prevIndependentHeadTurn = false;
}
void OnDisable()
{
independentHeadTurn = false;
returnIndependentHeadTurn = false;
prevIndependentHeadTurn = false;
}
public void CreateWorldAnchors()
{
//VR specific anchor
@ -69,7 +51,6 @@ public class QuickMenuHelper : MonoBehaviour
public void UpdateWorldAnchors()
{
if (worldAnchor == null || MSP_MenuInfo.CameraTransform == null) return;
worldAnchor.eulerAngles = MSP_MenuInfo.CameraTransform.eulerAngles;
worldAnchor.position = MSP_MenuInfo.CameraTransform.position;
}
@ -81,39 +62,6 @@ public class QuickMenuHelper : MonoBehaviour
HandleVRPosition();
return;
}
float angle = (float)ms_followAngleY.GetValue(MovementSystem.Instance);
bool independentHeadTurnChanged = CVRInputManager.Instance.independentHeadTurn != prevIndependentHeadTurn;
if (independentHeadTurnChanged)
{
prevIndependentHeadTurn = CVRInputManager.Instance.independentHeadTurn;
//if pressing but not already enabled
if (prevIndependentHeadTurn)
{
if (!independentHeadTurn && angle == 0f)
{
UpdateWorldAnchors();
MSP_MenuInfo.ToggleDesktopInputMethod(!prevIndependentHeadTurn);
independentHeadTurn = true;
}
returnIndependentHeadTurn = false;
}
else
{
returnIndependentHeadTurn = true;
}
}
if (returnIndependentHeadTurn)
{
if (angle == 0f)
{
independentHeadTurn = false;
returnIndependentHeadTurn = false;
MSP_MenuInfo.ToggleDesktopInputMethod(!prevIndependentHeadTurn);
}
}
HandleDesktopPosition();
}
@ -122,7 +70,7 @@ public class QuickMenuHelper : MonoBehaviour
{
if (MSP_MenuInfo.CameraTransform == null || MSP_MenuInfo.DisableQMHelper) return;
Transform activeAnchor = independentHeadTurn ? worldAnchor : MSP_MenuInfo.CameraTransform;
Transform activeAnchor = MSP_MenuInfo.independentHeadTurn ? worldAnchor : MSP_MenuInfo.CameraTransform;
transform.localScale = new Vector3(1f * MSP_MenuInfo.ScaleFactor, 1f * MSP_MenuInfo.ScaleFactor, 1f);
transform.eulerAngles = activeAnchor.eulerAngles;
transform.position = activeAnchor.position + activeAnchor.transform.forward * 1f * MSP_MenuInfo.ScaleFactor;

View file

@ -1,4 +1,5 @@
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -32,11 +33,29 @@ public class MSP_MenuInfo
public static void ToggleDesktopInputMethod(bool flag)
{
if (MetaPort.Instance.isUsingVr) return;
MelonLoader.MelonLogger.Msg("Toggled Desktop Input");
PlayerSetup.Instance._movementSystem.disableCameraControl = flag;
CVRInputManager.Instance.inputEnabled = !flag;
RootLogic.Instance.ToggleMouse(flag);
CVR_MenuManager.Instance.desktopControllerRay.enabled = !flag;
Traverse.Create(CVR_MenuManager.Instance).Field("_desktopMouseMode").SetValue(flag);
}
static readonly FieldInfo ms_followAngleY = typeof(MovementSystem).GetField("_followAngleY", BindingFlags.NonPublic | BindingFlags.Instance);
public static bool independentHeadTurn = false;
public static void HandleIndependentLookInput()
{
//angle of independent look axis
float angle = (float)ms_followAngleY.GetValue(MovementSystem.Instance);
bool isPressed = CVRInputManager.Instance.independentHeadTurn;
if (isPressed && !independentHeadTurn)
{
independentHeadTurn = true;
MSP_MenuInfo.ToggleDesktopInputMethod(false);
}else if (!isPressed && independentHeadTurn && angle == 0f)
{
independentHeadTurn = false;
MSP_MenuInfo.ToggleDesktopInputMethod(true);
}
}
}