using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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.Reflection;
using LoopsAndWhorls.Model;
using Microsoft.CodeAnalysis;
using SOD.Common;
using SOD.Common.Helpers;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("LoopsAndWhorls")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LoopsAndWhorls")]
[assembly: AssemblyTitle("LoopsAndWhorls")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace LoopsAndWhorls
{
[BepInPlugin("ekem.loopsandwhorls", "Loops & Whorls", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInIncompatibility("m75partialprints")]
public class Plugin : BasePlugin
{
public static ManualLogSource Log { get; private set; }
public static Settings Cfg { get; private set; }
public override void Load()
{
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
Cfg = new Settings(((BasePlugin)this).Config);
new Harmony("ekem.loopsandwhorls").PatchAll();
PrintFile.Install();
City.Install();
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Loops & Whorls");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
}
log.LogInfo(val);
}
}
public class Settings
{
public readonly ConfigEntry<float> Loop;
public readonly ConfigEntry<float> Whorl;
public readonly ConfigEntry<float> Arch;
public readonly ConfigEntry<float> TentedArch;
public readonly ConfigEntry<string> RidgeBands;
public readonly ConfigEntry<bool> OneHand;
public readonly ConfigEntry<float> TargetMedian;
public readonly ConfigEntry<string> WholeFingers;
public readonly ConfigEntry<string> PatternOnlyFingers;
public readonly ConfigEntry<FileScope> Scope;
public readonly ConfigEntry<bool> IncludeEnforcers;
public readonly ConfigEntry<bool> IncludeDead;
public readonly ConfigEntry<bool> CodeTable;
public readonly ConfigEntry<bool> QuickMenu;
public Settings(ConfigFile config)
{
Loop = config.Bind<float>("Patterns", "Loop", 60f, "How common loops (L) are. Weights are relative. Changing them changes every citizen's prints in the city.");
Whorl = config.Bind<float>("Patterns", "Whorl", 30f, "How common whorls (W) are. Weights are relative. Changing them changes every citizen's prints in the city.");
Arch = config.Bind<float>("Patterns", "Arch", 5f, "How common plain arches (A) are. Weights are relative. Changing them changes every citizen's prints in the city.");
TentedArch = config.Bind<float>("Patterns", "TentedArch", 5f, "How common tented arches (T) are. Weights are relative. Changing them changes every citizen's prints in the city.");
RidgeBands = config.Bind<string>("Patterns", "RidgeBands", "15,25,30,20,10", "How common each ridge count band 1 to 5 is for loops and whorls, comma-separated. Arches have no ridge count (0). Weights are relative. Changing them changes every citizen's prints in the city.");
OneHand = config.Bind<bool>("Smudge", "OneHand", true, "A print found at a scene shows fingers of one hand only. Off: any of the ten fingers can show.");
TargetMedian = config.Bind<float>("Smudge", "TargetMedian", 3f, "How many people on file a typical found print should fit. The mod picks how much of a print is readable to match this for your city.");
WholeFingers = config.Bind<string>("Smudge", "WholeFingers", "0", "How many fingers of a found print are fully readable, as a number or a range like 2-3. 0 = pick for the city.");
PatternOnlyFingers = config.Bind<string>("Smudge", "PatternOnlyFingers", "0", "How many fingers show only their pattern (ridge count unreadable), as a number or a range like 1-2. 0 = pick for the city when WholeFingers is 0, otherwise none.");
Scope = config.Bind<FileScope>("File", "Scope", FileScope.Employed, "Whose prints the enforcer lab has on file. Employed: people with a legal job (if their employee records carry prints), enforcers, and anyone booked at a station. Documents: everyone whose prints the game's own documents show; while the government database carries prints, that is the whole city.");
IncludeEnforcers = config.Bind<bool>("File", "IncludeEnforcers", true, "Enforcers are always on file.");
IncludeDead = config.Bind<bool>("File", "IncludeDead", true, "The dead stay on file.");
CodeTable = config.Bind<bool>("Debug", "CodeTable", false, "When a city loads, write every citizen's print code to BepInEx/LoopsAndWhorls-codes.tsv.");
QuickMenu = config.Bind<bool>("Debug", "QuickMenu", false, "Show debug entries in Quick Menu (if installed): print survey.");
}
}
public enum FileScope
{
Employed,
Documents
}
public static class PluginInfo
{
public const string Guid = "ekem.loopsandwhorls";
public const string Name = "Loops & Whorls";
public const string Version = "1.0.0";
}
public static class PrintsApi
{
public static int Version => 1;
public static bool Ready => City.Ready;
public static int CodeLength => 20;
public static int Fingers => 10;
public static char Unknown => '-';
public static string Patterns => new string(Codes.Patterns);
public static string Normalize(string pattern)
{
return Codes.Normalize(pattern);
}
public static string? Problem(string pattern)
{
return Codes.Problem(pattern);
}
public static bool IsValid(string pattern)
{
return Codes.Problem(pattern) == null;
}
public static string? FullCode(int humanID)
{
return Wrap(() => City.CodeOf(City.Find(humanID)));
}
public static string? PrintCode(string evID)
{
return Wrap(delegate
{
if (string.IsNullOrEmpty(evID) || (Object)(object)Toolbox.Instance == (Object)null)
{
return (string)null;
}
Evidence ev = default(Evidence);
return (!Toolbox.Instance.TryGetEvidence(evID, ref ev)) ? null : Smudge.For(ev);
});
}
public static string Format(string code, bool compact)
{
return Codes.Format(code, compact);
}
public static int UnknownFingers(string pattern)
{
return Codes.UnknownFingers(pattern);
}
public static bool Matches(string pattern, string code)
{
return Codes.Matches(Codes.Normalize(pattern), Codes.Normalize(code));
}
public static bool OnFile(int humanID)
{
return Wrap(() => PrintFile.OnFile(City.Find(humanID)));
}
public static int[] Search(string pattern)
{
return Wrap(delegate
{
pattern = Codes.Normalize(pattern);
return (Codes.Problem(pattern) != null) ? Array.Empty<int>() : (from h in PrintFile.Members().Where(delegate(Human h)
{
string text = City.CodeOf(h);
return text != null && Codes.Matches(pattern, text);
})
select h.humanID).ToArray();
}) ?? Array.Empty<int>();
}
public static int FileSize()
{
return Wrap(() => PrintFile.Members().Count);
}
public static bool Book(int humanID)
{
return Wrap(() => PrintFile.Book(humanID));
}
private static T Wrap<T>(Func<T> f)
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
try
{
return f();
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] API call failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
return default(T);
}
}
}
internal static class QuickMenuHook
{
public static IEnumerable<(string id, Func<string?> label, Action run)> Entries()
{
yield return (id: "lw.survey", label: () => (!Plugin.Cfg.QuickMenu.Value) ? null : "L&W: print survey", run: Survey.Run);
}
}
public static class Survey
{
public static void Summary()
{
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_0295: Expected O, but got Unknown
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Expected O, but got Unknown
bool flag = default(bool);
try
{
if (City.Ready)
{
IReadOnlyDictionary<int, string> all = City.All;
Dictionary<string, int> dictionary = (from h in City.Citizens()
select PrintFile.Why(h) into w
where w != null
group w by w).ToDictionary((IGrouping<string, string> g) => g.Key, (IGrouping<string, string> g) => g.Count());
Plugin.Log.LogInfo((object)($"[prints] {CityData.Instance.cityName}: {all.Count} citizens, all codes unique" + ((City.Rehashed > 0) ? $" ({City.Rehashed} re-rolled)" : "") + $"; on file {dictionary.Values.Sum()} ({string.Join(", ", dictionary.Select((KeyValuePair<string, int> kv) => $"{kv.Key} {kv.Value}"))}); " + "employee records " + (PrintFile.EmployeeRecordsHavePrints ? "carry" : "don't carry") + " prints, government database " + (PrintFile.GovDatabaseHasPrints ? "carries" : "doesn't carry") + " them"));
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] found prints show ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Smudge.Describe());
}
log.LogInfo(val);
if (Plugin.Cfg.CodeTable.Value)
{
WriteTable();
}
}
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[prints] summary failed: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
}
log2.LogError(val2);
}
}
public static void Run()
{
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Expected O, but got Unknown
try
{
if (!City.Ready)
{
Plugin.Log.LogInfo((object)"[prints] survey: no city loaded");
return;
}
Summary();
List<string> codes = City.All.Values.ToList();
Dictionary<char, int> dictionary = Codes.Patterns.ToDictionary((char p) => p, (char p) => codes.Sum((string c) => Enumerable.Range(0, 10).Count((int f) => c[f * 2] == p)));
int total = Math.Max(1, dictionary.Values.Sum());
Plugin.Log.LogInfo((object)("[prints] patterns across all fingers: " + string.Join(", ", dictionary.Select((KeyValuePair<char, int> kv) => $"{kv.Key} {100.0 * (double)kv.Value / (double)total:0.#}%"))));
List<string> list = (from g in City.Citizens().Where(PrintFile.IsIllegalWork).GroupBy(delegate(Human h)
{
Occupation job = h.job;
object obj;
if (job == null)
{
obj = null;
}
else
{
Company employer = job.employer;
if (employer == null)
{
obj = null;
}
else
{
CompanyPreset preset = employer.preset;
obj = ((preset != null) ? ((Object)preset).name : null);
}
}
if (obj == null)
{
Occupation job2 = h.job;
object obj2;
if (job2 == null)
{
obj2 = null;
}
else
{
OccupationPreset preset2 = job2.preset;
obj2 = ((preset2 != null) ? ((Object)preset2).name : null);
}
obj = "criminal: " + (string?)obj2;
}
return (string)obj;
})
select $"{g.Key} ({g.Count()})").ToList();
Plugin.Log.LogInfo((object)("[prints] illegal work, kept off file: " + ((list.Count == 0) ? "none" : string.Join(", ", list))));
WriteTable();
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] survey failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
private static void WriteTable()
{
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Expected O, but got Unknown
string text = Path.Combine(Paths.BepInExRootPath, "LoopsAndWhorls-codes.tsv");
StringBuilder stringBuilder = new StringBuilder("humanID\tname\tcode\ton_file\tdead\thomeless\tjob\temployer\n");
foreach (Human item in from h in City.Citizens()
orderby h.humanID
select h)
{
StringBuilder stringBuilder2 = stringBuilder.Append(item.humanID).Append('\t').Append(item.GetCitizenName())
.Append('\t')
.Append(Codes.Format(City.CodeOf(item) ?? "", compact: false))
.Append('\t')
.Append(PrintFile.Why(item) ?? "")
.Append('\t')
.Append(((Actor)item).isDead ? "dead" : "")
.Append('\t')
.Append(((Actor)item).isHomeless ? "homeless" : "")
.Append('\t');
Occupation job = item.job;
object obj;
if (job == null)
{
obj = null;
}
else
{
OccupationPreset preset = job.preset;
obj = ((preset != null) ? ((Object)preset).name : null);
}
if (obj == null)
{
obj = "";
}
StringBuilder stringBuilder3 = stringBuilder2.Append((string?)obj).Append('\t');
Occupation job2 = item.job;
object obj2;
if (job2 == null)
{
obj2 = null;
}
else
{
Company employer = job2.employer;
if (employer == null)
{
obj2 = null;
}
else
{
CompanyPreset preset2 = employer.preset;
obj2 = ((preset2 != null) ? ((Object)preset2).name : null);
}
}
if (obj2 == null)
{
obj2 = "";
}
stringBuilder3.Append((string?)obj2).Append('\n');
}
File.WriteAllText(text, stringBuilder.ToString());
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] codes written to ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
}
log.LogInfo(val);
}
}
}
namespace LoopsAndWhorls.Patches
{
[HarmonyPatch]
internal static class NoFreeLinks
{
private const string BelongsTo = "FingerprintBelongsTo";
private static float _lastOwnerNotice = -999f;
[HarmonyPatch(typeof(InfoWindow), "SpawnFingerprintOwner")]
[HarmonyPrefix]
private static bool OwnerButton()
{
try
{
float realtimeSinceStartup = Time.realtimeSinceStartup;
if (realtimeSinceStartup - _lastOwnerNotice > 3f)
{
_lastOwnerNotice = realtimeSinceStartup;
Lib.GameMessage.Broadcast("Whose print this is, you'll have to work out: compare it with prints you know.", (GameMessageType)0, (Icon)7, (Color?)null, 0f);
}
}
catch
{
}
return false;
}
private static bool IsBelongsTo(Fact fact)
{
if ((SoCustomComparison)(object)((fact != null) ? fact.preset : null) != (SoCustomComparison)null)
{
return ((Object)fact.preset).name == "FingerprintBelongsTo";
}
return false;
}
[HarmonyPatch(typeof(Evidence), "AddFactLink", new Type[]
{
typeof(Fact),
typeof(DataKey),
typeof(bool)
})]
[HarmonyPrefix]
private static bool FactLinkOne(Fact __0)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
try
{
return !IsBelongsTo(__0);
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(33, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] fact link check failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
return true;
}
}
[HarmonyPatch(typeof(Evidence), "AddFactLink", new Type[]
{
typeof(Fact),
typeof(List<DataKey>),
typeof(bool)
})]
[HarmonyPrefix]
private static bool FactLinkMany(Fact __0)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
try
{
return !IsBelongsTo(__0);
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(33, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] fact link check failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
return true;
}
}
[HarmonyPatch(typeof(FactMatches), "MatchCheck")]
[HarmonyPrefix]
private static bool Matches(MatchPreset __0, Evidence __1, Evidence __2, ref bool __result)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Invalid comparison between Unknown and I4
try
{
if (((__0 != null) ? __0.matchConditions : null) == null || ((__1 != null) ? ((Il2CppObjectBase)__1).TryCast<EvidenceFingerprint>() : null) == null || ((__2 != null) ? ((Il2CppObjectBase)__2).TryCast<EvidenceFingerprint>() : null) == null)
{
return true;
}
Enumerator<MatchCondition> enumerator = __0.matchConditions.GetEnumerator();
while (enumerator.MoveNext())
{
if ((int)enumerator.Current == 1)
{
__result = false;
return false;
}
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] match check failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
return true;
}
}
[HarmonyPatch]
internal static class PrintText
{
private static readonly HashSet<string> _traced = new HashSet<string>();
[HarmonyPatch(typeof(EvidenceFingerprint), "GetNameForDataKey")]
[HarmonyPostfix]
private static void Name(EvidenceFingerprint __instance, ref string __result)
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
try
{
string text = Smudge.For((Evidence?)(object)__instance);
if (text != null)
{
__result = Codes.Label(text);
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] print name failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
[HarmonyPatch(typeof(EvidenceFingerprint), "GetNote")]
[HarmonyPrefix]
private static bool Note(EvidenceFingerprint __instance, ref string __result)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
try
{
string text = Smudge.For((Evidence?)(object)__instance);
if (text == null)
{
return true;
}
__result = "<b>Fingerprint</b>\n" + Codes.Grid(text) + "\n\n<size=70%>L loop, W whorl, A arch, T tented arch.\nDigit: ridge count 1-5, arches 0.\n- : can't read it.</size>";
return false;
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] print note failed: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
return true;
}
}
[HarmonyPatch(typeof(EvidenceFingerprintController), "CheckEnabled")]
[HarmonyPostfix]
private static void Card(EvidenceFingerprintController __instance)
{
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Expected O, but got Unknown
try
{
TextMeshProUGUI identifierText = __instance.identifierText;
InfoWindow parentWindow = __instance.parentWindow;
Evidence val = ((parentWindow != null) ? parentWindow.passedEvidence : null);
if ((Object)(object)identifierText == (Object)null || val == null)
{
Trace(val, null, "no text or no evidence");
return;
}
EvidenceCitizen obj = ((Il2CppObjectBase)val).TryCast<EvidenceCitizen>();
Human val2 = ((obj != null) ? obj.witnessController : null) ?? OwnerOf(val) ?? val.writer ?? Subject(val);
if ((Object)(object)val2 == (Object)null)
{
((TMP_Text)identifierText).text = "";
Trace(val, null, "owner not found, caption cleared");
return;
}
bool flag = Known(val);
string text = (flag ? City.CodeOf(val2) : null);
((TMP_Text)identifierText).enableAutoSizing = true;
((TMP_Text)identifierText).fontSizeMin = 6f;
((TMP_Text)identifierText).enableWordWrapping = false;
((TMP_Text)identifierText).text = ((text == null) ? "" : Codes.Format(text, compact: false, twoLines: true));
Trace(val, val2, flag ? "full code shown" : "prints not known, caption cleared");
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag2 = default(bool);
BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag2);
if (flag2)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[prints] citizen card print failed: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<Exception>(ex);
}
log.LogError(val3);
}
}
private static void Trace(Evidence? ev, Human? h, string what)
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003a: Expected O, but got Unknown
string item = (((ev != null) ? ev.evID : null) ?? "null") + what;
if (!_traced.Add(item))
{
return;
}
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(49, 6, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] card ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((ev != null) ? ev.evID : null) ?? "null");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((ev != null) ? ((MemberInfo)((Object)ev).GetIl2CppType()).Name : null) ?? "?");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("), ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("owner ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)(object)h == (Object)null) ? "none" : h.GetCitizenName());
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (writer ");
object obj;
if (ev == null)
{
obj = null;
}
else
{
Human writer = ev.writer;
obj = ((writer != null) ? writer.GetCitizenName() : null);
}
if (obj == null)
{
obj = "none";
}
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((string)obj);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("belongsTo ");
object obj2;
if (ev == null)
{
obj2 = null;
}
else
{
Human belongsTo = ev.belongsTo;
obj2 = ((belongsTo != null) ? belongsTo.GetCitizenName() : null);
}
if (obj2 == null)
{
obj2 = "none";
}
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>((string)obj2);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(what);
}
log.LogInfo(val);
}
private static Human? OwnerOf(Evidence ev)
{
foreach (Human item in City.Citizens())
{
if (((Actor)item).evidenceEntry != null && ((Il2CppObjectBase)((Actor)item).evidenceEntry).Pointer == ((Il2CppObjectBase)ev).Pointer)
{
return item;
}
}
return null;
}
private static Human? Subject(Evidence ev)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Invalid comparison between Unknown and I4
Interactable interactable = ev.interactable;
List<Passed> val = ((interactable != null) ? interactable.pv : null);
if (val == null)
{
return null;
}
Enumerator<Passed> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Passed current = enumerator.Current;
if (current != null && (int)current.varType == 1)
{
return City.Find((int)current.value);
}
}
return null;
}
public static bool Known(Evidence citizen)
{
List<DataKey> tiedKeys = citizen.GetTiedKeys((DataKey)2);
if (tiedKeys != null)
{
if (!tiedKeys.Contains((DataKey)1))
{
return tiedKeys.Contains((DataKey)0);
}
return true;
}
return false;
}
}
}
namespace LoopsAndWhorls.Model
{
public static class City
{
private static uint _seed;
private static Dictionary<int, string>? _codes;
private static Codes.Weights _weights = new Codes.Weights();
public static int Rehashed { get; private set; }
public static bool Ready
{
get
{
CityData instance = CityData.Instance;
if ((Object)(object)instance != (Object)null && instance.citizenDirectory != null && instance.citizenDirectory.Count > 0)
{
return !string.IsNullOrEmpty(instance.seed);
}
return false;
}
}
public static uint Seed
{
get
{
if (!Ensure())
{
return 0u;
}
return _seed;
}
}
public static IReadOnlyDictionary<int, string> All
{
get
{
if (!Ensure())
{
return new Dictionary<int, string>();
}
return _codes;
}
}
public static void Install()
{
Lib.SaveGame.OnBeforeLoad += delegate
{
Reset();
};
Lib.SaveGame.OnBeforeNewGame += delegate
{
Reset();
};
Lib.SaveGame.OnAfterLoad += delegate
{
Survey.Summary();
};
Lib.SaveGame.OnAfterNewGame += delegate
{
Survey.Summary();
};
}
public static void Reset()
{
_codes = null;
Rehashed = 0;
Smudge.Reset();
PrintFile.ResetPresets();
}
public static List<Human> Citizens()
{
List<Human> list = new List<Human>();
CityData instance = CityData.Instance;
List<Citizen> val = ((instance != null) ? instance.citizenDirectory : null);
if (val == null)
{
return list;
}
Enumerator<Citizen> enumerator = val.GetEnumerator();
while (enumerator.MoveNext())
{
Citizen current = enumerator.Current;
if ((Object)(object)current != (Object)null && !((Actor)current).isPlayer)
{
list.Add((Human)(object)current);
}
}
return list;
}
public static Human? Find(int humanID)
{
CityData instance = CityData.Instance;
Dictionary<int, Human> val = ((instance != null) ? instance.citizenDictionary : null);
if (val == null)
{
return null;
}
Human result = default(Human);
if (!val.TryGetValue(humanID, ref result))
{
return null;
}
return result;
}
private static bool Ensure()
{
if (_codes != null)
{
return true;
}
if (!Ready)
{
return false;
}
_seed = Lib.SaveGame.GetUniqueNumber(CityData.Instance.seed);
_weights = Codes.Weights.FromConfig();
Dictionary<int, string> dictionary = new Dictionary<int, string>();
HashSet<string> hashSet = new HashSet<string>();
int num = 0;
foreach (Human item in from h in Citizens()
orderby h.humanID
select h)
{
int num2 = 0;
string text = Codes.Generate(_seed, item.humanID, num2, _weights);
while (hashSet.Contains(text) && num2 < 100)
{
num2++;
num++;
text = Codes.Generate(_seed, item.humanID, num2, _weights);
}
hashSet.Add(text);
dictionary[item.humanID] = text;
}
_codes = dictionary;
Rehashed = num;
Smudge.Calibrate(dictionary.Values.ToList(), _seed);
return true;
}
public static string? CodeOf(Human? h)
{
if ((Object)(object)h == (Object)null || !Ensure())
{
return null;
}
if (_codes.TryGetValue(h.humanID, out string value))
{
return value;
}
return Codes.Generate(_seed, h.humanID, 0, _weights);
}
}
public static class Codes
{
public sealed class Weights
{
public double[] Pattern = new double[4] { 60.0, 30.0, 5.0, 5.0 };
public double[] Bands = new double[5] { 15.0, 25.0, 30.0, 20.0, 10.0 };
public static Weights FromConfig()
{
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_013e: Expected O, but got Unknown
Weights weights = new Weights();
Settings cfg = Plugin.Cfg;
double[] array = new double[4]
{
cfg.Loop.Value,
cfg.Whorl.Value,
cfg.Arch.Value,
cfg.TentedArch.Value
};
if (array.All((double x) => x >= 0.0) && array.Sum() > 0.0)
{
weights.Pattern = array;
}
else
{
Plugin.Log.LogWarning((object)"[prints] pattern weights must be zero or more and not all zero; using 60/30/5/5");
}
try
{
double[] array2 = (from s in cfg.RidgeBands.Value.Split(',')
select double.Parse(s.Trim(), CultureInfo.InvariantCulture)).ToArray();
if (array2.Length != 5 || !array2.All((double x) => x >= 0.0) || !(array2.Sum() > 0.0))
{
throw new FormatException();
}
weights.Bands = array2;
}
catch
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(77, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] RidgeBands '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(cfg.RidgeBands.Value);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' is not five non-negative numbers; using 15,25,30,20,10");
}
log.LogWarning(val);
}
return weights;
}
}
public const int Fingers = 10;
public const int PerHand = 5;
public const int Length = 20;
public const char Unknown = '-';
public static readonly char[] Patterns = new char[4] { 'L', 'W', 'A', 'T' };
private static readonly string[] FingerNames = new string[5] { "thumb", "index", "middle", "ring", "little" };
public static bool IsArch(char p)
{
if (p != 'A')
{
return p == 'T';
}
return true;
}
public static ulong Mix(ulong x)
{
x += 11400714819323198485uL;
x = (x ^ (x >> 30)) * 13787848793156543929uL;
x = (x ^ (x >> 27)) * 10723151780598845931uL;
return x ^ (x >> 31);
}
public static ulong Hash(params ulong[] parts)
{
ulong num = 328287088755uL;
foreach (ulong num2 in parts)
{
num = Mix(num ^ num2);
}
return num;
}
public static ulong Of(string s)
{
ulong num = 14695981039346656037uL;
foreach (char c in s)
{
num ^= c;
num *= 1099511628211L;
}
return num;
}
public static double Unit(ulong h)
{
return (double)(h >> 11) * 1.1102230246251565E-16;
}
private static int Pick(double[] weights, double u)
{
double num = weights.Sum();
double num2 = 0.0;
for (int i = 0; i < weights.Length; i++)
{
num2 += weights[i] / num;
if (u < num2)
{
return i;
}
}
return weights.Length - 1;
}
public static string Generate(uint seed, int humanID, int attempt, Weights w)
{
StringBuilder stringBuilder = new StringBuilder(20);
for (int i = 0; i < 10; i++)
{
ulong num = Hash(seed, (uint)humanID, (ulong)i, (ulong)attempt);
char c = Patterns[Pick(w.Pattern, Unit(Hash(num, 1uL)))];
char value = (IsArch(c) ? '0' : ((char)(49 + Pick(w.Bands, Unit(Hash(num, 2uL))))));
stringBuilder.Append(c).Append(value);
}
return stringBuilder.ToString();
}
public static string Normalize(string s)
{
return new string((from c in (s ?? "").ToUpperInvariant()
where c != ' ' && c != '/' && c != '|' && c != '\n'
select c).ToArray());
}
public static string Finger(string code, int f)
{
return code.Substring(f * 2, 2);
}
public static string Format(string code, bool compact, bool twoLines = false)
{
code = Normalize(code);
if (code.Length != 20)
{
return code;
}
if (compact)
{
List<string> list = (from f in Enumerable.Range(0, 10)
where Finger(code, f) != "--"
select $"{f + 1}:{Finger(code, f)}").ToList();
if (list.Count != 0)
{
return string.Join(" ", list);
}
return "smudged";
}
return Hand(0) + (twoLines ? "\n" : " / ") + Hand(5);
string Hand(int from)
{
return string.Join(" ", from f in Enumerable.Range(@from, 5)
select Finger(code, f));
}
}
public static string Grid(string code)
{
code = Normalize(code);
List<string> list = new List<string>();
for (int i = 0; i < 2; i++)
{
List<string> list2 = (from f in Enumerable.Range(i * 5, 5)
select Finger(code, f)).ToList();
if (!list2.All((string x) => x == "--"))
{
list.Add(((i == 0) ? "R: " : "L: ") + string.Join(" ", list2));
}
}
if (list.Count != 0)
{
return string.Join("\n", list);
}
return "smudged";
}
public static int Visible(string code)
{
return Enumerable.Range(0, 10).Count((int f) => Finger(code, f) != "--");
}
public static string Label(string code)
{
code = Normalize(code);
bool flag = Enumerable.Range(0, 5).Any((int f) => Finger(code, f) != "--");
bool flag2 = Enumerable.Range(5, 5).Any((int f) => Finger(code, f) != "--");
int num = Visible(code);
string text = ((num == 1) ? "1 finger" : $"{num} fingers");
return ((flag && flag2) ? "Fingerprint" : (flag ? "Right hand print" : (flag2 ? "Left hand print" : "Fingerprint"))) + ", " + text;
}
public static string FingerName(int f)
{
return ((f < 5) ? "right " : "left ") + FingerNames[f % 5];
}
public static bool Matches(string pattern, string code)
{
if (pattern.Length != 20 || code.Length != 20)
{
return false;
}
for (int i = 0; i < 20; i++)
{
if (pattern[i] != '-' && pattern[i] != code[i])
{
return false;
}
}
return true;
}
public static int UnknownFingers(string pattern)
{
pattern = Normalize(pattern);
if (pattern.Length != 20)
{
return 10;
}
return Enumerable.Range(0, 10).Count((int f) => pattern[f * 2] == '-' || pattern[f * 2 + 1] == '-');
}
public static string? Problem(string pattern)
{
pattern = Normalize(pattern);
if (pattern.Length != 20)
{
return $"A print is {10} fingers, two characters each ({20} in all); you have {pattern.Length}.";
}
int num = 0;
while (num < 10)
{
char c = pattern[num * 2];
char c2 = pattern[num * 2 + 1];
string text = $"Finger {num + 1} ({FingerName(num)})";
if (c != '-' && Array.IndexOf(Patterns, c) < 0)
{
return text + ": the pattern is L, W, A, T or '-'.";
}
switch (c2)
{
default:
return text + ": the ridge count is 0 to 5 or '-'.";
case '-':
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
if (IsArch(c) && c2 != '-' && c2 != '0')
{
return text + ": arches have no ridge count, so it is 0.";
}
if ((c == 'L' || c == 'W') && c2 == '0')
{
return text + ": loops and whorls have a ridge count of 1 to 5.";
}
num++;
break;
}
}
if (pattern.All((char c3) => c3 == '-'))
{
return "That's all smudge: put in at least one character you can read.";
}
return null;
}
}
public static class PrintFile
{
private sealed class Saved
{
public List<int>? Booked { get; set; }
}
private const string FileName = "loopsandwhorls_booked.json";
private static HashSet<int> _booked = new HashSet<int>();
private static bool? _employeeRecords;
private static bool? _govDatabase;
public static bool EmployeeRecordsHavePrints
{
get
{
bool valueOrDefault = _employeeRecords == true;
if (!_employeeRecords.HasValue)
{
valueOrDefault = PresetHasPrints("employeerecord") || PresetHasPrints("printedemployeerecord");
_employeeRecords = valueOrDefault;
return valueOrDefault;
}
return valueOrDefault;
}
}
public static bool GovDatabaseHasPrints
{
get
{
bool valueOrDefault = _govDatabase == true;
if (!_govDatabase.HasValue)
{
valueOrDefault = PresetHasPrints("printedcitizenfile");
_govDatabase = valueOrDefault;
return valueOrDefault;
}
return valueOrDefault;
}
}
public static int BookedCount => _booked.Count;
public static void Install()
{
Lib.SaveGame.OnBeforeSave += delegate(object? _, SaveGameArgs e)
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_005d: Expected O, but got Unknown
try
{
File.WriteAllText(PathFor(e), JsonSerializer.Serialize(new Saved
{
Booked = _booked.OrderBy((int x) => x).ToList()
}));
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] could not save the booked list: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
};
Lib.SaveGame.OnAfterLoad += delegate(object? _, SaveGameArgs e)
{
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
_booked = new HashSet<int>();
try
{
string path = PathFor(e);
if (File.Exists(path))
{
Saved saved = JsonSerializer.Deserialize<Saved>(File.ReadAllText(path));
if (saved?.Booked != null)
{
_booked = new HashSet<int>(saved.Booked);
}
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] could not read the booked list: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val);
}
};
Lib.SaveGame.OnBeforeNewGame += delegate
{
_booked = new HashSet<int>();
};
Lib.SaveGame.OnBeforeDelete += delegate(object? _, SaveGameArgs e)
{
try
{
string path = PathFor(e);
if (File.Exists(path))
{
File.Delete(path);
}
}
catch
{
}
};
}
private static string PathFor(SaveGameArgs args)
{
return Lib.SaveGame.GetSaveGameDataPath(args, "loopsandwhorls_booked.json");
}
public static void ResetPresets()
{
_employeeRecords = (_govDatabase = null);
}
private static bool PresetHasPrints(string key)
{
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
try
{
Toolbox instance = Toolbox.Instance;
Dictionary<string, EvidencePreset> val = ((instance != null) ? instance.evidencePresetDictionary : null);
EvidencePreset val2 = default(EvidencePreset);
if (val == null || !val.TryGetValue(key, ref val2) || ((val2 != null) ? val2.keyMergeOnDiscovery : null) == null)
{
return false;
}
Enumerator<MergeKeysSetup> enumerator = val2.keyMergeOnDiscovery.GetEnumerator();
while (enumerator.MoveNext())
{
MergeKeysSetup current = enumerator.Current;
if (((current != null) ? current.mergeKeys : null) != null && current.mergeKeys.Contains((DataKey)2))
{
return true;
}
}
}
catch (Exception ex)
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(41, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[prints] could not read the '");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(key);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("' document: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
log.LogWarning(val3);
}
return false;
}
public static bool Book(int humanID)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
if (!_booked.Add(humanID))
{
return false;
}
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] booked ");
Human? obj = City.Find(humanID);
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((obj != null) ? obj.GetCitizenName() : null) ?? humanID.ToString());
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": now on file");
}
log.LogInfo(val);
return true;
}
public static bool IsEnforcer(Human h)
{
if (!((Actor)h).isEnforcer)
{
Occupation job = h.job;
object obj;
if (job == null)
{
obj = null;
}
else
{
Company employer = job.employer;
if (employer == null)
{
obj = null;
}
else
{
CompanyPreset preset = employer.preset;
obj = ((preset != null) ? ((Object)preset).name : null);
}
}
return (string?)obj == "EnforcerBranch";
}
return true;
}
public static bool IsIllegalWork(Human h)
{
Occupation job = h.job;
if (job != null)
{
Company employer = job.employer;
bool? obj;
if (employer == null)
{
obj = null;
}
else
{
CompanyPreset preset = employer.preset;
obj = ((preset != null) ? new bool?(preset.isIllegal) : ((bool?)null));
}
if (obj == true)
{
return true;
}
}
Occupation job2 = h.job;
if (job2 == null)
{
return false;
}
OccupationPreset preset2 = job2.preset;
return ((preset2 != null) ? new bool?(preset2.isCriminal) : ((bool?)null)) == true;
}
public static string? Why(Human? h)
{
if ((Object)(object)h == (Object)null || ((Actor)h).isPlayer)
{
return null;
}
if (((Actor)h).isDead && !Plugin.Cfg.IncludeDead.Value)
{
return null;
}
if (_booked.Contains(h.humanID))
{
return "booked";
}
if (Plugin.Cfg.IncludeEnforcers.Value && IsEnforcer(h))
{
return "enforcer";
}
if (Plugin.Cfg.Scope.Value == FileScope.Documents && GovDatabaseHasPrints)
{
return "government database";
}
if (EmployeeRecordsHavePrints)
{
Occupation job = h.job;
if (((job != null) ? job.employer : null) != null && !IsIllegalWork(h))
{
return "employed";
}
}
return null;
}
public static bool OnFile(Human? h)
{
return Why(h) != null;
}
public static List<Human> Members()
{
return City.Citizens().Where(OnFile).ToList();
}
}
public static class Smudge
{
private static readonly Dictionary<string, string> _cache = new Dictionary<string, string>();
public static int WholeMin { get; private set; } = 2;
public static int WholeMax { get; private set; } = 2;
public static int PatternMin { get; private set; } = 1;
public static int PatternMax { get; private set; } = 2;
public static double Median { get; private set; }
public static bool Auto { get; private set; } = true;
public static int Pool
{
get
{
if (!Plugin.Cfg.OneHand.Value)
{
return 10;
}
return 5;
}
}
public static void Reset()
{
_cache.Clear();
}
private static (int lo, int hi)? Range(string s)
{
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Expected O, but got Unknown
s = (s ?? "").Trim();
if (s == "" || s == "0")
{
return null;
}
string[] array = s.Split('-');
try
{
int num = int.Parse(array[0].Trim(), CultureInfo.InvariantCulture);
int num2 = ((array.Length > 1) ? int.Parse(array[1].Trim(), CultureInfo.InvariantCulture) : num);
if (num2 < num)
{
int num3 = num2;
num2 = num;
num = num3;
}
return (Math.Max(0, num), Math.Max(0, num2));
}
catch
{
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(77, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[prints] '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(s);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' is not a number or a range like 2-3; picking for the city instead");
}
log.LogWarning(val);
return null;
}
}
public static void Calibrate(List<string> codes, uint seed)
{
_cache.Clear();
int pool = Pool;
(int, int)? tuple = Range(Plugin.Cfg.WholeFingers.Value);
(int, int)? tuple2 = Range(Plugin.Cfg.PatternOnlyFingers.Value);
if (tuple.HasValue)
{
Auto = false;
WholeMin = Math.Min(tuple.Value.Item1, pool);
WholeMax = Math.Min(tuple.Value.Item2, pool);
PatternMin = Math.Min(tuple2?.Item1 ?? 0, pool);
PatternMax = Math.Min(tuple2?.Item2 ?? 0, pool);
if (WholeMax + PatternMax == 0)
{
WholeMin = (WholeMax = 1);
}
Median = Estimate(codes, (WholeMin + WholeMax) / 2, (PatternMin + PatternMax) / 2, seed);
return;
}
Auto = true;
double d = Math.Max(1.0, Plugin.Cfg.TargetMedian.Value);
int num2 = 1;
int num3 = 0;
double median = double.MaxValue;
double num4 = double.MaxValue;
for (int i = 1; i <= pool; i++)
{
for (int j = 0; i + j <= pool; j++)
{
double num5 = Estimate(codes, i, j, seed);
double num6 = Math.Abs(Math.Log(num5) - Math.Log(d)) + (double)(i + j) * 0.001;
if (num6 < num4)
{
num4 = num6;
median = num5;
num2 = i;
num3 = j;
}
}
}
WholeMin = (WholeMax = num2);
PatternMin = Math.Max(0, num3 - 1);
PatternMax = Math.Min(pool - num2, num3 + 1);
if (WholeMax + PatternMin == 0)
{
PatternMin = Math.Min(1, PatternMax);
}
Median = median;
}
private static double Estimate(List<string> codes, int a, int b, uint seed)
{
if (codes.Count == 0)
{
return 0.0;
}
int num = Math.Min(120, codes.Count);
List<int> list = new List<int>(num);
List<(int, char)> list2 = new List<(int, char)>(20);
for (int i = 0; i < num; i++)
{
ulong num2 = Codes.Hash(seed, 827675uL, (ulong)a, (ulong)b, (ulong)i);
string text = Apply(codes[(int)(Codes.Mix(num2) % (ulong)codes.Count)], num2, a, a, b, b);
list2.Clear();
for (int j = 0; j < 20; j++)
{
if (text[j] != '-')
{
list2.Add((j, text[j]));
}
}
int num3 = 0;
foreach (string code in codes)
{
bool flag = true;
foreach (var (index, c) in list2)
{
if (code[index] != c)
{
flag = false;
break;
}
}
if (flag)
{
num3++;
}
}
list.Add(num3);
}
list.Sort();
return list[list.Count / 2];
}
private static string Apply(string code, ulong h, int wholeMin, int wholeMax, int patternMin, int patternMax)
{
int pool = Pool;
ulong step = h;
int start = 0;
if (pool == 5)
{
start = (((Next() & 1) != 0L) ? 5 : 0);
}
int[] array = Enumerable.Range(start, pool).ToArray();
for (int num = array.Length - 1; num > 0; num--)
{
int num2 = (int)(Next() % (ulong)(num + 1));
ref int reference = ref array[num];
ref int reference2 = ref array[num2];
int num3 = array[num2];
int num4 = array[num];
reference = num3;
reference2 = num4;
}
int val = wholeMin + (int)(Next() % (ulong)(wholeMax - wholeMin + 1));
int val2 = patternMin + (int)(Next() % (ulong)(patternMax - patternMin + 1));
val = Math.Min(val, pool);
val2 = Math.Min(val2, pool - val);
StringBuilder stringBuilder = new StringBuilder(new string('-', 20));
for (int i = 0; i < val + val2; i++)
{
int num5 = array[i];
stringBuilder[num5 * 2] = code[num5 * 2];
if (i < val)
{
stringBuilder[num5 * 2 + 1] = code[num5 * 2 + 1];
}
}
return stringBuilder.ToString();
ulong Next()
{
return step = Codes.Mix(step);
}
}
private static string Key(Evidence ev)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
Interactable interactable = ev.interactable;
if (interactable != null)
{
Vector3 wPos = interactable.wPos;
return string.Format(CultureInfo.InvariantCulture, "{0},{1},{2}", Mathf.RoundToInt(wPos.x * 100f), Mathf.RoundToInt(wPos.y * 100f), Mathf.RoundToInt(wPos.z * 100f));
}
return ev.evID ?? "";
}
public static string? For(Evidence? ev)
{
if (ev == null || (Object)(object)ev.writer == (Object)null)
{
return null;
}
string text = Key(ev);
string key = ev.writer.humanID + "@" + text;
if (_cache.TryGetValue(key, out string value))
{
return value;
}
string text2 = City.CodeOf(ev.writer);
if (text2 == null)
{
return null;
}
ulong h = Codes.Hash(City.Seed, 91307374uL, (uint)ev.writer.humanID, Codes.Of(text));
string text3 = Apply(text2, h, WholeMin, WholeMax, PatternMin, PatternMax);
_cache[key] = text3;
return text3;
}
public static string Describe()
{
return $"{((Pool == 5) ? "one hand" : "any fingers")}: {Span(WholeMin, WholeMax)} whole + {Span(PatternMin, PatternMax)} pattern-only fingers ({(Auto ? "picked for the city" : "from config")}, median ~{Median:0.#} people fit)";
}
private static string Span(int lo, int hi)
{
if (lo != hi)
{
return $"{lo}-{hi}";
}
return lo.ToString();
}
}
}