Decompiled source of DifficultySelection v0.1.2

DifficultySelection.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using RoR2;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.0")]
namespace Local.Difficulty.Selection;

[BepInPlugin("local.difficulty.selection", "DifficultySelection", "0.1.2")]
public class Plugin : BaseUnityPlugin
{
	public const string versionNumber = "0.1.2";

	private static ConfigFile configuration;

	public void Awake()
	{
		configuration = ((BaseUnityPlugin)this).Config;
		Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
	}

	[HarmonyPatch(typeof(RuleCatalog), "Init")]
	[HarmonyFinalizer]
	private static void Initialize(Exception __exception)
	{
		if (__exception != null)
		{
			throw __exception;
		}
		UpdateSelection();
	}

	[HarmonyPatch(typeof(PreGameController), "ResolveChoiceMask")]
	[HarmonyPrefix]
	private static void UpdateSelection()
	{
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Invalid comparison between Unknown and I4
		RuleDef val = RuleCatalog.allRuleDefs?.FirstOrDefault();
		List<RuleChoiceDef> list = val?.choices;
		if (list == null)
		{
			Console.WriteLine("ERROR: Unable to update difficulty selection.");
			return;
		}
		string[] array = list.Select((RuleChoiceDef choice) => choice.localName).ToArray();
		string value = configuration.Bind<string>("General", "Default Difficulty", list.Find((RuleChoiceDef choice) => (int)choice.difficultyIndex == 2)?.localName, new ConfigDescription("If no other option is chosen in the lobby, this one will be selected by default.", (AcceptableValueBase)(object)new AcceptableValueList<string>(array), Array.Empty<object>())).Value;
		for (int i = 0; i < list.Count; i++)
		{
			RuleChoiceDef val2 = list[i];
			ConfigFile obj = configuration;
			string localName = val2.localName;
			string text = "Adjust this value to " + (val2.excludeByDefault ? "show" : "hide") + " the \"" + Language.GetString(val2.tooltipNameToken) + "\" difficulty option in the lobby.";
			val2.excludeByDefault = !obj.Bind<bool>("Options", localName, !val2.excludeByDefault || (int)val2.difficultyIndex == 10, text).Value;
			if (value == val2.localName)
			{
				val.defaultChoiceIndex = i;
				val2.excludeByDefault = false;
			}
		}
	}
}