Decompiled source of Fish Attractor And Traps v1.0.0

plugins/FishAttractor.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OctoberJemini.FishAttractor
{
	[BepInPlugin("OctoberJemini.FishAttractor", "Fish Attractor & Traps", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "OctoberJemini.FishAttractor";

		internal static ConfigEntry<float> Interval;

		internal static ConfigEntry<float> FirstDelay;

		internal static ConfigEntry<float> Depth;

		internal static ConfigEntry<int> Capacity;

		internal static ConfigEntry<int> FishLimit;

		internal static ConfigEntry<string> ExtraMeats;

		private GameObject attractor;

		private GameObject trap;

		private bool iconDone;

		private void Awake()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			Interval = ((BaseUnityPlugin)this).Config.Bind<float>("Attraction", "Seconds between fish", 300f, new ConfigDescription("World-time seconds between successful arrivals. No catch-up spawning burst.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 3600f), Array.Empty<object>()));
			FirstDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Attraction", "First fish delay", 60f, new ConfigDescription("Seconds after the first bait is loaded before the first fish can arrive.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(15f, 600f), Array.Empty<object>()));
			FishLimit = ((BaseUnityPlugin)this).Config.Bind<int>("Attraction", "Nearby fish limit", 3, new ConfigDescription("Stops attracting fish when this many fish are within 25 metres. Nearby stations share the same fish count.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()));
			Capacity = ((BaseUnityPlugin)this).Config.Bind<int>("Bait", "Capacity", 20, new ConfigDescription("Maximum pieces of manually loaded raw meat.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			Depth = ((BaseUnityPlugin)this).Config.Bind<float>("Attraction", "Minimum water depth", 1.5f, new ConfigDescription("Required water depth at a candidate arrival point.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.8f, 5f), Array.Empty<object>()));
			ExtraMeats = ((BaseUnityPlugin)this).Config.Bind<string>("Bait", "Additional raw meat prefabs", "", "Optional comma-separated modded raw-meat prefab IDs. Cooked meals are not accepted by default.");
			PrefabManager.OnVanillaPrefabsAvailable += Register;
			PieceManager.OnPiecesRegistered += Icon;
		}

		private void Register()
		{
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Expected O, but got Unknown
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Expected O, but got Unknown
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Expected O, but got Unknown
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)attractor))
			{
				return;
			}
			try
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("piece_beehive");
				GameObject prefab2 = PrefabManager.Instance.GetPrefab("wood_beam_1");
				if (!Object.op_Implicit((Object)(object)prefab) || !Object.op_Implicit((Object)(object)prefab2))
				{
					throw new InvalidOperationException("Vanilla building assets unavailable.");
				}
				GameObject val = PrefabManager.Instance.CreateClonedPrefab("oct_fish_attractor", prefab);
				Beehive[] components = val.GetComponents<Beehive>();
				for (int i = 0; i < components.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)components[i]);
				}
				for (int num = val.transform.childCount - 1; num >= 0; num--)
				{
					Object.DestroyImmediate((Object)(object)((Component)val.transform.GetChild(num)).gameObject);
				}
				Collider[] components2 = val.GetComponents<Collider>();
				for (int i = 0; i < components2.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)components2[i]);
				}
				WearNTear component = prefab2.GetComponent<WearNTear>();
				MeshRenderer componentInChildren = component.m_new.GetComponentInChildren<MeshRenderer>(true);
				MeshFilter componentInChildren2 = component.m_new.GetComponentInChildren<MeshFilter>(true);
				Mesh mesh = NormalizeBeam(prefab2, componentInChildren2);
				WearNTear component2 = val.GetComponent<WearNTear>();
				component2.m_new = MakeVisual(val, "new", mesh, ((Renderer)componentInChildren).sharedMaterial);
				component2.m_worn = MakeVisual(val, "worn", mesh, ((Renderer)componentInChildren).sharedMaterial);
				component2.m_broken = MakeVisual(val, "broken", mesh, ((Renderer)componentInChildren).sharedMaterial);
				component2.m_worn.SetActive(false);
				component2.m_broken.SetActive(false);
				component2.m_fragmentRoots = (GameObject[])(object)new GameObject[1] { component2.m_new };
				component2.m_comOffset = new Vector3(0f, 0f, 0f);
				BoxCollider obj = val.AddComponent<BoxCollider>();
				obj.center = new Vector3(-0.4f, 0.55f, 0f);
				obj.size = new Vector3(0.18f, 1.1f, 0.18f);
				BoxCollider obj2 = val.AddComponent<BoxCollider>();
				obj2.center = new Vector3(0.3f, -0.75f, 0f);
				obj2.size = new Vector3(0.6f, 0.5f, 0.6f);
				val.transform.localRotation = Quaternion.identity;
				val.transform.localScale = Vector3.one;
				val.AddComponent<Attractor>();
				val.GetComponent<Piece>().m_noInWater = false;
				PieceConfig val2 = new PieceConfig();
				val2.Name = "Fish Attractor";
				val2.Description = "Load raw meat as chum to attract ordinary live fish. Build on a low dock or shoreline beside water at least 1.5m deep. Your companion still needs a fishing rod and normal fishing bait.";
				val2.PieceTable = "Hammer";
				val2.Category = "BuildingWorkbench";
				val2.CraftingStation = "piece_workbench";
				val2.Requirements = (RequirementConfig[])(object)new RequirementConfig[2]
				{
					new RequirementConfig
					{
						Item = "Wood",
						Amount = 10,
						Recover = true
					},
					new RequirementConfig
					{
						Item = "Resin",
						Amount = 2,
						Recover = true
					}
				};
				PieceConfig val3 = val2;
				if (!PieceManager.Instance.AddPiece(new CustomPiece(val, false, val3)))
				{
					throw new InvalidOperationException("Could not register fish attractor.");
				}
				attractor = val;
				RegisterTrap();
				PrefabManager.OnVanillaPrefabsAvailable -= Register;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Fish Attractor registered: manually loaded meat, live perch/pike, owner-only spawning.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Fish Attractor registration failed: " + ex));
			}
		}

		private void RegisterTrap()
		{
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			GameObject prefab = PrefabManager.Instance.GetPrefab("piece_chest_wood");
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				throw new InvalidOperationException("Vanilla chest unavailable.");
			}
			GameObject val = PrefabManager.Instance.CreateClonedPrefab("oct_fish_trap", prefab);
			Container component = val.GetComponent<Container>();
			component.m_name = "Fish Trap";
			component.m_width = 3;
			component.m_height = 2;
			MeshRenderer[] componentsInChildren = val.GetComponentsInChildren<MeshRenderer>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Renderer)componentsInChildren[i]).enabled = false;
			}
			GameObject prefab2 = PrefabManager.Instance.GetPrefab("wood_beam_1");
			GameObject val2 = prefab2.GetComponent<WearNTear>().m_new;
			Mesh mesh = NormalizeBeam(prefab2, val2.GetComponentInChildren<MeshFilter>(true));
			Material sharedMaterial = ((Renderer)val2.GetComponentInChildren<MeshRenderer>(true)).sharedMaterial;
			WearNTear component2 = val.GetComponent<WearNTear>();
			component2.m_new = MakeTrapVisual(val, "TrapNew", mesh, sharedMaterial);
			component2.m_worn = MakeTrapVisual(val, "TrapWorn", mesh, sharedMaterial);
			component2.m_broken = MakeTrapVisual(val, "TrapBroken", mesh, sharedMaterial);
			component2.m_worn.SetActive(false);
			component2.m_broken.SetActive(false);
			component2.m_fragmentRoots = (GameObject[])(object)new GameObject[1] { component2.m_new };
			val.GetComponent<Piece>().m_noInWater = false;
			val.AddComponent<FishTrap>();
			PieceConfig val3 = new PieceConfig();
			val3.Name = "Fish Trap";
			val3.Description = "Load fishing bait and collect matching caught fish. Needs nearby water at least 1.5m deep. One bait per catch; pauses when full.";
			val3.PieceTable = "Hammer";
			val3.Category = "BuildingWorkbench";
			val3.CraftingStation = "piece_workbench";
			val3.Requirements = (RequirementConfig[])(object)new RequirementConfig[3]
			{
				new RequirementConfig
				{
					Item = "Wood",
					Amount = 20,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "FineWood",
					Amount = 10,
					Recover = true
				},
				new RequirementConfig
				{
					Item = "BronzeNails",
					Amount = 10,
					Recover = true
				}
			};
			PieceConfig val4 = val3;
			if (!PieceManager.Instance.AddPiece(new CustomPiece(val, false, val4)))
			{
				throw new InvalidOperationException("Could not register fish trap.");
			}
			trap = val;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Fish Trap registered; bait matches are read from native fish definitions when the world loads.");
		}

		private static GameObject MakeTrapVisual(GameObject parent, string name, Mesh mesh, Material wood)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0055: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: 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_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.layer = parent.layer;
			val.transform.SetParent(parent.transform, false);
			float[] array = new float[2] { 0.08f, 0.75f };
			foreach (float num in array)
			{
				Beam(val, mesh, wood, new Vector3(-0.7f, num, -0.45f), new Vector3(0.7f, num, -0.45f), 0.07f);
				Beam(val, mesh, wood, new Vector3(-0.7f, num, 0.45f), new Vector3(0.7f, num, 0.45f), 0.07f);
				Beam(val, mesh, wood, new Vector3(-0.7f, num, -0.45f), new Vector3(-0.7f, num, 0.45f), 0.07f);
				Beam(val, mesh, wood, new Vector3(0.7f, num, -0.45f), new Vector3(0.7f, num, 0.45f), 0.07f);
			}
			for (int j = 0; j <= 10; j++)
			{
				float num2 = -0.7f + 1.4f * (float)j / 10f;
				array = new float[2] { -0.45f, 0.45f };
				foreach (float num3 in array)
				{
					Beam(val, mesh, wood, new Vector3(num2, 0.08f, num3), new Vector3(num2, 0.75f, num3), 0.035f);
				}
				array = new float[2] { 0.08f, 0.75f };
				foreach (float num4 in array)
				{
					Beam(val, mesh, wood, new Vector3(num2, num4, -0.45f), new Vector3(num2, num4, 0.45f), 0.035f);
				}
			}
			for (int k = 1; k < 6; k++)
			{
				float num5 = -0.45f + 0.9f * (float)k / 6f;
				array = new float[2] { -0.7f, 0.7f };
				foreach (float num6 in array)
				{
					Beam(val, mesh, wood, new Vector3(num6, 0.08f, num5), new Vector3(num6, 0.75f, num5), 0.035f);
				}
			}
			Beam(val, mesh, wood, new Vector3(-0.2f, 0.75f, 0f), new Vector3(-0.2f, 0.9f, 0f), 0.05f);
			Beam(val, mesh, wood, new Vector3(0.2f, 0.75f, 0f), new Vector3(0.2f, 0.9f, 0f), 0.05f);
			Beam(val, mesh, wood, new Vector3(-0.2f, 0.9f, 0f), new Vector3(0.2f, 0.9f, 0f), 0.05f);
			Combine(val, wood);
			return val;
		}

		private static Mesh NormalizeBeam(GameObject source, MeshFilter filter)
		{
			//IL_0019: 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_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_0035: 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_003f: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_008a: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: 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_00d3: 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_00f3: 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_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: 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)
			Mesh val = Object.Instantiate<Mesh>(filter.sharedMesh);
			Vector3[] vertices = val.vertices;
			Matrix4x4 val2 = source.transform.worldToLocalMatrix * ((Component)filter).transform.localToWorldMatrix;
			Bounds val3 = default(Bounds);
			((Bounds)(ref val3))..ctor(((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[0]), Vector3.zero);
			for (int i = 0; i < vertices.Length; i++)
			{
				vertices[i] = ((Matrix4x4)(ref val2)).MultiplyPoint3x4(vertices[i]);
				((Bounds)(ref val3)).Encapsulate(vertices[i]);
			}
			Vector3 size = ((Bounds)(ref val3)).size;
			Quaternion val4 = Quaternion.FromToRotation((Vector3)(((!(size.x >= size.y) || !(size.x >= size.z)) ? ((size.y >= size.z) ? 1 : 2) : 0) switch
			{
				1 => Vector3.up, 
				0 => Vector3.right, 
				_ => Vector3.forward, 
			}), Vector3.forward);
			for (int j = 0; j < vertices.Length; j++)
			{
				Vector3 val5 = vertices[j] - ((Bounds)(ref val3)).center;
				vertices[j] = val4 * new Vector3(val5.x / size.x, val5.y / size.y, val5.z / size.z);
			}
			val.vertices = vertices;
			val.RecalculateNormals();
			val.RecalculateBounds();
			return val;
		}

		private static GameObject MakeVisual(GameObject parent, string name, Mesh mesh, Material wood)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00dd: 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_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: 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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.layer = parent.layer;
			val.transform.SetParent(parent.transform, false);
			GameObject val2 = new GameObject("Post");
			val2.transform.SetParent(val.transform, false);
			GameObject val3 = new GameObject("BaitBasket");
			val3.transform.SetParent(val.transform, false);
			Beam(val2, mesh, wood, new Vector3(-0.4f, 0f, 0f), new Vector3(-0.4f, 1.1f, 0f), 0.14f);
			Beam(val2, mesh, wood, new Vector3(-0.5f, 1.05f, 0f), new Vector3(0.4f, 1.05f, 0f), 0.1f);
			((Object)Beam(val, mesh, wood, new Vector3(0.3f, 1.02f, 0f), new Vector3(0.3f, -0.5f, 0f), 0.025f)).name = "BaitRope";
			Vector3 a = default(Vector3);
			Vector3 val4 = default(Vector3);
			for (int i = 0; i < 12; i++)
			{
				float num = (float)i * (float)Math.PI * 2f / 12f;
				float num2 = (float)(i + 1) * (float)Math.PI * 2f / 12f;
				((Vector3)(ref a))..ctor(0.3f + Mathf.Cos(num) * 0.28f, -1f, Mathf.Sin(num) * 0.28f);
				((Vector3)(ref val4))..ctor(0.3f + Mathf.Cos(num) * 0.34f, -0.5f, Mathf.Sin(num) * 0.34f);
				Beam(val3, mesh, wood, a, val4, 0.035f);
				Beam(val3, mesh, wood, a, new Vector3(0.3f + Mathf.Cos(num2) * 0.28f, -1f, Mathf.Sin(num2) * 0.28f), 0.04f);
				Beam(val3, mesh, wood, val4, new Vector3(0.3f + Mathf.Cos(num2) * 0.34f, -0.5f, Mathf.Sin(num2) * 0.34f), 0.04f);
				if (i % 3 == 0)
				{
					Beam(val3, mesh, wood, a, new Vector3(0.3f, -1f, 0f), 0.035f);
				}
			}
			Combine(val2, wood);
			Combine(val3, wood);
			return val;
		}

		private static GameObject Beam(GameObject parent, Mesh mesh, Material wood, Vector3 a, Vector3 b, float width)
		{
			//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_0016: 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_002e: 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_0031: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			GameObject val = new GameObject("Timber")
			{
				layer = parent.layer
			};
			val.transform.SetParent(parent.transform, false);
			val.transform.localPosition = (a + b) / 2f;
			val.transform.localRotation = Quaternion.LookRotation(b - a);
			val.transform.localScale = new Vector3(width, width, Vector3.Distance(a, b));
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = wood;
			return val;
		}

		private static void Combine(GameObject group, Material material)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			MeshFilter[] componentsInChildren = group.GetComponentsInChildren<MeshFilter>();
			CombineInstance[] array = (CombineInstance[])(object)new CombineInstance[componentsInChildren.Length];
			for (int i = 0; i < array.Length; i++)
			{
				int num = i;
				CombineInstance val = default(CombineInstance);
				((CombineInstance)(ref val)).mesh = componentsInChildren[i].sharedMesh;
				((CombineInstance)(ref val)).transform = group.transform.worldToLocalMatrix * ((Component)componentsInChildren[i]).transform.localToWorldMatrix;
				array[num] = val;
			}
			Mesh val2 = new Mesh();
			val2.CombineMeshes(array, true, true);
			MeshFilter[] array2 = componentsInChildren;
			for (int j = 0; j < array2.Length; j++)
			{
				Object.DestroyImmediate((Object)(object)((Component)array2[j]).gameObject);
			}
			group.AddComponent<MeshFilter>().sharedMesh = val2;
			((Renderer)group.AddComponent<MeshRenderer>()).sharedMaterial = material;
		}

		private void Icon()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Invalid comparison between Unknown and I4
			//IL_002a: 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)
			if (!Object.op_Implicit((Object)(object)attractor) || iconDone || (int)SystemInfo.graphicsDeviceType == 4)
			{
				return;
			}
			try
			{
				Sprite val = RenderManager.Instance.Render(attractor, RenderManager.IsometricRotation);
				if (!Object.op_Implicit((Object)(object)val))
				{
					return;
				}
				attractor.GetComponent<Piece>().m_icon = val;
				if (Object.op_Implicit((Object)(object)trap))
				{
					Sprite val2 = RenderManager.Instance.Render(trap, RenderManager.IsometricRotation);
					if (Object.op_Implicit((Object)(object)val2))
					{
						trap.GetComponent<Piece>().m_icon = val2;
					}
				}
				iconDone = true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Fish Attractor icon: " + ex.Message));
			}
		}

		private void OnDestroy()
		{
			PrefabManager.OnVanillaPrefabsAvailable -= Register;
			PieceManager.OnPiecesRegistered -= Icon;
		}
	}
	public sealed class Attractor : MonoBehaviour, Hoverable, Interactable
	{
		private const string BaitKey = "oct_fish_bait";

		private const string DueKey = "oct_fish_due";

		private const string StatusKey = "oct_fish_status";

		private ZNetView view;

		private BoxCollider basketCollider;

		private readonly List<Transform> baskets = new List<Transform>();

		private readonly List<Transform> ropes = new List<Transform>();

		private void Awake()
		{
			view = ((Component)this).GetComponent<ZNetView>();
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid())
			{
				return;
			}
			basketCollider = ((IEnumerable<BoxCollider>)((Component)this).GetComponents<BoxCollider>()).FirstOrDefault((Func<BoxCollider, bool>)((BoxCollider c) => c.center.x > 0f));
			view.Register<string>("OCT_AddChum", (Action<long, string>)AddChum);
			WearNTear component = ((Component)this).GetComponent<WearNTear>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.m_onDestroyed = (Action)Delegate.Combine(component.m_onDestroyed, new Action(ReturnBait));
				GameObject[] array = (GameObject[])(object)new GameObject[3] { component.m_new, component.m_worn, component.m_broken };
				foreach (GameObject val in array)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						baskets.Add(val.transform.Find("BaitBasket"));
						ropes.Add(val.transform.Find("BaitRope"));
					}
				}
			}
			((MonoBehaviour)this).InvokeRepeating("Tick", Random.Range(3f, 8f), 15f);
		}

		private List<string> Bait()
		{
			return BaitPolicy.Read(view.GetZDO().GetString("oct_fish_bait", ""));
		}

		private static string Prefab(ItemData item)
		{
			if (item == null || !Object.op_Implicit((Object)(object)item.m_dropPrefab))
			{
				return "";
			}
			return ((Object)item.m_dropPrefab).name;
		}

		private ItemData NextMeat(Humanoid user)
		{
			return ((IEnumerable<ItemData>)user.GetInventory().GetAllItems()).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => BaitPolicy.Allowed(Prefab(i), Plugin.ExtraMeats.Value)));
		}

		public string GetHoverName()
		{
			return "Fish Attractor";
		}

		public float GetHoverOffset()
		{
			return 0f;
		}

		public string GetHoverText()
		{
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid())
			{
				return "Fish Attractor";
			}
			ItemData val = (Object.op_Implicit((Object)(object)Player.m_localPlayer) ? NextMeat((Humanoid)(object)Player.m_localPlayer) : null);
			string text = ((val != null) ? ("Add 1 " + Localization.instance.Localize(val.m_shared.m_name)) : "Add raw meat");
			return Localization.instance.Localize("Fish Attractor\nChum: " + Bait().Count + "/" + Plugin.Capacity.Value + "\n" + view.GetZDO().GetString("oct_fish_status", "Load raw meat to begin") + "\n[<color=yellow><b>$KEY_Use</b></color>] " + text + "\nUse a raw-meat hotbar item while pointing here to choose the meat.");
		}

		public bool Interact(Humanoid user, bool hold, bool alt)
		{
			if (hold)
			{
				return false;
			}
			ItemData val = NextMeat(user);
			if (val == null)
			{
				((Character)user).Message((MessageType)2, "Carry raw meat to load chum.", 0, (Sprite)null, false);
				return true;
			}
			return UseItem(user, val);
		}

		public bool UseItem(Humanoid user, ItemData item)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			if (!BaitPolicy.Allowed(Prefab(item), Plugin.ExtraMeats.Value))
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || !PrivateArea.CheckAccess(((Component)this).transform.position, 0f, true, false))
			{
				return true;
			}
			if (Bait().Count >= Plugin.Capacity.Value)
			{
				((Character)user).Message((MessageType)2, "The chum basket is full.", 0, (Sprite)null, false);
				return true;
			}
			string text = Prefab(item);
			if (!user.GetInventory().RemoveItem(item, 1))
			{
				return true;
			}
			view.InvokeRPC("OCT_AddChum", new object[1] { text });
			return true;
		}

		private void AddChum(long sender, string prefab)
		{
			if (!view.IsOwner() || !BaitPolicy.Allowed(prefab, Plugin.ExtraMeats.Value))
			{
				return;
			}
			List<string> list = Bait();
			if (list.Count >= Plugin.Capacity.Value)
			{
				Drop(prefab, 1);
				return;
			}
			list.Add(prefab);
			ZDO zDO = view.GetZDO();
			zDO.Set("oct_fish_bait", BaitPolicy.Write(list));
			if (zDO.GetLong("oct_fish_due", 0L) == 0L)
			{
				zDO.Set("oct_fish_due", ZNet.instance.GetTime().AddSeconds(Plugin.FirstDelay.Value).Ticks);
			}
			zDO.Set("oct_fish_status", "Attracting fish");
		}

		private void Tick()
		{
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || !Object.op_Implicit((Object)(object)ZoneSystem.instance))
			{
				return;
			}
			UpdateBasket();
			if (!view.IsOwner() || !Object.op_Implicit((Object)(object)ZNet.instance))
			{
				return;
			}
			try
			{
				ZDO zDO = view.GetZDO();
				List<string> list = Bait();
				if (list.Count == 0)
				{
					zDO.Set("oct_fish_due", 0L);
					zDO.Set("oct_fish_status", "Needs raw meat");
					return;
				}
				long ticks = ZNet.instance.GetTime().Ticks;
				long num = zDO.GetLong("oct_fish_due", 0L);
				if (num == 0L)
				{
					zDO.Set("oct_fish_due", ZNet.instance.GetTime().AddSeconds(Plugin.FirstDelay.Value).Ticks);
				}
				else
				{
					if (ticks < num)
					{
						return;
					}
					int num2 = 0;
					foreach (IMonoUpdater instance in Fish.Instances)
					{
						Fish val = (Fish)(object)((instance is Fish) ? instance : null);
						if (Object.op_Implicit((Object)(object)val))
						{
							Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
							if (((Vector3)(ref val2)).sqrMagnitude < 625f)
							{
								num2++;
							}
						}
					}
					if (!BaitPolicy.Ready(list.Count, num2, Plugin.FishLimit.Value, ticks, num))
					{
						zDO.Set("oct_fish_status", "Fish already nearby");
						return;
					}
					if (!FindWater(out var point))
					{
						zDO.Set("oct_fish_status", "Needs deeper water nearby");
						return;
					}
					GameObject prefab = PrefabManager.Instance.GetPrefab((Random.value < 0.65f) ? "Fish1" : "Fish2");
					if (!Object.op_Implicit((Object)(object)prefab))
					{
						zDO.Set("oct_fish_status", "Fish prefab unavailable");
					}
					else if (Object.op_Implicit((Object)(object)Object.Instantiate<GameObject>(prefab, point, Quaternion.Euler(0f, Random.Range(0f, 360f), 0f))))
					{
						list.RemoveAt(0);
						zDO.Set("oct_fish_bait", BaitPolicy.Write(list));
						zDO.Set("oct_fish_due", ZNet.instance.GetTime().AddSeconds(Plugin.Interval.Value).Ticks);
						zDO.Set("oct_fish_status", "Fish arrived nearby");
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[Fish Attractor] Attraction paused: " + ex.Message));
				((MonoBehaviour)this).CancelInvoke("Tick");
			}
		}

		private void UpdateBasket()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0089: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			float liquidLevel = Floating.GetLiquidLevel(((Component)this).transform.position - Vector3.up * 4f, 0f, (LiquidType)0);
			if (liquidLevel < -1000f || Mathf.Abs(liquidLevel - ((Component)this).transform.position.y) > 4f)
			{
				return;
			}
			float num = liquidLevel - ((Component)this).transform.position.y;
			if (Object.op_Implicit((Object)(object)basketCollider))
			{
				basketCollider.center = new Vector3(0.3f, -0.75f + num, 0f);
			}
			foreach (Transform basket in baskets)
			{
				if (Object.op_Implicit((Object)(object)basket))
				{
					basket.localPosition = new Vector3(0f, num, 0f);
				}
			}
			foreach (Transform rope in ropes)
			{
				if (Object.op_Implicit((Object)(object)rope))
				{
					rope.localPosition = new Vector3(0.3f, (1.02f + num - 0.5f) / 2f, 0f);
					rope.localScale = new Vector3(0.025f, 0.025f, 1.52f - num);
				}
			}
		}

		private bool FindWater(out Vector3 point)
		{
			//IL_002d: 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_0052: 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_006e: 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_008b: 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_00e6: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 12; i++)
			{
				float num = Random.Range(0f, (float)Math.PI * 2f);
				float num2 = Random.Range(4f, 8f);
				Vector3 val = ((Component)this).transform.position + new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2);
				float liquidLevel = Floating.GetLiquidLevel(new Vector3(val.x, ((Component)this).transform.position.y - 4f, val.z), 0f, (LiquidType)0);
				float groundHeight = ZoneSystem.instance.GetGroundHeight(val);
				if (BaitPolicy.WaterSuitable(liquidLevel, groundHeight, Plugin.Depth.Value, ((Component)this).transform.position.y))
				{
					point = new Vector3(val.x, liquidLevel - 0.6f, val.z);
					return true;
				}
			}
			point = Vector3.zero;
			return false;
		}

		private void Drop(string prefab, int count)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			GameObject prefab2 = PrefabManager.Instance.GetPrefab(prefab);
			if (!Object.op_Implicit((Object)(object)prefab2))
			{
				return;
			}
			ItemDrop component = prefab2.GetComponent<ItemDrop>();
			if (Object.op_Implicit((Object)(object)component))
			{
				ItemData val = component.m_itemData.Clone();
				val.m_dropPrefab = prefab2;
				while (count > 0)
				{
					int num = Math.Min(count, Math.Max(1, val.m_shared.m_maxStackSize));
					ItemDrop.DropItem(val, num, ((Component)this).transform.position + Vector3.up * 0.5f, Quaternion.identity);
					count -= num;
				}
			}
		}

		private void ReturnBait()
		{
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || !view.IsOwner())
			{
				return;
			}
			List<string> source = Bait();
			view.GetZDO().Set("oct_fish_bait", "");
			foreach (IGrouping<string, string> item in from s in source
				group s by s)
			{
				Drop(item.Key, item.Count());
			}
		}
	}
	public static class BaitPolicy
	{
		public static readonly string[] DefaultMeats = new string[12]
		{
			"RawMeat", "DeerMeat", "NeckTail", "WolfMeat", "LoxMeat", "HareMeat", "ChickenMeat", "SerpentMeat", "SeekerMeat", "AsksvinMeat",
			"VoltureMeat", "FishRaw"
		};

		public static bool Allowed(string prefab, string extras)
		{
			string[] defaultMeats = DefaultMeats;
			foreach (string b in defaultMeats)
			{
				if (string.Equals(prefab, b, StringComparison.Ordinal))
				{
					return true;
				}
			}
			defaultMeats = (extras ?? "").Split(',');
			foreach (string text in defaultMeats)
			{
				if (text.Trim().Length > 0 && string.Equals(prefab, text.Trim(), StringComparison.Ordinal))
				{
					return true;
				}
			}
			return false;
		}

		public static List<string> Read(string stored)
		{
			List<string> list = new List<string>();
			string[] array = (stored ?? "").Split('|');
			foreach (string text in array)
			{
				if (text.Length > 0)
				{
					list.Add(text);
				}
			}
			return list;
		}

		public static string Write(List<string> bait)
		{
			return string.Join("|", bait.ToArray());
		}

		public static bool Ready(int bait, int nearby, int limit, long now, long due)
		{
			if (bait > 0 && nearby < limit && due > 0)
			{
				return now >= due;
			}
			return false;
		}

		public static bool WaterSuitable(float level, float ground, float depth, float stationY)
		{
			if (!float.IsNaN(level) && !float.IsInfinity(level) && level > -1000f && level - ground >= depth)
			{
				return Math.Abs(stationY - level) <= 4f;
			}
			return false;
		}
	}
	public sealed class FishTrap : MonoBehaviour
	{
		private sealed class Catch
		{
			internal string Fish;

			internal float Weight;
		}

		private static readonly Dictionary<string, List<Catch>> Catalog = new Dictionary<string, List<Catch>>(StringComparer.Ordinal);

		private const string DueKey = "oct_trap_due";

		private static ConfigEntry<float> interval;

		private static ConfigEntry<float> firstDelay;

		private static ConfigEntry<int> storage;

		private ZNetView view;

		private Container container;

		internal static int BaitKinds => Catalog.Count;

		internal static void BuildCatalog()
		{
			if (!Object.op_Implicit((Object)(object)ZNetScene.instance))
			{
				return;
			}
			Catalog.Clear();
			foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
			{
				if (!Object.op_Implicit((Object)(object)prefab))
				{
					continue;
				}
				Fish component = prefab.GetComponent<Fish>();
				if (!Object.op_Implicit((Object)(object)component) || component.m_baits == null)
				{
					continue;
				}
				GameObject item = (Object.op_Implicit((Object)(object)prefab.GetComponent<ItemDrop>()) ? prefab : component.m_pickupItem);
				if (!Object.op_Implicit((Object)(object)item) || !Object.op_Implicit((Object)(object)item.GetComponent<ItemDrop>()))
				{
					continue;
				}
				foreach (BaitSetting bait in component.m_baits)
				{
					if (Object.op_Implicit((Object)(object)bait.m_bait) && !(bait.m_chance <= 0f))
					{
						string name = ((Object)((Component)bait.m_bait).gameObject).name;
						if (!Catalog.TryGetValue(name, out var value))
						{
							value = new List<Catch>();
							Catalog.Add(name, value);
						}
						if (!value.Any((Catch c) => c.Fish == ((Object)item).name))
						{
							value.Add(new Catch
							{
								Fish = ((Object)item).name,
								Weight = bait.m_chance
							});
						}
					}
				}
			}
		}

		private void Awake()
		{
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			view = ((Component)this).GetComponent<ZNetView>();
			container = ((Component)this).GetComponent<Container>();
			if (Object.op_Implicit((Object)(object)view) && view.IsValid() && Object.op_Implicit((Object)(object)container))
			{
				ConfigFile config = Chainloader.PluginInfos["OctoberJemini.FishAttractor"].Instance.Config;
				interval = config.Bind<float>("Fish trap", "Seconds between catches", 300f, new ConfigDescription("World-time seconds per successful catch. No accumulated catch-up burst.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(30f, 3600f), Array.Empty<object>()));
				firstDelay = config.Bind<float>("Fish trap", "First catch delay", 60f, new ConfigDescription("Delay after first loading fishing bait.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(15f, 600f), Array.Empty<object>()));
				storage = config.Bind<int>("Fish trap", "Stored fish limit", 20, new ConfigDescription("Maximum number of caught fish in the trap, across species.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
				((MonoBehaviour)this).InvokeRepeating("Tick", Random.Range(4f, 9f), 15f);
			}
		}

		private void Tick()
		{
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)view) || !view.IsValid() || !view.IsOwner() || !Object.op_Implicit((Object)(object)ZNet.instance) || !Object.op_Implicit((Object)(object)ZoneSystem.instance) || !Object.op_Implicit((Object)(object)container))
			{
				return;
			}
			try
			{
				if (Catalog.Count == 0)
				{
					BuildCatalog();
				}
				if (container.IsInUse())
				{
					return;
				}
				Inventory inventory = container.GetInventory();
				if (inventory == null)
				{
					return;
				}
				List<ItemData> allItems = inventory.GetAllItems();
				int num = allItems.Where((ItemData i) => Object.op_Implicit((Object)(object)i.m_dropPrefab) && Catalog.Values.Any((List<Catch> cs) => cs.Any((Catch c) => c.Fish == ((Object)i.m_dropPrefab).name))).Sum((ItemData i) => i.m_stack);
				ItemData val = ((IEnumerable<ItemData>)allItems).FirstOrDefault((Func<ItemData, bool>)((ItemData i) => Object.op_Implicit((Object)(object)i.m_dropPrefab) && Catalog.ContainsKey(((Object)i.m_dropPrefab).name)));
				if (val == null || num >= storage.Value)
				{
					return;
				}
				ZDO zDO = view.GetZDO();
				long ticks = ZNet.instance.GetTime().Ticks;
				long num2 = zDO.GetLong("oct_trap_due", 0L);
				if (num2 == 0L)
				{
					zDO.Set("oct_trap_due", ZNet.instance.GetTime().AddSeconds(firstDelay.Value).Ticks);
				}
				else
				{
					if (ticks < num2 || !Water(out var _))
					{
						return;
					}
					List<Catch> list = Catalog[((Object)val.m_dropPrefab).name].Where(delegate(Catch c)
					{
						GameObject prefab2 = PrefabManager.Instance.GetPrefab(c.Fish);
						return Object.op_Implicit((Object)(object)prefab2) && inventory.CanAddItem(prefab2, 1);
					}).ToList();
					if (list.Count == 0)
					{
						return;
					}
					int num3 = TrapRules.Choose(Random.value, list.Select((Catch c) => c.Weight).ToArray());
					if (num3 < 0)
					{
						return;
					}
					GameObject prefab = PrefabManager.Instance.GetPrefab(list[num3].Fish);
					if (!Object.op_Implicit((Object)(object)prefab) || !TrapRules.CanCatch(num, storage.Value, inUse: false, hasSpace: true, hasBait: true, ticks, num2))
					{
						return;
					}
					ItemData val2 = val.Clone();
					val2.m_stack = 1;
					if (!inventory.RemoveItem(val, 1))
					{
						return;
					}
					if (!inventory.AddItem(prefab, 1))
					{
						if (!inventory.AddItem(val2))
						{
							ItemDrop.DropItem(val2, 1, ((Component)this).transform.position + Vector3.up, Quaternion.identity);
						}
					}
					else
					{
						zDO.Set("oct_trap_due", ZNet.instance.GetTime().AddSeconds(interval.Value).Ticks);
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[Fish Trap] Catching paused: " + ex.Message));
				((MonoBehaviour)this).CancelInvoke("Tick");
			}
		}

		private bool Water(out Vector3 result)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: 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_003f: 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_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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 9; i++)
			{
				float num = (float)i * (float)Math.PI / 4f;
				float num2 = ((i != 0) ? 3 : 0);
				Vector3 val = ((Component)this).transform.position + new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2);
				if (BaitPolicy.WaterSuitable(Floating.GetLiquidLevel(new Vector3(val.x, ((Component)this).transform.position.y - 4f, val.z), 0f, (LiquidType)0), ZoneSystem.instance.GetGroundHeight(val), Plugin.Depth.Value, ((Component)this).transform.position.y))
				{
					result = val;
					return true;
				}
			}
			result = Vector3.zero;
			return false;
		}
	}
	public static class TrapRules
	{
		public static bool CanCatch(int count, int limit, bool inUse, bool hasSpace, bool hasBait, long now, long due)
		{
			if (hasBait && !inUse && hasSpace && count < limit && due > 0)
			{
				return now >= due;
			}
			return false;
		}

		public static int Choose(float unit, float[] weights)
		{
			float num = 0f;
			foreach (float num2 in weights)
			{
				if (num2 > 0f)
				{
					num += num2;
				}
			}
			if (num <= 0f)
			{
				return -1;
			}
			float num3 = unit * num;
			for (int j = 0; j < weights.Length; j++)
			{
				if (!(weights[j] <= 0f))
				{
					num3 -= weights[j];
					if (num3 < 0f)
					{
						return j;
					}
				}
			}
			for (int num4 = weights.Length - 1; num4 >= 0; num4--)
			{
				if (weights[num4] > 0f)
				{
					return num4;
				}
			}
			return -1;
		}
	}
}