Decompiled source of Modlist v0.2.0

Silksong.Modlist.dll

Decompiled 3 weeks 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;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GlobalEnums;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("Silksong.Modlist")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0+934cba7eb69c598c86eacd92f06e3aad1b81cb9d")]
[assembly: AssemblyProduct("Silksong.Modlist")]
[assembly: AssemblyTitle("Modlist")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/silksong-modding/Silksong.Modlist")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Silksong.Modlist
{
	public class ModListDraw : MonoBehaviour
	{
		private static readonly GUIStyle Style = new GUIStyle(GUIStyle.none);

		public string? drawString;

		private void Start()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			Style.normal.textColor = Color.white;
			Style.alignment = (TextAnchor)0;
			Style.padding = new RectOffset(5, 5, 5, 5);
			Style.fontSize = 15;
		}

		public void OnGUI()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			if (!((Object)(object)UIManager._instance == (Object)null))
			{
				bool flag = drawString != null;
				if (flag)
				{
					UIState uiState = UIManager.instance.uiState;
					bool flag2 = (((int)uiState == 1 || (int)uiState == 5) ? true : false);
					flag = flag2;
				}
				if (flag)
				{
					GUI.Label(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), drawString, Style);
				}
			}
		}
	}
	public static class Constants
	{
		public const string Guid = "org.silksong-modding.modlist";
	}
	[BepInPlugin("org.silksong-modding.modlist", "Modlist", "0.2.0")]
	public class ModlistPlugin : BaseUnityPlugin
	{
		private List<BepInPlugin> _loadedMinors = new List<BepInPlugin>();

		private List<BepInPlugin> _loadedMajors = new List<BepInPlugin>();

		private GameObject? _modListGO;

		private ModListDraw? _modListDraw;

		private Harmony _harmony;

		internal ConfigEntry<bool> HideMinorList;

		public const string Id = "org.silksong-modding.modlist";

		public static ModlistPlugin Instance { get; private set; }

		public static string Name => "Modlist";

		public static string Version => "0.2.0";

		private void Awake()
		{
			Instance = this;
			HideMinorList = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HideMinorList", false, "Whether to hide the modlist. Note that some mods will always display in the modlist for moderation reasons.");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Silksong version: 1.0.29315");
		}

		private void Start()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			_harmony = Harmony.CreateAndPatchAll(typeof(ModlistPatches), (string)null);
			_modListGO = new GameObject("Silksong.ModList");
			_modListDraw = _modListGO.AddComponent<ModListDraw>();
			Object.DontDestroyOnLoad((Object)(object)_modListGO);
			GenerateModList();
			HideMinorList.SettingChanged += delegate
			{
				GenerateModList();
			};
		}

		private void GenerateModList()
		{
			Dictionary<string, PluginInfo> pluginInfos = Chainloader.PluginInfos;
			((BaseUnityPlugin)this).Logger.LogDebug((object)$"Plugins: {pluginInfos.Count}");
			_loadedMinors.Clear();
			_loadedMajors.Clear();
			foreach (var (text2, val2) in pluginInfos)
			{
				if (val2 == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Plugin " + text2 + " has no PluginInfo, ignoring..."));
					continue;
				}
				Attribute? customAttribute = Attribute.GetCustomAttribute(((object)val2.Instance).GetType(), typeof(BepInPlugin));
				BepInPlugin val3 = (BepInPlugin)(object)((customAttribute is BepInPlugin) ? customAttribute : null);
				((BaseUnityPlugin)this).Logger.LogDebug((object)$"GUID {val3.GUID} w/ {val2.Dependencies.Count()} dependencies");
				if (val2.Dependencies.FirstOrDefault((Func<BepInDependency, bool>)((BepInDependency x) => ((Enum)x.Flags).HasFlag((Enum)(object)(DependencyFlags)1) && x.DependencyGUID == "org.silksong-modding.modlist")) != null)
				{
					_loadedMajors.Add(val3);
				}
				else
				{
					_loadedMinors.Add(val3);
				}
			}
			_modListDraw.drawString = GetListString();
		}

		private string GetListString()
		{
			List<string> majorList = GetMajorList();
			if (HideMinorList.Value)
			{
				if (majorList.Count == 0)
				{
					return "";
				}
				majorList.Add($"& {GetMinorList().Count} others");
			}
			else
			{
				majorList.AddRange(GetMinorList());
			}
			return string.Join("\n", majorList);
		}

		private List<string> GetMajorList()
		{
			return _loadedMajors.Select((BepInPlugin plugin) => $"{plugin.Name}: {plugin.Version}").ToList();
		}

		private List<string> GetMinorList()
		{
			return _loadedMinors.Select((BepInPlugin plugin) => $"{plugin.Name}: {plugin.Version}").ToList();
		}

		public int GetModCount()
		{
			return _loadedMajors.Count + _loadedMinors.Count;
		}

		public string GetMajorString()
		{
			return string.Join(", ", _loadedMajors.Select((BepInPlugin plugin) => plugin.Name ?? ""));
		}
	}
	public static class ModlistPatches
	{
		[HarmonyPatch(typeof(SetVersionNumber), "Start")]
		[HarmonyPostfix]
		public static void SetVersionNumber_Start(SetVersionNumber __instance)
		{
			string text = __instance.textUi.text;
			text += $" | {ModlistPlugin.Instance.GetModCount()} Mods\n{ModlistPlugin.Instance.GetMajorString()}";
			__instance.textUi.text = text;
		}
	}
}