Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of HUDToggle v1.0.0
HUDToggle.dll
Decompiled 2 years agousing System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using GameNetcodeStuff; using HUDToggle.Patches; using HarmonyLib; using Unity.Netcode; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("HUDToggle")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HUDToggle")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("8a8abe19-a32f-4d06-99aa-bac93f74d9af")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace HUDToggle { [BepInPlugin("Nerd100.HUDToggle", "HUDToggle", "1.0.0.0")] public class HUDToggleBase : BaseUnityPlugin { private const string modGUID = "Nerd100.HUDToggle"; private const string modName = "HUDToggle"; private const string modVerion = "1.0.0.0"; private readonly Harmony harmony = new Harmony("Nerd100.HUDToggle"); private static HUDToggleBase Instance; internal ManualLogSource mls; public static bool isHUDDisabled = true; private void Awake() { if ((Object)(object)Instance == (Object)null) { Instance = this; } mls = Logger.CreateLogSource("Nerd100.HUDToggle"); mls.LogInfo((object)"Test Mod HUDToggleBase has awaken"); harmony.PatchAll(typeof(HudManagerPatch)); harmony.PatchAll(typeof(PlayerControllerBPatch)); mls = ((BaseUnityPlugin)this).Logger; mls.LogInfo((object)"HudToggle load successfully"); } } } namespace HUDToggle.Patches { [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch { private static FieldRef<HUDManager, HUDElement[]> hudElementsRef = AccessTools.FieldRefAccess<HUDManager, HUDElement[]>("HUDElements"); public static List<int> allHudElementIds = new List<int> { 0, 1, 2, 3, 4, 5 }; public static List<int> standardHudElementIds = new List<int> { 0, 2, 3 }; [HarmonyPatch("Update")] [HarmonyPrefix] private static void Prefix(PlayerControllerB __instance) { if (((!((NetworkBehaviour)__instance).IsOwner || !__instance.isPlayerControlled || (((NetworkBehaviour)__instance).IsServer && !__instance.isHostPlayerObject)) && !__instance.isTestingPlayer) || __instance.inTerminalMenu || __instance.isTypingChat || !Application.isFocused) { return; } if (((ButtonControl)Keyboard.current[(Key)34]).wasPressedThisFrame) { HUDToggleBase.isHUDDisabled = !HUDToggleBase.isHUDDisabled; Debug.Log((object)("HUD disabled is:" + HUDToggleBase.isHUDDisabled)); } if (!((Object)(object)HUDManager.Instance != (Object)null)) { return; } if (HUDToggleBase.isHUDDisabled && hudElementsRef.Invoke(HUDManager.Instance).Any((HUDElement hudElement) => hudElement.targetAlpha != 0f)) { foreach (HUDElement item in hudElementsRef.Invoke(HUDManager.Instance).Where((HUDElement hudElement, int idx) => allHudElementIds.Contains(idx))) { item.targetAlpha = 0f; } return; } if (HUDToggleBase.isHUDDisabled) { return; } foreach (HUDElement item2 in hudElementsRef.Invoke(HUDManager.Instance).Where((HUDElement hudElement, int idx) => standardHudElementIds.Contains(idx))) { item2.targetAlpha = 1f; } } } [HarmonyPatch(typeof(HUDManager))] internal class HudManagerPatch { [HarmonyPatch("SetClockVisible")] [HarmonyPrefix] private static bool Prefix(HUDManager __instance) { if (HUDToggleBase.isHUDDisabled) { __instance.Clock.targetAlpha = 0f; return false; } return true; } } }