Decompiled source of Pies Generic Patch v1.5.0

Pies_Generic_Patch.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SOD.Common.BepInEx;
using TMPro;
using UnityEngine;
using UniverseLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Pies_Generic_Patch")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyDescription("Bugfixes for Shadows of Doubt. See the README for what is patched")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyInformationalVersion("1.5.0+9d54c01b55efe16c71d847f1aecdaff6f623fb51")]
[assembly: AssemblyProduct("Pies_Generic_Patch")]
[assembly: AssemblyTitle("Pies_Generic_Patch")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.5.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Pies_Generic_Patch
{
	[BepInPlugin("Pies_Generic_Patch", "Pies_Generic_Patch", "1.5.0")]
	public class Pies_Generic_PatchPlugin : PluginController<Pies_Generic_PatchPlugin>
	{
		private static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> DebugLogging;

		private static ConfigEntry<bool> PatchEnabled_AddRetirees;

		private static ConfigEntry<bool> PatchEnabled_FixGroups;

		public override void Load()
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			Enabled = base.Config.Bind<bool>("General", "Enabled", true, "Is the mod enabled at all? (Game restart required)");
			DebugLogging = base.Config.Bind<bool>("Debugging", "Logging", false, "Is debug logging enabled?");
			if (Enabled.Value)
			{
				ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Pies_Generic_Patch");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
				}
				log.LogInfo(val);
				Harmony val2 = new Harmony("Pies_Generic_Patch");
				val2.PatchAll();
				ManualLogSource log2 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Pies_Generic_Patch");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is patched!");
				}
				log2.LogInfo(val);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Pies_Generic_Patch";

		public const string PLUGIN_NAME = "Pies_Generic_Patch";

		public const string PLUGIN_VERSION = "1.5.0";
	}
}
namespace Pies_Generic_Patch.BugFixes
{
	public class AddRetirees
	{
		[HarmonyPatch(typeof(Creator), "SetComplete")]
		public class CitizenCreator_SetComplete
		{
			public static void Prefix(object __instance)
			{
				if (ReflectionExtensions.GetActualType(__instance) == typeof(CitizenCreator) && CityConstructor.Instance.generateNew)
				{
					OverrideCitizensToRetired();
				}
			}
		}

		public static void DoPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(CitizenCreator_SetComplete));
		}

		public static void OverrideCitizensToRetired()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			bool flag = default(bool);
			for (int num = CityData.Instance.citizenDirectory.Count - 1; num >= 0; num--)
			{
				Citizen val = CityData.Instance.citizenDirectory[num];
				if (!((Actor)val).isHomeless && ((SoCustomComparison)((Human)val).job.preset).presetName == ((SoCustomComparison)CitizenCreator.Instance.unemployedPreset).presetName)
				{
					if (Pies_Generic_PatchPlugin.DebugLogging.Value)
					{
						ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
						BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(39, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Overriding ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Human)val).citizenName);
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": From unemployed to retired");
						}
						log.LogInfo(val2);
					}
					Occupation val3 = new Occupation
					{
						preset = CitizenCreator.Instance.retiredPreset,
						employer = null,
						paygrade = 0f
					};
					val3.name = Strings.Get("jobs", ((Object)val3.preset).name, (Casing)0, false, false, false, (Human)null);
					((Human)val).SetJob(val3);
				}
			}
		}
	}
	public class FixDialogPasswordPrompt
	{
		[HarmonyPatch(typeof(DialogController), "ExecuteDialog")]
		public class DialogController_ExecuteDialog
		{
			public static void Prefix(DialogOption dialog, Interactable saysTo, ref ForceSuccess forceSuccess)
			{
				//IL_007e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Expected O, but got Unknown
				if (forceSuccess || dialog == null || (SoCustomComparison)(object)dialog.preset == (SoCustomComparison)null || saysTo == null)
				{
					return;
				}
				DialogPreset preset = dialog.preset;
				if (!preset.useSuccessTest || !preset.requiresPassword || preset.baseChance < 1f || PasswordRequiredAndUnknown(saysTo))
				{
					return;
				}
				forceSuccess = (ForceSuccess)1;
				if (Pies_Generic_PatchPlugin.DebugLogging.Value)
				{
					ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(51, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Dialog ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)preset).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": forcing success as no password is required");
					}
					log.LogInfo(val);
				}
			}

			private static bool PasswordRequiredAndUnknown(Interactable saysTo)
			{
				Actor isActor = saysTo.isActor;
				object obj;
				if (isActor == null)
				{
					obj = null;
				}
				else
				{
					NewGameLocation currentGameLocation = isActor.currentGameLocation;
					obj = ((currentGameLocation != null) ? currentGameLocation.thisAsAddress : null);
				}
				NewAddress val = (NewAddress)obj;
				if ((Object)(object)val == (Object)null || (SoCustomComparison)(object)val.addressPreset == (SoCustomComparison)null || !val.addressPreset.needsPassword)
				{
					return false;
				}
				return !GameplayController.Instance.playerKnowsPasswords.Contains(val.id);
			}
		}

		public static void DoPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(DialogController_ExecuteDialog));
		}
	}
	public class FixGroups
	{
		[HarmonyPatch(typeof(Company), "IsOpenAtDecimalTime")]
		public class Company_IsOpenAtDecimalTime
		{
			public static bool Prefix(ref bool __result, Company __instance, WeekDay day, float hour)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: 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)
				//IL_0053: Expected I4, but got Unknown
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Expected I4, but got Unknown
				float x = __instance.preset.workHours.retailOpenHours.x;
				float y = __instance.preset.workHours.retailOpenHours.y;
				if (1 == 0)
				{
				}
				bool flag = (int)day switch
				{
					0 => __instance.preset.workHours.monday, 
					1 => __instance.preset.workHours.tuesday, 
					2 => __instance.preset.workHours.wednesday, 
					3 => __instance.preset.workHours.thursday, 
					4 => __instance.preset.workHours.friday, 
					5 => __instance.preset.workHours.saturday, 
					6 => __instance.preset.workHours.sunday, 
					_ => false, 
				};
				if (1 == 0)
				{
				}
				bool flag2 = flag;
				WeekDay val = (WeekDay)((day + 6) % 7);
				if (1 == 0)
				{
				}
				flag = (int)val switch
				{
					0 => __instance.preset.workHours.monday, 
					1 => __instance.preset.workHours.tuesday, 
					2 => __instance.preset.workHours.wednesday, 
					3 => __instance.preset.workHours.thursday, 
					4 => __instance.preset.workHours.friday, 
					5 => __instance.preset.workHours.saturday, 
					6 => __instance.preset.workHours.sunday, 
					_ => false, 
				};
				if (1 == 0)
				{
				}
				bool flag3 = flag;
				if (x <= y && (!(x < 1f) || !(y > 23f)))
				{
					__result = flag2 && hour >= x && hour <= y;
				}
				else
				{
					bool flag4 = flag2 && hour >= x;
					bool flag5 = flag3 && hour <= y;
					__result = flag4 || flag5;
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(GroupsController), "CreateGroups")]
		public class GroupsController_CreateGroups
		{
			public static bool ReadyForGroups;

			public static bool Prefix()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Expected O, but got Unknown
				if (!ReadyForGroups)
				{
					if (Pies_Generic_PatchPlugin.DebugLogging.Value)
					{
						ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
						bool flag = default(bool);
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(15, 0, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Skipping groups");
						}
						log.LogInfo(val);
					}
					return false;
				}
				ClampGroupMinMembers();
				return true;
			}

			private static void ClampGroupMinMembers()
			{
				//IL_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_007e: Expected O, but got Unknown
				Enumerator<string, ScriptableObject> enumerator = Toolbox.Instance.resourcesCache[Il2CppType.Of<GroupPreset>()].Values.GetEnumerator();
				bool flag = default(bool);
				while (enumerator.MoveNext())
				{
					ScriptableObject current = enumerator.Current;
					GroupPreset val = ReflectionExtensions.TryCast<GroupPreset>((object)current);
					if ((SoCustomComparison)(object)val == (SoCustomComparison)null || val.minMembers >= 1)
					{
						continue;
					}
					val.minMembers = 1;
					if (Pies_Generic_PatchPlugin.DebugLogging.Value)
					{
						ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
						BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Clamped minMembers to 1 for group ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
						}
						log.LogInfo(val2);
					}
				}
			}

			public static void Postfix()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Expected O, but got Unknown
				//IL_0136: Unknown result type (might be due to invalid IL or missing references)
				//IL_013d: Expected O, but got Unknown
				//IL_029e: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a5: Expected O, but got Unknown
				//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0303: Expected O, but got Unknown
				//IL_035b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0362: Expected O, but got Unknown
				if (!ReadyForGroups)
				{
					return;
				}
				bool flag = default(bool);
				if (Pies_Generic_PatchPlugin.DebugLogging.Value)
				{
					ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 0, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CreateGroups running");
					}
					log.LogInfo(val);
				}
				HashSet<string> hashSet = new HashSet<string>();
				Enumerator<SocialGroup> enumerator = GroupsController.Instance.groups.GetEnumerator();
				while (enumerator.MoveNext())
				{
					SocialGroup current = enumerator.Current;
					if (current.meetingPlace <= 0)
					{
						continue;
					}
					GroupPreset preset = current.GetPreset();
					NewAddress meetingPlace = current.GetMeetingPlace();
					Enumerator<int> enumerator2 = current.members.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						int current2 = enumerator2.Current;
						Human val2 = CityData.Instance.citizenDictionary[current2];
						((Actor)val2).ai.CreateNewGoal(preset.meetUpGoal, 0f, preset.meetUpLength, (NewNode)null, (Interactable)null, (NewGameLocation)(object)meetingPlace, current, (Murder)null, -2).name = ((Object)preset.meetUpGoal).name + ": " + ((Object)preset).name;
						if (Pies_Generic_PatchPlugin.DebugLogging.Value)
						{
							ManualLogSource log2 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
							BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(23, 3, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Created goal for ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(val2.citizenName);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" - ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(current.preset);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(current.id);
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
							}
							log2.LogInfo(val);
						}
						if (current.preset == "CheatersMeet")
						{
							hashSet.Add(val2.citizenName);
						}
					}
				}
				HashSet<string> hashSet2 = new HashSet<string>();
				Enumerator<Citizen> enumerator3 = CityData.Instance.citizenDirectory.GetEnumerator();
				while (enumerator3.MoveNext())
				{
					Citizen current3 = enumerator3.Current;
					if ((Object)(object)((Human)current3).paramour == (Object)null || hashSet2.Contains(((Human)current3).citizenName) || hashSet2.Contains(((Human)((Human)current3).paramour).citizenName))
					{
						continue;
					}
					hashSet2.Add(((Human)current3).citizenName);
					hashSet2.Add(((Human)((Human)current3).paramour).citizenName);
					if (Pies_Generic_PatchPlugin.DebugLogging.Value)
					{
						ManualLogSource log3 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Checking cheaters: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Human)current3).citizenName);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" & ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Human)((Human)current3).paramour).citizenName);
						}
						log3.LogInfo(val);
						ManualLogSource log4 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
						val = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\t");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Human)current3).citizenName);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" has meeting: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(hashSet.Contains(((Human)current3).citizenName));
						}
						log4.LogInfo(val);
						ManualLogSource log5 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
						val = new BepInExInfoLogInterpolatedStringHandler(15, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\t");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Human)((Human)current3).paramour).citizenName);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" has meeting: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(hashSet.Contains(((Human)((Human)current3).paramour).citizenName));
						}
						log5.LogInfo(val);
					}
				}
			}
		}

		[HarmonyPatch(typeof(Creator), "SetComplete")]
		public class CitizenCreator_SetComplete
		{
			public static void Prefix(object __instance)
			{
				if (ReflectionExtensions.GetActualType(__instance) == typeof(RelationshipCreator) && CityConstructor.Instance.generateNew)
				{
					GroupsController_CreateGroups.ReadyForGroups = true;
					GroupsController.Instance.CreateGroups();
				}
			}
		}

		[HarmonyPatch(typeof(Strings), "GetContainedValue")]
		public class Strings_GetContainedValue
		{
			public const string ValueName = "pie_casualsignature";

			public static bool Prefix(ref string __result, string withinScope, string newValue, object inputObject, Evidence baseEvidence, LinkSetting linkSetting)
			{
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Invalid comparison between Unknown and I4
				if (withinScope.ToLower() != "citizen" || newValue.ToLower() != "pie_casualsignature")
				{
					return true;
				}
				__result = string.Empty;
				Human val = ReflectionExtensions.TryCast<Human>(inputObject);
				if ((Object)(object)val == (Object)null || (SoCustomComparison)(object)val.handwriting == (SoCustomComparison)null || val.GetSurName().Length <= 0)
				{
					return false;
				}
				string value = val.GetFirstName() + " " + val.GetSurName().Substring(0, 1) + ".";
				if ((int)linkSetting == 1 && baseEvidence != null)
				{
					LinkData val2 = Strings.AddOrGetLink((Evidence)(object)((Actor)val).evidenceEntry, baseEvidence.GetMergedDiscoveryLinkKeysFor((Evidence)(object)((Actor)val).evidenceEntry, (DataKey)38));
					if (val2 != null)
					{
						value = $"<link={val2.id}>{value}</link>";
					}
				}
				__result = $"<font=\"{((Object)val.handwriting.fontAsset).name}\">{value}</font>";
				return false;
			}
		}

		public static void DoPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(Company_IsOpenAtDecimalTime));
			harmony.PatchAll(typeof(GroupsController_CreateGroups));
		}
	}
	public class FixHandwritingTypeE
	{
		[HarmonyPatch(typeof(Toolbox), "Start")]
		public class Toolbox_Start
		{
			public static void Postfix()
			{
				RepointHalogenFont();
			}
		}

		public const string PresetName = "Halogen";

		public const string FontName = "Halogen SDF";

		public static void DoPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(Toolbox_Start));
		}

		public static void RepointHalogenFont()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Expected O, but got Unknown
			Type val = Il2CppType.Of<HandwritingPreset>();
			bool flag = default(bool);
			if (!Toolbox.Instance.resourcesCache.ContainsKey(val) || !Toolbox.Instance.resourcesCache[val].ContainsKey("Halogen"))
			{
				ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(53, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("HandwritingPreset ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Halogen");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" not found, handwriting fix skipped");
				}
				log.LogWarning(val2);
				return;
			}
			HandwritingPreset val3 = ReflectionExtensions.TryCast<HandwritingPreset>((object)Toolbox.Instance.resourcesCache[val]["Halogen"]);
			if ((SoCustomComparison)(object)val3 == (SoCustomComparison)null || (Object)(object)val3.fontAsset == (Object)null)
			{
				ManualLogSource log2 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(55, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("HandwritingPreset ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Halogen");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" has no font, handwriting fix skipped");
				}
				log2.LogWarning(val2);
			}
			else
			{
				if (((Object)val3.fontAsset).name == "Halogen SDF")
				{
					return;
				}
				if ((Object)(object)DDSControls.Instance == (Object)null)
				{
					PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log.LogWarning((object)"DDSControls not ready, handwriting fix skipped");
					return;
				}
				TMP_FontAsset val4 = null;
				Enumerator<TMP_FontAsset> enumerator = DDSControls.Instance.fonts.GetEnumerator();
				while (enumerator.MoveNext())
				{
					TMP_FontAsset current = enumerator.Current;
					if ((Object)(object)current != (Object)null && ((Object)current).name == "Halogen SDF")
					{
						val4 = current;
						break;
					}
				}
				if ((Object)(object)val4 == (Object)null)
				{
					ManualLogSource log3 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(55, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Font ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Halogen SDF");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" not in DDSControls.fonts, handwriting fix skipped");
					}
					log3.LogWarning(val2);
					return;
				}
				string name = ((Object)val3.fontAsset).name;
				val3.fontAsset = val4;
				MaterialReferenceManager.AddFontAsset(val4);
				if (Pies_Generic_PatchPlugin.DebugLogging.Value)
				{
					ManualLogSource log4 = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
					BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(42, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("HandwritingPreset ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>("Halogen");
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(": font changed from ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(name);
						((BepInExLogInterpolatedStringHandler)val5).AppendLiteral(" to ");
						((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(((Object)val4).name);
					}
					log4.LogInfo(val5);
				}
			}
		}
	}
	public class FixMetaObjectCollision
	{
		[HarmonyPatch(typeof(CityConstructor), "GatherData")]
		public class CityConstructor_GatherData
		{
			public static void Postfix()
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				try
				{
					ReserveLoadedIds();
				}
				catch (Exception ex)
				{
					ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(42, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to reserve loaded meta object IDs: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					log.LogError(val);
				}
			}
		}

		public static void DoPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(CityConstructor_GatherData));
		}

		private static void ReserveLoadedIds()
		{
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			CityConstructor instance = CityConstructor.Instance;
			if ((Object)(object)instance == (Object)null || instance.generateNew || instance.currentData == null)
			{
				return;
			}
			int num = Interactable.worldAssignID - 1;
			int num2 = 0;
			List<MetaObject> metas = instance.currentData.metas;
			if (metas != null)
			{
				Dictionary<int, MetaObject> metaObjectDictionary = CityData.Instance.metaObjectDictionary;
				Enumerator<MetaObject> enumerator = metas.GetEnumerator();
				while (enumerator.MoveNext())
				{
					MetaObject current = enumerator.Current;
					if (current != null)
					{
						if (current.id > num)
						{
							num = current.id;
						}
						if (!metaObjectDictionary.ContainsKey(current.id))
						{
							metaObjectDictionary.Add(current.id, current);
							num2++;
						}
					}
				}
			}
			List<Interactable> interactables = instance.currentData.interactables;
			if (interactables != null)
			{
				Enumerator<Interactable> enumerator2 = interactables.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					Interactable current2 = enumerator2.Current;
					if (current2 != null && current2.id > num)
					{
						num = current2.id;
					}
				}
			}
			int worldAssignID = Interactable.worldAssignID;
			Interactable.worldAssignID = num + 1;
			if (Pies_Generic_PatchPlugin.DebugLogging.Value)
			{
				ManualLogSource log = PluginController<Pies_Generic_PatchPlugin, IEmptyBindings>.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(80, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Meta objects: registered ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" city meta objects early, moved worldAssignID from ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(worldAssignID);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" to ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Interactable.worldAssignID);
				}
				log.LogInfo(val);
			}
		}
	}
	public class FixNeedDrainDuringInteraction
	{
		[HarmonyPatch(typeof(NewAIController), "AITick")]
		public class NewAIController_AITick
		{
			public static void Postfix(NewAIController __instance)
			{
				Human human = __instance.human;
				if (!((Object)(object)human == (Object)null) && !((Actor)human).isDead && !Game.Instance.pauseAI && (((Actor)human).interactingWith != null || ((Actor)human).inConversation))
				{
					__instance.lastUpdated = SessionData.Instance.gameTime;
				}
			}
		}

		public static void DoPatch(Harmony harmony)
		{
			harmony.PatchAll(typeof(NewAIController_AITick));
		}
	}
	public class FixSignatures
	{
		[HarmonyPatch(typeof(Strings), "GetContainedValue")]
		public class Strings_GetContainedValue
		{
			public static bool Prefix(ref string __result, string withinScope, string newValue, object inputObject, Evidence baseEvidence, LinkSetting linkSetting)
			{
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Invalid comparison between Unknown and I4
				if (withinScope.ToLower() != "citizen" || newValue.ToLower() != "signature")
				{
					return true;
				}
				__result = string.Empty;
				Human val = ReflectionExtensions.TryCast<Human>(inputObject);
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				string text = val.GetInitialledName();
				if ((int)linkSetting == 1 && baseEvidence != null)
				{
					LinkData val2 = Strings.AddOrGetLink((Evidence)(object)((Actor)val).evidenceEntry, baseEvidence.GetMergedDiscoveryLinkKeysFor((Evidence)(object)((Actor)val).evidenceEntry, (DataKey)40));
					if (val2 != null)
					{
						text = $"<link={val2.id}>{text}</link>";
					}
				}
				__result = (((SoCustomComparison)(object)val.handwriting != (SoCustomComparison)null) ? $"<font=\"{((Object)val.handwriting.fontAsset).name}\">{text}</font>" : text);
				return false;
			}
		}
	}
}