From 6e447c5cfffa30c4f056bc0b6a18c269b8047952 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidOnSteam@users.noreply.github.com> Date: Thu, 6 Jul 2023 14:51:29 -0500 Subject: [PATCH] [FOVAdjustment] Initial release --- FOVAdjustment/FOVAdjustment.csproj | 2 + FOVAdjustment/Main.cs | 64 ++++++++++++++++++++++++ FOVAdjustment/Properties/AssemblyInfo.cs | 29 +++++++++++ FOVAdjustment/README.md | 18 +++++++ FOVAdjustment/format.json | 23 +++++++++ 5 files changed, 136 insertions(+) create mode 100644 FOVAdjustment/FOVAdjustment.csproj create mode 100644 FOVAdjustment/Main.cs create mode 100644 FOVAdjustment/Properties/AssemblyInfo.cs create mode 100644 FOVAdjustment/README.md create mode 100644 FOVAdjustment/format.json diff --git a/FOVAdjustment/FOVAdjustment.csproj b/FOVAdjustment/FOVAdjustment.csproj new file mode 100644 index 0000000..66a50a8 --- /dev/null +++ b/FOVAdjustment/FOVAdjustment.csproj @@ -0,0 +1,2 @@ + + diff --git a/FOVAdjustment/Main.cs b/FOVAdjustment/Main.cs new file mode 100644 index 0000000..a593ab0 --- /dev/null +++ b/FOVAdjustment/Main.cs @@ -0,0 +1,64 @@ +using ABI.CCK.Components; +using ABI_RC.Core.Player; +using MelonLoader; +using System.Reflection; +using UnityEngine; + +namespace NAK.FOVAdjustment; + +public class FOVAdjustment : MelonMod +{ + internal const string SettingsCategory = nameof(FOVAdjustment); + + public static readonly MelonPreferences_Category Category = + MelonPreferences.CreateCategory(SettingsCategory); + + public static readonly MelonPreferences_Entry EntryEnabled = + Category.CreateEntry("Enabled", true, description: "Toggle FOVAdjustment entirely."); + + public static readonly MelonPreferences_Entry EntryFOV = + Category.CreateEntry("FOV", 60f, description: "Target Desktop FOV. This is ignored if the world specifies a custom FOV!"); + + public override void OnInitializeMelon() + { + HarmonyInstance.Patch( + typeof(CVR_DesktopCameraController).GetMethod(nameof(CVR_DesktopCameraController.UpdateFov)), + prefix: new HarmonyLib.HarmonyMethod(typeof(FOVAdjustment).GetMethod(nameof(OnUpdateFov_Prefix), BindingFlags.NonPublic | BindingFlags.Static)) + ); + + EntryEnabled.OnEntryValueChanged.Subscribe(OnEntryEnabledChanged); + EntryFOV.OnEntryValueChanged.Subscribe(OnEntryFovChanged); + } + + private void OnEntryEnabledChanged(bool oldValue, bool newValue) + { + UpdateDesktopCameraControllerFov(newValue ? EntryFOV.Value : 60f); + CVR_DesktopCameraController.UpdateFov(); + } + + private void OnEntryFovChanged(float oldValue, float newValue) + { + if (!EntryEnabled.Value) + return; + + UpdateDesktopCameraControllerFov(newValue); + CVR_DesktopCameraController.UpdateFov(); + } + + private static void OnUpdateFov_Prefix() + { + if (!EntryEnabled.Value) + return; + + UpdateDesktopCameraControllerFov(EntryFOV.Value); + } + + private static void UpdateDesktopCameraControllerFov(float value) + { + if (CVRWorld.Instance != null && Mathf.Approximately(CVRWorld.Instance.fov, 60f)) + { + CVR_DesktopCameraController.defaultFov = Mathf.Clamp(value, 60f, 120f); + CVR_DesktopCameraController.zoomFov = CVR_DesktopCameraController.defaultFov * 0.5f; + } + } +} \ No newline at end of file diff --git a/FOVAdjustment/Properties/AssemblyInfo.cs b/FOVAdjustment/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8d6aada --- /dev/null +++ b/FOVAdjustment/Properties/AssemblyInfo.cs @@ -0,0 +1,29 @@ +using MelonLoader; +using NAK.FOVAdjustment.Properties; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.FOVAdjustment))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.FOVAdjustment))] + +[assembly: MelonInfo( + typeof(NAK.FOVAdjustment.FOVAdjustment), + nameof(NAK.FOVAdjustment), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/FOVAdjustment" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] + +namespace NAK.FOVAdjustment.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/FOVAdjustment/README.md b/FOVAdjustment/README.md new file mode 100644 index 0000000..e465762 --- /dev/null +++ b/FOVAdjustment/README.md @@ -0,0 +1,18 @@ +# FOVAdjustment + +A simple mod that makes the CVR_DesktopCameraController defaultFov adjustable. + +The custom FOV setting is ignored if a world author specified a FOV other than 60f. + +It is limited between 60f and 120f to match the limitations world creators have with setting custom FOV. + +--- + +Here is the block of text where I tell you this mod is not affiliated or endorsed by ABI. +https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games + +> This mod is an independent creation and is not affiliated with, supported by or approved by Alpha Blend Interactive. + +> Use of this mod is done so at the user's own risk and the creator cannot be held responsible for any issues arising from its use. + +> To the best of my knowledge, I have adhered to the Modding Guidelines established by Alpha Blend Interactive. diff --git a/FOVAdjustment/format.json b/FOVAdjustment/format.json new file mode 100644 index 0000000..243b478 --- /dev/null +++ b/FOVAdjustment/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "FOVAdjustment", + "modversion": "1.0.0", + "gameversion": "2022r170p1", + "loaderversion": "0.6.1", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "A simple mod that makes CVR_DesktopCameraController defaultFov configurable by the user if the world author didn't specify a custom world FOV.\n\nCustom FOV values are limited between 60f and 120f to match the limitations imposed on world creators.", + "searchtags": [ + "aas", + "sync", + "naked", + "buffer" + ], + "requirements": [ + "UIExpansionKit" + ], + "downloadlink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/releases/download/r13/FOVAdjustment.dll", + "sourcelink": "https://github.com/NotAKidOnSteam/NAK_CVR_Mods/tree/main/FOVAdjustment/", + "changelog": "- Initial CVRMG release", + "embedcolor": "7d7d7d" +} \ No newline at end of file