Decompiled source of SodRelaciones v0.1.1

SodRelaciones.dll

Decompiled 14 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.Text;
using System.Text.Json;
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 Il2CppSystem.IO;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
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("SodRelaciones")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SodRelaciones")]
[assembly: AssemblyTitle("SodRelaciones")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SodRelaciones
{
	public static class Aliases
	{
		public const int MaxOffered = 3;

		public const int MaxFakeIds = 2;

		private static bool _traderLogged;

		public static string RealName => Game.Instance.playerFirstName + " " + Game.Instance.playerSurname;

		public static int FakeIdsHeld => RelationState.Aliases.Count((Alias a) => a.FakeId && !a.Burned);

		public static List<Alias> Usable()
		{
			EnsureImprovised();
			List<Alias> list = RelationState.Aliases.Where((Alias a) => !a.Burned && !a.FakeId).Take(1).ToList();
			list.AddRange(RelationState.Aliases.Where((Alias a) => !a.Burned && a.FakeId).Reverse().Take(3 - list.Count));
			return list;
		}

		private static void EnsureImprovised()
		{
			if (!RelationState.Aliases.Any((Alias a) => !a.Burned && !a.FakeId))
			{
				Alias alias = new Alias
				{
					Name = NewName()
				};
				RelationState.Aliases.Add(alias);
				Plugin.Debug("Nuevo alias improvisado: " + alias.Name);
			}
		}

		public static Alias BuyFakeId()
		{
			Alias alias = new Alias
			{
				Name = NewName(),
				FakeId = true
			};
			RelationState.Aliases.Add(alias);
			Plugin.Debug("DNI falso comprado: " + alias.Name);
			return alias;
		}

		private static string NewName()
		{
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			List<Citizen> citizenDirectory = CityData.Instance.citizenDirectory;
			HashSet<string> hashSet = new HashSet<string> { RealName };
			Enumerator<Citizen> enumerator = citizenDirectory.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Citizen current = enumerator.Current;
				hashSet.Add(((Human)current).firstName + " " + ((Human)current).surName);
			}
			foreach (Alias alias in RelationState.Aliases)
			{
				hashSet.Add(alias.Name);
			}
			Gender gender = ((Human)Player.Instance).gender;
			for (int i = 0; i < 100; i++)
			{
				Citizen val = citizenDirectory[Random.Range(0, citizenDirectory.Count)];
				Citizen val2 = citizenDirectory[Random.Range(0, citizenDirectory.Count)];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && (((Human)val).gender == gender || i >= 80))
				{
					string text = ((Human)val).firstName + " " + ((Human)val2).surName;
					if (!hashSet.Contains(text))
					{
						return text;
					}
				}
			}
			return "John Doe";
		}

		public static void ShowDocuments()
		{
			List<string> list = new List<string> { string.Format(Texts.Get("docs_real_id"), RealName) };
			foreach (Alias item in Usable())
			{
				list.Add(string.Format(Texts.Get(item.FakeId ? "docs_fake_id" : "docs_improvised"), item.Name));
			}
			foreach (Alias item2 in RelationState.Aliases.Where((Alias a) => a.Burned && a.FakeId))
			{
				list.Add(string.Format(Texts.Get("docs_burned"), item2.Name));
			}
			IdentityDialog.Notify(string.Join(" · ", list));
			Plugin.Debug("Documentos: " + string.Join(" | ", list));
		}

		public static void LogTraderLocation()
		{
			if (_traderLogged || !Plugin.DebugLog.Value || (Object)(object)CityData.Instance == (Object)null)
			{
				return;
			}
			_traderLogged = true;
			Enumerator<NewAddress> enumerator = CityData.Instance.addressDirectory.GetEnumerator();
			while (enumerator.MoveNext())
			{
				NewAddress current = enumerator.Current;
				if (!((Object)(object)current == (Object)null) && !((SoCustomComparison)(object)current.addressPreset == (SoCustomComparison)null) && !(((Object)current.addressPreset).name != "BlackmarketTrader"))
				{
					string value = (((Object)(object)((NewGameLocation)current).building != (Object)null) ? ((Object)((NewGameLocation)current).building).name : "?");
					string value2 = (((Object)(object)((NewGameLocation)current).building != (Object)null && (Object)(object)((NewGameLocation)current).building.street != (Object)null) ? ((Object)((NewGameLocation)current).building.street).name : "?");
					string value3 = (((Object)(object)((NewGameLocation)current).floor != (Object)null) ? ((NewGameLocation)current).floor.floor.ToString() : "?");
					Plugin.Debug($"Mercado negro: {((Object)current).name} — edificio {value}, calle {value2}, planta {value3}, contraseña {current.GetPassword()}");
					return;
				}
			}
			Plugin.Debug("Mercado negro: no se ha encontrado en esta ciudad");
		}

		public static void ResetTraderLog()
		{
			_traderLogged = false;
		}

		public static bool IsTrader(Citizen cit)
		{
			if ((Object)(object)cit != (Object)null && ((Actor)cit).isAtWork && ((Human)cit).job != null && ((Human)cit).job.employer != null && (SoCustomComparison)(object)((Human)cit).job.employer.preset != (SoCustomComparison)null)
			{
				return ((Object)((Human)cit).job.employer.preset).name == "BlackmarketTrader";
			}
			return false;
		}

		private static bool KnowsPassword(Citizen cit)
		{
			List<int> playerKnowsPasswords = GameplayController.Instance.playerKnowsPasswords;
			NewAddress val = (((Object)(object)((Actor)cit).currentGameLocation != (Object)null) ? ((Actor)cit).currentGameLocation.thisAsAddress : null);
			if (!((Object)(object)((Human)cit).job.employer.address != (Object)null) || !playerKnowsPasswords.Contains(((Human)cit).job.employer.address.id))
			{
				if ((Object)(object)val != (Object)null)
				{
					return playerKnowsPasswords.Contains(val.id);
				}
				return false;
			}
			return true;
		}

		public static bool CanBuyHere(Citizen cit)
		{
			if (IsTrader(cit) && FakeIdsHeld < 2)
			{
				return KnowsPassword(cit);
			}
			return false;
		}
	}
	public static class Confront
	{
		private const float LieTrustLoss = -0.1f;

		private const float AnnoyTrustLoss = -0.04f;

		private const float AdmitArgumentChance = 0.75f;

		private const float AffairAdmitTrust = 0.7f;

		private const float AnnoyBase = 0.03f;

		private const float AnnoyDisagreeable = 0.05f;

		private const float RefuseTrust = 0.35f;

		private const int MaxPerConversation = 3;

		private static int _convCitizen = -1;

		private static int _convCount;

		private static float _convLast;

		private static float Now => SessionData.Instance.gameTime;

		private static string Key(Rumour r)
		{
			return $"{r.Kind}:{r.SubjectId}:{r.AddressId}:{Gossip.NightIndex(r.Time)}";
		}

		private static int CountThisConversation(Citizen cit)
		{
			if (_convCitizen != ((Human)cit).humanID || Now - _convLast > 1f)
			{
				_convCount = 0;
			}
			_convCitizen = ((Human)cit).humanID;
			_convLast = Now;
			return ++_convCount;
		}

		private static bool AtHome(Rumour r, Human h)
		{
			if ((Object)(object)h.home != (Object)null)
			{
				return r.AddressId == h.home.id;
			}
			return false;
		}

		public static Rumour Topic(Citizen cit)
		{
			if ((Object)(object)cit == (Object)null)
			{
				return null;
			}
			CitizenRecord rec = RelationState.Get((Human)(object)cit);
			return RelationState.Rumours.Where((Rumour r) => r.Told && (r.SubjectId == ((Human)cit).humanID || AtHome(r, (Human)(object)cit)) && !rec.Confronted.Contains(Key(r))).OrderByDescending(Gossip.Priority).ThenByDescending((Rumour r) => r.Time)
				.FirstOrDefault();
		}

		public static bool Available(Citizen cit)
		{
			if (Topic(cit) == null)
			{
				return FeudTopic(cit) != null;
			}
			return true;
		}

		private static string FeudKey(Feud f)
		{
			return $"Feud:{f.AId}:{f.BId}";
		}

		public static Feud FeudTopic(Citizen cit)
		{
			if ((Object)(object)cit == (Object)null)
			{
				return null;
			}
			Feud feud = Feuds.Of((Human)(object)cit);
			if (feud == null)
			{
				return null;
			}
			if (!((feud.AId == ((Human)cit).humanID) ? feud.ToldByB : feud.ToldByA) || RelationState.Get((Human)(object)cit).Confronted.Contains(FeudKey(feud)))
			{
				return null;
			}
			return feud;
		}

		public static string OptionText(Citizen cit)
		{
			Rumour rumour = Topic(cit);
			if (rumour == null)
			{
				Feud feud = FeudTopic(cit);
				Human val = ((feud != null) ? Feuds.Rival(feud, (Human)(object)cit) : null);
				if (!((Object)(object)val != (Object)null))
				{
					return string.Empty;
				}
				return string.Format(Texts.Variant("opt_confront_feud_" + feud.Cause), val.GetCitizenName());
			}
			string arg = Gossip.Clock(rumour.Time);
			string text = Gossip.Place(Gossip.AddressById(rumour.AddressId));
			return string.Format(Texts.Variant(rumour.Kind switch
			{
				GossipKind.Scream => "opt_confront_scream", 
				GossipKind.Gunshot => "opt_confront_gunshot", 
				GossipKind.CoupleNoise => "opt_confront_couple", 
				GossipKind.NightVisitor => (rumour.SubjectId != ((Human)cit).humanID) ? "opt_confront_host" : "opt_confront_visit", 
				GossipKind.LateArrival => "opt_confront_late", 
				_ => "opt_confront_seen", 
			}), arg, (rumour.Kind == GossipKind.Suspicious) ? (rumour.Where ?? "?") : text, Gossip.DayWord(rumour.Time));
		}

		private static Human Victim(Rumour r)
		{
			Human val = Gossip.HumanById(r.SubjectId);
			GossipKind kind = r.Kind;
			bool flag = (uint)(kind - 2) <= 1u;
			if (flag && DiedAround(val))
			{
				return val;
			}
			NewAddress val2 = Gossip.AddressById(r.AddressId);
			if ((Object)(object)val2 != (Object)null)
			{
				Enumerator<Human> enumerator = val2.inhabitants.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Human current = enumerator.Current;
					if (DiedAround(current))
					{
						return current;
					}
				}
			}
			return null;
			bool DiedAround(Human h)
			{
				if ((Object)(object)h != (Object)null && ((Actor)h).isDead && h.death != null && h.death.time >= r.Time - 1f)
				{
					return h.death.time <= r.Time + 4f;
				}
				return false;
			}
		}

		private static bool IsKiller(Human h, Human victim, Rumour r)
		{
			if ((!((Object)(object)victim != (Object)null) || victim.death == null || victim.death.killer != h.humanID) && (r.Kind != GossipKind.Suspicious || r.SubjectId != h.humanID))
			{
				if ((Object)(object)victim != (Object)null && IdentityDialog.IsActiveMurderer(h))
				{
					return r.SubjectId == h.humanID;
				}
				return false;
			}
			return true;
		}

		public static string React(Citizen cit, out bool ends)
		{
			ends = false;
			Rumour rumour = Topic(cit);
			Feud feud = ((rumour == null) ? FeudTopic(cit) : null);
			if (rumour == null && feud == null)
			{
				return Texts.Variant("confront_nothing");
			}
			int num = CountThisConversation(cit);
			float trust = RelationState.Get((Human)(object)cit).Trust;
			if (trust < 0.35f || num > 3)
			{
				RelationState.AddTrust((Human)(object)cit, -0.05f, "insistes con los rumores");
				ends = true;
				Plugin.Debug($"{((Human)cit).GetCitizenName()} se niega a hablar de rumores (confianza {trust:0.00}, vez {num})");
				return Texts.Variant("confront_refuse");
			}
			RelationState.Get((Human)(object)cit).Confronted.Add((rumour != null) ? Key(rumour) : FeudKey(feud));
			RelationState.AddTrust((Human)(object)cit, (0f - (0.03f + 0.05f * (1f - ((Human)cit).agreeableness))) * (float)num, "le incomodas con lo que dicen de él");
			string text = ((num >= 2 || trust < 0.5f) ? (Texts.Variant("confront_annoyed") + " ") : "");
			if (feud != null)
			{
				string text2 = FeudReply(cit, feud);
				if (RelationState.Get((Human)(object)cit).Trust < 0.35f)
				{
					ends = true;
				}
				return text + text2;
			}
			string text3 = Gossip.Clock(rumour.Time);
			string text4 = Gossip.Place(Gossip.AddressById(rumour.AddressId));
			Human subject = Gossip.HumanById(rumour.SubjectId);
			Human val = Victim(rumour);
			Human val2;
			int num2;
			if (rumour.FabricatedBy >= 0 && rumour.FabricatedBy != ((Human)cit).humanID)
			{
				val2 = Gossip.HumanById(rumour.FabricatedBy);
				if (rumour.SubjectId != ((Human)cit).humanID)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						Feud feud2 = Feuds.Of(val2);
						if (feud2 != null)
						{
							num2 = ((feud2.AId == ((Human)cit).humanID || feud2.BId == ((Human)cit).humanID) ? 1 : 0);
							goto IL_0208;
						}
					}
					num2 = 0;
				}
				else
				{
					num2 = 1;
				}
				goto IL_0208;
			}
			string text6;
			string truth;
			if (IsKiller((Human)(object)cit, val, rumour))
			{
				string text5;
				switch (rumour.Kind)
				{
				case GossipKind.Scream:
				case GossipKind.Gunshot:
					text5 = Fmt("confront_lie_noise", text3);
					break;
				case GossipKind.NightVisitor:
					text5 = Fmt("confront_lie_visit", text3, text4);
					break;
				case GossipKind.LateArrival:
					text5 = Fmt("confront_lie_late", text3);
					break;
				case GossipKind.Suspicious:
					text5 = Fmt("confront_lie_seen", text3, rumour.Where ?? "?");
					break;
				default:
					text5 = Fmt("confront_private");
					break;
				}
				text6 = text5;
				Tell(cit, 0.3f + 0.5f * ((Human)cit).emotionality);
				RelationState.AddTrust((Human)(object)cit, -0.1f, "le has echado en cara algo que oculta");
				truth = "miente: es el asesino" + (((Object)(object)val != (Object)null) ? (" de " + val.GetCitizenName()) : "");
			}
			else if ((Object)(object)val != (Object)null)
			{
				text6 = ((rumour.SubjectId == ((Human)cit).humanID && rumour.Kind == GossipKind.NightVisitor) ? Fmt("confront_murder_visit", val.GetCitizenName()) : Fmt("confront_murder_home", text3));
				if (((Human)cit).emotionality > 0.6f)
				{
					Tell(cit, 0.5f);
				}
				truth = "dice la verdad: no fue cosa suya, está relacionado con la muerte de " + val.GetCitizenName();
			}
			else
			{
				text6 = Innocent(cit, rumour, subject, text3, text4, out truth);
			}
			goto IL_0424;
			IL_0424:
			Plugin.Debug($"Increpas a {((Human)cit).GetCitizenName()} por {rumour.Kind} ({text4}, {text3}): {truth}");
			if (RelationState.Get((Human)(object)cit).Trust < 0.35f)
			{
				ends = true;
			}
			return text + text6;
			IL_0208:
			bool flag = (byte)num2 != 0;
			text6 = (((Object)(object)val2 != (Object)null) ? Fmt(flag ? "confront_slander" : "confront_slander_housemate", val2.GetCitizenName()) : Fmt("confront_nothing"));
			truth = "bulo inventado por " + ((val2 != null) ? val2.GetCitizenName() : null) + " (enemistad)";
			goto IL_0424;
		}

		private static string FeudReply(Citizen cit, Feud f)
		{
			Human val = Feuds.Rival(f, (Human)(object)cit);
			if ((Object)(object)val == (Object)null)
			{
				return Fmt("confront_nothing");
			}
			string citizenName = val.GetCitizenName();
			if (((Actor)val).isDead && val.death != null && val.death.killer == ((Human)cit).humanID)
			{
				Tell(cit, 0.4f + 0.5f * ((Human)cit).emotionality);
				RelationState.AddTrust((Human)(object)cit, -0.1f, "le has sacado a su enemigo muerto");
				Plugin.Debug($"Increpas a {((Human)cit).GetCitizenName()} por su enemistad con {citizenName}: miente, lo ha matado");
				return Fmt("confront_feud_killer", citizenName);
			}
			if (f.AId == ((Human)cit).humanID)
			{
				f.ToldByA = true;
			}
			else
			{
				f.ToldByB = true;
			}
			IdentityDialog.Refer((Human)(object)cit, val);
			Plugin.Debug($"Increpas a {((Human)cit).GetCitizenName()} por su enemistad con {citizenName} ({f.Kind}/{f.Cause}): da su versión");
			return Fmt("confront_feud_" + f.Cause, citizenName);
		}

		private static string Innocent(Citizen cit, Rumour r, Human subject, string clock, string place, out string truth)
		{
			truth = "dice la verdad: no tiene que ver con ningún crimen";
			switch (r.Kind)
			{
			case GossipKind.Scream:
				if (IsCoupleMember((Human)(object)cit))
				{
					RelationState.AddTrust((Human)(object)cit, -0.04f, "le has preguntado por una bronca");
					if (!(Random.value < 0.75f))
					{
						return Fmt("confront_private");
					}
					return Fmt("confront_argument", clock);
				}
				return Fmt("confront_scream_tv", clock);
			case GossipKind.Gunshot:
				return Fmt("confront_gunshot", clock);
			case GossipKind.CoupleNoise:
				RelationState.AddTrust((Human)(object)cit, -0.04f, "le has preguntado por su vida íntima");
				return Fmt("confront_couple");
			case GossipKind.NightVisitor:
			{
				Human val = (Human)((r.SubjectId == ((Human)cit).humanID) ? ((object)cit) : ((object)subject));
				Human val2 = Affair((Human)(object)cit, val, Gossip.AddressById(r.AddressId));
				if ((Object)(object)val2 != (Object)null)
				{
					truth = "oculta una aventura con " + val2.GetCitizenName() + " (no tiene que ver con el crimen)";
					Citizen partner = ((Human)cit).partner;
					if ((Object)(object)partner != (Object)null && RelationState.Get((Human)(object)cit).Trust >= 0.7f && Random.value < 0.4f)
					{
						return Fmt("confront_affair_admit", ((Human)partner).GetFirstName());
					}
					Tell(cit, 0.5f + 0.4f * ((Human)cit).emotionality);
					RelationState.AddTrust((Human)(object)cit, -0.1f, "le has sacado su aventura");
					return Fmt("confront_affair_deny");
				}
				NewAddress addr = Gossip.AddressById(r.AddressId);
				if ((Object)(object)val != (Object)null && val.humanID == ((Human)cit).humanID)
				{
					Human val3 = BestKnown(addr, (Human)(object)cit, (Human)(object)cit);
					if ((Object)(object)val3 == (Object)null)
					{
						return Fmt("confront_private");
					}
					string text = Reason((Human)(object)cit, val3);
					if (text == "stranger")
					{
						truth = "no conoce a nadie en esa casa: oculta algo (no tiene por qué ser el crimen)";
						Tell(cit, 0.3f + 0.4f * ((Human)cit).emotionality);
						RelationState.AddTrust((Human)(object)cit, -0.04f, "le preguntas por una visita que no puede explicar");
					}
					return Fmt("confront_visit_" + text, val3.GetCitizenName());
				}
				if ((Object)(object)val == (Object)null)
				{
					return Fmt("confront_private");
				}
				Human val4 = BestKnown(addr, val, null);
				if ((Object)(object)val4 != (Object)null && val4.humanID != ((Human)cit).humanID && Reason(val4, val) != "stranger")
				{
					IdentityDialog.Refer((Human)(object)cit, val4);
					return Fmt("confront_host_housemate", val.GetCitizenName(), val4.GetCitizenName());
				}
				string text2 = Reason((Human)(object)cit, val);
				if (text2 == "stranger")
				{
					truth = "no conoce de nada a " + val.GetCitizenName() + ": alguien se coló en su casa";
				}
				return Fmt("confront_host_" + text2, val.GetCitizenName());
			}
			case GossipKind.LateArrival:
				return Fmt((((Human)cit).job != null && ((Human)cit).job.employer != null && Random.value < 0.5f) ? "confront_late_work" : "confront_late_out");
			default:
				return Fmt("confront_seen_innocent", r.Where ?? "?");
			}
		}

		private static Human Affair(Human cit, Human visitor, NewAddress addr)
		{
			if ((Object)(object)cit.paramour == (Object)null || (Object)(object)addr == (Object)null || (Object)(object)visitor == (Object)null)
			{
				return null;
			}
			if (visitor.humanID == cit.humanID)
			{
				Enumerator<Human> enumerator = addr.inhabitants.GetEnumerator();
				while (enumerator.MoveNext())
				{
					if (IdentityDialog.Same(enumerator.Current, (Human)(object)cit.paramour))
					{
						return (Human)(object)cit.paramour;
					}
				}
				return null;
			}
			if (!IdentityDialog.Same(visitor, (Human)(object)cit.paramour))
			{
				return null;
			}
			return (Human)(object)cit.paramour;
		}

		private static string Reason(Human a, Human b)
		{
			if (IdentityDialog.Same((Human)(object)a.partner, b))
			{
				return "partner";
			}
			Acquaintance val = null;
			Enumerator<Acquaintance> enumerator = a.acquaintances.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Acquaintance current = enumerator.Current;
				if ((Object)(object)current.with != (Object)null && current.with.humanID == b.humanID)
				{
					val = current;
					break;
				}
			}
			if (val == null)
			{
				return "stranger";
			}
			List<ConnectionType> connections = val.connections;
			if (connections.Contains((ConnectionType)3))
			{
				return "partner";
			}
			if (connections.Contains((ConnectionType)0))
			{
				return "friend";
			}
			if (connections.Contains((ConnectionType)4) || connections.Contains((ConnectionType)5) || connections.Contains((ConnectionType)6) || connections.Contains((ConnectionType)10))
			{
				return "work";
			}
			if (!(val.like > 0.6f))
			{
				return "neighbour";
			}
			return "friend";
		}

		private static Human BestKnown(NewAddress addr, Human who, Human except)
		{
			if ((Object)(object)addr == (Object)null)
			{
				return null;
			}
			Human result = null;
			float num = -1f;
			Enumerator<Human> enumerator = addr.inhabitants.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Human current = enumerator.Current;
				if ((Object)(object)current == (Object)null || current.humanID == who.humanID || ((Object)(object)except != (Object)null && current.humanID == except.humanID))
				{
					continue;
				}
				float num2 = 0f;
				Enumerator<Acquaintance> enumerator2 = who.acquaintances.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					Acquaintance current2 = enumerator2.Current;
					if ((Object)(object)current2.with != (Object)null && current2.with.humanID == current.humanID)
					{
						num2 = current2.known + 0.01f;
					}
				}
				if (num2 > num)
				{
					result = current;
					num = num2;
				}
			}
			return result;
		}

		private static bool IsCoupleMember(Human h)
		{
			if ((Object)(object)h.partner != (Object)null && (Object)(object)h.home != (Object)null && (Object)(object)((Human)h.partner).home != (Object)null)
			{
				return ((Human)h.partner).home.id == h.home.id;
			}
			return false;
		}

		private static Human FirstInhabitant(NewAddress addr, Human except)
		{
			if ((Object)(object)addr == (Object)null)
			{
				return null;
			}
			Enumerator<Human> enumerator = addr.inhabitants.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Human current = enumerator.Current;
				if ((Object)(object)current != (Object)null && current.humanID != except.humanID)
				{
					return current;
				}
			}
			return null;
		}

		private static void Tell(Citizen cit, float chance)
		{
			if (!(Random.value >= chance))
			{
				IdentityDialog.Notify(string.Format(Texts.Variant("msg_nervous_" + Random.Range(0, 3)), ((Human)cit).GetCitizenName()));
			}
		}

		private static string Fmt(string key, params object[] args)
		{
			return string.Format(Texts.Variant(key), args);
		}
	}
	public static class DebugMenu
	{
		private static readonly (string label, bool needsTarget, Action<Human> run)[] Commands = new(string, bool, Action<Human>)[14]
		{
			("Tiempo rápido (sí/no)", false, delegate
			{
				ToggleFastTime();
			}),
			("Confianza +0,2", true, delegate(Human h)
			{
				RelationState.AddTrust(h, 0.2f, "depuración");
			}),
			("Confianza -0,2", true, delegate(Human h)
			{
				RelationState.AddTrust(h, -0.2f, "depuración");
			}),
			("Cotilleos de prueba (uno de cada tipo)", true, delegate(Human h)
			{
				Gossip.DebugSeed(h);
			}),
			("Correo y diario de prueba", true, delegate(Human h)
			{
				Mails.DebugTest(h);
			}),
			("Ver sus cotilleos (log)", true, delegate(Human h)
			{
				Gossip.DebugDump(h);
			}),
			("Propagar rumores ahora", false, delegate
			{
				Gossip.DebugSpread();
			}),
			("Testigos de asesinato (aviso + log)", false, delegate
			{
				Gossip.DebugMurderWitnesses();
			}),
			("Borrar correos de cotilleo antiguos", false, delegate
			{
				Mails.DebugPurgeOldGossip();
			}),
			("Ver enemistades (log)", false, delegate
			{
				Feuds.DebugDump();
			}),
			("Recrear enemistades", false, delegate
			{
				Feuds.DebugReseed();
			}),
			("Borrar llegadas tarde", false, delegate
			{
				Gossip.DebugPurgeLate();
			}),
			("Olvidar todo sobre él", true, delegate(Human h)
			{
				Gossip.DebugForget(h);
			}),
			("+5000 de dinero", false, delegate
			{
				GameplayController.Instance.AddMoney(5000, true, "Debug");
			})
		};

		private static GameObject _root;

		private static GameObject _panel;

		private static TextMeshProUGUI _text;

		private static bool _open;

		private static int _selected;

		private static bool EnsureCreated()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root != (Object)null)
			{
				return true;
			}
			if ((Object)(object)InterfaceControls.Instance == (Object)null || (Object)(object)InterfaceControls.Instance.actionInteractionText == (Object)null)
			{
				return false;
			}
			_root = new GameObject("SodRelDebugMenu");
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 101;
			CanvasScaler obj2 = _root.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			_panel = new GameObject("Panel");
			_panel.transform.SetParent(_root.transform, false);
			RectTransform obj3 = _panel.AddComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 0f);
			obj3.pivot = val;
			Vector2 anchorMin = (obj3.anchorMax = val);
			obj3.anchorMin = anchorMin;
			obj3.anchoredPosition = new Vector2(24f, 24f);
			obj3.sizeDelta = new Vector2(440f, 455f);
			Image obj4 = _panel.AddComponent<Image>();
			((Graphic)obj4).color = new Color(0f, 0f, 0f, 0.75f);
			((Graphic)obj4).raycastTarget = false;
			GameObject val3 = new GameObject("Text");
			val3.transform.SetParent(_panel.transform, false);
			RectTransform obj5 = val3.AddComponent<RectTransform>();
			obj5.anchorMin = Vector2.zero;
			obj5.anchorMax = Vector2.one;
			obj5.offsetMin = new Vector2(12f, 10f);
			obj5.offsetMax = new Vector2(-12f, -10f);
			_text = val3.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_text).font = ((TMP_Text)InterfaceControls.Instance.actionInteractionText).font;
			((TMP_Text)_text).fontSize = 19f;
			((TMP_Text)_text).alignment = (TextAlignmentOptions)257;
			((TMP_Text)_text).enableWordWrapping = true;
			((Graphic)_text).raycastTarget = false;
			_panel.SetActive(false);
			return true;
		}

		public static void Update()
		{
			int num;
			if (Plugin.DebugKeys.Value && (Object)(object)SessionData.Instance != (Object)null)
			{
				num = (SessionData.Instance.startedGame ? 1 : 0);
				if (num != 0 && Input.GetKeyDown((KeyCode)288))
				{
					_open = !_open;
				}
			}
			else
			{
				num = 0;
			}
			if (num == 0 || !_open)
			{
				if ((Object)(object)_panel != (Object)null)
				{
					_panel.SetActive(false);
				}
			}
			else if (EnsureCreated())
			{
				if (Input.GetKeyDown((KeyCode)273))
				{
					_selected = (_selected + Commands.Length - 1) % Commands.Length;
				}
				if (Input.GetKeyDown((KeyCode)274))
				{
					_selected = (_selected + 1) % Commands.Length;
				}
				Human val = DebugPanel.Target();
				if (Input.GetKeyDown((KeyCode)275))
				{
					Run(val);
				}
				StringBuilder stringBuilder = new StringBuilder("<b>Depuración</b>  (F7 cerrar · ↑↓ elegir · → ejecutar)\n");
				stringBuilder.Append(((Object)(object)val != (Object)null) ? ("Objetivo: <color=#60c0ff>" + val.GetCitizenName() + "</color>\n") : "Objetivo: <color=#888888>mira a un ciudadano</color>\n");
				for (int i = 0; i < Commands.Length; i++)
				{
					(string label, bool needsTarget, Action<Human> run) tuple = Commands[i];
					string item = tuple.label;
					string text = ((tuple.needsTarget && (Object)(object)val == (Object)null) ? ("<color=#777777>" + item + "</color>") : item);
					stringBuilder.Append((i == _selected) ? ("<color=#ffd040>▶ " + text + "</color>\n") : ("   " + text + "\n"));
				}
				((TMP_Text)_text).text = stringBuilder.ToString();
				_panel.SetActive(true);
			}
		}

		private static void Run(Human target)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			var (text, flag, action) = Commands[_selected];
			if (flag && (Object)(object)target == (Object)null)
			{
				IdentityDialog.Notify("Depuración: mira a un ciudadano primero");
				return;
			}
			try
			{
				action(target);
				Plugin.Debug("Depuración: " + text + (((Object)(object)target != (Object)null) ? (" → " + target.GetCitizenName()) : ""));
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag2 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(25, 2, ref flag2);
				if (flag2)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Depuración: error en «");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("»: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}

		private static void ToggleFastTime()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			SessionData instance = SessionData.Instance;
			bool flag = (int)instance.currentTimeSpeed != 3;
			instance.SetTimeSpeed((TimeSpeed)((!flag) ? 1 : 3));
			IdentityDialog.Notify(flag ? "Depuración: tiempo rápido" : "Depuración: tiempo normal");
		}
	}
	public static class DebugPanel
	{
		private const float BarWidth = 300f;

		private static GameObject _root;

		private static GameObject _panel;

		private static RectTransform _fill;

		private static Image _fillImage;

		private static TextMeshProUGUI _text;

		private static bool EnsureCreated()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root != (Object)null)
			{
				return true;
			}
			if ((Object)(object)InterfaceControls.Instance == (Object)null || (Object)(object)InterfaceControls.Instance.actionInteractionText == (Object)null)
			{
				return false;
			}
			TMP_FontAsset font = ((TMP_Text)InterfaceControls.Instance.actionInteractionText).font;
			_root = new GameObject("SodRelDebugPanel");
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 100;
			CanvasScaler obj2 = _root.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			_panel = new GameObject("Panel");
			_panel.transform.SetParent(_root.transform, false);
			RectTransform obj3 = _panel.AddComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			obj3.pivot = val;
			Vector2 anchorMin = (obj3.anchorMax = val);
			obj3.anchorMin = anchorMin;
			obj3.anchoredPosition = new Vector2(24f, -24f);
			obj3.sizeDelta = new Vector2(320f, 200f);
			Image obj4 = _panel.AddComponent<Image>();
			((Graphic)obj4).color = new Color(0f, 0f, 0f, 0.65f);
			((Graphic)obj4).raycastTarget = false;
			GameObject val3 = new GameObject("BarBg");
			val3.transform.SetParent(_panel.transform, false);
			RectTransform obj5 = val3.AddComponent<RectTransform>();
			((Vector2)(ref val))..ctor(0f, 1f);
			obj5.pivot = val;
			anchorMin = (obj5.anchorMax = val);
			obj5.anchorMin = anchorMin;
			obj5.anchoredPosition = new Vector2(10f, -10f);
			obj5.sizeDelta = new Vector2(300f, 14f);
			Image obj6 = val3.AddComponent<Image>();
			((Graphic)obj6).color = new Color(0.3f, 0.3f, 0.3f, 1f);
			((Graphic)obj6).raycastTarget = false;
			GameObject val5 = new GameObject("Fill");
			val5.transform.SetParent(val3.transform, false);
			_fill = val5.AddComponent<RectTransform>();
			RectTransform fill = _fill;
			RectTransform fill2 = _fill;
			RectTransform fill3 = _fill;
			((Vector2)(ref val))..ctor(0f, 0.5f);
			fill3.pivot = val;
			anchorMin = (fill2.anchorMax = val);
			fill.anchorMin = anchorMin;
			_fill.anchoredPosition = Vector2.zero;
			_fillImage = val5.AddComponent<Image>();
			((Graphic)_fillImage).raycastTarget = false;
			GameObject val7 = new GameObject("Text");
			val7.transform.SetParent(_panel.transform, false);
			RectTransform obj7 = val7.AddComponent<RectTransform>();
			obj7.anchorMin = new Vector2(0f, 0f);
			obj7.anchorMax = new Vector2(1f, 1f);
			obj7.offsetMin = new Vector2(10f, 8f);
			obj7.offsetMax = new Vector2(-10f, -30f);
			_text = val7.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_text).font = font;
			((TMP_Text)_text).fontSize = 18f;
			((TMP_Text)_text).alignment = (TextAlignmentOptions)257;
			((TMP_Text)_text).enableWordWrapping = true;
			((Graphic)_text).raycastTarget = false;
			_panel.SetActive(false);
			return true;
		}

		internal static Human Target()
		{
			InteractionController instance = InteractionController.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return null;
			}
			Interactable val = ((instance.dialogMode && instance.talkingTo != null) ? instance.talkingTo : (((Object)(object)instance.currentLookingAtInteractable != (Object)null) ? instance.currentLookingAtInteractable.interactable : null));
			if (val == null || (Object)(object)val.isActor == (Object)null)
			{
				return null;
			}
			Human val2 = ((Il2CppObjectBase)val.isActor).TryCast<Human>();
			if (!((Object)(object)val2 != (Object)null) || ((Actor)val2).isPlayer)
			{
				return null;
			}
			return val2;
		}

		public static void Refresh()
		{
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.DebugPanel.Value || (Object)(object)SessionData.Instance == (Object)null || !SessionData.Instance.startedGame)
			{
				if ((Object)(object)_panel != (Object)null)
				{
					_panel.SetActive(false);
				}
				return;
			}
			Human val = Target();
			if ((Object)(object)val == (Object)null)
			{
				if ((Object)(object)_panel != (Object)null)
				{
					_panel.SetActive(false);
				}
			}
			else if (EnsureCreated())
			{
				CitizenRecord citizenRecord = RelationState.Get(val);
				_fill.sizeDelta = new Vector2(300f * Mathf.Clamp01(citizenRecord.Trust), 14f);
				((Graphic)_fillImage).color = Color.Lerp(new Color(0.9f, 0.15f, 0.1f), new Color(0.2f, 0.85f, 0.25f), citizenRecord.Trust);
				string value = (citizenRecord.Suspicious ? "<color=#ff5040>RECELOSO (avisa a la policía)</color>" : ((citizenRecord.Trust < 0.2f) ? "<color=#ff5040>Hostil (no habla)</color>" : ((citizenRecord.Trust < 0.4f) ? "<color=#ffb020>Frío</color>" : ((citizenRecord.Trust < 0.6f) ? "Neutral" : "<color=#60e070>Cordial</color>"))));
				string value2 = citizenRecord.Identity switch
				{
					IdentityGiven.RealName => "nombre real", 
					IdentityGiven.Alias => "alias «" + citizenRecord.AliasName + "»", 
					IdentityGiven.Refused => "no sabe quién eres", 
					_ => "aún no ha preguntado", 
				};
				StringBuilder stringBuilder = new StringBuilder();
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(20, 2, stringBuilder2);
				handler.AppendLiteral("<b>");
				handler.AppendFormatted(val.GetCitizenName());
				handler.AppendLiteral("</b>  confianza ");
				handler.AppendFormatted(citizenRecord.Trust, "0.00");
				handler.AppendLiteral("\n");
				stringBuilder3.Append(ref handler);
				stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder4 = stringBuilder2;
				handler = new StringBuilder.AppendInterpolatedStringHandler(10, 1, stringBuilder2);
				handler.AppendLiteral("Actitud: ");
				handler.AppendFormatted(value);
				handler.AppendLiteral("\n");
				stringBuilder4.Append(ref handler);
				stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder5 = stringBuilder2;
				handler = new StringBuilder.AppendInterpolatedStringHandler(12, 1, stringBuilder2);
				handler.AppendLiteral("Te conoce: ");
				handler.AppendFormatted(value2);
				handler.AppendLiteral("\n");
				stringBuilder5.Append(ref handler);
				string text = Gossip.WitnessTraits(val);
				if (text.Length > 0)
				{
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder6 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(10, 1, stringBuilder2);
					handler.AppendLiteral("Testigo: ");
					handler.AppendFormatted(text);
					handler.AppendLiteral("\n");
					stringBuilder6.Append(ref handler);
				}
				float num = Detective.Opinion(val);
				stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder7 = stringBuilder2;
				handler = new StringBuilder.AppendInterpolatedStringHandler(27, 4, stringBuilder2);
				handler.AppendLiteral("Opinión de detectives: ");
				handler.AppendFormatted(num, "+0.00;-0.00");
				handler.AppendLiteral(" (");
				handler.AppendFormatted(Detective.Tier(num));
				handler.AppendLiteral(")");
				handler.AppendFormatted(citizenRecord.KnowsDetective ? " · <color=#60c0ff>sabe que eres detective</color>" : "");
				handler.AppendFormatted((citizenRecord.Motive != null) ? (" · excusa: " + citizenRecord.Motive) : "");
				handler.AppendLiteral("\n");
				stringBuilder7.Append(ref handler);
				if (citizenRecord.CaughtLying)
				{
					stringBuilder.Append("<color=#ffb020>Te ha pillado mintiendo</color>\n");
				}
				if (citizenRecord.SawCrimes.Count > 0)
				{
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder8 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(9, 2, stringBuilder2);
					handler.AppendLiteral("Te vio: ");
					handler.AppendFormatted(Reports.CrimeList(citizenRecord.SawCrimes));
					handler.AppendFormatted(citizenRecord.RecognitionDone ? " (ya te reconoció)" : "");
					handler.AppendLiteral("\n");
					stringBuilder8.Append(ref handler);
				}
				string text2 = Feuds.Describe(val);
				if (text2 != null)
				{
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder9 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(34, 1, stringBuilder2);
					handler.AppendLiteral("<color=#ff8060>Enemistad ");
					handler.AppendFormatted(text2);
					handler.AppendLiteral("</color>\n");
					stringBuilder9.Append(ref handler);
				}
				if (Gossip.CountFor(val, out var untold) > 0)
				{
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder10 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(26, 2, stringBuilder2);
					handler.AppendLiteral("Cotilleos: ");
					handler.AppendFormatted(Gossip.CountFor(val, out var _));
					handler.AppendLiteral(" (");
					handler.AppendFormatted(untold);
					handler.AppendLiteral(" sin contar)\n");
					stringBuilder10.Append(ref handler);
				}
				string value3 = ((!((Actor)val).isEnforcer) ? (((Actor)val).isAtWork ? "trabajando" : "fuera del trabajo") : (((Actor)val).isOnDuty ? "policía de servicio" : "policía fuera de servicio"));
				stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder11 = stringBuilder2;
				handler = new StringBuilder.AppendInterpolatedStringHandler(47, 3, stringBuilder2);
				handler.AppendLiteral("<size=15>");
				handler.AppendFormatted(value3);
				handler.AppendLiteral(" · amabilidad ");
				handler.AppendFormatted(val.agreeableness, "0.00");
				handler.AppendLiteral(" · meticulosidad ");
				handler.AppendFormatted(val.conscientiousness, "0.00");
				handler.AppendLiteral("</size>");
				stringBuilder11.Append(ref handler);
				((TMP_Text)_text).text = stringBuilder.ToString();
				_panel.SetActive(true);
			}
		}
	}
	public static class Detective
	{
		private const float RevealTrust = 0.3f;

		public const float CooperationInfluence = 0.15f;

		private static readonly Dictionary<string, float> TraitWeights = new Dictionary<string, float>
		{
			["Interest-MysteryNovels"] = 0.4f,
			["Interest-FilmNoir"] = 0.35f,
			["Interest-PulpFiction"] = 0.25f,
			["Char-Nosy"] = 0.25f,
			["Char-Selfless"] = 0.15f,
			["Char-Honest"] = 0.15f,
			["Char-Empathetic"] = 0.1f,
			["Char-Kind"] = 0.1f,
			["Char-Enthusiastic"] = 0.1f,
			["Principle-TrustOfAuthority"] = 0.1f,
			["Principle-DistrustOfAuthority"] = -0.15f,
			["Char-Paranoid"] = -0.15f,
			["Char-Suspicious"] = -0.12f,
			["Char-Guarded"] = -0.08f,
			["Char-Dishonest"] = -0.1f,
			["Char-Hostile"] = -0.1f,
			["Char-Spiteful"] = -0.05f,
			["Affliction-Kleptomaniac"] = -0.15f,
			["Secret-CrimeSyndicate"] = -0.5f,
			["Secret-KilledSomeone"] = -0.5f,
			["Secret-InWitnessProtection"] = -0.4f,
			["Secret-Affair"] = -0.2f,
			["Secret-Paramour"] = -0.2f,
			["Secret-StealsFromWork"] = -0.2f,
			["Secret-Addict"] = -0.1f
		};

		private const float BaseOpinion = 0.08f;

		public static float Opinion(Human h)
		{
			float num = 0.08f + (float)(new Random(h.humanID * 7919).NextDouble() - 0.5) * 0.3f;
			Enumerator<Trait> enumerator = h.characterTraits.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Trait current = enumerator.Current;
				if (current != null && (SoCustomComparison)(object)current.trait != (SoCustomComparison)null && TraitWeights.TryGetValue(((Object)current.trait).name, out var value))
				{
					num += value;
				}
			}
			if (((Actor)h).isEnforcer)
			{
				num -= 0.4f;
			}
			Citizen val = ((Il2CppObjectBase)h).TryCast<Citizen>();
			if ((Object)(object)val != (Object)null && Aliases.IsTrader(val))
			{
				num -= 0.3f;
			}
			if (IdentityDialog.IsActiveMurderer(h))
			{
				num -= 0.6f;
			}
			return Mathf.Clamp(num, -1f, 1f);
		}

		public static string Tier(float opinion)
		{
			if (!(opinion >= 0.35f))
			{
				if (!(opinion >= 0.12f))
				{
					if (!(opinion > -0.18f))
					{
						if (!(opinion > -0.45f))
						{
							return "hostile";
						}
						return "cold";
					}
					return "neutral";
				}
				return "warm";
			}
			return "fan";
		}

		public static void Reveal(Human h)
		{
			CitizenRecord citizenRecord = RelationState.Get(h);
			if (!citizenRecord.KnowsDetective)
			{
				citizenRecord.KnowsDetective = true;
				citizenRecord.MotiveTime = SessionData.Instance.gameTime;
				float num = Opinion(h);
				RelationState.AddTrust(h, num * 0.3f, $"sabe que eres detective (opinión {num:+0.00;-0.00})");
			}
		}

		public static float CooperationBonus(Human h)
		{
			if (!RelationState.TryGet(h, out var rec) || !rec.KnowsDetective)
			{
				return 0f;
			}
			return Opinion(h) * 0.15f;
		}
	}
	public static class Feuds
	{
		[HarmonyPatch(typeof(MurderController), "PickNewVictim")]
		private static class VictimPatch
		{
			private static void Postfix(MurderController __instance)
			{
				try
				{
					PreferRival(__instance);
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)("Error en enemistades (víctima): " + ex));
				}
			}
		}

		private const float MaxLike = 0.42f;

		private const float PairChance = 0.5f;

		private const int CitizensPerFeud = 12;

		private const int CitizensPerWorkFeud = 20;

		private const float ClubFeudChance = 0.5f;

		private const float SlanderPerHour = 0.04f;

		private const float SlanderMaxAgreeableness = 0.6f;

		private const float MailPerHour = 0.01f;

		private static int _lastHour = -1;

		private static float Now => SessionData.Instance.gameTime;

		public static void Reset()
		{
			_lastHour = -1;
		}

		public static bool HasGrievanceDetails(Human h)
		{
			Feud feud = Of(h);
			if (feud == null)
			{
				return false;
			}
			if (feud.AId != h.humanID)
			{
				if (feud.ToldByB)
				{
					return !feud.DetailedByB;
				}
				return false;
			}
			if (feud.ToldByA)
			{
				return !feud.DetailedByA;
			}
			return false;
		}

		public static List<string> GrievanceDetails(Human h, out Human person, out NewAddress place)
		{
			person = null;
			place = null;
			List<string> list = new List<string>();
			Feud feud = Of(h);
			if (feud != null && feud.AId == h.humanID)
			{
				feud.DetailedByA = true;
			}
			else if (feud != null)
			{
				feud.DetailedByB = true;
			}
			Human val = ((feud != null) ? Rival(feud, h) : null);
			if ((Object)(object)val == (Object)null)
			{
				return list;
			}
			person = val;
			if (feud.Kind == "neighbour")
			{
				place = val.home;
			}
			int days = Mathf.Max(1, Mathf.RoundToInt((Now - feud.Since) / 24f)) + new Random(feud.AId * 31 + feud.BId).Next(20, 200);
			list.Add(string.Format(Texts.Variant("grievance_more_" + feud.Cause), val.GetCitizenName(), Months(days)));
			Rumour rumour = RelationState.Rumours.FirstOrDefault((Rumour r) => r.WitnessId == h.humanID && r.FabricatedBy == h.humanID && !r.Told);
			if (rumour != null && ((Il2CppObjectBase)h).TryCast<Citizen>() != null)
			{
				rumour.Told = true;
				rumour.ToldAt = Now;
				list.Add(Texts.Variant("grievance_more_and") + " " + Gossip.Phrase(rumour, h));
			}
			Plugin.Debug($"Detalles de la enemistad de {h.GetCitizenName()} con {val.GetCitizenName()} ({feud.Kind}/{feud.Cause})" + ((rumour != null) ? ", y suelta su bulo" : ""));
			return list;
		}

		private static string Months(int days)
		{
			if (days >= 45)
			{
				return string.Format(Texts.Get("feud_months"), Mathf.RoundToInt((float)days / 30f));
			}
			return Texts.Get("feud_weeks");
		}

		public static Feud Of(Human h)
		{
			if (!((Object)(object)h == (Object)null))
			{
				return RelationState.Feuds.FirstOrDefault((Feud f) => f.AId == h.humanID || f.BId == h.humanID);
			}
			return null;
		}

		public static Human Rival(Feud f, Human h)
		{
			return Gossip.HumanById((f.AId == h.humanID) ? f.BId : f.AId);
		}

		public static void Seed()
		{
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			RelationState.FeudsSeeded = true;
			List<Citizen> citizenDirectory = CityData.Instance.citizenDirectory;
			List<Citizen> list = (from _ in (IEnumerable<Citizen>)citizenDirectory.ToArray()
				where (Object)(object)_ != (Object)null && !((Actor)_).isDead
				orderby Random.value
				select _).ToList();
			int num = Mathf.Max(1, citizenDirectory.Count / 12);
			int num2 = 0;
			foreach (Citizen a in list)
			{
				if (num2 >= num)
				{
					break;
				}
				if ((Object)(object)((Human)a).home == (Object)null || Of((Human)(object)a) != null)
				{
					continue;
				}
				Human val = Candidate((Human)(object)a, (Human o) => (Object)(object)o.home != (Object)null && o.home.id != ((Human)a).home.id && (Object)(object)((NewGameLocation)o.home).building != (Object)null && (Object)(object)((NewGameLocation)((Human)a).home).building != (Object)null && ((NewGameLocation)o.home).building.buildingID == ((NewGameLocation)((Human)a).home).building.buildingID);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool flag = (Object)(object)((NewGameLocation)((Human)a).home).floor != (Object)null && (Object)(object)((NewGameLocation)val.home).floor != (Object)null && Mathf.Abs(((NewGameLocation)((Human)a).home).floor.floor - ((NewGameLocation)val.home).floor.floor) <= 1;
				Feud f = Create((Human)(object)a, val, "neighbour", (flag && Random.value < 0.5f) ? "noise" : ((Random.value < 0.45f) ? "debt" : "grudge"));
				num2++;
				for (int num3 = 1; num3 <= 2; num3++)
				{
					if (Random.value < 0.5f)
					{
						Slander((Human)(object)a, val, f, Mathf.Floor(Now / 24f) * 24f - 24f * (float)num3 + 22f + Random.Range(1f, 5f));
					}
					if (Random.value < 0.3f)
					{
						Slander(val, (Human)(object)a, f, Mathf.Floor(Now / 24f) * 24f - 24f * (float)num3 + 22f + Random.Range(1f, 5f));
					}
				}
			}
			num = Mathf.Max(1, citizenDirectory.Count / 20);
			num2 = 0;
			foreach (Citizen a2 in list)
			{
				if (num2 >= num)
				{
					break;
				}
				if (((Human)a2).job != null && ((Human)a2).job.employer != null && Of((Human)(object)a2) == null)
				{
					Human val2 = Candidate((Human)(object)a2, (Human o) => o.job != null && o.job.employer != null && o.job.employer.companyID == ((Human)a2).job.employer.companyID);
					if (!((Object)(object)val2 == (Object)null))
					{
						float value = Random.value;
						Create((Human)(object)a2, val2, "work", (value < 0.35f) ? "credit" : ((value < 0.7f) ? "blame" : "promotion"));
						num2++;
					}
				}
			}
			if ((Object)(object)GroupsController.Instance != (Object)null)
			{
				Enumerator<SocialGroup> enumerator2 = GroupsController.Instance.groups.GetEnumerator();
				GroupPreset val3 = default(GroupPreset);
				while (enumerator2.MoveNext())
				{
					SocialGroup current = enumerator2.Current;
					if (current == null || current.members == null || Random.value >= 0.5f || !Toolbox.Instance.groupsDictionary.TryGetValue(current.preset, ref val3) || (int)val3.groupType != 0)
					{
						continue;
					}
					HashSet<int> members = new HashSet<int>((IEnumerable<int>)current.members.ToArray());
					foreach (int item in ((IEnumerable<int>)current.members.ToArray()).OrderBy((int _) => Random.value))
					{
						Human val4 = Gossip.HumanById(item);
						if (!((Object)(object)val4 == (Object)null) && !((Actor)val4).isDead && Of(val4) == null)
						{
							Human val5 = Candidate(val4, (Human o) => members.Contains(o.humanID));
							if (!((Object)(object)val5 == (Object)null))
							{
								Create(val4, val5, "club", (Random.value < 0.5f) ? "leadership" : "insult");
								break;
							}
						}
					}
				}
			}
			Plugin.Debug($"Enemistades: {RelationState.Feuds.Count} (vecinos, trabajo y clubes)");
		}

		private static Human Candidate(Human a, Func<Human, bool> where)
		{
			if (Random.value >= 0.5f)
			{
				return null;
			}
			Human result = null;
			float num = 0.42f;
			Enumerator<Acquaintance> enumerator = a.acquaintances.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Acquaintance current = enumerator.Current;
				Human with = current.with;
				if (!((Object)(object)with == (Object)null) && !((Actor)with).isDead && !((Actor)with).isPlayer && with.humanID != a.humanID && Of(with) == null && where(with) && !(current.like >= num) && !IdentityDialog.IsIntimate(a, with, current))
				{
					result = with;
					num = current.like;
				}
			}
			return result;
		}

		private static Feud Create(Human a, Human b, string kind, string cause)
		{
			Feud feud = new Feud
			{
				AId = a.humanID,
				BId = b.humanID,
				Kind = kind,
				Cause = cause,
				Since = Now
			};
			RelationState.Feuds.Add(feud);
			return feud;
		}

		public static void Tick()
		{
			int num = Mathf.FloorToInt(Now);
			if (num == _lastHour)
			{
				return;
			}
			bool num2 = _lastHour < 0;
			_lastHour = num;
			if (num2)
			{
				return;
			}
			float num3 = (Now % 24f + 24f) % 24f;
			bool flag = num3 >= 23f || num3 < 6f;
			foreach (Feud item in RelationState.Feuds.ToList())
			{
				Human val = Gossip.HumanById(item.AId);
				Human val2 = Gossip.HumanById(item.BId);
				if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || ((Actor)val).isDead || ((Actor)val2).isDead)
				{
					continue;
				}
				if (flag && item.Kind == "neighbour")
				{
					if (Random.value < 0.04f)
					{
						Slander(val, val2, item, Now - Random.Range(0.2f, 1f));
					}
					if (Random.value < 0.04f)
					{
						Slander(val2, val, item, Now - Random.Range(0.2f, 1f));
					}
				}
				else if (Random.value < 0.01f && Now - item.LastMail > 48f)
				{
					item.LastMail = Now;
					Human to;
					Human val4;
					if (!(Random.value < 0.6f))
					{
						Human val3 = val;
						to = val3;
						val4 = val2;
					}
					else
					{
						Human val3 = val2;
						to = val3;
						val4 = val;
					}
					Mails.FeudMail(val4, to, item.Cause);
				}
			}
		}

		private static void Slander(Human liar, Human target, Feud f, float time)
		{
			if (!(liar.agreeableness >= 0.6f) && !((Object)(object)target.home == (Object)null) && !(time >= Now))
			{
				NewAddress home = target.home;
				string cause = f.Cause;
				Rumour rumour = ((cause == "noise") ? (HasCouple(home) ? new Rumour
				{
					Kind = GossipKind.CoupleNoise,
					AddressId = home.id
				} : new Rumour
				{
					Kind = GossipKind.Scream,
					AddressId = home.id,
					Take = "argument"
				}) : ((!(cause == "debt")) ? new Rumour
				{
					Kind = GossipKind.NightVisitor,
					AddressId = home.id,
					Seen = false
				} : new Rumour
				{
					Kind = GossipKind.LateArrival,
					SubjectId = target.humanID,
					AddressId = home.id,
					Seen = true
				}));
				rumour.WitnessId = liar.humanID;
				rumour.Time = time;
				rumour.FabricatedBy = liar.humanID;
				Gossip.AddRumour(rumour);
				Plugin.Debug($"Enemistad: {liar.GetCitizenName()} se inventa {rumour.Kind} sobre {target.GetCitizenName()}");
			}
		}

		private static bool HasCouple(NewAddress a)
		{
			Enumerator<Human> enumerator = a.inhabitants.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Human current = enumerator.Current;
				if ((Object)(object)current != (Object)null && (Object)(object)current.partner != (Object)null && (Object)(object)((Human)current.partner).home != (Object)null && ((Human)current.partner).home.id == a.id)
				{
					return true;
				}
			}
			return false;
		}

		public static string Grievance(Human h)
		{
			Feud feud = Of(h);
			if (feud == null)
			{
				return null;
			}
			bool flag = feud.AId == h.humanID;
			if (flag ? feud.ToldByA : feud.ToldByB)
			{
				return null;
			}
			if (flag)
			{
				feud.ToldByA = true;
			}
			else
			{
				feud.ToldByB = true;
			}
			Human val = Rival(feud, h);
			if ((Object)(object)val == (Object)null || (feud.Kind == "neighbour" && (Object)(object)val.home == (Object)null))
			{
				return null;
			}
			IdentityDialog.Refer(h, val);
			Plugin.Debug($"{h.GetCitizenName()} se queja de su enemigo {val.GetCitizenName()} ({feud.Kind}/{feud.Cause})");
			return string.Format(Texts.Variant("grievance_" + feud.Cause), val.GetCitizenName(), ((Object)(object)val.home != (Object)null) ? Gossip.Place(val.home) : "?");
		}

		private static void PreferRival(MurderController mc)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			Human currentMurderer = mc.currentMurderer;
			if ((Object)(object)currentMurderer == (Object)null || (SoCustomComparison)(object)mc.murderPreset == (SoCustomComparison)null || (SoCustomComparison)(object)mc.chosenMO == (SoCustomComparison)null || (int)mc.murderPreset.caseType == 1)
			{
				return;
			}
			Feud feud = Of(currentMurderer);
			object obj;
			if (feud == null)
			{
				obj = null;
			}
			else
			{
				Human obj2 = Rival(feud, currentMurderer);
				obj = ((obj2 != null) ? ((Il2CppObjectBase)obj2).TryCast<Citizen>() : null);
			}
			Citizen val = (Citizen)obj;
			if ((Object)(object)val == (Object)null || ((Actor)val).isDead || ((Actor)val).isPlayer || ((Actor)val).isHomeless || (Object)(object)((Human)val).home == (Object)null)
			{
				return;
			}
			if ((Object)(object)mc.currentVictim != (Object)null && mc.currentVictim.humanID == ((Human)val).humanID)
			{
				feud.Murderous = true;
				return;
			}
			Enumerator<Human> enumerator = mc.previousMurderers.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Human current = enumerator.Current;
				if ((Object)(object)current != (Object)null && current.humanID == ((Human)val).humanID)
				{
					return;
				}
			}
			if (!(Random.value >= Plugin.FeudMurderChance.Value))
			{
				List<MurdererModifierRule> victimTraitModifiers = mc.chosenMO.victimTraitModifiers;
				float num = default(float);
				if (mc.TraitTest(val, ref victimTraitModifiers, ref num))
				{
					string value = (((Object)(object)mc.currentVictim != (Object)null) ? mc.currentVictim.GetCitizenName() : "nadie");
					mc.currentVictim = (Human)(object)val;
					mc.currentVictimSite = null;
					feud.Murderous = true;
					Plugin.Debug($"Enemistad: {currentMurderer.GetCitizenName()} va a por su enemigo {((Human)val).GetCitizenName()} ({feud.Kind}/{feud.Cause}) en vez de {value}");
				}
			}
		}

		public static string Describe(Human h)
		{
			Feud feud = Of(h);
			Human val = ((feud != null) ? Rival(feud, h) : null);
			if (!((Object)(object)val == (Object)null))
			{
				return $"con {val.GetCitizenName()} ({feud.Kind}, {feud.Cause}){(feud.Murderous ? " · ¡víctima elegida!" : "")}";
			}
			return null;
		}

		private static string Where(Human h)
		{
			if ((Object)(object)h == (Object)null)
			{
				return "?";
			}
			string obj = (((Object)(object)h.home != (Object)null) ? ((((Object)(object)((NewGameLocation)h.home).building != (Object)null) ? ((Object)((NewGameLocation)h.home).building).name : "?") + ", " + Gossip.Place(h.home)) : "sin casa");
			string text = ((h.job != null && h.job.employer != null) ? (" · trabaja en " + h.job.employer.name) : "");
			return obj + text;
		}

		public static void DebugReseed()
		{
			RelationState.Rumours.RemoveAll((Rumour r) => r.FabricatedBy >= 0);
			RelationState.Feuds.Clear();
			Seed();
			IdentityDialog.Notify($"Depuración: {RelationState.Feuds.Count} enemistades creadas");
		}

		public static void DebugDump()
		{
			StringBuilder stringBuilder = new StringBuilder($"Enemistades ({RelationState.Feuds.Count}):");
			foreach (Feud f in RelationState.Feuds)
			{
				Human val = Gossip.HumanById(f.AId);
				Human val2 = Gossip.HumanById(f.BId);
				int value = RelationState.Rumours.Count((Rumour r) => r.FabricatedBy == f.AId || r.FabricatedBy == f.BId);
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(28, 8, stringBuilder2);
				handler.AppendLiteral("\n  ");
				handler.AppendFormatted((val != null) ? val.GetCitizenName() : null);
				handler.AppendLiteral(" (");
				handler.AppendFormatted(Where(val));
				handler.AppendLiteral(") contra ");
				handler.AppendFormatted((val2 != null) ? val2.GetCitizenName() : null);
				handler.AppendLiteral(" (");
				handler.AppendFormatted(Where(val2));
				handler.AppendLiteral("): ");
				handler.AppendFormatted(f.Kind);
				handler.AppendLiteral("/");
				handler.AppendFormatted(f.Cause);
				handler.AppendLiteral(", ");
				handler.AppendFormatted(value);
				handler.AppendLiteral(" bulos");
				handler.AppendFormatted(f.Murderous ? ", ASESINATO" : "");
				stringBuilder2.Append(ref handler);
			}
			Plugin.Debug(stringBuilder.ToString());
			IdentityDialog.Notify($"Depuración: {RelationState.Feuds.Count} enemistades volcadas al log");
		}
	}
	public static class FinesForm
	{
		[HarmonyPatch(typeof(CityConstructor), "StartGame")]
		private static class AddOnStartPatch
		{
			private static void Postfix()
			{
				try
				{
					AddActionToTrays();
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)("Error añadiendo el formulario de multas: " + ex));
				}
			}
		}

		[HarmonyPatch(typeof(Interactable), "UpdateCurrentActions")]
		private static class AvailabilityPatch
		{
			private static void Postfix(Interactable __instance)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Invalid comparison between Unknown and I4
				if ((SoCustomComparison)(object)__instance.preset == (SoCustomComparison)null || (int)__instance.preset.specialCaseFlag != 24)
				{
					return;
				}
				Enumerator<InteractionKey, InteractableCurrentAction> enumerator = __instance.currentActions.GetEnumerator();
				while (enumerator.MoveNext())
				{
					InteractableCurrentAction value = enumerator.Current.Value;
					if (((value != null) ? value.currentAction : null) != null && !(value.currentAction.interactionName != "SodRel_FinesForm"))
					{
						bool enabled = (value.display = RelationState.PendingFines > 0);
						value.enabled = enabled;
					}
				}
			}
		}

		[HarmonyPatch(typeof(Interactable), "OnInteraction", new Type[]
		{
			typeof(InteractionAction),
			typeof(Actor),
			typeof(bool),
			typeof(float)
		})]
		private static class InteractionPatch
		{
			private static bool Prefix(InteractionAction action)
			{
				if (action == null || action.interactionName != "SodRel_FinesForm")
				{
					return true;
				}
				OpenForm();
				return false;
			}
		}

		[HarmonyPatch(typeof(PopupMessageController), "OnButtonPress")]
		private static class ButtonPatch
		{
			private static void Prefix(PopupMessageController __instance, int buttonVal)
			{
				if (_formOpen && __instance.active && buttonVal >= 0 && buttonVal < __instance.buttonActions.Count)
				{
					string text = __instance.buttonActions[buttonVal];
					_formOpen = false;
					if (!(text != "sodrel_pay") && PayAll("formulario del ayuntamiento"))
					{
						Reports.Notify(Texts.Get("msg_fines_paid_form"));
					}
				}
			}
		}

		public const string ActionName = "SodRel_FinesForm";

		public const string PopupKey = "sodrel_fines";

		private const string PayButton = "sodrel_pay";

		private static readonly HashSet<string> PatchedPresets = new HashSet<string>();

		private static bool _formOpen;

		public static bool PayAll(string where)
		{
			int pendingFines = RelationState.PendingFines;
			if (pendingFines <= 0 || GameplayController.Instance.money < pendingFines)
			{
				return false;
			}
			GameplayController.Instance.AddMoney(-pendingFines, true, "Fines");
			bool wanted = RelationState.Wanted;
			RelationState.ClearFines();
			Plugin.Debug($"Multas pagadas ({where}): {pendingFines} (orden de búsqueda anulada: {wanted})");
			return true;
		}

		private static void AddActionToTrays()
		{
			Enumerator<Interactable> enumerator = CityData.Instance.caseTrays.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Interactable current = enumerator.Current;
				if (current != null && !((SoCustomComparison)(object)current.preset == (SoCustomComparison)null))
				{
					InteractablePreset preset = current.preset;
					if (PatchedPresets.Add(((Object)preset).name))
					{
						AddAction(preset);
					}
					current.UpdateCurrentActions();
				}
			}
		}

		private static void AddAction(InteractablePreset preset)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: 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)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Expected O, but got Unknown
			List<InteractionKey> used = new List<InteractionKey>();
			Enumerator<InteractionAction> enumerator = preset.GetActions(0).GetEnumerator();
			while (enumerator.MoveNext())
			{
				InteractionAction current = enumerator.Current;
				used.Add(current.GetInteractionKey());
				Plugin.Debug($"Bandeja '{((Object)preset).name}': acción '{current.interactionName}' en {current.GetInteractionKey()}");
			}
			InteractionKey[] array = new InteractionKey[3];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			InteractionKey val = ((IEnumerable<InteractionKey>)(object)array).FirstOrDefault((Func<InteractionKey, bool>)((InteractionKey k) => !used.Contains(k)));
			if ((int)val == 0)
			{
				ManualLogSource logger = Plugin.Logger;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(65, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("La bandeja '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)preset).name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' no tiene teclas libres para el formulario de multas");
				}
				logger.LogWarning(val2);
				return;
			}
			AIActionPreset val3 = Object.Instantiate<AIActionPreset>(RoutineControls.Instance.getHandIn);
			((Object)val3).name = "SodRel_FinesForm";
			Object.DontDestroyOnLoad((Object)(object)val3);
			InteractionAction val4 = new InteractionAction
			{
				interactionName = "SodRel_FinesForm",
				action = val3,
				useDefaultKeySetting = false,
				keyOverride = val,
				usableByAI = false,
				availableWhileIllegal = true,
				availableWhileWitnessesToIllegal = true
			};
			InteractableActionsPreset val5 = ScriptableObject.CreateInstance<InteractableActionsPreset>();
			((Object)val5).name = "SodRel_FinesForm";
			val5.actions.Add(val4);
			Object.DontDestroyOnLoad((Object)(object)val5);
			preset.actionsPreset.Add(val5);
			Plugin.Debug($"Formulario de multas añadido a '{((Object)preset).name}' en la tecla {val}");
		}

		private static void OpenForm()
		{
			string cityCurrency = CityControls.Instance.cityCurrency;
			float gameTime = SessionData.Instance.gameTime;
			int pendingFines = RelationState.PendingFines;
			bool flag = pendingFines > 0 && GameplayController.Instance.money >= pendingFines;
			StringBuilder stringBuilder = new StringBuilder();
			List<Report> list = RelationState.Reports.Where((Report r) => r.Filed && !r.Paid).ToList();
			if (list.Count == 0)
			{
				stringBuilder.AppendLine(Texts.Get("form_empty"));
			}
			foreach (Report item in list)
			{
				StringBuilder stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder3 = stringBuilder2;
				StringBuilder.AppendInterpolatedStringHandler handler = new StringBuilder.AppendInterpolatedStringHandler(4, 2, stringBuilder2);
				handler.AppendLiteral("• ");
				handler.AppendFormatted(item.WitnessName);
				handler.AppendLiteral(": ");
				handler.AppendFormatted(Reports.Describe(item));
				stringBuilder3.Append(ref handler);
				if (!string.IsNullOrEmpty(item.Address))
				{
					stringBuilder2 = stringBuilder;
					StringBuilder stringBuilder4 = stringBuilder2;
					handler = new StringBuilder.AppendInterpolatedStringHandler(3, 1, stringBuilder2);
					handler.AppendLiteral(" (");
					handler.AppendFormatted(item.Address);
					handler.AppendLiteral(")");
					stringBuilder4.Append(ref handler);
				}
				stringBuilder2 = stringBuilder;
				StringBuilder stringBuilder5 = stringBuilder2;
				handler = new StringBuilder.AppendInterpolatedStringHandler(3, 2, stringBuilder2);
				handler.AppendLiteral(" — ");
				handler.AppendFormatted(cityCurrency);
				handler.AppendFormatted(item.Fine);
				stringBuilder5.Append(ref handler);
				if (item.Surcharged && item.StolenValue > 0)
				{
					stringBuilder.Append(" " + Texts.Get("form_surcharge"));
				}
				stringBuilder.AppendLine();
				if (gameTime < item.DueAt)
				{
					stringBuilder.AppendLine("   " + string.Format(Texts.Get("form_due"), Mathf.CeilToInt(item.DueAt - gameTime)));
				}
				else
				{
					stringBuilder.AppendLine("   " + Texts.Get("form_overdue"));
				}
			}
			stringBuilder.AppendLine();
			stringBuilder.AppendLine(string.Format(Texts.Get("form_total"), cityCurrency + pendingFines));
			if (RelationState.Wanted)
			{
				stringBuilder.AppendLine(Texts.Get("form_wanted"));
			}
			if (pendingFines > 0 && !flag)
			{
				stringBuilder.AppendLine(Texts.Get("form_no_money"));
			}
			StringsPatch.Inject("ui.popups", "sodrel_pay", string.Format(Texts.Get("form_pay"), cityCurrency + pendingFines));
			_formOpen = true;
			PopupMessageController.Instance.PopupMessage("sodrel_fines", true, flag, "Cancel", "sodrel_pay", true, (AffectPauseState)0, false, "", false, false, false, false, "", "", false, "", false, "", stringBuilder.ToString(), false);
		}
	}
	public static class FinesHud
	{
		private const float AmberHours = 12f;

		private const float RedHours = 6f;

		private static readonly Color White = new Color(0.95f, 0.95f, 0.95f, 1f);

		private static readonly Color Amber = new Color(1f, 0.7f, 0.1f, 1f);

		private static readonly Color Red = new Color(1f, 0.2f, 0.15f, 1f);

		private static GameObject _root;

		private static GameObject _panel;

		private static Image _icon;

		private static TextMeshProUGUI _text;

		private static TextMeshProUGUI _extra;

		private static Color _color = White;

		private static bool _pulse;

		private static bool EnsureCreated()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Invalid comparison between Unknown and I4
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_root != (Object)null)
			{
				return true;
			}
			if ((Object)(object)InterfaceControls.Instance == (Object)null || (Object)(object)InterfaceControls.Instance.actionInteractionText == (Object)null)
			{
				return false;
			}
			_root = new GameObject("SodRelFinesHUD");
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 100;
			CanvasScaler obj2 = _root.AddComponent<CanvasScaler>();
			obj2.uiScaleMode = (ScaleMode)1;
			obj2.referenceResolution = new Vector2(1920f, 1080f);
			_panel = new GameObject("Panel");
			_panel.transform.SetParent(_root.transform, false);
			RectTransform obj3 = _panel.AddComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(1f, 1f);
			obj3.pivot = val;
			Vector2 anchorMin = (obj3.anchorMax = val);
			obj3.anchorMin = anchorMin;
			obj3.anchoredPosition = new Vector2(-24f, -24f);
			obj3.sizeDelta = new Vector2(250f, 48f);
			Image obj4 = _panel.AddComponent<Image>();
			((Graphic)obj4).color = new Color(0f, 0f, 0f, 0.6f);
			((Graphic)obj4).raycastTarget = false;
			GameObject val3 = new GameObject("Icon");
			val3.transform.SetParent(_panel.transform, false);
			RectTransform obj5 = val3.AddComponent<RectTransform>();
			((Vector2)(ref val))..ctor(0f, 0.5f);
			obj5.pivot = val;
			anchorMin = (obj5.anchorMax = val);
			obj5.anchorMin = anchorMin;
			obj5.anchoredPosition = new Vector2(8f, 0f);
			obj5.sizeDelta = new Vector2(36f, 36f);
			_icon = val3.AddComponent<Image>();
			((Graphic)_icon).raycastTarget = false;
			_icon.preserveAspect = true;
			Enumerator<IconConfig> enumerator = InterfaceControls.Instance.iconReference.GetEnumerator();
			while (enumerator.MoveNext())
			{
				IconConfig current = enumerator.Current;
				if ((int)current.iconType == 35)
				{
					_icon.sprite = current.sprite;
				}
			}
			GameObject val5 = new GameObject("Text");
			val5.transform.SetParent(_panel.transform, false);
			RectTransform obj6 = val5.AddComponent<RectTransform>();
			obj6.anchorMin = new Vector2(0f, 0f);
			obj6.anchorMax = new Vector2(1f, 1f);
			obj6.offsetMin = new Vector2(52f, 0f);
			obj6.offsetMax = new Vector2(-10f, 0f);
			_text = val5.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_text).font = ((TMP_Text)InterfaceControls.Instance.actionInteractionText).font;
			((TMP_Text)_text).fontSize = 24f;
			((TMP_Text)_text).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)_text).enableWordWrapping = false;
			((Graphic)_text).raycastTarget = false;
			GameObject val6 = new GameObject("Extra");
			val6.transform.SetParent(_panel.transform, false);
			RectTransform obj7 = val6.AddComponent<RectTransform>();
			((Vector2)(ref val))..ctor(1f, 1f);
			obj7.pivot = val;
			anchorMin = (obj7.anchorMax = val);
			obj7.anchorMin = anchorMin;
			obj7.anchoredPosition = new Vector2(-4f, -50f);
			obj7.sizeDelta = new Vector2(120f, 26f);
			_extra = val6.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_extra).font = ((TMP_Text)_text).font;
			((TMP_Text)_extra).fontSize = 20f;
			((TMP_Text)_extra).alignment = (TextAlignmentOptions)4100;
			((TMP_Text)_extra).enableWordWrapping = false;
			((Graphic)_extra).raycastTarget = false;
			_panel.SetActive(false);
			return true;
		}

		public static void Refresh()
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)SessionData.Instance != (Object)null) || !SessionData.Instance.startedGame || RelationState.PendingFines <= 0)
			{
				if ((Object)(object)_panel != (Object)null)
				{
					_panel.SetActive(false);
				}
			}
			else if (EnsureCreated())
			{
				float gameTime = SessionData.Instance.gameTime;
				List<Report> list = RelationState.Reports.Where((Report r) => r.Filed && !r.Paid).ToList();
				float num = ((list.Count > 0) ? (list.Min((Report r) => r.DueAt) - gameTime) : float.MaxValue);
				string text = CityControls.Instance.cityCurrency + RelationState.PendingFines;
				string text2;
				if (RelationState.Wanted || num <= 0f)
				{
					text2 = Texts.Get("hud_wanted");
					_color = Red;
					_pulse = true;
				}
				else
				{
					text2 = $"{Mathf.CeilToInt(num)} h";
					_color = ((num < 6f) ? Red : ((num < 12f) ? Amber : White));
					_pulse = false;
				}
				((TMP_Text)_text).text = text + " · " + text2;
				((TMP_Text)_extra).text = ((list.Count > 1) ? $"+{list.Count - 1}" : "");
				_panel.SetActive(true);
				Animate();
			}
		}

		public static void Animate()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_panel == (Object)null) && _panel.activeSelf)
			{
				Color color = _color;
				if (_pulse)
				{
					color.a = 0.45f + 0.55f * Mathf.Abs(Mathf.Sin(Time.unscaledTime * 3f));
				}
				((Graphic)_text).color = color;
				((Graphic)_icon).color = color;
				((Graphic)_extra).color = color;
			}
		}
	}
	[HarmonyPatch(typeof(DialogController), "ExecuteDialog")]
	internal static class TrustScopePatch
	{
		internal static Citizen Current;

		private static void Prefix(Interactable saysTo)
		{
			Current = ((saysTo != null && (Object)(object)saysTo.isActor != (Object)null) ? ((Il2CppObjectBase)saysTo.isActor).TryCast<Citizen>() : null);
		}

		private static void Postfix(DialogOption dialog, bool __result)
		{
			if ((Object)(object)Current != (Object)null && (SoCustomComparison)(object)((dialog != null) ? dialog.preset : null) != (SoCustomComparison)null && dialog.preset.useSuccessTest && !IdentityDialog.IsOurs(dialog.preset))
			{
				Plugin.Debug($"Pregunta '{((Object)dialog.preset).name}' a {((Human)Current).GetCitizenName()}: {(__result ? "éxito" : "fallo")} (confianza {RelationState.Get((Human)(object)Current).Trust:0.00})");
			}
			Current = null;
		}
	}
	[HarmonyPatch(typeof(UpgradeEffectController), "GetUpgradeEffect")]
	internal static class TrustChancePatch
	{
		private static void Postfix(Effect effect, ref float __result)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			Citizen current = TrustScopePatch.Current;
			if (!((Object)(object)current == (Object)null) && (int)effect == 14)
			{
				float trust = RelationState.Get((Human)(object)current).Trust;
				__result += (trust - 0.5f) * 2f * Plugin.TrustInfluence.Value;
				__result += Detective.CooperationBonus((Human)(object)current);
			}
		}
	}
	[HarmonyPatch(typeof(Strings), "LoadTextFiles")]
	internal static class StringsPatch
	{
		private static void Postfix()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Dictionary<string, DisplayString> val = new Dictionary<string, DisplayString>();
			foreach (KeyValuePair<string, string> item in Texts.All)
			{
				DisplayString val2 = new DisplayString
				{
					displayStr = item.Value,
					alternateStr = item.Value
				};
				val[item.Key.ToLower()] = val2;
			}
			Strings.stringTable["sodrel"] = val;
			Inject("ui.interaction", "SodRel_FinesForm", Texts.Get("action_fines_form"));
			Inject("ui.popups", "sodrel_fines_title", Texts.Get("form_title"));
			Game instance = Game.Instance;
			Plugin.Debug("Textos inyectados (" + ((instance != null) ? instance.language : null) + ")");
		}

		internal static void Inject(string dictionary, string key, string value)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			if (!Strings.stringTable.ContainsKey(dictionary))
			{
				Strings.stringTable[dictionary] = new Dictionary<string, DisplayString>();
			}
			Strings.stringTable[dictionary][key.ToLower()] = new DisplayString
			{
				displayStr = value,
				alternateStr = value
			};
		}
	}
	[HarmonyPatch(typeof(SaveStateController), "CaptureSaveStateAsync")]
	internal static class SavePatch
	{
		private static void Prefix(string path)
		{
			RelationState.Save(path);
		}
	}
	[HarmonyPatch(typeof(CityConstructor), "StartGame")]
	internal static class StartGamePatch
	{
		private static void Prefix()
		{
			Aliases.ResetTraderLog();
			Gossip.Reset();
			Mails.Reset();
			IdentityDialog.ResetReferred();
			RestartSafeController instance = RestartSafeController.Instance;
			if ((Object)(object)instance != (Object)null && instance.loadSaveGame && instance.saveStateFileInfo != null)
			{
				RelationState.Load(((FileSystemInfo)instance.saveStateFileInfo).FullName);
			}
			else
			{
				RelationState.Clear();
			}
		}
	}
	[HarmonyPatch(typeof(InterfaceController), "UpdateAnchoredSpeechPositions")]
	internal static class AnchoredSpeechGuard
	{
		private static void Prefix(InterfaceController __instance)
		{
			List<SpeechBubbleController> anchoredSpeech = __instance.anchoredSpeech;
			for (int num = anchoredSpeech.Count - 1; num >= 0; num--)
			{
				SpeechBubbleController val = anchoredSpeech[num];
				if ((Object)(object)val == (Object)null || (Object)(object)val.bubbleRect == (Object)null)
				{
					anchoredSpeech.RemoveAt(num);
					Plugin.Debug("Bocadillo de texto roto eliminado");
				}
			}
		}
	}
	[HarmonyPatch(typeof(SpeechController), "Speak", new Type[]
	{
		typeof(string),
		typeof(string),
		typeof(bool),
		typeof(bool),
		typeof(bool),
		typeof(float),
		typeof(bool),
		typeof(Color),
		typeof(Human),
		typeof(bool),
		typeof(bool),
		typeof(SideJob),
		typeof(DialogPreset),
		typeof(AISpeechPreset),
		typeof(Interactable),
		typeof(InteractionDialogInstance)
	})]
	internal static class NullSpeechGuard
	{
		private static bool Prefix(string dictionary, string speechEntryRef)
		{
			if (!string.IsNullOrEmpty(dictionary) && !string.IsNullOrEmpty(speechEntryRef))
			{
				return true;
			}
			Plugin.Logger.LogWarning((object)($"Frase descartada sin clave (diccionario '{dictionary}', clave '{speechEntryRef}'):\n" + Environment.StackTrace));
			return false;
		}
	}
	public static class Gossip
	{
		[HarmonyPatch(typeof(Human), "OnRoomChange")]
		private static class RoomChangePatch
		{
			private static void Postfix(Human __instance)
			{
				try
				{
					OnRoomChange(__instance);
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)("Error en cotilleos (cambio de habitación): " + ex));
				}
			}
		}

		[HarmonyPatch(typeof(NewAIController), "HearIllegal")]
		private static class HearPatch
		{
			private static void Postfix(NewAIController __instance, AudioEvent audioEvent, NewNode newInvestigateNode, Actor newTarget)
			{
				try
				{
					OnHear(__instance.human, audioEvent, newInvestigateNode, newTarget);
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)("Error en cotilleos (sonido): " + ex));
				}
			}
		}

		[HarmonyPatch(typeof(Human), "UpdateLastSighting")]
		private static class SightingPatch
		{
			private static void Postfix(Human __instance, Human citizen, bool phoneCall, int isSound)
			{
				try
				{
					Sighting val = default(Sighting);
					if (phoneCall || isSound != 0 || (Object)(object)__instance == (Object)null || (Object)(object)citizen == (Object)null || ((Actor)__instance).isPlayer || ((Actor)citizen).isPlayer || (Object)(object)SessionData.Instance == (Object)null || !SessionData.Instance.startedGame || !__instance.lastSightings.TryGetValue(citizen, ref val) || val == null || !val.poi)
					{
						return;
					}
					(int, int) key = (__instance.humanID, citizen.humanID);
					if (!_lastSuspicious.TryGetValue(key, out var value) || !(Now - value < 6f))
					{
						_lastSuspicious[key] = Now;
						if (!IdentityDialog.IsActiveMurderer(__instance))
						{
							Add(new Rumour
							{
								WitnessId = __instance.humanID,
								SubjectId = citizen.humanID,
								Kind = GossipKind.Suspicious,
								Time = val.time,
								Seen = true,
								Where = SightingPlace(val),
								Running = val.run,
								Drunk = val.drunk
							});
							Plugin.Debug($"Cotilleo: {__instance.GetCitizenName()} ha visto a {citizen.GetCitizenName()} en pleno asesinato");
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Logger.LogError((object)("Error en cotilleos (avistamiento): " + ex));
				}
			}
		}

		private const float LateFrom = 0.5f;

		private const float LateTo = 5.5f;

		private const float NightFrom = 23f;

		private const float NightTo = 6f;

		private const float SeenChance = 0.8f;

		private const float HeardAwakeChance = 0.45f;

		private const float HeardAsleepChance = 0.08f;

		private const int MaxWitnesses = 6;

		private const float CoupleNoiseChance = 0.03f;

		private const float NoiseAwakeChance = 0.6f;

		private const float NoiseAsleepChance = 0.3f;

		private const float ExpireHours = 96f;

		private const int MaxRumours = 2500;

		private const float MinTellTrust = 0.25f;

		private const int MaxToldPerAsk = 1;

		private const float ShareBase = 0.45f;

		private const float ShareTrust = 1.2f;

		private const float ShareExtraversion = 0.15f;

		private const float ShareOpinion = 0.6f;

		private const float ShareSensitive = -0.2f;

		private const float ShareTrivial = 0.15f;

		private const float ReconsiderTrust = 0.1f;

		private const float SpreadBase = 0.04f;

		private const float SpreadExtraversion = 0.12f;

		private const float SpreadMaxAge = 48f;

		private const int MaxHops = 2;

		private static readonly Dictionary<int, int> _lastAddress = new Dictionary<int, int>();

		private static readonly HashSet<(int, int, int)> _seenEntries = new HashSet<(int, int, int)>();

		private static readonly Dictionary<(int, GossipKind), float> _lastHeard = new Dictionary<(int, GossipKind), float>();

		private static int _lastNoiseHour = -1;

		private static int _lastSpreadHour = -1;

		private static float _expireTimer;

		private static readonly Dictionary<(int, int), float> _lastSuspicious = new Dictionary<(int, int), float>();

		private const float MailChance = 0.06f;

		private const float FakeAdmitChance = 0.35f;

		private const float FakeBlameChance = 0.35f;

		private const float MailChanceNosy = 0.06f;

		private const float SameSightingHours = 6f;

		private static readonly Dictionary<int, HashSet<string>> _traits = new Dictionary<int, HashSet<string>>();

		private const float MinLateHours = 3f;

		private const int HabitNights = 7;

		private const float DefaultArrival = 23.5f;

		private const int MaxDiaryPerNight = 2;

		private static readonly Dictionary<(int, int), int> _diaryCount = new Dictionary<(int, int), int>();

		private const int HistoryNights = 3;

		private const float HistoryWitnessChance = 0.4f;

		private const int HistoryMaxWitnesses = 3;

		private const float AffairVisitChance = 0.5f;

		private const float FriendVisitChance = 0.015f;

		private const float LateBase = 0.02f;

		private const float LateExtraversion = 0.06f;

		private const float HistoryNoiseChance = 0.04f;

		private const float ArgumentBase = 0.02f;

		private const float ArgumentDislike = 0.12f;

		private static Dictionary<(int, int), List<Human>> _byFloor;

		private const float RecognizeKnown = 0.5f;

		private static float Now => SessionData.Instance.gameTime;

		internal static bool Has(Human h, string trait)
		{
			if (!_traits.TryGetValue(h.humanID, out var value))
			{
				value = new HashSet<string>();
				Enumerator<Trait> enumerator = h.characterTraits.GetEnumerator();
				while (enumerator.MoveNext())
				{
					Trait current = enumerator.Current;
					if (current != null && (SoCustomComparison)(object)current.trait != (SoCustomComparison)null)
					{
						value.Add(((Object)current.trait).name);
					}
				}
				_traits[h.humanID] = value;
			}
			return value.Contains(trait);
		}

		private static bool Awake(Human c)
		{
			if (((Actor)c).isAsleep)
			{
				return Has(c, "Affliction-Insomnia");
			}
			return true;
		}

		private static float Observant(Human c)
		{
			if (!Has(c, "Char-Nosy"))
			{
				if (!Has(c, "Char-Paranoid"))
				{
					return 1f;
				}
				return 1.2f;
			}
			return 1.5f;
		}

		private static float Hearing(Human c)
		{
			if (!Has(c, "Affliction-HardOfHearing"))
			{
				return 1f;
			}
			return 0.3f;
		}

		private static float Precision(Human c)
		{
			if (!Has(c, "Affliction-MemoryLoss"))
			{
				if (!Has(c, "Quirk-Forgetful"))
				{
					return c.conscientiousness;
				}
				return c.conscientiousness * 0.5f;
			}
			return 0f;
		}

		private static float Memory(Human c)
		{
			if (!((Object)(object)c == (Object)null))
			{
				if (!Has(c, "Affliction-MemoryLoss"))
				{
					if (!Has(c, "Quirk-Forgetful"))
					{
						return 96f;
					}
					return 48f;
				}
				return 24f;
			}
			return 96f;
		}

		public static string WitnessTraits(Human h)
		{
			List<string> list = new List<string>();
			if (Has(h, "Char-Nosy"))
			{
				list.Add("cotilla");
			}
			if (Has(h, "Char-Paranoid"))
			{
				list.Add("paranoico");
			}
			if (Has(h, "Affliction-Insomnia"))
			{
				list.Add("insomnio");
			}
			if (Has(h, "Affliction-HardOfHearing"))
			{
				list.Add("duro de oído");
			}
			if (Has(h, "Affliction-MemoryLoss"))
			{
				list.Add("pérdida de memoria");
			}
			if (Has(h, "Quirk-Forgetful"))
			{
				list.Add("olvidadizo");
			}
			if (Has(h, "Quirk-DiaryKeeper"))
			{
				list.Add("escribe un diario");
			}
			return string.Join(", ", list);
		}

		public static void Reset()
		{
			Feuds.Reset();
			_lastAddress.Clear();
			_seenEntries.Clear();
			_lastHeard.Clear();
			_lastNoiseHour = -1;
			_lastSpreadHour = -1;
			_expireTimer = 0f;
			_traits.Clear();
			_lastSuspicious.Clear();
			_diaryCount.Clear();
		}

		private static float HourOf(float gameTime)
		{
			return (gameTime % 24f + 24f) % 24f;
		}

		private static bool Between(float hour, float from, float to)
		{
			if (!(from <= to))
			{
				if (!(hour >= from))
				{
					return hour < to;
				}
				return true;
			}
			if (hour >= from)
			{
				return hour < to;
			}
			return false;
		}

		internal static int NightIndex(float gameTime)
		{
			return Mathf.FloorToInt((gameTime - 12f) / 24f);
		}

		private static bool IsHome(NewAddress a)
		{
			if ((Object)(object)a != (Object)null && (Object)(object)a.residence != (Object)null)
			{
				return a.inhabitants.Count > 0;
			}
			return false;
		}

		private static bool SameFloor(NewGameLocation loc, NewAddress addr)
		{
			if ((Object)(object)loc != (Object)null && (Object)(object)loc.building != (Object)null && (Object)(object)loc.floor != (Object)null && (Object)(object)((NewGameLocation)addr).building != (Object)null && (Object)(object)((NewGameLocation)addr).floor != (Object)null && loc.building.buildingID == ((NewGameLocation)addr).building.buildingID)
			{
				return loc.floor.floor == ((NewGameLocation)addr).floor.floor;
			}
			return false;
		}

		private static bool AdjacentFloor(NewGameLocation loc, NewAddress addr)
		{
			if ((Object)(object)loc != (Object)null && (Object)(object)loc.building != (Object)null && (Object)(object)loc.floor != (Object)null && (Object)(object)((NewGameLocation)addr).building != (Object)null && (Object)(object)((NewGameLocation)addr).floor != (Object)null && loc.building.buildingID == ((NewGameLocation)addr).building.buildingID)
			{
				return Math.Abs(loc.floor.floor - ((NewGameLocation)addr).floor.floor) == 1;
			}
			return false;
		}

		private static bool HasCoupleHome(NewAddress a)
		{
			Enumerator<Human> enumerator = a.inhabitants.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Human current = enumerator.Current;
				if ((Object)(object)current == (Object)null || (Object)(object)current.partner == (Object)null || !((Actor)current).isHome || !((Actor)current.partner).isHome)
				{
					continue;
				}
				Enumerator<Human> enumerator2 = a.inhabitants.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					Human current2 = enumerator2.Current;
					if ((Object)(object)current2 != (Object)null && current2.humanID == ((Human)current.partner).humanID)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool HasCouple(NewAddress a)
		{
			Enumerator<Human> enumerator = a.inhabitants.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Human current = enumerator.Current;
				if ((Object)(object)current == (Object)null || (Object)(object)current.partner == (Object)null)
				{
					continue;
				}
				Enumerator<Human> enumerator2 = a.inhabitants.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					Human current2 = enumerator2.Current;
					if ((Object)(object)current2 != (Object)null && current2.humanID == ((Human)current.partner).humanID)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static Acquaintance AcquaintanceOf(Human witness, Human subject)
		{
			if ((Object)(object)subject == (Object)null)
			{
				return null;
			}
			Enumerator<Acquaintance> enumerator = witness.acquaintances.GetEnumerator();
			while (enumerator.MoveNext())
			{
				Acquaintance current = enumerator.Current;
				if ((Object)(object)current.with != (Object)null && current.with.humanID == subject.humanID)
				{
					return current;
				}
			}
			return null;
		}

		private static bool Protects(Human witness, Human subject)
		{
			if ((Object)(object)subject == (Object)null)
			{
				return false;
			}
			if (witness.humanID == subject.humanID)
			{
				return true;
			}
			Acquaintance val = AcquaintanceOf(witness, subject);
			if (val == null)
			{
				if (!IdentityDialog.Same((Human)(object)witness.partner, subject))
				{
					return IdentityDialog.Same((Human)(object)witness.paramour, subject);
				}
				return true;
			}
			return IdentityDialog.IsIntimate(witness, subject, val);
		}

		private static void OnRoomChange(Human h)
		{
			if ((Object)(object)h == (Object)null || ((Actor)h).isPlayer || ((Actor)h).isDead || (Object)(object)SessionData.Instance == (Object)null || !SessionData.Instance.startedGame)
			{
				return;
			}
			NewAddress val = (((Object)(object)((Actor)h).currentGameLocation != (Object)null) ? ((Actor)h).currentGameLocation.thisAsAddress : null);
			int num = (((Object)(object)val != (Object)null) ? val.id : (-1));
			int value;
			bool flag = _lastAddress.TryGetValue(h.humanID, out value);
			if (fl