Decompiled source of Kidnapper Message Fix v1.0.0

plugins/KidnapperMessageFix.dll

Decompiled 11 hours ago
using System;
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 Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SOD.Common;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("KidnapperMessageFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("KidnapperMessageFix")]
[assembly: AssemblyTitle("KidnapperMessageFix")]
[assembly: AssemblyVersion("1.0.0.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 KidnapperMessageFix
{
	[BepInPlugin("fares.kidnappermessagefix", "Kidnapper Message Fix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string GUID = "fares.kidnappermessagefix";

		private const string Item = "KidnapperScienceDenDetails";

		internal static ManualLogSource L;

		private static ConfigEntry<bool> FixExistingNotes;

		public override void Load()
		{
			L = ((BasePlugin)this).Log;
			FixExistingNotes = ((BasePlugin)this).Config.Bind<bool>("General", "FixExistingNotes", true, "When a save loads, also repair den notes that were already created with the bug (they get the kidnapper as receiver).");
			Lib.SaveGame.OnBeforeLoad += delegate
			{
				FixPresets("before load");
			};
			Lib.SaveGame.OnBeforeNewGame += delegate
			{
				FixPresets("before new game");
			};
			Lib.SaveGame.OnAfterLoad += delegate
			{
				FixExisting("after load");
			};
			L.LogInfo((object)"Kidnapper Message Fix loaded");
		}

		private static bool IsDenNote(InteractablePreset p)
		{
			if ((SoCustomComparison)(object)p != (SoCustomComparison)null)
			{
				if (!(((SoCustomComparison)p).presetName == "KidnapperScienceDenDetails"))
				{
					return ((Object)p).name == "KidnapperScienceDenDetails";
				}
				return true;
			}
			return false;
		}

		private static void FixPresets(string when)
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Invalid comparison between Unknown and I4
			bool flag = default(bool);
			try
			{
				int num = 0;
				foreach (Object item in (Il2CppArrayBase<Object>)(object)Resources.FindObjectsOfTypeAll(Il2CppType.Of<MurderMO>()))
				{
					MurderMO val = ((Il2CppObjectBase)item).TryCast<MurderMO>();
					if (((val != null) ? val.MOleads : null) == null)
					{
						continue;
					}
					Enumerator<MurderLeadItem> enumerator2 = val.MOleads.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						MurderLeadItem current = enumerator2.Current;
						if (current != null && IsDenNote(current.spawnItem) && (int)current.receiver != 2)
						{
							current.receiver = (LeadCitizen)2;
							current.writer = (LeadCitizen)0;
							num++;
						}
					}
				}
				ManualLogSource l = L;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(25, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(when);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("] den note leads fixed: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(num);
				}
				l.LogInfo(val2);
			}
			catch (Exception ex)
			{
				ManualLogSource l2 = L;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(12, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("FixPresets: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
				}
				l2.LogError(val3);
			}
		}

		private static void FixExisting(string when)
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			if (!FixExistingNotes.Value)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				CityData instance = CityData.Instance;
				List<Interactable> val = ((instance != null) ? instance.interactableDirectory : null);
				if (val == null)
				{
					return;
				}
				int num = 0;
				Enumerator<Interactable> enumerator = val.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Interactable current = enumerator.Current;
					if (current == null || !IsDenNote(current.preset) || (Object)(object)current.reciever != (Object)null)
					{
						continue;
					}
					Human val2 = current.writer ?? current.belongsTo;
					if (!((Object)(object)val2 == (Object)null))
					{
						current.SetReciever(val2);
						num++;
						ManualLogSource l = L;
						BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(21, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(when);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("] den note ");
							((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(current.id);
							((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(" repaired");
						}
						l.LogInfo(val3);
					}
				}
				if (num == 0)
				{
					ManualLogSource l2 = L;
					BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(when);
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("] no broken den note in this save");
					}
					l2.LogInfo(val3);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource l3 = L;
				BepInExErrorLogInterpolatedStringHandler val4 = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("FixExisting: ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<Exception>(ex);
				}
				l3.LogError(val4);
			}
		}
	}
}