Decompiled source of QuickSandColor v1.1.1

QuickSandColor/QuickSandColor.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
using Microsoft.CodeAnalysis;
using QuickSandColor.Dependency;
using UnityEngine;
using UnityEngine.Rendering.HighDefinition;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("QuickSandColor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+9abc38410b78c5b28a3713551634438404cc8fec")]
[assembly: AssemblyProduct("Quick Sand Color")]
[assembly: AssemblyTitle("QuickSandColor")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 QuickSandColor
{
	[HarmonyPatch]
	[BepInPlugin("mattymatty.QuickSandColor", "QuickSandColor", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class QuickSandColor : BaseUnityPlugin
	{
		[HarmonyPatch]
		internal class RoundManagerPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch(typeof(RoundManager), "Awake")]
			private static void OnAwake()
			{
				UpdateQuicksand();
			}
		}

		[HarmonyPatch]
		internal class StartOfRoundPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch(typeof(StartOfRound), "ChangeLevel")]
			private static void AfterMoonChange()
			{
				UpdateQuicksand();
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(StartOfRound), "Awake")]
			private static void AfterBoot(StartOfRound __instance)
			{
				SelectableLevel[] levels = __instance.levels;
				foreach (SelectableLevel val in levels)
				{
					GetOrAddMoon("Moons", val.PlanetName, out var _);
				}
			}
		}

		internal static QuickSandColor INSTANCE;

		public const string GUID = "mattymatty.QuickSandColor";

		public const string NAME = "QuickSandColor";

		public const string VERSION = "1.1.0";

		internal static ManualLogSource Log;

		internal static readonly Dictionary<string, ConfigEntry<string>> ColorMap = new Dictionary<string, ConfigEntry<string>>();

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			INSTANCE = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				if (LobbyCompatibilityProxy.Enabled)
				{
					LobbyCompatibilityProxy.Init();
				}
				Log.LogInfo((object)"Patching Methods");
				Harmony val = new Harmony("mattymatty.QuickSandColor");
				val.PatchAll(Assembly.GetExecutingAssembly());
				ConfigEntry<string> val2 = ((BaseUnityPlugin)this).Config.Bind<string>("Default", "default_color", "#FFFF00", "the new color for quicksand ( in HEX format )");
				val2.SettingChanged += OnConfigChange;
				ColorMap.Add("default", val2);
				if (LethalConfigProxy.Enabled)
				{
					LethalConfigProxy.AddConfig(val2);
				}
				Color val3 = default(Color);
				if (!ColorUtility.TryParseHtmlString(val2.Value, ref val3))
				{
					Log.LogFatal((object)("Color value for moon 'Default' ('" + val2.Value + "') cannot be parsed"));
				}
				Log.LogInfo((object)"QuickSandColor v1.1.0 Loaded!");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Exception while initializing: \n" + ex));
			}
		}

		internal static bool GetOrAddMoon(string source, string name, out Color color)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			name = Regex.Replace(name, "[^\\w\\. @-]", "", RegexOptions.None);
			if (Utility.IsNullOrWhiteSpace(name))
			{
				color = Color.clear;
				return false;
			}
			string text = source + "." + name;
			if (!ColorMap.TryGetValue(text, out var value))
			{
				value = ((BaseUnityPlugin)INSTANCE).Config.Bind<string>(source, name, "Default", "overriden quicksand color for this moon ( in HEX format )");
				value.SettingChanged += OnConfigChange;
				ColorMap.Add(text, value);
				if (LethalConfigProxy.Enabled)
				{
					LethalConfigProxy.AddConfig(value);
				}
			}
			string value2 = ColorMap["default"].Value;
			if (value.Value.ToLower() != "default")
			{
				value2 = value.Value;
			}
			if (ColorUtility.TryParseHtmlString(value2, ref color))
			{
				return true;
			}
			Log.LogFatal((object)("Color value for moon '" + text + "' ('" + value2 + "') cannot be parsed"));
			color = Color.clear;
			return false;
		}

		private static void OnConfigChange(object sender, EventArgs eventArgs)
		{
			UpdateQuicksand();
		}

		internal static void UpdateQuicksand()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)RoundManager.Instance == (Object)null))
			{
				StartOfRound instance = StartOfRound.Instance;
				SelectableLevel currentLevel = instance.currentLevel;
				if (GetOrAddMoon("Moons", currentLevel.PlanetName, out var color))
				{
					RoundManager.Instance.quicksandPrefab.GetComponentInChildren<DecalProjector>().material.color = color;
				}
			}
		}
	}
}
namespace QuickSandColor.Dependency
{
	public static class LethalConfigProxy
	{
		private static bool? _enabled;

		public static bool Enabled
		{
			get
			{
				bool valueOrDefault = _enabled.GetValueOrDefault();
				if (!_enabled.HasValue)
				{
					valueOrDefault = Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");
					_enabled = valueOrDefault;
				}
				return _enabled.Value;
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void AddConfig(ConfigEntry<string> entry)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, new TextInputFieldOptions
			{
				RequiresRestart = false
			}));
		}
	}
	public static class LobbyCompatibilityProxy
	{
		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Init()
		{
			PluginHelper.RegisterPlugin("mattymatty.QuickSandColor", Version.Parse("1.1.0"), (CompatibilityLevel)0, (VersionStrictness)2);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}