Decompiled source of PrideOfTheMountain v1.0.0

plugins/PrideOfTheMountain.dll

Decompiled a week 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using On.RoR2;
using RoR2;
using UnityEngine;

[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("PrideOfTheMountain")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+dfed8eed1f60a3a814e9777e285e69ae3c4ff816")]
[assembly: AssemblyProduct("PrideOfTheMountain")]
[assembly: AssemblyTitle("PrideOfTheMountain")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace PrideOfTheMountain;

[BepInPlugin("Nebby1999.PrideOfTheMountain", "PrideOfTheMountain", "1.0.0")]
public class PrideOfTheMountainMain : BaseUnityPlugin
{
	public enum Presets
	{
		Custom = -1,
		Gay,
		Rainbow,
		Lesbian,
		Bisexual,
		Transgender,
		NonBinary
	}

	private readonly struct FlagColorer
	{
		public readonly int colorCount;

		public readonly ReadOnlyArray<Color> flagColors;

		public static FlagColorer Parse(string input)
		{
			if (TryParse(input, out var output))
			{
				return output;
			}
			return default(FlagColorer);
		}

		public static bool TryParse(string input, out FlagColorer output)
		{
			//IL_00b4: 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)
			output = default(FlagColorer);
			try
			{
				string[] array = input.Split(';');
				if (array.Length == 0)
				{
					throw new FormatException("String has the incorrect format, each value must be separated using the char \";\"");
				}
				if (array.Length <= 1)
				{
					throw new FormatException("String does not have enough ; separated arguments. There's only one, which is the color amount, the rest of the arguments must be the colors, which there are none.");
				}
				if (!int.TryParse(array[0], out var result))
				{
					throw new FormatException("The first argument of the String (\"" + array[0] + "\") is not a number.");
				}
				int num = array.Length - 1;
				if (num != result)
				{
					throw new FormatException($"The string should have a total of \"{result}\" colors, however, only {num} entries are left in the split array. The amount of colors defined after the first argument must be the amount specified. (3 means 3 hexadecimal colors)");
				}
				Color[] array2 = (Color[])(object)new Color[num];
				Color val = default(Color);
				for (int i = 1; i < array.Length; i++)
				{
					string text = array[i];
					if (!ColorUtility.TryParseHtmlString(text, ref val))
					{
						throw new FormatException("The hexadecimal color \"" + text + "\" has an invalid hexadecimal format.");
					}
					array2[i - 1] = val;
				}
				output = new FlagColorer(result, array2);
				return true;
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Failed to parse FlagColorer with input \"{input}\".\n{arg}");
				return false;
			}
		}

		private FlagColorer(int colorCount, Color[] colors)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			this.colorCount = colorCount;
			flagColors = new ReadOnlyArray<Color>(colors);
		}
	}

	private const string GAY_PRIDE = "5;#3D1A78;#7BADE2;#FFFFFF;#98E8C1;#078D70";

	private const string RAINBOW_PRIDE = "6;#732982;#004CFF;#008062;#FFED00;#FF8C00;#E40303";

	private const string LESBIAN_PRESET = "5;#A40062;#D462A6;#FFFFFF;#FF9B56;#D62800";

	private const string BISEXUAL_PRESET = "5;#0038A8;#0038A8;#9B4F96;#D60270;#D60270";

	private const string TRANSGENDER_PRESET = "4;#5BCFFB;#F5ABB9;#FFFFFF;#F5ABB9";

	private const string NON_BINARY_PRESET = "4;#282828;#9D59D2;#FCFCFC;#FCF431";

	private const string CUSTOM_DEFAULT_PRESET = "4;#810081;#FFFFFF;#A4A4A4;#000000";

	public const string PluginGUID = "Nebby1999.PrideOfTheMountain";

	public const string PluginAuthor = "Nebby1999";

	public const string PluginName = "PrideOfTheMountain";

	public const string PluginVersion = "1.0.0";

	private int _TintColor = Shader.PropertyToID("_TintColor");

	private ConfigEntry<Presets> _chosenPreset;

	private ConfigEntry<string> _customPreset;

	private ConfigEntry<bool> _prideify;

	private Dictionary<Presets, FlagColorer> _flagColorers = new Dictionary<Presets, FlagColorer>();

	private bool _customFailedToParse;

	private static ManualLogSource logger;

	private void Awake()
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		BindConfigs();
		PopulateColorers();
		if (_prideify.Value && !_customFailedToParse)
		{
			BossShrineCounter.RebuildIndicators += new hook_RebuildIndicators(SetupPrideIndicators);
		}
	}

	private void BindConfigs()
	{
		_prideify = ((BaseUnityPlugin)this).Config.Bind<bool>("Main Config", "Activate Recolors", true, "Wether the mod is active, set this to false to disable the mod's functionality.");
		_chosenPreset = ((BaseUnityPlugin)this).Config.Bind<Presets>("Main Config", "Preset", Presets.Transgender, "The current preset for shrine of the mountain icon patterns, each preset represents one of the built in pride flags. You can set this value to Custom if you wish to declare your own custom flag.");
		_customPreset = ((BaseUnityPlugin)this).Config.Bind<string>("Main Config", "Custom Preset", "4;#810081;#FFFFFF;#A4A4A4;#000000", "A custom color preset. a Color preset is a string value separated by \";\" The first value is the total amount of colors the preset uses, afterwards you must specify each color for each index in a Hexadecimal format (ex: #FFFFFF). The default value for this config is a way to declare the \"Asexual\" flag colors as a custom preset for the mod.");
	}

	private void PopulateColorers()
	{
		_flagColorers[Presets.Rainbow] = FlagColorer.Parse("6;#732982;#004CFF;#008062;#FFED00;#FF8C00;#E40303");
		_flagColorers[Presets.NonBinary] = FlagColorer.Parse("4;#282828;#9D59D2;#FCFCFC;#FCF431");
		_flagColorers[Presets.Lesbian] = FlagColorer.Parse("5;#A40062;#D462A6;#FFFFFF;#FF9B56;#D62800");
		_flagColorers[Presets.Gay] = FlagColorer.Parse("5;#3D1A78;#7BADE2;#FFFFFF;#98E8C1;#078D70");
		_flagColorers[Presets.Bisexual] = FlagColorer.Parse("5;#0038A8;#0038A8;#9B4F96;#D60270;#D60270");
		_flagColorers[Presets.Transgender] = FlagColorer.Parse("4;#5BCFFB;#F5ABB9;#FFFFFF;#F5ABB9");
		if (FlagColorer.TryParse(_customPreset.Value, out var output))
		{
			_flagColorers[Presets.Custom] = output;
			return;
		}
		logger.LogError((object)"Custom preset failed to parse, the mod will not modify anything this session.");
		_customFailedToParse = true;
	}

	private void SetupPrideIndicators(orig_RebuildIndicators orig, BossShrineCounter self)
	{
		DestroyMaterialsOnIndicators(self._indicators);
		orig.Invoke(self);
		PrideifyCounters(self._indicators, self._indicatorCount);
	}

	private void DestroyMaterialsOnIndicators(List<GameObject> indicators)
	{
		for (int i = 0; i < indicators.Count; i++)
		{
			Object.Destroy((Object)(object)((Renderer)indicators[i].GetComponent<MeshRenderer>()).material);
		}
	}

	private unsafe void PrideifyCounters(List<GameObject> indicators, int indicatorCount)
	{
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if (!_flagColorers.TryGetValue(_chosenPreset.Value, out var value))
		{
			return;
		}
		int num = 0;
		for (int i = 0; i < indicatorCount; i++)
		{
			MeshRenderer component = indicators[i].GetComponent<MeshRenderer>();
			Material material = ((Renderer)component).material;
			material.SetColor(_TintColor, Unsafe.Read<Color>((void*)value.flagColors[num]));
			((Renderer)component).material = material;
			num++;
			if (num >= value.colorCount)
			{
				num = 0;
			}
		}
	}

	[MethodImpl(MethodImplOptions.AggressiveInlining)]
	private void Log(object thing)
	{
	}
}