Decompiled source of Mod Menu v1.1.1

plugins/ModMenu/BadNorth.ModMenu.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using RTM.UISystem;
using UnityEngine;
using UnityEngine.UI;
using Voxels.TowerDefense.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("BadNorth.ModMenu")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BadNorth.ModMenu")]
[assembly: AssemblyTitle("BadNorth.ModMenu")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BadNorth.ModMenu;

[BepInPlugin("local.badnorth.mod-menu", "Bad North Mod Menu", "1.1.1")]
public sealed class ModMenuPlugin : BaseUnityPlugin
{
	private ConfigEntry<KeyboardShortcut> shortcut;

	private MainMenu installedIn;

	private NativeModDialog dialog;

	private void Awake()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		shortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Menu", "Shortcut", new KeyboardShortcut((KeyCode)291, (KeyCode[])(object)new KeyCode[0]), "Open or close the local mod menu from the main menu.");
		dialog = new NativeModDialog(((BaseUnityPlugin)this).Logger);
	}

	private void Update()
	{
		//IL_0041: 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)
		UIManager instance = Singleton<UIManager>.instance;
		if (!Object.op_Implicit((Object)(object)instance))
		{
			return;
		}
		UIMenu activeMenu = instance.activeMenu;
		MainMenu val = (MainMenu)(object)((activeMenu is MainMenu) ? activeMenu : null);
		if (val != null && Object.op_Implicit((Object)(object)val) && (Object)(object)installedIn != (Object)(object)val)
		{
			InstallButton(val);
		}
		KeyboardShortcut value = shortcut.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			if (dialog.IsOpen)
			{
				dialog.Close();
			}
			else if (instance.activeMenu is MainMenu)
			{
				dialog.Open();
			}
		}
	}

	private void InstallButton(MainMenu main)
	{
		installedIn = main;
		ButtonWidget val = ((IEnumerable<ButtonWidget>)((Component)main).GetComponentsInChildren<ButtonWidget>(true)).FirstOrDefault((Func<ButtonWidget, bool>)((ButtonWidget button) => Object.op_Implicit((Object)(object)((Widget)button).localize) && ((Widget)button).localize.Term == "UI/COMMON/SETTINGS"));
		ButtonWidget val2 = ((GeneratedMenu)main).AddButton("UI/COMMON/SETTINGS", (Func<bool>)dialog.Open, (Transform)null, (ButtonWidget)null);
		((Object)((Component)val2).gameObject).name = "Local Mods";
		((Widget)val2).SetNonLocalizedLabel("模组").SetSuccessAudio(FabricEventReference.op_Implicit("UI/Menu/Settings")).SetHoverAudio(FabricID.uiHover);
		if (Object.op_Implicit((Object)(object)val) && (Object)(object)((Component)val2).transform.parent == (Object)(object)((Component)val).transform.parent)
		{
			((Component)val2).transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex() + 1);
		}
		TransformExtensions.ForceChildLayoutUpdates(((Component)main).transform, false);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Added Local Mods to the main menu.");
	}
}
internal sealed class NativeModDialog
{
	private const BindingFlags PrivateInstance = BindingFlags.Instance | BindingFlags.NonPublic;

	private static readonly FieldInfo ModalMessage = typeof(ModalOverlay).GetField("message", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo TogglePrefab = typeof(GeneratedMenu).GetField("multiSelectWidgetPrefab", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo SettingsInstance = typeof(UserSettingsMenu).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);

	private readonly ManualLogSource log;

	private ModalOverlay modal;

	private RectTransform body;

	private Text notice;

	private Dictionary<string, bool> saved;

	private Dictionary<string, bool> draft;

	public bool IsOpen
	{
		get
		{
			if (Object.op_Implicit((Object)(object)modal))
			{
				return ((UIMenu)modal).isOpen;
			}
			return false;
		}
	}

	public NativeModDialog(ManualLogSource log)
	{
		this.log = log;
	}

	public bool Open()
	{
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Expected O, but got Unknown
		if (IsOpen)
		{
			return true;
		}
		object? obj = SettingsInstance?.GetValue(null);
		UserSettingsMenu val = (UserSettingsMenu)((obj is UserSettingsMenu) ? obj : null);
		MultiSelectWidget val2 = (MultiSelectWidget)(Object.op_Implicit((Object)(object)val) ? /*isinst with value type is only supported in some contexts*/: null);
		if (!ModMenuBootstrap.CatalogueReady || !Object.op_Implicit((Object)(object)val2) || (object)ModalMessage == null)
		{
			ModalOverlay.GetInstance().InitializeNonLocalized("模组", "无法读取本地模组。请查看 BepInEx 日志。", false).AddOKButton((Func<bool>)null);
			return true;
		}
		try
		{
			saved = PluginSelection.Read();
			draft = new Dictionary<string, bool>(saved, StringComparer.OrdinalIgnoreCase);
			modal = ModalOverlay.GetInstance();
			modal.InitializeNonLocalized("模组", "保存后重启游戏,开关才会生效。", true);
			Text message = (Text)ModalMessage.GetValue(modal);
			AddBody(message, val2);
			((Widget)modal.AddOKButton((Func<bool>)Save)).SetNonLocalizedLabel("保存");
			TransformExtensions.ForceChildLayoutUpdates(((Component)modal).transform, false);
			return true;
		}
		catch (Exception ex)
		{
			log.LogError((object)ex);
			Close();
			ModalOverlay.GetInstance().InitializeNonLocalized("模组", "无法打开模组设置。请查看 BepInEx 日志。", false).AddOKButton((Func<bool>)null);
			return true;
		}
	}

	public void Close()
	{
		if (IsOpen)
		{
			modal.Dismiss();
		}
	}

	private void AddBody(Text message, MultiSelectWidget prefab)
	{
		//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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Expected O, but got Unknown
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: 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)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0231: Expected O, but got Unknown
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		LayoutElement layout = ((Component)message).GetComponent<LayoutElement>();
		bool added = !Object.op_Implicit((Object)(object)layout);
		if (added)
		{
			layout = ((Component)message).gameObject.AddComponent<LayoutElement>();
		}
		float previousWidth = layout.preferredWidth;
		float previousHeight = layout.preferredHeight;
		int previousPriority = layout.layoutPriority;
		TextAnchor previousAlignment = message.alignment;
		LocalMod[] array = ModMenuBootstrap.Plugins.ToArray();
		float num = Mathf.Max(64f, LayoutUtility.GetPreferredHeight((RectTransform)((Component)prefab).transform));
		layout.preferredWidth = 864f;
		layout.preferredHeight = 88f + Mathf.Clamp((float)array.Length * (num + 8f) + 8f, 96f, 440f);
		layout.layoutPriority = 10;
		message.alignment = (TextAnchor)1;
		modal.SetCloseAction((Action)delegate
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)body))
			{
				((Component)body).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)body).gameObject);
			}
			if (added)
			{
				Object.Destroy((Object)(object)layout);
			}
			else
			{
				layout.preferredWidth = previousWidth;
				layout.preferredHeight = previousHeight;
				layout.layoutPriority = previousPriority;
			}
			message.alignment = previousAlignment;
			body = null;
			notice = null;
			modal = null;
		});
		body = AddRect("Local Mod Settings", (Transform)(object)((Graphic)message).rectTransform);
		Stretch(body, Vector2.zero, Vector2.zero);
		RectTransform val = AddRect("Installed Mod List", (Transform)(object)body);
		Stretch(val, new Vector2(0f, 34f), new Vector2(0f, -54f));
		((Graphic)((Component)val).gameObject.AddComponent<Image>()).color = Color.clear;
		((Component)val).gameObject.AddComponent<RectMask2D>();
		RectTransform val2 = AddRect("Mod Rows", (Transform)(object)val);
		val2.anchorMin = new Vector2(0f, 1f);
		val2.anchorMax = Vector2.one;
		val2.pivot = new Vector2(0.5f, 1f);
		val2.sizeDelta = Vector2.zero;
		VerticalLayoutGroup obj = ((Component)val2).gameObject.AddComponent<VerticalLayoutGroup>();
		((HorizontalOrVerticalLayoutGroup)obj).spacing = 8f;
		((LayoutGroup)obj).padding = new RectOffset(4, 4, 4, 4);
		((HorizontalOrVerticalLayoutGroup)obj).childControlWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj).childControlHeight = true;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandWidth = true;
		((HorizontalOrVerticalLayoutGroup)obj).childForceExpandHeight = false;
		((Component)val2).gameObject.AddComponent<ContentSizeFitter>().verticalFit = (FitMode)2;
		ScrollRect val3 = ((Component)val).gameObject.AddComponent<ScrollRect>();
		val3.viewport = val;
		val3.content = val2;
		val3.horizontal = false;
		val3.movementType = (MovementType)2;
		val3.scrollSensitivity = 32f;
		notice = AddLabel(string.Empty, message, (Transform)(object)body);
		((Graphic)notice).rectTransform.anchorMin = Vector2.zero;
		((Graphic)notice).rectTransform.anchorMax = Vector2.right;
		((Graphic)notice).rectTransform.offsetMin = Vector2.zero;
		((Graphic)notice).rectTransform.offsetMax = new Vector2(0f, 30f);
		LocalMod[] array2 = array;
		foreach (LocalMod mod in array2)
		{
			AddRow(mod, prefab, val2, num, val3);
		}
		RefreshNotice();
	}

	private void AddRow(LocalMod mod, MultiSelectWidget prefab, RectTransform parent, float minHeight, ScrollRect scroll)
	{
		MultiSelectWidget row = Object.Instantiate<MultiSelectWidget>(prefab, (Transform)(object)parent, false);
		((ValueWidget<int>)(object)row.SetOnOff()).Initialize("UI/COMMON/SETTINGS", (Func<int>)(() => NextEnabled(draft, mod) ? 1 : 0), (Func<int, bool>)delegate(int value)
		{
			draft[mod.Key] = value != 0;
			RefreshNotice();
			return true;
		});
		bool flag = Chainloader.PluginInfos.Values.Any((PluginInfo plugin) => string.Equals(plugin.Location, mod.ActivePath, StringComparison.OrdinalIgnoreCase));
		string text = (mod.ConflictingFiles ? "文件冲突" : (mod.ChangeFailed ? "切换失败" : (flag ? "已加载" : "未加载")));
		((Widget)row).SetNonLocalizedLabel(mod.Name + "(" + text + ")");
		LayoutElement val = ((Component)row).GetComponent<LayoutElement>();
		if (!Object.op_Implicit((Object)(object)val))
		{
			val = ((Component)row).gameObject.AddComponent<LayoutElement>();
		}
		val.minHeight = Mathf.Max(val.minHeight, minHeight);
		val.preferredHeight = Mathf.Max(val.preferredHeight, minHeight);
		if (mod.IsMenu || mod.ConflictingFiles)
		{
			UIInteractable[] componentsInChildren = ((Component)row).GetComponentsInChildren<UIInteractable>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				componentsInChildren[num].disabled = true;
			}
		}
		((Widget)row).ForceUpdate();
		UINavigable componentInChildren = ((Component)row).GetComponentInChildren<UINavigable>(true);
		if (!Object.op_Implicit((Object)(object)componentInChildren))
		{
			return;
		}
		componentInChildren.onFocusChanged += delegate(bool focused)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			if (focused)
			{
				RevealRow(scroll, (RectTransform)((Component)row).transform);
			}
		};
	}

	private void RefreshNotice()
	{
		bool flag = ModMenuBootstrap.Plugins.Any((LocalMod mod) => mod.IsSaveCompatibility && !NextEnabled(draft, mod));
		notice.text = (flag ? "关闭存档兼容补丁可能让旧档再次无法读取。" : string.Empty);
	}

	private bool Save()
	{
		if (!ModMenuBootstrap.Plugins.Any((LocalMod mod) => NextEnabled(saved, mod) != NextEnabled(draft, mod)))
		{
			return true;
		}
		try
		{
			PluginSelection.Save(draft);
			log.LogInfo((object)"Saved local mod selection for the next launch.");
			return true;
		}
		catch (Exception ex)
		{
			notice.text = "保存失败。请查看 BepInEx 日志。";
			log.LogError((object)ex);
			return false;
		}
	}

	private static bool NextEnabled(Dictionary<string, bool> selection, LocalMod mod)
	{
		if (!selection.TryGetValue(mod.Key, out var value))
		{
			return mod.IsEnabled;
		}
		return value;
	}

	private static RectTransform AddRect(string name, Transform parent)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
		((Component)component).gameObject.layer = ((Component)parent).gameObject.layer;
		((Transform)component).SetParent(parent, false);
		return component;
	}

	private static void Stretch(RectTransform rect, Vector2 min, Vector2 max)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		rect.anchorMin = Vector2.zero;
		rect.anchorMax = Vector2.one;
		rect.offsetMin = min;
		rect.offsetMax = max;
	}

	private static Text AddLabel(string value, Text style, Transform parent)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		Text obj = ((Component)AddRect("Text", parent)).gameObject.AddComponent<Text>();
		obj.font = style.font;
		obj.fontSize = style.fontSize;
		((Graphic)obj).color = ((Graphic)style).color;
		((Graphic)obj).raycastTarget = false;
		obj.alignment = (TextAnchor)4;
		obj.text = value;
		return obj;
	}

	private static void RevealRow(ScrollRect scroll, RectTransform row)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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_001f: 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_004f: 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_0063: 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_0078: 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)
		Rect rect = scroll.content.rect;
		float height = ((Rect)(ref rect)).height;
		rect = scroll.viewport.rect;
		float num = height - ((Rect)(ref rect)).height;
		if (!(num <= 0f))
		{
			float num2 = (1f - scroll.verticalNormalizedPosition) * num;
			float num3 = 0f - row.anchoredPosition.y;
			rect = row.rect;
			float num4 = num3 - ((Rect)(ref rect)).height * (1f - row.pivot.y);
			rect = row.rect;
			float num5 = num4 + ((Rect)(ref rect)).height;
			rect = scroll.viewport.rect;
			float num6 = num5 - ((Rect)(ref rect)).height;
			scroll.verticalNormalizedPosition = 1f - Mathf.Clamp01(Mathf.Clamp(num2, num6, num4) / num);
		}
	}
}

patchers/BadNorth.ModMenu.Bootstrap.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using Mono.Cecil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("BadNorth.ModMenu.Bootstrap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BadNorth.ModMenu.Bootstrap")]
[assembly: AssemblyTitle("BadNorth.ModMenu.Bootstrap")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace BadNorth.ModMenu;

public static class ModMenuBootstrap
{
	public const string MenuId = "local.badnorth.mod-menu";

	private const string DisabledSuffix = ".disabled";

	private const string SaveCompatibilityId = "local.badnorth.save-compatibility";

	private static ManualLogSource log;

	public static bool CatalogueReady { get; private set; }

	public static IEnumerable<LocalMod> Plugins { get; private set; } = new LocalMod[0];

	public static IEnumerable<string> TargetDLLs => new string[0];

	public static void Patch(AssemblyDefinition assembly)
	{
	}

	public static void Finish()
	{
		log = Logger.CreateLogSource("Bad North Mod Menu");
		try
		{
			string text = Path.GetFullPath(Paths.PluginPath).TrimEnd(new char[1] { Path.DirectorySeparatorChar });
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			string text2 = text + directorySeparatorChar;
			if (!Directory.Exists(text2))
			{
				return;
			}
			if (IsLink(File.GetAttributes(text2)))
			{
				log.LogWarning((object)"Skipping plugin selection because the plugin directory is a link.");
				return;
			}
			Dictionary<string, bool> selection = PluginSelection.Read();
			LocalMod[] array = FindMods(text2).OrderBy<LocalMod, string>((LocalMod mod) => mod.Name, StringComparer.CurrentCultureIgnoreCase).ToArray();
			LocalMod[] array2 = array;
			for (int num = 0; num < array2.Length; num++)
			{
				ApplySelection(array2[num], selection);
			}
			Plugins = array;
			CatalogueReady = true;
			log.LogInfo((object)("Local plugin catalogue ready: " + array.Length + " files."));
		}
		catch (Exception ex)
		{
			log.LogError((object)("Could not prepare the plugin selection: " + ex));
		}
	}

	private static IEnumerable<LocalMod> FindMods(string root)
	{
		Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
		foreach (string item in EnumeratePluginFiles(root))
		{
			bool num = item.EndsWith(".disabled", StringComparison.OrdinalIgnoreCase);
			string key = (num ? item.Substring(0, item.Length - ".disabled".Length) : item);
			if (!num || !dictionary.ContainsKey(key))
			{
				dictionary[key] = item;
			}
		}
		foreach (KeyValuePair<string, string> item2 in dictionary)
		{
			LocalMod localMod = ReadMod(root, item2.Key, item2.Value);
			if (localMod != null)
			{
				yield return localMod;
			}
		}
	}

	private static IEnumerable<string> EnumeratePluginFiles(string root)
	{
		Stack<string> directories = new Stack<string>();
		directories.Push(root);
		while (directories.Count != 0)
		{
			string[] fileSystemEntries = Directory.GetFileSystemEntries(directories.Pop());
			foreach (string text in fileSystemEntries)
			{
				FileAttributes attributes = File.GetAttributes(text);
				if (!IsLink(attributes) && text.StartsWith(root, StringComparison.OrdinalIgnoreCase))
				{
					if ((attributes & FileAttributes.Directory) != FileAttributes.None)
					{
						directories.Push(text);
					}
					else if (text.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) || text.EndsWith(".dll.disabled", StringComparison.OrdinalIgnoreCase))
					{
						yield return text;
					}
				}
			}
		}
	}

	private static bool IsLink(FileAttributes attributes)
	{
		return (attributes & FileAttributes.ReparsePoint) != 0;
	}

	private static LocalMod ReadMod(string root, string activePath, string file)
	{
		try
		{
			ModuleDefinition val = ModuleDefinition.ReadModule(file);
			try
			{
				CustomAttribute[] array = (from attribute in ((IEnumerable<TypeDefinition>)val.Types).SelectMany((TypeDefinition type) => (IEnumerable<CustomAttribute>)type.CustomAttributes)
					where ((MemberReference)attribute.AttributeType).FullName == "BepInEx.BepInPlugin"
					select attribute).ToArray();
				if (array.Length == 0)
				{
					return null;
				}
				string key = activePath.Substring(root.Length).Replace(Path.DirectorySeparatorChar, '/');
				string[] source = array.Select(delegate(CustomAttribute attribute)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					CustomAttributeArgument val2 = attribute.ConstructorArguments[0];
					return (string)((CustomAttributeArgument)(ref val2)).Value;
				}).ToArray();
				string name = string.Join(" / ", array.Select(delegate(CustomAttribute attribute)
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_002c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0031: Unknown result type (might be due to invalid IL or missing references)
					CustomAttributeArgument val2 = attribute.ConstructorArguments[1];
					string? obj = ((CustomAttributeArgument)(ref val2)).Value?.ToString();
					val2 = attribute.ConstructorArguments[2];
					return obj + " " + ((CustomAttributeArgument)(ref val2)).Value;
				}).ToArray());
				return new LocalMod(key, activePath, name, source.Contains("local.badnorth.mod-menu"), source.Contains("local.badnorth.save-compatibility"), !file.EndsWith(".disabled", StringComparison.OrdinalIgnoreCase), File.Exists(activePath) && File.Exists(activePath + ".disabled"));
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}
		catch (BadImageFormatException)
		{
			return null;
		}
		catch (Exception ex2)
		{
			log.LogWarning((object)("Could not inspect " + Path.GetFileName(file) + ": " + ex2.Message));
			return null;
		}
	}

	private static void ApplySelection(LocalMod mod, Dictionary<string, bool> selection)
	{
		if (mod.ConflictingFiles || !selection.TryGetValue(mod.Key, out var value) || mod.IsEnabled == value || mod.IsMenu)
		{
			return;
		}
		string text = mod.ActivePath + ".disabled";
		string sourceFileName = (value ? text : mod.ActivePath);
		string destFileName = (value ? mod.ActivePath : text);
		try
		{
			File.Move(sourceFileName, destFileName);
			mod.IsEnabled = value;
			log.LogInfo((object)((value ? "Enabled for this launch: " : "Disabled for this launch: ") + mod.Key));
		}
		catch (Exception ex)
		{
			mod.ChangeFailed = true;
			log.LogWarning((object)("Could not change " + mod.Key + ": " + ex.Message));
		}
	}
}
public sealed class LocalMod
{
	public string Key { get; }

	public string ActivePath { get; }

	public string Name { get; }

	public bool IsMenu { get; }

	public bool IsSaveCompatibility { get; }

	public bool IsEnabled { get; internal set; }

	public bool ConflictingFiles { get; }

	public bool ChangeFailed { get; internal set; }

	internal LocalMod(string key, string activePath, string name, bool isMenu, bool isSaveCompatibility, bool isEnabled, bool conflictingFiles)
	{
		Key = key;
		ActivePath = activePath;
		Name = name;
		IsMenu = isMenu;
		IsSaveCompatibility = isSaveCompatibility;
		IsEnabled = isEnabled;
		ConflictingFiles = conflictingFiles;
	}
}
public static class PluginSelection
{
	private static string SelectionPath => Path.Combine(Paths.ConfigPath, "local.badnorth.mod-menu.selection.txt");

	public static Dictionary<string, bool> Read()
	{
		Dictionary<string, bool> dictionary = new Dictionary<string, bool>(StringComparer.OrdinalIgnoreCase);
		if (!File.Exists(SelectionPath))
		{
			return dictionary;
		}
		string[] array = File.ReadAllLines(SelectionPath);
		foreach (string text in array)
		{
			if (text.Length >= 2 && (text[0] == '+' || text[0] == '-'))
			{
				dictionary[text.Substring(1)] = text[0] == '+';
			}
		}
		return dictionary;
	}

	public static void Save(Dictionary<string, bool> selection)
	{
		string selectionPath = SelectionPath;
		string text = selectionPath + "." + Guid.NewGuid().ToString("N") + ".tmp";
		try
		{
			string[] contents = (from entry in selection.OrderBy<KeyValuePair<string, bool>, string>((KeyValuePair<string, bool> entry) => entry.Key, StringComparer.OrdinalIgnoreCase)
				select (entry.Value ? "+" : "-") + entry.Key).ToArray();
			File.WriteAllLines(text, contents);
			if (File.Exists(selectionPath))
			{
				File.Replace(text, selectionPath, null);
			}
			else
			{
				File.Move(text, selectionPath);
			}
		}
		finally
		{
			if (File.Exists(text))
			{
				File.Delete(text);
			}
		}
	}
}