Decompiled source of The Father v1.2.0

BepInEx/plugins/TheFather/TheFather.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace TheFather;

public class DEN_TheFather : MonoBehaviour
{
	private enum State
	{
		Emerging,
		Idle,
		Talking,
		Leaving
	}

	private class Held
	{
		public Item item;

		public Item_Object drop;

		public Transform point;

		public float yaw;

		public bool taken;

		public Behaviour[] paused;
	}

	public FatherAnimator anim;

	public Transform[] grubPoints;

	public Collider interactCollider;

	private State state;

	private float awayTimer;

	private readonly List<Held> held = new List<Held>();

	private static int layer = -1;

	public bool CanInteract => state == State.Idle;

	internal void Setup(FatherAnimator a, Transform[] points)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		anim = a;
		grubPoints = points;
		GameObject val = new GameObject("TheFather_Interact");
		val.transform.SetParent(((Component)this).transform, false);
		float value = Plugin.Scale.Value;
		BoxCollider val2 = val.AddComponent<BoxCollider>();
		val2.center = new Vector3(0f, 3.1f, 0.6f) * value;
		val2.size = new Vector3(3.6f, 6.2f, 3.8f) * value;
		val.AddComponent<ObjectTagger>().tags = new List<string> { "Button" };
		val.AddComponent<FatherClickable>();
		interactCollider = (Collider)(object)val2;
		((Collider)val2).enabled = false;
	}

	private void Awake()
	{
		if ((Object)(object)anim != (Object)null && anim.Data == null)
		{
			anim.Data = Plugin.Data;
		}
		if ((Object)(object)interactCollider != (Object)null)
		{
			((Component)interactCollider).gameObject.layer = InteractLayer();
		}
		if (FatherLook.UsedFallback)
		{
			FatherLook.Apply(((Component)this).GetComponentInChildren<SkinnedMeshRenderer>(true), Plugin.Data);
		}
	}

	private void Start()
	{
		SnapToGroundFacingPlayer();
		anim.ClipFinished += OnClipFinished;
		anim.Play("Emerge");
		anim.Queue("Idle");
	}

	private void OnClipFinished(string clip)
	{
		if (clip == "Emerge" && state == State.Emerging)
		{
			state = State.Idle;
			if ((Object)(object)interactCollider != (Object)null)
			{
				interactCollider.enabled = true;
			}
		}
		else if (clip == "Submerge")
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}

	public void Interact()
	{
		if (state == State.Idle)
		{
			((MonoBehaviour)this).StartCoroutine(Talk());
		}
	}

	private void Update()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: 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)
		if (state != State.Idle)
		{
			return;
		}
		ENT_Player player = ENT_Player.GetPlayer();
		if (!((Object)player == (Object)null))
		{
			float num = Vector3.Distance(((Component)player).transform.position, ((Component)this).transform.position);
			awayTimer = ((num > 30f) ? (awayTimer + Time.deltaTime) : 0f);
			if (awayTimer > 3f)
			{
				Leave();
			}
		}
	}

	private IEnumerator Talk()
	{
		state = State.Talking;
		yield return TurnToPlayer(0.45f);
		TalkPlan plan;
		try
		{
			plan = (Plugin.QuestsEnabled.Value ? Quests.BuildPlan() : LegacyPlan());
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Quest plan failed: " + ex));
			plan = LegacyPlan();
		}
		bool handOut = false;
		float lineTime = Mathf.Max(2.5f, Plugin.TextTime.Value * 0.85f);
		for (int i = 0; i < plan.Lines.Count; i++)
		{
			if (plan.Gifts.Count > 0 && i == plan.GiftLine && !handOut)
			{
				handOut = true;
				anim.Play("OfferHand", 0.25f);
				anim.Queue("OfferHand_Hold");
				yield return (object)new WaitForSeconds(0.35f);
				FatherVoice.Say(plan.Lines[i]);
				yield return (object)new WaitForSeconds(0.3f);
				SpawnGifts(plan.Gifts, plan.GiftIsBuddy);
				yield return (object)new WaitForSeconds(lineTime - 0.3f);
			}
			else
			{
				FatherVoice.Say(plan.Lines[i]);
				if (i == plan.RewardLine)
				{
					Quests.GrantReward(plan.Reward);
				}
				yield return (object)new WaitForSeconds(lineTime);
			}
		}
		if (handOut)
		{
			float away = 0f;
			float t = 0f;
			while (held.Count > 0 && !held.All((Held h) => h.taken) && t < 40f)
			{
				ENT_Player player = ENT_Player.GetPlayer();
				away = (((Object)player != (Object)null && Vector3.Distance(((Component)player).transform.position, ((Component)this).transform.position) > 14f) ? (away + Time.deltaTime) : 0f);
				if (away > 4f)
				{
					break;
				}
				t += Time.deltaTime;
				yield return null;
			}
			yield return (object)new WaitForSeconds(1f);
			bool buddyLeft = held.Any((Held h) => !h.taken && h.item == Quests.BuddyItem);
			foreach (Held item in held.Where((Held h) => !h.taken && (Object)(object)h.drop != (Object)null))
			{
				Object.Destroy((Object)(object)((Component)item.drop).gameObject);
			}
			held.Clear();
			Quests.OnGiftsLeft(buddyLeft);
			anim.Play("Idle", 0.9f);
			yield return (object)new WaitForSeconds(1.1f);
		}
		else
		{
			yield return (object)new WaitForSeconds(0.6f);
		}
		Leave();
	}

	private TalkPlan LegacyPlan()
	{
		TalkPlan talkPlan = new TalkPlan();
		talkPlan.Lines.Add(Plugin.Line.Value);
		talkPlan.GiftLine = 0;
		Item_Object val = Gifts.Grub();
		if ((Object)(object)val != (Object)null)
		{
			for (int i = 0; i < Mathf.Clamp(Plugin.GrubCount.Value, 0, 3); i++)
			{
				talkPlan.Gifts.Add(val);
			}
		}
		return talkPlan;
	}

	public void Leave()
	{
		if (state != State.Leaving)
		{
			state = State.Leaving;
			if ((Object)(object)interactCollider != (Object)null)
			{
				interactCollider.enabled = false;
			}
			anim.Play("Submerge", 0.35f);
			Object.Destroy((Object)(object)((Component)this).gameObject, 8f);
		}
	}

	private void SpawnGifts(List<Item_Object> prefabs, bool buddy)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0047: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < prefabs.Count && i < grubPoints.Length; i++)
		{
			Item_Object val = prefabs[i];
			if ((Object)val == (Object)null)
			{
				continue;
			}
			try
			{
				Item clone = val.itemData.GetClone((Item)null, false);
				Item_Object dropObject = clone.GetDropObject(true);
				GameObject gameObject = ((Component)dropObject).gameObject;
				gameObject.transform.SetParent((Transform)null, true);
				gameObject.transform.position = grubPoints[i].position;
				gameObject.SetActive(true);
				Rigidbody component = gameObject.GetComponent<Rigidbody>();
				if ((Object)(object)component != (Object)null)
				{
					component.isKinematic = true;
					component.linearVelocity = Vector3.zero;
				}
				dropObject.canPickup = true;
				Behaviour[] array = (from d in gameObject.GetComponents<Denizen>()
					where ((Behaviour)d).enabled && (Object)(object)((Component)d).GetComponent<DEN_SlugGrub>() == (Object)null
					select d).Cast<Behaviour>().ToArray();
				Behaviour[] array2 = array;
				for (int num = 0; num < array2.Length; num++)
				{
					array2[num].enabled = false;
				}
				Held h = new Held
				{
					item = clone,
					drop = dropObject,
					point = grubPoints[i],
					yaw = Random.Range(0f, 360f),
					paused = array
				};
				clone._OnPickupAction = (Action<Item>)Delegate.Combine(clone._OnPickupAction, (Action<Item>)delegate
				{
					OnTaken(h);
				});
				held.Add(h);
				if (buddy && Quests.Current == Quests.Q.Buddy && Quests.BuddyItem == null)
				{
					Quests.BuddyItem = clone;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Gift spawn failed: " + ex.Message));
			}
		}
	}

	private void OnTaken(Held h)
	{
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		if (h.taken)
		{
			return;
		}
		h.taken = true;
		if (h.paused != null)
		{
			Behaviour[] paused = h.paused;
			foreach (Behaviour val in paused)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = true;
				}
			}
		}
		Rigidbody val2 = (((Object)(object)h.drop != (Object)null) ? ((Component)h.drop).GetComponent<Rigidbody>() : null);
		if ((Object)(object)val2 != (Object)null)
		{
			val2.isKinematic = false;
		}
	}

	private void LateUpdate()
	{
		//IL_0033: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: 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)
		for (int i = 0; i < this.held.Count; i++)
		{
			Held held = this.held[i];
			if (!held.taken)
			{
				if ((Object)(object)held.drop == (Object)null || !((Component)held.drop).gameObject.activeInHierarchy || held.item.inBag)
				{
					OnTaken(held);
					continue;
				}
				Transform transform = ((Component)held.drop).transform;
				transform.position = held.point.position;
				transform.rotation = Quaternion.Euler(0f, ((Component)this).transform.eulerAngles.y + held.yaw, 0f);
			}
		}
	}

	private void OnDestroy()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		foreach (Held item in held.Where((Held h) => !h.taken && (Object)(object)h.drop != (Object)null))
		{
			Object.Destroy((Object)(object)((Component)item.drop).gameObject);
		}
		if ((Object)(object)Quests.ActiveFather == (Object)(object)this)
		{
			Quests.ActiveFather = null;
		}
	}

	private void SnapToGroundFacingPlayer()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		foreach (RaycastHit item in from h in Physics.RaycastAll(((Component)this).transform.position + Vector3.up * 1.5f, Vector3.down, 12f, -1, (QueryTriggerInteraction)1)
			orderby ((RaycastHit)(ref h)).distance
			select h)
		{
			RaycastHit current = item;
			if (!((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)this).transform))
			{
				((Component)this).transform.position = ((RaycastHit)(ref current)).point;
				break;
			}
		}
		((Component)this).transform.rotation = Quaternion.Euler(0f, YawToPlayer(), 0f);
	}

	private float YawToPlayer()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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)
		ENT_Player player = ENT_Player.GetPlayer();
		if ((Object)player == (Object)null)
		{
			return ((Component)this).transform.eulerAngles.y;
		}
		Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
		val.y = 0f;
		if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f))
		{
			Quaternion val2 = Quaternion.LookRotation(val);
			return ((Quaternion)(ref val2)).eulerAngles.y;
		}
		return ((Component)this).transform.eulerAngles.y;
	}

	private IEnumerator TurnToPlayer(float time)
	{
		float from = ((Component)this).transform.eulerAngles.y;
		float to = YawToPlayer();
		if (!(Mathf.Abs(Mathf.DeltaAngle(from, to)) < 8f))
		{
			for (float t = 0f; t < time; t += Time.deltaTime)
			{
				((Component)this).transform.rotation = Quaternion.Euler(0f, Mathf.LerpAngle(from, to, Mathf.SmoothStep(0f, 1f, t / time)), 0f);
				yield return null;
			}
			((Component)this).transform.rotation = Quaternion.Euler(0f, to, 0f);
		}
	}

	private static int InteractLayer()
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		if (layer >= 0)
		{
			return layer;
		}
		layer = 0;
		try
		{
			ENT_Player player = ENT_Player.GetPlayer();
			int mask = (((Object)player != (Object)null) ? ((LayerMask)(ref player.interactMask)).value : (-1));
			CL_Button val = ((IEnumerable<CL_Button>)Resources.FindObjectsOfTypeAll<CL_Button>()).FirstOrDefault((Func<CL_Button, bool>)((CL_Button b) => (Object)(object)b != (Object)null && (mask & (1 << ((Component)b).gameObject.layer)) != 0));
			if ((Object)val != (Object)null)
			{
				layer = ((Component)val).gameObject.layer;
			}
			else if ((mask & 1) == 0)
			{
				for (int num = 0; num < 32; num++)
				{
					if ((mask & (1 << num)) != 0 && LayerMask.LayerToName(num) != "Player")
					{
						layer = num;
						break;
					}
				}
			}
		}
		catch
		{
		}
		return layer;
	}
}
public class FatherClickable : MonoBehaviour, Clickable
{
	private DEN_TheFather father;

	private ObjectTagger tagger;

	private void Awake()
	{
		father = ((Component)this).GetComponentInParent<DEN_TheFather>();
		tagger = ((Component)this).GetComponent<ObjectTagger>();
	}

	public void Interact(InteractionInfo info)
	{
		if ((Object)(object)father != (Object)null)
		{
			father.Interact();
		}
	}

	public bool CanInteract(Interaction info)
	{
		if ((Object)(object)father != (Object)null)
		{
			return father.CanInteract;
		}
		return false;
	}

	public ObjectTagger GetTagger()
	{
		return tagger;
	}

	public GameObject GetGameObject()
	{
		return ((Component)this).gameObject;
	}

	public Sprite GetSprite()
	{
		return null;
	}
}
public class FatherClip
{
	public string Name;

	public float Fps;

	public int Frames;

	public bool Loop;

	public Vector3[] Pos;

	public Quaternion[] Rot;

	public float Length => (float)(Loop ? Frames : (Frames - 1)) / Fps;
}
public class FatherData
{
	public string[] BoneNames;

	public int[] Parents;

	public Vector3[] RestPos;

	public Quaternion[] RestRot;

	public Matrix4x4[] BindPoses;

	public Mesh Mesh;

	public Texture2D Flesh;

	public Texture2D Mask;

	public Dictionary<string, FatherClip> Clips = new Dictionary<string, FatherClip>();

	public List<KeyValuePair<string, KeyValuePair<int, Vector3>>> Attach = new List<KeyValuePair<string, KeyValuePair<int, Vector3>>>();

	private static string RS(BinaryReader r)
	{
		int count = r.ReadInt32();
		return Encoding.UTF8.GetString(r.ReadBytes(count));
	}

	private static Vector3 V3(BinaryReader r)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
	}

	private static Quaternion Q(BinaryReader r)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		return new Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
	}

	public static FatherData Load(byte[] bytes)
	{
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: 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_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_025d: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0277: Unknown result type (might be due to invalid IL or missing references)
		//IL_0284: Expected O, but got Unknown
		//IL_0363: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_037c: Expected O, but got Unknown
		//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0474: Unknown result type (might be due to invalid IL or missing references)
		//IL_0479: Unknown result type (might be due to invalid IL or missing references)
		FatherData fatherData = new FatherData();
		using BinaryReader binaryReader = new BinaryReader(new MemoryStream(bytes));
		if (new string(binaryReader.ReadChars(4)) != "FTHR")
		{
			throw new Exception("father.bin: bad header");
		}
		binaryReader.ReadInt32();
		int num = binaryReader.ReadInt32();
		fatherData.BoneNames = new string[num];
		fatherData.Parents = new int[num];
		fatherData.RestPos = (Vector3[])(object)new Vector3[num];
		fatherData.RestRot = (Quaternion[])(object)new Quaternion[num];
		fatherData.BindPoses = (Matrix4x4[])(object)new Matrix4x4[num];
		for (int i = 0; i < num; i++)
		{
			fatherData.BoneNames[i] = RS(binaryReader);
			fatherData.Parents[i] = binaryReader.ReadInt32();
			fatherData.RestPos[i] = V3(binaryReader);
			fatherData.RestRot[i] = Q(binaryReader);
			Matrix4x4 val = default(Matrix4x4);
			for (int j = 0; j < 4; j++)
			{
				for (int k = 0; k < 4; k++)
				{
					((Matrix4x4)(ref val))[k, j] = binaryReader.ReadSingle();
				}
			}
			fatherData.BindPoses[i] = val;
		}
		int num2 = binaryReader.ReadInt32();
		Vector3[] array = (Vector3[])(object)new Vector3[num2];
		Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
		Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
		BoneWeight[] array4 = (BoneWeight[])(object)new BoneWeight[num2];
		for (int l = 0; l < num2; l++)
		{
			array[l] = V3(binaryReader);
		}
		for (int m = 0; m < num2; m++)
		{
			array2[m] = V3(binaryReader);
		}
		for (int n = 0; n < num2; n++)
		{
			array3[n] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
		}
		int[] array5 = new int[num2 * 4];
		for (int num3 = 0; num3 < num2 * 4; num3++)
		{
			array5[num3] = binaryReader.ReadInt32();
		}
		for (int num4 = 0; num4 < num2; num4++)
		{
			int num5 = num4;
			BoneWeight val2 = default(BoneWeight);
			((BoneWeight)(ref val2)).boneIndex0 = array5[num4 * 4];
			((BoneWeight)(ref val2)).boneIndex1 = array5[num4 * 4 + 1];
			((BoneWeight)(ref val2)).boneIndex2 = array5[num4 * 4 + 2];
			((BoneWeight)(ref val2)).boneIndex3 = array5[num4 * 4 + 3];
			((BoneWeight)(ref val2)).weight0 = binaryReader.ReadSingle();
			((BoneWeight)(ref val2)).weight1 = binaryReader.ReadSingle();
			((BoneWeight)(ref val2)).weight2 = binaryReader.ReadSingle();
			((BoneWeight)(ref val2)).weight3 = binaryReader.ReadSingle();
			array4[num5] = val2;
		}
		Mesh val3 = new Mesh
		{
			name = "TheFather"
		};
		if (num2 > 65000)
		{
			val3.indexFormat = (IndexFormat)1;
		}
		val3.vertices = array;
		val3.normals = array2;
		val3.uv = array3;
		val3.boneWeights = array4;
		val3.bindposes = fatherData.BindPoses;
		int num6 = (val3.subMeshCount = binaryReader.ReadInt32());
		for (int num8 = 0; num8 < num6; num8++)
		{
			int num9 = binaryReader.ReadInt32();
			int[] array6 = new int[num9];
			for (int num10 = 0; num10 < num9; num10++)
			{
				array6[num10] = binaryReader.ReadInt32();
			}
			val3.SetTriangles(array6, num8);
		}
		val3.RecalculateBounds();
		val3.RecalculateTangents();
		fatherData.Mesh = val3;
		int num11 = binaryReader.ReadInt32();
		for (int num12 = 0; num12 < num11; num12++)
		{
			string text = RS(binaryReader);
			int count = binaryReader.ReadInt32();
			byte[] array7 = binaryReader.ReadBytes(count);
			Texture2D val4 = new Texture2D(2, 2, (TextureFormat)4, false)
			{
				name = "Father_" + text
			};
			ImageConversion.LoadImage(val4, array7, false);
			((Texture)val4).filterMode = (FilterMode)0;
			((Texture)val4).wrapMode = (TextureWrapMode)1;
			((Texture)val4).anisoLevel = 0;
			if (text == "flesh")
			{
				fatherData.Flesh = val4;
			}
			else
			{
				fatherData.Mask = val4;
			}
		}
		int num13 = binaryReader.ReadInt32();
		for (int num14 = 0; num14 < num13; num14++)
		{
			FatherClip fatherClip = new FatherClip
			{
				Name = RS(binaryReader),
				Fps = binaryReader.ReadSingle(),
				Frames = binaryReader.ReadInt32(),
				Loop = (binaryReader.ReadInt32() != 0)
			};
			fatherClip.Pos = (Vector3[])(object)new Vector3[fatherClip.Frames * num];
			fatherClip.Rot = (Quaternion[])(object)new Quaternion[fatherClip.Frames * num];
			for (int num15 = 0; num15 < fatherClip.Frames; num15++)
			{
				for (int num16 = 0; num16 < num; num16++)
				{
					fatherClip.Pos[num15 * num + num16] = V3(binaryReader);
					fatherClip.Rot[num15 * num + num16] = Q(binaryReader);
				}
			}
			fatherData.Clips[fatherClip.Name] = fatherClip;
		}
		int num17 = binaryReader.ReadInt32();
		for (int num18 = 0; num18 < num17; num18++)
		{
			string key = RS(binaryReader);
			int key2 = binaryReader.ReadInt32();
			fatherData.Attach.Add(new KeyValuePair<string, KeyValuePair<int, Vector3>>(key, new KeyValuePair<int, Vector3>(key2, V3(binaryReader))));
		}
		return fatherData;
	}
}
public class FatherAnimator : MonoBehaviour
{
	public Transform[] Bones;

	public FatherData Data;

	public float Speed = 1f;

	private FatherClip cur;

	private float t;

	private readonly Queue<KeyValuePair<string, float>> queue = new Queue<KeyValuePair<string, float>>();

	private Vector3[] fromPos;

	private Quaternion[] fromRot;

	private float fade;

	private float fadeLen;

	private bool reported;

	public string Current { get; private set; }

	public float Time01
	{
		get
		{
			if (cur != null)
			{
				return Mathf.Clamp01(t / cur.Length);
			}
			return 0f;
		}
	}

	public bool Finished
	{
		get
		{
			if (cur != null && !cur.Loop)
			{
				return t >= cur.Length;
			}
			return false;
		}
	}

	public event Action<string> ClipFinished;

	public void Play(string clip, float crossFade = 0f)
	{
		queue.Clear();
		Begin(clip, crossFade);
	}

	public void Queue(string clip, float crossFade = 0f)
	{
		queue.Enqueue(new KeyValuePair<string, float>(clip, crossFade));
	}

	private void Begin(string clip, float crossFade)
	{
		//IL_0072: 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)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		if (!Data.Clips.TryGetValue(clip, out var value))
		{
			Debug.LogWarning((object)("[TheFather] missing clip " + clip));
			return;
		}
		if (crossFade > 0f && Bones != null)
		{
			fromPos = (Vector3[])(object)new Vector3[Bones.Length];
			fromRot = (Quaternion[])(object)new Quaternion[Bones.Length];
			for (int i = 0; i < Bones.Length; i++)
			{
				fromPos[i] = Bones[i].localPosition;
				fromRot[i] = Bones[i].localRotation;
			}
			fade = 0f;
			fadeLen = crossFade;
		}
		else
		{
			fadeLen = 0f;
		}
		cur = value;
		Current = clip;
		t = 0f;
		reported = false;
		Apply();
	}

	private void Update()
	{
		if (cur == null || Bones == null)
		{
			return;
		}
		t += Time.deltaTime * Speed;
		fade += Time.deltaTime;
		if (!cur.Loop && t >= cur.Length)
		{
			t = cur.Length;
			if (!reported)
			{
				reported = true;
				string current = Current;
				if (queue.Count > 0)
				{
					KeyValuePair<string, float> keyValuePair = queue.Dequeue();
					Begin(keyValuePair.Key, keyValuePair.Value);
				}
				this.ClipFinished?.Invoke(current);
				return;
			}
		}
		Apply();
	}

	private void Apply()
	{
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		int num = Bones.Length;
		float num2 = t * cur.Fps;
		int num3;
		int num4;
		if (cur.Loop)
		{
			num2 %= (float)cur.Frames;
			num3 = Mathf.FloorToInt(num2);
			num4 = (num3 + 1) % cur.Frames;
		}
		else
		{
			num2 = Mathf.Min(num2, (float)(cur.Frames - 1));
			num3 = Mathf.FloorToInt(num2);
			num4 = Mathf.Min(num3 + 1, cur.Frames - 1);
		}
		float num5 = num2 - (float)num3;
		float num6 = ((fadeLen > 0f) ? Mathf.SmoothStep(0f, 1f, Mathf.Clamp01(fade / fadeLen)) : 1f);
		for (int i = 0; i < num; i++)
		{
			Vector3 val = Vector3.Lerp(cur.Pos[num3 * num + i], cur.Pos[num4 * num + i], num5);
			Quaternion val2 = Quaternion.Slerp(cur.Rot[num3 * num + i], cur.Rot[num4 * num + i], num5);
			if (num6 < 1f)
			{
				val = Vector3.Lerp(fromPos[i], val, num6);
				val2 = Quaternion.Slerp(fromRot[i], val2, num6);
			}
			Bones[i].localPosition = val;
			Bones[i].localRotation = val2;
		}
	}
}
public static class FatherBuilder
{
	public static GameObject Build(FatherData d, float scale, Shader shader, out FatherAnimator anim, out Transform[] attach)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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_00cf: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("The Father");
		GameObject val2 = new GameObject("Model");
		val2.transform.SetParent(val.transform, false);
		val2.transform.localScale = Vector3.one * scale;
		Transform[] array = (Transform[])(object)new Transform[d.BoneNames.Length];
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = new GameObject(d.BoneNames[i]).transform;
			array[i].SetParent((d.Parents[i] < 0) ? val2.transform : array[d.Parents[i]], false);
			array[i].localPosition = d.RestPos[i];
			array[i].localRotation = d.RestRot[i];
		}
		GameObject val3 = new GameObject("Body");
		val3.transform.SetParent(val2.transform, false);
		SkinnedMeshRenderer val4 = val3.AddComponent<SkinnedMeshRenderer>();
		val4.sharedMesh = d.Mesh;
		val4.bones = array;
		val4.rootBone = array[0];
		val4.updateWhenOffscreen = true;
		if ((Object)(object)shader != (Object)null)
		{
			((Renderer)val4).sharedMaterials = (Material[])(object)new Material[2]
			{
				MakeMat(shader, d.Flesh, 0.18f, "Father_Flesh"),
				MakeMat(shader, d.Mask, 0.35f, "Father_Mask")
			};
		}
		anim = val2.AddComponent<FatherAnimator>();
		anim.Bones = array;
		anim.Data = d;
		attach = (Transform[])(object)new Transform[d.Attach.Count];
		for (int j = 0; j < attach.Length; j++)
		{
			KeyValuePair<string, KeyValuePair<int, Vector3>> keyValuePair = d.Attach[j];
			attach[j] = new GameObject(keyValuePair.Key).transform;
			attach[j].SetParent(array[keyValuePair.Value.Key], false);
			attach[j].localPosition = keyValuePair.Value.Value;
		}
		return val;
	}

	private static Material MakeMat(Shader shader, Texture2D tex, float smooth, string name)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		Material val = new Material(shader)
		{
			name = name
		};
		if (val.HasProperty("_MainTex"))
		{
			val.SetTexture("_MainTex", (Texture)(object)tex);
		}
		if (val.HasProperty("_BaseMap"))
		{
			val.SetTexture("_BaseMap", (Texture)(object)tex);
		}
		if (val.HasProperty("_Color"))
		{
			val.SetColor("_Color", Color.white);
		}
		if (val.HasProperty("_Glossiness"))
		{
			val.SetFloat("_Glossiness", smooth);
		}
		if (val.HasProperty("_Metallic"))
		{
			val.SetFloat("_Metallic", 0f);
		}
		val.mainTexture = (Texture)(object)tex;
		return val;
	}
}
[BepInPlugin("com.wkmods.thefather", "The Father", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "com.wkmods.thefather";

	internal static Plugin Instance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<float> Scale;

	internal static ConfigEntry<string> Line;

	internal static ConfigEntry<string> TextColor;

	internal static ConfigEntry<int> GrubCount;

	internal static ConfigEntry<bool> RefillGrubs;

	internal static ConfigEntry<float> TextTime;

	internal static FatherData Data;

	internal static ConfigEntry<bool> QuestsEnabled;

	internal static ConfigEntry<bool> SilosIntro;

	internal static ConfigEntry<bool> QuestGrubs;

	internal static ConfigEntry<bool> QuestBarnacles;

	internal static ConfigEntry<bool> QuestFetch;

	internal static ConfigEntry<bool> QuestBuddy;

	internal static ConfigEntry<bool> ShowTracker;

	internal static ConfigEntry<int> BarnacleTarget;

	internal static ConfigEntry<int> GiveUpAfter;

	internal static ConfigEntry<string> BreakroomKeywords;

	internal static ConfigEntry<string> BuddyName;

	internal static ConfigEntry<string> FetchKeywords;

	internal static ConfigEntry<string> GrubQuestRegions;

	private static GameObject template;

	private CommandConsole lastConsole;

	private void Awake()
	{
		//IL_033c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		Scale = ((BaseUnityPlugin)this).Config.Bind<float>("The Father", "Scale", 0.42f, "Size multiplier (1.0 = Blender size, ~8.4 m tall). 0.42 is about 3.5 m.");
		Line = ((BaseUnityPlugin)this).Config.Bind<string>("The Father", "Line", "Give these to the mother will ya?", "What he says when you interact with him.");
		TextColor = ((BaseUnityPlugin)this).Config.Bind<string>("The Father", "TextColor", "#C8141E", "Colour of his psychic text (hex).");
		TextTime = ((BaseUnityPlugin)this).Config.Bind<float>("The Father", "TextTime", 5f, "Seconds his text stays on screen.");
		GrubCount = ((BaseUnityPlugin)this).Config.Bind<int>("The Father", "GrubCount", 3, "How many grubs he holds out (max 3 on the hand).");
		RefillGrubs = ((BaseUnityPlugin)this).Config.Bind<bool>("The Father", "RefillGrubs", false, "(Unused when quests are on.)");
		QuestsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "Enabled", true, "He appears in every breakroom (first time you enter it) and gives side quests.");
		SilosIntro = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "AppearAtSilosStart", true, "He also crawls out when you first spawn in Silos.");
		BreakroomKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("Quests", "BreakroomKeywords", "interlude,breakroom,saferoom,break room", "Extra level-name words that count as a breakroom (levels flagged as safe areas always count).");
		QuestGrubs = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "GrubQuest", true, "Give the Mother the grubs he hands you.");
		QuestBarnacles = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "BarnacleQuest", true, "Kill barnacles before the next breakroom.");
		QuestFetch = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "FetchQuest", true, "Bring him a specific item.");
		QuestBuddy = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "BuddyQuest", true, "Keep a Calming Buddy safe until the next region.");
		BarnacleTarget = ((BaseUnityPlugin)this).Config.Bind<int>("Quests", "BarnaclesToKill", 3, "how many barnacles you have to kill");
		GrubQuestRegions = ((BaseUnityPlugin)this).Config.Bind<string>("Quests", "GrubQuestRegions", "abyss", "the grub quest only shows up in these regions (the one before the nest)");
		GiveUpAfter = ((BaseUnityPlugin)this).Config.Bind<int>("Quests", "GiveUpAfterMeetings", 3, "Unfinished grub/fetch quests are dropped after this many meetings.");
		BuddyName = ((BaseUnityPlugin)this).Config.Bind<string>("Quests", "BuddyItemName", "Calming Buddy", "Item name he hands out for the buddy quest.");
		FetchKeywords = ((BaseUnityPlugin)this).Config.Bind<string>("Quests", "FetchItems", "bean,piton,pill,injector,flare,rebar,food,ration,battery,bandage,rope,soda,can", "Words used to pick fetch-quest items (any item whose name contains one).");
		ShowTracker = ((BaseUnityPlugin)this).Config.Bind<bool>("Quests", "ShowTracker", true, "Show the current quest in the top-left corner.");
		try
		{
			Data = FatherData.Load(File.ReadAllBytes(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "father.bin")));
			Log.LogInfo((object)string.Format("The Father loaded: {0} verts, {1} bones, clips: {2}", Data.Mesh.vertexCount, Data.BoneNames.Length, string.Join(", ", Data.Clips.Keys.ToArray())));
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Could not load father.bin: " + ex));
			return;
		}
		Harmony h = new Harmony("com.wkmods.thefather");
		try
		{
			OmniBridge.TryPatch(h);
		}
		catch (Exception ex2)
		{
			Log.LogWarning((object)("OmniConsole hook failed: " + ex2.Message));
		}
		try
		{
			Quests.Patch(h);
		}
		catch (Exception ex3)
		{
			Log.LogWarning((object)("Quest hooks failed: " + ex3.Message));
		}
	}

	private void Update()
	{
		CommandConsole instance = CommandConsole.instance;
		if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)lastConsole)
		{
			lastConsole = instance;
			try
			{
				CommandConsole.RemoveCommand("spawnfather");
				CommandConsole.BuildCommand("spawnfather", (Action<string[]>)delegate
				{
					CommandConsole.Log(((Object)(object)SpawnAtCrosshair() != (Object)null) ? "The Father rises." : "Couldn't spawn The Father (see BepInEx log).");
				}).Description("Spawn The Father at your crosshair  <color=#C8141E>[The Father]</color>");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Command registration failed: " + ex.Message));
			}
			try
			{
				CommandConsole.RemoveCommand("fatherquest");
				CommandConsole.BuildCommand("fatherquest", (Action<string[]>)delegate
				{
					CommandConsole.Log((Quests.Current == Quests.Q.None) ? "No quest from The Father right now." : Quests.HudText());
				}).Description("Show The Father's current quest  <color=#C8141E>[The Father]</color>");
			}
			catch
			{
			}
		}
		if (Data == null)
		{
			return;
		}
		try
		{
			Quests.Tick();
		}
		catch (Exception ex2)
		{
			if (Time.frameCount % 600 == 0)
			{
				Log.LogWarning((object)("Quest tick: " + ex2.Message));
			}
		}
	}

	internal static GameObject SpawnNearPlayer()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_0073: 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_0082: 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_009d: 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_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: 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)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: 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_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: 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_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0175: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GetTemplate();
		ENT_Player player = ENT_Player.GetPlayer();
		Camera val2 = Camera.main;
		if ((Object)(object)val == (Object)null || (Object)player == (Object)null)
		{
			return null;
		}
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = player.cam;
		}
		if ((Object)(object)val2 == (Object)null)
		{
			return null;
		}
		int num = -5 & ~(1 << ((Component)player).gameObject.layer);
		Vector3 position = ((Component)val2).transform.position;
		Vector3 val3 = Vector3.ProjectOnPlane(((Component)val2).transform.forward, Vector3.up);
		if (((Vector3)(ref val3)).sqrMagnitude < 0.01f)
		{
			val3 = ((Component)player).transform.forward;
		}
		((Vector3)(ref val3)).Normalize();
		float num2 = 8.4f * Scale.Value;
		float[] array = new float[10] { 0f, 25f, -25f, 50f, -50f, 80f, -80f, 120f, -120f, 180f };
		RaycastHit val6 = default(RaycastHit);
		foreach (float num3 in array)
		{
			float[] array2 = new float[4] { 5.5f, 4.5f, 7f, 3.5f };
			foreach (float num4 in array2)
			{
				Vector3 val4 = Quaternion.Euler(0f, num3, 0f) * val3;
				Vector3 val5 = position + val4 * num4;
				if (!Physics.Linecast(position, val5, num, (QueryTriggerInteraction)1) && Physics.Raycast(val5, Vector3.down, ref val6, 6f, num, (QueryTriggerInteraction)1) && !(((RaycastHit)(ref val6)).normal.y < 0.7f) && !Physics.Raycast(((RaycastHit)(ref val6)).point + Vector3.up * 0.2f, Vector3.up, num2 * 0.85f, num, (QueryTriggerInteraction)1) && !Physics.CheckSphere(((RaycastHit)(ref val6)).point + Vector3.up * (num2 * 0.45f), 0.9f * Scale.Value / 0.42f, num, (QueryTriggerInteraction)1))
				{
					GameObject obj = Object.Instantiate<GameObject>(val, ((RaycastHit)(ref val6)).point, Quaternion.LookRotation(-val4));
					((Object)obj).name = "The Father";
					obj.SetActive(true);
					return obj;
				}
			}
		}
		Log.LogInfo((object)"No clear floor spot for The Father here.");
		return null;
	}

	internal static GameObject GetTemplate()
	{
		if ((Object)(object)template != (Object)null)
		{
			return template;
		}
		if (Data == null)
		{
			return null;
		}
		FatherAnimator anim;
		Transform[] attach;
		GameObject obj = FatherBuilder.Build(Data, Scale.Value, null, out anim, out attach);
		obj.SetActive(false);
		Object.DontDestroyOnLoad((Object)(object)obj);
		FatherLook.Apply(obj.GetComponentInChildren<SkinnedMeshRenderer>(true), Data);
		obj.AddComponent<DEN_TheFather>().Setup(anim, attach);
		template = obj;
		return template;
	}

	internal static GameObject SpawnAtCrosshair()
	{
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_004c: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_0072: 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_00bd: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Expected O, but got Unknown
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GetTemplate();
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		Camera val2 = Camera.main;
		ENT_Player player = ENT_Player.GetPlayer();
		if ((Object)(object)val2 == (Object)null && (Object)player != (Object)null)
		{
			val2 = player.cam;
		}
		if ((Object)(object)val2 == (Object)null)
		{
			return null;
		}
		Vector3 val3 = ((Component)val2).transform.position + ((Component)val2).transform.forward * 6f;
		foreach (RaycastHit item in from h in Physics.RaycastAll(((Component)val2).transform.position, ((Component)val2).transform.forward, 200f, -1, (QueryTriggerInteraction)1)
			orderby ((RaycastHit)(ref h)).distance
			select h)
		{
			RaycastHit current = item;
			if (!((Object)player != (Object)null) || !((Component)((RaycastHit)(ref current)).collider).transform.IsChildOf(((Component)player).transform))
			{
				val3 = ((RaycastHit)(ref current)).point;
				break;
			}
		}
		GameObject obj = Object.Instantiate<GameObject>(val, val3, Quaternion.identity);
		((Object)obj).name = "The Father";
		obj.SetActive(true);
		return obj;
	}
}
internal static class OmniBridge
{
	private static MethodInfo addMethod;

	private static Type entryType;

	private static Type catType;

	public static void TryPatch(Harmony h)
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Expected O, but got Unknown
		Type type = AccessTools.TypeByName("OmniConsole.Registry");
		if (type == null)
		{
			Plugin.Log.LogInfo((object)"OmniConsole not found — use the 'spawnfather' command.");
			return;
		}
		entryType = AccessTools.TypeByName("OmniConsole.SpawnEntry");
		catType = AccessTools.TypeByName("OmniConsole.Category");
		addMethod = AccessTools.Method(type, "Add", (Type[])null, (Type[])null);
		h.Patch((MethodBase)AccessTools.Method(type, "Build", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(OmniBridge), "BuildPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		Plugin.Log.LogInfo((object)"Registered with OmniConsole: spawn the_father");
	}

	private static void BuildPostfix()
	{
		try
		{
			GameObject template = Plugin.GetTemplate();
			if ((Object)(object)template == (Object)null || addMethod == null)
			{
				return;
			}
			object obj = Activator.CreateInstance(entryType);
			Set(obj, "displayName", "The Father");
			Set(obj, "category", Enum.Parse(catType, "Denizen"));
			Set(obj, "source", "The Father mod");
			Set(obj, "prefab", template);
			addMethod.Invoke(null, new object[1] { obj });
			if (!(AccessTools.Field(AccessTools.TypeByName("OmniConsole.Registry"), "All").GetValue(null) is IList list))
			{
				return;
			}
			List<object> list2 = (from object x in list
				orderby (int)Get(x, "category")
				select x).ThenBy<object, string>((object x) => (string)Get(x, "key"), StringComparer.OrdinalIgnoreCase).ToList();
			list.Clear();
			foreach (object item in list2)
			{
				list.Add(item);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Adding The Father to OmniConsole failed: " + ex.Message));
		}
	}

	private static void Set(object o, string f, object v)
	{
		o.GetType().GetField(f).SetValue(o, v);
	}

	private static object Get(object o, string f)
	{
		return o.GetType().GetField(f).GetValue(o);
	}
}
internal static class FatherLook
{
	private static Material baseMat;

	private static bool searched;

	public static bool UsedFallback { get; private set; }

	private static Material FindBase()
	{
		if (searched && (Object)(object)baseMat != (Object)null)
		{
			return baseMat;
		}
		searched = true;
		try
		{
			WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
			List<GameObject> list = new List<GameObject>();
			if ((Object)(object)fullCombinedAssetDatabase != (Object)null)
			{
				list.AddRange(fullCombinedAssetDatabase.denizenPrefabs.Where((GameObject g) => (Object)(object)g != (Object)null));
				list.AddRange(fullCombinedAssetDatabase.itemPrefabs.Where((GameObject g) => (Object)(object)g != (Object)null));
			}
			foreach (GameObject item in list.OrderBy((GameObject g) => (!((Object)(object)g.GetComponentInChildren<DEN_SlugGrub>(true) != (Object)null)) ? (((Object)(object)g.GetComponentInChildren<SkinnedMeshRenderer>(true) != (Object)null) ? 1 : 2) : 0))
			{
				Renderer[] componentsInChildren = item.GetComponentsInChildren<Renderer>(true);
				for (int num = 0; num < componentsInChildren.Length; num++)
				{
					Material[] sharedMaterials = componentsInChildren[num].sharedMaterials;
					foreach (Material val in sharedMaterials)
					{
						if (Usable(val))
						{
							baseMat = val;
							Plugin.Log.LogInfo((object)("The Father uses shader '" + ((Object)val.shader).name + "' (from " + ((Object)item).name + ")"));
							return baseMat;
						}
					}
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Shader search failed: " + ex.Message));
		}
		return null;
	}

	private static bool Usable(Material m)
	{
		if ((Object)(object)m != (Object)null && (Object)(object)m.shader != (Object)null && (Object)(object)m.mainTexture != (Object)null && m.renderQueue < 2450)
		{
			return m.HasProperty("_MainTex");
		}
		return false;
	}

	public static void Apply(SkinnedMeshRenderer smr, FatherData d)
	{
		if (!((Object)(object)smr == (Object)null))
		{
			Material val = FindBase();
			UsedFallback = (Object)(object)val == (Object)null;
			((Renderer)smr).sharedMaterials = (Material[])(object)new Material[2]
			{
				Make(val, d.Flesh, "Father_Flesh"),
				Make(val, d.Mask, "Father_Mask")
			};
		}
	}

	private static Material Make(Material b, Texture2D tex, string name)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected O, but got Unknown
		//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_013f: Expected O, but got Unknown
		//IL_00b6: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		Material val;
		if ((Object)(object)b != (Object)null)
		{
			val = new Material(b)
			{
				name = name
			};
			string[] array = new string[9] { "_BumpMap", "_NormalMap", "_EmissionMap", "_DetailAlbedoMap", "_DetailNormalMap", "_MetallicGlossMap", "_OcclusionMap", "_SpecGlossMap", "_ParallaxMap" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, (Texture)null);
				}
			}
			val.DisableKeyword("_NORMALMAP");
			val.DisableKeyword("_EMISSION");
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", Color.black);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", Color.white);
			}
			if (val.HasProperty("_MainTex"))
			{
				val.SetTextureScale("_MainTex", Vector2.one);
				val.SetTextureOffset("_MainTex", Vector2.zero);
			}
		}
		else
		{
			val = new Material(Shader.Find("Standard") ?? Shader.Find("Legacy Shaders/Diffuse") ?? Shader.Find("Unlit/Texture"))
			{
				name = name
			};
			if (val.HasProperty("_Glossiness"))
			{
				val.SetFloat("_Glossiness", 0.15f);
			}
		}
		val.mainTexture = (Texture)(object)tex;
		return val;
	}
}
internal static class FatherVoice
{
	private static HUD_CustomElement_PsychicCommunication prefab;

	private static AudioClip clip;

	private static float darken = 0.05f;

	private static bool Find()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected O, but got Unknown
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		if ((Object)(object)prefab != (Object)null)
		{
			return true;
		}
		try
		{
			UT_PsychicCommunicator val = null;
			if ((Object)DEN_Mother.instance != (Object)null)
			{
				val = DEN_Mother.instance.psychicCommunicator;
			}
			if ((Object)(object)val == (Object)null)
			{
				WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
				if ((Object)(object)fullCombinedAssetDatabase != (Object)null)
				{
					foreach (GameObject denizenPrefab in fullCombinedAssetDatabase.denizenPrefabs)
					{
						if (!((Object)(object)denizenPrefab == (Object)null))
						{
							DEN_Mother componentInChildren = denizenPrefab.GetComponentInChildren<DEN_Mother>(true);
							if ((Object)componentInChildren != (Object)null && (Object)(object)componentInChildren.psychicCommunicator != (Object)null)
							{
								val = componentInChildren.psychicCommunicator;
								break;
							}
						}
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				val = (from c in Resources.FindObjectsOfTypeAll<UT_PsychicCommunicator>()
					where (Object)(object)c.psychicCommunicationPrefab != (Object)null
					orderby (!((Object)(object)((Component)c).GetComponentInParent<DEN_Mother>() != (Object)null)) ? 1 : 0
					select c).FirstOrDefault();
			}
			if ((Object)(object)val != (Object)null)
			{
				prefab = val.psychicCommunicationPrefab;
				darken = val.darken;
				clip = val.clip;
				if ((Object)(object)clip == (Object)null && (Object)(object)val.clipHandler != (Object)null && !string.IsNullOrEmpty(val.clipHandlerID))
				{
					try
					{
						clip = val.clipHandler.GetSound(val.clipHandlerID);
					}
					catch
					{
					}
				}
			}
			if ((Object)(object)prefab == (Object)null)
			{
				prefab = ((IEnumerable<HUD_CustomElement_PsychicCommunication>)Resources.FindObjectsOfTypeAll<HUD_CustomElement_PsychicCommunication>()).FirstOrDefault((Func<HUD_CustomElement_PsychicCommunication, bool>)delegate(HUD_CustomElement_PsychicCommunication h)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					Scene scene = ((Component)h).gameObject.scene;
					return !((Scene)(ref scene)).IsValid();
				});
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Mother's voice lookup failed: " + ex.Message));
		}
		if ((Object)(object)prefab == (Object)null)
		{
			Plugin.Log.LogWarning((object)"Couldn't find the Mother's psychic text; using a plain fallback.");
		}
		return (Object)(object)prefab != (Object)null;
	}

	public static TMP_FontAsset Font()
	{
		if (!Find())
		{
			return null;
		}
		try
		{
			TMP_Text val = (((Object)(object)prefab.subtitleText != (Object)null) ? ((Component)prefab.subtitleText).GetComponent<TMP_Text>() : null);
			return ((Object)(object)val != (Object)null) ? val.font : null;
		}
		catch
		{
			return null;
		}
	}

	public static void Say(string text)
	{
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		float value = Plugin.TextTime.Value;
		Color val = default(Color);
		if (!ColorUtility.TryParseHtmlString(Plugin.TextColor.Value, ref val))
		{
			((Color)(ref val))..ctor(0.78f, 0.08f, 0.12f);
		}
		if (Find() && (Object)(object)CL_UIManager.instance != (Object)null && (Object)(object)CL_UIManager.instance.customElementLayoutGroup != (Object)null)
		{
			try
			{
				HUD_CustomElement_PsychicCommunication val2 = Object.Instantiate<HUD_CustomElement_PsychicCommunication>(prefab, CL_UIManager.instance.customElementLayoutGroup);
				((HUD_CustomElement)val2).id = "thefather-psychic-" + Time.frameCount;
				((Component)val2).gameObject.SetActive(true);
				TMP_Text val3 = (((Object)(object)val2.subtitleText != (Object)null) ? ((Component)val2.subtitleText).GetComponent<TMP_Text>() : null);
				if ((Object)(object)val3 != (Object)null)
				{
					((Graphic)val3).color = val;
					val3.faceColor = Color32.op_Implicit(val);
				}
				val2.Show(value, darken);
				val2.PlaySubtitle(text);
				if ((Object)(object)clip != (Object)null)
				{
					val2.PlayAudio(clip, 2f);
				}
				Object.Destroy((Object)(object)((Component)val2).gameObject, value + 6f);
				((MonoBehaviour)Plugin.Instance).StartCoroutine(KeepRed(val3, val, value + 5f));
				return;
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Psychic text failed, using fallback: " + ex.Message));
			}
		}
		FallbackText.Show(text, val, value);
	}

	private static IEnumerator KeepRed(TMP_Text tmp, Color col, float t)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		float end = Time.time + t;
		while ((Object)(object)tmp != (Object)null && Time.time < end)
		{
			if (((Graphic)tmp).color != col)
			{
				((Graphic)tmp).color = col;
			}
			yield return null;
		}
	}
}
internal class FallbackText : MonoBehaviour
{
	private string text;

	private Color col;

	private float until;

	private GUIStyle style;

	public static void Show(string text, Color col, float time)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: 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_0036: Expected O, but got Unknown
		GameObject val = new GameObject("TheFather_Text");
		FallbackText fallbackText = val.AddComponent<FallbackText>();
		fallbackText.text = text;
		fallbackText.col = col;
		fallbackText.until = Time.time + time;
		Object.Destroy((Object)val, time + 0.5f);
	}

	private void OnGUI()
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		if (style == null)
		{
			style = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontSize = Screen.height / 22,
				wordWrap = true
			};
		}
		style.normal.textColor = new Color(col.r, col.g, col.b, Mathf.Clamp01(until - Time.time));
		GUI.Label(new Rect((float)Screen.width * 0.15f, (float)Screen.height * 0.62f, (float)Screen.width * 0.7f, (float)Screen.height * 0.2f), text, style);
	}
}
public class TalkPlan
{
	public List<string> Lines = new List<string>();

	public int RewardLine = -1;

	public Trinket Reward;

	public List<Item_Object> Gifts = new List<Item_Object>();

	public int GiftLine;

	public bool GiftIsBuddy;
}
internal static class Quests
{
	public enum Q
	{
		None,
		Grubs,
		Barnacles,
		Fetch,
		Buddy
	}

	public static Q Current = Q.None;

	public static int Progress;

	public static int Target;

	public static int Meetings;

	public static bool Completed;

	public static bool Failed;

	public static string FailReason = "";

	public static Item_Object FetchPrefab;

	public static string FetchName = "";

	public static Item BuddyItem;

	private static object buddyRegion;

	private static Q lastType = Q.None;

	private static object lastGMan;

	private static object lastLevel;

	private static object lastRegion;

	private static float runStartTime = -1f;

	private static float nextTick;

	private static float spawnAt = -1f;

	private static int spawnTries;

	private static bool silosIntroDone;

	private static bool grubsGivenThisRun;

	private static string hereDesc = "";

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

	public static DEN_TheFather ActiveFather;

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

	private static readonly MethodInfo clearItem = AccessTools.Method(typeof(Inventory), "ClearItemFromInventory", (Type[])null, (Type[])null);

	private static bool GrubsDue
	{
		get
		{
			if (Plugin.QuestGrubs.Value && !grubsGivenThisRun && InGrubRegion())
			{
				return (Object)(object)Gifts.Grub() != (Object)null;
			}
			return false;
		}
	}

	private static void ResetRun()
	{
		Current = Q.None;
		Progress = (Target = (Meetings = 0));
		Completed = (Failed = false);
		FetchPrefab = null;
		BuddyItem = null;
		lastType = Q.None;
		silosIntroDone = false;
		grubsGivenThisRun = false;
		counted.Clear();
		visitedBreakrooms.Clear();
		lastLevel = (lastRegion = null);
		spawnAt = -1f;
		runStartTime = Time.time;
	}

	public static void Tick()
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected O, but got Unknown
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		HUD.Update();
		if (Time.time < nextTick)
		{
			return;
		}
		nextTick = Time.time + 0.5f;
		CL_GameManager gMan = CL_GameManager.gMan;
		if ((Object)(object)gMan == (Object)null || (Object)ENT_Player.GetPlayer() == (Object)null)
		{
			return;
		}
		if (gMan != lastGMan)
		{
			lastGMan = gMan;
			ResetRun();
			Plugin.Log.LogInfo((object)"The Father: new run.");
		}
		M_Level val = null;
		try
		{
			LevelInfo currentLevelFromBounds = WorldLoader.GetCurrentLevelFromBounds();
			val = ((currentLevelFromBounds != null) ? currentLevelFromBounds.GetLevel() : null);
		}
		catch
		{
		}
		if ((Object)val == (Object)null)
		{
			return;
		}
		object region = val.region;
		if (region != null && region != lastRegion)
		{
			if (lastRegion != null)
			{
				OnRegionChanged();
			}
			lastRegion = region;
		}
		if (Current == Q.Buddy && !Completed && !Failed && BuddyLost())
		{
			Fail("lost");
		}
		if (val != lastLevel)
		{
			lastLevel = val;
			string text = Describe(val);
			hereDesc = text.ToLowerInvariant();
			bool flag = IsBreakroom(val);
			Plugin.Log.LogInfo((object)$"The Father: entered {text} (breakroom: {flag})");
			int instanceID = ((Object)val).GetInstanceID();
			if (Plugin.QuestsEnabled.Value && flag && !visitedBreakrooms.Contains(instanceID))
			{
				visitedBreakrooms.Add(instanceID);
				OnBreakroomReached();
				spawnAt = Time.time + 1.5f;
				spawnTries = 0;
			}
			else if (Plugin.QuestsEnabled.Value && Plugin.SilosIntro.Value && !silosIntroDone && Time.time - runStartTime < 90f && text.ToLowerInvariant().Contains("silo"))
			{
				silosIntroDone = true;
				spawnAt = Time.time + 3f;
				spawnTries = 0;
			}
		}
		if (!(spawnAt > 0f) || !(Time.time >= spawnAt))
		{
			return;
		}
		spawnAt = -1f;
		if ((Object)(object)ActiveFather == (Object)null)
		{
			GameObject val2 = Plugin.SpawnNearPlayer();
			if ((Object)(object)val2 != (Object)null)
			{
				ActiveFather = val2.GetComponent<DEN_TheFather>();
			}
			else if (++spawnTries < 6)
			{
				spawnAt = Time.time + 2f;
			}
		}
	}

	private static string Describe(M_Level lvl)
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		string text = (((Object)(object)lvl.region != (Object)null) ? lvl.region.regionName : "");
		string text2 = (((Object)(object)lvl.subRegion != (Object)null) ? lvl.subRegion.subregionName : "");
		return "level '" + ((Object)lvl).name + "' / '" + lvl.levelName + "', region '" + text + "', subregion '" + text2 + "'";
	}

	public static bool IsBreakroom(M_Level lvl)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		if (lvl.safeArea || lvl.HasTag("saferoom"))
		{
			return true;
		}
		string text = (((Object)lvl).name + " " + lvl.levelName).ToLowerInvariant();
		return (from k in Plugin.BreakroomKeywords.Value.Split(',')
			select k.Trim().ToLowerInvariant() into k
			where k.Length > 0
			select k).Any(text.Contains);
	}

	private static void OnBreakroomReached()
	{
		if (Current == Q.Barnacles && !Completed && !Failed)
		{
			if (Progress >= Target)
			{
				Completed = true;
			}
			else
			{
				Fail("barnacles");
			}
		}
	}

	private static void OnRegionChanged()
	{
		if (Current == Q.Buddy && !Completed && !Failed)
		{
			if (BuddyWithPlayer())
			{
				Completed = true;
			}
			else
			{
				Fail("lost");
			}
		}
	}

	private static void Fail(string why)
	{
		Failed = true;
		FailReason = why;
		Plugin.Log.LogInfo((object)("The Father's quest failed: " + why));
	}

	public static void Patch(Harmony h)
	{
		//IL_0048: 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_006a: Expected O, but got Unknown
		//IL_006a: Expected O, but got Unknown
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		try
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(GameEntity), "Kill", new Type[2]
			{
				typeof(string),
				typeof(DamageInfo)
			}, (Type[])null);
			h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Quests), "KillPre", (Type[])null), new HarmonyMethod(typeof(Quests), "KillPost", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Plugin.Log.LogInfo((object)"Barnacle kill counter hooked.");
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Barnacle hook failed: " + ex));
		}
		try
		{
			h.Patch((MethodBase)AccessTools.Method(typeof(DEN_Mother), "GrabItem", new Type[1] { typeof(Item) }, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Quests), "MotherGrab", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			Plugin.Log.LogInfo((object)"Mother grub counter hooked.");
		}
		catch (Exception ex2)
		{
			Plugin.Log.LogWarning((object)("Mother hook failed: " + ex2));
		}
	}

	private static void KillPre(GameEntity __instance, out bool __state)
	{
		__state = (Object)(object)__instance != (Object)null && __instance.dead;
	}

	private static void KillPost(GameEntity __instance, bool __state)
	{
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if ((Object)(object)__instance == (Object)null || __state || !__instance.dead || !IsBarnacle(__instance) || !counted.Add(((Object)__instance).GetInstanceID()))
			{
				return;
			}
			Plugin.Log.LogInfo((object)("Barnacle killed: " + ((Object)__instance).name));
			if (Current == Q.Barnacles && !Completed && !Failed)
			{
				Progress++;
				if (Progress >= Target)
				{
					Completed = true;
				}
			}
		}
		catch
		{
		}
	}

	private static bool IsBarnacle(GameEntity e)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		if (e is DEN_Barnacle || e is DEN_Barnacle_Zombie)
		{
			return true;
		}
		return (((Object)e).name + " " + e.entityPrefabID + " " + e.objectType).ToLowerInvariant().Contains("barnacle");
	}

	private static void MotherGrab(Item item)
	{
		if (Current == Q.Grubs && !Completed && !Failed && item != null && IsGrub(item))
		{
			Progress++;
			if (Progress >= Target)
			{
				Completed = true;
			}
		}
	}

	private static bool IsGrub(Item item)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		if ((item.prefabName ?? "").ToLowerInvariant().Contains("grub") || (item.itemName ?? "").ToLowerInvariant().Contains("grub"))
		{
			return true;
		}
		try
		{
			Item_Object dropObject = item.GetDropObject(false);
			return (Object)dropObject != (Object)null && (Object)(object)((Component)dropObject).GetComponent<DEN_SlugGrub>() != (Object)null;
		}
		catch
		{
			return false;
		}
	}

	private static bool InGrubRegion()
	{
		return (from k in Plugin.GrubQuestRegions.Value.Split(',')
			select k.Trim().ToLowerInvariant() into k
			where k.Length > 0
			select k).Any(hereDesc.Contains);
	}

	public static TalkPlan BuildPlan()
	{
		TalkPlan talkPlan = new TalkPlan();
		bool flag = true;
		if (GrubsDue && Current != Q.None && Current != Q.Grubs && !Completed && !Failed)
		{
			talkPlan.Lines.Add("Forget that other thing. This is more important.");
			Clear();
		}
		if (Current != Q.None)
		{
			if (Current == Q.Fetch && !Completed && TakeFetchItem())
			{
				Completed = true;
			}
			if (Completed)
			{
				talkPlan.Lines.Add(Pick("You did good, kid.", "Not bad. Not bad at all.", "Knew I could count on ya."));
				Trinket val = PickTrinket();
				if ((Object)(object)val != (Object)null)
				{
					talkPlan.RewardLine = talkPlan.Lines.Count;
					talkPlan.Reward = val;
					talkPlan.Lines.Add("Here. Take this. <b>" + val.title + "</b>.");
				}
				Clear();
			}
			else if (Failed)
			{
				talkPlan.Lines.Add((FailReason == "lost") ? "You lost it... didn't you." : ((FailReason == "barnacles") ? $"Only {Progress} barnacles? You let me down." : "You let me down, kid."));
				Clear();
			}
			else
			{
				Meetings++;
				if (Meetings >= Plugin.GiveUpAfter.Value)
				{
					talkPlan.Lines.Add("Forget it. I'll find someone else.");
					Clear();
				}
				else
				{
					flag = false;
					talkPlan.Lines.Add((Current == Q.Grubs) ? $"The mother's still waitin' on those grubs. {Progress}/{Target}." : ((Current == Q.Fetch) ? ("Still waitin' on that " + FetchName + ".") : ((Current == Q.Buddy) ? "Keep that little one safe. Till the next region." : $"Barnacles. {Progress} of {Target}. Keep at it.")));
				}
			}
		}
		if (flag)
		{
			GiveNewQuest(talkPlan);
		}
		if (talkPlan.Lines.Count == 0)
		{
			talkPlan.Lines.Add("...");
		}
		return talkPlan;
	}

	private static void Clear()
	{
		lastType = Current;
		Current = Q.None;
		Progress = (Target = (Meetings = 0));
		Completed = (Failed = false);
		FetchPrefab = null;
		BuddyItem = null;
	}

	private static void GiveNewQuest(TalkPlan p)
	{
		List<Q> list = new List<Q>();
		if (GrubsDue)
		{
			list.Add(Q.Grubs);
		}
		if (Plugin.QuestBarnacles.Value)
		{
			list.Add(Q.Barnacles);
		}
		if (Plugin.QuestFetch.Value && Gifts.FetchCandidates().Count > 0)
		{
			list.Add(Q.Fetch);
		}
		if (Plugin.QuestBuddy.Value && (Object)(object)Gifts.Buddy() != (Object)null)
		{
			list.Add(Q.Buddy);
		}
		if (list.Count > 1)
		{
			list.Remove(lastType);
		}
		if (GrubsDue)
		{
			list.Clear();
			list.Add(Q.Grubs);
		}
		if (list.Count == 0)
		{
			return;
		}
		Current = list[Random.Range(0, list.Count)];
		Progress = (Meetings = 0);
		Completed = (Failed = false);
		switch (Current)
		{
		case Q.Grubs:
		{
			grubsGivenThisRun = true;
			Target = Mathf.Clamp(Plugin.GrubCount.Value, 1, 3);
			p.GiftLine = p.Lines.Count;
			p.Lines.Add(Plugin.Line.Value);
			for (int i = 0; i < Target; i++)
			{
				p.Gifts.Add(Gifts.Grub());
			}
			break;
		}
		case Q.Barnacles:
			Target = Mathf.Max(1, Plugin.BarnacleTarget.Value);
			p.Lines.Add("Kill " + Words(Target) + " of them barnacles before we meet again.");
			break;
		case Q.Fetch:
		{
			List<Item_Object> list2 = Gifts.FetchCandidates();
			FetchPrefab = list2[Random.Range(0, list2.Count)];
			FetchName = FetchPrefab.itemData.itemName;
			Target = 1;
			p.Lines.Add("Bring me a " + FetchName + ". Buy it, find it, I don't care. I'll be waitin'.");
			break;
		}
		case Q.Buddy:
			Target = 1;
			buddyRegion = lastRegion;
			p.GiftLine = p.Lines.Count;
			p.GiftIsBuddy = true;
			p.Lines.Add("Keep this little one safe till you reach the next region, will ya?");
			p.Gifts.Add(Gifts.Buddy());
			break;
		}
		Plugin.Log.LogInfo((object)string.Format("The Father gave a quest: {0} (target {1}{2})", Current, Target, (Current == Q.Fetch) ? (", item " + FetchName) : ""));
	}

	public static void OnGiftsLeft(bool buddyLeft)
	{
		if (Current == Q.Buddy && buddyLeft)
		{
			Fail("lost");
		}
	}

	private static bool TakeFetchItem()
	{
		try
		{
			if ((Object)(object)FetchPrefab == (Object)null || (Object)(object)Inventory.instance == (Object)null)
			{
				return false;
			}
			string pn = FetchPrefab.itemData.prefabName;
			string nm = FetchName.ToLowerInvariant();
			Item val = ((IEnumerable<Item>)Inventory.instance.GetItems(true, true, true)).FirstOrDefault((Func<Item, bool>)((Item i) => i != null && (i.prefabName == pn || (i.itemName ?? "").ToLowerInvariant() == nm)));
			if (val == null)
			{
				return false;
			}
			clearItem?.Invoke(Inventory.instance, new object[1] { val });
			return true;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Taking fetch item failed: " + ex.Message));
			return false;
		}
	}

	public static bool HasFetchItem()
	{
		try
		{
			if ((Object)(object)FetchPrefab == (Object)null || (Object)(object)Inventory.instance == (Object)null)
			{
				return false;
			}
			string pn = FetchPrefab.itemData.prefabName;
			string nm = FetchName.ToLowerInvariant();
			return Inventory.instance.GetItems(true, true, true).Any((Item i) => i != null && (i.prefabName == pn || (i.itemName ?? "").ToLowerInvariant() == nm));
		}
		catch
		{
			return false;
		}
	}

	private static bool BuddyWithPlayer()
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Expected O, but got Unknown
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		//IL_0090: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		if (BuddyItem == null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)Inventory.instance != (Object)null && Inventory.instance.GetItems(true, true, true).Contains(BuddyItem))
			{
				return true;
			}
			Item_Object dropObject = BuddyItem.GetDropObject(false);
			ENT_Player player = ENT_Player.GetPlayer();
			if ((Object)dropObject == (Object)null || (Object)player == (Object)null)
			{
				return false;
			}
			GameEntity component = ((Component)dropObject).GetComponent<GameEntity>();
			if ((Object)component != (Object)null && component.dead)
			{
				return false;
			}
			return ((Component)dropObject).gameObject.activeInHierarchy && Vector3.Distance(((Component)dropObject).transform.position, ((Component)player).transform.position) < 20f;
		}
		catch
		{
			return false;
		}
	}

	private static bool BuddyLost()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Expected O, but got Unknown
		if (BuddyItem == null)
		{
			return false;
		}
		try
		{
			if ((Object)(object)Inventory.instance != (Object)null && Inventory.instance.GetItems(true, true, true).Contains(BuddyItem))
			{
				return false;
			}
			Item_Object dropObject = BuddyItem.GetDropObject(false);
			if ((Object)dropObject == (Object)null)
			{
				return true;
			}
			GameEntity component = ((Component)dropObject).GetComponent<GameEntity>();
			return (Object)component != (Object)null && component.dead;
		}
		catch
		{
			return false;
		}
	}

	private static Trinket PickTrinket()
	{
		try
		{
			IEnumerable<Trinket> enumerable = null;
			M_Gamemode gamemode = CL_GameManager.gamemode;
			if ((Object)(object)gamemode != (Object)null && (Object)(object)gamemode.availableTrinkets != (Object)null && gamemode.availableTrinkets.trinkets != null)
			{
				enumerable = gamemode.availableTrinkets.trinkets;
			}
			if (enumerable == null || !enumerable.Any())
			{
				enumerable = Resources.FindObjectsOfTypeAll<Trinket>();
			}
			List<Trinket> list = enumerable.Where((Trinket t) => (Object)(object)t != (Object)null && !t.isBinding && !t.comingSoon && SafeUnlocked(t) && ((t.itemsToGrant != null && t.itemsToGrant.Count > 0) || (t.perksToGrant != null && t.perksToGrant.Count > 0) || t.pouchesToGrant > 0)).ToList();
			if (list.Count == 0)
			{
				list = enumerable.Where((Trinket t) => (Object)(object)t != (Object)null && !t.isBinding && !t.comingSoon).ToList();
			}
			return (list.Count > 0) ? list[Random.Range(0, list.Count)] : null;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Trinket pick failed: " + ex.Message));
			return null;
		}
	}

	private static bool SafeUnlocked(Trinket t)
	{
		try
		{
			return t.IsUnlocked();
		}
		catch
		{
			return true;
		}
	}

	public static void GrantReward(Trinket t)
	{
		if ((Object)(object)t == (Object)null)
		{
			return;
		}
		try
		{
			t.Activate(1f);
			Plugin.Log.LogInfo((object)("The Father gave trinket: " + t.title));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Trinket activate failed: " + ex.Message));
		}
	}

	private static string Pick(params string[] s)
	{
		return s[Random.Range(0, s.Length)];
	}

	private static string Words(int n)
	{
		string[] array = new string[13]
		{
			"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
			"ten", "eleven", "twelve"
		};
		if (n >= array.Length)
		{
			return n.ToString();
		}
		return array[n];
	}

	public static string HudText()
	{
		if (Current == Q.None)
		{
			return "";
		}
		string text = ((Current == Q.Grubs) ? $"Give the Mother {Target} grubs ({Progress}/{Target})" : ((Current == Q.Barnacles) ? $"Kill barnacles before the next breakroom ({Progress}/{Target})" : ((Current == Q.Fetch) ? ("Bring him a " + FetchName + (HasFetchItem() ? " (you have it)" : "")) : "Keep the Calming Buddy safe until the next region")));
		if (Completed)
		{
			text += " - done! Find him in a breakroom";
		}
		else if (Failed)
		{
			text += " - failed";
		}
		return "THE FATHER: " + text;
	}
}
internal static class Gifts
{
	private static Item_Object grub;

	private static Item_Object buddy;

	private static List<Item_Object> fetch;

	private static bool buddySearched;

	private static bool logged;

	private static IEnumerable<GameObject> AllItems()
	{
		WKAssetDatabase fullCombinedAssetDatabase = CL_AssetManager.GetFullCombinedAssetDatabase();
		if ((Object)(object)fullCombinedAssetDatabase == (Object)null)
		{
			return Enumerable.Empty<GameObject>();
		}
		return from g in fullCombinedAssetDatabase.itemPrefabs.Concat(fullCombinedAssetDatabase.denizenPrefabs).Concat(fullCombinedAssetDatabase.entityPrefabs)
			where (Object)(object)g != (Object)null
			select g;
	}

	private static Item_Object IO(GameObject g)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		Item_Object component = g.GetComponent<Item_Object>();
		if (!((Object)component != (Object)null) || component.itemData == null)
		{
			return null;
		}
		return component;
	}

	public static Item_Object Grub()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		if ((Object)grub != (Object)null)
		{
			return grub;
		}
		try
		{
			foreach (GameObject item in AllItems())
			{
				if ((Object)(object)item.GetComponent<DEN_SlugGrub>() != (Object)null && (Object)(object)IO(item) != (Object)null)
				{
					grub = IO(item);
					break;
				}
			}
		}
		catch
		{
		}
		return grub;
	}

	public static Item_Object Buddy()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Expected O, but got Unknown
		if ((Object)buddy != (Object)null || buddySearched)
		{
			return buddy;
		}
		buddySearched = true;
		try
		{
			List<Item_Object> source = (from i in AllItems().Select(IO)
				where (Object)(object)i != (Object)null
				select i).ToList();
			buddy = ((IEnumerable<Item_Object>)source).FirstOrDefault((Func<Item_Object, bool>)((Item_Object i) => (i.itemData.itemName ?? "").ToLowerInvariant().Contains(Plugin.BuddyName.Value.ToLowerInvariant()))) ?? ((IEnumerable<Item_Object>)source).FirstOrDefault((Func<Item_Object, bool>)((Item_Object i) => (i.itemData.itemName + " " + i.itemData.prefabName + " " + ((Object)((Component)i).gameObject).name).ToLowerInvariant().Contains("calm"))) ?? ((IEnumerable<Item_Object>)source).FirstOrDefault((Func<Item_Object, bool>)((Item_Object i) => (i.itemData.itemName ?? "").ToLowerInvariant().Contains("buddy")));
		}
		catch
		{
		}
		Plugin.Log.LogInfo((object)(((Object)buddy != (Object)null) ? ("Calming Buddy item: " + buddy.itemData.itemName) : "Couldn't find a Calming Buddy item — that quest is disabled."));
		return buddy;
	}

	public static List<Item_Object> FetchCandidates()
	{
		if (fetch != null)
		{
			return fetch;
		}
		fetch = new List<Item_Object>();
		try
		{
			string[] bad = new string[12]
			{
				"grub", "hammer", "key", "floppy", "disk", "buddy", "calm", "artifact", "note", "debug",
				"test", "dev"
			};
			List<Item_Object> source = (from i in AllItems().Select(IO)
				where (Object)(object)i != (Object)null && !string.IsNullOrEmpty(i.itemData.itemName) && !string.IsNullOrEmpty(i.itemData.prefabName)
				group i by i.itemData.prefabName into g
				select g.First()).ToList();
			if (!logged)
			{
				logged = true;
				Plugin.Log.LogInfo((object)("Items the game knows: " + string.Join(", ", source.Select((Item_Object i) => i.itemData.itemName + " [" + i.itemData.prefabName + "]").ToArray())));
			}
			List<Item_Object> source2 = source.Where((Item_Object i) => !bad.Any((string b) => (i.itemData.itemName + " " + i.itemData.prefabName).ToLowerInvariant().Contains(b))).ToList();
			List<string> wish = (from k in Plugin.FetchKeywords.Value.Split(',')
				select k.Trim().ToLowerInvariant() into k
				where k.Length > 0
				select k).ToList();
			fetch = source2.Where((Item_Object i) => wish.Any((string w) => (i.itemData.itemName + " " + i.itemData.prefabName).ToLowerInvariant().Contains(w))).ToList();
			if (fetch.Count == 0)
			{
				fetch = source2;
			}
			Plugin.Log.LogInfo((object)("Fetch-quest items: " + string.Join(", ", fetch.Select((Item_Object i) => i.itemData.itemName).ToArray())));
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Fetch item scan failed: " + ex.Message));
		}
		return fetch;
	}
}
internal static class HUD
{
	private class GUIHost : MonoBehaviour
	{
		public string text = "";

		private GUIStyle st;

		private void OnGUI()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			if (!string.IsNullOrEmpty(text))
			{
				if (st == null)
				{
					st = new GUIStyle(GUI.skin.label)
					{
						fontSize = Mathf.Max(14, Screen.height / 45),
						fontStyle = (FontStyle)1
					};
				}
				Color red = default(Color);
				if (!ColorUtility.TryParseHtmlString(Plugin.TextColor.Value, ref red))
				{
					red = Color.red;
				}
				st.normal.textColor = red;
				GUI.Label(new Rect(24f, 18f, (float)Screen.width * 0.6f, 60f), text, st);
			}
		}
	}

	private static TextMeshProUGUI tmp;

	private static bool tried;

	private static GUIHost host;

	private static float next;

	private static string text = "";

	public static void Update()
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Expected O, but got Unknown
		//IL_009a: 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_0094: Unknown result type (might be due to invalid IL or missing references)
		if (Time.unscaledTime < next)
		{
			return;
		}
		next = Time.unscaledTime + 0.25f;
		text = Quests.HudText();
		if (!Plugin.ShowTracker.Value)
		{
			text = "";
		}
		if ((Object)(object)tmp == (Object)null && (!tried || Time.frameCount % 120 == 0))
		{
			Create();
		}
		if ((Object)(object)tmp != (Object)null)
		{
			((TMP_Text)tmp).text = text;
			Color red = default(Color);
			if (!ColorUtility.TryParseHtmlString(Plugin.TextColor.Value, ref red))
			{
				red = Color.red;
			}
			((Graphic)tmp).color = red;
			return;
		}
		if ((Object)(object)host == (Object)null)
		{
			GameObject val = new GameObject("TheFather_QuestHUD");
			Object.DontDestroyOnLoad((Object)val);
			host = val.AddComponent<GUIHost>();
		}
		host.text = text;
	}

	private static void Create()
	{
		//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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: 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_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		tried = true;
		try
		{
			CL_UIManager instance = CL_UIManager.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.customElementLayoutGroup == (Object)null)
			{
				return;
			}
			Canvas componentInParent = ((Component)instance.customElementLayoutGroup).GetComponentInParent<Canvas>();
			if (!((Object)(object)componentInParent == (Object)null))
			{
				componentInParent = componentInParent.rootCanvas;
				TMP_FontAsset val = FatherVoice.Font();
				GameObject val2 = new GameObject("TheFather_QuestTracker", new Type[1] { typeof(RectTransform) });
				val2.transform.SetParent(((Component)componentInParent).transform, false);
				RectTransform val3 = (RectTransform)val2.transform;
				Vector2 val4 = (val3.pivot = new Vector2(0f, 1f));
				Vector2 anchorMin = (val3.anchorMax = val4);
				val3.anchorMin = anchorMin;
				val3.anchoredPosition = new Vector2(28f, -24f);
				val3.sizeDelta = new Vector2(900f, 90f);
				tmp = val2.AddComponent<TextMeshProUGUI>();
				if ((Object)(object)val != (Object)null)
				{
					((TMP_Text)tmp).font = val;
				}
				((TMP_Text)tmp).fontSize = 26f;
				((TMP_Text)tmp).textWrappingMode = (TextWrappingModes)1;
				((Graphic)tmp).raycastTarget = false;
				((TMP_Text)tmp).richText = true;
				((TMP_Text)tmp).alignment = (TextAlignmentOptions)257;
				if ((Object)(object)host != (Object)null)
				{
					host.text = "";
				}
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Quest tracker HUD failed, using fallback: " + ex.Message));
			tmp = null;
		}
	}
}