Decompiled source of ImNotANoob v1.2.0

BepInEx\plugins\HideKeyPrompts\HideKeyPrompts.dll

Decompiled 4 days ago
using System;
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;

[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! F7=damage numbers 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 _damageHidden = true;

	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 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)
		{
			return;
		}
		bool isPressed = ((ButtonControl)current[(Key)100]).isPressed;
		bool isPressed2 = ((ButtonControl)current[(Key)101]).isPressed;
		bool isPressed3 = ((ButtonControl)current[(Key)102]).isPressed;
		if (isPressed && !_f7Prev)
		{
			ToggleDamage();
		}
		if (isPressed2 && !_f8Prev)
		{
			Dump();
		}
		if (isPressed3 && !_f9Prev)
		{
			TogglePrompts();
		}
		_f7Prev = isPressed;
		_f8Prev = isPressed2;
		_f9Prev = isPressed3;
		_frameCounter++;
		if (_frameCounter % 90 == 0)
		{
			_frameCounter = 0;
			TryDimHealthBars();
			TryDimHud();
			if (_damageHidden)
			{
				ApplyDamageVisibility();
			}
		}
	}

	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 to " + 0.5f));
		}
	}

	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] + " alpha=" + HudDimAlphas[i]));
		}
	}

	private void ToggleDamage()
	{
		_damageHidden = !_damageHidden;
		ApplyDamageVisibility();
	}

	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++;
			}
		}
		if (num > 0)
		{
			_log.LogInfo((object)("Damage numbers " + (_damageHidden ? "HIDDEN" : "VISIBLE") + " (" + num + " objects)"));
		}
	}

	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 + " objects)"));
	}

	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);
			}
		}
	}
}