Decompiled source of ValheimPathfinder v0.3.1

plugins/ValheimPathfinder.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
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 UnityEngine;
using UnityEngine.Rendering;
using ValheimPathfinder.Core;
using ValheimPathfinder.Hunting;
using ValheimPathfinder.Roaming;
using ValheimPathfinder.Trails;
using ValheimPathfinder.Traps;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_guiutils")]
[assembly: IgnoresAccessChecksTo("assembly_utils")]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ValheimPathfinder")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+149ed1fbc20faeb1828e46776b16bf0790de54b6")]
[assembly: AssemblyProduct("ValheimPathfinder")]
[assembly: AssemblyTitle("ValheimPathfinder")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ValheimPathfinder
{
	[BepInPlugin("com.ghigog.valheimpathfinder", "Valheim Pathfinder", "0.3.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.ghigog.valheimpathfinder";

		public const string PluginName = "Valheim Pathfinder";

		public const string PluginVersion = "0.3.1";

		internal static ManualLogSource Log;

		private readonly Harmony harmony = new Harmony("com.ghigog.valheimpathfinder");

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			PfConfig.Bind(((BaseUnityPlugin)this).Config);
			HuntingSkill.Register();
			DebugCommands.Register();
			PrefabManager.OnVanillaPrefabsAvailable += OnVanillaPrefabsAvailable;
			harmony.PatchAll();
			Log.LogInfo((object)"Valheim Pathfinder 0.3.1 loaded");
		}

		private void OnVanillaPrefabsAvailable()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= OnVanillaPrefabsAvailable;
			Visuals.Init(PrefabManager.Instance.GetPrefab("piece_sharpstakes"));
			ClueRegistry.CreatePrefabs();
			TrailPainter.CreatePrefab();
			TrapRegistry.CreatePieces();
		}

		private void Update()
		{
			TreeMarks.UpdateInput();
			RavenTips.Tick();
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}
	}
}
namespace ValheimPathfinder.Traps
{
	internal class HuntingTrap : MonoBehaviour, Hoverable, Interactable
	{
		private static readonly int s_armed = StringExtensionMethods.GetStableHashCode("pf_armed");

		private const string s_victim = "pf_victim";

		private static readonly int s_holdUntil = StringExtensionMethods.GetStableHashCode("pf_holdUntil");

		private static readonly int s_unclaimed = StringExtensionMethods.GetStableHashCode("pf_unclaimed");

		private static readonly int s_lastCatch = StringExtensionMethods.GetStableHashCode("pf_lastCatch");

		private static readonly int s_skill = StringExtensionMethods.GetStableHashCode("pf_skill");

		private static readonly int s_bait = StringExtensionMethods.GetStableHashCode("pf_bait");

		private static readonly List<HuntingTrap> s_all = new List<HuntingTrap>();

		public string m_definition;

		private ZNetView m_nview;

		private Piece m_piece;

		private TrapDefinition m_def;

		private GameObject m_armedGroup;

		private GameObject m_sprungGroup;

		private readonly List<GameObject> m_baitVisuals = new List<GameObject>();

		private float m_nextRefresh;

		public TrapDefinition Definition => m_def;

		public bool IsArmed
		{
			get
			{
				if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid())
				{
					return m_nview.GetZDO().GetBool(s_armed, true);
				}
				return false;
			}
		}

		private string Bait
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
				{
					return "";
				}
				return m_nview.GetZDO().GetString(s_bait, "");
			}
		}

		private void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_piece = ((Component)this).GetComponent<Piece>();
			TrapRegistry.Definitions.TryGetValue(m_definition, out m_def);
			Transform obj = ((Component)this).transform.Find("pf_armed");
			m_armedGroup = ((obj != null) ? ((Component)obj).gameObject : null);
			Transform obj2 = ((Component)this).transform.Find("pf_sprung");
			m_sprungGroup = ((obj2 != null) ? ((Component)obj2).gameObject : null);
			if (Object.op_Implicit((Object)(object)m_armedGroup))
			{
				Transform[] componentsInChildren = m_armedGroup.GetComponentsInChildren<Transform>(true);
				foreach (Transform val in componentsInChildren)
				{
					if (((Object)val).name == "pf_bait")
					{
						m_baitVisuals.Add(((Component)val).gameObject);
					}
				}
			}
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.GetZDO() != null && m_def != null)
			{
				m_nview.Register<ZDOID>("PF_TryTrigger", (Action<long, ZDOID>)RPC_TryTrigger);
				m_nview.Register<bool>("PF_SetArmed", (Action<long, bool>)RPC_SetArmed);
				s_all.Add(this);
			}
		}

		private void Start()
		{
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid() && m_nview.IsOwner() && Object.op_Implicit((Object)(object)m_piece) && Object.op_Implicit((Object)(object)Player.m_localPlayer) && m_piece.GetCreator() == Player.m_localPlayer.GetPlayerID() && !m_nview.GetZDO().GetBool("pf_skillSet", false))
			{
				m_nview.GetZDO().Set(s_skill, HuntingSkill.LocalLevel());
				m_nview.GetZDO().Set("pf_skillSet", true);
				RavenTips.TrapPlaced();
			}
			RefreshVisual();
		}

		private void OnDestroy()
		{
			s_all.Remove(this);
		}

		private void Update()
		{
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < m_nextRefresh || !Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
			{
				return;
			}
			m_nextRefresh = Time.time + 0.5f;
			RefreshVisual();
			if (!IsArmed && m_nview.GetZDO().GetInt(s_unclaimed, 0) > 0 && Object.op_Implicit((Object)(object)m_piece) && Object.op_Implicit((Object)(object)Player.m_localPlayer) && m_piece.GetCreator() == Player.m_localPlayer.GetPlayerID())
			{
				RavenTips.TrapSprung(((Component)this).transform.position);
			}
			if (m_nview.IsOwner() && !m_def.Lethal)
			{
				ZDOID zDOID = m_nview.GetZDO().GetZDOID("pf_victim");
				if (!((ZDOID)(ref zDOID)).IsNone() && !IsHolding())
				{
					m_nview.GetZDO().Set("pf_victim", ZDOID.None);
				}
			}
		}

		private bool IsHolding()
		{
			//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)
			if (!m_def.Lethal)
			{
				ZDOID zDOID = m_nview.GetZDO().GetZDOID("pf_victim");
				if (!((ZDOID)(ref zDOID)).IsNone())
				{
					return GameTime.NowTicks < m_nview.GetZDO().GetLong(s_holdUntil, 0L);
				}
			}
			return false;
		}

		private void RefreshVisual()
		{
			bool flag = !Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid() || IsArmed;
			if (Object.op_Implicit((Object)(object)m_armedGroup) && m_armedGroup.activeSelf != flag)
			{
				m_armedGroup.SetActive(flag);
			}
			if (Object.op_Implicit((Object)(object)m_sprungGroup) && m_sprungGroup.activeSelf == flag)
			{
				m_sprungGroup.SetActive(!flag);
			}
			bool flag2 = flag && Bait != "";
			foreach (GameObject baitVisual in m_baitVisuals)
			{
				if (Object.op_Implicit((Object)(object)baitVisual) && baitVisual.activeSelf != flag2)
				{
					baitVisual.SetActive(flag2);
				}
			}
		}

		private bool BaitFits(Character c)
		{
			string bait = Bait;
			if (bait == "" || !Object.op_Implicit((Object)(object)c))
			{
				return false;
			}
			MonsterAI component = ((Component)c).GetComponent<MonsterAI>();
			if (Object.op_Implicit((Object)(object)component) && component.m_consumeItems != null)
			{
				foreach (ItemDrop consumeItem in component.m_consumeItems)
				{
					if (Object.op_Implicit((Object)(object)consumeItem) && Utils.GetPrefabName(((Component)consumeItem).gameObject) == bait)
					{
						return true;
					}
				}
			}
			Species species = Species.Of((Component)(object)c);
			if (species != null)
			{
				return InList(DietBait(species.Diet), bait);
			}
			return false;
		}

		private static string DietBait(Diet diet)
		{
			return diet switch
			{
				Diet.Herbivore => PfConfig.BaitHerbivore.Value, 
				Diet.Omnivore => PfConfig.BaitOmnivore.Value, 
				Diet.Carnivore => PfConfig.BaitCarnivore.Value, 
				_ => PfConfig.BaitBird.Value, 
			};
		}

		private static bool InList(string csv, string name)
		{
			string[] array = csv.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].Trim() == name)
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsBaitItem(ItemData item, string prefab)
		{
			if (item.m_shared.m_food > 0f || item.m_shared.m_foodStamina > 0f)
			{
				return true;
			}
			if (!InList(PfConfig.BaitHerbivore.Value, prefab) && !InList(PfConfig.BaitOmnivore.Value, prefab) && !InList(PfConfig.BaitCarnivore.Value, prefab))
			{
				return InList(PfConfig.BaitBird.Value, prefab);
			}
			return true;
		}

		private static string ItemName(string prefab)
		{
			GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(prefab) : null);
			ItemDrop val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<ItemDrop>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				return prefab;
			}
			return Localization.instance.Localize(val2.m_itemData.m_shared.m_name);
		}

		public static HuntingTrap FindLure(Character c, Vector3 pos)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			TrapSize trapSize = Species.SizeOf(Utils.GetPrefabName(((Component)c).gameObject));
			if (trapSize == TrapSize.None)
			{
				return null;
			}
			HuntingTrap result = null;
			float num = float.MaxValue;
			foreach (HuntingTrap item in s_all)
			{
				if (Object.op_Implicit((Object)(object)item) && item.m_def.Size == trapSize && item.IsArmed)
				{
					float num2 = Utils.DistanceXZ(pos, ((Component)item).transform.position);
					bool flag = item.BaitFits(c);
					float num3 = item.m_def.LureRadius * (flag ? 1.5f : 1f);
					float num4 = Mathf.Min(1f, item.m_def.LureChance * (flag ? 2f : 1f));
					if (num2 < num3 && num2 < num && Random.value < num4)
					{
						result = item;
						num = num2;
					}
				}
			}
			return result;
		}

		public static void FindTriggering(TrapSize size, Vector3 pos, List<HuntingTrap> results)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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)
			results.Clear();
			foreach (HuntingTrap item in s_all)
			{
				if (Object.op_Implicit((Object)(object)item) && item.m_def.Size == size && item.IsArmed && Utils.DistanceXZ(pos, ((Component)item).transform.position) < item.m_def.TriggerRadius && Mathf.Abs(pos.y - ((Component)item).transform.position.y) < 2f)
				{
					results.Add(item);
				}
			}
		}

		public void RequestTrigger(Character victim)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			m_nview.InvokeRPC("PF_TryTrigger", new object[1] { victim.GetZDOID() });
		}

		private void RPC_TryTrigger(long sender, ZDOID victimId)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			if (!m_nview.IsOwner() || !IsArmed)
			{
				return;
			}
			GameObject val = ZNetScene.instance.FindInstance(victimId);
			TrapVictim trapVictim = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<TrapVictim>() : null);
			if (!Object.op_Implicit((Object)(object)trapVictim))
			{
				return;
			}
			float level = m_nview.GetZDO().GetFloat(s_skill, 0f);
			float num = m_def.TriggerChance + 0.2f * HuntingSkill.Mastery(level) + 0.1f * HuntingSkill.Beyond(level);
			if (BaitFits(val.GetComponent<Character>()))
			{
				num += 0.2f;
			}
			if (!(Random.value > Mathf.Clamp01(num)))
			{
				ZDO zDO = m_nview.GetZDO();
				zDO.Set(s_armed, false);
				zDO.Set(s_bait, "");
				zDO.Set(s_unclaimed, zDO.GetInt(s_unclaimed, 0) + 1, false);
				zDO.Set(s_lastCatch, Utils.GetPrefabName(val));
				if (m_def.Lethal)
				{
					trapVictim.Kill(m_def.DropMultiplier);
				}
				else
				{
					long num2 = GameTime.TicksFromNow(m_def.HoldDays * GameTime.DayLength);
					zDO.Set("pf_victim", victimId);
					zDO.Set(s_holdUntil, num2);
					trapVictim.Hold(m_nview.GetZDO().m_uid, num2, m_def.TameMultiplier, ((Component)this).transform.position);
				}
				RefreshVisual();
			}
		}

		private void RPC_SetArmed(long sender, bool armed)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			if (m_nview.IsOwner())
			{
				m_nview.GetZDO().Set(s_armed, armed);
				if (armed)
				{
					m_nview.GetZDO().Set("pf_victim", ZDOID.None);
				}
				RefreshVisual();
			}
		}

		public string GetHoverName()
		{
			if (m_def == null)
			{
				return "";
			}
			return m_def.Name;
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public string GetHoverText()
		{
			if (m_def == null || !Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid())
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(m_def.Name);
			if (IsArmed)
			{
				stringBuilder.Append("\n<color=#88cc88>Set</color>");
				string bait = Bait;
				stringBuilder.Append((bait != "") ? (" (baited with " + ItemName(bait) + ")\n[<color=yellow><b>$ui_hold $KEY_Use</b></color>] Take bait") : "\nUse food on it to add bait");
			}
			else if (IsHolding())
			{
				string arg = Species.Get(m_nview.GetZDO().GetString(s_lastCatch, ""))?.Name ?? "an animal";
				double num = (double)(m_nview.GetZDO().GetLong(s_holdUntil, 0L) - GameTime.NowTicks) / 10000000.0 / (double)GameTime.DayLength * 24.0;
				stringBuilder.Append($"\n<color=#ffcc66>Holding {arg}</color> (about {Mathf.CeilToInt((float)num)} hours left)");
				stringBuilder.Append("\n[<color=yellow><b>$KEY_Use</b></color>] Release");
			}
			else
			{
				string text = ((m_nview.GetZDO().GetInt(s_unclaimed, 0) > 0) ? (" (caught " + (Species.Get(m_nview.GetZDO().GetString(s_lastCatch, ""))?.Name ?? "something") + ")") : "");
				stringBuilder.Append("\n<color=#cc8866>Sprung</color>" + text);
				stringBuilder.Append("\n[<color=yellow><b>$KEY_Use</b></color>] Reset");
			}
			return Localization.instance.Localize(stringBuilder.ToString());
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			//IL_0050: 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)
			if (m_def == null || !m_nview.IsValid())
			{
				return false;
			}
			if (IsArmed)
			{
				if (hold)
				{
					return TakeBait(user);
				}
				return false;
			}
			if (hold)
			{
				return false;
			}
			ZDO zDO = m_nview.GetZDO();
			if (IsHolding())
			{
				GameObject val = ZNetScene.instance.FindInstance(zDO.GetZDOID("pf_victim"));
				TrapVictim trapVictim = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<TrapVictim>() : null);
				if (Object.op_Implicit((Object)(object)trapVictim))
				{
					trapVictim.Release();
				}
				m_nview.ClaimOwnership();
				zDO.Set(s_holdUntil, 0L);
				zDO.Set("pf_victim", ZDOID.None);
				((Character)user).Message((MessageType)2, "You release the animal.", 0, (Sprite)null, false);
				return true;
			}
			int num = zDO.GetInt(s_unclaimed, 0);
			string text = "";
			if (num > 0 && (Object)(object)user == (Object)(object)Player.m_localPlayer)
			{
				HuntingSkill.RaiseLocal(15f * (float)num);
				m_nview.ClaimOwnership();
				zDO.Set(s_unclaimed, 0, false);
				text = ((HuntingSkill.LocalLevel() >= 100f) ? " You already know all a catch can teach." : " You learn from the catch.");
			}
			m_nview.InvokeRPC("PF_SetArmed", new object[1] { true });
			((Character)user).Message((MessageType)2, m_def.Name + " reset." + text, 0, (Sprite)null, false);
			return true;
		}

		private bool TakeBait(Humanoid user)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			string bait = Bait;
			if (bait == "")
			{
				return false;
			}
			m_nview.ClaimOwnership();
			m_nview.GetZDO().Set(s_bait, "");
			GameObject val = (Object.op_Implicit((Object)(object)ObjectDB.instance) ? ObjectDB.instance.GetItemPrefab(bait) : null);
			if (Object.op_Implicit((Object)(object)val) && !user.GetInventory().AddItem(val, 1))
			{
				Object.Instantiate<GameObject>(val, ((Component)user).transform.position + Vector3.up, Quaternion.identity);
			}
			((Character)user).Message((MessageType)2, "You take the " + ItemName(bait) + " off the " + m_def.Name + ".", 0, (Sprite)null, false);
			RefreshVisual();
			return true;
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			if (m_def == null || !m_nview.IsValid() || item == null || !Object.op_Implicit((Object)(object)item.m_dropPrefab))
			{
				return false;
			}
			string name = ((Object)item.m_dropPrefab).name;
			if (!IsBaitItem(item, name))
			{
				return false;
			}
			if (!IsArmed)
			{
				((Character)user).Message((MessageType)2, "Reset the trap before baiting it.", 0, (Sprite)null, false);
				return true;
			}
			m_nview.ClaimOwnership();
			m_nview.GetZDO().Set(s_bait, name);
			user.GetInventory().RemoveOneItem(item);
			((Character)user).Message((MessageType)2, "You bait the " + m_def.Name + " with " + ItemName(name) + ".", 0, (Sprite)null, false);
			RefreshVisual();
			return true;
		}
	}
	internal class TrapDefinition
	{
		public string Prefab;

		public string Name;

		public string Description;

		public TrapSize Size;

		public bool Lethal;

		public bool HighChance;

		public (string item, int amount)[] Cost;

		public Action<Transform> Build;

		public float TriggerChance
		{
			get
			{
				if (!HighChance)
				{
					return 0.3f;
				}
				return 0.75f;
			}
		}

		public float LureChance
		{
			get
			{
				if (!HighChance)
				{
					return 0.25f;
				}
				return 0.5f;
			}
		}

		public float LureRadius => (HighChance ? 20f : 12f) * SizeScale;

		public float TriggerRadius => Size switch
		{
			TrapSize.Small => 0.8f, 
			TrapSize.Medium => 1.3f, 
			_ => 2.2f, 
		};

		public float DropMultiplier
		{
			get
			{
				if (!HighChance)
				{
					return 1.5f;
				}
				return 0.5f;
			}
		}

		public float HoldDays
		{
			get
			{
				if (!HighChance)
				{
					return 1f;
				}
				return 0.15f;
			}
		}

		public float TameMultiplier
		{
			get
			{
				if (!HighChance)
				{
					return 5f;
				}
				return 2f;
			}
		}

		public float Footprint => Size switch
		{
			TrapSize.Small => 0.9f, 
			TrapSize.Medium => 1.8f, 
			_ => 3f, 
		};

		private float SizeScale
		{
			get
			{
				if (Size != TrapSize.Large)
				{
					if (Size != TrapSize.Medium)
					{
						return 1f;
					}
					return 1.2f;
				}
				return 1.5f;
			}
		}

		public string Summary()
		{
			string text = ((!Lethal) ? (HighChance ? "Non-lethal. Catches often, but only holds the animal briefly." : "Non-lethal. Rarely springs, but holds the animal for a day and tames it much faster.") : (HighChance ? "Lethal. Catches often, but spoils half the loot." : "Lethal. Rarely springs, but a clean kill yields extra loot."));
			string text2 = ((Size == TrapSize.Small) ? "small game (hares, fowl, necks, young)" : ((Size == TrapSize.Medium) ? "medium game (deer, boar, wolves)" : "large game (lox, bears)"));
			return Description + "\nFor " + text2 + ".\n" + text;
		}
	}
	internal class TrapParts
	{
		public Transform Static;

		public Transform Armed;

		public Transform Sprung;

		public GameObject Stakes;
	}
	internal static class TrapModels
	{
		private static readonly Color Wood = new Color(0.45f, 0.3f, 0.17f);

		private static readonly Color DarkWood = new Color(0.3f, 0.2f, 0.11f);

		private static readonly Color Rope = new Color(0.68f, 0.58f, 0.4f);

		private static readonly Color Stone = new Color(0.45f, 0.45f, 0.43f);

		private static readonly Color Pit = new Color(0.07f, 0.05f, 0.03f);

		private static readonly Color Leaves = new Color(0.28f, 0.36f, 0.16f);

		private static readonly Color BaitRed = new Color(0.62f, 0.12f, 0.1f);

		private static readonly Color Flint = new Color(0.25f, 0.27f, 0.3f);

		public const string BaitName = "pf_bait";

		public static TrapParts Groups(Transform root, GameObject stakes)
		{
			return new TrapParts
			{
				Static = Group(root, "pf_static"),
				Armed = Group(root, "pf_armed"),
				Sprung = Group(root, "pf_sprung"),
				Stakes = stakes
			};
		}

		private static Transform Group(Transform root, string name)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root, false);
			return val.transform;
		}

		public static void TwineSnare(TrapParts p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			Cyl(p.Static, new Vector3(0.35f, 0.2f, 0f), 0.025f, 0.4f, DarkWood);
			Cyl(p.Armed, new Vector3(0.2f, 0.3f, 0f), 0.015f, 0.6f, Wood, new Vector3(0f, 0f, 60f));
			Ring(p.Armed, new Vector3(0f, 0.03f, 0f), 0.15f, 8, 0.012f, Rope);
			Cyl(p.Sprung, new Vector3(0.3f, 0.5f, 0f), 0.015f, 0.6f, Wood, new Vector3(0f, 0f, 10f));
			Ring(p.Sprung, new Vector3(0.25f, 0.65f, 0f), 0.06f, 8, 0.012f, Rope);
			Bait(p.Armed, new Vector3(0f, 0.03f, 0.05f));
		}

		public static void FigureFourDeadfall(TrapParts p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_007d: 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_00a7: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			Box(p.Armed, new Vector3(0f, 0.22f, 0f), new Vector3(0.6f, 0.07f, 0.5f), Stone, new Vector3(25f, 0f, 0f));
			Cyl(p.Armed, new Vector3(0f, 0.12f, 0.1f), 0.012f, 0.25f, Wood);
			Cyl(p.Armed, new Vector3(0f, 0.2f, 0.05f), 0.01f, 0.25f, Wood, new Vector3(60f, 0f, 0f));
			Cyl(p.Armed, new Vector3(0f, 0.06f, 0f), 0.01f, 0.3f, Wood, new Vector3(90f, 0f, 0f));
			Bait(p.Armed, new Vector3(0f, 0.03f, -0.05f));
			Box(p.Sprung, new Vector3(0f, 0.04f, 0f), new Vector3(0.6f, 0.07f, 0.5f), Stone);
			Cyl(p.Sprung, new Vector3(0.2f, 0.02f, 0.3f), 0.01f, 0.25f, Wood, new Vector3(90f, 30f, 0f));
		}

		public static void BoxTrap(TrapParts p)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(0.5f, 0.4f, 0.75f);
			Box(p.Static, new Vector3((0f - val.x) / 2f, val.y / 2f, 0f), new Vector3(0.03f, val.y, val.z), Wood);
			Box(p.Static, new Vector3(val.x / 2f, val.y / 2f, 0f), new Vector3(0.03f, val.y, val.z), Wood);
			Box(p.Static, new Vector3(0f, val.y, 0f), new Vector3(val.x + 0.03f, 0.03f, val.z), Wood);
			Box(p.Static, new Vector3(0f, val.y / 2f, (0f - val.z) / 2f), new Vector3(val.x, val.y, 0.03f), Wood);
			Box(p.Armed, new Vector3(0f, val.y + 0.2f, val.z / 2f), new Vector3(val.x, val.y, 0.03f), DarkWood);
			Cyl(p.Armed, new Vector3(0f, val.y * 0.5f, val.z / 2f - 0.05f), 0.01f, val.y, Wood);
			Bait(p.Armed, new Vector3(0f, 0.03f, -0.15f));
			Box(p.Sprung, new Vector3(0f, val.y / 2f, val.z / 2f), new Vector3(val.x, val.y, 0.03f), DarkWood);
		}

		public static void WickerCage(TrapParts p)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_0052: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 12; i++)
			{
				if (i != 0 && i != 1)
				{
					float num = (float)i * (float)Math.PI * 2f / 12f;
					Cyl(p.Static, new Vector3(Mathf.Sin(num) * 0.4f, 0.3f, Mathf.Cos(num) * 0.4f), 0.012f, 0.6f, Wood);
				}
			}
			Ring(p.Static, new Vector3(0f, 0.6f, 0f), 0.4f, 16, 0.015f, Rope);
			Ring(p.Static, new Vector3(0f, 0.02f, 0f), 0.4f, 16, 0.015f, Rope);
			Bait(p.Armed, new Vector3(0f, 0.03f, 0f));
			Cyl(p.Armed, new Vector3(0.15f, 0.85f, 0.4f), 0.012f, 0.5f, Wood, new Vector3(0f, 0f, 70f));
			for (int j = 0; j < 2; j++)
			{
				float num2 = (float)j * (float)Math.PI * 2f / 12f;
				Cyl(p.Sprung, new Vector3(Mathf.Sin(num2) * 0.4f, 0.3f, Mathf.Cos(num2) * 0.4f), 0.012f, 0.6f, DarkWood);
			}
		}

		public static void SpikedPit(TrapParts p)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			PitHole(p.Static, 1.6f);
			StoneRim(p.Static, 0.85f, 10);
			Cover(p.Armed, 1.6f);
			Stakes(p.Sprung, p.Stakes, Vector3.zero, 0.35f);
		}

		public static void SpringSpear(TrapParts p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0083: 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_00a6: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			Cyl(p.Static, new Vector3(-0.7f, 0.5f, 0f), 0.05f, 1f, DarkWood);
			Cyl(p.Static, new Vector3(0.7f, 0.5f, -0.6f), 0.05f, 1f, DarkWood);
			Cyl(p.Armed, new Vector3(0f, 0.15f, 0f), 0.006f, 1.4f, Rope, new Vector3(0f, 0f, 90f));
			Spear(p.Armed, new Vector3(-0.7f, 0.6f, -0.4f), new Vector3(0f, 0f, 0f));
			Spear(p.Sprung, new Vector3(-0.1f, 0.6f, 0.1f), new Vector3(0f, 0f, 0f));
		}

		public static void NetTrap(TrapParts p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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)
			Cyl(p.Static, new Vector3(0.9f, 1f, 0f), 0.05f, 2f, DarkWood);
			Cyl(p.Static, new Vector3(0.45f, 1.95f, 0f), 0.03f, 1f, Wood, new Vector3(0f, 0f, 80f));
			Net(p.Armed, 1.4f);
			Cyl(p.Armed, new Vector3(0.45f, 1f, 0f), 0.005f, 1.9f, Rope, new Vector3(0f, 0f, 25f));
			Visuals.Part(p.Sprung, (PrimitiveType)0, new Vector3(0f, 0.6f, 0f), new Vector3(1f, 1.1f, 1f), Rope);
			Cyl(p.Sprung, new Vector3(0f, 1.6f, 0f), 0.006f, 0.8f, Rope);
		}

		public static void Pitfall(TrapParts p)
		{
			PitHole(p.Static, 1.6f);
			LogRim(p.Static, 1.6f, 0.08f);
			Cover(p.Armed, 1.6f);
		}

		public static void StakeField(TrapParts p)
		{
			//IL_0042: 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)
			for (int i = 0; i < 3; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / 3f;
				Stakes(p.Static, p.Stakes, new Vector3(Mathf.Sin(num) * 1.1f, 0f, Mathf.Cos(num) * 1.1f), 0.6f, (float)i * 120f + 180f);
			}
			PitHole(p.Static, 1.8f);
			Cover(p.Armed, 1.8f);
			Stakes(p.Sprung, p.Stakes, Vector3.zero, 0.55f);
		}

		public static void LogDeadfall(TrapParts p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0083: 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_00a6: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			Cyl(p.Static, new Vector3(-1.5f, 1.3f, 0f), 0.09f, 2.6f, DarkWood);
			Cyl(p.Static, new Vector3(1.5f, 1.3f, 0f), 0.09f, 2.6f, DarkWood);
			Cyl(p.Static, new Vector3(0f, 2.55f, 0f), 0.06f, 3.1f, Wood, new Vector3(0f, 0f, 90f));
			Cyl(p.Armed, new Vector3(0f, 2.2f, 0f), 0.35f, 2.9f, Wood, new Vector3(0f, 0f, 90f));
			Cyl(p.Armed, new Vector3(0f, 1.2f, 0f), 0.006f, 2f, Rope);
			Bait(p.Armed, new Vector3(0f, 0.04f, 0.2f), 2f);
			Cyl(p.Sprung, new Vector3(0f, 0.35f, 0f), 0.35f, 2.9f, Wood, new Vector3(0f, 0f, 90f));
		}

		public static void HeavySnare(TrapParts p)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Cyl(p.Static, new Vector3(1.6f, 0.6f, 0f), 0.12f, 1.2f, DarkWood);
			Cyl(p.Armed, new Vector3(1.3f, 0.05f, 0f), 0.025f, 0.7f, Rope, new Vector3(0f, 0f, 88f));
			Ring(p.Armed, new Vector3(0f, 0.05f, 0f), 1f, 20, 0.03f, Rope);
			Ring(p.Sprung, new Vector3(0f, 0.8f, 0f), 0.4f, 14, 0.03f, Rope);
			Cyl(p.Sprung, new Vector3(0.95f, 0.7f, 0f), 0.025f, 1.3f, Rope, new Vector3(0f, 0f, 80f));
		}

		public static void TimberPitfall(TrapParts p)
		{
			PitHole(p.Static, 2.8f);
			LogRim(p.Static, 2.8f, 0.14f);
			Cover(p.Armed, 2.8f);
		}

		private static void PitHole(Transform parent, float diameter)
		{
			//IL_0011: 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)
			Visuals.Part(parent, (PrimitiveType)2, new Vector3(0f, 0.01f, 0f), new Vector3(diameter, 0.01f, diameter), Pit);
		}

		private static void Cover(Transform parent, float diameter)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 6; i++)
			{
				Cyl(parent, new Vector3(0f, 0.04f, 0f), 0.02f, diameter * 1.05f, Wood, new Vector3(90f, (float)i * 30f, 0f));
			}
			Random random = new Random((int)(diameter * 1000f));
			for (int j = 0; j < 18; j++)
			{
				float num = (float)random.NextDouble() * (float)Math.PI * 2f;
				float num2 = Mathf.Sqrt((float)random.NextDouble()) * diameter * 0.45f;
				Box(parent, new Vector3(Mathf.Cos(num) * num2, 0.06f, Mathf.Sin(num) * num2), new Vector3(0.25f, 0.015f, 0.18f), Leaves, new Vector3(0f, num * 57.29578f, 0f));
			}
		}

		private static void StoneRim(Transform parent, float radius, int count)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < count; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / (float)count;
				Visuals.Part(parent, (PrimitiveType)0, new Vector3(Mathf.Sin(num) * radius, 0.05f, Mathf.Cos(num) * radius), new Vector3(0.22f, 0.14f, 0.18f), Stone, shadows: true);
			}
		}

		private static void LogRim(Transform parent, float diameter, float logRadius)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			float num = diameter / 2f + logRadius;
			Cyl(parent, new Vector3(0f, logRadius, num), logRadius, diameter + logRadius * 2f, DarkWood, new Vector3(0f, 0f, 90f));
			Cyl(parent, new Vector3(0f, logRadius, 0f - num), logRadius, diameter + logRadius * 2f, DarkWood, new Vector3(0f, 0f, 90f));
			Cyl(parent, new Vector3(num, logRadius, 0f), logRadius, diameter + logRadius * 2f, DarkWood, new Vector3(90f, 0f, 0f));
			Cyl(parent, new Vector3(0f - num, logRadius, 0f), logRadius, diameter + logRadius * 2f, DarkWood, new Vector3(90f, 0f, 0f));
		}

		private static void Net(Transform parent, float size)
		{
			//IL_0023: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0073: 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)
			int num = 6;
			for (int i = 0; i <= num; i++)
			{
				float num2 = (0f - size) / 2f + size * (float)i / (float)num;
				Box(parent, new Vector3(num2, 0.02f, 0f), new Vector3(0.012f, 0.012f, size), Rope);
				Box(parent, new Vector3(0f, 0.02f, num2), new Vector3(size, 0.012f, 0.012f), Rope);
			}
		}

		private static void Spear(Transform parent, Vector3 pos, Vector3 euler)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0076: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("spear");
			val.transform.SetParent(parent, false);
			val.transform.localPosition = pos;
			val.transform.localEulerAngles = euler;
			Cyl(val.transform, Vector3.zero, 0.025f, 1.4f, Wood, new Vector3(90f, 0f, 0f));
			Box(val.transform, new Vector3(0f, 0f, 0.75f), new Vector3(0.06f, 0.02f, 0.16f), Flint, new Vector3(0f, 45f, 0f));
		}

		private static void Stakes(Transform parent, GameObject stakes, Vector3 pos, float scale, float yaw = 0f)
		{
			//IL_0025: 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_0041: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_0068: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			for (int i = 0; i < 7; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / 7f + yaw * ((float)Math.PI / 180f);
				Vector3 val = pos + new Vector3(Mathf.Sin(num), 0f, Mathf.Cos(num)) * 0.4f * scale * 2f;
				Cyl(parent, val + Vector3.up * 0.35f * scale * 2f, 0.03f, 0.7f * scale * 2f, Wood, new Vector3(15f * Mathf.Cos(num), 0f, -15f * Mathf.Sin(num)));
			}
		}

		public static void Bait(Transform parent, Vector3 pos, float scale = 1f)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			GameObject val = new GameObject("pf_bait");
			val.transform.SetParent(parent, false);
			for (int i = 0; i < 3; i++)
			{
				Visuals.Part(val.transform, (PrimitiveType)0, pos + new Vector3((float)i * 0.035f * scale - 0.035f * scale, 0f, (float)(i % 2) * 0.03f * scale), Vector3.one * 0.04f * scale, BaitRed);
			}
			val.SetActive(false);
		}

		private static void Box(Transform parent, Vector3 pos, Vector3 size, Color c, Vector3 euler = default(Vector3))
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: 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_000b: Unknown result type (might be due to invalid IL or missing references)
			Visuals.Part(parent, (PrimitiveType)3, pos, size, Quaternion.Euler(euler), c, shadows: true);
		}

		private static void Cyl(Transform parent, Vector3 pos, float radius, float height, Color c, Vector3 euler = default(Vector3))
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			Visuals.Part(parent, (PrimitiveType)2, pos, new Vector3(radius * 2f, height / 2f, radius * 2f), Quaternion.Euler(euler), c, shadows: true);
		}

		private static void Ring(Transform parent, Vector3 centre, float radius, int segments, float thickness, Color c)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0054: 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)
			float num = (float)Math.PI * 2f * radius / (float)segments * 1.1f;
			for (int i = 0; i < segments; i++)
			{
				float num2 = (float)i * (float)Math.PI * 2f / (float)segments;
				Vector3 pos = centre + new Vector3(Mathf.Sin(num2) * radius, 0f, Mathf.Cos(num2) * radius);
				Box(parent, pos, new Vector3(num, thickness, thickness), c, new Vector3(0f, num2 * 57.29578f, 0f));
			}
		}
	}
	internal static class TrapRegistry
	{
		public const string Category = "Traps";

		private const string BasePiece = "piece_sharpstakes";

		private const string EffectsPiece = "woodwall";

		public static readonly Dictionary<string, TrapDefinition> Definitions;

		static TrapRegistry()
		{
			Definitions = new Dictionary<string, TrapDefinition>();
			Def("pf_trap_snare", "Small Twine Snare", "A noose on a bent sapling.", TrapSize.Small, true, true, TrapModels.TwineSnare, ("Wood", 2), ("LeatherScraps", 1));
			Def("pf_trap_deadfall_small", "Small Figure-Four Deadfall", "A flat stone propped on a figure-four trigger.", TrapSize.Small, true, false, TrapModels.FigureFourDeadfall, ("Wood", 3), ("Stone", 4));
			Def("pf_trap_box", "Small Box Trap", "A wooden box with a drop door.", TrapSize.Small, false, true, TrapModels.BoxTrap, ("Wood", 6));
			Def("pf_trap_cage", "Small Wicker Cage", "A woven cage with a baited gate.", TrapSize.Small, false, false, TrapModels.WickerCage, ("Wood", 8), ("Resin", 2));
			Def("pf_trap_spikedpit", "Medium Spiked Pit", "A covered pit lined with stakes.", TrapSize.Medium, true, true, TrapModels.SpikedPit, ("Wood", 8), ("Stone", 6));
			Def("pf_trap_spear", "Medium Spring Spear Trap", "A tripwire that releases a flint-tipped spear.", TrapSize.Medium, true, false, TrapModels.SpringSpear, ("Wood", 6), ("Flint", 4), ("LeatherScraps", 2));
			Def("pf_trap_net", "Medium Net Trap", "A net that snaps up into a tree.", TrapSize.Medium, false, true, TrapModels.NetTrap, ("Wood", 4), ("LeatherScraps", 6));
			Def("pf_trap_pitfall", "Medium Pitfall", "A deep covered pit with a log rim.", TrapSize.Medium, false, false, TrapModels.Pitfall, ("Wood", 10), ("Stone", 4));
			Def("pf_trap_stakefield", "Large Stake Field", "Hidden stakes around a covered pit.", TrapSize.Large, true, true, TrapModels.StakeField, ("Wood", 16), ("Stone", 8));
			Def("pf_trap_logdeadfall", "Large Log Deadfall", "A heavy log hung over a bait trigger.", TrapSize.Large, true, false, TrapModels.LogDeadfall, ("RoundLog", 6), ("Wood", 8), ("Stone", 6));
			Def("pf_trap_heavysnare", "Large Heavy Snare", "A thick rope noose anchored to a stout post.", TrapSize.Large, false, true, TrapModels.HeavySnare, ("Wood", 10), ("DeerHide", 4), ("LeatherScraps", 6));
			Def("pf_trap_timberpit", "Large Timber Pitfall", "A huge pit braced with timbers.", TrapSize.Large, false, false, TrapModels.TimberPitfall, ("RoundLog", 10), ("Wood", 10), ("Stone", 10));
		}

		private static void Def(string prefab, string name, string desc, TrapSize size, bool lethal, bool highChance, Action<TrapParts> build, params (string, int)[] cost)
		{
			Definitions[prefab] = new TrapDefinition
			{
				Prefab = prefab,
				Name = name,
				Description = desc,
				Size = size,
				Lethal = lethal,
				HighChance = highChance,
				Cost = cost,
				Build = delegate(Transform root)
				{
					//IL_004e: Unknown result type (might be due to invalid IL or missing references)
					TrapParts trapParts = TrapModels.Groups(root, PrefabManager.Instance.GetPrefab("piece_sharpstakes"));
					build(trapParts);
					if (!Object.op_Implicit((Object)(object)trapParts.Armed.Find("pf_bait")))
					{
						TrapModels.Bait(trapParts.Armed, new Vector3(0f, 0.08f, 0f), (size == TrapSize.Large) ? 2f : ((size == TrapSize.Medium) ? 1.5f : 1f));
					}
				}
			};
		}

		public static void CreatePieces()
		{
			if (!PfConfig.TrapsEnabled.Value)
			{
				return;
			}
			GameObject prefab = PrefabManager.Instance.GetPrefab("piece_sharpstakes");
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				Plugin.Log.LogError((object)"piece_sharpstakes not found, traps are disabled");
				return;
			}
			foreach (TrapDefinition value in Definitions.Values)
			{
				try
				{
					CreatePiece(value, prefab);
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"Failed to create {value.Prefab}: {arg}");
				}
			}
		}

		private static void CreatePiece(TrapDefinition def, GameObject basePrefab)
		{
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_027d: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Expected O, but got Unknown
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = PrefabManager.Instance.CreateClonedPrefab(def.Prefab, basePrefab);
			Aoe[] componentsInChildren = val.GetComponentsInChildren<Aoe>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
			}
			Collider[] componentsInChildren2 = val.GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren2[i]);
			}
			Renderer[] componentsInChildren3 = val.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren3.Length; i++)
			{
				componentsInChildren3[i].enabled = false;
			}
			def.Build(val.transform);
			((Component)val.transform.Find("pf_sprung")).gameObject.SetActive(false);
			int layer = LayerMask.NameToLayer("piece_nonsolid");
			Transform[] componentsInChildren4 = val.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				((Component)componentsInChildren4[i]).gameObject.layer = layer;
			}
			BoxCollider obj = val.AddComponent<BoxCollider>();
			obj.size = new Vector3(def.Footprint, 0.4f, def.Footprint);
			obj.center = new Vector3(0f, 0.2f, 0f);
			Piece component = val.GetComponent<Piece>();
			component.m_groundOnly = true;
			component.m_noInWater = true;
			WearNTear component2 = val.GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.m_noRoofWear = true;
				component2.m_noSupportWear = true;
				component2.m_fragmentRoots = null;
				GameObject prefab = PrefabManager.Instance.GetPrefab("woodwall");
				WearNTear val2 = ((prefab != null) ? prefab.GetComponent<WearNTear>() : null);
				if (Object.op_Implicit((Object)(object)val2))
				{
					component2.m_destroyedEffect = val2.m_destroyedEffect;
					component2.m_hitEffect = val2.m_hitEffect;
				}
			}
			val.AddComponent<HuntingTrap>().m_definition = def.Prefab;
			PieceConfig val3 = new PieceConfig
			{
				Name = def.Name,
				Description = def.Summary(),
				PieceTable = "Hammer",
				Category = "Traps",
				CraftingStation = "piece_workbench"
			};
			(string, int)[] cost = def.Cost;
			for (int i = 0; i < cost.Length; i++)
			{
				var (text, num) = cost[i];
				val3.AddRequirement(text, num, true);
			}
			try
			{
				val3.Icon = RenderManager.Instance.Render(val, RenderManager.IsometricRotation);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not render icon for " + def.Prefab + ": " + ex.Message));
			}
			PieceManager.Instance.AddPiece(new CustomPiece(val, false, val3));
		}
	}
	internal class TrapVictim : MonoBehaviour
	{
		public static readonly int s_dropMult = StringExtensionMethods.GetStableHashCode("pf_dropMult");

		private static readonly int s_heldUntil = StringExtensionMethods.GetStableHashCode("pf_heldUntil");

		private static readonly int s_heldPos = StringExtensionMethods.GetStableHashCode("pf_heldPos");

		private static readonly int s_tameMult = StringExtensionMethods.GetStableHashCode("pf_tameMult");

		private static readonly List<HuntingTrap> s_hits = new List<HuntingTrap>();

		private Character m_character;

		private BaseAI m_ai;

		private ZNetView m_nview;

		private Tameable m_tameable;

		private TrapSize m_size;

		private float m_nextCheck;

		private float m_nextTame;

		private readonly Dictionary<HuntingTrap, float> m_cooldown = new Dictionary<HuntingTrap, float>();

		public bool IsHeld
		{
			get
			{
				if (Object.op_Implicit((Object)(object)m_nview) && m_nview.IsValid())
				{
					return GameTime.NowTicks < m_nview.GetZDO().GetLong(s_heldUntil, 0L);
				}
				return false;
			}
		}

		private void Awake()
		{
			m_character = ((Component)this).GetComponent<Character>();
			m_ai = ((Component)this).GetComponent<BaseAI>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_tameable = ((Component)this).GetComponent<Tameable>();
			m_size = Species.SizeOf(Utils.GetPrefabName(((Component)this).gameObject));
			if (Object.op_Implicit((Object)(object)m_nview) && m_nview.GetZDO() != null)
			{
				m_nview.Register<float>("PF_TrapKill", (Action<long, float>)RPC_Kill);
				m_nview.Register<long, float, Vector3>("PF_TrapHold", (Action<long, long, float, Vector3>)RPC_Hold);
				m_nview.Register("PF_TrapRelease", (Action<long>)RPC_Release);
			}
		}

		public void Kill(float dropMultiplier)
		{
			m_nview.InvokeRPC("PF_TrapKill", new object[1] { dropMultiplier });
		}

		public void Hold(ZDOID trap, long until, float tameMult, Vector3 pos)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			m_nview.InvokeRPC("PF_TrapHold", new object[3] { until, tameMult, pos });
		}

		public void Release()
		{
			m_nview.InvokeRPC("PF_TrapRelease", Array.Empty<object>());
		}

		private void RPC_Kill(long sender, float mult)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (m_nview.IsOwner() && !m_character.IsDead())
			{
				m_nview.GetZDO().Set(s_dropMult, mult);
				HitData val = new HitData();
				val.m_damage.m_damage = m_character.GetMaxHealth() * 10f + 1000f;
				val.m_point = m_character.GetCenterPoint();
				val.m_dir = Vector3.down;
				m_character.Damage(val);
			}
		}

		private void RPC_Hold(long sender, long until, float tameMult, Vector3 pos)
		{
			//IL_002b: 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)
			if (m_nview.IsOwner())
			{
				ZDO zDO = m_nview.GetZDO();
				zDO.Set(s_heldUntil, until);
				zDO.Set(s_heldPos, pos);
				zDO.Set(s_tameMult, tameMult);
				((Component)this).transform.position = pos;
				((Component)this).GetComponent<RoamingBrain>()?.ClearLure();
			}
		}

		private void RPC_Release(long sender)
		{
			if (m_nview.IsOwner())
			{
				m_nview.GetZDO().Set(s_heldUntil, 0L);
			}
		}

		private void Update()
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < m_nextCheck || m_size == TrapSize.None || !PfConfig.TrapsEnabled.Value)
			{
				return;
			}
			m_nextCheck = Time.time + 0.5f;
			if (!Object.op_Implicit((Object)(object)m_nview) || !m_nview.IsValid() || !m_nview.IsOwner() || m_character.IsDead() || m_character.IsTamed() || IsHeld)
			{
				return;
			}
			HuntingTrap.FindTriggering(m_size, ((Component)this).transform.position, s_hits);
			foreach (HuntingTrap s_hit in s_hits)
			{
				if (!m_cooldown.TryGetValue(s_hit, out var value) || !(Time.time < value))
				{
					m_cooldown[s_hit] = Time.time + 30f;
					s_hit.RequestTrigger(m_character);
					((Component)this).GetComponent<RoamingBrain>()?.ClearLure();
					break;
				}
			}
		}

		public void HeldUpdate(float dt)
		{
			//IL_0018: 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_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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			ZDO zDO = m_nview.GetZDO();
			Vector3 vec = zDO.GetVec3(s_heldPos, ((Component)this).transform.position);
			BaseAI ai = m_ai;
			MonsterAI val = (MonsterAI)(object)((ai is MonsterAI) ? ai : null);
			Character character = m_character;
			Humanoid val2 = (Humanoid)(object)((character is Humanoid) ? character : null);
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || !val.UpdateConsumeItem(val2, dt))
			{
				m_ai.StopMoving();
			}
			if (m_ai.IsAlerted())
			{
				m_ai.SetAlerted(false);
			}
			if (Utils.DistanceXZ(((Component)this).transform.position, vec) > 0.6f)
			{
				((Component)this).transform.position = new Vector3(vec.x, ((Component)this).transform.position.y, vec.z);
				if (Object.op_Implicit((Object)(object)m_character.m_body))
				{
					m_character.m_body.linearVelocity = Vector3.zero;
				}
			}
			if (!Object.op_Implicit((Object)(object)m_tameable) || m_character.IsTamed() || !(Time.time >= m_nextTame))
			{
				return;
			}
			m_nextTame = Time.time + 3f;
			float num = zDO.GetFloat(s_tameMult, 1f);
			if (num > 1f && !m_tameable.IsHungry())
			{
				m_tameable.DecreaseRemainingTime(3f * (num - 1f));
				if (m_tameable.GetRemainingTime() <= 0f)
				{
					m_tameable.Tame();
				}
			}
		}
	}
}
namespace ValheimPathfinder.Trails
{
	internal static class FrequencyTrails
	{
		private class Cell
		{
			public int Count;

			public double LastVisit;

			public bool Done;
		}

		private static readonly Dictionary<long, Cell> s_cells = new Dictionary<long, Cell>();

		private static double s_nextPrune;

		private static readonly List<long> s_stale = new List<long>();

		public static long Key(Vector3 pos, out Vector2Int cell)
		{
			//IL_0016: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Max(0.5f, PfConfig.TrailCellSize.Value);
			cell = new Vector2Int(Mathf.FloorToInt(pos.x / num), Mathf.FloorToInt(pos.z / num));
			return ((long)((Vector2Int)(ref cell)).x << 32) ^ (uint)((Vector2Int)(ref cell)).y;
		}

		public static void Step(Vector3 pos)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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)
			if (!PfConfig.TrailsEnabled.Value || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return;
			}
			double nowSeconds = GameTime.NowSeconds;
			double num = PfConfig.TrailDecayDays.Value * GameTime.DayLength;
			Vector2Int cell;
			long key = Key(pos, out cell);
			if (!s_cells.TryGetValue(key, out var value))
			{
				value = new Cell();
				s_cells[key] = value;
			}
			if (value.Done)
			{
				return;
			}
			if (value.Count > 0 && nowSeconds - value.LastVisit > num)
			{
				value.Count = 0;
			}
			if (value.Count > 0 && nowSeconds - value.LastVisit < (double)PfConfig.MinSecondsBetweenVisits.Value)
			{
				return;
			}
			value.Count++;
			value.LastVisit = nowSeconds;
			if (value.Count >= PfConfig.StepsToPath.Value)
			{
				value.Done = true;
				if (TrailPainter.CanPaint(pos))
				{
					TrailPainter.Paint(pos);
					RavenTips.PathFormed(pos);
				}
			}
			if (nowSeconds > s_nextPrune)
			{
				s_nextPrune = nowSeconds + 300.0;
				Prune(nowSeconds, num);
			}
		}

		private static void Prune(double now, double decay)
		{
			s_stale.Clear();
			foreach (KeyValuePair<long, Cell> s_cell in s_cells)
			{
				if (!s_cell.Value.Done && now - s_cell.Value.LastVisit > decay)
				{
					s_stale.Add(s_cell.Key);
				}
			}
			foreach (long item in s_stale)
			{
				s_cells.Remove(item);
			}
		}
	}
	internal class TrailWalker : MonoBehaviour
	{
		private Character m_character;

		private ZNetView m_nview;

		private long m_lastCell = long.MinValue;

		private float m_nextCheck;

		private void Start()
		{
			m_character = ((Component)this).GetComponent<Character>();
			m_nview = ((Component)this).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)m_character) || !Object.op_Implicit((Object)(object)m_nview) || m_character.m_flying)
			{
				Object.Destroy((Object)(object)this);
			}
		}

		private void Update()
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < m_nextCheck)
			{
				return;
			}
			m_nextCheck = Time.time + 0.4f;
			if (m_nview.IsValid() && m_nview.IsOwner() && !m_character.IsDead() && m_character.IsOnGround() && !m_character.IsSwimming() && !m_character.InInterior())
			{
				Vector2Int cell;
				long num = FrequencyTrails.Key(((Component)this).transform.position, out cell);
				if (num != m_lastCell)
				{
					m_lastCell = num;
					FrequencyTrails.Step(((Component)this).transform.position);
				}
			}
		}
	}
	internal static class TrailPainter
	{
		public const string OpPrefab = "pf_trail_op";

		private static TerrainOp s_op;

		public static void CreatePrefab()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("pf_trail_op");
			val.transform.SetParent(ClueRegistry.Container, false);
			s_op = val.AddComponent<TerrainOp>();
			Settings settings = s_op.m_settings;
			settings.m_level = false;
			settings.m_raise = false;
			settings.m_smooth = false;
			settings.m_paintCleared = true;
			settings.m_paintType = (PaintType)0;
			settings.m_paintRadius = PfConfig.TrailPaintRadius.Value;
			settings.m_paintStrength = 1f;
			settings.m_paintExp = 0.6f;
			settings.m_paintHeightCheck = false;
			RegisterIn(ObjectDB.instance);
		}

		public static void RegisterIn(ObjectDB db)
		{
			if (Object.op_Implicit((Object)(object)db) && Object.op_Implicit((Object)(object)s_op) && !db.m_terrainOps.Contains(s_op))
			{
				db.m_terrainOps.Add(s_op);
				db.UpdateRegisters();
			}
		}

		public static bool CanPaint(Vector3 pos)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_004c: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)s_op) || pos.y < ZoneSystem.instance.m_waterLevel + 0.2f)
			{
				return false;
			}
			Heightmap val = Heightmap.FindHeightmap(pos);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			Color paintMask = val.GetPaintMask(pos);
			if (paintMask.r > 0.5f || paintMask.g > 0.3f || paintMask.b > 0.5f)
			{
				return false;
			}
			float value = PfConfig.AvoidBuildingsRadius.Value;
			if (value > 0f && Physics.CheckSphere(pos, value, LayerMask.GetMask(new string[2] { "piece", "piece_nonsolid" })))
			{
				return false;
			}
			return true;
		}

		public static void Paint(Vector3 pos)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			s_op.m_settings.m_paintRadius = PfConfig.TrailPaintRadius.Value;
			Object.Instantiate<GameObject>(((Component)s_op).gameObject, pos, Quaternion.identity);
		}

		public static bool IsPath(Vector3 pos)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Heightmap val = Heightmap.FindHeightmap(pos);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			Color paintMask = val.GetPaintMask(pos);
			if (!(paintMask.r > 0.5f))
			{
				return paintMask.b > 0.5f;
			}
			return true;
		}
	}
	[HarmonyPatch]
	internal static class ObjectDBPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static void Awake(ObjectDB __instance)
		{
			TrailPainter.RegisterIn(__instance);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
		private static void CopyOtherDB(ObjectDB __instance)
		{
			TrailPainter.RegisterIn(__instance);
		}
	}
	internal static class TreeMarks
	{
		private class MarkMaterial
		{
			public string Prefab;

			public string Label;

			public Color Color;
		}

		private struct Stripe
		{
			public int Mat;

			public Vector3 LocalPos;

			public Vector3 LocalNormal;

			public int Row;
		}

		private static readonly MarkMaterial[] s_materials = new MarkMaterial[7]
		{
			new MarkMaterial
			{
				Prefab = "Coal",
				Label = "coal (black)",
				Color = new Color(0.06f, 0.06f, 0.06f)
			},
			new MarkMaterial
			{
				Prefab = "BoneFragments",
				Label = "bone (white)",
				Color = new Color(0.92f, 0.9f, 0.85f)
			},
			new MarkMaterial
			{
				Prefab = "Mushroom",
				Label = "red mushroom (red)",
				Color = new Color(0.75f, 0.1f, 0.08f)
			},
			new MarkMaterial
			{
				Prefab = "MushroomYellow",
				Label = "yellow mushroom (yellow)",
				Color = new Color(0.9f, 0.75f, 0.1f)
			},
			new MarkMaterial
			{
				Prefab = "MushroomBlue",
				Label = "blue mushroom (blue)",
				Color = new Color(0.15f, 0.35f, 0.85f)
			},
			new MarkMaterial
			{
				Prefab = "Dandelion",
				Label = "dandelion (yellow)",
				Color = new Color(1f, 0.85f, 0.2f)
			},
			new MarkMaterial
			{
				Prefab = "Thistle",
				Label = "thistle (purple)",
				Color = new Color(0.5f, 0.2f, 0.6f)
			}
		};

		private const int MaxStripes = 3;

		private const float StripeWidth = 0.07f;

		private const float StripeHeight = 0.3f;

		private const float StripePitch = 0.085f;

		private const float MaxDistance = 3.5f;

		private const string RpcName = "PF_MarkChanged";

		private const string ChildName = "pf_marks";

		public static readonly int s_marks = StringExtensionMethods.GetStableHashCode("pf_marks");

		private static int s_selected = -1;

		private static ZRoutedRpc s_rpcFor;

		private static bool s_chatFocusedLastFrame;

		private static float s_nextTipCheck;

		private const string MarksMadeKey = "pf_marksMade";

		private const int HintedMarks = 3;

		public static void UpdateInput()
		{
			//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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			RegisterRpc();
			int num;
			int num2;
			if (Object.op_Implicit((Object)(object)Chat.instance))
			{
				num = (Chat.instance.HasFocus() ? 1 : 0);
				if (num != 0)
				{
					num2 = 1;
					goto IL_0029;
				}
			}
			else
			{
				num = 0;
			}
			num2 = (s_chatFocusedLastFrame ? 1 : 0);
			goto IL_0029;
			IL_0029:
			bool flag = (byte)num2 != 0;
			s_chatFocusedLastFrame = (byte)num != 0;
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)localPlayer) || !PfConfig.MarksEnabled.Value)
			{
				return;
			}
			if (Time.time >= s_nextTipCheck)
			{
				s_nextTipCheck = Time.time + 3f;
				if (!localPlayer.HaveSeenTutorial("pf_tip_marking") && FirstCarried(localPlayer, out var _) != null)
				{
					RavenTips.Show("pf_tip_marking");
				}
			}
			if (flag || BlockedByUi(localPlayer))
			{
				return;
			}
			KeyboardShortcut value = PfConfig.CycleMarkKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				Cycle(localPlayer);
				return;
			}
			value = PfConfig.MarkKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				TryMark(localPlayer);
			}
		}

		private static bool BlockedByUi(Player player)
		{
			if (!InventoryGui.IsVisible() && !Menu.IsVisible() && !Minimap.IsOpen() && !TextInput.IsVisible() && !Console.IsVisible() && !StoreGui.IsVisible() && !((Character)player).InPlaceMode() && !((Character)player).IsDead() && !((Character)player).InCutscene())
			{
				return ((Character)player).IsTeleporting();
			}
			return true;
		}

		private static void Cycle(Player player)
		{
			for (int i = s_selected + 1; i < s_materials.Length; i++)
			{
				if (Find(player, s_materials[i]) != null)
				{
					s_selected = i;
					((Character)player).Message((MessageType)1, "Marking with " + s_materials[i].Label, 0, (Sprite)null, false);
					return;
				}
			}
			s_selected = -1;
			int matIdx;
			ItemData val = FirstCarried(player, out matIdx);
			((Character)player).Message((MessageType)1, (val != null) ? ("Marking with the first material in your inventory (now " + s_materials[matIdx].Label + ")") : "Marking with the first material in your inventory", 0, (Sprite)null, false);
		}

		private static ItemData Find(Player player, MarkMaterial mat)
		{
			foreach (ItemData allItem in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (Object.op_Implicit((Object)(object)allItem.m_dropPrefab) && ((Object)allItem.m_dropPrefab).name == mat.Prefab)
				{
					return allItem;
				}
			}
			return null;
		}

		private static ItemData FirstCarried(Player player, out int matIdx)
		{
			matIdx = -1;
			ItemData val = null;
			foreach (ItemData item in ((Humanoid)player).GetInventory().GetAllItems())
			{
				if (Object.op_Implicit((Object)(object)item.m_dropPrefab))
				{
					int num = Array.FindIndex(s_materials, (MarkMaterial m) => m.Prefab == ((Object)item.m_dropPrefab).name);
					if (num >= 0 && (val == null || item.m_gridPos.y < val.m_gridPos.y || (item.m_gridPos.y == val.m_gridPos.y && item.m_gridPos.x < val.m_gridPos.x)))
					{
						val = item;
						matIdx = num;
					}
				}
			}
			return val;
		}

		private static void TryMark(Player player)
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			Transform val = (Object.op_Implicit((Object)(object)GameCamera.instance) ? ((Component)GameCamera.instance).transform : null);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			int mask = LayerMask.GetMask(new string[4] { "Default", "static_solid", "Default_small", "terrain" });
			RaycastHit hit = default(RaycastHit);
			if (!Physics.Raycast(val.position, val.forward, ref hit, 50f, mask) || Vector3.Distance(((Character)player).m_eye.position, ((RaycastHit)(ref hit)).point) > 3.5f)
			{
				return;
			}
			ZNetView val2 = FindMarkable((Component)(object)((RaycastHit)(ref hit)).collider);
			if (Object.op_Implicit((Object)(object)val2) && val2.IsValid())
			{
				int matIdx = s_selected;
				ItemData val3 = ((s_selected >= 0) ? Find(player, s_materials[s_selected]) : null);
				if (val3 == null)
				{
					val3 = FirstCarried(player, out matIdx);
				}
				if (val3 == null)
				{
					((Character)player).Message((MessageType)2, "You need coal, bone, a mushroom, a dandelion or a thistle to make a mark.", 0, (Sprite)null, false);
					return;
				}
				if (!AddStripe(val2, matIdx, hit, val.right))
				{
					((Character)player).Message((MessageType)2, "No room for another stripe there.", 0, (Sprite)null, false);
					return;
				}
				((Humanoid)player).GetInventory().RemoveItem(val3, 1);
				player.m_customData.TryGetValue("pf_marksMade", out var value);
				int.TryParse(value, out var result);
				player.m_customData["pf_marksMade"] = (result + 1).ToString(CultureInfo.InvariantCulture);
				string text = ((result < 3) ? ". Shift + right mouse changes the material" : "");
				((Character)player).Message((MessageType)1, "Marked with " + s_materials[matIdx].Label + text, 0, (Sprite)null, false);
			}
		}

		private static ZNetView FindMarkable(Component col)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Invalid comparison between Unknown and I4
			Component val = (Component)(object)col.GetComponentInParent<TreeBase>();
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = (Component)(object)col.GetComponentInParent<MineRock5>();
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = (Component)(object)col.GetComponentInParent<MineRock>();
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				Destructible componentInParent = col.GetComponentInParent<Destructible>();
				if (Object.op_Implicit((Object)(object)componentInParent) && ((int)componentInParent.m_destructibleType == 2 || ((Object)componentInParent).name.ToLowerInvariant().Contains("rock") || ((Object)componentInParent).name.ToLowerInvariant().Contains("stone")))
				{
					val = (Component)(object)componentInParent;
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			return val.GetComponentInParent<ZNetView>();
		}

		private static bool AddStripe(ZNetView nview, int mat, RaycastHit hit, Vector3 viewRight)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: 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_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)nview).transform;
			List<Stripe> list = Parse(nview.GetZDO().GetString(s_marks, ""));
			Vector3 point = ((RaycastHit)(ref hit)).point;
			Vector3 normal = ((RaycastHit)(ref hit)).normal;
			int row = 0;
			foreach (Stripe item3 in list)
			{
				row = Mathf.Max(row, item3.Row + 1);
			}
			int num = ClickedStripe(list, transform, point, viewRight);
			Vector3 val;
			if (num >= 0)
			{
				Stripe stripe = list[num];
				row = stripe.Row;
				if (list.Count >= 3)
				{
					int num2 = list.FindIndex((Stripe s) => s.Row != row);
					if (num2 < 0)
					{
						Stripe item = list[0];
						list.RemoveAt(0);
						item.Mat = mat;
						list.Add(item);
						return Save(nview, list);
					}
					list.RemoveAt(num2);
				}
				Vector3 p = transform.TransformPoint(stripe.LocalPos);
				val = transform.TransformDirection(stripe.LocalNormal);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				if (!FindSlotRight(list, transform, ((RaycastHit)(ref hit)).collider, p, normalized, viewRight, out point, out normal))
				{
					return false;
				}
			}
			Stripe item2 = new Stripe
			{
				Mat = mat,
				LocalPos = transform.InverseTransformPoint(point)
			};
			val = transform.InverseTransformDirection(normal);
			item2.LocalNormal = ((Vector3)(ref val)).normalized;
			item2.Row = row;
			list.Add(item2);
			while (list.Count > 3)
			{
				list.RemoveAt(0);
			}
			return Save(nview, list);
		}

		private static int ClickedStripe(List<Stripe> stripes, Transform root, Vector3 point, Vector3 viewRight)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			for (int num = stripes.Count - 1; num >= 0; num--)
			{
				Vector3 val = root.TransformPoint(stripes[num].LocalPos);
				Vector3 val2 = root.TransformDirection(stripes[num].LocalNormal);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				Vector3 val3 = point - val;
				if (Mathf.Abs(Vector3.Dot(val3, RightOf(normalized, viewRight))) <= 0.052500002f && Mathf.Abs(Vector3.Dot(val3, StripeUp(normalized))) <= 0.15f)
				{
					return num;
				}
			}
			return -1;
		}

		private static bool Save(ZNetView nview, List<Stripe> stripes)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			nview.ClaimOwnership();
			nview.GetZDO().Set(s_marks, Serialize(stripes));
			Refresh(nview);
			if (ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PF_MarkChanged", new object[1] { nview.GetZDO().m_uid });
			}
			return true;
		}

		private static bool FindSlotRight(List<Stripe> stripes, Transform root, Collider col, Vector3 p, Vector3 n, Vector3 viewRight, out Vector3 point, out Vector3 normal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_0004: 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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00d2: 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_0041: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0074: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = p;
			Vector3 val2 = n;
			RaycastHit val5 = default(RaycastHit);
			for (int i = 0; i <= 3; i++)
			{
				val += RightOf(val2, viewRight) * 0.085f;
				Vector3 val3 = Vector3.ProjectOnPlane(val2, Vector3.up);
				val3 = ((((Vector3)(ref val3)).sqrMagnitude < 0.01f) ? val2 : ((Vector3)(ref val3)).normalized);
				Vector3 val4 = new Vector3(val.x, p.y, val.z) + val3 * 0.3f;
				if (!col.Raycast(new Ray(val4, -val3), ref val5, 0.6f))
				{
					break;
				}
				val = ((RaycastHit)(ref val5)).point;
				val2 = ((RaycastHit)(ref val5)).normal;
				if (!Occupied(stripes, root, val))
				{
					point = val;
					normal = val2;
					return true;
				}
			}
			point = p;
			normal = n;
			return false;
		}

		private static Vector3 RightOf(Vector3 normal, Vector3 viewRight)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//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_000b: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.ProjectOnPlane(normal, Vector3.up);
			Vector3 val2 = ((((Vector3)(ref val)).sqrMagnitude < 0.01f) ? Vector3.ProjectOnPlane(viewRight, normal) : Vector3.Cross(Vector3.up, val));
			((Vector3)(ref val2)).Normalize();
			if (!(Vector3.Dot(val2, viewRight) < 0f))
			{
				return val2;
			}
			return -val2;
		}

		private static bool Occupied(List<Stripe> stripes, Transform root, Vector3 point)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			foreach (Stripe stripe in stripes)
			{
				if (Vector3.Distance(root.TransformPoint(stripe.LocalPos), point) < 0.07f)
				{
					return true;
				}
			}
			return false;
		}

		private static Vector3 StripeUp(Vector3 normal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_000b: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			Vector3 val = Vector3.ProjectOnPlane(Vector3.up, n