Decompiled source of VisitorCalendar v0.1.0

plugins/VisitorCalendar.dll

Decompiled an hour ago
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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using SuperFantasyKingdom;
using SuperFantasyKingdom.UI;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.Localization;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VisitorCalendar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+2eb064573b6403264e078cdf6ae85607bf3b05a0")]
[assembly: AssemblyProduct("VisitorCalendar")]
[assembly: AssemblyTitle("VisitorCalendar")]
[assembly: InternalsVisibleTo("CalendarChecks")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace VisitorCalendar;

internal static class CalendarShortcut
{
	internal const string OpenAction = "Game/Calendar";

	internal const string KeyboardBackAction = "Overlay/Calendar";

	internal static bool CanAdvertise(bool dayButtonEnabled, bool worldInteractable, bool cheats, bool leftControl)
	{
		if (dayButtonEnabled && worldInteractable && !cheats)
		{
			return !leftControl;
		}
		return false;
	}
}
internal static class CalendarUi
{
	internal static readonly Color Panel = new Color(0.11f, 0.13f, 0.17f, 0.97f);

	internal static readonly Color Gold = new Color(1f, 0.85f, 0.48f);

	internal static readonly Color Mint = new Color(0.63f, 0.94f, 0.67f);

	internal static RectTransform Rect(Transform parent, string name, Vector2 size, Vector2 position)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: 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_0032: 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: Expected O, but got Unknown
		RectTransform val = (RectTransform)new GameObject(name, new Type[1] { typeof(RectTransform) }).transform;
		((Transform)val).SetParent(parent, false);
		val.sizeDelta = size;
		val.anchoredPosition = position;
		return val;
	}

	internal static Image Image(RectTransform rect, Color color, bool raycast = false)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		Image obj = ((Component)rect).gameObject.AddComponent<Image>();
		((Graphic)obj).color = color;
		((Graphic)obj).raycastTarget = raycast;
		return obj;
	}

	internal static TextMeshProUGUI Label(RectTransform rect, TMP_FontAsset font, float size)
	{
		TextMeshProUGUI val = ((Component)rect).gameObject.AddComponent<TextMeshProUGUI>();
		if ((Object)(object)font != (Object)null)
		{
			((TMP_Text)val).font = font;
		}
		((TMP_Text)val).fontSize = size;
		((TMP_Text)val).enableAutoSizing = true;
		((TMP_Text)val).fontSizeMin = size * 0.72f;
		((TMP_Text)val).fontSizeMax = size;
		((TMP_Text)val).alignment = (TextAlignmentOptions)514;
		((Graphic)val).raycastTarget = false;
		return val;
	}

	internal static string Binding(string actionPath)
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		GamepadManager instance = GamepadManager.Instance;
		PlayerInput val = ((instance != null) ? instance.GetPlayerInput() : null);
		InputAction val2 = ((val != null) ? val.actions.FindAction(actionPath, false) : null);
		if (val2 == null || !val2.enabled)
		{
			return "";
		}
		int bindingIndex = InputActionRebindingExtensions.GetBindingIndex(val2, val.currentControlScheme, (string)null);
		if (bindingIndex < 0)
		{
			return "";
		}
		InputBinding val3 = val2.bindings[bindingIndex];
		string effectivePath = ((InputBinding)(ref val3)).effectivePath;
		if (string.IsNullOrEmpty(effectivePath))
		{
			return "";
		}
		if (effectivePath.StartsWith("*"))
		{
			Enumerator<InputControl> enumerator = val2.controls.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					InputControl current = enumerator.Current;
					if (((IEnumerable<InputDevice>)(object)val.devices).Contains(current.device))
					{
						return current.shortDisplayName ?? current.displayName;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
			}
		}
		return InputActionRebindingExtensions.GetBindingDisplayString(val2, bindingIndex, (DisplayStringOptions)0);
	}

	internal static string WithBinding(string action, string label)
	{
		string text = Binding(action);
		if (!string.IsNullOrEmpty(text))
		{
			return label + "  [" + text + "]";
		}
		return label;
	}
}
internal sealed class CalendarView : MonoBehaviour
{
	private Schedule schedule;

	private readonly Dictionary<int, Button> days = new Dictionary<int, Button>();

	private LocalizedString boss;

	private LocalizedString dayTitle;

	private Transform grid;

	private GameObject last;

	private TMP_FontAsset font;

	private RectTransform details;

	private Image portrait;

	private TextMeshProUGUI heading;

	private TextMeshProUGUI nameLabel;

	private TextMeshProUGUI status;

	private Button back;

	private Button previous;

	private Button next;

	private int inspected;

	private int index;

	private List<Actors> choices;

	private bool lastWasVisible;

	private int consumedFrame = -1;

	private int openedFrame;

	private bool initialFocusPending;

	internal void Bind(Transform cells, GameObject finalDay, LocalizedString bossTitle, LocalizedString title)
	{
		if (!((Object)(object)grid != (Object)null))
		{
			grid = cells;
			last = finalDay;
			dayTitle = title;
			boss = bossTitle;
			schedule = Visitors.Read();
			for (int i = 0; i < Mathf.Min(28, cells.childCount); i++)
			{
				BindDay(i + 1, cells.GetChild(i));
			}
			if (last.transform.childCount > 0)
			{
				BindDay(29, last.transform.GetChild(0));
			}
			SelectToday();
		}
	}

	private void BindDay(int day, Transform cell)
	{
		//IL_00c4: 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_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: 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)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Expected O, but got Unknown
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		Button component = ((Component)cell).GetComponent<Button>();
		if ((Object)(object)component == (Object)null)
		{
			return;
		}
		days.Add(day, component);
		if ((Object)(object)font == (Object)null)
		{
			Transform obj = cell.Find("Day");
			object obj2;
			if (obj == null)
			{
				obj2 = null;
			}
			else
			{
				TextMeshProUGUI component2 = ((Component)obj).GetComponent<TextMeshProUGUI>();
				obj2 = ((component2 != null) ? ((TMP_Text)component2).font : null);
			}
			font = (TMP_FontAsset)obj2;
		}
		List<Actors> list = schedule.ForDay(day);
		Transform val = cell.Find("Image");
		if ((Object)(object)val != (Object)null && day < 29)
		{
			((Component)val).gameObject.SetActive(false);
		}
		if (list.Count == 0)
		{
			return;
		}
		RectTransform parent = CalendarUi.Rect(cell, "Visitor portraits", new Vector2(44f, 24f), new Vector2(0f, -6f));
		int num = Mathf.Min(list.Count, 3);
		int num2 = Mathf.Min(24, 44 / num);
		for (int i = 0; i < num; i++)
		{
			RectTransform rect = CalendarUi.Rect((Transform)(object)parent, ((object)list[i]/*cast due to .constrained prefix*/).ToString(), new Vector2((float)num2, (float)num2), new Vector2(((float)i - (float)(num - 1) / 2f) * (float)num2, 0f));
			Sprite val2 = Visitors.Portrait(list[i]);
			string text = Schedule.CellMarker((Object)(object)val2 != (Object)null, i, list.Count);
			if (text != null)
			{
				TextMeshProUGUI obj3 = CalendarUi.Label(rect, font, num2);
				((TMP_Text)obj3).text = text;
				((Graphic)obj3).color = CalendarUi.Gold;
			}
			else
			{
				Image obj4 = CalendarUi.Image(rect, Color.white);
				obj4.sprite = val2;
				obj4.preserveAspect = true;
			}
		}
		((UnityEvent)component.onClick).AddListener((UnityAction)delegate
		{
			Inspect(day);
		});
	}

	internal void SelectToday()
	{
		openedFrame = Time.frameCount;
		initialFocusPending = true;
		if (days.TryGetValue(schedule.Today, out var value) && ((Behaviour)value).isActiveAndEnabled)
		{
			Plugin.Focus(((Component)value).gameObject);
			Hover(schedule.Today);
		}
	}

	internal void KeyboardToggle()
	{
		if (openedFrame != Time.frameCount && consumedFrame != Time.frameCount && !GamepadManager.Instance.IsGamepadInUse())
		{
			PlayerInput playerInput = GamepadManager.Instance.GetPlayerInput();
			InputAction val = ((playerInput != null) ? playerInput.actions.FindAction("Overlay/Calendar", false) : null);
			if (val != null && val.WasPerformedThisFrame())
			{
				OverlayManager.Instance.Cancel(true);
			}
		}
	}

	private void LateUpdate()
	{
		EventSystem current = EventSystem.current;
		GameObject val = ((current != null) ? current.currentSelectedGameObject : null);
		if ((initialFocusPending || (Object)(object)val == (Object)null || Plugin.IsPreviousFocus(val)) && (Object)(object)grid != (Object)null && OverlayManager.Instance.IsCalendarOpen() && days.TryGetValue(schedule.Today, out var value))
		{
			if ((Object)(object)details != (Object)null && ((Component)details).gameObject.activeInHierarchy)
			{
				Plugin.Focus(((Component)back).gameObject);
			}
			else if (((Behaviour)value).isActiveAndEnabled && ((Selectable)value).IsInteractable())
			{
				Plugin.Focus(((Component)value).gameObject);
				initialFocusPending = false;
			}
		}
		else if ((Object)(object)val != (Object)null && val.transform.IsChildOf(((Component)this).transform) && (Object)(object)GamepadManager.Instance.GetGameObjectToSelect() != (Object)(object)val)
		{
			GamepadManager.Instance.SetGameObjectToSelect(val, true);
		}
	}

	internal bool Hover(int day)
	{
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: 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_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: 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_01b2: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: 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)
		if (!days.ContainsKey(day))
		{
			return false;
		}
		if ((Object)(object)details != (Object)null && ((Component)details).gameObject.activeSelf)
		{
			return true;
		}
		string text = dayTitle.GetLocalizedString(new object[1] { day.ToString() });
		if (day <= 28 && day % 7 == 0)
		{
			text = text + "\n" + boss.GetLocalizedString();
		}
		List<Actors> list = schedule.ForDay(day);
		if (list.Count == 0)
		{
			text += "\nNo Known Appointments";
		}
		else
		{
			foreach (Actors item in list)
			{
				text = text + "\n" + Visitors.Title(item);
				text = text + "  ·  " + schedule.Status(day, item, day == schedule.Today && VisitState.IsClaimed(item));
			}
			text += "\nSelect day to inspect";
		}
		RectTransform val = (RectTransform)grid;
		Rect rect = val.rect;
		float num = ((Rect)(ref rect)).xMin - 16f;
		rect = val.rect;
		Vector3 val2 = ((Transform)val).TransformPoint(new Vector3(num, ((Rect)(ref rect)).center.y));
		TooltipManager instance = TooltipManager.Instance;
		instance.StopFollowMouse();
		if (val2.x >= 200f * SettingsManager.Instance.GetUIScaling())
		{
			instance.SetAnchor((AnchorPresets)5);
		}
		else
		{
			instance.SetAnchor((AnchorPresets)1);
			rect = val.rect;
			float x = ((Rect)(ref rect)).center.x;
			rect = val.rect;
			val2 = ((Transform)val).TransformPoint(new Vector3(x, ((Rect)(ref rect)).yMin - 16f));
		}
		instance.Display(text, val2, false);
		return true;
	}

	private void Inspect(int day)
	{
		choices = schedule.ForDay(day);
		if (choices.Count != 0)
		{
			inspected = day;
			index = 0;
			if ((Object)(object)details == (Object)null)
			{
				CreateDetails();
			}
			lastWasVisible = last.activeSelf;
			((Component)grid).gameObject.SetActive(false);
			last.SetActive(false);
			((Component)details).gameObject.SetActive(true);
			TooltipManager.Instance.Hide();
			Display();
			Plugin.Focus(((Component)back).gameObject);
		}
	}

	private void CreateDetails()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: 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_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Expected O, but got Unknown
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: Expected O, but got Unknown
		//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Expected O, but got Unknown
		RectTransform val = (RectTransform)grid;
		details = CalendarUi.Rect(grid.parent, "Appointment", val.sizeDelta, val.anchoredPosition);
		details.anchorMin = val.anchorMin;
		details.anchorMax = val.anchorMax;
		details.pivot = val.pivot;
		details.anchoredPosition = val.anchoredPosition;
		LayoutElement obj = ((Component)details).gameObject.AddComponent<LayoutElement>();
		Rect rect = val.rect;
		obj.preferredWidth = ((Rect)(ref rect)).width;
		rect = val.rect;
		obj.preferredHeight = ((Rect)(ref rect)).height;
		CalendarUi.Image(details, CalendarUi.Panel, raycast: true);
		heading = Text("Day", 82f, 24);
		portrait = CalendarUi.Image(CalendarUi.Rect((Transform)(object)details, "Portrait", new Vector2(66f, 66f), new Vector2(0f, 28f)), Color.white);
		portrait.preserveAspect = true;
		nameLabel = Text("Visitor", -22f, 24);
		status = Text("Status", -53f, 18);
		previous = Control("Previous", -122f, (UnityAction)delegate
		{
			index--;
			Display();
		});
		back = Control("Back", 0f, (UnityAction)delegate
		{
			Back();
		});
		next = Control("Next", 122f, (UnityAction)delegate
		{
			index++;
			Display();
		});
	}

	private TextMeshProUGUI Text(string name, float y, int size)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		return CalendarUi.Label(CalendarUi.Rect((Transform)(object)details, name, new Vector2(404f, 35f), new Vector2(0f, y)), font, size);
	}

	private Button Control(string title, float x, UnityAction action)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: 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)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = CalendarUi.Rect((Transform)(object)details, title, new Vector2(104f, 34f), new Vector2(x, -93f));
		Image targetGraphic = CalendarUi.Image(val, Color.white, raycast: true);
		Button obj = ((Component)val).gameObject.AddComponent<Button>();
		((Selectable)obj).targetGraphic = (Graphic)(object)targetGraphic;
		ColorBlock colors = ((Selectable)obj).colors;
		((ColorBlock)(ref colors)).normalColor = new Color(0.22f, 0.26f, 0.32f);
		Color val2 = default(Color);
		((Color)(ref val2))..ctor(0.4f, 0.45f, 0.53f);
		((ColorBlock)(ref colors)).highlightedColor = val2;
		((ColorBlock)(ref colors)).selectedColor = val2;
		((Selectable)obj).colors = colors;
		((TMP_Text)CalendarUi.Label(CalendarUi.Rect((Transform)(object)val, "Label", val.sizeDelta, Vector2.zero), font, 17f)).text = title;
		((UnityEvent)obj.onClick).AddListener(action);
		return obj;
	}

	private void Display()
	{
		//IL_0042: 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)
		//IL_00c4: 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_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		if (index < 0)
		{
			index = choices.Count - 1;
		}
		if (index >= choices.Count)
		{
			index = 0;
		}
		Actors val = choices[index];
		((TMP_Text)heading).text = dayTitle.GetLocalizedString(new object[1] { inspected.ToString() }) + ((choices.Count > 1) ? ("  ·  " + (index + 1) + "/" + choices.Count) : "");
		((Graphic)heading).color = CalendarUi.Gold;
		portrait.sprite = Visitors.Portrait(val);
		((Behaviour)portrait).enabled = (Object)(object)portrait.sprite != (Object)null;
		((TMP_Text)nameLabel).text = Visitors.Title(val);
		bool flag = inspected == schedule.Today && VisitState.IsClaimed(val);
		((TMP_Text)status).text = schedule.Status(inspected, val, flag);
		((Graphic)status).color = (flag ? CalendarUi.Mint : Color.white);
		((Component)previous).gameObject.SetActive(choices.Count > 1);
		((Component)next).gameObject.SetActive(choices.Count > 1);
		Link(back, previous, next);
		Link(previous, next, back);
		Link(next, back, previous);
	}

	private static void Link(Button button, Button left, Button right)
	{
		//IL_0002: 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_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		Navigation val = default(Navigation);
		((Navigation)(ref val)).mode = (Mode)4;
		Navigation navigation = val;
		((Navigation)(ref navigation)).selectOnLeft = (Selectable)(object)(((Component)left).gameObject.activeSelf ? left : button);
		((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)(((Component)right).gameObject.activeSelf ? right : button);
		Selectable selectOnUp = (((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)button);
		((Navigation)(ref navigation)).selectOnUp = selectOnUp;
		((Selectable)button).navigation = navigation;
	}

	internal bool Back()
	{
		if (consumedFrame == Time.frameCount)
		{
			return true;
		}
		if ((Object)(object)details == (Object)null || !((Component)details).gameObject.activeSelf)
		{
			return false;
		}
		consumedFrame = Time.frameCount;
		((Component)details).gameObject.SetActive(false);
		((Component)grid).gameObject.SetActive(true);
		last.SetActive(lastWasVisible);
		Plugin.Focus(((Component)days[inspected]).gameObject);
		return true;
	}
}
internal enum CaravanDecision
{
	Unavailable,
	Pending,
	Declined,
	Claimed
}
internal static class CaravanReplay
{
	internal static CaravanDecision Read(object visit)
	{
		if (visit == null)
		{
			return CaravanDecision.Unavailable;
		}
		Type type = visit.GetType();
		if (!(type.GetField("kingdom")?.GetValue(visit) is int num) || num < 0)
		{
			return CaravanDecision.Unavailable;
		}
		FieldInfo field = type.GetField("selected");
		if (field?.FieldType != typeof(string))
		{
			return CaravanDecision.Unavailable;
		}
		if (!string.IsNullOrEmpty((string)field.GetValue(visit)))
		{
			return CaravanDecision.Claimed;
		}
		if (!object.Equals(type.GetField("declined")?.GetValue(visit), true))
		{
			return CaravanDecision.Pending;
		}
		return CaravanDecision.Declined;
	}
}
internal struct CardResolution
{
	internal Actors Actor;

	internal bool Confirmed;

	internal void Finish(HashSet<Actors> claims, bool completed)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		if (completed && Confirmed && (int)Actor != 0)
		{
			claims.Add(Actor);
		}
	}
}
internal sealed class DayBadge : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
{
	private RectTransform panel;

	private TMP_FontAsset font;

	private float refresh;

	private bool shortcutVisible;

	private GameInputManager mapInput;

	private static readonly FieldRef<GameInputManager, Button> NativeCalendarButton = AccessTools.FieldRefAccess<GameInputManager, Button>("calendarButton");

	private string lastKey;

	private RectTransform foodDropdown;

	private readonly Vector3[] corners = (Vector3[])(object)new Vector3[4];

	internal static void Attach(Transform day)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		RectTransform val = CalendarUi.Rect(day, "Visitor Calendar", new Vector2(122f, 25f), Vector2.zero);
		val.pivot = new Vector2(1f, 1f);
		Vector2 val2 = default(Vector2);
		((Vector2)(ref val2))..ctor(1f, 0f);
		val.anchorMax = val2;
		val.anchorMin = val2;
		val.anchoredPosition = new Vector2(0f, -2f);
		if ((Object)(object)((Component)day).GetComponent<UIClockButtonDay>() != (Object)null)
		{
			val2 = (val.anchorMin = (val.anchorMax = Vector2.zero));
			val.anchoredPosition = new Vector2(-8f, -2f);
		}
		DayBadge dayBadge = ((Component)val).gameObject.AddComponent<DayBadge>();
		dayBadge.panel = val;
		dayBadge.mapInput = Object.FindObjectOfType<GameInputManager>();
		Transform parent = day.parent;
		while ((Object)(object)parent != (Object)null && (Object)(object)dayBadge.foodDropdown == (Object)null)
		{
			ref RectTransform reference = ref dayBadge.foodDropdown;
			Transform obj = parent.Find("HeaderNEW/PanelFood/Dropwdown");
			reference = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			parent = parent.parent;
		}
		TextMeshProUGUI componentInChildren = ((Component)day).GetComponentInChildren<TextMeshProUGUI>(true);
		dayBadge.font = ((componentInChildren != null) ? ((TMP_Text)componentInChildren).font : null);
		CalendarUi.Image(val, CalendarUi.Panel, raycast: true);
	}

	private void LateUpdate()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: 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_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: 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)
		if ((Object)(object)foodDropdown == (Object)null)
		{
			return;
		}
		RectTransform val = (RectTransform)((Transform)panel).parent;
		Vector2 anchoredPosition = panel.anchoredPosition;
		float num = -2f;
		if (((Component)foodDropdown).gameObject.activeInHierarchy)
		{
			panel.GetWorldCorners(corners);
			float x = ((Transform)val).InverseTransformPoint(corners[0]).x;
			float x2 = ((Transform)val).InverseTransformPoint(corners[2]).x;
			foodDropdown.GetWorldCorners(corners);
			Vector3 val2 = ((Transform)val).InverseTransformPoint(corners[0]);
			Vector3 val3 = ((Transform)val).InverseTransformPoint(corners[2]);
			if (val2.x < x2 && val3.x > x)
			{
				float num2 = num;
				float y = val2.y;
				Rect rect = val.rect;
				num = Mathf.Min(num2, y - ((Rect)(ref rect)).yMin - 6f);
			}
		}
		if (!Mathf.Approximately(anchoredPosition.y, num))
		{
			panel.anchoredPosition = new Vector2(anchoredPosition.x, num);
		}
	}

	private unsafe void Update()
	{
		//IL_0139: 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_0140: 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_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GameManager.Instance == (Object)null || !GameManager.Instance.IsGameLoaded() || GameManager.Instance.IsUnloading() || (Object)(object)DialogueManager.Instance == (Object)null || (Object)(object)DaytimeManager.Instance == (Object)null || (Object)(object)WorldManager.Instance == (Object)null)
		{
			return;
		}
		if (!Object.op_Implicit((Object)(object)mapInput) && Time.unscaledTime >= refresh)
		{
			mapInput = Object.FindObjectOfType<GameInputManager>();
		}
		Button val = (Object.op_Implicit((Object)(object)mapInput) ? NativeCalendarButton.Invoke(mapInput) : null);
		bool flag = CalendarShortcut.CanAdvertise(Object.op_Implicit((Object)(object)val) && ((Selectable)val).IsInteractable(), UIManager.Instance.IsWorldInteractable(), UIManager.Instance.CheatsEnabled(), Input.GetKey((KeyCode)306));
		if (Time.unscaledTime < refresh && shortcutVisible == flag)
		{
			return;
		}
		refresh = Time.unscaledTime + 0.75f;
		shortcutVisible = flag;
		Schedule schedule = Visitors.Read();
		List<Actors> list = schedule.ForDay(schedule.Today);
		string text = (flag ? CalendarUi.WithBinding("Game/Calendar", "Calendar") : "Calendar");
		string text2 = text;
		foreach (Actors item in list)
		{
			Sprite val2 = Visitors.Portrait(item);
			text2 = text2 + "|" + ((object)(*(Actors*)(&item))/*cast due to .constrained prefix*/).ToString() + ":" + (((Object)(object)val2 != (Object)null) ? ((Object)val2).GetInstanceID() : 0) + ":" + schedule.Status(schedule.Today, item, VisitState.IsClaimed(item)) + ":" + Visitors.Title(item);
		}
		if (!(text2 == lastKey))
		{
			lastKey = text2;
			Redraw(list, text, schedule);
		}
	}

	private void Redraw(List<Actors> visits, string prompt, Schedule schedule)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		foreach (Transform item in (Transform)panel)
		{
			((Component)item).gameObject.SetActive(false);
			Object.Destroy((Object)(object)((Component)item).gameObject);
		}
		int num = ((visits.Count == 0) ? 126 : 158);
		panel.sizeDelta = new Vector2((float)num, (float)(22 + visits.Count * 31));
		((TMP_Text)CalendarUi.Label(Row("Calendar", 0, num - 4, 20, 0), font, 15f)).text = prompt;
		for (int i = 0; i < visits.Count; i++)
		{
			Actors val2 = visits[i];
			int top = 22 + i * 31;
			Image obj = CalendarUi.Image(Row("Portrait", 4, 28, 28, top), Color.white);
			obj.sprite = Visitors.Portrait(val2);
			((Behaviour)obj).enabled = (Object)(object)obj.sprite != (Object)null;
			obj.preserveAspect = true;
			bool flag = VisitState.IsClaimed(val2);
			TextMeshProUGUI val3 = CalendarUi.Label(Row("Appointment", 36, num - 38, 30, top), font, 15f);
			((TMP_Text)val3).alignment = (TextAlignmentOptions)4097;
			((TMP_Text)val3).text = Visitors.Title(val2) + "\n" + schedule.Status(schedule.Today, val2, flag);
			if (flag)
			{
				((Graphic)val3).color = CalendarUi.Mint;
			}
		}
	}

	private RectTransform Row(string name, int x, int width, int height, int top)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		RectTransform obj = CalendarUi.Rect((Transform)(object)panel, name, new Vector2((float)width, (float)height), Vector2.zero);
		Vector2 val = default(Vector2);
		((Vector2)(ref val))..ctor(0f, 1f);
		obj.pivot = val;
		Vector2 anchorMin = (obj.anchorMax = val);
		obj.anchorMin = anchorMin;
		obj.anchoredPosition = new Vector2((float)x, (float)(-top));
		return obj;
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		if ((int)eventData.button != 0 || !UIManager.Instance.IsWorldInteractable() || OverlayManager.Instance.IsOpen())
		{
			return;
		}
		Button component = ((Component)((Component)this).transform.parent).GetComponent<Button>();
		if (!((Object)(object)component != (Object)null) || ((Selectable)component).IsInteractable())
		{
			if ((Object)(object)component != (Object)null)
			{
				Plugin.Focus(((Component)component).gameObject);
			}
			OverlayManager.Instance.OpenCalendar();
		}
	}
}
internal static class MerchantBooking
{
	internal static int? FirstVisit(object plugin, string runId, bool challenge, bool dailyCaravan)
	{
		if (challenge || dailyCaravan || plugin == null || string.IsNullOrEmpty(runId))
		{
			return null;
		}
		Type type = plugin.GetType();
		if (!object.Equals(type.GetField("RunId", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(plugin), runId))
		{
			return null;
		}
		object obj = type.GetField("Run", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(plugin);
		if (obj == null || obj.GetType().GetField("choice", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj)?.ToString() != "Merchant")
		{
			return null;
		}
		return obj.GetType().GetField("firstVisit", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.GetValue(obj) as int?;
	}
}
[HarmonyPatch]
internal static class NativeBookings
{
	private static readonly Dictionary<Type, Actors> Guests = new Dictionary<Type, Actors>
	{
		{
			typeof(GuestHermit),
			(Actors)1
		},
		{
			typeof(GuestMerchant),
			(Actors)11
		},
		{
			typeof(GuestMonsterHunter),
			(Actors)10
		},
		{
			typeof(GuestWitchDoctor),
			(Actors)40
		},
		{
			typeof(GuestGnomes),
			(Actors)66
		},
		{
			typeof(GuestBuilder),
			(Actors)15
		},
		{
			typeof(GuestDemolisher),
			(Actors)16
		},
		{
			typeof(GuestCaravan),
			(Actors)80
		},
		{
			typeof(GuestWizard),
			(Actors)14
		},
		{
			typeof(GuestResearcher),
			(Actors)64
		}
	};

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

	private static readonly HashSet<Actors> patchedDates = new HashSet<Actors>();

	internal static readonly HashSet<Actors> ArrivalOnly = new HashSet<Actors>();

	internal static bool SharedArrivalOverride;

	internal static bool CaravanUnlockPatched;

	private static IEnumerable<MethodBase> TargetMethods()
	{
		return Guests.Keys.Select((Type type) => AccessTools.DeclaredMethod(type, "GetDay", (Type[])null, (Type[])null));
	}

	[HarmonyPriority(0)]
	private static void Postfix(Guest __instance, int __result)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		if (Guests.TryGetValue(((object)__instance).GetType(), out var value))
		{
			effectiveDays[value] = __result;
		}
	}

	internal static void BeginLoad()
	{
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		effectiveDays.Clear();
		patchedDates.Clear();
		ArrivalOnly.Clear();
		SharedArrivalOverride = Changed(typeof(Guest), "OnLoad", (Actors)0) || Changed(typeof(WorldManager), "IsTodayGuest", (Actors)0);
		CaravanUnlockPatched = Changed(typeof(WorldManager), "HasUnlockedCaravans", (Actors)0);
		foreach (KeyValuePair<Type, Actors> guest in Guests)
		{
			if (Changed(guest.Key, "GetDay", (Actors)0))
			{
				patchedDates.Add(guest.Value);
			}
			if (Changed(guest.Key, "CheckDay", guest.Value) || Changed(guest.Key, "OnLoad", guest.Value))
			{
				ArrivalOnly.Add(guest.Value);
			}
		}
	}

	private static bool Changed(Type type, string name, Actors actor = (Actors)0)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		MethodInfo method = type.GetMethod(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		Patches val = ((method == null) ? null : Harmony.GetPatchInfo((MethodBase)method));
		return val?.Prefixes.Concat(val.Postfixes).Concat(val.Transpilers).Concat(val.Finalizers)
			.Concat(val.ILManipulators)
			.Any((Patch patch) => patch.owner != "sfk.visitorcalendar" && ((int)actor != 1 || !(patch.owner == "gkj.superfantasykingdom.weeklyhermit")) && ((int)actor != 80 || (!(patch.owner == "sfk.dailycaravan") && !(patch.owner == "gkj.sfk.kingdomcharters"))) && (!(type == typeof(Guest)) || !(name == "OnLoad") || !(patch.owner == "gkj.sfk.caravancommissions") || !(patch.PatchMethod.DeclaringType?.FullName == "CaravanCommissions.Plugin+Arrival") || !(patch.PatchMethod.Name == "Prefix"))) ?? false;
	}

	internal static int FixedDay(Actors actor, int authored)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		if (effectiveDays.TryGetValue(actor, out var value))
		{
			return value;
		}
		if (!patchedDates.Contains(actor))
		{
			return authored;
		}
		return 0;
	}
}
[BepInPlugin("sfk.visitorcalendar", "Visitor Calendar", "0.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(UICalendar), "GetGuestImage")]
	private static class MissingActor
	{
		private static bool Prefix(int guestName)
		{
			return (Object)(object)Visitors.Actor((Actors)guestName) != (Object)null;
		}
	}

	[HarmonyPatch(typeof(UICalendar), "GetGuestTitle")]
	private static class MissingTitle
	{
		private static bool Prefix(int guestName, ref string __result)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (guestName == 0)
			{
				return true;
			}
			Actors id = (Actors)guestName;
			LocalizedString val = Visitors.Actor(id)?.stringTitle;
			if (val != null && !((LocalizedReference)val).IsEmpty)
			{
				return true;
			}
			__result = Visitors.Title(id);
			return false;
		}
	}

	[HarmonyPatch(typeof(OverlayManager), "OpenCalendar")]
	private static class Open
	{
		private static void Prefix()
		{
			EventSystem current = EventSystem.current;
			returnTo = ((current != null) ? current.currentSelectedGameObject : null);
			if ((Object)(object)returnTo == (Object)null)
			{
				returnTo = GamepadManager.Instance.GetGameObjectToSelect();
			}
		}

		private static void Postfix(Transform __result)
		{
			if ((Object)(object)View != (Object)null && (Object)(object)((Component)View).transform == (Object)(object)__result)
			{
				View.SelectToday();
			}
		}
	}

	[HarmonyPatch(typeof(UICalendar), "OnEnable")]
	private static class Bind
	{
		private static void Postfix(UICalendar __instance, Transform ___calendarDays, GameObject ___lastDay, LocalizedString ___stringBoss, LocalizedString ___stringDayX)
		{
			View = ((Component)__instance).GetComponent<CalendarView>() ?? ((Component)__instance).gameObject.AddComponent<CalendarView>();
			View.Bind(___calendarDays, ___lastDay, ___stringBoss, ___stringDayX);
		}
	}

	[HarmonyPatch(typeof(UICalendar), "OnEnterDay")]
	private static class Tooltip
	{
		private static bool Prefix(UICalendar __instance, int day)
		{
			CalendarView component = ((Component)__instance).GetComponent<CalendarView>();
			if (!((Object)(object)component == (Object)null))
			{
				return !component.Hover(day);
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(UICalendar), "Update")]
	private static class CalendarKey
	{
		private static bool Prefix(UICalendar __instance)
		{
			if ((Object)(object)View == (Object)null || (Object)(object)((Component)View).gameObject != (Object)(object)((Component)__instance).gameObject)
			{
				return true;
			}
			View.KeyboardToggle();
			return false;
		}
	}

	[HarmonyPatch(typeof(OverlayManager), "Cancel")]
	private static class Back
	{
		private static bool Prefix(OverlayManager __instance)
		{
			if (__instance.IsCalendarOpen() && !((Object)(object)View == (Object)null))
			{
				return !View.Back();
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(OverlayManager), "CloseOverlay")]
	private static class Close
	{
		private static void Prefix(OverlayManager __instance, out bool __state)
		{
			__state = __instance.IsCalendarOpen();
		}

		private static void Postfix(OverlayManager __instance, bool __state)
		{
			if (__state && !__instance.IsCalendarOpen())
			{
				if ((Object)(object)returnTo != (Object)null && returnTo.activeInHierarchy)
				{
					Focus(returnTo);
				}
				View = null;
				returnTo = null;
			}
		}
	}

	[HarmonyPatch(typeof(UIClockButtonDay), "Start")]
	private static class Clock
	{
		private static void Postfix(UIClockButtonDay __instance)
		{
			DayBadge.Attach(((Component)__instance).transform);
		}
	}

	[HarmonyPatch(typeof(UIResourceAmount), "Start")]
	private static class ResourceDay
	{
		private static void Postfix(UIResourceAmount __instance)
		{
			if (__instance is UIResourceAmountDay)
			{
				DayBadge.Attach(((Component)__instance).transform);
			}
		}
	}

	internal const string Id = "sfk.visitorcalendar";

	private static ManualLogSource log;

	private Harmony patches;

	private static GameObject returnTo;

	internal static CalendarView View;

	private void Awake()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		log = ((BaseUnityPlugin)this).Logger;
		patches = new Harmony("sfk.visitorcalendar");
		try
		{
			patches.PatchAll(typeof(Plugin).Assembly);
		}
		catch
		{
			patches.UnpatchSelf();
			throw;
		}
		WorldManager.OnGuestArriving += VisitState.Arrival;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Visitor Calendar 0.1.0 ready.");
	}

	private void OnDestroy()
	{
		WorldManager.OnGuestArriving -= VisitState.Arrival;
		Harmony obj = patches;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	internal static void LogWarning(Exception e)
	{
		log.LogWarning((object)e.Message);
	}

	internal static void Focus(GameObject target)
	{
		if (!((Object)(object)target != (Object)null) || target.activeInHierarchy)
		{
			GamepadManager.Instance.SetGameObjectToSelect(target, true);
			EventSystem current = EventSystem.current;
			if ((Object)(object)current != (Object)null && (Object)(object)current.currentSelectedGameObject != (Object)(object)target)
			{
				current.SetSelectedGameObject(target);
			}
		}
	}

	internal static bool IsPreviousFocus(GameObject target)
	{
		return (Object)(object)target == (Object)(object)returnTo;
	}
}
internal sealed class Schedule
{
	internal readonly Dictionary<Actors, int> FixedDays = new Dictionary<Actors, int>();

	internal readonly int[] Invitations = new int[4];

	internal readonly HashSet<Actors> Known = new HashSet<Actors>();

	internal readonly HashSet<Actors> Arrived = new HashSet<Actors>();

	internal readonly HashSet<Actors> ArrivalOnly = new HashSet<Actors>();

	internal VisitHistory History = new VisitHistory();

	internal bool SharedArrivalOverride;

	internal bool CaravanGateOpened = true;

	internal int ConsumedCaravanDay;

	internal bool PendingMerchantCharter;

	internal bool VanillaCaravanUnlock = true;

	internal int Today;

	internal int LastDay;

	internal int HermitInterval;

	internal int CaravanStart;

	internal bool CaravansUnlocked;

	internal bool Challenge;

	internal bool HermitOfferPossible = true;

	internal List<Actors> ForDay(int day)
	{
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Invalid comparison between Unknown and I4
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0207: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		Schedule schedule = this;
		int day2 = day;
		List<Actors> result = new List<Actors>();
		if (day2 < 1 || day2 > LastDay)
		{
			return result;
		}
		if (History.Days.TryGetValue(day2, out var value))
		{
			foreach (Actors key in value.Keys)
			{
				Add(key, observed: true);
			}
		}
		if (day2 < Today)
		{
			return result;
		}
		foreach (KeyValuePair<Actors, int> fixedDay in FixedDays)
		{
			if (fixedDay.Value == day2)
			{
				Add(fixedDay.Key);
			}
		}
		if (day2 <= 28 && day2 % 7 == 0)
		{
			Actors val = (Actors)Invitations[day2 / 7 - 1];
			Add((Actors)(((int)val == 24) ? 14 : ((int)val)));
		}
		if (!Challenge && HermitInterval > 0 && day2 > 2 && (day2 - 2) % HermitInterval == 0 && (day2 != Today || HermitOfferPossible))
		{
			Add((Actors)1);
		}
		if (!Challenge && CaravanGateOpened && CaravanStart > 0 && day2 >= CaravanStart)
		{
			bool num;
			if (!VanillaCaravanUnlock)
			{
				if (day2 != Today)
				{
					goto IL_01e3;
				}
				num = CaravansUnlocked;
			}
			else
			{
				if (CaravansUnlocked)
				{
					goto IL_01d8;
				}
				num = day2 > 14;
			}
			if (num)
			{
				goto IL_01d8;
			}
		}
		goto IL_01e3;
		IL_01e3:
		if (day2 == Today)
		{
			foreach (Actors item in Arrived)
			{
				Add(item, observed: true);
			}
		}
		return result;
		IL_01d8:
		Add((Actors)80);
		goto IL_01e3;
		void Add(Actors actor, bool observed = false)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			if ((observed || (!SharedArrivalOverride && !ArrivalOnly.Contains(actor) && ((int)actor != 80 || (CaravanGateOpened && day2 != ConsumedCaravanDay && !CanStillMove(day2))))) && Known.Contains(actor) && !result.Contains(actor))
			{
				result.Add(actor);
			}
		}
	}

	internal string Status(int day, Actors actor, bool claimedToday)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		bool value = false;
		Dictionary<Actors, bool> value2;
		bool flag = History.Days.TryGetValue(day, out value2) && value2.TryGetValue(actor, out value);
		if (day == Today && claimedToday)
		{
			return "Claimed Today";
		}
		if (day < Today && flag && value)
		{
			return "Visited · Claimed";
		}
		if (flag || (day == Today && Arrived.Contains(actor)))
		{
			return "Visited";
		}
		return "Forecast";
	}

	internal static string CellMarker(bool hasPortrait, int index, int count)
	{
		if (index == 2 && count > 3)
		{
			return "+" + (count - 2);
		}
		if (!hasPortrait)
		{
			return "•";
		}
		return null;
	}

	private bool CanStillMove(int day)
	{
		if (!PendingMerchantCharter || day <= Today + 1)
		{
			return false;
		}
		FixedDays.TryGetValue((Actors)80, out var value);
		if (value < Today)
		{
			value = int.MaxValue;
		}
		for (int i = 0; i < Invitations.Length; i++)
		{
			int num = (i + 1) * 7;
			if (num >= Today && Invitations[i] == 80)
			{
				value = Math.Min(value, num);
			}
		}
		return day == value;
	}
}
internal sealed class VisitHistory
{
	internal readonly Dictionary<int, Dictionary<Actors, bool>> Days = new Dictionary<int, Dictionary<Actors, bool>>();

	internal void Record(int day, Actors actor, bool claimed)
	{
		//IL_0004: 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: Unknown result type (might be due to invalid IL or missing references)
		if (day >= 1 && (int)actor != 0)
		{
			if (!Days.TryGetValue(day, out var value))
			{
				Days.Add(day, value = new Dictionary<Actors, bool>());
			}
			if (!value.ContainsKey(actor) || claimed)
			{
				value[actor] = claimed;
			}
		}
	}

	internal void RecordCaravan(int day, CaravanDecision decision)
	{
		if (decision == CaravanDecision.Claimed || decision == CaravanDecision.Declined)
		{
			Record(day, (Actors)80, decision == CaravanDecision.Claimed);
		}
	}

	internal IEnumerable<string> Lines()
	{
		foreach (KeyValuePair<int, Dictionary<Actors, bool>> day in Days)
		{
			foreach (KeyValuePair<Actors, bool> item in day.Value)
			{
				yield return string.Format(CultureInfo.InvariantCulture, "{0}|{1}|{2}", day.Key, (int)item.Key, item.Value ? 1 : 0);
			}
		}
	}

	internal void Restore(IEnumerable<string> lines, int lastDay)
	{
		foreach (string line in lines)
		{
			string[] array = line.Split('|');
			if (array.Length == 3 && int.TryParse(array[0], out var result) && result <= lastDay && int.TryParse(array[1], out var result2) && (array[2] == "1" || array[2] == "0"))
			{
				Record(result, (Actors)result2, array[2] == "1");
			}
		}
	}
}
internal static class Visitors
{
	internal const string Weekly = "gkj.superfantasykingdom.weeklyhermit";

	internal const string Daily = "sfk.dailycaravan";

	internal const string Charters = "gkj.sfk.kingdomcharters";

	private static readonly FieldInfo DialogueId = typeof(DialogueCollection).GetField("actor", BindingFlags.Instance | BindingFlags.NonPublic);

	internal static Actors Identity(Guest guest)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)guest == (Object)null))
		{
			if (((object)guest).GetType().Assembly != typeof(Guest).Assembly)
			{
				DialogueCollection dialogueCollection = guest.GetDialogueCollection();
				if ((Object)(object)dialogueCollection != (Object)null)
				{
					object obj = DialogueId?.GetValue(dialogueCollection);
					if (obj is Actors)
					{
						return (Actors)obj;
					}
				}
				return (Actors)0;
			}
			if (!(guest is GuestHermit))
			{
				if (!(guest is GuestMerchant))
				{
					if (!(guest is GuestMonsterHunter))
					{
						if (!(guest is GuestWitchDoctor))
						{
							if (!(guest is GuestGnomes))
							{
								if (!(guest is GuestBuilder) && !(guest is GuestSiege))
								{
									if (!(guest is GuestDemolisher))
									{
										if (!(guest is GuestCaravan))
										{
											if (!(guest is GuestWizard))
											{
												if (!(guest is GuestResearcher))
												{
													if (guest is GuestBlacksmith)
													{
														return (Actors)12;
													}
													return (Actors)0;
												}
												return (Actors)64;
											}
											return (Actors)14;
										}
										return (Actors)80;
									}
									return (Actors)16;
								}
								return (Actors)15;
							}
							return (Actors)66;
						}
						return (Actors)40;
					}
					return (Actors)10;
				}
				return (Actors)11;
			}
			return (Actors)1;
		}
		return (Actors)0;
	}

	private static int Setting(string guid, string key)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		ConfigEntry<int> val = default(ConfigEntry<int>);
		if (Chainloader.PluginInfos.TryGetValue(guid, out var value) && (Object)(object)value.Instance != (Object)null && value.Instance.Config.TryGetEntry<int>(new ConfigDefinition("Schedule", key), ref val))
		{
			return val.Value;
		}
		return 0;
	}

	internal static Schedule Read()
	{
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
		RaceDataManager race = RaceDataManager.Instance;
		DaytimeManager instance = DaytimeManager.Instance;
		VisitState.CheckDay(instance.CurrentDay());
		ChallengeData val = (MainManager.Instance.IsChallenge() ? ChallengeManager.Instance.GetLoadedChallenge() : null);
		Schedule s = new Schedule
		{
			Today = instance.CurrentDay(),
			LastDay = instance.GetDayLimit(),
			Challenge = (val != null),
			HermitInterval = Setting("gkj.superfantasykingdom.weeklyhermit", "IntervalDays"),
			CaravanStart = Setting("sfk.dailycaravan", "FirstDay"),
			History = VisitState.History,
			CaravanGateOpened = race.HasRaceEventFlag((RaceEvent)13),
			CaravansUnlocked = WorldManager.Instance.HasUnlockedCaravans()
		};
		Add((Actors)1, val?.guestHermit ?? 2, (RaceEvent)5);
		Add((Actors)11, val?.guestMerchant ?? 5, (RaceEvent)61);
		Add((Actors)10, val?.guestMonsterHunter ?? 6, (RaceEvent)120);
		Add((Actors)40, val?.guestWitchDoctor ?? 9, (RaceEvent)90);
		Add((Actors)66, val?.guestGnomes ?? 12, (RaceEvent)201);
		Add((Actors)15, val?.guestBuilder ?? 13, (RaceEvent)232);
		Add((Actors)80, val?.guestCaravan ?? 16, (RaceEvent)13);
		Add((Actors)16, val?.guestDemolisher ?? 19, (RaceEvent)222);
		Add((Actors)14, val?.guestWizard ?? 23, (RaceEvent)162);
		Add((Actors)64, val?.guestResearcher ?? 26, (RaceEvent)251);
		if (race.HasRaceEventFlag((RaceEvent)20))
		{
			s.Known.Add((Actors)12);
		}
		s.Invitations[0] = race.GetGuestWeek1();
		s.Invitations[1] = race.GetGuestWeek2();
		s.Invitations[2] = race.GetGuestWeek3();
		s.Invitations[3] = race.GetGuestWeek4();
		s.SharedArrivalOverride = NativeBookings.SharedArrivalOverride;
		s.ArrivalOnly.UnionWith(NativeBookings.ArrivalOnly);
		s.VanillaCaravanUnlock = !NativeBookings.CaravanUnlockPatched;
		if (Chainloader.PluginInfos.TryGetValue("gkj.sfk.kingdomcharters", out var value) && (Object)(object)value.Instance != (Object)null)
		{
			int? num = MerchantBooking.FirstVisit(value.Instance, GameDataManager.Instance.GetRunID(), s.Challenge, Chainloader.PluginInfos.ContainsKey("sfk.dailycaravan"));
			s.ConsumedCaravanDay = num.GetValueOrDefault();
			s.PendingMerchantCharter = num == 0;
		}
		CaravanDecision caravanDecision = DailyCaravanDecision(s.Today);
		if (caravanDecision == CaravanDecision.Claimed || caravanDecision == CaravanDecision.Declined)
		{
			VisitState.Arrived.Add((Actors)80);
		}
		s.Arrived.UnionWith(VisitState.Arrived);
		s.Arrived.UnionWith(VisitState.Claimed);
		foreach (Dictionary<Actors, bool> value2 in s.History.Days.Values)
		{
			foreach (Actors key in value2.Keys)
			{
				DiscoverArrival(key);
			}
		}
		foreach (Actors item in s.Arrived)
		{
			DiscoverArrival(item);
		}
		int[] invitations = s.Invitations;
		for (int i = 0; i < invitations.Length; i++)
		{
			Discover((Actors)invitations[i]);
		}
		s.HermitOfferPossible = s.Arrived.Contains((Actors)1);
		return s;
		void Add(Actors actor, int day, RaceEvent discovery)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Invalid comparison between Unknown and I4
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			s.FixedDays.Add(actor, NativeBookings.FixedDay(actor, day));
			bool flag = race.HasRaceEventFlag(discovery);
			if ((int)actor == 1)
			{
				flag |= race.GetDialogData(actor).Count != 0 || DialogueManager.Instance.HasSpokenToThisRun(actor);
			}
			if (flag)
			{
				s.Known.Add(actor);
			}
		}
		void Discover(Actors actor)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if ((int)actor != 0 && !s.Known.Contains(actor) && !s.FixedDays.ContainsKey(actor) && (int)actor != 24 && !((Object)(object)Actor(actor) == (Object)null) && (DialogueManager.Instance.HasSpokenToThisRun(actor) || race.GetDialogData(actor).Count > 0))
			{
				s.Known.Add(actor);
			}
		}
		void DiscoverArrival(Actors actor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (s.FixedDays.ContainsKey(actor) || (int)actor == 12)
			{
				s.Known.Add(actor);
			}
			else
			{
				Discover(actor);
			}
		}
	}

	internal static CaravanDecision DailyCaravanDecision(int day)
	{
		if (!Chainloader.PluginInfos.TryGetValue("sfk.dailycaravan", out var value) || (Object)(object)value.Instance == (Object)null)
		{
			return CaravanDecision.Unavailable;
		}
		BaseUnityPlugin instance = value.Instance;
		Type type = ((object)instance).GetType();
		if (AccessTools.Field(type, "scene")?.GetValue(instance) != GameDataManager.Instance || !object.Equals(AccessTools.Field(type, "day")?.GetValue(instance), day))
		{
			return CaravanDecision.Unavailable;
		}
		return CaravanReplay.Read(AccessTools.Field(type, "Visit")?.GetValue(instance));
	}

	internal static Actor Actor(Actors id)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		return DialogueManager.Instance.GetActor(id);
	}

	internal static Sprite Portrait(Actors id)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		Actor val = Actor(id);
		if (!((Object)(object)val != (Object)null))
		{
			return null;
		}
		return val.avatar;
	}

	internal unsafe static string Title(Actors id)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		Actor val = Actor(id);
		if ((Object)(object)val != (Object)null)
		{
			LocalizedString[] array = (LocalizedString[])(object)new LocalizedString[2] { val.stringTitle, val.stringName };
			foreach (LocalizedString val2 in array)
			{
				if (val2 != null && !((LocalizedReference)val2).IsEmpty)
				{
					string localizedString = val2.GetLocalizedString();
					if (!string.IsNullOrWhiteSpace(localizedString))
					{
						return localizedString;
					}
				}
			}
			if (!string.IsNullOrWhiteSpace(val.title))
			{
				return val.title;
			}
		}
		if (!Enum.IsDefined(typeof(Actors), id))
		{
			return "Visitor";
		}
		return ((object)(*(Actors*)(&id))/*cast due to .constrained prefix*/).ToString();
	}
}
internal static class VisitState
{
	[HarmonyPatch(typeof(GameDataManager), "Load")]
	private static class Load
	{
		private static void Prefix(GameData ___m_GameData)
		{
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			Claimed.Clear();
			Arrived.Clear();
			scene = null;
			History.Days.Clear();
			NativeBookings.BeginLoad();
			try
			{
				string text = HistoryPath(___m_GameData);
				if (text != null && File.Exists(text))
				{
					int num = ___m_GameData.day + 1;
					History.Restore(File.ReadAllLines(text), num);
					if (!History.Days.TryGetValue(num, out var value))
					{
						return;
					}
					{
						foreach (KeyValuePair<Actors, bool> item in value)
						{
							Arrived.Add(item.Key);
							if (item.Value)
							{
								Claimed.Add(item.Key);
							}
						}
						return;
					}
				}
				string text2 = PathFor(___m_GameData);
				if (text2 == null || !File.Exists(text2))
				{
					return;
				}
				string[] array = File.ReadAllLines(text2);
				for (int i = 0; i < array.Length; i++)
				{
					if (Enum.TryParse<Actors>(array[i], out Actors result) && (int)result != 0)
					{
						Claimed.Add(result);
					}
				}
			}
			catch (IOException e)
			{
				Plugin.LogWarning(e);
			}
			catch (UnauthorizedAccessException e2)
			{
				Plugin.LogWarning(e2);
			}
		}

		private static void Postfix(GameDataManager __instance)
		{
			scene = __instance;
			day = DaytimeManager.Instance.CurrentDay();
		}
	}

	[HarmonyPatch(typeof(GameDataManager), "GenerateGameData")]
	private static class Snapshot
	{
		private static void Postfix(GameDataManager __instance, GameData __result)
		{
			if ((Object)(object)__instance != (Object)(object)scene || __result == null)
			{
				return;
			}
			Remember();
			if (History.Days.Count == 0)
			{
				return;
			}
			try
			{
				string text = HistoryPath(__result);
				if (text != null)
				{
					Directory.CreateDirectory(Path.GetDirectoryName(text));
					string text2 = text + ".tmp";
					File.WriteAllLines(text2, History.Lines());
					if (File.Exists(text))
					{
						File.Replace(text2, text, null);
					}
					else
					{
						File.Move(text2, text);
					}
				}
			}
			catch (IOException e)
			{
				Plugin.LogWarning(e);
			}
			catch (UnauthorizedAccessException e2)
			{
				Plugin.LogWarning(e2);
			}
		}
	}

	[HarmonyPatch(typeof(UIOverlayMerchant), "Init")]
	private static class ResetSpeaker
	{
		private static void Postfix(UIOverlayMerchant __instance)
		{
			MerchantSpeaker component = ((Component)__instance).GetComponent<MerchantSpeaker>();
			if ((Object)(object)component != (Object)null)
			{
				component.WeeklyOffer = false;
			}
		}
	}

	[HarmonyPatch(typeof(UIOverlayMerchant), "SetCallback")]
	private static class WeeklyOffer
	{
		private static void Postfix(UIOverlayMerchant __instance, Action<int, ResourceAmount[]> cb)
		{
			MerchantSpeaker component = ((Component)__instance).GetComponent<MerchantSpeaker>();
			if ((Object)(object)component != (Object)null)
			{
				component.WeeklyOffer = false;
			}
			if (cb != null && Chainloader.PluginInfos.TryGetValue("gkj.superfantasykingdom.weeklyhermit", out var value) && !((Object)(object)value.Instance == (Object)null) && !(cb.Method.DeclaringType?.Assembly != ((object)value.Instance).GetType().Assembly))
			{
				(((Component)__instance).GetComponent<MerchantSpeaker>() ?? ((Component)__instance).gameObject.AddComponent<MerchantSpeaker>()).WeeklyOffer = true;
				CheckDay(DaytimeManager.Instance.CurrentDay());
				Arrived.Add((Actors)1);
			}
		}
	}

	[HarmonyPatch(typeof(UICard), "Callback")]
	private static class Resolve
	{
		private static void Prefix(UICard __instance, out CardResolution __state)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			__state = resolving;
			resolving = default(CardResolution);
			UIOverlayMerchant componentInParent = ((Component)__instance).GetComponentInParent<UIOverlayMerchant>();
			if ((Object)(object)componentInParent == (Object)null)
			{
				return;
			}
			object? obj = Callback.Invoke(componentInParent)?.Target;
			Guest val = (Guest)((obj is Guest) ? obj : null);
			if (val != null)
			{
				resolving.Actor = Visitors.Identity(val);
				return;
			}
			MerchantSpeaker component = ((Component)componentInParent).GetComponent<MerchantSpeaker>();
			if (component != null && component.WeeklyOffer && __instance is UICardUnit)
			{
				resolving.Actor = (Actors)1;
			}
		}

		private static void Finalizer(CardResolution __state, Exception __exception)
		{
			resolving.Finish(Claimed, __exception == null);
			resolving = __state;
		}
	}

	[HarmonyPatch(typeof(OverlayManager), "Confirm")]
	private static class Confirm
	{
		private static void Postfix(bool __runOriginal)
		{
			if (__runOriginal)
			{
				resolving.Confirmed = true;
			}
		}
	}

	internal static readonly HashSet<Actors> Arrived = new HashSet<Actors>();

	internal static readonly HashSet<Actors> Claimed = new HashSet<Actors>();

	internal static readonly VisitHistory History = new VisitHistory();

	private static int day;

	private static GameDataManager scene;

	private static CardResolution resolving;

	private static readonly FieldRef<UIOverlayMerchant, Action<int, ResourceAmount[]>> Callback = AccessTools.FieldRefAccess<UIOverlayMerchant, Action<int, ResourceAmount[]>>("m_Callback");

	internal static bool IsClaimed(Actors id)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if ((int)id == 80)
		{
			CaravanDecision caravanDecision = Visitors.DailyCaravanDecision(DaytimeManager.Instance.CurrentDay());
			if (caravanDecision != CaravanDecision.Unavailable)
			{
				return caravanDecision == CaravanDecision.Claimed;
			}
		}
		return Claimed.Contains(id);
	}

	internal static void CheckDay(int currentDay)
	{
		if (!((Object)(object)scene != (Object)(object)GameDataManager.Instance) && day != currentDay)
		{
			Remember();
			day = currentDay;
			Arrived.Clear();
			Claimed.Clear();
		}
	}

	private static void Remember()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		History.RecordCaravan(day, Visitors.DailyCaravanDecision(day));
		foreach (Actors item in Arrived)
		{
			History.Record(day, item, claimed: false);
		}
		foreach (Actors item2 in Claimed)
		{
			History.Record(day, item2, claimed: true);
		}
	}

	private static string HistoryPath(GameData data)
	{
		if (data != null && !string.IsNullOrEmpty(data.runID) && !string.IsNullOrEmpty(data.lastPlayed))
		{
			return Path.Combine(Paths.ConfigPath, "VisitorCalendar", Helper.GenerateHash(string.Join("|", SettingsManager.Instance.GetProfile(), data.runID, data.lastPlayed)) + ".visits");
		}
		return null;
	}

	private static string PathFor(GameData data)
	{
		if (data == null || string.IsNullOrEmpty(data.runID) || string.IsNullOrEmpty(data.lastPlayed))
		{
			return null;
		}
		return Path.Combine(Paths.ConfigPath, "VisitorCalendar", Helper.GenerateHash(string.Join("|", SettingsManager.Instance.GetProfile(), data.runID, data.day, data.lastPlayed, data.hash)) + ".txt");
	}

	internal static void Arrival(Guest guest)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		CheckDay(DaytimeManager.Instance.CurrentDay());
		Actors val = Visitors.Identity(guest);
		if ((int)val != 0)
		{
			Arrived.Add(val);
		}
	}
}
internal sealed class MerchantSpeaker : MonoBehaviour
{
	internal bool WeeklyOffer;
}