Decompiled source of MasterList v1.0.2

MasterList.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SOD.Common;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MasterList")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+99b7a0c06c94c87a0eec359fe10f514d4099d038")]
[assembly: AssemblyProduct("MasterList")]
[assembly: AssemblyTitle("MasterList")]
[assembly: AssemblyVersion("1.0.2.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 MasterList
{
	[HarmonyPatch(typeof(DatabaseApp), "OnSetup")]
	internal static class DatabaseApp_OnSetup_Patch
	{
		private static readonly List<Delegate> KeepAlive = new List<Delegate>();

		[HarmonyPostfix]
		private static void Postfix(DatabaseApp __instance)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			try
			{
				Inject(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("MLIST button injection failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void Inject(DatabaseApp app)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Expected O, but got Unknown
			if (Plugin.GovernmentDatabaseOnly.Value && (int)app.citizenPool != 0)
			{
				return;
			}
			RectTransform component = ((Component)app).GetComponent<RectTransform>();
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Log.LogWarning((object)"DatabaseApp has no RectTransform root; cannot add MLIST button.");
			}
			else
			{
				if ((Object)(object)((Transform)component).Find("MasterListButton") != (Object)null)
				{
					return;
				}
				Transform val = ((Transform)component).Find("Exit");
				RectTransform val2 = (((Object)(object)val != (Object)null) ? ((Il2CppObjectBase)val).TryCast<RectTransform>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					Plugin.Log.LogWarning((object)"Title-bar Exit button not found; cannot add MLIST button.");
					return;
				}
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, (Transform)(object)component);
				((Object)val3).name = "MasterListButton";
				val3.SetActive(true);
				RectTransform component2 = val3.GetComponent<RectTransform>();
				Vector2 anchoredPosition = val2.anchoredPosition;
				Rect rect = val2.rect;
				component2.anchoredPosition = anchoredPosition + new Vector2(0f - (((Rect)(ref rect)).width + 0.01f), 0f);
				foreach (ComputerAutoTextController componentsInChild in val3.GetComponentsInChildren<ComputerAutoTextController>(true))
				{
					Object.DestroyImmediate((Object)(object)componentsInChild);
				}
				TextMeshProUGUI componentInChildren = ((Component)val2).GetComponentInChildren<TextMeshProUGUI>(true);
				float num = (((Object)(object)componentInChildren != (Object)null) ? ((TMP_Text)componentInChildren).fontSize : 0f);
				if (num < 0.01f || num > 1f)
				{
					num = 0.045f;
				}
				foreach (TextMeshProUGUI componentsInChild2 in val3.GetComponentsInChildren<TextMeshProUGUI>(true))
				{
					((TMP_Text)componentsInChild2).text = "MLIST";
					((TMP_Text)componentsInChild2).enableAutoSizing = false;
					((TMP_Text)componentsInChild2).enableWordWrapping = false;
					((TMP_Text)componentsInChild2).alignment = (TextAlignmentOptions)514;
					((TMP_Text)componentsInChild2).overflowMode = (TextOverflowModes)0;
					((TMP_Text)componentsInChild2).fontSize = num;
				}
				Button componentInChildren2 = val3.GetComponentInChildren<Button>(true);
				if ((Object)(object)componentInChildren2 == (Object)null)
				{
					Plugin.Log.LogWarning((object)"Cloned Exit button has no UI.Button; cannot wire MLIST.");
					Object.Destroy((Object)(object)val3);
					return;
				}
				componentInChildren2.onClick = new ButtonClickedEvent();
				Action action = delegate
				{
					RevealService.Run(app);
				};
				KeepAlive.Add(action);
				((UnityEvent)componentInChildren2.onClick).AddListener(UnityAction.op_Implicit(action));
				Plugin.Log.LogInfo((object)"MLIST button injected into the Citizens Database title bar.");
			}
		}
	}
	[HarmonyPatch(typeof(InterfaceController), "NewGameMessage")]
	internal static class InterfaceController_NewGameMessage_Patch
	{
		[HarmonyPrefix]
		private static bool Prefix()
		{
			return !RevealService.SuppressGameMessages;
		}
	}
	[BepInPlugin("com.aloyradogan.masterlist", "MasterList", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> GovernmentDatabaseOnly;

		internal static ConfigEntry<string> RevealKeys;

		internal static ConfigEntry<bool> IncludeEverything;

		internal static ConfigEntry<bool> ShowMessage;

		internal static ConfigEntry<bool> PlaySound;

		public override void Load()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			GovernmentDatabaseOnly = ((BasePlugin)this).Config.Bind<bool>("General", "GovernmentDatabaseOnly", true, "Only add the MASTER LIST button to database apps that search ALL citizens (the City Hall Government Database). Set false to also add it to employee/resident database variants.");
			RevealKeys = ((BasePlugin)this).Config.Bind<string>("Reveal", "RevealKeys", "", "Comma-separated Evidence.DataKey names to reveal per citizen (e.g. 'photo,address,work,jobTitle,telephoneNumber'). Leave empty to mirror exactly what reading a vanilla printed citizen record reveals.");
			IncludeEverything = ((BasePlugin)this).Config.Bind<bool>("Reveal", "IncludeEverything", true, "Reveal EVERY data key the game tracks for every citizen (fingerprints, blood type, etc.). Overrides RevealKeys. Set false to mirror only what a vanilla printed record reveals (or a custom RevealKeys list).");
			ShowMessage = ((BasePlugin)this).Config.Bind<bool>("Feedback", "ShowMessage", true, "Show an in-game message after the master list is compiled.");
			PlaySound = ((BasePlugin)this).Config.Bind<bool>("Feedback", "PlaySound", true, "Play the cruncher print sound when the master list is compiled.");
			new Harmony("com.aloyradogan.masterlist").PatchAll(Assembly.GetExecutingAssembly());
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("MasterList");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.2");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
			}
			log.LogInfo(val);
		}
	}
	internal static class RevealService
	{
		internal static bool SuppressGameMessages;

		public static void Run(DatabaseApp app)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			try
			{
				RunInternal(app);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Master list reveal failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void RunInternal(DatabaseApp app)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			List<DataKey> list = ResolveKeys();
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Revealing keys: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(string.Join(", ", list));
			}
			log.LogInfo(val);
			Stopwatch stopwatch = Stopwatch.StartNew();
			int num = 0;
			int num2 = 0;
			SuppressGameMessages = true;
			try
			{
				Enumerator<Citizen> enumerator = CityData.Instance.citizenDirectory.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Citizen current = enumerator.Current;
					if ((Object)(object)current == (Object)null || ((Actor)current).isPlayer)
					{
						continue;
					}
					try
					{
						EvidenceWitness evidenceEntry = ((Actor)current).evidenceEntry;
						if (evidenceEntry == null)
						{
							continue;
						}
						foreach (DataKey item in list)
						{
							if ((int)item != 0)
							{
								((Evidence)evidenceEntry).MergeDataKeys((DataKey)0, item);
							}
						}
						num++;
					}
					catch (Exception)
					{
						num2++;
					}
				}
			}
			finally
			{
				SuppressGameMessages = false;
			}
			stopwatch.Stop();
			ManualLogSource log2 = Plugin.Log;
			val = new BepInExInfoLogInterpolatedStringHandler(60, 4, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Master list: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" citizens revealed (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" failed) with ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list.Count);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" keys in ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<long>(stopwatch.ElapsedMilliseconds);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ms.");
			}
			log2.LogInfo(val);
			ComputerController val2 = (((Object)(object)app != (Object)null) ? ((CruncherAppContent)app).controller : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.SetTimedLoading(Toolbox.Instance.Rand(0.5f, 1f, false), 0.33f);
			}
			if (Plugin.PlaySound.Value && (Object)(object)val2 != (Object)null && (Object)(object)val2.ic != (Object)null && val2.ic.interactable != null)
			{
				AudioController.Instance.PlayWorldOneShot(AudioControls.Instance.computerPrint, (Actor)(object)Player.Instance, val2.ic.interactable.node, val2.ic.interactable.wPos, (Interactable)null, (List<FMODParam>)null, 1f, (List<NewNode>)null, false, (SoundMaterialOverride)null, false);
			}
			if (Plugin.ShowMessage.Value)
			{
				Lib.GameMessage.Broadcast($"MASTER LIST: {num} citizen records revealed", (GameMessageType)0, (Icon)21, (Color?)null, 0f);
			}
		}

		private static List<DataKey> ResolveKeys()
		{
			//IL_0025: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.IncludeEverything.Value)
			{
				List<DataKey> list = new List<DataKey>();
				Enumerator<DataKey> enumerator = Toolbox.Instance.allDataKeys.GetEnumerator();
				while (enumerator.MoveNext())
				{
					DataKey current = enumerator.Current;
					list.Add(current);
				}
				if (list.Count > 0)
				{
					return list;
				}
			}
			string value = Plugin.RevealKeys.Value;
			if (!string.IsNullOrWhiteSpace(value))
			{
				List<DataKey> list2 = new List<DataKey>();
				string[] array = value.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
				bool flag = default(bool);
				foreach (string text in array)
				{
					if (Enum.TryParse<DataKey>(text, ignoreCase: true, out DataKey result))
					{
						list2.Add(result);
						continue;
					}
					ManualLogSource log = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Unknown DataKey '");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' in RevealKeys ignored.");
					}
					log.LogWarning(val);
				}
				if (list2.Count > 0)
				{
					return list2;
				}
			}
			Dictionary<string, EvidencePreset> evidencePresetDictionary = Toolbox.Instance.evidencePresetDictionary;
			if (evidencePresetDictionary != null && evidencePresetDictionary.ContainsKey("printedcitizenfile"))
			{
				EvidencePreset val2 = evidencePresetDictionary["printedcitizenfile"];
				if ((SoCustomComparison)(object)val2 != (SoCustomComparison)null && val2.keyMergeOnDiscovery != null)
				{
					HashSet<DataKey> hashSet = new HashSet<DataKey>();
					Enumerator<MergeKeysSetup> enumerator2 = val2.keyMergeOnDiscovery.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						Enumerator<DataKey> enumerator = enumerator2.Current.mergeKeys.GetEnumerator();
						while (enumerator.MoveNext())
						{
							DataKey current2 = enumerator.Current;
							hashSet.Add(current2);
						}
					}
					if (hashSet.Count > 0)
					{
						return new List<DataKey>(hashSet);
					}
				}
			}
			Plugin.Log.LogWarning((object)"printedcitizenfile preset unavailable; using built-in fallback key set.");
			return new List<DataKey>
			{
				(DataKey)1,
				(DataKey)14,
				(DataKey)33,
				(DataKey)20,
				(DataKey)15,
				(DataKey)17,
				(DataKey)16,
				(DataKey)21,
				(DataKey)5,
				(DataKey)6,
				(DataKey)9,
				(DataKey)10,
				(DataKey)19,
				(DataKey)13,
				(DataKey)11,
				(DataKey)12,
				(DataKey)2
			};
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.aloyradogan.masterlist";

		public const string PLUGIN_NAME = "MasterList";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}