Decompiled source of Citizen File Popups v1.0.0

plugins/CitizenFilePopup.dll

Decompiled 3 days 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;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using TMPro;
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("CitizenFilePopup")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyInformationalVersion("0.4.1+a34c99dab9922bf68b0075d56d3628d4234ad53b")]
[assembly: AssemblyProduct("CitizenFilePopup")]
[assembly: AssemblyTitle("CitizenFilePopup")]
[assembly: AssemblyVersion("0.4.1.0")]
[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.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]
	[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 CitizenFilePopup
{
	[BepInPlugin("sm3gm.citizenfilepopup", "Citizen File Popup", "1.0.0")]
	public class CitizenFilePopupPlugin : BasePlugin
	{
		internal const string VER = "1.0.0";

		internal static ManualLogSource LogSource;

		internal static ConfigEntry<int> MaxListed;

		public override void Load()
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			LogSource = ((BasePlugin)this).Log;
			MaxListed = ((BasePlugin)this).Config.Bind<int>("Popup", "MaxDetailsShown", 0, "How many new details to list before summarising the rest as '+N more'. 0 shows them all.");
			Harmony.CreateAndPatchAll(typeof(KeyMergeMessagePatch), (string)null);
			Harmony.CreateAndPatchAll(typeof(PopupExtraLine), (string)null);
			Harmony.CreateAndPatchAll(typeof(ForgetOnCityLoad), (string)null);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Citizen File Popup ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
			}
			log.LogInfo(val);
		}
	}
	[HarmonyPatch(typeof(GameMessageController), "Setup")]
	internal static class KeyMergeMessagePatch
	{
		internal static readonly Dictionary<string, HashSet<string>> Known = new Dictionary<string, HashSet<string>>();

		private static readonly HashSet<string> Hidden = new HashSet<string> { "name", "firstName", "surname", "initialedName", "initials", "firstNameInitial", "photo", "voice", "fingerprints" };

		private static readonly Dictionary<string, string> Labels = new Dictionary<string, string>
		{
			["photo"] = "photo",
			["fingerprints"] = "fingerprints",
			["code"] = "code",
			["voice"] = "voice",
			["height"] = "height",
			["heightEstimate"] = "height (estimate)",
			["build"] = "build",
			["age"] = "age",
			["ageGroup"] = "age group",
			["sex"] = "sex",
			["hair"] = "hair",
			["eyes"] = "eyes",
			["bloodType"] = "blood type",
			["shoeSize"] = "shoe size",
			["shoeSizeEstimate"] = "shoe size (estimate)",
			["facialHair"] = "facial hair",
			["glasses"] = "glasses",
			["address"] = "address",
			["work"] = "workplace",
			["workHours"] = "work hours",
			["jobTitle"] = "job title",
			["dateOfBirth"] = "date of birth",
			["salary"] = "salary",
			["randomInterest"] = "an interest",
			["randomSocialClub"] = "a social club",
			["partnerFirstName"] = "partner's name",
			["partnerJobTitle"] = "partner's job",
			["partnerSocialClub"] = "partner's social club",
			["randomAffliction"] = "an affliction",
			["handwriting"] = "handwriting",
			["livesOnFloor"] = "floor they live on",
			["telephoneNumber"] = "phone number",
			["livesInBuilding"] = "building they live in",
			["worksInBuilding"] = "building they work in",
			["location"] = "location",
			["blueprints"] = "blueprints"
		};

		private static void Postfix(GameMessageController __instance, Evidence keyTieEvidence, List<DataKey> newTiedKeys)
		{
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			PopupExtraLine.Lines.Remove(((Il2CppObjectBase)__instance).Pointer);
			if (keyTieEvidence == null || newTiedKeys == null || (Object)(object)__instance.messageText == (Object)null)
			{
				return;
			}
			try
			{
				string key;
				try
				{
					key = keyTieEvidence.GetNameForDataKey((DataKey)0);
				}
				catch
				{
					key = ((Object)keyTieEvidence).GetHashCode().ToString();
				}
				HashSet<string> hashSet = new HashSet<string>();
				for (int i = 0; i < newTiedKeys.Count; i++)
				{
					hashSet.Add(((object)newTiedKeys[i]/*cast due to .constrained prefix*/).ToString());
				}
				Known.TryGetValue(key, out HashSet<string> value);
				Known[key] = hashSet;
				List<string> list = new List<string>();
				foreach (string item in hashSet)
				{
					if (!Hidden.Contains(item) && (value == null || !value.Contains(item)))
					{
						list.Add(Labels.TryGetValue(item, out string value2) ? value2 : item);
					}
				}
				if (list.Count != 0)
				{
					int value3 = CitizenFilePopupPlugin.MaxListed.Value;
					string text = ((value3 <= 0 || list.Count <= value3) ? string.Join(", ", list) : string.Format("{0} +{1} more", string.Join(", ", list.GetRange(0, value3)), list.Count - value3));
					PopupExtraLine.Lines[((Il2CppObjectBase)__instance).Pointer] = "\nNew in file: " + text;
				}
			}
			catch (Exception ex)
			{
				ManualLogSource logSource = CitizenFilePopupPlugin.LogSource;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[POPUP] failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
				}
				logSource.LogInfo(val);
			}
		}
	}
	[HarmonyPatch(typeof(GameMessageController), "Update")]
	internal static class PopupExtraLine
	{
		internal static readonly Dictionary<IntPtr, string> Lines = new Dictionary<IntPtr, string>();

		private static void Postfix(GameMessageController __instance)
		{
			if (Lines.Count == 0 || !Lines.TryGetValue(((Il2CppObjectBase)__instance).Pointer, out string value))
			{
				return;
			}
			TextMeshProUGUI messageText = __instance.messageText;
			if (!((Object)(object)messageText == (Object)null))
			{
				string text = ((TMP_Text)messageText).text ?? "";
				if (!text.EndsWith(value))
				{
					((TMP_Text)messageText).text = text + value;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CityConstructor), "StartLoading")]
	internal static class ForgetOnCityLoad
	{
		private static void Prefix()
		{
			KeyMergeMessagePatch.Known.Clear();
			PopupExtraLine.Lines.Clear();
		}
	}
}