From 0b96d9347fb1b4b8fd4cbac5b4b1270ebab909c0 Mon Sep 17 00:00:00 2001 From: NotAKidoS <37721153+NotAKidoS@users.noreply.github.com> Date: Tue, 27 Aug 2024 12:29:06 -0500 Subject: [PATCH] SmartReticle: initial release --- SmartReticle/Main.cs | 101 ++++++++++++++++++++++++ SmartReticle/Properties/AssemblyInfo.cs | 32 ++++++++ SmartReticle/README.md | 14 ++++ SmartReticle/SmartReticle.csproj | 6 ++ SmartReticle/format.json | 23 ++++++ 5 files changed, 176 insertions(+) create mode 100644 SmartReticle/Main.cs create mode 100644 SmartReticle/Properties/AssemblyInfo.cs create mode 100644 SmartReticle/README.md create mode 100644 SmartReticle/SmartReticle.csproj create mode 100644 SmartReticle/format.json diff --git a/SmartReticle/Main.cs b/SmartReticle/Main.cs new file mode 100644 index 0000000..ae94900 --- /dev/null +++ b/SmartReticle/Main.cs @@ -0,0 +1,101 @@ +using ABI_RC.Core.InteractionSystem; +using ABI_RC.Core.Player; +using ABI_RC.Core.UI; +using HarmonyLib; +using MelonLoader; +using UnityEngine; + +namespace NAK.SmartReticle; + +public class SmartReticleMod : MelonMod +{ + #region Melon Preferences + + private const string SettingsCategory = nameof(SmartReticleMod); + + 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 SmartReticleMod entirely."); + + private static readonly MelonPreferences_Entry Entry_HideTimeout = + Category.CreateEntry("hide_timeout", 1f, display_name: "Hide Timeout (s)", description: "Timeout before the reticle hides again. Set to 0 to instantly hide."); + + #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 static Transform _mainMenuTransform; + private static Transform _quickMenuTransform; + private static float _lastDisplayedTime; + + [HarmonyPostfix] + [HarmonyPatch(typeof(ControllerRay), nameof(ControllerRay.Start))] + private static void Postfix_ControllerRay_Start() + { + _mainMenuTransform = ViewManager.Instance.transform; + _quickMenuTransform = CVR_MenuManager.Instance.transform; + } + + [HarmonyPostfix] + [HarmonyPatch(typeof(ControllerRay), nameof(ControllerRay.DisplayAuraHighlight))] + private static void Postfix_ControllerRay_DisplayAuraHighlight(ref ControllerRay __instance) + { + if (!Entry_Enabled.Value) + return; + + if (!__instance.isDesktopRay) + return; + + GameObject desktopPointer = CohtmlHud.Instance.desktopPointer; + + if (!desktopPointer.activeSelf) + { + _lastDisplayedTime = 0; // reset time + return; // pointing at menu or cursor is active + } + + bool shouldDisplayPointer = (__instance._interact // pressing mouse1 or mouse2 + || __instance._isTryingToPickup + // using some tool/utility + || (PlayerSetup.Instance.GetCurrentPropSelectionMode() + != PlayerSetup.PropSelectionMode.None) + // hit something- other than the two menus + || (__instance._objectWasHit + && (__instance.hitTransform != _mainMenuTransform + && __instance.hitTransform != _quickMenuTransform))); + + if (shouldDisplayPointer) + { + _lastDisplayedTime = Time.time; + return; + } + + if (Time.time - _lastDisplayedTime > Entry_HideTimeout.Value) + desktopPointer.SetActive(false); + } + } + + #endregion Patches +} \ No newline at end of file diff --git a/SmartReticle/Properties/AssemblyInfo.cs b/SmartReticle/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d393fda --- /dev/null +++ b/SmartReticle/Properties/AssemblyInfo.cs @@ -0,0 +1,32 @@ +using NAK.SmartReticle.Properties; +using MelonLoader; +using System.Reflection; + +[assembly: AssemblyVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyFileVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyInformationalVersion(AssemblyInfoParams.Version)] +[assembly: AssemblyTitle(nameof(NAK.SmartReticle))] +[assembly: AssemblyCompany(AssemblyInfoParams.Author)] +[assembly: AssemblyProduct(nameof(NAK.SmartReticle))] + +[assembly: MelonInfo( + typeof(NAK.SmartReticle.SmartReticleMod), + nameof(NAK.SmartReticle), + AssemblyInfoParams.Version, + AssemblyInfoParams.Author, + downloadLink: "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/SmartReticle" +)] + +[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.SmartReticle.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/SmartReticle/README.md b/SmartReticle/README.md new file mode 100644 index 0000000..b32d3f3 --- /dev/null +++ b/SmartReticle/README.md @@ -0,0 +1,14 @@ +# SmartReticle + +Simple mod that makes the Desktop reticle only appear when needed. + +--- + +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/SmartReticle/SmartReticle.csproj b/SmartReticle/SmartReticle.csproj new file mode 100644 index 0000000..728edb7 --- /dev/null +++ b/SmartReticle/SmartReticle.csproj @@ -0,0 +1,6 @@ + + + + net48 + + diff --git a/SmartReticle/format.json b/SmartReticle/format.json new file mode 100644 index 0000000..958ffac --- /dev/null +++ b/SmartReticle/format.json @@ -0,0 +1,23 @@ +{ + "_id": -1, + "name": "SmartReticle", + "modversion": "1.0.0", + "gameversion": "2024r175", + "loaderversion": "0.6.1", + "modtype": "Mod", + "author": "NotAKidoS", + "description": "Simple mod that makes the Desktop reticle only appear when needed.", + "searchtags": [ + "reticle", + "hud", + "cursor", + "dot" + ], + "requirements": [ + "None" + ], + "downloadlink": "https://github.com/NotAKidoS/NAK_CVR_Mods/releases/download/r39/SmartReticle.dll", + "sourcelink": "https://github.com/NotAKidoS/NAK_CVR_Mods/tree/main/SmartReticle/", + "changelog": "- Initial Release", + "embedcolor": "#f61963" +} \ No newline at end of file