Decompiled source of CleanMainMenu v1.1.0

CleanMainMenu/CleanMainMenu.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CleanMainMenu")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CleanMainMenu")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f019665c-ee34-4661-b490-78c14c6ce504")]
[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")]
[BepInPlugin("crevitka.cleanmenu", "Clean Main Menu", "1.1.0")]
public class CleanMainMenuPlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <HideRoutine>d__23 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public CleanMainMenuPlugin <>4__this;

		private float <initialDelay>5__1;

		private int <tries>5__2;

		private float <wait>5__3;

		private int <i>5__4;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <HideRoutine>d__23(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<initialDelay>5__1 = Mathf.Max(0f, <>4__this._initialDelaySeconds.Value);
				if (<initialDelay>5__1 > 0f)
				{
					<>2__current = (object)new WaitForSeconds(<initialDelay>5__1);
					<>1__state = 1;
					return true;
				}
				goto IL_0080;
			case 1:
				<>1__state = -1;
				goto IL_0080;
			case 2:
				{
					<>1__state = -1;
					<i>5__4++;
					break;
				}
				IL_0080:
				<tries>5__2 = Mathf.Clamp(<>4__this._attempts.Value, 1, 60);
				<wait>5__3 = Mathf.Clamp(<>4__this._intervalSeconds.Value, 0.1f, 10f);
				<i>5__4 = 0;
				break;
			}
			if (<i>5__4 < <tries>5__2)
			{
				<>4__this.ApplyOnce();
				<>2__current = (object)new WaitForSeconds(<wait>5__3);
				<>1__state = 2;
				return true;
			}
			((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Clean Main Menu applied.");
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <MenuWatchdog>d__24 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public CleanMainMenuPlugin <>4__this;

		private float <wait>5__1;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <MenuWatchdog>d__24(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<wait>5__1 = Mathf.Clamp(<>4__this._watchIntervalSeconds.Value, 0.25f, 10f);
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (!<>4__this.IsMenuScene(SceneManager.GetActiveScene()))
			{
				<>4__this.StopWatchdog();
				return false;
			}
			<>4__this.ApplyOnce();
			<>2__current = (object)new WaitForSeconds(<wait>5__1);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private ConfigEntry<bool> _hideModdedText;

	private ConfigEntry<bool> _hideShowLogButton;

	private ConfigEntry<bool> _hideTopRightMerch;

	private ConfigEntry<bool> _hideChangelog;

	private ConfigEntry<bool> _hideVersionNumber;

	private ConfigEntry<float> _initialDelaySeconds;

	private ConfigEntry<int> _attempts;

	private ConfigEntry<float> _intervalSeconds;

	private ConfigEntry<bool> _reapplyOnMenuScenes;

	private ConfigEntry<bool> _watchMenuContinuously;

	private ConfigEntry<float> _watchIntervalSeconds;

	private Coroutine _hideRoutine;

	private Coroutine _watchRoutine;

	private void Awake()
	{
		_hideModdedText = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide modded_text", true, "Hide the 'modded' warning text in main menu (object name: modded_text).");
		_hideShowLogButton = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide showlog button", true, "Hide 'showlog' button in main menu (object name: showlog).");
		_hideTopRightMerch = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide TopRight (Merch)", true, "Hide top-right panel (usually merch store / icons) (object name: TopRight).");
		_hideChangelog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide Changelog", true, "Hide left-side changelog panel (object name: Canvas Changelog).");
		_hideVersionNumber = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Hide Version Number", true, "Hide Version Number (object name: version_text).");
		_initialDelaySeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Timing", "Initial delay (seconds)", 1.5f, "Wait before first attempt (menu UI may spawn a bit later).");
		_attempts = ((BaseUnityPlugin)this).Config.Bind<int>("Timing", "Attempts", 10, "How many times to try hiding (useful when UI spawns late or gets recreated).");
		_intervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Timing", "Interval between attempts (seconds)", 1f, "Delay between attempts.");
		_reapplyOnMenuScenes = ((BaseUnityPlugin)this).Config.Bind<bool>("Advanced", "Reapply on menu scene load", true, "Re-apply cleanup whenever a menu scene loads (fixes UI coming back after exiting a world).");
		_watchMenuContinuously = ((BaseUnityPlugin)this).Config.Bind<bool>("Advanced", "Watch menu continuously", true, "While in the menu, keep re-applying cleanup periodically (handles UI being recreated later).");
		_watchIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Advanced", "Watch interval (seconds)", 1f, "How often to re-apply cleanup while watching the menu.");
		if (_reapplyOnMenuScenes.Value)
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Clean Main Menu loaded (config initialized).");
	}

	private void OnDestroy()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}

	private void Start()
	{
		StartApplyForCurrentScene();
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		StartApplyForScene(scene);
	}

	private void StartApplyForCurrentScene()
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		StartApplyForScene(SceneManager.GetActiveScene());
	}

	private void StartApplyForScene(Scene scene)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		if (!IsMenuScene(scene))
		{
			StopWatchdog();
			return;
		}
		RestartHideRoutine();
		if (_watchMenuContinuously.Value)
		{
			StartWatchdog();
		}
		else
		{
			StopWatchdog();
		}
	}

	private bool IsMenuScene(Scene scene)
	{
		if (!string.IsNullOrEmpty(((Scene)(ref scene)).name))
		{
			string text = ((Scene)(ref scene)).name.ToLower();
			if (text == "start" || text.Contains("start"))
			{
				return true;
			}
		}
		return (Object)(object)GameObject.Find("StartGui") != (Object)null || (Object)(object)GameObject.Find("GUI") != (Object)null;
	}

	private void RestartHideRoutine()
	{
		if (_hideRoutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(_hideRoutine);
			_hideRoutine = null;
		}
		_hideRoutine = ((MonoBehaviour)this).StartCoroutine(HideRoutine());
	}

	private void StartWatchdog()
	{
		if (_watchRoutine == null)
		{
			_watchRoutine = ((MonoBehaviour)this).StartCoroutine(MenuWatchdog());
		}
	}

	private void StopWatchdog()
	{
		if (_watchRoutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(_watchRoutine);
			_watchRoutine = null;
		}
	}

	[IteratorStateMachine(typeof(<HideRoutine>d__23))]
	private IEnumerator HideRoutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <HideRoutine>d__23(0)
		{
			<>4__this = this
		};
	}

	[IteratorStateMachine(typeof(<MenuWatchdog>d__24))]
	private IEnumerator MenuWatchdog()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <MenuWatchdog>d__24(0)
		{
			<>4__this = this
		};
	}

	private void ApplyOnce()
	{
		if (_hideModdedText.Value)
		{
			HideByName("modded_text");
		}
		if (_hideShowLogButton.Value)
		{
			HideByName("showlog");
		}
		if (_hideTopRightMerch.Value)
		{
			HideByName("TopRight");
		}
		if (_hideChangelog.Value)
		{
			HideByName("Canvas Changelog");
		}
		if (_hideVersionNumber.Value)
		{
			HideByName("version_text");
		}
	}

	private void HideByName(string name)
	{
		GameObject val = GameObject.Find(name);
		if (!((Object)(object)val == (Object)null) && val.activeSelf)
		{
			val.SetActive(false);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Hidden: " + name));
		}
	}
}