diff --git a/DesktopVRIK/DesktopVRIKSystem.cs b/DesktopVRIK/DesktopVRIKSystem.cs index 81d0896..25ae996 100644 --- a/DesktopVRIK/DesktopVRIKSystem.cs +++ b/DesktopVRIK/DesktopVRIKSystem.cs @@ -183,6 +183,7 @@ internal class DesktopVRIKSystem : MonoBehaviour // Last Movement Parent Info Vector3 _movementPosition; Quaternion _movementRotation; + CVRMovementParent _currentParent; DesktopVRIKSystem() { @@ -377,14 +378,19 @@ internal class DesktopVRIKSystem : MonoBehaviour // desktop pivots from playerlocal transform var platformPivot = transform.position; - // Add platform motion to IK solver - avatarIKSolver.AddPlatformMotion(deltaPosition, deltaRotation, platformPivot); + // Prevent targeting other parent position + if (_currentParent == currentParent) + { + // Add platform motion to IK solver + avatarIKSolver.AddPlatformMotion(deltaPosition, deltaRotation, platformPivot); + ResetDesktopVRIK(); + } // Store for next frame + _currentParent = currentParent; _movementPosition = currentPosition; _movementRotation = currentRotation; - ResetDesktopVRIK(); return true; } diff --git a/DesktopVRIK/HarmonyPatches.cs b/DesktopVRIK/HarmonyPatches.cs index 69bf391..d66c1b7 100644 --- a/DesktopVRIK/HarmonyPatches.cs +++ b/DesktopVRIK/HarmonyPatches.cs @@ -1,6 +1,7 @@ using ABI_RC.Core.Player; using HarmonyLib; using UnityEngine; +using ABI.CCK.Components; /** @@ -64,4 +65,4 @@ class PlayerSetupPatches { return !(bool)DesktopVRIKSystem.Instance?.OnPlayerSetupResetIk(); } -} +} \ No newline at end of file diff --git a/DesktopVRIK/Properties/AssemblyInfo.cs b/DesktopVRIK/Properties/AssemblyInfo.cs index b1dcf82..8c203c9 100644 --- a/DesktopVRIK/Properties/AssemblyInfo.cs +++ b/DesktopVRIK/Properties/AssemblyInfo.cs @@ -26,6 +26,6 @@ using System.Reflection; namespace NAK.Melons.DesktopVRIK.Properties; internal static class AssemblyInfoParams { - public const string Version = "4.1.7"; + public const string Version = "4.1.8"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/DesktopVRIK/format.json b/DesktopVRIK/format.json index 8075692..0b99f9f 100644 --- a/DesktopVRIK/format.json +++ b/DesktopVRIK/format.json @@ -1,7 +1,7 @@ { "_id": 117, "name": "DesktopVRIK", - "modversion": "4.1.7", + "modversion": "4.1.8", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", @@ -17,8 +17,8 @@ "requirements": [ "BTKUILib" ], - "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r1/DesktopVRIK.dll", + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r2/DesktopVRIK.dll", "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/", - "changelog": "- Enable useAnimatedBendNormal when Locomotion tracking is disabled. This fixes some sitting animations that bend at unnatural angles.\n- Fix avatar root offset not being reset when entering/playing emotes.", + "changelog": "- Fixed feet targeting previous movement parent position for a frame.", "embedcolor": "9b59b6" } \ No newline at end of file diff --git a/IKFixes/HarmonyPatches.cs b/IKFixes/HarmonyPatches.cs index 1ebc6eb..3c623f0 100644 --- a/IKFixes/HarmonyPatches.cs +++ b/IKFixes/HarmonyPatches.cs @@ -7,7 +7,7 @@ using HarmonyLib; using RootMotion.FinalIK; using UnityEngine; -namespace NAK.Melons.IKFixes.HarmonyPatches; +namespace NAK.IKFixes.HarmonyPatches; internal static class BodySystemPatches { @@ -213,6 +213,7 @@ internal static class VRIKPatches internal static class PlayerSetupPatches { // Last Movement Parent Info + static CVRMovementParent lastMovementParent; static Vector3 lastMovementPosition; static Quaternion lastMovementRotation; @@ -234,10 +235,15 @@ internal static class PlayerSetupPatches Vector3 deltaPosition = currentPosition - lastMovementPosition; Quaternion deltaRotation = Quaternion.Inverse(lastMovementRotation) * currentRotation; - // Add platform motion to IK solver - IKSystem.vrik.solver.AddPlatformMotion(deltaPosition, deltaRotation, currentPosition); + // Prevent targeting other parent position + if (lastMovementParent == currentParent || lastMovementParent == null) + { + // Add platform motion to IK solver + IKSystem.vrik.solver.AddPlatformMotion(deltaPosition, deltaRotation, currentPosition); + } // Store for next frame + lastMovementParent = currentParent; lastMovementPosition = currentPosition; lastMovementRotation = currentRotation; return false; diff --git a/IKFixes/Main.cs b/IKFixes/Main.cs index 3a443f0..605f37d 100644 --- a/IKFixes/Main.cs +++ b/IKFixes/Main.cs @@ -1,6 +1,6 @@ using MelonLoader; -namespace NAK.Melons.IKFixes; +namespace NAK.IKFixes; public class IKFixes : MelonMod { diff --git a/IKFixes/Properties/AssemblyInfo.cs b/IKFixes/Properties/AssemblyInfo.cs index a3e9278..477dfff 100644 --- a/IKFixes/Properties/AssemblyInfo.cs +++ b/IKFixes/Properties/AssemblyInfo.cs @@ -1,17 +1,17 @@ using MelonLoader; -using NAK.Melons.IKFixes.Properties; +using NAK.IKFixes.Properties; using System.Reflection; [assembly: AssemblyVersion(AssemblyInfoParams.Version)] [assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] [assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] -[assembly: AssemblyTitle(nameof(NAK.Melons.IKFixes))] +[assembly: AssemblyTitle(nameof(NAK.IKFixes))] [assembly: AssemblyCompany(AssemblyInfoParams.Author)] -[assembly: AssemblyProduct(nameof(NAK.Melons.IKFixes))] +[assembly: AssemblyProduct(nameof(NAK.IKFixes))] [assembly: MelonInfo( - typeof(NAK.Melons.IKFixes.IKFixes), - nameof(NAK.Melons.IKFixes), + typeof(NAK.IKFixes.IKFixes), + nameof(NAK.IKFixes), AssemblyInfoParams.Version, AssemblyInfoParams.Author, downloadLink: "https://github.com/NotAKidOnSteam/IKFixes" @@ -22,9 +22,9 @@ using System.Reflection; [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] [assembly: HarmonyDontPatchAll] -namespace NAK.Melons.IKFixes.Properties; +namespace NAK.IKFixes.Properties; internal static class AssemblyInfoParams { - public const string Version = "1.0.2"; + public const string Version = "1.0.3"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/IKFixes/format.json b/IKFixes/format.json index 0ca28a9..d8c7e74 100644 --- a/IKFixes/format.json +++ b/IKFixes/format.json @@ -1,7 +1,7 @@ { "_id": 142, "name": "IKFixes", - "modversion": "1.0.2", + "modversion": "1.0.3", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/IKFixes/releases/download/v1.0.2/IKFixes.dll", - "sourcelink": "https://github.com/NotAKidOnSteam/IKFixes/", - "changelog": "- Initial Release\n- Added FakeRootAngle fix for Halfbody. Feet will no longer only point in the direction of head while looking around/turning. This can be disabled in mod settings.", + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r2/IKFixes.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/", + "changelog": "- Fixed feet targeting previous movement parent position for a frame.", "embedcolor": "f46e49" } \ No newline at end of file diff --git a/MenuScalePatch/HarmonyPatches.cs b/MenuScalePatch/HarmonyPatches.cs index 445a258..32c8ceb 100644 --- a/MenuScalePatch/HarmonyPatches.cs +++ b/MenuScalePatch/HarmonyPatches.cs @@ -1,12 +1,15 @@ -using ABI_RC.Core; +using ABI.CCK.Components; +using ABI_RC.Core; using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Player; using ABI_RC.Core.Savior; using HarmonyLib; -using NAK.Melons.MenuScalePatch.Helpers; +using NAK.MenuScalePatch.Helpers; +using System.Reflection; +using System.Reflection.Emit; using UnityEngine; -namespace NAK.Melons.MenuScalePatch.HarmonyPatches; +namespace NAK.MenuScalePatch.HarmonyPatches; /** ViewManager.SetScale runs once a second when it should only run when aspect ratio changes- CVR bug @@ -21,17 +24,10 @@ internal class HarmonyPatches [HarmonyPatch(typeof(PlayerSetup), "Start")] private static void Postfix_PlayerSetup_Start() { - try - { - MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform; - MenuScalePatch.UpdateAllSettings(); - QuickMenuHelper.Instance.CreateWorldAnchors(); - MainMenuHelper.Instance.CreateWorldAnchors(); - } - catch (System.Exception e) - { - MenuScalePatch.Logger.Error(e); - } + MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform; + MenuScalePatch.UpdateSettings(); + QuickMenuHelper.Instance.CreateWorldAnchors(); + MainMenuHelper.Instance.CreateWorldAnchors(); } [HarmonyPrefix] @@ -83,15 +79,8 @@ internal class HarmonyPatches [HarmonyPatch(typeof(CVR_MenuManager), "Start")] private static void Postfix_CVR_MenuManager_Start(ref CVR_MenuManager __instance, ref GameObject ____leftVrAnchor) { - try - { - QuickMenuHelper helper = __instance.quickMenu.gameObject.AddComponent(); - helper.handAnchor = ____leftVrAnchor.transform; - } - catch (System.Exception e) - { - MenuScalePatch.Logger.Error(e); - } + QuickMenuHelper helper = __instance.quickMenu.gameObject.AddComponent(); + helper.handAnchor = ____leftVrAnchor.transform; } //Set MM stuff @@ -99,14 +88,7 @@ internal class HarmonyPatches [HarmonyPatch(typeof(ViewManager), "Start")] private static void Postfix_ViewManager_Start(ref ViewManager __instance) { - try - { - __instance.gameObject.AddComponent(); - } - catch (System.Exception e) - { - MenuScalePatch.Logger.Error(e); - } + __instance.gameObject.AddComponent(); } //hook quickmenu open/close @@ -178,13 +160,28 @@ internal class HarmonyPatches [HarmonyPatch(typeof(CVRTools), "ConfigureHudAffinity")] private static void Postfix_CVRTools_ConfigureHudAffinity() { - try - { - MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform; - } - catch (System.Exception e) - { - MenuScalePatch.Logger.Error(e); - } + MSP_MenuInfo.CameraTransform = PlayerSetup.Instance.GetActiveCamera().transform; + } + + // prevents CVRWorld from closing menus when world transitioning, cause cool + [HarmonyTranspiler] + [HarmonyPatch(typeof(CVRWorld), nameof(CVRWorld.Start), MethodType.Enumerator)] + private static IEnumerable Transpiler_CVRWorld_Start(IEnumerable instructions, ILGenerator il) + { + var patchedInstructions = new CodeMatcher(instructions).MatchForward(false, + new CodeMatch(OpCodes.Ldsfld), + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(i => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo { Name: "ForceUiStatus" })) + .RemoveInstructions(3) + .InstructionEnumeration(); + + patchedInstructions = new CodeMatcher(patchedInstructions).MatchForward(false, + new CodeMatch(OpCodes.Ldsfld), + new CodeMatch(OpCodes.Ldc_I4_0), + new CodeMatch(i => i.opcode == OpCodes.Callvirt && i.operand is MethodInfo { Name: "ToggleQuickMenu" })) + .RemoveInstructions(3) + .InstructionEnumeration(); + + return patchedInstructions; } } \ No newline at end of file diff --git a/MenuScalePatch/Helpers/MainMenuHelper.cs b/MenuScalePatch/Helpers/MainMenuHelper.cs index b41ff44..0849ba5 100644 --- a/MenuScalePatch/Helpers/MainMenuHelper.cs +++ b/MenuScalePatch/Helpers/MainMenuHelper.cs @@ -3,7 +3,7 @@ using ABI_RC.Core.Savior; using UnityEngine; -namespace NAK.Melons.MenuScalePatch.Helpers; +namespace NAK.MenuScalePatch.Helpers; //TODO: Implement desktop ratio scaling back to MM diff --git a/MenuScalePatch/Helpers/QuickMenuHelper.cs b/MenuScalePatch/Helpers/QuickMenuHelper.cs index c5c2aae..7404ec8 100644 --- a/MenuScalePatch/Helpers/QuickMenuHelper.cs +++ b/MenuScalePatch/Helpers/QuickMenuHelper.cs @@ -2,7 +2,7 @@ using ABI_RC.Core.Savior; using UnityEngine; -namespace NAK.Melons.MenuScalePatch.Helpers; +namespace NAK.MenuScalePatch.Helpers; /** diff --git a/MenuScalePatch/MSP_Menus.cs b/MenuScalePatch/MSP_Menus.cs index aae26d2..a20dcde 100644 --- a/MenuScalePatch/MSP_Menus.cs +++ b/MenuScalePatch/MSP_Menus.cs @@ -2,10 +2,9 @@ using ABI_RC.Core.InteractionSystem; using ABI_RC.Core.Savior; using ABI_RC.Systems.MovementSystem; -using System.Reflection; using UnityEngine; -namespace NAK.Melons.MenuScalePatch.Helpers; +namespace NAK.MenuScalePatch.Helpers; public class MSP_MenuInfo { @@ -25,21 +24,14 @@ public class MSP_MenuInfo public static bool DisableMMHelper; public static bool DisableMMHelper_VR; - //reflection - internal static readonly FieldInfo _desktopMouseModeQM = typeof(ViewManager).GetField("_desktopMouseMode", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo _desktopMouseModeMM = typeof(CVR_MenuManager).GetField("_desktopMouseMode", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo ms_followAngleX = typeof(MovementSystem).GetField("_followAngleX", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo ms_followAngleY = typeof(MovementSystem).GetField("_followAngleY", BindingFlags.NonPublic | BindingFlags.Instance); - internal static readonly FieldInfo ms_manualAngleX = typeof(MovementSystem).GetField("_manualAngleX", BindingFlags.NonPublic | BindingFlags.Instance); - internal static bool isIndependentHeadTurn = false; internal static void ToggleDesktopInputMethod(bool flag) { if (MetaPort.Instance.isUsingVr) return; - _desktopMouseModeQM.SetValue(ViewManager.Instance, flag); - _desktopMouseModeMM.SetValue(CVR_MenuManager.Instance, flag); + ViewManager.Instance._desktopMouseMode = flag; + CVR_MenuManager.Instance._desktopMouseMode = flag; RootLogic.Instance.ToggleMouse(flag); CVRInputManager.Instance.inputEnabled = !flag; @@ -59,9 +51,9 @@ public class MSP_MenuInfo } else if (!isPressed && isIndependentHeadTurn) { - float angleX = (float)ms_followAngleX.GetValue(MovementSystem.Instance); - float angleY = (float)ms_followAngleY.GetValue(MovementSystem.Instance); - float manualAngleX = (float)ms_manualAngleX.GetValue(MovementSystem.Instance); + float angleX = MovementSystem.Instance._followAngleX; + float angleY = MovementSystem.Instance._followAngleY; + float manualAngleX = MovementSystem.Instance._manualAngleX; if (angleY == 0f && angleX == manualAngleX) { isIndependentHeadTurn = false; diff --git a/MenuScalePatch/Main.cs b/MenuScalePatch/Main.cs index 3f8387f..e0b09a7 100644 --- a/MenuScalePatch/Main.cs +++ b/MenuScalePatch/Main.cs @@ -1,35 +1,29 @@ using MelonLoader; -using NAK.Melons.MenuScalePatch.Helpers; -namespace NAK.Melons.MenuScalePatch; +namespace NAK.MenuScalePatch; public class MenuScalePatch : MelonMod { - internal static MelonLogger.Instance Logger; - internal static MelonPreferences_Category m_categoryMenuScalePatch; - internal static MelonPreferences_Entry - //m_entryWorldAnchorVRQM, - m_entryUseIndependentHeadTurn, - m_entryPlayerAnchorMenus; + internal static MelonPreferences_Category Category = MelonPreferences.CreateCategory(nameof(MenuScalePatch)); + + internal static MelonPreferences_Entry EntryUseIndependentHeadTurn = + Category.CreateEntry("Use Independent Head Turn", true, description: "Should you be able to use independent head turn in a menu while in Desktop?"); + + internal static MelonPreferences_Entry EntryPlayerAnchorMenus = + Category.CreateEntry("Player Anchor Menus", true, description: "Should the menus be anchored to & constantly follow the player?"); + public override void OnInitializeMelon() { - m_categoryMenuScalePatch = MelonPreferences.CreateCategory(nameof(MenuScalePatch)); - //m_entryWorldAnchorVRQM = m_categoryMenuScalePatch.CreateEntry("World Anchor VR QM", false, description: "Should place QM in World Space while VR."); - m_entryUseIndependentHeadTurn = m_categoryMenuScalePatch.CreateEntry("Use Independent Head Turn", true, description: "Should you be able to use independent head turn in a menu while in Desktop?"); - m_entryPlayerAnchorMenus = m_categoryMenuScalePatch.CreateEntry("Player Anchor Menus", true, description: "Should the menus be anchored to & constantly follow the player?"); - - foreach (var setting in m_categoryMenuScalePatch.Entries) + foreach (var setting in Category.Entries) { setting.OnEntryValueChangedUntyped.Subscribe(OnUpdateSettings); } + } - Logger = LoggerInstance; - } - internal static void UpdateAllSettings() + internal static void UpdateSettings() { - //MSP_MenuInfo.WorldAnchorQM = m_entryWorldAnchorVRQM.Value; - MSP_MenuInfo.UseIndependentHeadTurn = m_entryUseIndependentHeadTurn.Value; - MSP_MenuInfo.PlayerAnchorMenus = m_entryPlayerAnchorMenus.Value; + Helpers.MSP_MenuInfo.UseIndependentHeadTurn = EntryUseIndependentHeadTurn.Value; + Helpers.MSP_MenuInfo.PlayerAnchorMenus = EntryPlayerAnchorMenus.Value; } - private static void OnUpdateSettings(object arg1, object arg2) => UpdateAllSettings(); + private static void OnUpdateSettings(object arg1, object arg2) => UpdateSettings(); } \ No newline at end of file diff --git a/MenuScalePatch/MenuScalePatch.csproj b/MenuScalePatch/MenuScalePatch.csproj index 72168e2..dc1602b 100644 --- a/MenuScalePatch/MenuScalePatch.csproj +++ b/MenuScalePatch/MenuScalePatch.csproj @@ -6,29 +6,30 @@ enable latest false + True - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\0Harmony.dll + ..\_ManagedLibs\0Harmony.dll - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Assembly-CSharp.dll + ..\_ManagedLibs\Assembly-CSharp.dll - C:\Program Files (x86)\\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\Cohtml.Runtime.dll + ..\_ManagedLibs\Cohtml.Runtime.dll - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\MelonLoader\MelonLoader.dll + ..\_ManagedLibs\MelonLoader.dll - C:\Program Files (x86)\\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.AnimationModule.dll + ..\_ManagedLibs\UnityEngine.AnimationModule.dll - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.CoreModule.dll + ..\_ManagedLibs\UnityEngine.CoreModule.dll - C:\Program Files (x86)\Steam\steamapps\common\ChilloutVR\ChilloutVR_Data\Managed\UnityEngine.InputLegacyModule.dll + ..\_ManagedLibs\UnityEngine.InputLegacyModule.dll diff --git a/MenuScalePatch/Properties/AssemblyInfo.cs b/MenuScalePatch/Properties/AssemblyInfo.cs index c74bca0..ada3637 100644 --- a/MenuScalePatch/Properties/AssemblyInfo.cs +++ b/MenuScalePatch/Properties/AssemblyInfo.cs @@ -1,30 +1,30 @@ using MelonLoader; -using NAK.Melons.MenuScalePatch.Properties; +using NAK.MenuScalePatch.Properties; using System.Reflection; [assembly: AssemblyVersion(AssemblyInfoParams.Version)] [assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] [assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] -[assembly: AssemblyTitle(nameof(NAK.Melons.MenuScalePatch))] +[assembly: AssemblyTitle(nameof(NAK.MenuScalePatch))] [assembly: AssemblyCompany(AssemblyInfoParams.Author)] -[assembly: AssemblyProduct(nameof(NAK.Melons.MenuScalePatch))] +[assembly: AssemblyProduct(nameof(NAK.MenuScalePatch))] [assembly: MelonInfo( - typeof(NAK.Melons.MenuScalePatch.MenuScalePatch), - nameof(NAK.Melons.MenuScalePatch), + typeof(NAK.MenuScalePatch.MenuScalePatch), + nameof(NAK.MenuScalePatch), AssemblyInfoParams.Version, AssemblyInfoParams.Author, - downloadLink: "https://github.com/NotAKidOnSteam/MenuScalePatch" + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods" )] [assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] [assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] [assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] -namespace NAK.Melons.MenuScalePatch.Properties; +namespace NAK.MenuScalePatch.Properties; internal static class AssemblyInfoParams { - public const string Version = "4.2.6"; + public const string Version = "4.2.7"; public const string Author = "NotAKidoS"; } \ No newline at end of file diff --git a/MenuScalePatch/format.json b/MenuScalePatch/format.json index 717ab3b..6b21041 100644 --- a/MenuScalePatch/format.json +++ b/MenuScalePatch/format.json @@ -1,7 +1,7 @@ { "_id": 95, "name": "MenuScalePatch", - "modversion": "4.2.6", + "modversion": "4.2.7", "gameversion": "2022r170", "loaderversion": "0.5.7", "modtype": "Mod", @@ -16,8 +16,8 @@ "requirements": [ "None" ], - "downloadlink": "https://github.com/NotAKidOnSteam/MenuScalePatch/releases/download/v4.2.6/MenuScalePatch.dll", - "sourcelink": "https://github.com/NotAKidOnSteam/MenuScalePatch/", - "changelog": "- Fixed hitching & potential crash when opening menu after a long time of it being closed. Don't disable CohtmlView, only enable it.\n- Let game update menu position while its closed.\n- Tweaked independent head turn handling to ensure menu is correctly positioned on recenter if PlayerAnchorMenus is disabled.\n- Undo change to which transform to parent menu anchors.", + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r2/MenuScalePatch.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/", + "changelog": "- Menus are no longer forced closed on world load.", "embedcolor": "363020" } \ No newline at end of file diff --git a/NAK.CustomComponents/Components/NAKPointerTracker.cs b/NAK.CustomComponents/Components/NAKPointerTracker.cs index 257fd7d..1ccc1e7 100644 --- a/NAK.CustomComponents/Components/NAKPointerTracker.cs +++ b/NAK.CustomComponents/Components/NAKPointerTracker.cs @@ -1,5 +1,6 @@ using ABI.CCK.Components; using UnityEngine; +using ABI_RC.Core.Player; namespace NAK.CCK.CustomComponents; @@ -16,6 +17,7 @@ public class NAKPointerTracker : MonoBehaviour public string parameterName; // Internal stuff + bool isLocal; float initialAngle; CVRPointer trackedPointer; @@ -46,6 +48,7 @@ public class NAKPointerTracker : MonoBehaviour Vector3 direction = (transform.TransformPoint(offset) - referenceTransform.position); Vector3 projectedDirection = Vector3.ProjectOnPlane(direction, referenceTransform.up); initialAngle = Vector3.SignedAngle(referenceTransform.forward, projectedDirection, referenceTransform.up); + isLocal = gameObject.layer == 8; } void OnDrawGizmosSelected() @@ -88,8 +91,13 @@ public class NAKPointerTracker : MonoBehaviour { if (animator != null) { - float angle = GetAngleFromPosition(trackedPointer.transform.position, initialAngle); - animator.SetFloat(parameterName + "_Angle", angle / 360); + float angle = GetAngleFromPosition(trackedPointer.transform.position, initialAngle) / 360; + if (!isLocal) + { + animator.SetFloat(parameterName + "_Angle", angle); + return; + } + PlayerSetup.Instance.changeAnimatorParam(parameterName + "_Angle", angle); } } diff --git a/NAK.CustomComponents/Main.cs b/NAK.CustomComponents/Main.cs index dfe1697..dd374ed 100644 --- a/NAK.CustomComponents/Main.cs +++ b/NAK.CustomComponents/Main.cs @@ -9,7 +9,7 @@ public class CustomComponents : MelonMod public override void OnInitializeMelon() { // Add our CCK component to the prop whitelist - var propWhitelist = SharedFilter._spawnableWhitelist; + var propWhitelist = SharedFilter._avatarWhitelist; propWhitelist.Add(typeof(NAKPointerTracker)); } } \ No newline at end of file diff --git a/ThirdPerson/CameraLogic.cs b/ThirdPerson/CameraLogic.cs new file mode 100644 index 0000000..776d7f1 --- /dev/null +++ b/ThirdPerson/CameraLogic.cs @@ -0,0 +1,182 @@ +using ABI_RC.Core.Base; +using ABI_RC.Core.Player; +using ABI_RC.Core.Util.Object_Behaviour; +using Aura2API; +using BeautifyEffect; +using System.Collections; +using System.Reflection; +using UnityEngine; +using UnityEngine.AzureSky; +using UnityEngine.Rendering.PostProcessing; + +namespace ThirdPerson; + +internal static class CameraLogic +{ + private static float _dist; + private static GameObject _ourCam; + private static GameObject _desktopCam; + private static CameraFovClone _cameraFovClone; + + internal static CameraLocation CurrentLocation = CameraLocation.Default; + + internal enum CameraLocation + { + Default, + FrontView, + RightSide, + LeftSide + } + + private static bool _state; + internal static bool State + { + get => _state; + set + { + _state = value; + _ourCam.SetActive(_state); + } + } + + private static bool _setupPostProcessing; + private static readonly FieldInfo _ppResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_Resources", BindingFlags.NonPublic | BindingFlags.Instance); + private static readonly FieldInfo _ppOldResourcesFieldInfo = typeof(PostProcessLayer).GetField("m_OldResources", BindingFlags.NonPublic | BindingFlags.Instance); + + internal static IEnumerator SetupCamera() + { + yield return new WaitUntil(() => PlayerSetup.Instance); + + _ourCam = new GameObject("ThirdPersonCameraObj") { }; + _ourCam.AddComponent(); + + _cameraFovClone = _ourCam.AddComponent(); + + _desktopCam = PlayerSetup.Instance.desktopCamera; + _cameraFovClone.targetCamera = _desktopCam.GetComponent(); + + _ourCam.transform.SetParent(_desktopCam.transform); + + RelocateCam(CameraLocation.Default); + + _ourCam.gameObject.SetActive(false); + + ThirdPerson.Logger.Msg("Finished setting up third person camera."); + } + + internal static void CopyFromPlayerCam() + { + Camera ourCamComponent = _ourCam.GetComponent(); + Camera playerCamComponent = _desktopCam.GetComponent(); + if (ourCamComponent == null || playerCamComponent == null) return; + ThirdPerson.Logger.Msg("Copying active camera settings & components."); + + //steal basic settings + ourCamComponent.farClipPlane = playerCamComponent.farClipPlane; + ourCamComponent.nearClipPlane = playerCamComponent.nearClipPlane; + ourCamComponent.cullingMask = playerCamComponent.cullingMask; + ourCamComponent.depthTextureMode = playerCamComponent.depthTextureMode; + + //steal post processing if added + PostProcessLayer ppLayerPlayerCam = playerCamComponent.GetComponent(); + PostProcessLayer ppLayerThirdPerson = ourCamComponent.AddComponentIfMissing(); + if (ppLayerPlayerCam != null && ppLayerThirdPerson != null) + { + ppLayerThirdPerson.enabled = ppLayerPlayerCam.enabled; + ppLayerThirdPerson.volumeLayer = ppLayerPlayerCam.volumeLayer; + //need to copy these via reflection, otherwise post processing will error + if (!_setupPostProcessing) + { + _setupPostProcessing = true; + PostProcessResources resources = (PostProcessResources)_ppResourcesFieldInfo.GetValue(ppLayerPlayerCam); + PostProcessResources oldResources = (PostProcessResources)_ppOldResourcesFieldInfo.GetValue(ppLayerPlayerCam); + _ppResourcesFieldInfo.SetValue(ppLayerThirdPerson, resources); + _ppResourcesFieldInfo.SetValue(ppLayerThirdPerson, oldResources); + } + } + + //what even is this aura camera stuff + AuraCamera auraPlayerCam = playerCamComponent.GetComponent(); + AuraCamera auraThirdPerson = ourCamComponent.AddComponentIfMissing(); + if (auraPlayerCam != null && auraThirdPerson != null) + { + auraThirdPerson.enabled = auraPlayerCam.enabled; + auraThirdPerson.frustumSettings = auraPlayerCam.frustumSettings; + } + else + { + auraThirdPerson.enabled = false; + } + + //flare layer thing? the sun :_:_:_:_:_: + FlareLayer flarePlayerCam = playerCamComponent.GetComponent(); + FlareLayer flareThirdPerson = ourCamComponent.AddComponentIfMissing(); + if (flarePlayerCam != null && flareThirdPerson != null) + { + flareThirdPerson.enabled = flarePlayerCam.enabled; + } + else + { + flareThirdPerson.enabled = false; + } + + //and now what the fuck is fog scattering + AzureFogScattering azureFogPlayerCam = playerCamComponent.GetComponent(); + AzureFogScattering azureFogThirdPerson = ourCamComponent.AddComponentIfMissing(); + if (azureFogPlayerCam != null && azureFogThirdPerson != null) + { + azureFogThirdPerson.fogScatteringMaterial = azureFogPlayerCam.fogScatteringMaterial; + } + else + { + Object.Destroy(ourCamComponent.GetComponent()); + } + + //why is there so many thingsssssssss + Beautify beautifyPlayerCam = playerCamComponent.GetComponent(); + Beautify beautifyThirdPerson = ourCamComponent.AddComponentIfMissing(); + if (beautifyPlayerCam != null && beautifyThirdPerson != null) + { + beautifyThirdPerson.quality = beautifyPlayerCam.quality; + beautifyThirdPerson.profile = beautifyPlayerCam.profile; + } + else + { + Object.Destroy(ourCamComponent.gameObject.GetComponent()); + } + } + + internal static void RelocateCam(CameraLocation location, bool resetDist = false) + { + _ourCam.transform.rotation = _desktopCam.transform.rotation; + if (resetDist) ResetDist(); + switch (location) + { + case CameraLocation.FrontView: + _ourCam.transform.localPosition = new Vector3(0, 0.015f, 0.55f + _dist); + _ourCam.transform.localRotation = new Quaternion(0, 180, 0, 0); + CurrentLocation = CameraLocation.FrontView; + break; + case CameraLocation.RightSide: + _ourCam.transform.localPosition = new Vector3(0.3f, 0.015f, -0.55f + _dist); + _ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0); + CurrentLocation = CameraLocation.RightSide; + break; + case CameraLocation.LeftSide: + _ourCam.transform.localPosition = new Vector3(-0.3f, 0.015f, -0.55f + _dist); + _ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0); + CurrentLocation = CameraLocation.LeftSide; + break; + case CameraLocation.Default: + default: + _ourCam.transform.localPosition = new Vector3(0, 0.015f, -0.55f + _dist); + _ourCam.transform.localRotation = new Quaternion(0, 0, 0, 0); + CurrentLocation = CameraLocation.Default; + break; + } + } + + private static void ResetDist() => _dist = 0; + internal static void IncrementDist() { _dist += 0.25f; RelocateCam(CurrentLocation); } + internal static void DecrementDist() { _dist -= 0.25f; RelocateCam(CurrentLocation); } +} \ No newline at end of file diff --git a/ThirdPerson/Patches.cs b/ThirdPerson/Patches.cs new file mode 100644 index 0000000..82c1e40 --- /dev/null +++ b/ThirdPerson/Patches.cs @@ -0,0 +1,27 @@ +using ABI.CCK.Components; +using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core.Player; +using MelonLoader; +using System.Linq; +using System.Reflection; +using static ThirdPerson.CameraLogic; + +namespace ThirdPerson; + +internal static class Patches +{ + internal static void Apply(HarmonyLib.Harmony harmony) + { + harmony.Patch( + typeof(CVRWorld).GetMethod("SetDefaultCamValues", BindingFlags.NonPublic | BindingFlags.Instance), + postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod() + ); + harmony.Patch( + typeof(CVRWorld).GetMethod("CopyRefCamValues", BindingFlags.NonPublic | BindingFlags.Instance), + postfix: typeof(Patches).GetMethod(nameof(OnWorldStart), BindingFlags.NonPublic | BindingFlags.Static).ToNewHarmonyMethod() + ); + } + + //Copy camera settings & postprocessing components + private static void OnWorldStart() => CopyFromPlayerCam(); +} \ No newline at end of file diff --git a/ThirdPerson/ThirdPerson.cs b/ThirdPerson/ThirdPerson.cs new file mode 100644 index 0000000..2fcb1bb --- /dev/null +++ b/ThirdPerson/ThirdPerson.cs @@ -0,0 +1,48 @@ +using MelonLoader; +using System; +using System.Reflection; +using UnityEngine; +using static ThirdPerson.CameraLogic; +using BuildInfo = ThirdPerson.BuildInfo; + +[assembly: AssemblyCopyright("Created by " + BuildInfo.Author)] +[assembly: MelonInfo(typeof(ThirdPerson.ThirdPerson), BuildInfo.Name, BuildInfo.Version, BuildInfo.Author)] +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonColor(ConsoleColor.DarkMagenta)] + +namespace ThirdPerson; + +public static class BuildInfo +{ + public const string Name = "ThirdPerson"; + public const string Author = "Davi & NotAKidoS"; + public const string Version = "1.0.1"; +} + +public class ThirdPerson : MelonMod +{ + internal static MelonLogger.Instance Logger; + + public override void OnInitializeMelon() + { + Logger = LoggerInstance; + + MelonCoroutines.Start(SetupCamera()); + + Patches.Apply(HarmonyInstance); + } + + public override void OnUpdate() + { + if (State) + { + if (Input.GetAxis("Mouse ScrollWheel") > 0f) IncrementDist(); + else if (Input.GetAxis("Mouse ScrollWheel") < 0f) DecrementDist(); + } + + if (!Input.GetKey(KeyCode.LeftControl)) return; + if (Input.GetKeyDown(KeyCode.T)) State = !State; + if (!State || !Input.GetKeyDown(KeyCode.Y)) return; + RelocateCam((CameraLocation)(((int)CurrentLocation + 1) % Enum.GetValues(typeof(CameraLocation)).Length), true); + } +} \ No newline at end of file diff --git a/ThirdPerson/ThirdPerson.csproj b/ThirdPerson/ThirdPerson.csproj new file mode 100644 index 0000000..66b26a6 --- /dev/null +++ b/ThirdPerson/ThirdPerson.csproj @@ -0,0 +1,54 @@ + + + net472 + true + true + latest + 1.0.0.0 + 1.0.0 + True + + + + ..\_ManagedLibs\0Harmony.dll + + + ..\_ManagedLibs\Assembly-CSharp.dll + + + ..\_ManagedLibs\Assembly-CSharp-firstpass.dll + + + ..\_ManagedLibs\Aura2_Core.dll + + + ..\_ManagedLibs\Cohtml.Runtime.dll + + + ..\_ManagedLibs\MelonLoader.dll + + + ..\_ManagedLibs\Unity.Postprocessing.Runtime.dll + + + ..\_ManagedLibs\UnityEngine.AnimationModule.dll + + + ..\_ManagedLibs\UnityEngine.AssetBundleModule.dll + + + ..\_ManagedLibs\UnityEngine.CoreModule.dll + + + ..\_ManagedLibs\UnityEngine.InputLegacyModule.dll + + + ..\_ManagedLibs\UnityEngine.PhysicsModule.dll + + + + + + + + \ No newline at end of file diff --git a/ThirdPerson/ThirdPerson.sln b/ThirdPerson/ThirdPerson.sln new file mode 100644 index 0000000..ffaaf99 --- /dev/null +++ b/ThirdPerson/ThirdPerson.sln @@ -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}") = "ThirdPerson", "ThirdPerson.csproj", "{F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5DE9D13-231E-4DBD-8294-D0AA1B5A91A1}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {B44A1184-3AC9-4ABD-8603-6B13ECDA5CA9} + EndGlobalSection +EndGlobal diff --git a/ThirdPerson/format.json b/ThirdPerson/format.json new file mode 100644 index 0000000..4fff9dc --- /dev/null +++ b/ThirdPerson/format.json @@ -0,0 +1,22 @@ +[ + { + "_id": 16, + "name": "ThirdPerson", + "modversion": "1.0.1", + "gameversion": "2022r170", + "loaderversion": "0.5.7", + "modtype": "Mod", + "author": "Davi & NotAKidoS", + "description": "Allows you to go into third person view by pressing Ctrl + T to toggle and Ctrl + Y to change the mode", + "searchtags": [ + "third person view", + "3rd person", + "third person" + ], + "requirements": [], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/tag/r2/ThirdPerson.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/", + "changelog": "- Made thirdperson camera parent to Desktop camera instead of active camera.\n- Copy postprocessing settings from player camera on world start.\n - This fixed HUD rendering twice in thirdperson due to game update.\n- Added CameraFovClone component to copy zoom from desktop camera.\n- Removed logic that disabled thirdperson when opening a menu, as Game UI renders on top anyways.", + "embedcolor": "F61961" + } +] \ No newline at end of file