From e54a20ee42f38ae240271491c4767baf6c091d17 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 26 Dec 2022 22:21:43 -0600 Subject: [PATCH] fixed shit --- MenuScalePatch/Main.cs | 73 ++++++++++++++++++----- MenuScalePatch/Properties/AssemblyInfo.cs | 2 +- MenuScalePatch/format.json | 6 +- 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/MenuScalePatch/Main.cs b/MenuScalePatch/Main.cs index 7a090e2..b8b38df 100644 --- a/MenuScalePatch/Main.cs +++ b/MenuScalePatch/Main.cs @@ -13,26 +13,42 @@ public class MenuScalePatch : MelonMod [HarmonyPatch] private class HarmonyPatches { - [HarmonyPostfix] - [HarmonyPatch(typeof(CVR_MenuManager), "SetScale")] - private static void SetQMScale(ref CohtmlView ___quickMenu, ref float ____scaleFactor) + internal static bool adjustedMenuPosition = false; + internal static void SetMenuPosition(Transform menuTransform, float scale) { + Transform rotationPivot = PlayerSetup.Instance._movementSystem.rotationPivot; if (!MetaPort.Instance.isUsingVr) { - //correct quickmenu - pretty much needsQuickmenuPositionUpdate() - Transform rotationPivot = PlayerSetup.Instance._movementSystem.rotationPivot; - ___quickMenu.transform.eulerAngles = new Vector3(rotationPivot.eulerAngles.x, rotationPivot.eulerAngles.y, rotationPivot.eulerAngles.z); - ___quickMenu.transform.position = rotationPivot.position + rotationPivot.forward * 1f * ____scaleFactor; + menuTransform.eulerAngles = rotationPivot.eulerAngles; } + menuTransform.position = rotationPivot.position + rotationPivot.forward * 1f * scale; + adjustedMenuPosition = true; } - //ViewManager.SetScale runs once a second when it should only run when aspect ratio changes- CVR bug - //assuming its caused by cast from int to float getting the screen size, something floating point bleh - //attempting to ignore that call if there wasnt actually a change + [HarmonyPostfix] + [HarmonyPatch(typeof(CVR_MenuManager), "SetScale")] + private static void SetQMScale(ref CohtmlView ___quickMenu, ref bool ___needsQuickmenuPositionUpdate, ref float ____scaleFactor, ref GameObject ____leftVrAnchor) + { + if (MetaPort.Instance.isUsingVr) + { + ___quickMenu.transform.position = ____leftVrAnchor.transform.position; + ___quickMenu.transform.rotation = ____leftVrAnchor.transform.rotation; + ___needsQuickmenuPositionUpdate = false; + return; + } + SetMenuPosition(___quickMenu.transform, ____scaleFactor); + ___needsQuickmenuPositionUpdate = false; + } + + /** + ViewManager.SetScale runs once a second when it should only run when aspect ratio changes- CVR bug + assuming its caused by cast from int to float getting the screen size, something floating point bleh + attempting to ignore that call if there wasnt actually a change + **/ [HarmonyPrefix] [HarmonyPatch(typeof(ViewManager), "SetScale")] - private static void CheckLegit(float avatarHeight, ref float ___cachedAvatarHeight, out bool __state) + private static void CheckMMScale(float avatarHeight, ref float ___cachedAvatarHeight, out bool __state) { if (___cachedAvatarHeight == avatarHeight) { @@ -48,10 +64,39 @@ public class MenuScalePatch : MelonMod { if (!__state) return; - //correct main menu - pretty much UpdateMenuPosition() - Transform rotationPivot = PlayerSetup.Instance._movementSystem.rotationPivot; - __instance.gameObject.transform.position = rotationPivot.position + __instance.gameObject.transform.forward * 1f * ___scaleFactor; + SetMenuPosition(__instance.transform, ___scaleFactor); ___needsMenuPositionUpdate = false; } + + /** + Following code resets the menu position on LateUpdate so you can use the menu while moving/falling. + It is Desktop only. QM inputs still don't work because they do their input checks in LateUpdate??? + **/ + + [HarmonyPrefix] + [HarmonyPatch(typeof(CVR_MenuManager), "LateUpdate")] + private static void DesktopQMFix(ref CohtmlView ___quickMenu, ref bool ___needsQuickmenuPositionUpdate, ref float ____scaleFactor, ref bool ____quickMenuOpen) + { + if (MetaPort.Instance.isUsingVr) return; + if (____quickMenuOpen && !adjustedMenuPosition) + { + SetMenuPosition(___quickMenu.transform, ____scaleFactor); + ___needsQuickmenuPositionUpdate = false; + } + adjustedMenuPosition = false; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(ViewManager), "LateUpdate")] + private static void DesktopMMFix(ref ViewManager __instance, ref bool ___needsMenuPositionUpdate, ref float ___scaleFactor, bool __state, ref bool ____gameMenuOpen) + { + if (MetaPort.Instance.isUsingVr) return; + if (____gameMenuOpen && !adjustedMenuPosition) + { + SetMenuPosition(__instance.transform, ___scaleFactor); + ___needsMenuPositionUpdate = false; + } + adjustedMenuPosition = false; + } } } \ No newline at end of file diff --git a/MenuScalePatch/Properties/AssemblyInfo.cs b/MenuScalePatch/Properties/AssemblyInfo.cs index e5e3453..a007473 100644 --- a/MenuScalePatch/Properties/AssemblyInfo.cs +++ b/MenuScalePatch/Properties/AssemblyInfo.cs @@ -25,6 +25,6 @@ using System.Reflection; namespace MenuScalePatch.Properties; internal static class AssemblyInfoParams { - public const string Version = "2.0.0"; + public const string Version = "3.0.0"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/MenuScalePatch/format.json b/MenuScalePatch/format.json index e845b2b..0efb4ff 100644 --- a/MenuScalePatch/format.json +++ b/MenuScalePatch/format.json @@ -1,8 +1,8 @@ { "_id": 95, "name": "MenuScalePatch", - "modversion": "2.0.0", - "gameversion": "2022r169", + "modversion": "3.0.0", + "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", "author": "NotAKidoS", @@ -18,6 +18,6 @@ ], "downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/r4/MenuScalePatch.dll", "sourcelink": "https://github.com/NotAKidOnSteam/MenuScalePatch/", - "changelog": "Removed collision scaling feature as it is now native.", + "changelog": "Removed collision scaling feature as it is now native.\nImplemented adjusted QM scaling for VR.\nAdded menu correction for Desktop so you can use menus while moving.", "embedcolor": "804221" } \ No newline at end of file