Decompiled source of BabyDino v0.16.0

plugins/DinoValheim/DinoValheim.dll

Decompiled 11 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("DinoValheim")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.16.0.0")]
[assembly: AssemblyInformationalVersion("0.16.0")]
[assembly: AssemblyProduct("DinoValheim")]
[assembly: AssemblyTitle("DinoValheim")]
[assembly: AssemblyVersion("0.16.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DinoValheim
{
	public class DinoAI : BaseAI
	{
		protected override void Awake()
		{
			((BaseAI)this).Awake();
			base.m_avoidFire = false;
			base.m_afraidOfFire = false;
			base.m_aggravatable = false;
		}

		public override bool UpdateAI(float dt)
		{
			return false;
		}

		public override bool IsSleeping()
		{
			return false;
		}

		public bool StepTo(Vector3 point, float arrive, bool run, bool mayWade)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Pathfinding.instance == (Object)null)
			{
				return true;
			}
			base.m_pathAgentType = (AgentType)(mayWade ? 1 : 6);
			return ((BaseAI)this).MoveTo(Time.deltaTime, point, arrive, run);
		}
	}
	public class DinoAnimator : MonoBehaviour
	{
		public const float DefaultFade = 0.15f;

		private const string ClipKey = "dv_clip";

		private const string LoopKey = "dv_loop";

		private const string SeqKey = "dv_seq";

		public Transform[] Bones;

		private static AssetDef _sharedAsset;

		private ClipDef _clip;

		private float _time;

		private float _fps = 30f;

		private bool _loop;

		private bool _playing;

		private Vector3[] _fromPos;

		private Quaternion[] _fromRot;

		private float _fadeLeft;

		private float _fadeTotal;

		private ZNetView _nview;

		private int _lastSeq = -1;

		private float _nextPoll;

		private bool _loggedBones;

		public string Current
		{
			get
			{
				if (_clip != null)
				{
					return _clip.name;
				}
				return "";
			}
		}

		public bool HasAsset
		{
			get
			{
				if (_sharedAsset != null)
				{
					return Bones != null;
				}
				return false;
			}
		}

		public float LoopPhase
		{
			get
			{
				if (!_playing || _clip == null || _clip.frames.Length < 2)
				{
					return -1f;
				}
				float num = (float)(_clip.frames.Length - 1) / _fps;
				if (num <= 0f || _fps <= 0f)
				{
					return -1f;
				}
				return Mathf.Repeat(_time / num, 1f);
			}
		}

		private ZNetView NView
		{
			get
			{
				if ((Object)(object)_nview == (Object)null)
				{
					_nview = ((Component)this).GetComponent<ZNetView>();
				}
				return _nview;
			}
		}

		private bool IsOwner
		{
			get
			{
				ZNetView nView = NView;
				if ((Object)(object)nView == (Object)null || !nView.IsValid())
				{
					return true;
				}
				return nView.IsOwner();
			}
		}

		public void Initialise(AssetDef asset, Transform[] bones)
		{
			_sharedAsset = asset;
			Bones = bones;
		}

		private void EnsureBones()
		{
			AssetDef sharedAsset = _sharedAsset;
			if (sharedAsset == null || (Bones != null && Bones.Length == sharedAsset.bones.Length && (Object)(object)Bones[0] != (Object)null))
			{
				return;
			}
			Transform val = ((Component)this).transform.Find("Visual/DinoArmature");
			if ((Object)(object)val == (Object)null)
			{
				if (!_loggedBones)
				{
					_loggedBones = true;
					DinoPlugin.Log.LogError((object)"[anim] armature not found");
				}
				return;
			}
			Dictionary<string, Transform> dictionary = new Dictionary<string, Transform>();
			Transform[] componentsInChildren = ((Component)val).GetComponentsInChildren<Transform>(true);
			foreach (Transform val2 in componentsInChildren)
			{
				dictionary[((Object)val2).name] = val2;
			}
			Transform[] array = (Transform[])(object)new Transform[sharedAsset.bones.Length];
			int num = 0;
			for (int j = 0; j < array.Length; j++)
			{
				if (dictionary.TryGetValue(sharedAsset.bones[j].name, out var value))
				{
					array[j] = value;
					num++;
				}
			}
			Bones = array;
			if (num != array.Length)
			{
				DinoPlugin.Log.LogWarning((object)("[anim] resolved " + num + "/" + array.Length + " bones on " + ((Object)this).name));
			}
		}

		private void Start()
		{
			DinoGuard.Stage("DinoAnimator.Start");
			EnsureBones();
		}

		private void LateUpdate()
		{
			if (_sharedAsset == null)
			{
				return;
			}
			if (!IsOwner)
			{
				PollRemote();
			}
			if (!_playing || _clip == null)
			{
				return;
			}
			EnsureBones();
			if (Bones == null)
			{
				return;
			}
			int num = _clip.frames.Length;
			if (num < 2)
			{
				return;
			}
			float num2 = (float)(num - 1) / _fps;
			_time += Time.deltaTime;
			if (_time >= num2)
			{
				if (_loop)
				{
					_time -= num2 * Mathf.Floor(_time / num2);
				}
				else
				{
					_time = num2;
					_playing = false;
				}
			}
			Apply(_time, advanceFade: true);
		}

		public void Play(string name, bool loop, float fade = 0.15f)
		{
			DinoLog.DebugEvery("play:" + name, 2f, "anim: " + name + " loop=" + loop + " fade=" + fade);
			if (_sharedAsset == null)
			{
				return;
			}
			EnsureBones();
			if (Bones == null)
			{
				return;
			}
			if (_clip != null && _clip.name == name)
			{
				if (_playing)
				{
					_loop = loop;
					return;
				}
				_loop = loop;
				_time = 0f;
				_playing = true;
				StartFade(fade);
				Apply(0f, advanceFade: false);
				PushState(name, loop);
				return;
			}
			ClipDef clipDef = null;
			for (int i = 0; i < _sharedAsset.clips.Length; i++)
			{
				if (_sharedAsset.clips[i].name == name)
				{
					clipDef = _sharedAsset.clips[i];
					break;
				}
			}
			if (clipDef == null)
			{
				DinoPlugin.Log.LogWarning((object)("[anim] no clip named '" + name + "'"));
				return;
			}
			StartFade(fade);
			_clip = clipDef;
			_fps = ((clipDef.fps > 0f) ? clipDef.fps : 30f);
			_time = 0f;
			_loop = loop;
			_playing = true;
			Apply(0f, advanceFade: false);
			PushState(name, loop);
		}

		public bool IsPlaying(string name)
		{
			if (_playing && _clip != null)
			{
				return _clip.name == name;
			}
			return false;
		}

		private void StartFade(float fade)
		{
			//IL_007f: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			if (Bones == null || fade <= 0f)
			{
				_fadeLeft = 0f;
				return;
			}
			if (_fromPos == null || _fromPos.Length != Bones.Length)
			{
				_fromPos = (Vector3[])(object)new Vector3[Bones.Length];
				_fromRot = (Quaternion[])(object)new Quaternion[Bones.Length];
			}
			for (int i = 0; i < Bones.Length; i++)
			{
				if (!((Object)(object)Bones[i] == (Object)null))
				{
					_fromPos[i] = Bones[i].localPosition;
					_fromRot[i] = Bones[i].localRotation;
				}
			}
			_fadeTotal = fade;
			_fadeLeft = fade;
		}

		private void Apply(float seconds, bool advanceFade)
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			int num = _clip.frames.Length;
			float num2 = seconds * _fps;
			int num3 = Mathf.Clamp(Mathf.FloorToInt(num2), 0, num - 1);
			int num4 = Mathf.Min(num3 + 1, num - 1);
			float num5 = Mathf.Clamp01(num2 - (float)num3);
			float num6 = 1f;
			if (_fadeLeft > 0f)
			{
				if (advanceFade)
				{
					_fadeLeft -= Time.deltaTime;
				}
				num6 = ((_fadeTotal > 0f) ? Mathf.Clamp01(1f - _fadeLeft / _fadeTotal) : 1f);
				num6 = num6 * num6 * (3f - 2f * num6);
			}
			float[][] array = _clip.frames[num3];
			float[][] array2 = _clip.frames[num4];
			int num7 = Mathf.Min(Bones.Length, Mathf.Min(array.Length, array2.Length));
			for (int i = 0; i < num7; i++)
			{
				Transform val = Bones[i];
				if (!((Object)(object)val == (Object)null))
				{
					float[] array3 = array[i];
					float[] array4 = array2[i];
					Vector3 val2 = Vector3.Lerp(new Vector3(array3[0], array3[1], array3[2]), new Vector3(array4[0], array4[1], array4[2]), num5);
					Quaternion val3 = Quaternion.Slerp(new Quaternion(array3[3], array3[4], array3[5], array3[6]), new Quaternion(array4[3], array4[4], array4[5], array4[6]), num5);
					if (num6 < 1f && _fromPos != null && i < _fromPos.Length)
					{
						val2 = Vector3.Lerp(_fromPos[i], val2, num6);
						val3 = Quaternion.Slerp(_fromRot[i], val3, num6);
					}
					val.localPosition = val2;
					val.localRotation = val3;
				}
			}
		}

		private void PushState(string name, bool loop)
		{
			ZNetView nView = NView;
			if (!((Object)(object)nView == (Object)null) && nView.IsValid() && nView.IsOwner())
			{
				ZDO zDO = nView.GetZDO();
				if (zDO != null)
				{
					zDO.Set("dv_clip", name);
					zDO.Set("dv_loop", loop);
					zDO.Set("dv_seq", zDO.GetInt("dv_seq", 0) + 1);
				}
			}
		}

		private void PollRemote()
		{
			ZNetView nView = NView;
			if ((Object)(object)nView == (Object)null || !nView.IsValid() || Time.time < _nextPoll)
			{
				return;
			}
			_nextPoll = Time.time + 0.2f;
			ZDO zDO = nView.GetZDO();
			if (zDO == null)
			{
				return;
			}
			int num = zDO.GetInt("dv_seq", 0);
			if (num == _lastSeq)
			{
				return;
			}
			_lastSeq = num;
			string text = zDO.GetString("dv_clip", "");
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			bool loop = zDO.GetBool("dv_loop", true);
			if (_clip != null && _clip.name == text)
			{
				_loop = loop;
				if (!_playing)
				{
					_time = 0f;
					_playing = true;
				}
				return;
			}
			for (int i = 0; i < _sharedAsset.clips.Length; i++)
			{
				if (!(_sharedAsset.clips[i].name != text))
				{
					StartFade(0.15f);
					_clip = _sharedAsset.clips[i];
					_fps = ((_clip.fps > 0f) ? _clip.fps : 30f);
					_time = 0f;
					_loop = loop;
					_playing = true;
					break;
				}
			}
		}
	}
	[Serializable]
	public class BoneDef
	{
		public string name;

		public int parent;

		public float[] pos;

		public float[] quat;
	}
	[Serializable]
	public class ClipDef
	{
		public string name;

		public int start;

		public int end;

		public float fps;

		public float[][][] frames;
	}
	[Serializable]
	public class AssetDef
	{
		public MetaDef meta;

		public BoneDef[] bones;

		public MeshDef mesh;

		public ClipDef[] clips;
	}
	[Serializable]
	public class MetaDef
	{
		public float fps;

		public int fur_from;
	}
	[Serializable]
	public class MeshDef
	{
		public float[][] verts;

		public float[][] normals;

		public float[][] uvs;

		public float[][] weights;

		public int[] tris;
	}
	public static class DinoAssets
	{
		public static AssetDef Load()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			DinoGuard.Stage("asset: load");
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DinoValheim.assets.dino_asset.json");
			using StreamReader streamReader = new StreamReader(stream);
			return (AssetDef)new JsonSerializer().Deserialize((TextReader)streamReader, typeof(AssetDef));
		}

		public static byte[] ReadResource(string name)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}

		public static IEnumerable<string> SoundResourceNames()
		{
			return ResourceNames("DinoValheim.assets.sounds_wav.");
		}

		public static IEnumerable<string> StepResourceNames()
		{
			return ResourceNames("DinoValheim.assets.sounds_step.");
		}

		private static IEnumerable<string> ResourceNames(string prefix)
		{
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
			foreach (string text in manifestResourceNames)
			{
				if (text.StartsWith(prefix) && text.EndsWith(".wav"))
				{
					yield return text;
				}
			}
		}
	}
	public class DinoBrain : MonoBehaviour
	{
		private enum Curious
		{
			Player,
			Creature,
			Pickable,
			Object,
			Fire,
			Puddle,
			RandomPlace
		}

		private const float GreetStopDistance = 2.2f;

		private const float ArriveDistance = 0.8f;

		private const float ShortLeg = 2.5f;

		private const float GreetCooldown = 25f;

		private const float DinoHelloCooldown = 90f;

		private const float HelloRange = 8f;

		private const float HelloAnswerCooldown = 25f;

		private const float HelloPollInterval = 0.1f;

		private const float GiftCooldown = 60f;

		private const float ForageReach = 1.6f;

		private const float InspectStopDistance = 1.8f;

		private const float FireSitDistance = 1.7f;

		private const float MaxWadeDepth = 0.15f;

		private static readonly float[] PuddleSlapPhases = new float[2] { 0.35f, 0.85f };

		private const float SplashScaleEnter = 0.35f;

		private const float SplashScaleHop = 0.2f;

		private const float ForgetObjectSeconds = 60f;

		private const float WakeDistance = 1.6f;

		private const float SleepDownFade = 0.3f;

		private const float FollowStop = 2f;

		private const float FollowWalkToRun = 8f;

		private const float FollowRunToWalk = 5f;

		private const float PetLeash = 40f;

		private static readonly Collider[] PickBuffer = (Collider[])(object)new Collider[512];

		private static readonly List<Pickable> PickCandidates = new List<Pickable>();

		private static readonly List<Transform> ObjectCandidates = new List<Transform>();

		private DinoRig rig;

		private Character character;

		private DinoAI ai;

		private Humanoid humanoid;

		private ZNetView nview;

		private Rigidbody body;

		private float nextGreetTime;

		private float nextDinoHelloTime;

		private float nextHelloAnswerTime;

		private float nextHelloPoll;

		private bool helloPending;

		private bool napping;

		private Character helloFrom;

		private int helloSeen;

		private float nextGiftTime;

		private float nextFireTime;

		private float nextSleepTime;

		private float nextWaterCheck;

		private bool moveRun;

		private bool loggedMissingBerry;

		private EffectList splash;

		private EffectList plume;

		private GameObject splashSound;

		private GameObject splashSoundBig;

		private bool splashChecked;

		private bool soundChecked;

		private bool navLogged;

		private float petUntil;

		private long petPlayerID;

		private bool approachArrived;

		private Transform lastObject;

		private float forgetObjectUntil;

		private static readonly string[] IdleClips = new string[7] { "idle", "idle", "idle2", "idle2", "idle look", "idle stretch", "idle hop" };

		public const string HelloKey = "dv_hello";

		private bool Owns
		{
			get
			{
				if ((Object)(object)nview == (Object)null)
				{
					return true;
				}
				if (!nview.IsValid())
				{
					return false;
				}
				return nview.IsOwner();
			}
		}

		private bool PetActive => Time.time < petUntil;

		private bool HelloPending
		{
			get
			{
				if (napping)
				{
					return false;
				}
				if (Time.time < nextHelloPoll)
				{
					return helloPending;
				}
				nextHelloPoll = Time.time + 0.1f;
				helloPending = Time.time >= nextHelloAnswerTime && (Object)(object)FindHello(out var _) != (Object)null;
				return helloPending;
			}
		}

		private static bool IsNight => EnvMan.IsNight();

		private float LiquidDepth => Mathf.Max(0f, character.GetLiquidLevel() - ((Component)this).transform.position.y);

		private static float NoticeRange => Mathf.Max(5f, DinoPlugin.CuriosityRange.Value);

		private static float PuddleDepth => Mathf.Clamp(DinoPlugin.PuddlePlayMaxDepth.Value, 0.05f, 0.6f);

		private void Awake()
		{
			DinoGuard.Stage("DinoBrain.Awake");
			DinoGuard.Beat("brain awake");
			rig = ((Component)this).GetComponent<DinoRig>();
			character = ((Component)this).GetComponent<Character>();
			ai = ((Component)this).GetComponent<DinoAI>();
			humanoid = ((Component)this).GetComponent<Humanoid>();
			nview = ((Component)this).GetComponent<ZNetView>();
			body = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)nview != (Object)null)
			{
				nview.Register<long>("DinoPet", (Action<long, long>)RPC_Pet);
			}
		}

		private void OnEnable()
		{
			DinoRegistry.Register(character);
		}

		private void OnDisable()
		{
			DinoRegistry.Unregister(character);
		}

		private void Start()
		{
			DinoGuard.Stage("DinoBrain.Start");
			if ((Object)(object)character == (Object)null || (Object)(object)rig == (Object)null || (Object)(object)rig.Driver == (Object)null)
			{
				if (DinoPlugin.Log != null)
				{
					DinoPlugin.Log.LogError((object)"[dino] missing Character/DinoRig on this prefab");
				}
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(Life());
			}
		}

		private void LateUpdate()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)body != (Object)null)
			{
				Vector3 angularVelocity = body.angularVelocity;
				if (((Vector3)(ref angularVelocity)).sqrMagnitude > 0.0001f)
				{
					body.angularVelocity = Vector3.zero;
				}
			}
		}

		private IEnumerator Wait(float seconds)
		{
			float end = Time.time + seconds;
			while (Time.time < end && !PetActive && !HelloPending)
			{
				yield return null;
			}
		}

		private void MaybeSound(float chance)
		{
			if (Random.value < chance)
			{
				rig.PlayRandomSound();
			}
		}

		private IEnumerator Life()
		{
			DinoGuard.Stage("brain: life");
			yield return Wait(Random.Range(0.5f, 1.5f));
			Vector3 position;
			if (DinoPlugin.Log != null)
			{
				ManualLogSource log = DinoPlugin.Log;
				position = ((Component)this).transform.position;
				log.LogInfo((object)("[dino] spawned at " + ((Vector3)(ref position)).ToString("F1") + (Owns ? "" : " (remote)")));
			}
			string[] obj = new string[8]
			{
				"brain: ",
				((Object)((Component)this).gameObject).name,
				" life started, owns=",
				Owns.ToString(),
				" zdo=",
				((Object)(object)nview != (Object)null && nview.GetZDO() != null) ? ((object)Unsafe.As<ZDOID, ZDOID>(ref nview.GetZDO().m_uid)/*cast due to .constrained prefix*/).ToString() : "none",
				" pos=",
				null
			};
			position = ((Component)this).transform.position;
			obj[7] = ((Vector3)(ref position)).ToString("F1");
			DinoLog.Debug(string.Concat(obj));
			while (true)
			{
				if (!Owns)
				{
					yield return null;
					continue;
				}
				if (PetActive)
				{
					yield return PetFollow();
					continue;
				}
				if (Time.time >= nextHelloAnswerTime && TryTakeHello(out var greeter))
				{
					yield return AnswerHello(greeter);
					continue;
				}
				if (Time.time >= nextSleepTime && SleepRoll())
				{
					yield return Sleep();
					nextSleepTime = Time.time + Mathf.Max(5f, DinoPlugin.SleepCooldown.Value);
					continue;
				}
				yield return FollowCuriosity();
				if (!PetActive)
				{
					float value = Random.value;
					if (value < 0.15f)
					{
						yield return Sit();
					}
					else if (value < 0.55f)
					{
						yield return Idle();
					}
					else
					{
						yield return Wait(Random.Range(1f, 2.5f));
					}
				}
			}
		}

		private static bool SleepRoll()
		{
			float num = (IsNight ? DinoPlugin.SleepNightChance.Value : DinoPlugin.SleepDayChance.Value);
			return Random.value < num / 100f;
		}

		private IEnumerator Sleep()
		{
			DinoGuard.Stage("brain: sleep");
			napping = true;
			bool isNight = IsNight;
			string[] obj = new string[7]
			{
				"brain: ",
				((Object)((Component)this).gameObject).name,
				" sleeping (night=",
				isNight.ToString(),
				", at ",
				null,
				null
			};
			Vector3 position = ((Component)this).transform.position;
			obj[5] = ((Vector3)(ref position)).ToString("F1");
			obj[6] = ")";
			DinoLog.Debug(string.Concat(obj));
			float num = (isNight ? DinoPlugin.SleepNightSecondsMin.Value : DinoPlugin.SleepNapSecondsMin.Value);
			float num2 = (isNight ? DinoPlugin.SleepNightSecondsMax.Value : DinoPlugin.SleepNapSecondsMax.Value);
			num = Mathf.Max(3f, num);
			float end = Time.time + Random.Range(num, Mathf.Max(num, num2));
			StopMoving();
			rig.PlayOnce("sleep down", 0.3f);
			yield return Wait(0.78f);
			if (WakeCondition())
			{
				yield return Wake();
				yield break;
			}
			rig.PlayLoop("sleep", 0.12f);
			while (Time.time < end && Owns && !WakeCondition())
			{
				yield return null;
			}
			yield return Wake();
		}

		private bool WakeCondition()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (PetActive)
			{
				return true;
			}
			List<Player> allPlayers = Player.GetAllPlayers();
			for (int i = 0; i < allPlayers.Count; i++)
			{
				Player val = allPlayers[i];
				if (!((Object)(object)val == (Object)null) && !((Character)val).IsDead() && TryGetLivePosition(((Component)val).transform, out var pos))
				{
					Vector3 val2 = pos - ((Component)this).transform.position;
					val2.y = 0f;
					if (((Vector3)(ref val2)).sqrMagnitude <= 2.5600002f)
					{
						return true;
					}
				}
			}
			return false;
		}

		private IEnumerator Wake()
		{
			DinoGuard.Stage("brain: wake");
			napping = false;
			if (PetActive)
			{
				yield return Wait(1.3f);
				yield break;
			}
			rig.PlayOnce("wake up", 0.12f);
			yield return Wait(0.95f);
			rig.PlayOnce("idle stretch", 0.35f);
			MaybeSound(0.5f);
			yield return Wait(1.2f);
		}

		private IEnumerator FollowCuriosity()
		{
			DinoGuard.Stage("brain: curiosity");
			string key = "curiosity:" + ((Object)this).GetInstanceID();
			string name = ((Object)((Component)this).gameObject).name;
			Vector3 position = ((Component)this).transform.position;
			DinoLog.DebugEvery(key, 4f, "brain: " + name + " looking around at " + ((Vector3)(ref position)).ToString("F1"));
			FindCuriosityCharacters(out var player, out var creature);
			TryFindPickable(out var best);
			Transform val = FindObjectTarget();
			Vector3 result;
			bool puddle = TryFindPuddle(out result);
			Fireplace result2;
			float fireWeight = (TryFindFire(out result2) ? FireWeight() : 0f);
			switch (ChooseCuriosity(player, creature, best, val, puddle, fireWeight))
			{
			case Curious.Player:
			{
				if (Time.time >= nextGiftTime && TryGetLivePosition(((Component)player).transform, out var pos) && BerryForBiome((Biome)((WorldGenerator.instance != null) ? ((int)WorldGenerator.instance.GetBiome(pos)) : 0)) != null && Random.value < DinoPlugin.GiftChance.Value / 100f)
				{
					yield return Gift(player);
				}
				else
				{
					yield return Greet(player, isPlayer: true);
				}
				break;
			}
			case Curious.Creature:
				if (DinoRegistry.IsDino(creature))
				{
					yield return HelloDino(creature);
				}
				else
				{
					yield return Greet(creature, isPlayer: false);
				}
				break;
			case Curious.Pickable:
				yield return Forage(best);
				break;
			case Curious.Object:
				lastObject = val;
				forgetObjectUntil = Time.time + 60f;
				yield return InspectObject(val);
				break;
			case Curious.Fire:
				yield return WarmUpAtFire(result2);
				break;
			case Curious.Puddle:
				yield return PlayInPuddle(result);
				break;
			default:
				yield return Wander();
				break;
			}
		}

		private static Curious ChooseCuriosity(Character player, Character creature, Pickable pickable, Transform obj, bool puddle, float fireWeight)
		{
			float num = (((Object)(object)player != (Object)null) ? Mathf.Max(0f, DinoPlugin.CuriosityPlayerChance.Value) : 0f);
			float num2 = (((Object)(object)creature != (Object)null) ? Mathf.Max(0f, DinoPlugin.CuriosityCreatureChance.Value) : 0f);
			float num3 = (((Object)(object)pickable != (Object)null) ? Mathf.Max(0f, DinoPlugin.CuriosityPickableChance.Value) : 0f);
			float num4 = (((Object)(object)obj != (Object)null) ? Mathf.Max(0f, DinoPlugin.CuriosityObjectChance.Value) : 0f);
			float num5 = (puddle ? Mathf.Max(0f, DinoPlugin.CuriosityPuddleChance.Value) : 0f);
			float num6 = Mathf.Max(0f, fireWeight);
			float num7 = Mathf.Max(0f, DinoPlugin.CuriosityRandomChance.Value);
			float num8 = num + num2 + num3 + num4 + num6 + num5 + num7;
			if (num8 <= 0f)
			{
				return Curious.RandomPlace;
			}
			float num9 = Random.value * num8;
			if ((num9 -= num) < 0f)
			{
				return Curious.Player;
			}
			if ((num9 -= num2) < 0f)
			{
				return Curious.Creature;
			}
			if ((num9 -= num3) < 0f)
			{
				return Curious.Pickable;
			}
			if ((num9 -= num4) < 0f)
			{
				return Curious.Object;
			}
			if ((num9 -= num6) < 0f)
			{
				return Curious.Fire;
			}
			if ((num9 -= num5) < 0f)
			{
				return Curious.Puddle;
			}
			return Curious.RandomPlace;
		}

		private IEnumerator InspectObject(Transform target)
		{
			if (!TryGetLivePosition(target, out var pos))
			{
				yield break;
			}
			yield return GoTo(pos, 20f, 1.8f);
			if (!HelloPending && TryGetLivePosition(target, out pos) && !(HorizontalDistance(pos) > 3.3f))
			{
				FaceToward(pos);
				rig.PlayLoop("idle2");
				MaybeSound(0.35f);
				yield return Wait(Random.Range(1.6f, 3f));
				if (!HelloPending && Random.value < 0.35f)
				{
					rig.PlayLoop("idle hop");
					rig.PlayRandomSound();
					yield return Wait(1.4f);
				}
			}
		}

		private IEnumerator PlayInPuddle(Vector3 spot)
		{
			//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 depth = PuddleDepth;
			yield return GoTo(spot, 25f, 0.3f, 0f - depth, pathThroughWater: true);
			if (HelloPending || HorizontalDistance(spot) > 2.5f)
			{
				yield break;
			}
			if (character.InWater() && !character.IsSwimming())
			{
				rig.PlayLoop("puddle play");
				Splash(big: true);
				float num = Mathf.Max(0f, DinoPlugin.PuddlePlaySecondsMin.Value);
				float num2 = Mathf.Max(num, DinoPlugin.PuddlePlaySecondsMax.Value);
				float until = Time.time + Random.Range(num, num2);
				float prevPhase = -1f;
				while (Time.time < until && !PetActive && !HelloPending)
				{
					float num3 = (((Object)(object)rig.Driver != (Object)null) ? rig.Driver.LoopPhase : (-1f));
					if (num3 >= 0f && prevPhase >= 0f)
					{
						bool flag = num3 < prevPhase;
						for (int i = 0; i < PuddleSlapPhases.Length; i++)
						{
							float num4 = PuddleSlapPhases[i];
							if ((prevPhase < num4 && (num3 >= num4 || flag)) || (flag && num3 >= num4))
							{
								Splash(big: false);
							}
						}
					}
					prevPhase = num3;
					yield return null;
				}
				MaybeSound(0.25f);
			}
			if (!TryFindDrySpot(spot, out var result))
			{
				Vector3 val = ((Component)this).transform.position - spot;
				val.y = 0f;
				result = ((Component)this).transform.position + ((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? (((Vector3)(ref val)).normalized * 6f) : (-((Component)this).transform.forward * 6f));
			}
			yield return GoTo(result, 12f, 0.8f, 0f - depth, pathThroughWater: true);
			if (!HelloPending)
			{
				rig.PlayOnce("shake off");
				MaybeSound(0.3f);
				yield return Wait(1.3f);
			}
		}

		private IEnumerator WarmUpAtFire(Fireplace fire)
		{
			DinoGuard.Stage("brain: fire");
			if (!TryGetLivePosition(((Object)(object)fire != (Object)null) ? ((Component)fire).transform : null, out var pos))
			{
				yield break;
			}
			DinoLog.Debug("fire: " + ((Object)((Component)this).gameObject).name + " warming up at " + ((Vector3)(ref pos)).ToString("F1") + " (coldness " + Coldness().ToString("F1") + ")");
			yield return GoTo(pos, 25f, 1.7f);
			if (HelloPending || HorizontalDistance(pos) > 3.2f || !Burning(fire))
			{
				yield break;
			}
			FaceToward(pos);
			rig.PlayOnce("sit down", 0.12f);
			yield return Wait(0.4f);
			if (HelloPending)
			{
				yield break;
			}
			float num = Mathf.Max(1f, DinoPlugin.FireWarmSecondsMin.Value);
			float num2 = Mathf.Max(num, DinoPlugin.FireWarmSecondsMax.Value);
			float until = Time.time + Random.Range(num, num2);
			rig.PlayLoop((Random.value < 0.5f) ? "sit idle" : "sit idle2");
			MaybeSound(0.3f);
			bool wentOut = false;
			while (Time.time < until && Owns && !PetActive && !HelloPending)
			{
				if (!Burning(fire))
				{
					wentOut = true;
					break;
				}
				yield return null;
			}
			if (!PetActive && !HelloPending)
			{
				rig.PlayOnce("stand up", 0.1f);
				yield return Wait(0.5f);
			}
			if (wentOut && !HelloPending && TryGetLivePosition(((Object)(object)fire != (Object)null) ? ((Component)fire).transform : null, out pos))
			{
				FaceToward(pos);
				rig.PlayLoop("idle look");
				MaybeSound(0.4f);
				yield return Wait(2f);
			}
			nextFireTime = Time.time + Mathf.Max(0f, DinoPlugin.FireCooldown.Value);
		}

		private float Coldness()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			if (IsNight)
			{
				num += 1f;
			}
			if (EnvMan.IsWet())
			{
				num += 1f;
			}
			WorldGenerator instance = WorldGenerator.instance;
			if (instance != null)
			{
				Biome biome = instance.GetBiome(((Component)this).transform.position);
				if ((biome & 0x44) != 0)
				{
					num += 2f;
				}
				else if ((biome & 0x102) != 0)
				{
					num += 1f;
				}
			}
			return num;
		}

		private float FireWeight()
		{
			float num = Mathf.Max(0f, DinoPlugin.CuriosityFireChance.Value);
			if (num <= 0f)
			{
				return 0f;
			}
			float num2 = Mathf.Max(0f, DinoPlugin.FireColdBonus.Value);
			return num * (1f + num2 * Coldness());
		}

		private IEnumerator ApproachCharacter(Character target, float stopDistance, float timeout, float abandonRange)
		{
			approachArrived = false;
			float end = Time.time + timeout;
			bool gaitDecided = false;
			while (Time.time < end)
			{
				if (!Owns)
				{
					StopMoving();
					yield break;
				}
				if (PetActive)
				{
					StopMoving();
					yield break;
				}
				if (HelloPending)
				{
					StopMoving();
					yield break;
				}
				if ((Object)(object)target == (Object)null)
				{
					StopMoving();
					yield break;
				}
				if (target.IsDead())
				{
					StopMoving();
					yield break;
				}
				if (!TryGetLivePosition(((Component)target).transform, out var pos))
				{
					StopMoving();
					yield break;
				}
				Vector3 val = pos - ((Component)this).transform.position;
				val.y = 0f;
				float magnitude = ((Vector3)(ref val)).magnitude;
				if (magnitude > abandonRange)
				{
					StopMoving();
					yield break;
				}
				if (magnitude <= stopDistance)
				{
					approachArrived = true;
					break;
				}
				if (!gaitDecided)
				{
					BeginMove(magnitude);
					gaitDecided = true;
				}
				Vector3 dir = val / Mathf.Max(magnitude, 0.001f);
				if (StepToward(pos, dir, magnitude, stopDistance, mayWade: false))
				{
					MoveToward(dir);
				}
				yield return null;
			}
			StopMoving();
		}

		private IEnumerator Idle()
		{
			DinoGuard.Stage("brain: idle");
			rig.PlayLoop(IdleClips[Random.Range(0, IdleClips.Length)]);
			MaybeSound(0.25f);
			yield return Wait(Random.Range(3f, 6f));
		}

		private IEnumerator Sit()
		{
			DinoGuard.Stage("brain: sit");
			rig.PlayOnce("sit down", 0.12f);
			yield return Wait(0.4f);
			if (!HelloPending)
			{
				rig.PlayLoop((Random.value < 0.5f) ? "sit idle" : "sit idle2");
				yield return Wait(Random.Range(6f, 12f));
				if (!HelloPending && !PetActive && !HelloPending)
				{
					rig.PlayOnce("stand up", 0.1f);
					yield return Wait(0.5f);
				}
			}
		}

		private IEnumerator Wander()
		{
			if (!TryPickWaypoint(out var result))
			{
				yield return Idle();
				yield break;
			}
			yield return GoTo(result, 30f);
			if (!HelloPending)
			{
				yield return Idle();
			}
		}

		private IEnumerator Forage(Pickable pickable)
		{
			if (!((Object)(object)pickable == (Object)null))
			{
				yield return GoTo(((Component)pickable).transform.position, 25f);
				if (!HelloPending && !((Object)(object)pickable == (Object)null) && !(Vector3.Distance(((Component)this).transform.position, ((Component)pickable).transform.position) > 1.6f) && TryHarvest(pickable))
				{
					rig.PlayLoop("idle2");
					MaybeSound(0.35f);
					yield return Wait(1.2f);
				}
			}
		}

		private bool TryHarvest(Pickable pickable)
		{
			if ((Object)(object)pickable == (Object)null || (Object)(object)humanoid == (Object)null)
			{
				return false;
			}
			if (pickable.GetPicked())
			{
				return false;
			}
			ZNetView component = ((Component)pickable).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			if (!component.IsOwner())
			{
				return false;
			}
			pickable.Interact(humanoid, false, false);
			return true;
		}

		private IEnumerator Gift(Character player)
		{
			if (!TryGetLivePosition(((Object)(object)player != (Object)null) ? ((Component)player).transform : null, out var pos))
			{
				yield break;
			}
			string berry = BerryForBiome((Biome)((WorldGenerator.instance != null) ? ((int)WorldGenerator.instance.GetBiome(pos)) : 0));
			if (berry == null)
			{
				yield break;
			}
			yield return ApproachCharacter(player, 2.2f, 12f, NoticeRange * 1.7f);
			if (approachArrived && !((Object)(object)player == (Object)null) && !player.IsDead())
			{
				Vector3 val = ((Component)player).transform.position - ((Component)this).transform.position;
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
				{
					character.SetLookDir(((Vector3)(ref val)).normalized, 0f);
				}
				if (DropBerry(berry, player))
				{
					nextGiftTime = Time.time + 60f;
					rig.PlayOnce("wave", 0.15f);
					rig.PlayRandomSound();
					yield return Wait(1.6f);
				}
			}
		}

		private IEnumerator Greet(Character target, bool isPlayer)
		{
			nextGreetTime = Time.time + 25f;
			float stopDistance = (isPlayer ? 2.2f : 2.9f);
			yield return ApproachCharacter(target, stopDistance, 12f, NoticeRange * 1.7f);
			if (!approachArrived)
			{
				yield break;
			}
			if ((Object)(object)target != (Object)null && !target.IsDead())
			{
				Vector3 val = ((Component)target).transform.position - ((Component)this).transform.position;
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
				{
					character.SetLookDir(((Vector3)(ref val)).normalized, 0f);
				}
			}
			rig.PlayOnce("wave", 0.15f);
			rig.PlayRandomSound();
			yield return Wait(1.7f);
			if (Random.value < 0.5f)
			{
				yield return Sit();
			}
			else
			{
				yield return Idle();
			}
		}

		private IEnumerator HelloDino(Character other)
		{
			DinoGuard.Stage("brain: hello dino");
			nextDinoHelloTime = Time.time + 90f;
			yield return ApproachCharacter(other, 2.9f, 12f, NoticeRange * 1.7f);
			if (approachArrived && !((Object)(object)other == (Object)null) && !other.IsDead() && TryGetLivePosition(((Component)other).transform, out var pos))
			{
				FaceToward(pos);
				string[] obj = new string[6]
				{
					"hello: ",
					((Object)((Component)this).gameObject).name,
					" greets ",
					((Object)(object)other != (Object)null) ? ((Object)((Component)other).gameObject).name : "?",
					" at ",
					null
				};
				Vector3 position = ((Component)this).transform.position;
				obj[5] = ((Vector3)(ref position)).ToString("F1");
				DinoLog.Debug(string.Concat(obj));
				rig.PlayOnce("wave", 0.15f);
				rig.PlayRandomSound();
				BumpHello();
				yield return Wait(1.7f);
				if (TryGetLivePosition(((Object)(object)other != (Object)null) ? ((Component)other).transform : null, out pos) && HorizontalDistance(pos) <= 5.2f && Random.value < 0.6f)
				{
					FaceToward(pos);
					rig.PlayLoop("idle hop");
					MaybeSound(0.4f);
					yield return Wait(1.4f);
				}
				if (Random.value < 0.5f)
				{
					yield return Sit();
				}
				else
				{
					yield return Idle();
				}
			}
		}

		private IEnumerator AnswerHello(Character greeter)
		{
			DinoGuard.Stage("brain: answer hello");
			nextHelloAnswerTime = Time.time + 25f;
			yield return ApproachCharacter(greeter, 2.9f, 6f, 10.2f);
			if (approachArrived && !((Object)(object)greeter == (Object)null) && !greeter.IsDead() && TryGetLivePosition(((Component)greeter).transform, out var pos))
			{
				DinoLog.Debug("hello: " + ((Object)((Component)this).gameObject).name + " waves back at " + (((Object)(object)greeter != (Object)null) ? ((Object)((Component)greeter).gameObject).name : "?"));
				FaceToward(pos);
				rig.PlayOnce("wave", 0.15f);
				rig.PlayRandomSound();
				yield return Wait(1.5f);
			}
		}

		private bool TryTakeHello(out Character greeter)
		{
			greeter = FindHello(out var count);
			if ((Object)(object)greeter == (Object)null)
			{
				return false;
			}
			helloFrom = greeter;
			helloSeen = count;
			helloPending = false;
			return true;
		}

		private Character FindHello(out int count)
		{
			//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)
			count = 0;
			Character result = null;
			float num = float.MaxValue;
			List<Character> allCharacters = Character.GetAllCharacters();
			for (int i = 0; i < allCharacters.Count; i++)
			{
				Character val = allCharacters[i];
				if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)character || val.IsDead() || !DinoRegistry.IsDino(val) || !TryGetLivePosition(((Component)val).transform, out var pos))
				{
					continue;
				}
				Vector3 val2 = pos - ((Component)this).transform.position;
				val2.y = 0f;
				float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
				if (sqrMagnitude > 64f || sqrMagnitude >= num)
				{
					continue;
				}
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if ((Object)(object)component == (Object)null || !component.IsValid())
				{
					continue;
				}
				ZDO zDO = component.GetZDO();
				if (zDO != null)
				{
					int num2 = zDO.GetInt("dv_hello", 0);
					if (num2 > 0 && (!((Object)(object)helloFrom != (Object)null) || !((Object)(object)val == (Object)(object)helloFrom) || num2 != helloSeen))
					{
						num = sqrMagnitude;
						result = val;
						count = num2;
					}
				}
			}
			return result;
		}

		private void BumpHello()
		{
			if (!((Object)(object)nview == (Object)null) && nview.IsValid() && nview.IsOwner())
			{
				ZDO zDO = nview.GetZDO();
				if (zDO != null)
				{
					zDO.Set("dv_hello", zDO.GetInt("dv_hello", 0) + 1);
				}
			}
		}

		private static bool IsAsleep(Character c)
		{
			DinoAnimator dinoAnimator = (((Object)(object)c != (Object)null) ? ((Component)c).GetComponent<DinoAnimator>() : null);
			if ((Object)(object)dinoAnimator != (Object)null)
			{
				return dinoAnimator.IsPlaying("sleep");
			}
			return false;
		}

		private void RPC_Pet(long sender, long playerID)
		{
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			DinoLog.Debug("pet rpc: " + ((Object)((Component)this).gameObject).name + " sender=" + sender + " player=" + playerID + " owner=" + Owns);
			if (!((Object)(object)nview == (Object)null) && nview.IsValid() && nview.IsOwner() && !((Object)(object)character == (Object)null) && !((Object)(object)rig == (Object)null))
			{
				float num = Mathf.Max(1f, DinoPlugin.PetFollowSecondsMin.Value);
				float num2 = Mathf.Max(num, DinoPlugin.PetFollowSecondsMax.Value);
				petPlayerID = playerID;
				petUntil = Time.time + Random.Range(num, num2);
				StopMoving();
				Player val = FindPlayerByID(playerID);
				if ((Object)(object)val != (Object)null)
				{
					FaceToward(((Component)val).transform.position);
				}
				rig.PlayOnce("wave", 0.12f);
				rig.PlayRandomSound();
				ZDO zDO = nview.GetZDO();
				if (zDO != null)
				{
					zDO.Set("dv_love", zDO.GetInt("dv_love", 0) + 1);
				}
			}
		}

		private IEnumerator PetFollow()
		{
			DinoGuard.Stage("brain: pet follow");
			float wave = Time.time + 1.25f;
			while (Time.time < wave && PetActive)
			{
				yield return null;
			}
			float nextClip = 0f;
			bool followingRun = false;
			bool moving = false;
			while (PetActive)
			{
				if (!Owns)
				{
					StopMoving();
					yield break;
				}
				Player val = FindPlayerByID(petPlayerID);
				if ((Object)(object)val == (Object)null || ((Character)val).IsDead())
				{
					StopMoving();
					yield break;
				}
				if (!TryGetLivePosition(((Component)val).transform, out var pos))
				{
					StopMoving();
					yield break;
				}
				Vector3 val2 = pos - ((Component)this).transform.position;
				val2.y = 0f;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				if (magnitude > 40f)
				{
					StopMoving();
					yield break;
				}
				if (magnitude <= 2f)
				{
					if (moving)
					{
						moving = false;
						followingRun = false;
						StopMoving();
					}
					FaceToward(pos);
					if (Time.time >= nextClip)
					{
						nextClip = Time.time + Random.Range(2.5f, 4.5f);
						rig.PlayLoop((Random.value < 0.5f) ? "idle hop" : "idle");
					}
				}
				else
				{
					bool flag = (followingRun ? (magnitude > 5f) : (magnitude > 8f));
					if (!moving || flag != followingRun)
					{
						moving = true;
						followingRun = flag;
						rig.PlayLoop(flag ? "run" : "walk");
					}
					moveRun = followingRun;
					Vector3 dir = val2 / Mathf.Max(magnitude, 0.001f);
					if (StepToward(pos, dir, magnitude, 2f, mayWade: false))
					{
						MoveToward(dir);
					}
					if (character.IsSwimming() || LiquidDepth > 0.15f)
					{
						StopMoving();
						yield break;
					}
				}
				yield return null;
			}
			StopMoving();
			rig.PlayLoop("idle2");
			MaybeSound(0.35f);
			yield return Wait(1.5f);
		}

		private void FaceToward(Vector3 target)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = target - ((Component)this).transform.position;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude > 0.01f && (Object)(object)character != (Object)null)
			{
				character.SetLookDir(((Vector3)(ref val)).normalized, 0f);
			}
		}

		private static Player FindPlayerByID(long playerID)
		{
			if (playerID == 0L)
			{
				return null;
			}
			List<Player> allPlayers = Player.GetAllPlayers();
			for (int i = 0; i < allPlayers.Count; i++)
			{
				Player val = allPlayers[i];
				if (!((Object)(object)val == (Object)null) && !((Character)val).IsDead() && val.GetPlayerID() == playerID)
				{
					return val;
				}
			}
			return null;
		}

		private void BeginMove(float distance)
		{
			moveRun = distance > DinoPlugin.RunDistance.Value;
			rig.PlayLoop(moveRun ? "run" : "walk");
		}

		private void ApplySpeeds()
		{
			character.m_walkSpeed = DinoPlugin.WalkSpeed.Value;
			character.m_runSpeed = DinoPlugin.RunSpeed.Value;
			character.m_speed = DinoPlugin.RunSpeed.Value;
			character.SetWalk(!moveRun);
			character.SetRun(moveRun);
		}

		private void MoveToward(Vector3 dir)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			ApplySpeeds();
			character.SetLookDir(dir, 0f);
			character.SetMoveDir(dir);
		}

		private bool StepToward(Vector3 target, Vector3 dir, float dist, float arrive, bool mayWade)
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)character == (Object)null || (Object)(object)ai == (Object)null)
			{
				return true;
			}
			if (!DinoPlugin.UsePathfinding.Value)
			{
				return true;
			}
			if (dist <= 2.5f)
			{
				return true;
			}
			if (!navLogged)
			{
				navLogged = true;
				DinoLog.Debug("nav: pathfinding " + (((Object)(object)Pathfinding.instance != (Object)null) ? "on" : "MISSING") + ", agent " + (mayWade ? "Humanoid" : "HumanoidAvoidWater") + ", first path leg " + dist.ToString("F1") + " m");
			}
			ApplySpeeds();
			return ai.StepTo(target, arrive, moveRun, mayWade);
		}

		private IEnumerator GoTo(Vector3 target, float timeout, float arrive = 0.8f, float waterMargin = -0.15f, bool pathThroughWater = false)
		{
			//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)
			if ((Object)(object)character == (Object)null)
			{
				yield break;
			}
			float wade = Mathf.Max(0f, 0f - waterMargin);
			float end = Time.time + timeout;
			float checkAt = Time.time + 1.5f;
			Vector3 lastPos = ((Component)this).transform.position;
			nextWaterCheck = 0f;
			BeginMove(HorizontalDistance(target));
			while (Time.time < end)
			{
				if (!Owns)
				{
					StopMoving();
					yield break;
				}
				if (PetActive)
				{
					StopMoving();
					yield break;
				}
				if (HelloPending)
				{
					StopMoving();
					yield break;
				}
				float num = HorizontalDistance(target);
				if (num < arrive)
				{
					break;
				}
				Vector3 dir = target - ((Component)this).transform.position;
				dir.y = 0f;
				if (((Vector3)(ref dir)).sqrMagnitude < 0.0001f)
				{
					break;
				}
				((Vector3)(ref dir)).Normalize();
				bool flag = StepToward(target, dir, num, arrive, pathThroughWater);
				if (flag)
				{
					MoveToward(dir);
				}
				if (Time.time >= checkAt)
				{
					Vector3 val = ((Component)this).transform.position - lastPos;
					if (((Vector3)(ref val)).sqrMagnitude < 0.09f)
					{
						break;
					}
					lastPos = ((Component)this).transform.position;
					checkAt = Time.time + 1.5f;
				}
				if (character.IsSwimming() || (character.InWater() && LiquidDepth > wade))
				{
					break;
				}
				if (flag && Time.time >= nextWaterCheck)
				{
					nextWaterCheck = Time.time + 1f;
					if (TerrainBlocksAhead(dir, waterMargin))
					{
						break;
					}
				}
				yield return null;
			}
			StopMoving();
		}

		private bool TerrainBlocksAhead(Vector3 dir, float waterMargin)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			Vector3 val = ((Component)this).transform.position + dir * 1.5f;
			float num = default(float);
			if (instance.GetGroundHeight(val, ref num) && num < instance.m_waterLevel + waterMargin)
			{
				return true;
			}
			return instance.IsLava(val, false);
		}

		private void EnsureSplashEffect()
		{
			if (splashChecked)
			{
				return;
			}
			ZNetScene instance = ZNetScene.instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)character == (Object)null)
			{
				return;
			}
			splashChecked = true;
			if (character.m_waterEffects.HasEffects())
			{
				splash = character.m_waterEffects;
				DinoPlugin.Log.LogInfo((object)"[dino] water fx: his own m_waterEffects");
			}
			else
			{
				string[] array = new string[7] { "Neck", "Boar", "Deer", "Grayling", "Wolf", "Lox", "Hen" };
				for (int i = 0; i < array.Length; i++)
				{
					if (splash != null)
					{
						break;
					}
					GameObject prefab = instance.GetPrefab(array[i]);
					if (!((Object)(object)prefab == (Object)null))
					{
						Character component = prefab.GetComponent<Character>();
						if (!((Object)(object)component == (Object)null) && component.m_waterEffects.HasEffects())
						{
							splash = component.m_waterEffects;
							character.m_waterEffects = splash;
							DinoPlugin.Log.LogInfo((object)("[dino] water fx: borrowed m_waterEffects of " + array[i]));
						}
					}
				}
				if (splash == null)
				{
					DinoPlugin.Log.LogWarning((object)"[dino] no wading water fx found");
				}
			}
			List<GameObject> prefabs = instance.m_prefabs;
			if (prefabs == null)
			{
				return;
			}
			for (int j = 0; j < prefabs.Count; j++)
			{
				GameObject val = prefabs[j];
				if (!((Object)(object)val == (Object)null))
				{
					Projectile component2 = val.GetComponent<Projectile>();
					if (!((Object)(object)component2 == (Object)null) && component2.m_hitWaterEffects.HasEffects())
					{
						plume = component2.m_hitWaterEffects;
						DinoPlugin.Log.LogInfo((object)("[dino] splash plume: Projectile.m_hitWaterEffects of " + ((Object)val).name));
						return;
					}
				}
			}
			DinoPlugin.Log.LogWarning((object)"[dino] no water impact plume found, hops use the ripple");
		}

		private void SplashSound(Vector3 pos, bool big)
		{
			//IL_00b7: 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)
			if (!soundChecked)
			{
				ZNetScene instance = ZNetScene.instance;
				if ((Object)(object)instance == (Object)null)
				{
					return;
				}
				soundChecked = true;
				splashSound = instance.GetPrefab("sfx_footstep_water");
				splashSoundBig = instance.GetPrefab("sfx_land_water");
				DinoPlugin.Log.LogInfo((object)("[dino] splash sound: " + (((Object)(object)splashSound != (Object)null) ? "sfx_footstep_water" : "none") + (((Object)(object)splashSoundBig != (Object)null) ? " + sfx_land_water" : "")));
			}
			GameObject val = ((big && (Object)(object)splashSoundBig != (Object)null) ? splashSoundBig : splashSound);
			if (!((Object)(object)val == (Object)null))
			{
				Object.Destroy((Object)(object)Object.Instantiate<GameObject>(val, pos, Quaternion.identity), 4f);
			}
		}

		private void Splash(bool big)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			EnsureSplashEffect();
			float num = character.GetLiquidLevel() + 0.05f;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(((Component)this).transform.position.x, num, ((Component)this).transform.position.z);
			Quaternion val2 = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
			float num2 = (big ? 0.35f : 0.2f);
			EffectList val3 = ((plume != null && plume.HasEffects()) ? plume : splash);
			if (val3 != null && val3.HasEffects())
			{
				DetachAndExpire(val3.Create(val, val2, ((Component)this).transform, num2, -1, default(ZDOID)), big ? 1.5f : 1f);
			}
			SplashSound(val, big);
		}

		private void DetachAndExpire(GameObject[] instances, float life)
		{
			if (instances == null)
			{
				return;
			}
			foreach (GameObject val in instances)
			{
				if (!((Object)(object)val == (Object)null))
				{
					val.transform.SetParent((Transform)null, true);
					Object.Destroy((Object)(object)val, life);
				}
			}
		}

		private void StopMoving()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)character == (Object)null))
			{
				character.SetMoveDir(Vector3.zero);
				character.SetWalk(false);
				character.SetRun(false);
			}
		}

		private float HorizontalDistance(Vector3 target)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = target - ((Component)this).transform.position;
			val.y = 0f;
			return ((Vector3)(ref val)).magnitude;
		}

		private void FindCuriosityCharacters(out Character player, out Character creature)
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
			player = null;
			creature = null;
			float num = float.MaxValue;
			float num2 = float.MaxValue;
			float num3 = float.MaxValue;
			Character val = null;
			float noticeRange = NoticeRange;
			List<Character> allCharacters = Character.GetAllCharacters();
			for (int i = 0; i < allCharacters.Count; i++)
			{
				Character val2 = allCharacters[i];
				if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)character || val2.IsDead() || !IsGreetable(val2))
				{
					continue;
				}
				if (DinoRegistry.IsDino(val2))
				{
					if (Time.time < nextDinoHelloTime || IsAsleep(val2))
					{
						continue;
					}
				}
				else if (Time.time < nextGreetTime)
				{
					continue;
				}
				Vector3 val3 = ((Component)val2).transform.position - ((Component)this).transform.position;
				float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
				if (sqrMagnitude > noticeRange * noticeRange || Physics.Raycast(((Component)this).transform.position + Vector3.up * 0.5f, ((Vector3)(ref val3)).normalized, ((Vector3)(ref val3)).magnitude, LayerMask.GetMask(new string[3] { "Default", "static_solid", "Default_small" })))
				{
					continue;
				}
				if (val2.IsPlayer())
				{
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						player = val2;
					}
				}
				else if (DinoRegistry.IsDino(val2))
				{
					if (sqrMagnitude < num3)
					{
						num3 = sqrMagnitude;
						val = val2;
					}
				}
				else if (sqrMagnitude < num2)
				{
					num2 = sqrMagnitude;
					creature = val2;
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				creature = val;
			}
		}

		private static bool IsGreetable(Character c)
		{
			return (Object)(object)((Component)c).GetComponent<Fish>() == (Object)null;
		}

		private static bool TryGetLivePosition(Transform t, out Vector3 pos)
		{
			//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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			if ((Object)(object)t == (Object)null)
			{
				return false;
			}
			try
			{
				pos = t.position;
				return true;
			}
			catch (MissingReferenceException)
			{
				return false;
			}
		}

		private bool TryFindPickable(out Pickable best)
		{
			//IL_004f: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			best = null;
			PickCandidates.Clear();
			int mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "item" });
			int num = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, NoticeRange, PickBuffer, mask, (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				Collider val = PickBuffer[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Pickable componentInParent = ((Component)val).GetComponentInParent<Pickable>();
				if (!((Object)(object)componentInParent == (Object)null) && !componentInParent.GetPicked())
				{
					ZNetView component = ((Component)componentInParent).GetComponent<ZNetView>();
					if (!((Object)(object)component == (Object)null) && component.IsValid() && component.IsOwner() && GroundOk(((Component)componentInParent).transform.position, out var _))
					{
						PickCandidates.Add(componentInParent);
					}
				}
			}
			if (PickCandidates.Count == 0)
			{
				return false;
			}
			best = PickCandidates[Random.Range(0, PickCandidates.Count)];
			for (int j = 0; j < 4; j++)
			{
				if (!((Object)(object)best != (Object)null))
				{
					break;
				}
				if (Reachable(((Component)best).transform.position))
				{
					break;
				}
				best = PickCandidates[Random.Range(0, PickCandidates.Count)];
			}
			return true;
		}

		private Transform FindObjectTarget()
		{
			//IL_004c: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			ObjectCandidates.Clear();
			int mask = LayerMask.GetMask(new string[6] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid", "item" });
			int num = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, NoticeRange, PickBuffer, mask, (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				Collider val = PickBuffer[i];
				if (!((Object)(object)val == (Object)null) && !((Component)val).transform.IsChildOf(((Component)this).transform) && !((Object)(object)((Component)val).GetComponentInParent<Character>() != (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<Pickable>() != (Object)null))
				{
					Transform val2 = InterestingObject(val);
					if (!((Object)(object)val2 == (Object)null) && (!((Object)(object)val2 == (Object)(object)lastObject) || !(Time.time < forgetObjectUntil)) && GroundOk(val2.position, out var _))
					{
						ObjectCandidates.Add(val2);
					}
				}
			}
			if (ObjectCandidates.Count == 0)
			{
				return null;
			}
			Transform val3 = ObjectCandidates[Random.Range(0, ObjectCandidates.Count)];
			for (int j = 0; j < 4; j++)
			{
				if (!((Object)(object)val3 != (Object)null))
				{
					break;
				}
				if (Reachable(val3.position))
				{
					break;
				}
				val3 = ObjectCandidates[Random.Range(0, ObjectCandidates.Count)];
			}
			return val3;
		}

		private static Transform InterestingObject(Collider col)
		{
			ItemDrop componentInParent = ((Component)col).GetComponentInParent<ItemDrop>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				return ((Component)componentInParent).transform;
			}
			if ((Object)(object)((Component)col).GetComponentInParent<TreeBase>() != (Object)null)
			{
				return null;
			}
			if ((Object)(object)((Component)col).GetComponentInParent<MineRock>() != (Object)null)
			{
				return null;
			}
			if ((Object)(object)((Component)col).GetComponentInParent<MineRock5>() != (Object)null)
			{
				return null;
			}
			Interactable componentInParent2 = ((Component)col).GetComponentInParent<Interactable>();
			Component val = (Component)(object)((componentInParent2 is Component) ? componentInParent2 : null);
			if ((Object)(object)val != (Object)null)
			{
				return val.transform;
			}
			Destructible componentInParent3 = ((Component)col).GetComponentInParent<Destructible>();
			if ((Object)(object)componentInParent3 != (Object)null)
			{
				return ((Component)componentInParent3).transform;
			}
			return null;
		}

		private bool TryPickWaypoint(out Vector3 result)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(2f, DinoPlugin.WanderRadius.Value);
			Vector3 position = ((Component)this).transform.position;
			Vector3? val = null;
			for (int i = 0; i < 10; i++)
			{
				Vector2 val2 = Random.insideUnitCircle * num;
				if (GroundOk(position + new Vector3(val2.x, 0f, val2.y), out var ground))
				{
					if (!val.HasValue)
					{
						val = ground;
					}
					if (Reachable(ground))
					{
						result = ground;
						return true;
					}
				}
			}
			if (val.HasValue)
			{
				result = val.Value;
				return true;
			}
			result = ((Component)this).transform.position;
			return false;
		}

		private bool TryFindPuddle(out Vector3 result)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_0087: 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_00af: 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)
			//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_00d5: Unknown result type (might be due to invalid IL or missing references)
			result = ((Component)this).transform.position;
			if (DinoPlugin.CuriosityPuddleChance.Value <= 0f)
			{
				return false;
			}
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			float puddleDepth = PuddleDepth;
			float num = Mathf.Min(20f, NoticeRange);
			float num2 = default(float);
			for (int i = 0; i < 20; i++)
			{
				Vector2 val = Random.insideUnitCircle * num;
				Vector3 val2 = ((Component)this).transform.position + new Vector3(val.x, 0f, val.y);
				if (instance.GetGroundHeight(val2, ref num2))
				{
					float num3 = instance.m_waterLevel - num2;
					if (!(num3 < 0.05f) && !(num3 > puddleDepth) && !instance.IsLava(val2, false))
					{
						result = new Vector3(val2.x, num2 + 0.05f, val2.z);
						return true;
					}
				}
			}
			return false;
		}

		private bool TryFindFire(out Fireplace result)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			result = null;
			if (DinoPlugin.CuriosityFireChance.Value <= 0f)
			{
				return false;
			}
			if (Time.time < nextFireTime)
			{
				return false;
			}
			float num = Mathf.Clamp(DinoPlugin.FireRange.Value, 5f, 60f);
			int mask = LayerMask.GetMask(new string[5] { "Default", "static_solid", "Default_small", "piece", "piece_nonsolid" });
			int num2 = Physics.OverlapSphereNonAlloc(((Component)this).transform.position, num, PickBuffer, mask, (QueryTriggerInteraction)2);
			float num3 = float.MaxValue;
			for (int i = 0; i < num2; i++)
			{
				Collider val = PickBuffer[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Fireplace componentInParent = ((Component)val).GetComponentInParent<Fireplace>();
				if (!((Object)(object)componentInParent == (Object)null) && Burning(componentInParent) && TryGetLivePosition(((Component)componentInParent).transform, out var pos))
				{
					Vector3 val2 = pos - ((Component)this).transform.position;
					val2.y = 0f;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (!(sqrMagnitude >= num3) && GroundOk(pos, out var _) && Reachable(pos))
					{
						num3 = sqrMagnitude;
						result = componentInParent;
					}
				}
			}
			return (Object)(object)result != (Object)null;
		}

		private static bool Burning(Fireplace fire)
		{
			if ((Object)(object)fire == (Object)null)
			{
				return false;
			}
			ZNetView component = ((Component)fire).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			return fire.IsBurning();
		}

		private bool TryFindDrySpot(Vector3 water, out Vector3 result)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b1: 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)
			result = ((Component)this).transform.position;
			float num = 0f;
			Vector3 val = ((Component)this).transform.position - water;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
			{
				num = Mathf.Atan2(val.x, val.z) * 57.29578f;
			}
			for (int i = 1; i <= 2; i++)
			{
				for (int j = 0; j < 8; j++)
				{
					Vector3 val2 = Quaternion.Euler(0f, num + (float)j * 45f, 0f) * Vector3.forward;
					if (GroundOk(((Component)this).transform.position + val2 * (2.5f * (float)i), out var ground))
					{
						result = ground;
						return true;
					}
				}
			}
			return false;
		}

		private bool Reachable(Vector3 p)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!DinoPlugin.UsePathfinding.Value)
			{
				return true;
			}
			Pathfinding instance = Pathfinding.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return true;
			}
			return instance.HavePath(((Component)this).transform.position, p, (AgentType)6);
		}

		private static bool GroundOk(Vector3 p, out Vector3 ground)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0076: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			ground = p;
			ZoneSystem instance = ZoneSystem.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			float num = default(float);
			if (!instance.GetGroundHeight(p, ref num))
			{
				return false;
			}
			if (num < instance.m_waterLevel + 0.5f)
			{
				return false;
			}
			if (instance.IsLava(p, false))
			{
				return false;
			}
			float num3 = default(float);
			for (int i = 0; i < 4; i++)
			{
				float num2 = (float)i * 90f;
				Vector3 val = Quaternion.Euler(0f, num2, 0f) * Vector3.forward * 1.5f;
				if (!instance.GetGroundHeight(p + val, ref num3))
				{
					return false;
				}
				if (Mathf.Abs(num3 - num) > 1.2f)
				{
					return false;
				}
			}
			if (WorldGenerator.instance != null && (WorldGenerator.instance.GetBiome(p) & 0x27F) == 0)
			{
				return false;
			}
			ground = new Vector3(p.x, num + 0.05f, p.z);
			return true;
		}

		private static string BerryForBiome(Biome biome)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if ((biome & 1) != 0)
			{
				return "Raspberry";
			}
			if ((biome & 8) != 0)
			{
				return "Blueberry";
			}
			if ((biome & 0x10) != 0)
			{
				return "Cloudberry";
			}
			return null;
		}

		private bool DropBerry(string itemName, Character player)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			ObjectDB instance = ObjectDB.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			GameObject itemPrefab = instance.GetItemPrefab(itemName);
			if ((Object)(object)itemPrefab == (Object)null)
			{
				if (!loggedMissingBerry)
				{
					loggedMissingBerry = true;
					DinoPlugin.Log.LogWarning((object)("[dino] no item prefab named " + itemName));
				}
				return false;
			}
			Vector3 val = ((Component)player).transform.position + ((Component)player).transform.forward * 1.1f;
			float num = default(float);
			if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetGroundHeight(val, ref num))
			{
				val.y = num + 0.35f;
			}
			else
			{
				val.y = ((Component)player).transform.position.y + 0.4f;
			}
			GameObject obj = Object.Instantiate<GameObject>(itemPrefab, val, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f));
			ItemDrop component = obj.GetComponent<ItemDrop>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetStack(1);
				ItemDrop.OnCreateNew(component, false);
			}
			Rigidbody component2 = obj.GetComponent<Rigidbody>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.linearVelocity = Vector3.up * 2.5f;
			}
			return true;
		}
	}
	internal static class DinoDreams
	{
		private sealed class Dream
		{
			public readonly string Token;

			public readonly string Text;

			public Dream(string token, string text)
			{
				Token = token;
				Text = text;
			}
		}

		private static readonly Dream[] All = new Dream[6]
		{
			new Dream("$dream_dino1", "You dream of a tiny dino asleep in an upturned mushroom cap. The cap rocks gently with every snore."),
			new Dream("$dream_dino2", "Little Baby Dino trots after you through the whole dream, a single berry held carefully in his mouth for later."),
			new Dream("$dream_dino3", "You dream of Dino chasing a butterfly across the meadow. He never catches it, and he does not seem to mind at all."),
			new Dream("$dream_dino4", "A small warm dino curls up against your feet in your dream. Every time you shift, he shuffles a little closer."),
			new Dream("$dream_dino5", "You dream of Dino stomping through a puddle, splashing with both front feet, then shaking the water off onto you."),
			new Dream("$dream_dino6", "In your dream Dino brings you a stone. It is not a good stone. It is the best stone he has ever found.")
		};

		private static DreamText[] _pool;

		internal static void Register()
		{
			CustomLocalization localization = LocalizationManager.Instance.GetLocalization();
			Dream[] all = All;
			foreach (Dream dream in all)
			{
				string text = "English";
				localization.AddTranslation(ref text, ref dream.Token, dream.Text);
			}
		}

		internal static DreamText Pick()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			if (_pool == null)
			{
				_pool = (DreamText[])(object)new DreamText[All.Length];
				for (int i = 0; i < All.Length; i++)
				{
					_pool[i] = new DreamText
					{
						m_text = All[i].Token,
						m_chanceToDream = 1f,
						m_trueKeys = new List<string>(),
						m_falseKeys = new List<string>()
					};
				}
			}
			return _pool[Random.Range(0, _pool.Length)];
		}
	}
	[HarmonyPatch(typeof(DreamTexts), "GetRandomDreamText")]
	internal static class DinoDreamPatch
	{
		[HarmonyPostfix]
		private static void AddDinoDream(ref DreamText __result)
		{
			if (__result == null)
			{
				ConfigEntry<float> dinoDreamChance = DinoPlugin.DinoDreamChance;
				if (dinoDreamChance != null && !(dinoDreamChance.Value <= 0f) && !(Random.value > dinoDreamChance.Value / 100f))
				{
					__result = DinoDreams.Pick();
				}
			}
		}
	}
	internal static class DinoGuard
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static LogCallback <0>__OnUnityLog;

			public static UnhandledExceptionEventHandler <1>__OnUnhandledException;

			public static EventHandler<FirstChanceExceptionEventArgs> <2>__OnFirstChanceException;
		}

		private const int BreadcrumbCount = 8;

		private const long MaxLogBytes = 2097152L;

		private static readonly string[] DinoTokens = new string[14]
		{
			"BabyDino", "DinoValheim", "DinoPlugin", "DinoBrain", "DinoAI", "DinoRig", "DinoPet", "DinoSleepFx", "DinoAnimator", "DinoAsset",
			"DinoDreams", "DinoLove", "DinoRegistry", "dino.valheim"
		};

		private static readonly object Sync = new object();

		private static readonly string[] Breadcrumbs = new string[8];

		private static int _breadcrumbNext;

		private static int _exceptionCount;

		private static string _stage = "nothing yet";

		private static string _exceptionPath;

		private static string _heartbeatPath;

		private static string _throwPath;

		private static DateTime _lastThrowAt = DateTime.MinValue;

		private static DateTime _lastBeatAt = DateTime.MinValue;

		private static DateTime _lastErrorWrite = DateTime.MinValue;

		private static int _suppressedErrors;

		private static bool _staleAssemblyReported;

		private static bool _installed;

		private static float _nextHeartbeat;

		private static int _mainThreadId;

		[ThreadStatic]
		private static bool _inHandler;

		internal static float HeartbeatSeconds = 5f;

		private static bool IsMainThread => Thread.CurrentThread.ManagedThreadId == _mainThreadId;

		internal static void Install()
		{
			//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_006c: Expected O, but got Unknown
			if (!_installed)
			{
				_installed = true;
				_mainThreadId = Thread.CurrentThread.ManagedThreadId;
				string bepInExRootPath = Paths.BepInExRootPath;
				_exceptionPath = Path.Combine(bepInExRootPath, "dino-exceptions.log");
				_heartbeatPath = Path.Combine(bepInExRootPath, "dino-heartbeat.log");
				_throwPath = Path.Combine(bepInExRootPath, "dino-last-throw.log");
				object obj = <>O.<0>__OnUnityLog;
				if (obj == null)
				{
					LogCallback val = OnUnityLog;
					<>O.<0>__OnUnityLog = val;
					obj = (object)val;
				}
				Application.logMessageReceivedThreaded += (LogCallback)obj;
				AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
				AppDomain.CurrentDomain.FirstChanceException += OnFirstChanceException;
				Stage("plugin awake");
				Append(_exceptionPath, Environment.NewLine + "=== BabyDino 0.16.0 loaded " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ===");
				if (DinoPlugin.Log != null)
				{
					DinoPlugin.Log.LogInfo((object)("[guard] dino exceptions -> " + _exceptionPath + " , last known state -> " + _heartbeatPath));
				}
			}
		}

		internal static void Stage(string stage)
		{
			if (string.IsNullOrEmpty(stage) || stage == _stage)
			{
				return;
			}
			_stage = stage;
			lock (Sync)
			{
				Breadcrumbs[_breadcrumbNext % 8] = DateTime.Now.ToString("HH:mm:ss") + " " + stage;
				_breadcrumbNext++;
			}
		}

		internal static void Beat(string why)
		{
			if (_installed)
			{
				if (IsMainThread)
				{
					_nextHeartbeat = Time.unscaledTime + Mathf.Max(1f, HeartbeatSeconds);
				}
				_lastBeatAt = DateTime.UtcNow;
				Write(_heartbeatPath, HeartbeatText(why));
				DinoLog.Debug("heartbeat: " + why + " (stage " + _stage + ", dinos " + DinoRegistry.Count + ", exceptions " + _exceptionCount + ")");
			}
		}

		internal static void BeatIfStale(string why, float minSeconds)
		{
			if (_installed && IsMainThread && (!(minSeconds > 0f) || !((DateTime.UtcNow - _lastBeatAt).TotalSeconds < (double)minSeconds)))
			{
				Beat(why);
			}
		}

		internal static void Tick()
		{
			if (!_installed || HeartbeatSeconds <= 0f)
			{
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (!(unscaledTime < _nextHeartbeat))
			{
				_nextHeartbeat = unscaledTime + Mathf.Max(1f, HeartbeatSeconds);
				if (DinoRegistry.Count != 0)
				{
					Write(_heartbeatPath, HeartbeatText("tick"));
				}
			}
		}

		private static void OnUnityLog(string condition, string stackTrace, LogType type)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_000c: 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)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			if (_inHandler || ((int)type != 4 && (int)type != 0 && (int)type != 1))
			{
				return;
			}
			_inHandler = true;
			try
			{
				bool flag = MentionsDino(condition) || MentionsDino(stackTrace);
				_exceptionCount++;
				if (!_staleAssemblyReported && condition != null && condition.IndexOf("BadImageFormatException", StringComparison.Ordinal) >= 0)
				{
					_staleAssemblyReported = true;
					if (DinoPlugin.Log != null)
					{
						DinoPlugin.Log.LogError((object)"[guard] BadImageFormatException spam: a plugin DLL was replaced while this session was running, so mono is reading a half-swapped image. Restart Valheim, and deploy with mod/deploy.sh (rename, never cp over a loaded DLL).");
					}
				}
				DateTime utcNow = DateTime.UtcNow;
				DateTime now = DateTime.Now;
				if (!flag && (utcNow - _lastErrorWrite).TotalSeconds < 1.0)
				{
					_suppressedErrors++;
					return;
				}
				_lastErrorWrite = utcNow;
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append('[').Append(now.ToString("HH:mm:ss.fff")).Append("] ")
					.Append(type)
					.Append(flag ? "  *** DINO ***" : "  other")
					.Append("   stage: ")
					.Append(_stage)
					.AppendLine();
				stringBuilder.AppendLine(condition);
				if (!string.IsNullOrEmpty(stackTrace))
				{
					stringBuilder.AppendLine(stackTrace);
				}
				stringBuilder.AppendLine("-- dinos alive: " + DinoRegistry.Count + ", exceptions logged: " + _exceptionCount);
				if (_suppressedErrors > 0)
				{
					stringBuilder.AppendLine("-- suppressed " + _suppressedErrors + " further non-dino lines in the last second");
					_suppressedErrors = 0;
				}
				stringBuilder.AppendLine("-- last stages: " + BreadcrumbLine());
				Append(_exceptionPath, stringBuilder.ToString());
				if (flag && DinoPlugin.Log != null)
				{
					DinoPlugin.Log.LogError((object)("[guard] DINO EXCEPTION: " + FirstLine(condition) + " (full trace in BepInEx/dino-exceptions.log)"));
				}
				Beat("exception");
			}
			catch
			{
			}
			finally
			{
				_inHandler = false;
			}
		}

		private static void OnFirstChanceException(object sender, FirstChanceExceptionEventArgs e)
		{
			if (_inHandler)
			{
				return;
			}
			Exception exception = e.Exception;
			if (exception == null)
			{
				return;
			}
			_inHandler = true;
			try
			{
				string fullName = exception.GetType().FullName;
				string message = exception.Message;
				string text = null;
				try
				{
					MethodBase targetSite = exception.TargetSite;
					if (targetSite != null && targetSite.DeclaringType != null)
					{
						text = targetSite.DeclaringType.FullName + "." + targetSite.Name;
					}
				}
				catch
				{
				}
				bool flag = MentionsDino(fullName) || MentionsDino(message) || MentionsDino(text);
				DateTime utcNow = DateTime.UtcNow;
				if (flag || !((utcNow - _lastThrowAt).TotalMilliseconds < 250.0))
				{
					_lastThrowAt = utcNow;
					StringBuilder stringBuilder = new StringBuilder();
					stringBuilder.Append('[').Append(DateTime.Now.ToString("HH:mm:ss.fff")).Append("] thrown: ")
						.Append(fullName)
						.Append(flag ? "  *** DINO ***" : "")
						.AppendLine();
					stringBuilder.Append("  message: ").AppendLine(message);
					stringBuilder.Append("  site: ").AppendLine(text ?? "(unknown)");
					stringBuilder.Append("  stage: ").Append(_stage).Append("   dinos alive: ")
						.Append(DinoRegistry.Count)
						.AppendLine();
					stringBuilder.Append("  last stages: ").Append(BreadcrumbLine()).AppendLine();
					stringBuilder.AppendLine("  (first chance: this was written the moment it was thrown, before Unity logged or formatted it)");
					Write(_throwPath, stringBuilder.ToString());
				}
			}
			catch
			{
			}
			finally
			{
				_inHandler = false;
			}
		}

		private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append('[').Append(DateTime.Now.ToString("HH:mm:ss.fff")).Append("] UNHANDLED EXCEPTION  terminating=")
					.Append(e.IsTerminating)
					.Append("   stage: ")
					.Append(_stage)
					.AppendLine();
				stringBuilder.AppendLine((e.ExceptionObject == null) ? "(null)" : e.ExceptionObject.ToString());
				stringBuilder.AppendLine("-- dinos alive: " + DinoRegistry.Count);
				stringBuilder.AppendLine("-- last stages: " + BreadcrumbLine());
				Append(_exceptionPath, stringBuilder.ToString());
				Write(_heartbeatPath, HeartbeatText("unhandled exception"));
			}
			catch
			{
			}
		}

		private static string HeartbeatText(string why)
		{
			//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_0165: 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)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")).Append("   dino heartbeat (").Append(why)
				.Append(')')
				.AppendLine();
			stringBuilder.Append("stage: ").Append(_stage).AppendLine();
			stringBuilder.Append("dinos alive: ").Append(DinoRegistry.Count).Append("   exceptions logged this session: ")
				.Append(_exceptionCount)
				.AppendLine();
			stringBuilder.Append("last stages: ").Append(BreadcrumbLine()).AppendLine();
			if (!IsMainThread)
			{
				stringBuilder.AppendLine("  (per-dino state skipped: logged from a worker thread)");
				return stringBuilder.ToString();
			}
			Player localPlayer = Player.m_localPlayer;
			List<Character> list = DinoRegistry.Snapshot();
			for (int i = 0; i < list.Count; i++)
			{
				Character val = list[i];
				stringBuilder.Append("  #").Append(i + 1).Append(' ');
				if ((Object)(object)val == (Object)null)
				{
					stringBuilder.Append("(destroyed)").AppendLine();
					continue;
				}
				StringBuilder stringBuilder2 = stringBuilder.Append(((Object)val).name).Append("  pos=");
				Vector3 position = ((Component)val).transform.position;
				stringBuilder2.Append(((Vector3)(ref position)).ToString("F1"));
				if ((Object)(object)localPlayer != (Object)null)
				{
					stringBuilder.Append("  dist=").Append(Vector3.Distance(((Component)localPlayer).transform.position, ((Component)val).transform.position).ToString("F1"));
				}
				ZNetView component = ((Component)val).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					stringBuilder.Append(component.IsOwner() ? "  owner=local" : "  owner=remote");
				}
				stringBuilder.AppendLine();
			}
			return stringBuilder.ToString();
		}

		private static string BreadcrumbLine()
		{
			StringBuilder stringBuilder = new StringBuilder();
			lock (Sync)
			{
				for (int i = ((_breadcrumbNext > 8) ? (_breadcrumbNext - 8) : 0); i < _breadcrumbNext; i++)
				{
					string text = Breadcrumbs[i % 8];
					if (text != null)
					{
						if (stringBuilder.Length > 0)
						{
							stringBuilder.Append(" | ");
						}
						stringBuilder.Append(text);
					}
				}
			}
			if (stringBuilder.Length != 0)
			{
				return stringBuilder.ToString();
			}
			return "(none)";
		}

		private static bool MentionsDino(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			for (int i = 0; i < DinoTokens.Length; i++)
			{
				if (text.IndexOf(DinoTokens[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		private static string FirstLine(string text)
		{
			if (string.IsNullOrEmpty(text))
			{
				return "(empty)";
			}
			int num = text.IndexOfAny(new char[2] { '\r', '\n' });
			string text2 = ((num < 0) ? text : text.Substring(0, num));
			if (text2.Length <= 300)
			{
				return text2;
			}
			return text2.Substring(0, 300) + "...";
		}

		private static void Append(string path, string text)
		{
			if (string.IsNullOrEmpty(path))
			{
				return;
			}
			try
			{
				lock (Sync)
				{
					FileInfo fileInfo = new FileInfo(path);
					if (fileInfo.Exists && fileInfo.Length > 2097152)
					{
						string text2 = path + ".1";
						if (File.Exists(text2))
						{
							File.Delete(text2);
						}
						File.Move(path, text2);
					}
					File.AppendAllText(path, text + Environment.NewLine);
				}
			}
			catch
			{
			}
		}

		private static void Write(string path, string text)
		{
			if (string.IsNullOrEmpty(path))
			{
				return;
			}
			try
			{
				lock (Sync)
				{
					File.WriteAllText(path, text);
				}
			}
			catch
			{
			}
		}
	}
	internal static class DinoLog
	{
		internal const bool IsDevBuild = false;

		internal static bool Verbose;

		private static readonly Dictionary<string, float> NextAt = new Dictionary<string, float>();

		internal static void Init(ConfigEntry<bool> entry)
		{
			Verbose = entry?.Value ?? false;
			string environmentVariable = Environment.GetEnvironmentVariable("DINO_VERBOSE");
			if (!string.IsNullOrEmpty(environmentVariable) && environmentVariable != "0")
			{
				Verbose = true;
			}
			if (DinoPlugin.Log != null)
			{
				DinoPlugin.Log.LogInfo((object)("[dino] build = RELEASE, verbose logging " + (Verbose ? "ON" : "off")));
			}
		}

		internal static void Debug(string message)
		{
			if (Verbose && DinoPlugin.Log != null)
			{
				DinoPlugin.Log.LogInfo((object)("[dbg] " + message));
			}
		}

		internal static void DebugEvery(string key, float seconds, string message)
		{
			if (Verbose && DinoPlugin.Log != null)
			{
				float unscaledTime = Time.unscaledTime;
				if (!NextAt.TryGetValue(key, out var value) || !(unscaledTime < value))
				{
					NextAt[key] = unscaledTime + Mathf.Max(0.1f, seconds);
					DinoPlugin.Log.LogInfo((object)("[dbg] " + message));
				}
			}
		}

		internal static void Once(string key, string message)
		{
			if (DinoPlugin.Log != null && (!NextAt.TryGetValue("once:" + key, out var value) || !(value > 0f)))
			{
				NextAt["once:" + key] = 1f;
				DinoPlugin.Log.LogInfo((object)("[dino] " + message));
			}
		}
	}
	public class DinoPet : MonoBehaviour, Hoverable, Interactable
	{
		public const string LoveKey = "dv_love";

		public const string PetRpc = "DinoPet";

		private const float PetCooldown = 1f;

		private const float HeartPoll = 0.1f;

		private ZNetView nview;

		private DinoRig rig;

		private EffectList hearts;

		private float nextPetTime;

		private float nextHeartPoll;

		private int lastLoveSeq = -1;

		private ZDO Zdo
		{
			get
			{
				if ((Object)(object)nview == (Object)null || !nview.IsValid())
				{
					return null;
				}
				return nview.GetZDO();
			}
		}

		private void Awake()
		{
			DinoGuard.Stage("DinoPet.Awake");
			nview = ((Component)this).GetComponent<ZNetView>();
			rig = ((Component)this).GetComponent<DinoRig>();
		}

		private void Start()
		{
			DinoGuard.Stage("DinoPet.Start");
			hearts = DinoLove.HeartEffect();
			ZDO zdo = Zdo;
			if (zdo != null)
			{
				lastLoveSeq = zdo.GetInt("dv_love", 0);
			}
		}

		public string GetHoverText()
		{
			string text = Loc("$creature_babydino");
			if (!DinoPlugin.PettingEnabled.Value)
			{
				return text;
			}
			return text + "\n" + Loc("[<color=yellow><b>$KEY_Use</b></color>] Mrauw!");
		}

		public string GetHoverName()
		{
			return Loc("$creature_babydino");
		}

		private static string Loc(string token)
		{
			Localization instance = Localization.instance;
			if (instance == null)
			{
				return token;
			}
			return instance.Localize(token);
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold || alt)
			{
				return false;
			}
			if (!DinoPlugin.PettingEnabled.Value)
			{
				return false;
			}
			Player val = (Player)(object)((user is Player) ? user : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if (Time.time - nextPetTime < 1f)
			{
				return false;
			}
			nextPetTime = Time.time;
			DinoLove.Apply(val);
			long playerID = val.GetPlayerID();
			if ((Object)(object)nview != (Object)null && nview.IsValid())
			{
				nview.InvokeRPC("DinoPet", new object[1] { playerID });
			}
			else
			{
				if ((Object)(object)rig != (Object)null)
				{
					rig.PlayOnce("wave", 0.12f);
					rig.PlayRandomSound();
				}
				SpawnHearts();
			}
			((Character)val).Message((MessageType)2, "Mrauw!", 0, (Sprite)null, false);
			if ((Object)(object)Game.instance != (Object)null)
			{
				Game.instance.IncrementPlayerStat((PlayerStatType)191, 1f, false);
			}
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			return false;
		}

		private void Update()
		{
			if (Time.time < nextHeartPoll)
			{
				return;
			}
			nextHeartPoll = Time.time + 0.1f;
			ZDO zdo = Zdo;
			if (zdo != null)
			{
				int num = zdo.GetInt("dv_love", 0);
				if (num != lastLoveSeq)
				{
					lastLoveSeq = num;
					SpawnHearts();
				}
			}
		}

		private void SpawnHearts()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0092: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			if (hearts == null)
			{
				hearts = DinoLove.HeartEffect();
			}
			if (hearts != null && hearts.m_effectPrefabs != null && hearts.m_effectPrefabs.Length != 0)
			{
				Vector3 val = ((Component)this).transform.position + Vector3.up * 0.9f + ((Component)this).transform.forward * 0.25f;
				hearts.Create(val, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f), ((Component)this).transform, 1f, -1, default(ZDOID));
			}
		}
	}
	internal static class DinoLove
	{
		public const string EffectName = "Dino Love";

		private const string EffectAssetName = "SE_DinoLove";

		private static SE_Stats template;

		private static EffectList hearts;

		private static bool heartsSearched;

		public static void Apply(Player player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return;
			}
			SEMan sEMan = ((Character)player).GetSEMan();
			if (sEMan != null)
			{
				SE_Stats val = Template();
				if (!((Object)(object)val == (Object)null))
				{
					float num = Mathf.Max(1f, DinoPlugin.PetBuffSeconds.Value);
					float num2 = Mathf.Max(0f, DinoPlugin.PetBuffStaminaPercent.Value);
					((StatusEffect)val).m_ttl = num;
					val.m_staminaRegenMultiplier = 1f + num2 * 0.01f;
					((StatusEffect)val).m_tooltip = "+" + Mathf.RoundToInt(num2) + "% stamina regeneration for " + Mathf.RoundToInt(num / 60f) + " min";
					sEMan.AddStatusEffect((StatusEffect)(object)val, true, 0, 0f, (short)(-1));
				}
			}
		}

		private static SE_Stats Template()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)template != (Object)null)
			{
				return template;