Decompiled source of RiedlmMod v1.0.0

RiedlmMod.dll

Decompiled 2 weeks 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Networking;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RiedlmMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RiedlmMod")]
[assembly: AssemblyTitle("RiedlmMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RiedlmMod
{
	[BepInPlugin("riedlm.RiedlmMod", "Riedlm Mod", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "riedlm.RiedlmMod";

		public const string Name = "Riedlm Mod";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static string Folder;

		internal static ConfigEntry<string> SplashText;

		internal static ConfigEntry<float> SplashAngle;

		internal static ConfigEntry<float> SplashX;

		internal static ConfigEntry<float> SplashY;

		internal static ConfigEntry<float> SplashSize;

		internal static ConfigEntry<bool> LobbyMusicOn;

		internal static ConfigEntry<bool> MuteGameMusic;

		internal static ConfigEntry<float> LobbyMusicVolume;

		private void Awake()
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Folder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			SplashText = ((BaseUnityPlugin)this).Config.Bind<string>("Main menu", "Text", "made by Riedlm and matydvere", "The tilted text in the main menu corner.");
			SplashAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Main menu", "Tilt", 16f, "How much the text is tilted (degrees).");
			SplashX = ((BaseUnityPlugin)this).Config.Bind<float>("Main menu", "OffsetX", -250f, "Distance from the right edge (negative = left).");
			SplashY = ((BaseUnityPlugin)this).Config.Bind<float>("Main menu", "OffsetY", -150f, "Distance from the top edge (negative = down).");
			SplashSize = ((BaseUnityPlugin)this).Config.Bind<float>("Main menu", "FontSize", 38f, "Text size.");
			LobbyMusicOn = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby music", "Enabled", true, "Play the song while waiting for players in the multiplayer lobby.");
			LobbyMusicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Lobby music", "Volume", 0.3f, new ConfigDescription("Song volume (0-1). It is also scaled by the game's Master and Music volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			MuteGameMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby music", "MuteGameMusic", true, "Mute the game's own lobby music while the song plays.");
			GameObject val = new GameObject("RiedlmMod_Runner")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<Splash>();
			val.AddComponent<LobbyMusic>();
			Log.LogInfo((object)"Riedlm Mod 1.0.0 loaded.");
		}
	}
	internal class Splash : MonoBehaviour
	{
		private Canvas canvas;

		private RectTransform holder;

		private TextMeshProUGUI text;

		private TextMeshProUGUI shadow;

		private void Update()
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			try
			{
				flag = SemiFunc.IsMainMenu() && (Object)(object)MenuPageMain.instance != (Object)null && ((Behaviour)MenuPageMain.instance).isActiveAndEnabled;
			}
			catch
			{
			}
			if (!flag)
			{
				if ((Object)(object)canvas != (Object)null && ((Component)canvas).gameObject.activeSelf)
				{
					((Component)canvas).gameObject.SetActive(false);
				}
				return;
			}
			if ((Object)(object)canvas == (Object)null)
			{
				Build();
			}
			if (!((Component)canvas).gameObject.activeSelf)
			{
				((Component)canvas).gameObject.SetActive(true);
			}
			float unscaledTime = Time.unscaledTime;
			float num = 1f + 0.07f * Mathf.Abs(Mathf.Sin(unscaledTime * MathF.PI * 1.6f));
			((Transform)holder).localScale = Vector3.one * num;
			((Transform)holder).localRotation = Quaternion.Euler(0f, 0f, Plugin.SplashAngle.Value + Mathf.Sin(unscaledTime * 1.3f) * 2f);
			holder.anchoredPosition = new Vector2(Plugin.SplashX.Value, Plugin.SplashY.Value);
			if (((TMP_Text)text).text != Plugin.SplashText.Value)
			{
				((TMP_Text)text).text = Plugin.SplashText.Value;
				((TMP_Text)shadow).text = ((TMP_Text)text).text;
			}
		}

		private void Build()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0051: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("RiedlmMod_SplashCanvas");
			Object.DontDestroyOnLoad((Object)(object)val);
			canvas = val.AddComponent<Canvas>();
			canvas.renderMode = (RenderMode)0;
			canvas.sortingOrder = 500;
			CanvasScaler obj = val.AddComponent<CanvasScaler>();
			obj.uiScaleMode = (ScaleMode)1;
			obj.referenceResolution = new Vector2(1920f, 1080f);
			obj.matchWidthOrHeight = 0.5f;
			holder = new GameObject("Holder", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)holder).SetParent(val.transform, false);
			RectTransform obj2 = holder;
			RectTransform obj3 = holder;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(1f, 1f);
			obj3.anchorMax = val2;
			obj2.anchorMin = val2;
			holder.pivot = new Vector2(0.5f, 0.5f);
			holder.sizeDelta = new Vector2(520f, 80f);
			TMP_FontAsset font = null;
			try
			{
				TextMeshProUGUI componentInChildren = ((Component)MenuPageMain.instance).GetComponentInChildren<TextMeshProUGUI>(true);
				if ((Object)(object)componentInChildren != (Object)null)
				{
					font = ((TMP_Text)componentInChildren).font;
				}
			}
			catch
			{
			}
			shadow = MakeText("Shadow", font, new Color(0.15f, 0.08f, 0f, 0.85f));
			((TMP_Text)shadow).rectTransform.anchoredPosition = new Vector2(4f, -4f);
			text = MakeText("Text", font, new Color(1f, 0.9f, 0.15f));
		}

		private TextMeshProUGUI MakeText(string name, TMP_FontAsset font, Color color)
		{
			//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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent((Transform)(object)holder, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			Vector2 offsetMin = (component.offsetMax = Vector2.zero);
			component.offsetMin = offsetMin;
			TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
			if ((Object)(object)font != (Object)null)
			{
				((TMP_Text)val2).font = font;
			}
			((TMP_Text)val2).text = Plugin.SplashText.Value;
			((TMP_Text)val2).fontSize = Plugin.SplashSize.Value;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)val2).overflowMode = (TextOverflowModes)0;
			((Graphic)val2).color = color;
			((Graphic)val2).raycastTarget = false;
			return val2;
		}
	}
	internal class LobbyMusic : MonoBehaviour
	{
		private AudioSource src;

		private AudioClip clip;

		private bool loading;

		private bool loadFailed;

		private float fade;

		private float muteScan;

		private readonly List<AudioSource> muted = new List<AudioSource>();

		private AudioMixerGroup musicGroup;

		private void Awake()
		{
			src = ((Component)this).gameObject.AddComponent<AudioSource>();
			src.loop = true;
			src.playOnAwake = false;
			src.spatialBlend = 0f;
			src.ignoreListenerPause = true;
			src.volume = 0f;
		}

		private static bool InLobby()
		{
			try
			{
				return (Object)(object)MenuPageLobby.instance != (Object)null && ((Behaviour)MenuPageLobby.instance).isActiveAndEnabled;
			}
			catch
			{
				return false;
			}
		}

		private static float GameVolume()
		{
			try
			{
				DataDirector instance = DataDirector.instance;
				if ((Object)(object)instance == (Object)null)
				{
					return 1f;
				}
				float num = (float)instance.SettingValueFetch((Setting)13) / 100f;
				float num2 = (float)instance.SettingValueFetch((Setting)0) / 100f;
				return Mathf.Clamp01(num) * Mathf.Clamp01(num2);
			}
			catch
			{
				return 1f;
			}
		}

		private void Update()
		{
			bool flag = Plugin.LobbyMusicOn.Value && InLobby();
			if (flag && (Object)(object)clip == (Object)null && !loading && !loadFailed)
			{
				((MonoBehaviour)this).StartCoroutine(Load());
			}
			fade = Mathf.MoveTowards(fade, (flag && (Object)(object)clip != (Object)null) ? 1f : 0f, Time.unscaledDeltaTime / (flag ? 2f : 1f));
			src.volume = fade * Plugin.LobbyMusicVolume.Value * GameVolume();
			if (flag && (Object)(object)clip != (Object)null && !src.isPlaying)
			{
				src.clip = clip;
				src.time = 0f;
				src.Play();
			}
			if (!flag && fade <= 0f && src.isPlaying)
			{
				src.Stop();
			}
			if (flag && (Object)(object)clip != (Object)null && Plugin.MuteGameMusic.Value)
			{
				muteScan -= Time.unscaledDeltaTime;
				if (muteScan <= 0f)
				{
					muteScan = 1f;
					MuteOthers();
				}
			}
			else
			{
				if (muted.Count <= 0 || !(fade <= 0f))
				{
					return;
				}
				foreach (AudioSource item in muted)
				{
					if ((Object)(object)item != (Object)null)
					{
						item.mute = false;
					}
				}
				muted.Clear();
			}
		}

		private void MuteOthers()
		{
			AudioMixerGroupCheck();
			AudioSource[] array = Object.FindObjectsByType<AudioSource>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			foreach (AudioSource val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)src) && !val.mute)
				{
					AudioMixerGroup outputAudioMixerGroup = val.outputAudioMixerGroup;
					if (((Object)(object)musicGroup != (Object)null && (Object)(object)outputAudioMixerGroup == (Object)(object)musicGroup) || ((Object)(object)outputAudioMixerGroup != (Object)null && ((Object)outputAudioMixerGroup).name.IndexOf("Music", StringComparison.OrdinalIgnoreCase) >= 0))
					{
						val.mute = true;
						muted.Add(val);
					}
				}
			}
		}

		private void AudioMixerGroupCheck()
		{
			if ((Object)(object)musicGroup == (Object)null && (Object)(object)AudioManager.instance != (Object)null)
			{
				musicGroup = AudioManager.instance.MusicMasterGroup;
			}
		}

		private IEnumerator Load()
		{
			loading = true;
			string text = Path.Combine(Plugin.Folder, "lobby_music.mp3");
			if (!File.Exists(text))
			{
				Plugin.Log.LogWarning((object)("lobby_music.mp3 not found next to the mod: " + text));
				loadFailed = true;
				loading = false;
				yield break;
			}
			string text2 = "file:///" + text.Replace('\\', '/');
			UnityWebRequest req = UnityWebRequestMultimedia.GetAudioClip(text2, (AudioType)13);
			try
			{
				yield return req.SendWebRequest();
				if ((int)req.result != 1)
				{
					Plugin.Log.LogError((object)("Couldn't load lobby music: " + req.error));
					loadFailed = true;
				}
				else
				{
					clip = DownloadHandlerAudioClip.GetContent(req);
					((Object)clip).name = "RiedlmMod_LobbyMusic";
					Plugin.Log.LogInfo((object)("Lobby music loaded (" + clip.length.ToString("0") + "s)."));
				}
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
			loading = false;
		}
	}
}