Decompiled source of HideMUI v1.0.7

HideMUI.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HideMUI.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HideMUI")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HideMUI")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6fefbae1-544b-4342-a483-62a3cd360dec")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HideMUI
{
	[BepInPlugin("moltenhead.HideMUI", "Hide MUI", "1.0.0")]
	[BepInProcess("valheim.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static readonly ManualLogSource HMUILogger = Logger.CreateLogSource("HideMUI");

		private readonly Harmony _harmony = new Harmony("moltenhead.HideMUI");

		private static readonly string configFileName = "moltenhead.HideMUI.cfg";

		private static readonly string configFileFullPath;

		public static ConfigEntry<bool> m_crosshairActive;

		public static ConfigEntry<bool> m_stealthGUIActive;

		private void Awake()
		{
			InitializeConfig();
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			ConfigWatcher();
		}

		private void InitializeConfig()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			m_crosshairActive = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ActivateCrosshair", false, new ConfigDescription("Activates the main crosshair - default is deactivated (false).", (AcceptableValueBase)null, Array.Empty<object>()));
			m_stealthGUIActive = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ActivateStealthGUI", false, new ConfigDescription("Activates the stealth indicator and bar - default is deactivated (false).", (AcceptableValueBase)null, Array.Empty<object>()));
		}

		private void ConfigWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, configFileName);
			fileSystemWatcher.Changed += OnConfigChanged;
			fileSystemWatcher.Created += OnConfigChanged;
			fileSystemWatcher.Renamed += OnConfigChanged;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void OnConfigChanged(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(configFileFullPath))
			{
				return;
			}
			try
			{
				HMUILogger.LogDebug((object)"OnConfigChanged called..");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				HMUILogger.LogError((object)("There was an issue loading your " + configFileName));
				HMUILogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		static Plugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			configFileFullPath = configPath + directorySeparatorChar + configFileName;
		}
	}
	[HarmonyPatch]
	public static class HudPatch
	{
		[HarmonyPatch(typeof(Hud), "Awake")]
		public static class HudAwake_Patch
		{
			public static void Postfix(Hud __instance)
			{
				UI.UpdateHud(__instance);
			}
		}

		[HarmonyPatch(typeof(Hud), "UpdateCrosshair")]
		public static class HudUpdateCrosshair_Patch
		{
			public static void Postfix(Hud __instance, Player player)
			{
				if (!((Object)(object)player != (Object)(object)Player.m_localPlayer))
				{
					UI.setActiveCrosshair(__instance, Plugin.m_crosshairActive.Value);
				}
			}
		}

		[HarmonyPatch(typeof(Hud), "UpdateStealth")]
		public static class HudUpdateStealth_Patch
		{
			public static bool Prefix(Hud __instance, Player player)
			{
				if ((Object)(object)player != (Object)(object)Player.m_localPlayer || Plugin.m_stealthGUIActive.Value)
				{
					return true;
				}
				UI.setActiveStealthHud(__instance, active: false);
				return false;
			}
		}
	}
}
namespace HideMUI.Utils
{
	internal class UI
	{
		public static void UpdateHud(Hud hudInstance)
		{
			setActiveCrosshair(hudInstance, Plugin.m_crosshairActive.Value);
			setActiveStealthHud(hudInstance, Plugin.m_stealthGUIActive.Value);
		}

		public static void setActiveCrosshair(Hud hudInstance, bool active)
		{
			GameObject val = (Object.op_Implicit((Object)(object)hudInstance.m_crosshair) ? ((Component)hudInstance.m_crosshair).gameObject : null);
			if (Object.op_Implicit((Object)(object)val) && (!Object.op_Implicit((Object)(object)val) || active != val.activeInHierarchy))
			{
				val.SetActive(active);
			}
		}

		public static void setActiveStealthHud(Hud hudInstance, bool active)
		{
			GameObject[] stealthHudGameObjects = getStealthHudGameObjects(hudInstance);
			GameObject[] array = stealthHudGameObjects;
			foreach (GameObject val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && (!Object.op_Implicit((Object)(object)val) || active != val.activeInHierarchy))
				{
					val.SetActive(active);
				}
			}
		}

		private static GameObject[] getStealthHudGameObjects(Hud hudInstance)
		{
			return (GameObject[])(object)new GameObject[4]
			{
				hudInstance.m_targeted,
				hudInstance.m_hidden,
				hudInstance.m_targetedAlert,
				Object.op_Implicit((Object)(object)hudInstance.m_stealthBar) ? ((Component)hudInstance.m_stealthBar).gameObject : null
			};
		}
	}
}