From 6ee3d80ef84d3d0ac7fbf93dc7a286ff8ed15c47 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Mon, 12 Jun 2023 21:28:08 -0500 Subject: [PATCH] [DesktopCameraFix] initial test --- DesktopCameraFix/DesktopCameraFix.csproj | 2 + DesktopCameraFix/HarmonyPatches.cs | 42 +++++++++++++++++++++ DesktopCameraFix/Main.cs | 34 +++++++++++++++++ DesktopCameraFix/Properties/AssemblyInfo.cs | 30 +++++++++++++++ DesktopCameraFix/format.json | 23 +++++++++++ NAK_CVR_Mods.sln | 6 +++ 6 files changed, 137 insertions(+) create mode 100644 DesktopCameraFix/DesktopCameraFix.csproj create mode 100644 DesktopCameraFix/HarmonyPatches.cs create mode 100644 DesktopCameraFix/Main.cs create mode 100644 DesktopCameraFix/Properties/AssemblyInfo.cs create mode 100644 DesktopCameraFix/format.json diff --git a/DesktopCameraFix/DesktopCameraFix.csproj b/DesktopCameraFix/DesktopCameraFix.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/DesktopCameraFix/DesktopCameraFix.csproj @@ -0,0 +1,2 @@ + + diff --git a/DesktopCameraFix/HarmonyPatches.cs b/DesktopCameraFix/HarmonyPatches.cs new file mode 100644 index 0000000..a56c32d --- /dev/null +++ b/DesktopCameraFix/HarmonyPatches.cs @@ -0,0 +1,42 @@ +using ABI_RC.Core.Player; +using ABI_RC.Systems.MovementSystem; +using HarmonyLib; +using UnityEngine; + +namespace NAK.DesktopCameraFix.HarmonyPatches; + +class PlayerSetupPatches +{ + [HarmonyPostfix] + [HarmonyPatch(typeof(PlayerSetup), nameof(PlayerSetup.HandleDesktopCameraPosition))] + public static void Postfix_PlayerSetup_HandleDesktopCameraPosition(bool ignore, ref PlayerSetup __instance, ref MovementSystem ____movementSystem, ref int ___headBobbingLevel) + { + if (!DesktopCameraFix.EntryEnabled.Value) + return; + + if (____movementSystem.disableCameraControl && !ignore) + return; + + if (___headBobbingLevel != 2) + return; + + Transform viewpointTransform = __instance._viewPoint.pointer.transform; + if (viewpointTransform != null) + { + __instance.desktopCamera.transform.position = viewpointTransform.position; + } + + /** + desktopCameraRig -> desktopCamera + desktopCameraRig is parent of desktopCamera. + + desktopCamera rotates, so it pivots in place. + desktopCameraRig is moved to head bone, local position of camera is viewpoint offset when standing + + if rig was moving position & rotation, this would work + but because rig handles position and camera handles rotation, camera pivots in place instead of at correct point + which is gross + + **/ + } +} diff --git a/DesktopCameraFix/Main.cs b/DesktopCameraFix/Main.cs new file mode 100644 index 0000000..427b901 --- /dev/null +++ b/DesktopCameraFix/Main.cs @@ -0,0 +1,34 @@ +using ABI_RC.Core.IO; +using MelonLoader; +using UnityEngine; + +namespace NAK.DesktopCameraFix; + +public class DesktopCameraFix : MelonMod +{ + internal const string SettingsCategory = nameof(DesktopCameraFix); + + public static readonly MelonPreferences_Category Category = + MelonPreferences.CreateCategory(SettingsCategory); + + public static readonly MelonPreferences_Entry EntryEnabled = + Category.CreateEntry("Enabled", true, description: "Toggle DesktopCameraFix entirely."); + + public override void OnInitializeMelon() + { + ApplyPatches(typeof(HarmonyPatches.PlayerSetupPatches)); + } + + void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } + } +} \ No newline at end of file diff --git a/DesktopCameraFix/Properties/AssemblyInfo.cs b/DesktopCameraFix/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..44d7413 --- /dev/null +++ b/DesktopCameraFix/Properties/AssemblyInfo.cs @@ -0,0 +1,30 @@ +using CameraFixes.Properties; +using MelonLoader; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.DesktopCameraFix))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.DesktopCameraFix))] + +[assembly: MelonInfo( + typeof(NAK.DesktopCameraFix.DesktopCameraFix), + nameof(NAK.DesktopCameraFix), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/DesktopCameraFix" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: HarmonyDontPatchAll] + +namespace CameraFixes.Properties; +internal static class AssemblyInfoParams +{ + public const string Version = "1.0.0"; + public const string Author = "NotAKidoS"; +} \ No newline at end of file diff --git a/DesktopCameraFix/format.json b/DesktopCameraFix/format.json new file mode 100644 index 0000000..8c9236d --- /dev/null +++ b/DesktopCameraFix/format.json @@ -0,0 +1,23 @@ +{ + "_id": 129, + "name": "CameraFixes", + "modversion": "1.0.0", + "gameversion": "2022r170", + "loaderversion": "0.5.7", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Prevents VRIK from using toe bones in VR & optionaly FBT.\n\nVRIK calculates weird center of mass when toes are mapped, so it is sometimes desired to unmap toes to prevent an avatars feet from resting far back.\n\nPlease see the README for relevant imagery detailing the problem.", + "searchtags": [ + "toes", + "vrik", + "ik", + "feet" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r3/CameraFixes.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/CameraFixes/", + "changelog": "- Initial Release\n- No double patching. Bad. Stinky. Dont do it.", + "embedcolor": "#ffc700" +} \ No newline at end of file diff --git a/NAK_CVR_Mods.sln b/NAK_CVR_Mods.sln index bf256f5..2ae5ab5 100644 --- a/NAK_CVR_Mods.sln +++ b/NAK_CVR_Mods.sln @@ -59,6 +59,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SmoothRay", "SmoothRay\Smoo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TrackedPointFix", "TrackedPointFix\TrackedPointFix.csproj", "{0A6788A8-89E9-4FC4-B4FE-27FE8B39926C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DesktopCameraFix", "DesktopCameraFix\DesktopCameraFix.csproj", "{E17F78BF-90FB-44F7-A919-EDDF0BC1AF01}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -177,6 +179,10 @@ Global {0A6788A8-89E9-4FC4-B4FE-27FE8B39926C}.Debug|Any CPU.Build.0 = Debug|Any CPU {0A6788A8-89E9-4FC4-B4FE-27FE8B39926C}.Release|Any CPU.ActiveCfg = Release|Any CPU {0A6788A8-89E9-4FC4-B4FE-27FE8B39926C}.Release|Any CPU.Build.0 = Release|Any CPU + {E17F78BF-90FB-44F7-A919-EDDF0BC1AF01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E17F78BF-90FB-44F7-A919-EDDF0BC1AF01}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E17F78BF-90FB-44F7-A919-EDDF0BC1AF01}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E17F78BF-90FB-44F7-A919-EDDF0BC1AF01}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE