From c408a9f83c07aba1108d7c461dcfac1909875396 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidoS@users.noreply.github.com> Date: Tue, 27 Aug 2024 14:05:42 -0500 Subject: [PATCH] WhereAmIPointing: Initial Release --- WhereAmIPointing/Main.cs | 105 ++++++++++++++++++++ WhereAmIPointing/Properties/AssemblyInfo.cs | 32 ++++++ WhereAmIPointing/README.md | 14 +++ WhereAmIPointing/WhereAmIPointing.csproj | 6 ++ WhereAmIPointing/format.json | 23 +++++ 5 files changed, 180 insertions(+) create mode 100644 WhereAmIPointing/Main.cs create mode 100644 WhereAmIPointing/Properties/AssemblyInfo.cs create mode 100644 WhereAmIPointing/README.md create mode 100644 WhereAmIPointing/WhereAmIPointing.csproj create mode 100644 WhereAmIPointing/format.json diff --git a/WhereAmIPointing/Main.cs b/WhereAmIPointing/Main.cs new file mode 100644 index 0000000..4771375 --- /dev/null +++ b/WhereAmIPointing/Main.cs @@ -0,0 +1,105 @@ +using ABI_RC.Core.InteractionSystem; +using HarmonyLib; +using MelonLoader; +using UnityEngine; + +namespace NAK.WhereAmIPointing; + +public class WhereAmIPointingMod : MelonMod +{ + #region Melon Preferences + + // cannot disable because then id need extra logic to reset the alpha :) + // private const string SettingsCategory = nameof(WhereAmIPointingMod); + // + // private static readonly MelonPreferences_Category Category = + // MelonPreferences.CreateCategory(SettingsCategory); + // + // private static readonly MelonPreferences_Entry Entry_Enabled = + // Category.CreateEntry("enabled", true, display_name: "Enabled",description: "Toggle WhereAmIPointingMod entirely."); + + #endregion Melon Preferences + + public override void OnInitializeMelon() + { + ApplyPatches(typeof(ControllerRay_Patches)); + } + + private void ApplyPatches(Type type) + { + try + { + HarmonyInstance.PatchAll(type); + } + catch (Exception e) + { + LoggerInstance.Msg($"Failed while patching {type.Name}!"); + LoggerInstance.Error(e); + } + } + + #region Patches + + private static class ControllerRay_Patches + { + private const float ORIGINAL_ALPHA = 0.502f; + private const float INTERACTION_ALPHA = 0.1f; + private const float RAY_LENGTH = 1000f; // game normally raycasts to PositiveInfinity... -_- + + [HarmonyPostfix] + [HarmonyPatch(typeof(ControllerRay), nameof(ControllerRay.LateUpdate))] + private static void Postfix_ControllerRay_LateUpdate(ref ControllerRay __instance) + { + if (__instance.isDesktopRay + || !__instance.enabled + || !__instance.IsTracking() + || !__instance.lineRenderer) + return; + + UpdateLineRendererAlpha(__instance); + + if (__instance.lineRenderer.enabled + || !ShouldOverrideLineRenderer(__instance)) + return; + + UpdateLineRendererPosition(__instance); + } + + private static void UpdateLineRendererAlpha(ControllerRay instance) + { + Material material = instance.lineRenderer.material; + Color color = material.color; + + float targetAlpha = instance.uiActive ? ORIGINAL_ALPHA : INTERACTION_ALPHA; + if (!(Math.Abs(color.a - targetAlpha) > float.Epsilon)) + return; + + color.a = targetAlpha; + material.color = color; + } + + private static bool ShouldOverrideLineRenderer(ControllerRay instance) + { + if (!ViewManager.Instance.IsAnyMenuOpen) + return false; + + if (CVR_MenuManager.Instance.IsQuickMenuOpen + && instance.hand == CVR_MenuManager.Instance.SelectedQuickMenuHand) + return false; + + return true; + } + + private static void UpdateLineRendererPosition(ControllerRay instance) + { + Vector3 rayOrigin = instance.rayDirectionTransform.position; + Vector3 rayEnd = rayOrigin + instance.rayDirectionTransform.forward * RAY_LENGTH; + + instance.lineRenderer.SetPosition(0, instance.lineRenderer.transform.InverseTransformPoint(rayOrigin)); + instance.lineRenderer.SetPosition(1, instance.lineRenderer.transform.InverseTransformPoint(rayEnd)); + instance.lineRenderer.enabled = true; + } + } + + #endregion Patches +} \ No newline at end of file diff --git a/WhereAmIPointing/Properties/AssemblyInfo.cs b/WhereAmIPointing/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..97e5356 --- /dev/null +++ b/WhereAmIPointing/Properties/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using NAK.WhereAmIPointing.Properties; +using MelonLoader; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.WhereAmIPointing))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.WhereAmIPointing))] + +[assembly: MelonInfo( + typeof(NAK.WhereAmIPointing.WhereAmIPointingMod), + nameof(NAK.WhereAmIPointing), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/WhereAmIPointing" +)] + +[assembly: MelonGame("Alpha Blend Interactive", "ChilloutVR")] +[assembly: MelonPlatform(MelonPlatformAttribute.CompatiblePlatforms.WINDOWS_X64)] +[assembly: MelonPlatformDomain(MelonPlatformDomainAttribute.CompatibleDomains.MONO)] +[assembly: MelonColor(255, 246, 25, 99)] // red-pink +[assembly: MelonAuthorColor(255, 158, 21, 32)] // red +[assembly: HarmonyDontPatchAll] + +namespace NAK.WhereAmIPointing.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/WhereAmIPointing/README.md b/WhereAmIPointing/README.md new file mode 100644 index 0000000..c78a56a --- /dev/null +++ b/WhereAmIPointing/README.md @@ -0,0 +1,14 @@ +# WhereAmIPointing + +Simple mod that makes your controller rays always visible when the menus are open. Useful for when you're trying to aim at something in the distance. Also visualizes which ray is being used for menu interaction. + +--- + +Here is the block of text where I tell you this mod is not affiliated with or endorsed by ABI. +https://documentation.abinteractive.net/official/legal/tos/#7-modding-our-games + +> This mod is an independent creation 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/WhereAmIPointing/WhereAmIPointing.csproj b/WhereAmIPointing/WhereAmIPointing.csproj new file mode 100644 index 0000000..728edb7 --- /dev/null +++ b/WhereAmIPointing/WhereAmIPointing.csproj @@ -0,0 +1,6 @@ + + + + net48 + + diff --git a/WhereAmIPointing/format.json b/WhereAmIPointing/format.json new file mode 100644 index 0000000..e352352 --- /dev/null +++ b/WhereAmIPointing/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "WhereAmIPointing", + "modversion": "1.0.0", + "gameversion": "2024r175", + "loaderversion": "0.6.1", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Simple mod that makes your controller rays always visible when the menus are open. Useful for when you're trying to aim at something in the distance. Also visualizes which ray is being used for menu interaction.", + "searchtags": [ + "controller", + "ray", + "line", + "tomato" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r39/WhereAmIPointing.dll", + "sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/WhereAmIPointing/", + "changelog": "- Initial Release", + "embedcolor": "#f61963" +} \ No newline at end of file