Decompiled source of AuroraMainMenu v1.0.4

plugins/AuroraMainMenu.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("AuroraMainMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AuroraMainMenu")]
[assembly: AssemblyTitle("AuroraMainMenu")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace AuroraMainMenu;

[BepInPlugin("com.aurora.mainmenu", "Aurora Main Menu", "2.0.11")]
public class AuroraMenuPlugin : BaseUnityPlugin
{
	public const string PluginGUID = "com.aurora.mainmenu";

	public const string PluginName = "Aurora Main Menu";

	public const string PluginVersion = "2.0.11";

	public const string ServerAddress = "85.206.119.102";

	public const int ServerPort = 2456;

	internal static AuroraMenuPlugin Instance;

	internal bool IsConnecting;

	internal static ConfigEntry<float> LoginVolume;

	internal static ConfigEntry<bool> MuteLoginSoundtrack;

	private Harmony _harmony;

	public void InfoLog(string msg)
	{
		ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
		if (logger != null)
		{
			logger.LogInfo((object)msg);
		}
	}

	public void WarnLog(string msg)
	{
		ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
		if (logger != null)
		{
			logger.LogWarning((object)msg);
		}
	}

	private void Awake()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Expected O, but got Unknown
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013e: Expected O, but got Unknown
		Instance = this;
		LoginVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "LoginVolume", 0.5f, new ConfigDescription("Volume of the Aurora login/main-menu soundtrack (0.0 - 1.0). Independent of Valheim's in-game music slider.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		MuteLoginSoundtrack = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "MuteLoginSoundtrack", false, "Mute only the Aurora login soundtrack. Other menu sounds (clicks, hovers) still play.");
		LoginVolume.SettingChanged += delegate
		{
			MountainAtmospherePatches.ApplyMenuMusicVolume();
		};
		MuteLoginSoundtrack.SettingChanged += delegate
		{
			MountainAtmospherePatches.ApplyMenuMusicVolume();
		};
		_harmony = new Harmony("com.aurora.mainmenu");
		_harmony.PatchAll(typeof(FejdStartupPatches));
		_harmony.PatchAll(typeof(LocalizationPatches));
		_harmony.PatchAll(typeof(MountainAtmospherePatches));
		_harmony.PatchAll(typeof(MusicPatches));
		_harmony.PatchAll(typeof(AdminSteamIdPatches));
		GameObject val = new GameObject("AuroraAudioTabInjector");
		Object.DontDestroyOnLoad((Object)val);
		val.AddComponent<AudioTabInjectorMB>();
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} loaded. Server: {2}:{3}", "Aurora Main Menu", "2.0.11", "85.206.119.102", 2456));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[AudioTabInjector] Polling watcher active — will inject on first AudioSettings instance.");
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	internal void ConnectToServer()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("Connecting to {0}:{1} (no password)...", "85.206.119.102", 2456));
		try
		{
			IsConnecting = true;
			ZSteamMatchmaking instance = ZSteamMatchmaking.instance;
			if (instance != null)
			{
				instance.QueueServerJoin(string.Format("{0}:{1}", "85.206.119.102", 2456));
			}
		}
		catch (Exception ex)
		{
			IsConnecting = false;
			((BaseUnityPlugin)this).Logger.LogError((object)("Connection failed: " + ex.Message));
		}
	}
}
[HarmonyPatch]
public static class LocalizationPatches
{
	[HarmonyPatch(typeof(Localization), "TranslateSingleId")]
	[HarmonyPostfix]
	public static void TranslateSingleId_Postfix(ref string __result, string locaId)
	{
		if (__result != null && __result.Equals("Start Game", StringComparison.OrdinalIgnoreCase))
		{
			__result = "Play Aurora";
		}
	}
}
[HarmonyPatch]
public static class FejdStartupPatches
{
	private static Type _cachedTmpType;

	private static PropertyInfo _cachedTextProp;

	private static MethodInfo _cachedSetText;

	private static bool _typesResolved;

	private static bool _pendingCharSelect;

	[HarmonyPatch(typeof(FejdStartup), "Update")]
	[HarmonyPostfix]
	public static void Update_Postfix(FejdStartup __instance)
	{
		if ((Object)(object)__instance.m_mainMenu == (Object)null || !__instance.m_mainMenu.activeInHierarchy)
		{
			return;
		}
		try
		{
			if (!_typesResolved)
			{
				_cachedTmpType = AccessTools.TypeByName("TMPro.TMP_Text");
				_cachedTextProp = _cachedTmpType?.GetProperty("text");
				_cachedSetText = _cachedTmpType?.GetMethod("SetText", new Type[1] { typeof(string) });
				_typesResolved = true;
			}
			if (_cachedTmpType == null || _cachedTextProp == null)
			{
				return;
			}
			Button[] componentsInChildren = __instance.m_mainMenu.GetComponentsInChildren<Button>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Component componentInChildren = ((Component)componentsInChildren[i]).GetComponentInChildren(_cachedTmpType, true);
				if ((Object)(object)componentInChildren == (Object)null)
				{
					continue;
				}
				string text = (_cachedTextProp.GetValue(componentInChildren) as string)?.Trim() ?? "";
				if (!text.Equals("Start Game", StringComparison.OrdinalIgnoreCase) && !text.Equals("Start game", StringComparison.OrdinalIgnoreCase))
				{
					continue;
				}
				if (_cachedSetText != null)
				{
					_cachedSetText.Invoke(componentInChildren, new object[1] { "Play Aurora" });
				}
				else
				{
					_cachedTextProp.SetValue(componentInChildren, "Play Aurora");
				}
				MonoBehaviour[] componentsInParent = componentInChildren.gameObject.GetComponentsInParent<MonoBehaviour>(true);
				foreach (MonoBehaviour val in componentsInParent)
				{
					if (((object)val).GetType().Name.IndexOf("Localize", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						Object.DestroyImmediate((Object)(object)val);
					}
				}
				break;
			}
		}
		catch (Exception ex)
		{
			Debug.LogError((object)("[AuroraMenu] Update_Postfix rename error: " + ex.Message));
		}
	}

	[HarmonyPatch(typeof(FejdStartup), "ShowCharacterSelection")]
	[HarmonyPrefix]
	public static bool ShowCharacterSelection_Prefix(FejdStartup __instance)
	{
		AuroraMenuPlugin instance = AuroraMenuPlugin.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return true;
		}
		if (instance.IsConnecting)
		{
			return true;
		}
		if (_pendingCharSelect)
		{
			_pendingCharSelect = false;
			return true;
		}
		_pendingCharSelect = true;
		Debug.Log((object)"[AuroraMenu] Play Aurora clicked -> showing character selection");
		__instance.m_characterSelectScreen.SetActive(true);
		__instance.m_mainMenu.SetActive(false);
		try
		{
			AccessTools.Method(typeof(FejdStartup), "UpdateCharacterList", (Type[])null, (Type[])null)?.Invoke(__instance, null);
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[AuroraMenu] UpdateCharacterList: " + ex.Message));
		}
		return false;
	}

	[HarmonyPatch(typeof(FejdStartup), "OnCharacterStart")]
	[HarmonyPrefix]
	public static bool OnCharacterStart_Prefix(FejdStartup __instance)
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		AuroraMenuPlugin instance = AuroraMenuPlugin.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return true;
		}
		if (instance.IsConnecting)
		{
			return true;
		}
		try
		{
			Debug.Log((object)"[AuroraMenu] Character selected, connecting to Aurora server...");
			PlayerProfile selectedProfile = GetSelectedProfile(__instance);
			if (selectedProfile == null)
			{
				Debug.LogWarning((object)"[AuroraMenu] No character selected.");
				return true;
			}
			object value = Traverse.Create((object)__instance).Field("m_profileFileSource").GetValue();
			if (value != null)
			{
				Game.SetProfile(selectedProfile.GetFilename(), (FileSource)value);
			}
			else
			{
				Game.SetProfile(selectedProfile.GetFilename(), (FileSource)1);
			}
			__instance.m_characterSelectScreen.SetActive(false);
			instance.ConnectToServer();
			return false;
		}
		catch (Exception arg)
		{
			Debug.LogError((object)$"[AuroraMenu] OnCharacterStart_Prefix error: {arg}");
			return true;
		}
	}

	[HarmonyPatch(typeof(FejdStartup), "OnSelelectCharacterBack")]
	[HarmonyPrefix]
	public static bool OnSelectCharacterBack_Prefix(FejdStartup __instance)
	{
		if ((Object)(object)AuroraMenuPlugin.Instance == (Object)null)
		{
			return true;
		}
		_pendingCharSelect = false;
		__instance.m_characterSelectScreen.SetActive(false);
		__instance.m_mainMenu.SetActive(true);
		Debug.Log((object)"[AuroraMenu] Returned to main menu from character selection.");
		return false;
	}

	private static PlayerProfile GetSelectedProfile(FejdStartup instance)
	{
		try
		{
			Traverse obj = Traverse.Create((object)instance);
			IList list = obj.Field("m_profiles").GetValue() as IList;
			int value = obj.Field("m_profileIndex").GetValue<int>();
			if (list != null && value >= 0 && value < list.Count)
			{
				object? obj2 = list[value];
				return (PlayerProfile)((obj2 is PlayerProfile) ? obj2 : null);
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[AuroraMenu] GetSelectedProfile error: " + ex.Message));
		}
		return null;
	}
}
[HarmonyPatch]
public static class MountainAtmospherePatches
{
	[CompilerGenerated]
	private sealed class <ApplyMountainScene>d__8 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		private int <i>5__2;

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

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

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

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

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<i>5__2 = 0;
				break;
			case 1:
				<>1__state = -1;
				<i>5__2++;
				break;
			}
			if (<i>5__2 < 15)
			{
				<>2__current = null;
				<>1__state = 1;
				return true;
			}
			if (_applied)
			{
				return false;
			}
			_applied = true;
			try
			{
				FindMountainPrefabs();
				EnableGlobalSnow();
				HideMeadowStuff();
				SnowifyTerrainOnly();
				ReplaceRocksWithMountainAssets();
				PlaceIceAndSnow();
				ApplyMountainNightLighting();
				ConvertFireToFrostFire();
				SpawnSnowParticles();
				PlaceHaldorNearFire();
				PlaceBogWitchBehindLogo();
				PlaceHildirAndGolem();
				HideMenuUIElements();
				Debug.Log((object)"[AuroraMenu] Mountain scene applied.");
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"[AuroraMenu] Mountain scene error: {arg}");
			}
			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 <LoadAndPlayCustomMusic>d__21 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		private UnityWebRequest <www>5__2;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || num == 1)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<www>5__2 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Invalid comparison between Unknown and I4
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			bool result;
			try
			{
				switch (<>1__state)
				{
				default:
					result = false;
					break;
				case 0:
				{
					<>1__state = -1;
					string text = Path.Combine(Paths.ConfigPath, "sounds", "menu_theme.mp3");
					if (!File.Exists(text))
					{
						Debug.LogWarning((object)("[AuroraMenu] Music not found: " + text));
						result = false;
						break;
					}
					string text2 = "file:///" + text.Replace("\\", "/");
					<www>5__2 = UnityWebRequestMultimedia.GetAudioClip(text2, (AudioType)13);
					<>1__state = -3;
					<>2__current = <www>5__2.SendWebRequest();
					<>1__state = 1;
					result = true;
					break;
				}
				case 1:
					<>1__state = -3;
					if ((int)<www>5__2.result != 1)
					{
						Debug.LogError((object)("[AuroraMenu] Music load error: " + <www>5__2.error));
						result = false;
					}
					else
					{
						AudioClip content = DownloadHandlerAudioClip.GetContent(<www>5__2);
						if (!((Object)(object)content == (Object)null))
						{
							((Object)content).name = "AuroraMenuTheme";
							MuteExistingMusic();
							if ((Object)(object)_customMusicSource == (Object)null)
							{
								GameObject val = new GameObject("AuroraMenuMusic");
								Object.DontDestroyOnLoad((Object)val);
								_customMusicSource = val.AddComponent<AudioSource>();
							}
							_customMusicSource.clip = content;
							_customMusicSource.loop = true;
							_customMusicSource.volume = ((AuroraMenuPlugin.LoginVolume != null) ? AuroraMenuPlugin.LoginVolume.Value : 0.5f);
							_customMusicSource.mute = AuroraMenuPlugin.MuteLoginSoundtrack != null && AuroraMenuPlugin.MuteLoginSoundtrack.Value;
							_customMusicSource.spatialBlend = 0f;
							_customMusicSource.priority = 0;
							_customMusicSource.Play();
							Debug.Log((object)$"[AuroraMenu] Music playing ({content.length:F0}s).");
							<>m__Finally1();
							<www>5__2 = null;
							result = false;
							break;
						}
						result = false;
					}
					<>m__Finally1();
					break;
				}
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
			return result;
		}

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

		private void <>m__Finally1()
		{
			<>1__state = -1;
			if (<www>5__2 != null)
			{
				((IDisposable)<www>5__2).Dispose();
			}
		}

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

	private static bool _applied = false;

	private static AudioSource _customMusicSource;

	private static Dictionary<string, GameObject> _prefabs = new Dictionary<string, GameObject>();

	internal static bool IsCustomMusicPlaying()
	{
		if ((Object)(object)_customMusicSource != (Object)null)
		{
			return _customMusicSource.isPlaying;
		}
		return false;
	}

	internal static AudioSource GetCustomMusicSource()
	{
		return _customMusicSource;
	}

	internal static void ApplyMenuMusicVolume()
	{
		if ((Object)(object)_customMusicSource == (Object)null)
		{
			return;
		}
		try
		{
			float num = ((AuroraMenuPlugin.LoginVolume != null) ? AuroraMenuPlugin.LoginVolume.Value : 0.5f);
			bool mute = AuroraMenuPlugin.MuteLoginSoundtrack != null && AuroraMenuPlugin.MuteLoginSoundtrack.Value;
			_customMusicSource.volume = Mathf.Clamp01(num);
			_customMusicSource.mute = mute;
		}
		catch
		{
		}
	}

	internal static void StopCustomMusic()
	{
		if ((Object)(object)_customMusicSource != (Object)null)
		{
			_customMusicSource.Stop();
			Debug.Log((object)"[AuroraMenu] Custom music stopped.");
		}
		try
		{
			if ((Object)(object)MusicMan.instance != (Object)null)
			{
				AudioSource value = Traverse.Create((object)MusicMan.instance).Field("m_musicSource").GetValue<AudioSource>();
				if ((Object)(object)value != (Object)null)
				{
					value.mute = false;
					value.volume = 1f;
				}
			}
		}
		catch
		{
		}
		try
		{
			if ((Object)(object)AudioMan.instance != (Object)null)
			{
				string[] array = new string[3] { "m_musicSource", "m_oceanAmbientSource", "m_windLoopSource" };
				foreach (string text in array)
				{
					try
					{
						AudioSource value2 = Traverse.Create((object)AudioMan.instance).Field(text).GetValue<AudioSource>();
						if ((Object)(object)value2 != (Object)null)
						{
							value2.mute = false;
						}
					}
					catch
					{
					}
				}
			}
		}
		catch
		{
		}
		Debug.Log((object)"[AuroraMenu] Vanilla music system restored.");
	}

	[HarmonyPatch(typeof(FejdStartup), "Start")]
	[HarmonyPostfix]
	public static void Start_Postfix(FejdStartup __instance)
	{
		_applied = false;
		_prefabs.Clear();
		AuroraMenuPlugin instance = AuroraMenuPlugin.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.IsConnecting = false;
		}
		((MonoBehaviour)__instance).StartCoroutine(ApplyMountainScene());
		((MonoBehaviour)__instance).StartCoroutine(LoadAndPlayCustomMusic());
	}

	[IteratorStateMachine(typeof(<ApplyMountainScene>d__8))]
	private static IEnumerator ApplyMountainScene()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ApplyMountainScene>d__8(0);
	}

	private static void FindMountainPrefabs()
	{
		HashSet<string> hashSet = new HashSet<string>(new string[11]
		{
			"Haldor", "BogWitch", "Hildir", "silvervein", "rock1_mountain", "rock2_mountain", "rock3_mountain", "MineRock_Obsidian", "ice_rock1", "FirTree",
			"StoneGolem"
		});
		GameObject[] array = Resources.FindObjectsOfTypeAll<GameObject>();
		foreach (GameObject val in array)
		{
			if (!((Object)(object)val == (Object)null) && hashSet.Contains(((Object)val).name) && !_prefabs.ContainsKey(((Object)val).name) && (Object)(object)val.GetComponentInChildren<Renderer>(true) != (Object)null)
			{
				_prefabs[((Object)val).name] = val;
				Debug.Log((object)("[AuroraMenu] Found prefab: " + ((Object)val).name));
			}
		}
	}

	private static void ReplaceRocksWithMountainAssets()
	{
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Expected O, but got Unknown
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Expected O, but got Unknown
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0350: Unknown result type (might be due to invalid IL or missing references)
		//IL_0357: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Static");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = val.transform.Find("props_al");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Transform val3 = val2.Find("Rocks2");
		if ((Object)(object)val3 == (Object)null)
		{
			return;
		}
		List<Vector3> list = new List<Vector3>();
		List<Vector3> list2 = new List<Vector3>();
		List<Quaternion> list3 = new List<Quaternion>();
		foreach (Transform item in val3)
		{
			Transform val4 = item;
			list.Add(val4.position);
			list2.Add(val4.localScale);
			list3.Add(val4.rotation);
		}
		((Component)val3).gameObject.SetActive(false);
		GameObject val5 = (_prefabs.ContainsKey("silvervein") ? _prefabs["silvervein"] : null);
		GameObject val6 = (_prefabs.ContainsKey("rock1_mountain") ? _prefabs["rock1_mountain"] : null);
		GameObject val7 = (_prefabs.ContainsKey("rock2_mountain") ? _prefabs["rock2_mountain"] : null);
		GameObject val8 = (_prefabs.ContainsKey("rock3_mountain") ? _prefabs["rock3_mountain"] : null);
		GameObject val9 = (_prefabs.ContainsKey("ice_rock1") ? _prefabs["ice_rock1"] : null);
		GameObject val10 = (_prefabs.ContainsKey("MineRock_Obsidian") ? _prefabs["MineRock_Obsidian"] : null);
		List<GameObject> list4 = new List<GameObject>();
		if ((Object)(object)val5 != (Object)null)
		{
			list4.Add(val5);
			list4.Add(val5);
			list4.Add(val5);
		}
		if ((Object)(object)val6 != (Object)null)
		{
			list4.Add(val6);
			list4.Add(val6);
		}
		if ((Object)(object)val7 != (Object)null)
		{
			list4.Add(val7);
			list4.Add(val7);
		}
		if ((Object)(object)val8 != (Object)null)
		{
			list4.Add(val8);
		}
		if ((Object)(object)val9 != (Object)null)
		{
			list4.Add(val9);
		}
		if ((Object)(object)val10 != (Object)null)
		{
			list4.Add(val10);
		}
		if (list4.Count == 0)
		{
			Debug.LogWarning((object)"[AuroraMenu] No mountain rock prefabs found!");
			((Component)val3).gameObject.SetActive(true);
			return;
		}
		GameObject val11 = new GameObject("MountainRocks");
		val11.transform.SetParent(val2, false);
		Random random = new Random(42);
		int num = 0;
		Vector3 val12 = default(Vector3);
		((Vector3)(ref val12))..ctor(-165.5f, 54.42f, 231.21f);
		Vector3 val13 = default(Vector3);
		((Vector3)(ref val13))..ctor(-165.35f, 54.46f, 229.09f);
		for (int i = 0; i < list.Count; i++)
		{
			float num2 = Vector3.Distance(list[i], val12);
			float num3 = Vector3.Distance(list[i], val13);
			if (!(num2 < 5f) && !(num3 < 4f) && (!(list[i].x > -158f) || !(list[i].z < 226f)))
			{
				GameObject prefab = list4[random.Next(list4.Count)];
				float num4 = 0.12f + (float)random.NextDouble() * 0.15f;
				GameObject val14 = SafeSpawn(prefab, list[i], Vector3.one * num4);
				if ((Object)(object)val14 != (Object)null)
				{
					val14.transform.SetParent(val11.transform, true);
					val14.transform.rotation = list3[i];
					val14.transform.Rotate(0f, (float)random.NextDouble() * 360f, 0f);
					num++;
				}
			}
		}
		Debug.Log((object)$"[AuroraMenu] Replaced rocks with {num} mountain assets (silver veins, mountain rocks, ice).");
	}

	private static void PlaceIceAndSnow()
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = (_prefabs.ContainsKey("ice_rock1") ? _prefabs["ice_rock1"] : null);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		GameObject val2 = GameObject.Find("Static");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Transform val3 = val2.transform.Find("MenuFire");
		if ((Object)(object)val3 == (Object)null)
		{
			return;
		}
		Vector3 position = val3.position;
		int num = 0;
		Random random = new Random(99);
		int num2 = 6;
		for (int i = 0; i < num2; i++)
		{
			float num3 = (float)i / (float)num2 * 360f;
			float num4 = 8f + (float)random.NextDouble() * 8f;
			float num5 = Mathf.Cos(num3 * ((float)Math.PI / 180f)) * num4;
			float num6 = Mathf.Sin(num3 * ((float)Math.PI / 180f)) * num4;
			Vector3 position2 = position + new Vector3(num5, 0f, num6);
			float num7 = 0.06f + (float)random.NextDouble() * 0.08f;
			GameObject val4 = SafeSpawn(val, position2, Vector3.one * num7);
			if ((Object)(object)val4 != (Object)null)
			{
				val4.transform.Rotate(0f, (float)random.NextDouble() * 360f, 0f);
				num++;
			}
		}
		for (int j = 0; j < 4; j++)
		{
			float num8 = (float)random.NextDouble() * 360f;
			float num9 = 3f + (float)random.NextDouble() * 5f;
			float num10 = Mathf.Cos(num8 * ((float)Math.PI / 180f)) * num9;
			float num11 = Mathf.Sin(num8 * ((float)Math.PI / 180f)) * num9;
			Vector3 position3 = position + new Vector3(num10, -0.2f, num11);
			float num12 = 0.04f + (float)random.NextDouble() * 0.06f;
			GameObject val5 = SafeSpawn(val, position3, Vector3.one * num12);
			if ((Object)(object)val5 != (Object)null)
			{
				val5.transform.Rotate(0f, (float)random.NextDouble() * 360f, 0f);
				num++;
			}
		}
		Debug.Log((object)$"[AuroraMenu] Placed {num} ice decorations + snow patches.");
	}

	private static void SnowifyTerrainOnly()
	{
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Expected O, but got Unknown
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		GameObject val = GameObject.Find("Static");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = val.transform.Find("Terrain");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Shader val3 = null;
		string[] array = new string[3] { "Standard", "Legacy Shaders/Diffuse", "Diffuse" };
		for (int i = 0; i < array.Length; i++)
		{
			val3 = Shader.Find(array[i]);
			if ((Object)(object)val3 != (Object)null)
			{
				break;
			}
		}
		if ((Object)(object)val3 == (Object)null)
		{
			MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val4 in componentsInChildren)
			{
				object obj;
				if (val4 == null)
				{
					obj = null;
				}
				else
				{
					Material sharedMaterial = ((Renderer)val4).sharedMaterial;
					obj = ((sharedMaterial != null) ? sharedMaterial.shader : null);
				}
				if ((Object)obj != (Object)null && !((Object)((Renderer)val4).sharedMaterial.shader).name.Contains("Water") && !((Object)((Renderer)val4).sharedMaterial.shader).name.Contains("Particle"))
				{
					val3 = ((Renderer)val4).sharedMaterial.shader;
					break;
				}
			}
		}
		if ((Object)(object)val3 == (Object)null)
		{
			return;
		}
		Material val5 = new Material(val3);
		val5.color = new Color(0.75f, 0.78f, 0.85f, 1f);
		if (val5.HasProperty("_Glossiness"))
		{
			val5.SetFloat("_Glossiness", 0.3f);
		}
		if (val5.HasProperty("_Metallic"))
		{
			val5.SetFloat("_Metallic", 0f);
		}
		int num = 0;
		foreach (Transform item in val2)
		{
			Transform val6 = item;
			if (!((Object)val6).name.StartsWith("MenuZone") && !((Object)val6).name.Contains("Terrain"))
			{
				continue;
			}
			MeshRenderer[] componentsInChildren = ((Component)val6).GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val7 in componentsInChildren)
			{
				if (!((Object)(object)val7 == (Object)null))
				{
					Material[] materials = ((Renderer)val7).materials;
					for (int j = 0; j < materials.Length; j++)
					{
						materials[j] = val5;
					}
					((Renderer)val7).materials = materials;
					num++;
				}
			}
		}
		Transform val8 = val2.Find("MenuTerrain_DISTANT");
		if ((Object)(object)val8 != (Object)null)
		{
			MeshRenderer[] componentsInChildren = ((Component)val8).GetComponentsInChildren<MeshRenderer>(true);
			foreach (MeshRenderer val9 in componentsInChildren)
			{
				if (!((Object)(object)val9 == (Object)null))
				{
					Material[] materials2 = ((Renderer)val9).materials;
					for (int k = 0; k < materials2.Length; k++)
					{
						materials2[k] = val5;
					}
					((Renderer)val9).materials = materials2;
					num++;
				}
			}
		}
		Debug.Log((object)$"[AuroraMenu] Snowified {num} terrain renderers (MenuZone only).");
	}

	private static void EnableGlobalSnow()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		Shader.EnableKeyword("_ADDSNOW_ON");
		Shader.SetGlobalFloat("_AddSnow", 1f);
		Shader.SetGlobalFloat("_SnowAmount", 1f);
		Shader.SetGlobalFloat("_Snow", 1f);
		Shader.SetGlobalVector("_SnowDir", new Vector4(0f, 1f, 0f, 0f));
		Shader.SetGlobalColor("_SnowColor", new Color(0.9f, 0.92f, 0.96f, 1f));
		GameObject val = GameObject.Find("Static");
		if ((Object)(object)val != (Object)null)
		{
			Transform val2 = val.transform.Find("fogplanes");
			if ((Object)(object)val2 != (Object)null)
			{
				MeshRenderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val3 in componentsInChildren)
				{
					if ((Object)(object)val3 == (Object)null || (Object)(object)((Renderer)val3).material == (Object)null)
					{
						continue;
					}
					try
					{
						if (((Renderer)val3).material.HasProperty("_Color"))
						{
							((Renderer)val3).material.SetColor("_Color", new Color(0.04f, 0.05f, 0.1f, 0.8f));
						}
						if (((Renderer)val3).material.HasProperty("_TintColor"))
						{
							((Renderer)val3).material.SetColor("_TintColor", new Color(0.04f, 0.05f, 0.1f, 0.8f));
						}
					}
					catch
					{
					}
				}
			}
		}
		Debug.Log((object)"[AuroraMenu] Global snow enabled + fogplanes tinted.");
	}

	private static void HideMeadowStuff()
	{
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_026f: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_0111: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		//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)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Static");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = val.transform.Find("props_al");
		if ((Object)(object)val2 != (Object)null)
		{
			foreach (Transform item in val2)
			{
				Transform val3 = item;
				string text = ((Object)val3).name.ToLower();
				if (text.Contains("bush") || text.Contains("flower") || text.Contains("meadow") || text.Contains("monster"))
				{
					((Component)val3).gameObject.SetActive(false);
				}
			}
			Transform val4 = val2.Find("Pines");
			Vector3 val5 = default(Vector3);
			((Vector3)(ref val5))..ctor(-165.35f, 54.46f, 229.09f);
			if ((Object)(object)val4 != (Object)null)
			{
				Random random = new Random(77);
				int num = 0;
				int num2 = 0;
				foreach (Transform item2 in val4)
				{
					Transform val6 = item2;
					float num3 = val6.position.z - val5.z;
					float num4 = ((num3 < -2f) ? 0.55f : ((!(num3 > 2f)) ? 0.4f : 0.3f));
					if (random.NextDouble() < (double)num4)
					{
						((Component)val6).gameObject.SetActive(false);
						num++;
						if (num % 4 == 0)
						{
							GameObject val7 = new GameObject("BlueTorch");
							val7.transform.position = val6.position + Vector3.up * 4f;
							Light obj = val7.AddComponent<Light>();
							obj.type = (LightType)2;
							obj.color = new Color(0.15f, 0.45f, 1f, 1f);
							obj.intensity = 1f;
							obj.range = 6f;
							num2++;
						}
					}
				}
				Debug.Log((object)$"[AuroraMenu] Thinned trees: {num} hidden, {num2} blue torches added.");
			}
		}
		Transform val8 = val.transform.Find("Terrain");
		if ((Object)(object)val8 != (Object)null)
		{
			Transform val9 = val8.Find("DistantWater");
			if ((Object)(object)val9 != (Object)null)
			{
				Vector3 position = val9.position;
				position.y = 30f;
				val9.position = position;
			}
		}
		GameObject val10 = GameObject.Find("Backgroundscene");
		if ((Object)(object)val10 != (Object)null)
		{
			Transform val11 = val10.transform.Find("grassroot");
			if ((Object)(object)val11 != (Object)null)
			{
				((Component)val11).gameObject.SetActive(false);
			}
		}
		Debug.Log((object)"[AuroraMenu] Meadow elements hidden.");
	}

	private static void ApplyMountainNightLighting()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0290: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
		RenderSettings.fog = true;
		RenderSettings.fogMode = (FogMode)3;
		RenderSettings.fogColor = new Color(0.02f, 0.03f, 0.06f, 1f);
		RenderSettings.fogDensity = 0.03f;
		RenderSettings.ambientMode = (AmbientMode)3;
		RenderSettings.ambientLight = new Color(0.015f, 0.02f, 0.04f, 1f);
		RenderSettings.ambientIntensity = 0.15f;
		GameObject val = GameObject.Find("Backgroundscene");
		if ((Object)(object)val != (Object)null)
		{
			Transform val2 = val.transform.Find("Directional Light");
			if ((Object)(object)val2 != (Object)null)
			{
				Light component = ((Component)val2).GetComponent<Light>();
				if ((Object)(object)component != (Object)null)
				{
					component.color = new Color(0.08f, 0.1f, 0.2f, 1f);
					component.intensity = 0.06f;
					((Component)component).transform.rotation = Quaternion.Euler(60f, -30f, 0f);
				}
			}
		}
		GameObject val3 = GameObject.Find("Static");
		if ((Object)(object)val3 != (Object)null)
		{
			Light[] componentsInChildren = val3.GetComponentsInChildren<Light>(true);
			foreach (Light val4 in componentsInChildren)
			{
				if (!((Object)(object)val4 == (Object)null) && (int)val4.type == 0)
				{
					val4.intensity *= 0.1f;
					val4.color = new Color(0.1f, 0.12f, 0.25f, 1f);
				}
			}
		}
		Material skybox = RenderSettings.skybox;
		if ((Object)(object)skybox != (Object)null)
		{
			if (skybox.HasProperty("_Exposure"))
			{
				skybox.SetFloat("_Exposure", 0.05f);
			}
			if (skybox.HasProperty("_Tint"))
			{
				skybox.SetColor("_Tint", new Color(0.04f, 0.06f, 0.12f, 1f));
			}
			if (skybox.HasProperty("_SkyTint"))
			{
				skybox.SetColor("_SkyTint", new Color(0.04f, 0.06f, 0.12f, 1f));
			}
		}
		if ((Object)(object)val3 != (Object)null)
		{
			Transform val5 = val3.transform.Find("fogplanes");
			if ((Object)(object)val5 != (Object)null)
			{
				MeshRenderer[] componentsInChildren2 = ((Component)val5).GetComponentsInChildren<MeshRenderer>(true);
				foreach (MeshRenderer val6 in componentsInChildren2)
				{
					if ((Object)(object)val6 == (Object)null || (Object)(object)((Renderer)val6).material == (Object)null)
					{
						continue;
					}
					try
					{
						if (((Renderer)val6).material.HasProperty("_Color"))
						{
							((Renderer)val6).material.SetColor("_Color", new Color(0.04f, 0.06f, 0.1f, 0.8f));
						}
						if (((Renderer)val6).material.HasProperty("_TintColor"))
						{
							((Renderer)val6).material.SetColor("_TintColor", new Color(0.04f, 0.06f, 0.1f, 0.8f));
						}
					}
					catch
					{
					}
				}
			}
		}
		Debug.Log((object)"[AuroraMenu] Mountain night lighting applied.");
	}

	private static void ConvertFireToFrostFire()
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_017e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.Find("Static");
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		Transform val2 = val.transform.Find("MenuFire");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Light[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Light>(true);
		foreach (Light val3 in componentsInChildren)
		{
			if (!((Object)(object)val3 == (Object)null))
			{
				val3.color = new Color(0.2f, 0.45f, 1f, 1f);
				val3.intensity = 0.5f;
				val3.range = 4f;
			}
		}
		ParticleSystemRenderer[] componentsInChildren2 = ((Component)val2).GetComponentsInChildren<ParticleSystemRenderer>(true);
		foreach (ParticleSystemRenderer val4 in componentsInChildren2)
		{
			if ((Object)(object)val4 == (Object)null || (Object)(object)((Renderer)val4).material == (Object)null)
			{
				continue;
			}
			try
			{
				Material material = ((Renderer)val4).material;
				if (material.HasProperty("_TintColor"))
				{
					material.SetColor("_TintColor", new Color(0.15f, 0.25f, 0.6f, 0.25f));
				}
				else if (material.HasProperty("_Color"))
				{
					material.SetColor("_Color", new Color(0.2f, 0.3f, 0.6f, material.GetColor("_Color").a * 0.4f));
				}
			}
			catch
			{
			}
		}
		ParticleSystem[] componentsInChildren3 = ((Component)val2).GetComponentsInChildren<ParticleSystem>(true);
		foreach (ParticleSystem val5 in componentsInChildren3)
		{
			if (!((Object)(object)val5 == (Object)null))
			{
				try
				{
					MainModule main = val5.main;
					MinMaxGradient startColor = ((MainModule)(ref main)).startColor;
					((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.2f, 0.35f, 0.7f, ((MinMaxGradient)(ref startColor)).color.a * 0.4f));
				}
				catch
				{
				}
			}
		}
		Debug.Log((object)"[AuroraMenu] Frost fire applied.");
	}

	private static void PlaceHaldorNearFire()
	{
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = null;
		if (_prefabs.ContainsKey("Haldor"))
		{
			val = _prefabs["Haldor"];
		}
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		GameObject val2 = GameObject.Find("Static");
		if ((Object)(object)val2 == (Object)null)
		{
			return;
		}
		Transform val3 = val2.transform.Find("MenuFire");
		if (!((Object)(object)val3 == (Object)null))
		{
			Vector3 position = val3.position;
			Vector3 val4 = default(Vector3);
			((Vector3)(ref val4))..ctor(-166.5f, 54.42f, 227.2f);
			GameObject val5 = SafeSpawn(val, val4, Vector3.one * 0.9f);
			if ((Object)(object)val5 != (Object)null)
			{
				val5.transform.rotation = Quaternion.Euler(0f, 180f, 0f);
				GameObject val6 = new GameObject("HaldorLantern");
				val6.transform.SetParent(val5.transform, false);
				val6.transform.localPosition = new Vector3(0f, 3f, 0f);
				Light obj = val6.AddComponent<Light>();
				obj.type = (LightType)2;
				obj.color = new Color(1f, 0.75f, 0.3f, 1f);
				obj.intensity = 1f;
				obj.range = 5f;
				Debug.Log((object)$"[AuroraMenu] Placed Haldor at {val4} near fire at {position}.");
			}
		}
	}

	private static void PlaceBogWitchBehindLogo()
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0149: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = (_prefabs.ContainsKey("BogWitch") ? _prefabs["BogWitch"] : null);
		if ((Object)(object)val == (Object)null)
		{
			Debug.LogWarning((object)"[AuroraMenu] BogWitch prefab not found.");
			return;
		}
		Vector3 val2 = default(Vector3);
		((Vector3)(ref val2))..ctor(-168f, 53.5f, 229f);
		GameObject val3 = SafeSpawn(val, val2, Vector3.one * 1.5f);
		if ((Object)(object)val3 != (Object)null)
		{
			Vector3 val4 = new Vector3(-142.53f, 59f, 227.72f) - val2;
			Vector3 normalized = ((Vector3)(ref val4)).normalized;
			normalized.y = 0f;
			val3.transform.rotation = Quaternion.LookRotation(normalized);
			GameObject val5 = new GameObject("BogWitchLight");
			val5.transform.SetParent(val3.transform, false);
			val5.transform.localPosition = new Vector3(0f, 4f, 0f);
			Light obj = val5.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.color = new Color(0.15f, 0.8f, 0.25f, 1f);
			obj.intensity = 1.2f;
			obj.range = 5f;
			GameObject val6 = new GameObject("BogWitchFill");
			val6.transform.SetParent(val3.transform, false);
			val6.transform.localPosition = new Vector3(0f, 2f, 2f);
			Light obj2 = val6.AddComponent<Light>();
			obj2.type = (LightType)2;
			obj2.color = new Color(0.1f, 0.6f, 0.2f, 1f);
			obj2.intensity = 0.8f;
			obj2.range = 4f;
			GameObject val7 = new GameObject("BogWitchRim");
			val7.transform.SetParent(val3.transform, false);
			val7.transform.localPosition = new Vector3(0f, 7f, -1f);
			Light obj3 = val7.AddComponent<Light>();
			obj3.type = (LightType)0;
			obj3.color = new Color(0.1f, 0.7f, 0.2f, 1f);
			obj3.intensity = 0.8f;
			obj3.range = 5f;
			obj3.spotAngle = 60f;
			val7.transform.rotation = Quaternion.Euler(90f, 0f, 0f);
			Debug.Log((object)$"[AuroraMenu] Placed BogWitch at {val2} (scale 1.5x).");
		}
	}

	private static void PlaceHildirAndGolem()
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: 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_0063: 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_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = default(Vector3);
		((Vector3)(ref val))..ctor(-165.35f, 54.46f, 229.09f);
		GameObject val2 = (_prefabs.ContainsKey("Hildir") ? _prefabs["Hildir"] : null);
		Vector3 val5;
		if ((Object)(object)val2 != (Object)null)
		{
			Vector3 val3 = val + new Vector3(1f, 0f, -2f);
			GameObject val4 = SafeSpawn(val2, val3, Vector3.one * 1f);
			if ((Object)(object)val4 != (Object)null)
			{
				val5 = val - val3;
				Vector3 normalized = ((Vector3)(ref val5)).normalized;
				normalized.y = 0f;
				val4.transform.rotation = Quaternion.LookRotation(normalized);
				Debug.Log((object)$"[AuroraMenu] Placed Hildir at {val3}.");
			}
		}
		else
		{
			Debug.LogWarning((object)"[AuroraMenu] Hildir prefab not found.");
		}
		GameObject val6 = (_prefabs.ContainsKey("StoneGolem") ? _prefabs["StoneGolem"] : null);
		GameObject val7 = (_prefabs.ContainsKey("MineRock_Obsidian") ? _prefabs["MineRock_Obsidian"] : null);
		GameObject val8 = val6 ?? val7;
		if ((Object)(object)val8 != (Object)null)
		{
			Vector3 val9 = default(Vector3);
			((Vector3)(ref val9))..ctor(-156f, 54f, 221f);
			float num = (((Object)(object)val8 == (Object)(object)val6) ? 0.8f : 0.15f);
			GameObject val10 = SafeSpawn(val8, val9, Vector3.one * num);
			if ((Object)(object)val10 != (Object)null)
			{
				val5 = val - val9;
				Vector3 normalized2 = ((Vector3)(ref val5)).normalized;
				normalized2.y = 0f;
				val10.transform.rotation = Quaternion.LookRotation(normalized2);
				Debug.Log((object)$"[AuroraMenu] Placed {((Object)val8).name} at {val9}.");
			}
		}
	}

	private static void SpawnSnowParticles()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: 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_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_0233: Unknown result type (might be due to invalid IL or missing references)
		//IL_0238: Unknown result type (might be due to invalid IL or missing references)
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Expected O, but got Unknown
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = GameObject.Find("Static");
		Transform val = ((obj != null) ? obj.transform.Find("MenuFire") : null);
		Vector3 val2 = (Vector3)(((Object)(object)val != (Object)null) ? val.position : new Vector3(-165f, 54f, 229f));
		GameObject val3 = new GameObject("MountainSnow");
		val3.transform.position = val2 + Vector3.up * 20f;
		ParticleSystem val4 = val3.AddComponent<ParticleSystem>();
		MainModule main = val4.main;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).startLifetime = MinMaxCurve.op_Implicit(10f);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.5f, 2f);
		((MainModule)(ref main)).startSize = new MinMaxCurve(0.06f, 0.18f);
		((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(new Color(0.85f, 0.9f, 1f, 0.9f));
		((MainModule)(ref main)).maxParticles = 5000;
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.08f);
		EmissionModule emission = val4.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(400f);
		ShapeModule shape = val4.shape;
		((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5;
		((ShapeModule)(ref shape)).scale = new Vector3(80f, 2f, 80f);
		ParticleSystemRenderer component = val3.GetComponent<ParticleSystemRenderer>();
		if ((Object)(object)component != (Object)null)
		{
			component.renderMode = (ParticleSystemRenderMode)0;
			ParticleSystemRenderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<ParticleSystemRenderer>(true);
			foreach (ParticleSystemRenderer val5 in componentsInChildren)
			{
				if ((Object)(object)val5 != (Object)null && (Object)(object)((Renderer)val5).material != (Object)null)
				{
					Material val6 = new Material(((Renderer)val5).material);
					if (val6.HasProperty("_TintColor"))
					{
						val6.SetColor("_TintColor", new Color(1f, 1f, 1f, 0.85f));
					}
					if (val6.HasProperty("_Color"))
					{
						val6.SetColor("_Color", new Color(1f, 1f, 1f, 0.85f));
					}
					((Renderer)component).material = val6;
					break;
				}
			}
		}
		NoiseModule noise = val4.noise;
		((NoiseModule)(ref noise)).enabled = true;
		((NoiseModule)(ref noise)).strength = MinMaxCurve.op_Implicit(0.6f);
		((NoiseModule)(ref noise)).frequency = 0.2f;
		((NoiseModule)(ref noise)).damping = true;
		VelocityOverLifetimeModule velocityOverLifetime = val4.velocityOverLifetime;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true;
		((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(-0.3f, 0.5f);
		val4.Play();
		Debug.Log((object)"[AuroraMenu] Snow particles spawned.");
	}

	[IteratorStateMachine(typeof(<LoadAndPlayCustomMusic>d__21))]
	private static IEnumerator LoadAndPlayCustomMusic()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadAndPlayCustomMusic>d__21(0);
	}

	private static void MuteExistingMusic()
	{
		try
		{
			AudioSource value = Traverse.Create((object)MusicMan.instance).Field("m_musicSource").GetValue<AudioSource>();
			if ((Object)(object)value != (Object)null)
			{
				value.Stop();
				value.mute = true;
			}
		}
		catch
		{
		}
		try
		{
			if ((Object)(object)AudioMan.instance != (Object)null)
			{
				string[] array = new string[3] { "m_musicSource", "m_oceanAmbientSource", "m_windLoopSource" };
				foreach (string text in array)
				{
					try
					{
						AudioSource value2 = Traverse.Create((object)AudioMan.instance).Field(text).GetValue<AudioSource>();
						if ((Object)(object)value2 != (Object)null)
						{
							value2.Stop();
							value2.mute = true;
						}
					}
					catch
					{
					}
				}
			}
		}
		catch
		{
		}
		GameObject val = GameObject.Find("Amb_MainMenu");
		if ((Object)(object)val != (Object)null)
		{
			AudioSource component = val.GetComponent<AudioSource>();
			if ((Object)(object)component != (Object)null)
			{
				component.Stop();
				component.mute = true;
			}
		}
	}

	private static void HideMenuUIElements()
	{
		try
		{
			FejdStartup instance = FejdStartup.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			GameObject val = GameObject.Find("GuiRoot");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			string[] array = new string[16]
			{
				"changelog", "change_log", "merch", "store", "patch", "news", "moddedstuff", "modded", "version", "beta",
				"bepinex", "valheimversion", "buildid", "networkversion", "versioninfo", "modding"
			};
			Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				string text = ((Object)val2).name.ToLower();
				string[] array2 = array;
				foreach (string value in array2)
				{
					if (text.Contains(value))
					{
						((Component)val2).gameObject.SetActive(false);
						break;
					}
				}
			}
			try
			{
				Traverse val3 = Traverse.Create((object)instance);
				string[] array2 = new string[8] { "m_changeLog", "m_changelog", "m_newsPanel", "m_patchNotes", "m_merchPanel", "m_versionLabel", "m_moddedStuff", "m_betaText" };
				foreach (string text2 in array2)
				{
					try
					{
						object value2 = val3.Field(text2).GetValue();
						GameObject val4 = (GameObject)((value2 is GameObject) ? value2 : null);
						if (val4 != null)
						{
							val4.SetActive(false);
							continue;
						}
						Component val5 = (Component)((value2 is Component) ? value2 : null);
						if (val5 != null)
						{
							val5.gameObject.SetActive(false);
						}
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
		}
		catch
		{
		}
	}

	private static GameObject SafeSpawn(GameObject prefab, Vector3 position, Vector3 scale)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			bool activeSelf = prefab.activeSelf;
			prefab.SetActive(false);
			GameObject val = Object.Instantiate<GameObject>(prefab);
			prefab.SetActive(activeSelf);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			DisableGameplayComponents(val);
			val.transform.position = position;
			val.transform.localScale = scale;
			val.SetActive(true);
			return val;
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[AuroraMenu] SafeSpawn failed: " + ex.Message));
			return null;
		}
	}

	private static void DisableGameplayComponents(GameObject obj)
	{
		try
		{
			MonoBehaviour[] componentsInChildren = obj.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					string name = ((object)val).GetType().Name;
					if (name != "LODGroup" && name != "MeshRenderer" && name != "MeshFilter" && name != "SkinnedMeshRenderer")
					{
						((Behaviour)val).enabled = false;
					}
				}
				catch
				{
				}
			}
			Collider[] componentsInChildren2 = obj.GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.enabled = false;
				}
			}
			Rigidbody[] componentsInChildren3 = obj.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val3 in componentsInChildren3)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					val3.isKinematic = true;
				}
			}
		}
		catch
		{
		}
	}
}
[HarmonyPatch]
public static class AdminSteamIdPatches
{
	private static readonly Regex SteamIdPattern = new Regex("(?:Steam_)?(7656\\d{13})", RegexOptions.Compiled);

	private static HashSet<string> _adminIds;

	private static bool _adminIdsLoaded;

	private static readonly HashSet<string> _botIds = new HashSet<string>();

	private static Type _tmpType;

	private static PropertyInfo _tmpTextProp;

	private static PropertyInfo _tmpRichTextProp;

	private static bool _tmpResolved;

	private static readonly Dictionary<int, string> _lastSource = new Dictionary<int, string>();

	private static readonly Dictionary<int, string> _lastMasked = new Dictionary<int, string>();

	private static void ResolveTMP()
	{
		if (!_tmpResolved)
		{
			_tmpResolved = true;
			_tmpType = AccessTools.TypeByName("TMPro.TMP_Text");
			if (_tmpType != null)
			{
				_tmpTextProp = _tmpType.GetProperty("text");
				_tmpRichTextProp = _tmpType.GetProperty("richText");
			}
			Debug.Log((object)$"[AuroraMenu] TMPro resolved: {_tmpType != null}");
		}
	}

	private static void LoadAdminIds()
	{
		if (_adminIdsLoaded)
		{
			return;
		}
		_adminIdsLoaded = true;
		_adminIds = new HashSet<string>();
		string text = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "AppData", "LocalLow", "IronGate", "Valheim", "adminlist.txt");
		try
		{
			if (!File.Exists(text))
			{
				return;
			}
			string[] array = File.ReadAllLines(text);
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (!string.IsNullOrEmpty(text2) && !text2.StartsWith("//"))
				{
					_adminIds.Add(text2);
				}
			}
			Debug.Log((object)$"[AuroraMenu] Loaded {_adminIds.Count} admin IDs from {text}");
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[AuroraMenu] Failed to read adminlist: " + ex.Message));
		}
	}

	private static bool IsAdmin(string steamId)
	{
		if (_adminIds != null)
		{
			return _adminIds.Contains(steamId);
		}
		return false;
	}

	private static bool IsBot(string steamId)
	{
		return _botIds.Contains(steamId);
	}

	private static string ReplaceSteamIds(string text)
	{
		return SteamIdPattern.Replace(text, delegate(Match match)
		{
			string value = match.Groups[1].Value;
			if (IsAdmin(value))
			{
				return "<color=#CC55FF>ADMIN</color>";
			}
			return IsBot(value) ? "<color=#FFB863>BOT</color>" : match.Value;
		});
	}

	[HarmonyPatch(typeof(ConnectPanel), "Update")]
	[HarmonyPostfix]
	public static void ConnectPanel_Update_Postfix(ConnectPanel __instance)
	{
		try
		{
			ResolveTMP();
			LoadAdminIds();
			if (_tmpType == null || _tmpTextProp == null)
			{
				return;
			}
			Component[] componentsInChildren = ((Component)__instance).GetComponentsInChildren(_tmpType, true);
			foreach (Component val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				string text = _tmpTextProp.GetValue(val) as string;
				if (string.IsNullOrEmpty(text))
				{
					continue;
				}
				int instanceID = ((Object)val).GetInstanceID();
				if ((_lastMasked.TryGetValue(instanceID, out var value) && text == value) || !text.Contains("7656"))
				{
					continue;
				}
				if (_lastSource.TryGetValue(instanceID, out var value2) && text == value2 && value != null)
				{
					if (_tmpRichTextProp != null)
					{
						_tmpRichTextProp.SetValue(val, true);
					}
					_tmpTextProp.SetValue(val, value);
					continue;
				}
				string text2 = ReplaceSteamIds(text);
				if (!(text2 == text))
				{
					_lastSource[instanceID] = text;
					_lastMasked[instanceID] = text2;
					if (_tmpRichTextProp != null)
					{
						_tmpRichTextProp.SetValue(val, true);
					}
					_tmpTextProp.SetValue(val, text2);
				}
			}
		}
		catch
		{
		}
	}

	[HarmonyPatch(typeof(ZNet), "GetPlayerList")]
	[HarmonyPostfix]
	public static void GetPlayerList_Postfix(ref List<PlayerInfo> __result)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: 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)
		if (__result == null)
		{
			return;
		}
		LoadAdminIds();
		try
		{
			for (int i = 0; i < __result.Count; i++)
			{
				PlayerInfo val = __result[i];
				string userID = val.m_userInfo.m_id.m_userID;
				if (!string.IsNullOrEmpty(userID))
				{
					if ((val.m_name ?? "").Equals("Aurora", StringComparison.OrdinalIgnoreCase))
					{
						_botIds.Add(userID);
						val.m_userInfo.m_displayName = "BOT";
						__result[i] = val;
					}
					else if (IsAdmin(userID))
					{
						val.m_userInfo.m_displayName = "ADMIN";
						__result[i] = val;
					}
				}
			}
		}
		catch
		{
		}
	}
}
[HarmonyPatch]
public static class MusicPatches
{
	[HarmonyPatch(typeof(MusicMan), "UpdateMusic")]
	[HarmonyPrefix]
	public static bool UpdateMusic_Prefix()
	{
		if ((Object)(object)FejdStartup.instance != (Object)null && MountainAtmospherePatches.IsCustomMusicPlaying())
		{
			return false;
		}
		return true;
	}

	[HarmonyPatch(typeof(Player), "OnSpawned")]
	[HarmonyPostfix]
	public static void OnSpawned_Postfix()
	{
		MountainAtmospherePatches.StopCustomMusic();
	}
}
public class AudioTabInjectorMB : MonoBehaviour
{
	private static readonly HashSet<int> _processedPanels = new HashSet<int>();

	private static Type _audioSettingsType;

	private float _nextScan;

	private void Update()
	{
		if (Time.unscaledTime < _nextScan)
		{
			return;
		}
		_nextScan = Time.unscaledTime + 1f;
		if (_audioSettingsType == null)
		{
			_audioSettingsType = AccessTools.TypeByName("Valheim.SettingsGui.AudioSettings") ?? AccessTools.TypeByName("AudioSettings");
			if (_audioSettingsType == null)
			{
				return;
			}
		}
		Object[] array = Object.FindObjectsOfType(_audioSettingsType);
		if (array == null || array.Length == 0)
		{
			return;
		}
		Object[] array2 = array;
		foreach (Object obj in array2)
		{
			MonoBehaviour val = (MonoBehaviour)(object)((obj is MonoBehaviour) ? obj : null);
			if (!((Object)(object)val == (Object)null) && !_processedPanels.Contains(((Object)val).GetInstanceID()))
			{
				try
				{
					Inject(val);
					_processedPanels.Add(((Object)val).GetInstanceID());
				}
				catch (Exception ex)
				{
					AuroraMenuPlugin.Instance?.WarnLog("[AudioTabInjector] Inject failed: " + ex.Message + "\n" + ex.StackTrace);
					_processedPanels.Add(((Object)val).GetInstanceID());
				}
			}
		}
	}

	private static void Inject(MonoBehaviour audioSettings)
	{
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f2: Expected O, but got Unknown
		//IL_0425: Unknown result type (might be due to invalid IL or missing references)
		//IL_042f: Expected O, but got Unknown
		if ((Object)(object)audioSettings == (Object)null)
		{
			return;
		}
		int instanceID = ((Object)audioSettings).GetInstanceID();
		if (_processedPanels.Contains(instanceID))
		{
			return;
		}
		_processedPanels.Add(instanceID);
		Traverse val = Traverse.Create((object)audioSettings);
		Slider val2 = val.Field("m_volumeSlider").GetValue<Slider>() ?? val.Field("m_masterVolumeSlider").GetValue<Slider>();
		Toggle val3 = val.Field("m_continousMusic").GetValue<Toggle>() ?? val.Field("m_continuousMusic").GetValue<Toggle>();
		if ((Object)(object)val2 == (Object)null)
		{
			AuroraMenuPlugin.Instance?.WarnLog("[AudioTabInjector] m_volumeSlider field not found on AudioSettings — layout changed?");
			return;
		}
		Transform parent = ((Component)val2).transform.parent;
		if ((Object)(object)parent == (Object)null)
		{
			return;
		}
		int siblingIndex = ((Component)val2).transform.GetSiblingIndex();
		int num = (((Object)(object)val3 != (Object)null) ? ((Component)val3).transform.GetSiblingIndex() : (-1));
		AuroraMenuPlugin.Instance?.InfoLog($"[AudioTabInjector] container='{((Object)parent).name}', childCount={parent.childCount}, masterSliderIdx={siblingIndex}, continuousMusicToggleIdx={num}");
		Type type = Type.GetType("TMPro.TMP_Text, Unity.TextMeshPro") ?? Type.GetType("TMPro.TextMeshProUGUI, Unity.TextMeshPro");
		PropertyInfo propertyInfo = type?.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
		for (int i = 0; i < parent.childCount; i++)
		{
			Transform child = parent.GetChild(i);
			string text = "";
			if ((Object)(object)((Component)child).GetComponent<Slider>() != (Object)null)
			{
				text += " [Slider]";
			}
			if ((Object)(object)((Component)child).GetComponent<Toggle>() != (Object)null)
			{
				text += " [Toggle]";
			}
			if (type != null)
			{
				Component[] componentsInChildren = ((Component)child).GetComponentsInChildren(type, true);
				if (componentsInChildren.Length != 0)
				{
					string arg = (propertyInfo?.GetValue(componentsInChildren[0]) as string) ?? "";
					text += $" [TMP x{componentsInChildren.Length} first='{arg}']";
				}
			}
			AuroraMenuPlugin.Instance?.InfoLog($"[AudioTabInjector]   child[{i}] = '{((Object)child).name}'{text}");
		}
		GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject, parent);
		((Object)val4).name = "AuroraLoginVolumeSlider";
		val4.transform.SetAsLastSibling();
		StripLocalize(val4);
		if (!HasNonNumericTMP(val4))
		{
			GameObject val5 = FindLabelTMPInList(parent);
			if ((Object)(object)val5 != (Object)null)
			{
				GameObject obj = Object.Instantiate<GameObject>(val5, parent);
				((Object)obj).name = "AuroraLoginVolumeLabel";
				obj.transform.SetSiblingIndex(val4.transform.GetSiblingIndex());
				StripLocalize(obj);
				SetCloneLabel(obj, "Login Volume");
			}
		}
		else
		{
			SetCloneLabel(val4, "Login Volume");
		}
		Slider component = val4.GetComponent<Slider>();
		component.onValueChanged = new SliderEvent();
		component.minValue = 0f;
		component.maxValue = 1f;
		component.value = AuroraMenuPlugin.LoginVolume?.Value ?? 0.5f;
		Component percentTmpComponent = FindNumericOrPercentTMP(val4);
		Action<float> updatePercent = delegate(float v)
		{
			if (!((Object)(object)percentTmpComponent == (Object)null))
			{
				((object)percentTmpComponent).GetType().GetProperty("text", BindingFlags.Instance | BindingFlags.Public)?.SetValue(percentTmpComponent, Mathf.RoundToInt(v * 100f) + "%");
			}
		};
		updatePercent(component.value);
		((UnityEvent<float>)(object)component.onValueChanged).AddListener((UnityAction<float>)delegate(float v)
		{
			if (AuroraMenuPlugin.LoginVolume != null)
			{
				AuroraMenuPlugin.LoginVolume.Value = v;
			}
			updatePercent(v);
		});
		if ((Object)(object)val3 != (Object)null)
		{
			GameObject val6 = Object.Instantiate<GameObject>(((Component)val3).gameObject, parent);
			((Object)val6).name = "AuroraMuteLoginToggle";
			val6.transform.SetAsLastSibling();
			StripLocalize(val6);
			if (!HasNonNumericTMP(val6))
			{
				GameObject val7 = FindLabelTMPInList(parent);
				if ((Object)(object)val7 != (Object)null)
				{
					GameObject obj2 = Object.Instantiate<GameObject>(val7, parent);
					((Object)obj2).name = "AuroraMuteLoginToggleLabel";
					obj2.transform.SetSiblingIndex(val6.transform.GetSiblingIndex());
					StripLocalize(obj2);
					SetCloneLabel(obj2, "Mute Login Soundtrack");
				}
			}
			else
			{
				SetCloneLabel(val6, "Mute Login Soundtrack");
			}
			if ((Object)(object)val6 != (Object)null)
			{
				Toggle component2 = val6.GetComponent<Toggle>();
				component2.onValueChanged = new ToggleEvent();
				component2.isOn = AuroraMenuPlugin.MuteLoginSoundtrack?.Value ?? false;
				((UnityEvent<bool>)(object)component2.onValueChanged).AddListener((UnityAction<bool>)delegate(bool b)
				{
					if (AuroraMenuPlugin.MuteLoginSoundtrack != null)
					{
						AuroraMenuPlugin.MuteLoginSoundtrack.Value = b;
					}
				});
			}
		}
		AuroraMenuPlugin.Instance?.InfoLog("[AudioTabInjector] Cloned Login Volume slider + Mute toggle into Audio tab.");
	}

	private static GameObject FindLabelTMPInList(Transform list)
	{
		if ((Object)(object)list == (Object)null)
		{
			return null;
		}
		Type type = Type.GetType("TMPro.TMP_Text, Unity.TextMeshPro") ?? Type.GetType("TMPro.TextMeshProUGUI, Unity.TextMeshPro");
		if (type == null)
		{
			return null;
		}
		PropertyInfo property = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
		if (property == null)
		{
			return null;
		}
		for (int i = 0; i < list.childCount; i++)
		{
			GameObject gameObject = ((Component)list.GetChild(i)).gameObject;
			if ((Object)(object)gameObject.GetComponent<Slider>() != (Object)null || (Object)(object)gameObject.GetComponent<Toggle>() != (Object)null)
			{
				continue;
			}
			Component[] componentsInChildren = gameObject.GetComponentsInChildren(type, true);
			foreach (Component obj in componentsInChildren)
			{
				string text = (property.GetValue(obj) as string) ?? "";
				if (!string.IsNullOrWhiteSpace(text) && !float.TryParse(text, out var _) && !text.EndsWith("%"))
				{
					return gameObject;
				}
			}
		}
		return null;
	}

	private static Component FindNumericOrPercentTMP(GameObject root)
	{
		if ((Object)(object)root == (Object)null)
		{
			return null;
		}
		Type type = Type.GetType("TMPro.TMP_Text, Unity.TextMeshPro") ?? Type.GetType("TMPro.TextMeshProUGUI, Unity.TextMeshPro");
		if (type == null)
		{
			return null;
		}
		PropertyInfo property = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
		if (property == null)
		{
			return null;
		}
		Component[] componentsInChildren = root.GetComponentsInChildren(type, true);
		foreach (Component val in componentsInChildren)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			string text = (property.GetValue(val) as string) ?? "";
			if (!string.IsNullOrWhiteSpace(text))
			{
				if (text.EndsWith("%"))
				{
					return val;
				}
				if (float.TryParse(text, out var _))
				{
					return val;
				}
			}
		}
		return null;
	}

	private static bool HasNonNumericTMP(GameObject go)
	{
		Type type = Type.GetType("TMPro.TMP_Text, Unity.TextMeshPro") ?? Type.GetType("TMPro.TextMeshProUGUI, Unity.TextMeshPro");
		if (type == null)
		{
			return false;
		}
		PropertyInfo property = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
		if (property == null)
		{
			return false;
		}
		Component[] componentsInChildren = go.GetComponentsInChildren(type, true);
		foreach (Component val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null))
			{
				string text = (property.GetValue(val) as string) ?? "";
				if (!string.IsNullOrWhiteSpace(text) && !float.TryParse(text, out var _) && !text.EndsWith("%"))
				{
					return true;
				}
			}
		}
		return false;
	}

	private static void StripLocalize(GameObject root)
	{
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		Component[] componentsInChildren = root.GetComponentsInChildren<Component>(true);
		foreach (Component val in componentsInChildren)
		{
			if (!((Object)(object)val == (Object)null))
			{
				switch (((object)val).GetType().Name)
				{
				case "Localize":
				case "LocalizeText":
				case "UITooltip":
					Object.Destroy((Object)(object)val);
					break;
				}
			}
		}
	}

	private static void OffsetBelowSibling(GameObject clone, Transform source)
	{
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		Transform parent = clone.transform.parent;
		if ((Object)(object)parent == (Object)null || (Object)(object)((Component)parent).GetComponent<VerticalLayoutGroup>() != (Object)null || (Object)(object)((Component)parent).GetComponent<GridLayoutGroup>() != (Object)null)
		{
			return;
		}
		RectTransform component = clone.GetComponent<RectTransform>();
		RectTransform component2 = ((Component)source).GetComponent<RectTransform>();
		if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
		{
			return;
		}
		Rect rect = component2.rect;
		float num = Mathf.Max(((Rect)(ref rect)).height, 40f) + 8f;
		float y = component2.anchoredPosition.y;
		for (int i = 0; i < parent.childCount; i++)
		{
			Transform child = parent.GetChild(i);
			if (!((Object)(object)child == (Object)(object)clone.transform))
			{
				RectTransform component3 = ((Component)child).GetComponent<RectTransform>();
				if ((Object)(object)component3 != (Object)null && component3.anchoredPosition.y < y)
				{
					y = component3.anchoredPosition.y;
				}
			}
		}
		component.anchoredPosition = new Vector2(component2.anchoredPosition.x, y - num);
	}

	private static void SetCloneLabel(GameObject cloneRow, string newText)
	{
		Type type = Type.GetType("TMPro.TMP_Text, Unity.TextMeshPro") ?? Type.GetType("TMPro.TextMeshProUGUI, Unity.TextMeshPro");
		if (type != null)
		{
			PropertyInfo property = type.GetProperty("text", BindingFlags.Instance | BindingFlags.Public);
			Component[] componentsInChildren = cloneRow.GetComponentsInChildren(type, true);
			foreach (Component val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !(property == null))
				{
					string text = (property.GetValue(val) as string) ?? "";
					if (!string.IsNullOrWhiteSpace(text) && !float.TryParse(text, out var _))
					{
						property.SetValue(val, newText);
						return;
					}
				}
			}
		}
		Text[] componentsInChildren2 = cloneRow.GetComponentsInChildren<Text>(true);
		foreach (Text val2 in componentsInChildren2)
		{
			if (!((Object)(object)val2 == (Object)null) && !string.IsNullOrWhiteSpace(val2.text) && !float.TryParse(val2.text, out var _))
			{
				val2.text = newText;
				break;
			}
		}
	}
}