Decompiled source of Mod Doctor v1.0.1

Mods/WoodStudios.ModDoctor.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.UI;
using MelonLoader;
using MelonLoader.Properties;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using ModDoctor;
using S1API.PhoneApp;
using S1API.UI;
using S1API.Utils;
using Schedule2.Game;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(Main), "Mod Doctor", "1.0.0", "Wood Studios", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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 Schedule2
{
	internal static class S2Ui
	{
		private static Font _font;

		internal static (GameObject, Button, Text) ButtonWithLabel(string name, string label, Transform parent, Color bgColor, float Width, float Height)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.AddComponent<RectTransform>().sizeDelta = new Vector2(Width, Height);
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = bgColor;
			Button val3 = val.AddComponent<Button>();
			((Selectable)val3).targetGraphic = (Graphic)(object)val2;
			GameObject val4 = new GameObject("Label");
			val4.transform.SetParent(val.transform, false);
			RectTransform obj = val4.AddComponent<RectTransform>();
			obj.anchorMin = Vector2.zero;
			obj.anchorMax = Vector2.one;
			obj.offsetMin = Vector2.zero;
			obj.offsetMax = Vector2.zero;
			Text val5 = val4.AddComponent<Text>();
			val5.text = label;
			val5.alignment = (TextAnchor)4;
			val5.fontSize = 16;
			val5.fontStyle = (FontStyle)1;
			((Graphic)val5).color = Color.white;
			if ((Object)(object)_font == (Object)null)
			{
				_font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			}
			val5.font = _font;
			return (val, val3, val5);
		}
	}
}
namespace Schedule2.Game
{
	internal static class AppUi
	{
		public static Text Body(Transform parent, float top, float height, int size = 15)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			Text obj = UIFactory.Text("Body", "", parent, size, (TextAnchor)0, (FontStyle)0);
			obj.supportRichText = true;
			obj.horizontalOverflow = (HorizontalWrapMode)0;
			obj.verticalOverflow = (VerticalWrapMode)0;
			RectTransform rectTransform = ((Graphic)obj).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.sizeDelta = new Vector2(-32f, height);
			rectTransform.anchoredPosition = new Vector2(0f, 0f - top);
			return obj;
		}

		public static Text Title(Transform parent, string s)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			Text obj = UIFactory.Text("Title", s, parent, 26, (TextAnchor)1, (FontStyle)1);
			RectTransform rectTransform = ((Graphic)obj).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = new Vector2(1f, 1f);
			rectTransform.pivot = new Vector2(0.5f, 1f);
			rectTransform.sizeDelta = new Vector2(0f, 40f);
			rectTransform.anchoredPosition = new Vector2(0f, -8f);
			((Graphic)obj).color = new Color(0.45f, 0.83f, 0.38f);
			return obj;
		}

		public static Button Btn(Transform parent, string label, float x, float y, float w, Color c, Action onClick)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			(GameObject, Button, Text) tuple = S2Ui.ButtonWithLabel("Btn_" + label, label, parent, c, w, 34f);
			GameObject item = tuple.Item1;
			Button item2 = tuple.Item2;
			RectTransform component = item.GetComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0f, 0f);
			component.anchoredPosition = new Vector2(x, y);
			EventHelper.AddListener((Action)delegate
			{
				try
				{
					onClick();
				}
				catch (Exception ex)
				{
					MelonLogger.Warning(label + ": " + ex.Message);
				}
			}, (UnityEvent)(object)item2.onClick);
			return item2;
		}

		public static Sprite Icon(string letters, Color bg)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = (float)j - 63.5f;
					float num2 = (float)i - 63.5f;
					bool flag = Mathf.Abs(Mathf.Sqrt(num * num + num2 * num2) - 50f) < 5f;
					array[i * 128 + j] = (Color)(flag ? new Color(0.92f, 0.92f, 0.92f) : bg);
				}
			}
			val.SetPixels(Il2CppStructArray<Color>.op_Implicit(array));
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f));
		}
	}
}
namespace ModDoctor
{
	internal sealed class Finding
	{
		public int Level;

		public string Title;

		public string Fix;
	}
	public sealed class Main : MelonMod
	{
		internal static readonly List<Finding> Found = new List<Finding>();

		internal static DateTime CheckedAt;

		private static float _recheckAt = -1f;

		private static readonly (string pack, string packName, string[] inside)[] Packs = new(string, string, string[])[2]
		{
			("HoldTheFort", "Fortify Your Base", new string[8] { "WoodStudios.GameRoom", "WoodStudios.PlayerPiano", "WoodStudios.HomeBar", "WoodStudios.HomeGym", "WoodStudios.FoodTruck", "WoodStudios.NeonSigns", "WoodStudios.SecurityCameras", "WoodStudios.PerformanceBoost" }),
			("WoodStudios.DrugPack", "Drug Pack", new string[10] { "WoodStudios.AngelDustLab", "WoodStudios.DmtLab", "WoodStudios.EdiblesKitchen", "WoodStudios.HomeBrew", "WoodStudios.LsdLab", "WoodStudios.PillPress", "WoodStudios.PoppyLab", "WoodStudios.PreRollShop", "WoodStudios.TobaccoBarn", "WoodStudios.VapeLab" })
		};

		private static readonly (string mod, string needs, string needsName)[] Needs = new(string, string, string)[1] { ("WoodStudios.EndOfTheWorld", "HoldTheFort", "Fortify Your Base") };

		private static readonly string[] Noise = new string[7] { "Failed to create agent", "SteamAPI_Init", "Steam not initialized", "No platform user implementation", "Coroutine continue failure", "The referenced script", "BoxColliders does not support negative" };

		internal static string ReportPath => Path.Combine(MelonEnvironment.UserDataDirectory, "WoodStudios", "ModDoctor.txt");

		public override void OnLateInitializeMelon()
		{
			Run();
			((MelonBase)this).LoggerInstance.Msg($"Mod Doctor: {Found.Count((Finding f) => f.Level == 2)} problem(s), {Found.Count((Finding f) => f.Level == 1)} warning(s). Full report: UserData/WoodStudios/ModDoctor.txt (also in the Mod Doctor phone app).");
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "Main")
			{
				_recheckAt = Time.unscaledTime + 60f;
			}
		}

		public override void OnUpdate()
		{
			if (_recheckAt > 0f && Time.unscaledTime >= _recheckAt)
			{
				_recheckAt = -1f;
				Run();
			}
			try
			{
				DoctorApp.Tick();
			}
			catch
			{
			}
		}

		internal static void Run()
		{
			Found.Clear();
			CheckedAt = DateTime.Now;
			string modsDirectory = MelonEnvironment.ModsDirectory;
			string dir = Path.Combine(MelonEnvironment.GameRootDirectory, "Plugins");
			string[] array = SafeFiles(modsDirectory, "*.dll", SearchOption.TopDirectoryOnly);
			Dictionary<string, List<string>> names = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
			string[] array2 = array;
			foreach (string path in array2)
			{
				string key = AsmName(path) ?? Path.GetFileNameWithoutExtension(path);
				if (!names.TryGetValue(key, out var value))
				{
					value = (names[key] = new List<string>());
				}
				value.Add(Path.GetFileName(path));
			}
			string text = "?";
			try
			{
				text = BuildInfo.Version;
			}
			catch
			{
			}
			if (Version.TryParse(Regex.Match(text, "\\d+\\.\\d+\\.\\d+").Value, out Version result) && result < new Version(0, 7, 0))
			{
				Add(2, "MelonLoader " + text + " is too old", "Install MelonLoader 0.7.0 or newer (the Schedule I mods are built for it).");
			}
			if (!names.Keys.Any((string k) => k.StartsWith("S1API", StringComparison.OrdinalIgnoreCase)) && !MelonBase.RegisteredMelons.Any(delegate(MelonBase m)
			{
				MelonInfoAttribute info = m.Info;
				return info != null && info.Name?.IndexOf("S1API", StringComparison.OrdinalIgnoreCase) >= 0;
			}))
			{
				Add(2, "S1API is missing", "Almost every Schedule I mod needs S1API. Download S1API (the Bars fork) and put its DLL in your Mods folder.");
			}
			if (names.Keys.Count((string k) => k.StartsWith("S1API", StringComparison.OrdinalIgnoreCase)) > 1)
			{
				Add(2, "More than one S1API", "Keep one S1API DLL in Mods and delete the others: " + string.Join(", ", names.Where((KeyValuePair<string, List<string>> k) => k.Key.StartsWith("S1API", StringComparison.OrdinalIgnoreCase)).SelectMany((KeyValuePair<string, List<string>> k) => k.Value)) + ".");
			}
			(string, string, string[])[] packs = Packs;
			for (int i = 0; i < packs.Length; i++)
			{
				var (asm, text2, array3) = packs[i];
				if (!Has(asm))
				{
					continue;
				}
				array2 = array3;
				foreach (string text3 in array2)
				{
					if (Has(text3))
					{
						Add(2, Pretty(text3) + " is already in " + text2, $"Delete {string.Join(", ", names[text3])} from Mods. {text2} already has it, and having both doubles items in shops and causes errors.");
					}
				}
			}
			(string, string, string)[] needs = Needs;
			for (int i = 0; i < needs.Length; i++)
			{
				var (text4, asm2, text5) = needs[i];
				if (Has(text4) && !Has(asm2))
				{
					Add(2, Pretty(text4) + " needs " + text5, $"Install {text5} too, or remove {string.Join(", ", names[text4])}.");
				}
			}
			foreach (KeyValuePair<string, List<string>> item in names)
			{
				if (item.Value.Count > 1)
				{
					Add(2, $"{Pretty(item.Key)} is in Mods {item.Value.Count} times", "Keep the newest one and delete the rest: " + string.Join(", ", item.Value) + ".");
				}
			}
			array2 = array;
			foreach (string path2 in array2)
			{
				if (Regex.IsMatch(Path.GetFileNameWithoutExtension(path2), "\\(\\d+\\)$|[ _-]copy$|[ _-]Copy \\d+$|\\.dll$", RegexOptions.IgnoreCase))
				{
					Add(1, Path.GetFileName(path2) + " looks like a duplicate download", "If you already have this mod, delete this file. Browsers add \"(1)\" when you download a file twice.");
				}
			}
			foreach (string item2 in from p in SafeFiles(modsDirectory, "*.*", SearchOption.TopDirectoryOnly)
				where p.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) || p.EndsWith(".rar", StringComparison.OrdinalIgnoreCase) || p.EndsWith(".7z", StringComparison.OrdinalIgnoreCase)
				select p)
			{
				Add(2, Path.GetFileName(item2) + " is still zipped", "Mods can't load from a zip. Open it and put the .dll files straight into Mods, then delete the zip.");
			}
			array2 = SafeDirs(modsDirectory);
			foreach (string text6 in array2)
			{
				string fileName = Path.GetFileName(text6);
				if (!fileName.Equals("packs", StringComparison.OrdinalIgnoreCase) && !fileName.StartsWith("."))
				{
					string[] array4 = SafeFiles(text6, "*.dll", SearchOption.AllDirectories);
					if (array4.Length != 0)
					{
						Add(2, "DLLs inside Mods\\" + fileName + " won't load", "MelonLoader only loads DLLs sitting directly in Mods. Move " + string.Join(", ", array4.Take(4).Select(Path.GetFileName)) + ((array4.Length > 4) ? " and others" : "") + " up into Mods.");
					}
				}
			}
			array2 = SafeFiles(MelonEnvironment.GameRootDirectory, "*.dll", SearchOption.TopDirectoryOnly);
			foreach (string path3 in array2)
			{
				string text7 = AsmName(path3) ?? "";
				if (text7.StartsWith("WoodStudios.") || text7 == "HoldTheFort" || text7.StartsWith("S1API"))
				{
					Add(2, Path.GetFileName(path3) + " is in the game folder, not Mods", "Move it into the Mods folder (Schedule I\\Mods).");
				}
			}
			array2 = SafeFiles(dir, "*.dll", SearchOption.TopDirectoryOnly);
			foreach (string path4 in array2)
			{
				string text8 = AsmName(path4) ?? "";
				if (text8.StartsWith("WoodStudios.") || text8 == "HoldTheFort")
				{
					Add(2, Path.GetFileName(path4) + " is in Plugins", "Wood Studios mods go in Mods, not Plugins. Move it.");
				}
			}
			ReadLog(out var failed, out var spam);
			foreach (var item3 in failed)
			{
				Add(2, "Failed to load: " + item3.Item1, item3.Item2);
			}
			foreach (var item4 in spam)
			{
				Add(1, item4.Item1, item4.Item2);
			}
			if (Found.Count == 0)
			{
				Add(0, "No problems found", $"{array.Length} mod file(s) checked. If something still isn't working, send UserData\\WoodStudios\\ModDoctor.txt with your bug report.");
			}
			Found.Sort((Finding a, Finding b) => b.Level.CompareTo(a.Level));
			Write(array, names, text);
			bool Has(string key2)
			{
				return names.ContainsKey(key2);
			}
		}

		private static void ReadLog(out List<(string, string)> failed, out List<(string, string)> spam)
		{
			failed = new List<(string, string)>();
			spam = new List<(string, string)>();
			try
			{
				FileInfo fileInfo = (from f in new DirectoryInfo(Path.Combine(MelonEnvironment.MelonLoaderDirectory, "Logs")).GetFiles("*.log")
					orderby f.LastWriteTimeUtc descending
					select f).FirstOrDefault();
				string text;
				if (fileInfo == null)
				{
					string path = Path.Combine(MelonEnvironment.MelonLoaderDirectory, "Latest.log");
					if (!File.Exists(path))
					{
						return;
					}
					text = ReadShared(path);
				}
				else
				{
					text = ReadShared(fileInfo.FullName);
				}
				string[] array = text.Split('\n');
				HashSet<string> hashSet = new HashSet<string>();
				string[] array2 = array;
				for (int num = 0; num < array2.Length; num++)
				{
					string input = array2[num].Trim();
					Match match = Regex.Match(input, "Failed to load (?:Melon|Assembly|Mod)[^:]*[: ]+(.*)", RegexOptions.IgnoreCase);
					if (!match.Success)
					{
						match = Regex.Match(input, "Could not load file or assembly '([^',]+)", RegexOptions.IgnoreCase);
					}
					if (match.Success && hashSet.Add(match.Groups[1].Value))
					{
						failed.Add((Short(match.Groups[1].Value, 60), "The mod is probably built for a different game or MelonLoader version, or needs another mod. Update it, or check its page for what it needs."));
					}
					Match match2 = Regex.Match(input, "\\[([^\\]]+)\\].*(?:is not compatible|Incompatible|requires a newer)", RegexOptions.IgnoreCase);
					if (match2.Success && hashSet.Add("inc" + match2.Groups[1].Value))
					{
						failed.Add((match2.Groups[1].Value, "MelonLoader says it isn't compatible with this game version. Update it."));
					}
				}
				Dictionary<string, (int, string, string)> dictionary = new Dictionary<string, (int, string, string)>();
				array2 = array;
				foreach (string text2 in array2)
				{
					string l = text2.Trim();
					bool num2 = l.Contains("[ERROR]") || l.Contains("[Unity Error]") || l.Contains("Exception");
					bool flag = l.Contains("[WARNING]") || l.Contains("[Unity Warning]");
					if ((num2 || flag) && !Noise.Any((string z) => l.Contains(z)))
					{
						string text3 = Regex.Replace(l, "^\\[[0-9:.]+\\]\\s*", "");
						string value = Regex.Match(text3, "^\\[([^\\]]+)\\]").Groups[1].Value;
						string key = Regex.Replace(text3, "[-0-9.,]+", "#");
						dictionary[key] = (dictionary.TryGetValue(key, out var value2) ? (value2.Item1 + 1, value2.Item2, value2.Item3) : (1, value, text3));
					}
				}
				foreach (KeyValuePair<string, (int, string, string)> item in dictionary.OrderByDescending<KeyValuePair<string, (int, string, string)>, int>((KeyValuePair<string, (int n, string mod, string sample)> k) => k.Value.n).Take(5))
				{
					if (item.Value.Item1 >= 50)
					{
						string value3 = ((string.IsNullOrEmpty(item.Value.Item2) || item.Value.Item2.StartsWith("Unity") || item.Value.Item2 == "ERROR" || item.Value.Item2 == "WARNING") ? "the game or a mod" : item.Value.Item2);
						spam.Add(($"Repeated {item.Value.Item1} times ({value3})", "\"" + Short(item.Value.Item3, 110) + "\". A message this often can slow the game. If it names a mod, update or remove that mod."));
						continue;
					}
					break;
				}
			}
			catch
			{
			}
		}

		private static string ReadShared(string path)
		{
			using FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
			using StreamReader streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}

		private static void Write(string[] dlls, Dictionary<string, List<string>> names, string ml)
		{
			try
			{
				Directory.CreateDirectory(Path.GetDirectoryName(ReportPath));
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.AppendLine("Mod Doctor report (Wood Studios)  " + CheckedAt.ToString("yyyy-MM-dd HH:mm"));
				stringBuilder.AppendLine("MelonLoader " + ml + "   Mods folder: " + MelonEnvironment.ModsDirectory);
				stringBuilder.AppendLine();
				foreach (Finding item in Found)
				{
					stringBuilder.AppendLine(((item.Level == 2) ? "[PROBLEM] " : ((item.Level == 1) ? "[WARNING] " : "[OK] ")) + item.Title + Environment.NewLine + "          " + item.Fix);
				}
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("Mods loaded (" + MelonBase.RegisteredMelons.Count() + "):");
				foreach (MelonBase registeredMelon in MelonBase.RegisteredMelons)
				{
					try
					{
						stringBuilder.AppendLine("  " + registeredMelon.Info.Name + " " + registeredMelon.Info.Version + " by " + registeredMelon.Info.Author);
					}
					catch
					{
					}
				}
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("Files in Mods (" + dlls.Length + "):");
				foreach (KeyValuePair<string, List<string>> item2 in names.OrderBy((KeyValuePair<string, List<string>> k) => k.Key))
				{
					stringBuilder.AppendLine("  " + string.Join(", ", item2.Value) + ((item2.Value.Count == 1 && !item2.Value[0].StartsWith(item2.Key, StringComparison.OrdinalIgnoreCase)) ? ("   (" + item2.Key + ")") : ""));
				}
				File.WriteAllText(ReportPath, stringBuilder.ToString());
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Mod Doctor: couldn't write the report (" + ex.Message + ").");
			}
		}

		private static void Add(int level, string title, string fix)
		{
			Found.Add(new Finding
			{
				Level = level,
				Title = title,
				Fix = fix
			});
		}

		private static string Short(string s, int n)
		{
			if (s != null)
			{
				if (s.Length > n)
				{
					return s.Substring(0, n - 3) + "...";
				}
				return s;
			}
			return "";
		}

		private static string Pretty(string asm)
		{
			return Regex.Replace(asm.Replace("WoodStudios.", ""), "(?<=[a-z])(?=[A-Z])", " ");
		}

		private static string AsmName(string path)
		{
			try
			{
				return AssemblyName.GetAssemblyName(path).Name;
			}
			catch
			{
				return null;
			}
		}

		private static string[] SafeFiles(string dir, string pat, SearchOption o)
		{
			try
			{
				return Directory.Exists(dir) ? Directory.GetFiles(dir, pat, o) : new string[0];
			}
			catch
			{
				return new string[0];
			}
		}

		private static string[] SafeDirs(string dir)
		{
			try
			{
				return Directory.Exists(dir) ? Directory.GetDirectories(dir) : new string[0];
			}
			catch
			{
				return new string[0];
			}
		}
	}
	public sealed class DoctorApp : PhoneApp
	{
		private static Sprite _icon;

		private Text _body;

		private int _page;

		private float _next;

		internal static DoctorApp Instance;

		private const int PerPage = 4;

		protected override string AppName => "WoodStudios_ModDoctor";

		protected override string AppTitle => "Mod Doctor";

		protected override string IconLabel => "Mod Doctor";

		protected override string IconFileName => "WoodStudios_ModDoctor.png";

		protected override Sprite IconSprite
		{
			get
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				if (!((Object)(object)_icon != (Object)null))
				{
					return _icon = AppUi.Icon("MD", new Color(0.13f, 0.5f, 0.42f));
				}
				return _icon;
			}
		}

		protected override void OnCreatedUI(GameObject container)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			GameObject val = UIFactory.Panel("ModDoctorPanel", container.transform, new Color(0.06f, 0.06f, 0.08f), (Vector2?)null, (Vector2?)null, true);
			AppUi.Title(val.transform, "MOD DOCTOR");
			_body = AppUi.Body(val.transform, 56f, 560f, 22);
			Color c = default(Color);
			((Color)(ref c))..ctor(0.25f, 0.25f, 0.28f);
			Color c2 = default(Color);
			((Color)(ref c2))..ctor(0.15f, 0.45f, 0.2f);
			AppUi.Btn(val.transform, "< Back", 16f, 16f, 160f, c, delegate
			{
				_page = Mathf.Max(0, _page - 1);
				Fill();
			});
			AppUi.Btn(val.transform, "More >", 186f, 16f, 160f, c, delegate
			{
				int num = Mathf.Max(1, (Main.Found.Count + 4 - 1) / 4);
				_page = Mathf.Min(num - 1, _page + 1);
				Fill();
			});
			AppUi.Btn(val.transform, "Check again", 356f, 16f, 200f, c2, delegate
			{
				Main.Run();
				_page = 0;
				Fill();
			});
			Fill();
		}

		internal static string DevOpen()
		{
			try
			{
				Singleton<GameplayMenu>.Instance.Open();
				DoctorApp instance = Instance;
				if (instance != null)
				{
					((PhoneApp)instance).OpenApp();
				}
				return "open";
			}
			catch (Exception ex)
			{
				return ex.Message;
			}
		}

		internal static string DevClose()
		{
			try
			{
				DoctorApp instance = Instance;
				if (instance != null)
				{
					((PhoneApp)instance).CloseApp();
				}
				Singleton<GameplayMenu>.Instance.Close();
				return "closed";
			}
			catch (Exception ex)
			{
				return ex.Message;
			}
		}

		public static void Tick()
		{
			DoctorApp instance = Instance;
			if (instance == null || Time.unscaledTime < instance._next)
			{
				return;
			}
			instance._next = Time.unscaledTime + 2f;
			try
			{
				instance.Fill();
			}
			catch
			{
			}
		}

		private void Fill()
		{
			if ((Object)(object)_body == (Object)null)
			{
				return;
			}
			List<Finding> found = Main.Found;
			StringBuilder stringBuilder = new StringBuilder();
			int num = found.Count((Finding x) => x.Level == 2);
			int num2 = found.Count((Finding x) => x.Level == 1);
			stringBuilder.Append((num > 0) ? ("<color=#ff6050><b>" + num + " problem(s)</b></color>") : "<color=#9fd38a><b>No problems</b></color>");
			if (num2 > 0)
			{
				stringBuilder.Append("   <color=#f5bd45>" + num2 + " warning(s)</color>");
			}
			stringBuilder.Append("   <size=16><color=#8a8a8a>checked " + Main.CheckedAt.ToString("h:mm tt") + "</color></size>\n\n");
			int num3 = Mathf.Max(1, (found.Count + 4 - 1) / 4);
			_page = Mathf.Clamp(_page, 0, num3 - 1);
			foreach (Finding item in found.Skip(_page * 4).Take(4))
			{
				string text = ((item.Level == 2) ? "#ff6050" : ((item.Level == 1) ? "#f5bd45" : "#9fd38a"));
				stringBuilder.Append("<color=" + text + "><b>" + item.Title + "</b></color>\n<size=19>" + item.Fix + "</size>\n\n");
			}
			stringBuilder.Append("<size=16><color=#8a8a8a>Page " + (_page + 1) + " of " + num3 + ". Full report: UserData\\WoodStudios\\ModDoctor.txt</color></size>");
			_body.text = stringBuilder.ToString();
		}
	}
}