Decompiled source of ImNotANoob v1.3.0

BepInEx\plugins\HideKeyPrompts\HideKeyPrompts.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HideKeyPrompts")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HideKeyPrompts")]
[assembly: AssemblyTitle("HideKeyPrompts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace HideKeyPrompts;

[BepInPlugin("com.maxi.hidekeyprompts", "HideKeyPrompts", "1.0.0")]
public class HideKeyPromptsPlugin : BasePlugin
{
	public override void Load()
	{
		ClassInjector.RegisterTypeInIl2Cpp<HideKeyBehaviour>();
		((BasePlugin)this).AddComponent<HideKeyBehaviour>();
		((BasePlugin)this).Log.LogInfo((object)"HideKeyPrompts loaded! Z=scope F6=fog F7=damage F8=dump F9=prompts");
	}
}
public class HideKeyBehaviour : MonoBehaviour
{
	private static ManualLogSource _log;

	private bool _promptsHidden;

	private static readonly string[] PromptNames = new string[5] { "ContextualInputPrompt(Clone)", "InteractionHud(Clone)", "ToggleHelpText(Clone)", "PlayerInputHelp(Clone)", "ItemUsagePrompts" };

	private bool _fogHidden;

	private static readonly string[] FogNames = new string[3] { "Local Volumetric Fog", "Fog", "Expanse Sky and Fog Volume" };

	private bool _damageHidden;

	private static readonly string[] DamageNames = new string[1] { "DamageNumbers(Clone)" };

	private GameObject _enemyHealthBars;

	private int _frameCounter;

	private const float HealthBarAlpha = 0.5f;

	private static readonly string[] HudDimNames = new string[4] { "HealthBar", "HealthBuffContainer(Clone)", "StaminaBarHud(Clone)", "ToolBar(Clone)" };

	private static readonly float[] HudDimAlphas = new float[4] { 0.5f, 0.5f, 0.5f, 0.3f };

	private bool[] _hudDimmed;

	private const float ZoomFov = 10f;

	private const float ZoomSpeed = 6f;

	private float _renderFov = -1f;

	private bool _isZooming;

	private bool _projOverridden;

	private Camera _camera;

	private GameObject _scopeOverlay;

	private List<Renderer> _hiddenRenderers = new List<Renderer>();

	private bool _playerHidden;

	private float _savedLodBias = 1f;

	private float _savedFarClip = -1f;

	private const float FarClipMultiplier = 4f;

	private float[] _savedLayerCullDistances;

	private LODGroup[] _forcedLodGroups;

	private List<Renderer> _zoomEnabledRenderers = new List<Renderer>();

	private Text _notifText;

	private GameObject _notifRoot;

	private float _notifTimer;

	private const float NotifDuration = 2f;

	private bool _f6Prev;

	private bool _f7Prev;

	private bool _f8Prev;

	private bool _f9Prev;

	public HideKeyBehaviour(IntPtr ptr)
		: base(ptr)
	{
	}

	private void Awake()
	{
		_log = Logger.CreateLogSource("HideKeyPrompts");
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
	}

	private void Update()
	{
		Keyboard current = Keyboard.current;
		if (current != null)
		{
			bool isPressed = ((ButtonControl)current[(Key)99]).isPressed;
			bool isPressed2 = ((ButtonControl)current[(Key)100]).isPressed;
			bool isPressed3 = ((ButtonControl)current[(Key)101]).isPressed;
			bool isPressed4 = ((ButtonControl)current[(Key)102]).isPressed;
			bool isPressed5 = ((ButtonControl)current[(Key)40]).isPressed;
			if (isPressed && !_f6Prev)
			{
				ToggleFog();
			}
			if (isPressed2 && !_f7Prev)
			{
				ToggleDamage();
			}
			if (isPressed3 && !_f8Prev)
			{
				Dump();
			}
			if (isPressed4 && !_f9Prev)
			{
				TogglePrompts();
			}
			_f6Prev = isPressed;
			_f7Prev = isPressed2;
			_f8Prev = isPressed3;
			_f9Prev = isPressed4;
			UpdateScope(isPressed5);
			if (_damageHidden && Time.frameCount % 5 == 0)
			{
				ApplyDamageVisibility();
			}
			_frameCounter++;
			if (_frameCounter % 90 == 0)
			{
				_frameCounter = 0;
				TryDimHealthBars();
				TryDimHud();
			}
			TickNotification();
		}
	}

	private void UpdateScope(bool zPressed)
	{
		if ((Object)(object)_camera == (Object)null)
		{
			_camera = Camera.main;
		}
		if (!((Object)(object)_camera == (Object)null))
		{
			if ((Object)(object)_scopeOverlay == (Object)null)
			{
				CreateScopeOverlay();
			}
			_isZooming = zPressed;
			if ((Object)(object)_scopeOverlay != (Object)null)
			{
				_scopeOverlay.SetActive(_isZooming);
			}
		}
	}

	private void LateUpdate()
	{
		//IL_048c: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_camera == (Object)null)
		{
			return;
		}
		if (!_isZooming)
		{
			if (!_projOverridden)
			{
				return;
			}
			_camera.ResetProjectionMatrix();
			_projOverridden = false;
			_renderFov = -1f;
			HideNearbyRenderers(hide: false);
			QualitySettings.lodBias = _savedLodBias;
			if (_savedFarClip > 0f)
			{
				_camera.farClipPlane = _savedFarClip;
				_savedFarClip = -1f;
			}
			if (_savedLayerCullDistances != null)
			{
				_camera.layerCullDistances = Il2CppStructArray<float>.op_Implicit(_savedLayerCullDistances);
				_savedLayerCullDistances = null;
			}
			if (_forcedLodGroups != null)
			{
				LODGroup[] forcedLodGroups = _forcedLodGroups;
				foreach (LODGroup val in forcedLodGroups)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.ForceLOD(-1);
					}
				}
				_forcedLodGroups = null;
			}
			foreach (Renderer zoomEnabledRenderer in _zoomEnabledRenderers)
			{
				if ((Object)(object)zoomEnabledRenderer != (Object)null)
				{
					zoomEnabledRenderer.enabled = false;
				}
			}
			_zoomEnabledRenderers.Clear();
			_log.LogInfo((object)"Zoom OFF, restored");
			return;
		}
		if (_renderFov < 0f)
		{
			_renderFov = _camera.fieldOfView;
			_savedLodBias = QualitySettings.lodBias;
			_savedFarClip = _camera.farClipPlane;
			QualitySettings.lodBias = 150f;
			_camera.farClipPlane = _savedFarClip * 4f;
			Il2CppStructArray<float> layerCullDistances = _camera.layerCullDistances;
			_savedLayerCullDistances = new float[32];
			bool flag = false;
			for (int j = 0; j < 32; j++)
			{
				_savedLayerCullDistances[j] = ((Il2CppArrayBase<float>)(object)layerCullDistances)[j];
				if (((Il2CppArrayBase<float>)(object)layerCullDistances)[j] > 0f)
				{
					_log.LogInfo((object)("Layer " + j + " cullDist=" + ((Il2CppArrayBase<float>)(object)layerCullDistances)[j]));
					flag = true;
				}
			}
			if (flag)
			{
				_camera.layerCullDistances = Il2CppStructArray<float>.op_Implicit(new float[32]);
				_log.LogInfo((object)"Layer cull distances reset to global farClip");
			}
			else
			{
				_log.LogInfo((object)"No per-layer cull distances found");
			}
			_forcedLodGroups = Il2CppArrayBase<LODGroup>.op_Implicit(Object.FindObjectsOfType<LODGroup>(false));
			LODGroup[] forcedLodGroups = _forcedLodGroups;
			foreach (LODGroup val2 in forcedLodGroups)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.ForceLOD(0);
				}
			}
			_zoomEnabledRenderers.Clear();
			foreach (Renderer item in Object.FindObjectsOfType<Renderer>(false))
			{
				if (!item.enabled)
				{
					item.enabled = true;
					_zoomEnabledRenderers.Add(item);
				}
			}
			_log.LogInfo((object)("ForceLOD(0) on " + _forcedLodGroups.Length + " groups, enabled " + _zoomEnabledRenderers.Count + " hidden renderers"));
			HideNearbyRenderers(hide: true);
			_log.LogInfo((object)("Zoom ON, fov=" + _renderFov + " farClip=" + _savedFarClip + "→" + _camera.farClipPlane));
		}
		_renderFov = Mathf.MoveTowards(_renderFov, 10f, 90f * Time.deltaTime);
		if (_frameCounter % 120 == 1 && _isZooming)
		{
			_log.LogInfo((object)("farClip now=" + _camera.farClipPlane + " (should be " + _savedFarClip * 4f + ")"));
		}
		if (_savedFarClip > 0f)
		{
			_camera.farClipPlane = _savedFarClip * 4f;
		}
		float aspect = _camera.aspect;
		_camera.projectionMatrix = Matrix4x4.Perspective(_renderFov, aspect, _camera.nearClipPlane, _camera.farClipPlane);
		_projOverridden = true;
	}

	private void HideNearbyRenderers(bool hide)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		if (hide && !_playerHidden)
		{
			_hiddenRenderers.Clear();
			foreach (SkinnedMeshRenderer item in Object.FindObjectsOfType<SkinnedMeshRenderer>(false))
			{
				if ((Object)(object)_camera != (Object)null && Vector3.Distance(((Component)item).transform.position, ((Component)_camera).transform.position) < 5f)
				{
					_hiddenRenderers.Add((Renderer)(object)item);
				}
			}
			foreach (Renderer hiddenRenderer in _hiddenRenderers)
			{
				hiddenRenderer.enabled = false;
			}
			_playerHidden = true;
			_log.LogInfo((object)("Player hidden: " + _hiddenRenderers.Count + " renderers"));
		}
		else
		{
			if (hide || !_playerHidden)
			{
				return;
			}
			foreach (Renderer hiddenRenderer2 in _hiddenRenderers)
			{
				if ((Object)(object)hiddenRenderer2 != (Object)null)
				{
					hiddenRenderer2.enabled = true;
				}
			}
			_hiddenRenderers.Clear();
			_playerHidden = false;
		}
	}

	private void CreateScopeOverlay()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			GameObject val = new GameObject("ScopeOverlay");
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 999;
			CanvasScaler obj2 = val.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			obj2.screenMatchMode = (ScreenMatchMode)0;
			obj2.matchWidthOrHeight = 0.5f;
			GameObject val2 = new GameObject("Vignette");
			val2.transform.SetParent(val.transform, false);
			RawImage obj3 = val2.AddComponent<RawImage>();
			obj3.texture = (Texture)(object)CreateVignetteTexture(480, 270);
			((Graphic)obj3).color = Color.white;
			RectTransform component = val2.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			val.SetActive(false);
			_scopeOverlay = val;
			_log.LogInfo((object)"Scope overlay created");
		}
		catch (Exception ex)
		{
			_log.LogError((object)("Scope overlay error: " + ex.Message));
		}
	}

	private Texture2D CreateVignetteTexture(int w, int h)
	{
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(w, h, (TextureFormat)4, false);
		float num = (float)w / 2f;
		float num2 = (float)h / 2f;
		float num3 = num2 * 0.88f;
		float num4 = num2 * 0.15f;
		for (int i = 0; i < w; i++)
		{
			for (int j = 0; j < h; j++)
			{
				float num5 = (float)i - num;
				float num6 = (float)j - num2;
				float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6);
				float num8 = ((!(num7 <= num3)) ? ((!(num7 >= num3 + num4)) ? ((num7 - num3) / num4) : 1f) : 0f);
				val.SetPixel(i, j, new Color(0f, 0f, 0f, num8));
			}
		}
		val.Apply();
		return val;
	}

	private void TryDimHealthBars()
	{
		if ((Object)(object)_enemyHealthBars != (Object)null)
		{
			return;
		}
		_enemyHealthBars = GameObject.Find("Enemy Health Bars");
		if (!((Object)(object)_enemyHealthBars == (Object)null))
		{
			CanvasGroup val = _enemyHealthBars.GetComponent<CanvasGroup>();
			if ((Object)(object)val == (Object)null)
			{
				val = _enemyHealthBars.AddComponent<CanvasGroup>();
			}
			val.alpha = 0.5f;
			val.blocksRaycasts = true;
			val.interactable = true;
			_log.LogInfo((object)"Enemy health bars dimmed");
		}
	}

	private void TryDimHud()
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		if (_hudDimmed == null)
		{
			_hudDimmed = new bool[HudDimNames.Length];
		}
		for (int i = 0; i < HudDimNames.Length; i++)
		{
			if (_hudDimmed[i])
			{
				continue;
			}
			GameObject val = GameObject.Find(HudDimNames[i]);
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			CanvasGroup val2 = val.GetComponent<CanvasGroup>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = val.AddComponent<CanvasGroup>();
			}
			val2.alpha = HudDimAlphas[i];
			val2.blocksRaycasts = true;
			val2.interactable = true;
			if (HudDimNames[i] == "StaminaBarHud(Clone)")
			{
				Transform val3 = val.transform.Find("Bar");
				if ((Object)(object)val3 != (Object)null)
				{
					val3.localScale = new Vector3(0.5f, 0.5f, 1f);
					CanvasGroup val4 = ((Component)val3).gameObject.GetComponent<CanvasGroup>();
					if ((Object)(object)val4 == (Object)null)
					{
						val4 = ((Component)val3).gameObject.AddComponent<CanvasGroup>();
					}
					val4.alpha = HudDimAlphas[i];
				}
			}
			_hudDimmed[i] = true;
			_log.LogInfo((object)("HUD dimmed: " + HudDimNames[i]));
		}
	}

	private void ShowNotif(string msg)
	{
		if ((Object)(object)_notifRoot == (Object)null)
		{
			CreateNotifUI();
		}
		if ((Object)(object)_notifText != (Object)null)
		{
			_notifText.text = msg;
		}
		if ((Object)(object)_notifRoot != (Object)null)
		{
			_notifRoot.SetActive(true);
		}
		_notifTimer = 2f;
	}

	private void TickNotification()
	{
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_notifRoot == (Object)null || !_notifRoot.activeSelf)
		{
			return;
		}
		_notifTimer -= Time.deltaTime;
		if (_notifTimer <= 0f)
		{
			_notifRoot.SetActive(false);
			return;
		}
		float num = ((_notifTimer < 0.5f) ? (_notifTimer / 0.5f) : 1f);
		if ((Object)(object)_notifText != (Object)null)
		{
			((Graphic)_notifText).color = new Color(1f, 0.95f, 0.4f, num);
		}
	}

	private void CreateNotifUI()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			_notifRoot = new GameObject("ModNotif");
			Object.DontDestroyOnLoad((Object)(object)_notifRoot);
			Canvas obj = _notifRoot.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 1000;
			CanvasScaler obj2 = _notifRoot.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			GameObject val = new GameObject("Label");
			val.transform.SetParent(_notifRoot.transform, false);
			_notifText = val.AddComponent<Text>();
			_notifText.font = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
			_notifText.fontSize = 30;
			_notifText.fontStyle = (FontStyle)1;
			_notifText.alignment = (TextAnchor)1;
			((Graphic)_notifText).color = new Color(1f, 0.95f, 0.4f, 1f);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.3f, 0.88f);
			component.anchorMax = new Vector2(0.7f, 0.96f);
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			_notifRoot.SetActive(false);
		}
		catch (Exception ex)
		{
			_log.LogError((object)("NotifUI error: " + ex.Message));
		}
	}

	private void ToggleFog()
	{
		_fogHidden = !_fogHidden;
		int num = 0;
		foreach (GameObject item in Object.FindObjectsOfType<GameObject>(true))
		{
			string[] fogNames = FogNames;
			foreach (string text in fogNames)
			{
				if (((Object)item).name == text || ((Object)item).name.StartsWith(text))
				{
					item.SetActive(!_fogHidden);
					num++;
					break;
				}
			}
		}
		ShowNotif(_fogHidden ? "Fog  OFF" : "Fog  ON");
		_log.LogInfo((object)("Fog " + (_fogHidden ? "HIDDEN" : "VISIBLE") + " (" + num + " objects)"));
	}

	private void ToggleDamage()
	{
		_damageHidden = !_damageHidden;
		ApplyDamageVisibility();
		ShowNotif(_damageHidden ? "Numbers  OFF" : "Numbers  ON");
	}

	private void ApplyDamageVisibility()
	{
		int num = 0;
		for (int i = 0; i < DamageNames.Length; i++)
		{
			GameObject val = GameObject.Find(DamageNames[i]);
			if ((Object)(object)val != (Object)null)
			{
				val.SetActive(!_damageHidden);
				num++;
			}
		}
	}

	private void TogglePrompts()
	{
		_promptsHidden = !_promptsHidden;
		int num = 0;
		for (int i = 0; i < PromptNames.Length; i++)
		{
			GameObject val = GameObject.Find(PromptNames[i]);
			if ((Object)(object)val != (Object)null)
			{
				val.SetActive(!_promptsHidden);
				num++;
			}
		}
		_log.LogInfo((object)("Prompts " + (_promptsHidden ? "HIDDEN" : "VISIBLE") + " (" + num + ")"));
		ShowNotif(_promptsHidden ? "Prompts  OFF" : "Prompts  ON");
	}

	private void Dump()
	{
		_log.LogInfo((object)"=== UI DUMP START ===");
		try
		{
			Il2CppArrayBase<Canvas> val = Object.FindObjectsOfType<Canvas>(true);
			_log.LogInfo((object)("Canvas count: " + val.Length));
			foreach (Canvas item in val)
			{
				_log.LogInfo((object)("CANVAS [" + (((Component)item).gameObject.activeSelf ? "ON" : "OFF") + "] " + ((Object)((Component)item).gameObject).name));
				Walk(((Component)item).transform, "  ", 0);
			}
		}
		catch (Exception ex)
		{
			_log.LogError((object)ex.Message);
		}
		_log.LogInfo((object)"=== UI DUMP END ===");
	}

	private void Walk(Transform p, string indent, int depth)
	{
		if (depth <= 4)
		{
			for (int i = 0; i < p.childCount; i++)
			{
				Transform child = p.GetChild(i);
				_log.LogInfo((object)(indent + "[" + (((Component)child).gameObject.activeSelf ? "ON" : "OFF") + "] " + ((Object)child).name));
				Walk(child, indent + "  ", depth + 1);
			}
		}
	}
}