using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CityDirectoryPhoneNumbers")]
[assembly: AssemblyConfiguration("IL2CPP")]
[assembly: AssemblyDescription("A small mod to change the city directory to list phone numbers instead of addresses")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5")]
[assembly: AssemblyProduct("CityDirectoryPhoneNumbers")]
[assembly: AssemblyTitle("CityDirectoryPhoneNumbers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 CityDirectoryPhoneNumbers
{
[BepInPlugin("CityDirectoryPhoneNumbers", "CityDirectoryPhoneNumbers", "1.0.5")]
public class CityDirectoryPhoneNumbersPlugin : BasePlugin
{
[HarmonyPatch(typeof(CityData), "CreateCityDirectory")]
public class CityData_CreateCityDirectory
{
public static void Postfix(CityData __instance)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_03ae: Unknown result type (might be due to invalid IL or missing references)
//IL_03b4: Expected O, but got Unknown
ManualLogSource pluginLogger = PluginLogger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(64, 0, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CityDirectoryPhoneNumbersPlugin: Started updating city directory");
}
pluginLogger.LogInfo(val);
Dictionary<string, int> currentLinkToPhoneNumber = new Dictionary<string, int>();
Enumerator<Company> enumerator = CityData.Instance.companyDirectory.GetEnumerator();
while (enumerator.MoveNext())
{
Company current = enumerator.Current;
if (GetPhoneEntry((current != null) ? current.address : null, out var evidenceLink) && ((current != null) ? current.name : null) != null)
{
currentLinkToPhoneNumber[current.name] = evidenceLink;
}
}
Enumerator<NewAddress> enumerator2 = CityData.Instance.addressDirectory.GetEnumerator();
while (enumerator2.MoveNext())
{
NewAddress current2 = enumerator2.Current;
if (GetPhoneEntry(current2, out var evidenceLink2))
{
currentLinkToPhoneNumber[((Object)current2).name] = evidenceLink2;
}
}
Enumerator<Citizen> enumerator3 = CityData.Instance.citizenDirectory.GetEnumerator();
Chapter val3 = default(Chapter);
int num = default(int);
while (enumerator3.MoveNext())
{
Citizen current3 = enumerator3.Current;
if (Object.op_Implicit((Object)(object)ChapterController.Instance.chapterScript))
{
ChapterIntro val2 = (ChapterIntro)((dynamic)ChapterController.Instance.chapterScript).Cast<ChapterIntro>();
if (Toolbox.Instance.IsStoryMissionActive(ref val3, ref num))
{
int? obj;
if (val2 == null)
{
obj = null;
}
else
{
Human kidnapper = val2.kidnapper;
obj = ((kidnapper != null) ? new int?(kidnapper.humanID) : null);
}
if (obj == ((current3 != null) ? new int?(((Human)current3).humanID) : null))
{
continue;
}
}
}
if (GetPhoneEntry((current3 != null) ? ((Human)current3).home : null, out var _))
{
List<DataKey> val4 = new List<DataKey>();
val4.Add((DataKey)40);
val4.Add((DataKey)33);
if (ShowAddressInCitizenCard.Value)
{
val4.Add((DataKey)14);
}
LinkData val5 = Strings.AddOrGetLink((Evidence)(object)((Actor)current3).evidenceEntry, val4);
currentLinkToPhoneNumber[((Human)current3).GetInitialledName()] = val5.id;
}
}
List<int> list = new List<int>();
Enumerator<int, string> enumerator4 = __instance.cityDirText.GetEnumerator();
while (enumerator4.MoveNext())
{
KeyValuePair<int, string> current4 = enumerator4.Current;
list.Add(current4.Key);
}
for (int i = 0; i < list.Count; i++)
{
int num2 = list[i];
__instance.cityDirText[num2] = Regex.Replace(__instance.cityDirText[num2], "<link=(\\d+)>(.*)</link>", delegate(Match match)
{
string value = match.Groups[2].Value;
return currentLinkToPhoneNumber.ContainsKey(value) ? $"<link={currentLinkToPhoneNumber[value]}>{match.Groups[2].Value}</link>" : match.Groups[0].Value;
});
}
ManualLogSource pluginLogger2 = PluginLogger;
val = new BepInExInfoLogInterpolatedStringHandler(55, 0, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CityDirectoryPhoneNumbersPlugin: Updated city directory");
}
pluginLogger2.LogInfo(val);
}
private static bool GetPhoneEntry(NewAddress phoneAddress, out int evidenceLink)
{
LinkData val = null;
evidenceLink = -1;
if (phoneAddress != null && ((NewGameLocation)phoneAddress).telephones?.Count > 0)
{
val = Strings.AddOrGetLink((Evidence)(object)((NewGameLocation)phoneAddress).telephones[0].telephoneEntry, (List<DataKey>)null);
if (val != null)
{
evidenceLink = val.id;
}
}
return val != null && evidenceLink != -1;
}
}
[HarmonyPatch(typeof(ChapterController), "LoadPart", new Type[]
{
typeof(int),
typeof(bool),
typeof(bool)
})]
public class ChapterController_LoadPart
{
public static void Postfix()
{
Chapter val = default(Chapter);
int num = default(int);
if (Toolbox.Instance.IsStoryMissionActive(ref val, ref num))
{
CityData.Instance.CreateCityDirectory();
}
}
}
public static ManualLogSource PluginLogger;
private static ConfigEntry<bool> ShowAddressInCitizenCard;
public override void Load()
{
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Expected O, but got Unknown
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Expected O, but got Unknown
PluginLogger = ((BasePlugin)this).Log;
ShowAddressInCitizenCard = ((BasePlugin)this).Config.Bind<bool>("General", "Should the directory entry for citizens also include their address?", false, (ConfigDescription)null);
ManualLogSource pluginLogger = PluginLogger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CityDirectoryPhoneNumbers");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
}
pluginLogger.LogInfo(val);
Harmony val2 = new Harmony("CityDirectoryPhoneNumbers");
val2.PatchAll();
ManualLogSource pluginLogger2 = PluginLogger;
val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CityDirectoryPhoneNumbers");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is patched!");
}
pluginLogger2.LogInfo(val);
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "CityDirectoryPhoneNumbers";
public const string PLUGIN_NAME = "CityDirectoryPhoneNumbers";
public const string PLUGIN_VERSION = "1.0.5";
}
}