Decompiled source of Cooler Mod v0.1.6

BepInEx/plugins/CoolerMod/CoolerMod.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using FishNet;
using FishNet.Broadcast;
using FishNet.Connection;
using FishNet.Managing;
using FishNet.Managing.Object;
using FishNet.Object;
using FishNet.Serializing;
using FishNet.Transporting;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[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 CoolerMod
{
	public static class Rules
	{
		public const byte ItemId = 249;

		public const ushort PrefabCollection = 42421;

		public const int Price = 1000;

		public const int ResalePrice = 500;

		public const int Capacity = 20;

		public const float UseRange = 5f;

		public const float DeployRange = 8f;

		public const float HoldSeconds = 1f;

		public const float VendorRange = 5f;

		public const float VendorLookDot = 0.72f;

		public static bool Finite(float value)
		{
			if (!float.IsNaN(value))
			{
				return !float.IsInfinity(value);
			}
			return false;
		}

		public static bool SurfaceAllowed(float normalY)
		{
			if (Finite(normalY))
			{
				return normalY >= 0.02f;
			}
			return false;
		}

		public static bool CanPickUp(bool freeSlot, bool emptyHands)
		{
			return freeSlot || emptyHands;
		}

		public static bool CanUseVendor(float distance, float lookDot)
		{
			if (Finite(distance) && Finite(lookDot) && distance <= 5.35f)
			{
				return lookDot >= 0.72f;
			}
			return false;
		}
	}
	[Serializable]
	public sealed class CoolerData
	{
		public int serial;

		public string name;

		public ulong owner;

		public string ownerName;

		public bool deployed;

		public bool available = true;

		public Vector3 position;

		public Vector3 surfaceNormal = Vector3.up;

		public float yaw;

		public List<SavedItem> fish = new List<SavedItem>();

		public List<StoredFishInfo> fishInfo = new List<StoredFishInfo>();

		public Quaternion Rotation => Quaternion.FromToRotation(Vector3.up, (((Vector3)(ref surfaceNormal)).sqrMagnitude > 0.01f) ? surfaceNormal : Vector3.up) * Quaternion.Euler(0f, yaw, 0f);
	}
	[Serializable]
	public sealed class StoredFishInfo
	{
		public string name;

		public int value;
	}
	[Serializable]
	public sealed class WorldData
	{
		public string name;

		public List<CoolerData> coolers = new List<CoolerData>();
	}
	[Serializable]
	public sealed class SaveData
	{
		public int version = 1;

		public int nextSerial = 1;

		public List<WorldData> worlds = new List<WorldData>();
	}
	[Serializable]
	public sealed class Command
	{
		public int protocol = 1;

		public int sequence;

		public int serial;

		public int index;

		public string action;

		public string text;

		public Vector3 position;

		public Vector3 normal;
	}
	[Serializable]
	public sealed class Snapshot
	{
		public int protocol = 1;

		public string world;

		public List<CoolerData> coolers = new List<CoolerData>();
	}
	[Serializable]
	public sealed class Reply
	{
		public int sequence;

		public int serial;

		public string message;
	}
	public struct RequestMessage : IBroadcast
	{
		public string json;
	}
	public struct StateMessage : IBroadcast
	{
		public string json;
	}
	public struct ReplyMessage : IBroadcast
	{
		public string json;
	}
	public static class Codec
	{
		private sealed class Fields : DefaultContractResolver
		{
			protected override IList<JsonProperty> CreateProperties(Type type, MemberSerialization mode)
			{
				return (from f in type.GetFields(BindingFlags.Instance | BindingFlags.Public)
					where !f.IsNotSerialized
					select ((DefaultContractResolver)this).CreateProperty((MemberInfo)f, (MemberSerialization)2)).ToList();
			}
		}

		private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
		{
			ContractResolver = (IContractResolver)(object)new Fields(),
			TypeNameHandling = (TypeNameHandling)0,
			ObjectCreationHandling = (ObjectCreationHandling)2,
			MaxDepth = 32
		};

		public static string ToJson(object value, bool pretty = false)
		{
			return JsonConvert.SerializeObject(value, (Formatting)(pretty ? 1 : 0), Settings);
		}

		public static T FromJson<T>(string json)
		{
			return JsonConvert.DeserializeObject<T>(json, Settings);
		}
	}
	public static class CoolerItem
	{
		public static Item Prefab;

		private static GameObject storage;

		public static bool Is(Item item)
		{
			if ((Object)(object)item != (Object)null && item.ID == 249)
			{
				return (Object)(object)((Component)item).GetComponent<CoolerVisual>() != (Object)null;
			}
			return false;
		}

		public static int Serial(Item item)
		{
			if (!Is(item))
			{
				return 0;
			}
			return Mathf.RoundToInt(item.BettingMultiplier);
		}

		public static void Register()
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_01f2: 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_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: 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_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Expected O, but got Unknown
			//IL_0332: Unknown result type (might be due to invalid IL or missing references)
			//IL_0337: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Prefab != (Object)null || (Object)(object)InstanceFinder.NetworkManager == (Object)null)
			{
				return;
			}
			Dictionary<byte, Item> dictionary = (Dictionary<byte, Item>)AccessTools.Field(typeof(GameInfo), "_idToSpawnable").GetValue(null);
			if (dictionary.Count == 0)
			{
				return;
			}
			if (dictionary.ContainsKey(249))
			{
				throw new Exception("Cooler Mod item ID 249 is already in use.");
			}
			Item? obj = (from i in dictionary.Values
				where (Object)(object)i != (Object)null && ((object)i).GetType() == typeof(Item) && (Object)(object)((Component)i).GetComponent<NetworkObject>() != (Object)null
				orderby i.ID
				select i).FirstOrDefault();
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("No compatible base item prefab was found.");
			}
			storage = new GameObject("Cooler Mod prefab storage");
			storage.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)storage);
			Item val = Object.Instantiate<Item>(obj, storage.transform);
			((Object)val).name = "Reusable Fishing Cooler";
			AccessTools.Field(typeof(Item), "_id").SetValue(val, (byte)249);
			AccessTools.Field(typeof(Item), "_cost").SetValue(val, 1000);
			AccessTools.Field(typeof(Item), "_worth").SetValue(val, 500);
			AccessTools.Field(typeof(Item), "_ignoredBySeagulls").SetValue(val, true);
			AccessTools.Field(typeof(Item), "_ignoredByMoneyNPC").SetValue(val, false);
			AccessTools.Field(typeof(Item), "_ignoredByCloseDots").SetValue(val, false);
			AccessTools.Field(typeof(Item), "_heldPos").SetValue(val, (object)new Vector3(0.32f, -0.5f, 0.82f));
			AccessTools.Field(typeof(Item), "_heldRot").SetValue(val, (object)new Vector3(2f, 88f, 2f));
			Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
			for (int num = 0; num < componentsInChildren.Length; num++)
			{
				componentsInChildren[num].enabled = false;
			}
			Collider[] componentsInChildren2 = ((Component)val).GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				if (!val2.isTrigger)
				{
					val2.enabled = false;
				}
			}
			GameObject val3 = new GameObject("CoolerBodyCollider");
			val3.transform.SetParent(((Component)val).transform, false);
			BoxCollider val4 = val3.AddComponent<BoxCollider>();
			val4.center = new Vector3(0f, 0.43f, 0f);
			val4.size = new Vector3(1.2f, 0.86f, 0.78f);
			AccessTools.Field(typeof(Item), "_worldColliders").SetValue(val, new Collider[1] { (Collider)val4 });
			Collider val5 = (Collider)AccessTools.Field(typeof(Item), "_pickUpCollider").GetValue(val);
			if (val5 is SphereCollider)
			{
				SphereCollider val6 = (SphereCollider)val5;
				val6.radius = 0.85f;
				val6.center = new Vector3(0f, 0.42f, 0f);
			}
			else if (val5 is BoxCollider)
			{
				BoxCollider val7 = (BoxCollider)val5;
				val7.size = new Vector3(1.5f, 1.15f, 1.1f);
				val7.center = new Vector3(0f, 0.42f, 0f);
			}
			AccessTools.Field(typeof(Item), "_outOfHandHolder").SetValue(val, null);
			AccessTools.Field(typeof(Item), "_inHandHolder").SetValue(val, null);
			CoolerVisual coolerVisual = ((Component)val).gameObject.AddComponent<CoolerVisual>();
			coolerVisual.Build();
			AccessTools.Field(typeof(Item), "_mesh").SetValue(val, coolerVisual.InventoryMesh());
			AccessTools.Field(typeof(Item), "_inventoryMeshScale").SetValue(val, 0.52f);
			AccessTools.Field(typeof(Item), "_inventoryMeshPos").SetValue(val, (object)new Vector3(0f, -0.15f, 0f));
			AccessTools.Field(typeof(Item), "_inventoryMeshRot").SetValue(val, (object)new Vector3(18f, 35f, 0f));
			AccessTools.Field(typeof(Item), "_renderers").SetValue(val, (from r in ((Component)coolerVisual).GetComponentsInChildren<Renderer>(true)
				where r.enabled
				select r).ToList());
			NetworkObject component = ((Component)val).GetComponent<NetworkObject>();
			component.SetIsSpawnable(true);
			PrefabObjects prefabObjects = InstanceFinder.NetworkManager.GetPrefabObjects<SinglePrefabObjects>((ushort)42421, true);
			if (prefabObjects.GetObjectCount() != 0)
			{
				throw new Exception("Cooler Mod network prefab collection 42421 is occupied.");
			}
			prefabObjects.AddObject(component, false, true);
			dictionary.Add(249, val);
			((Dictionary<byte, Item>)AccessTools.Field(typeof(GameInfo), "_allItems").GetValue(null)).Add(249, val);
			((Dictionary<string, Item>)AccessTools.Field(typeof(GameInfo), "_nameToSpawnable").GetValue(null)).Add("coolermod", val);
			Prefab = val;
			Plugin.Log("Registered reusable cooler item and network prefab.");
		}
	}
	public sealed class CoolerVisual : MonoBehaviour
	{
		private static Material teal;

		private static Material white;

		private static Material dark;

		private static Material silver;

		private Mesh inventoryMesh;

		public Mesh InventoryMesh()
		{
			return inventoryMesh;
		}

		public void Build()
		{
			//IL_00db: 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_011d: 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_0168: 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_01a2: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			//IL_008d: 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_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00d6: Expected O, but got Unknown
			//IL_025b: 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_0292: 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_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)((Component)this).transform.Find("CoolerModel") != (Object)null)
			{
				return;
			}
			Shader val = Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard");
			if ((Object)(object)teal == (Object)null)
			{
				teal = new Material(val)
				{
					color = new Color(0.03f, 0.48f, 0.58f)
				};
				white = new Material(val)
				{
					color = new Color(0.88f, 0.86f, 0.78f)
				};
				dark = new Material(val)
				{
					color = new Color(0.07f, 0.1f, 0.15f)
				};
				silver = new Material(val)
				{
					color = new Color(0.58f, 0.63f, 0.65f)
				};
			}
			Transform transform = new GameObject("CoolerModel").transform;
			transform.SetParent(((Component)this).transform, false);
			Transform val2 = Part("Body", transform, (PrimitiveType)3, new Vector3(0f, 0.39f, 0f), new Vector3(1.12f, 0.66f, 0.72f), teal);
			inventoryMesh = ((Component)val2).GetComponent<MeshFilter>().sharedMesh;
			Part("LowerBand", transform, (PrimitiveType)3, new Vector3(0f, 0.12f, 0f), new Vector3(1.18f, 0.1f, 0.78f), dark);
			Part("UpperBand", transform, (PrimitiveType)3, new Vector3(0f, 0.68f, 0f), new Vector3(1.18f, 0.1f, 0.78f), dark);
			Part("Lid", transform, (PrimitiveType)3, new Vector3(0f, 0.79f, 0f), new Vector3(1.22f, 0.18f, 0.82f), white);
			Part("LidInset", transform, (PrimitiveType)3, new Vector3(0f, 0.895f, 0f), new Vector3(0.76f, 0.035f, 0.45f), silver);
			float[] array = new float[2] { -0.35f, 0.35f };
			foreach (float num in array)
			{
				Part("Latch", transform, (PrimitiveType)3, new Vector3(num, 0.66f, -0.425f), new Vector3(0.14f, 0.22f, 0.07f), dark);
				Part("LatchCap", transform, (PrimitiveType)3, new Vector3(num, 0.73f, -0.47f), new Vector3(0.17f, 0.08f, 0.06f), silver);
			}
			array = new float[2] { -0.56f, 0.56f };
			foreach (float num2 in array)
			{
				Part("HandlePost", transform, (PrimitiveType)3, new Vector3(num2, 0.91f, 0f), new Vector3(0.08f, 0.48f, 0.09f), dark);
			}
			Part("Handle", transform, (PrimitiveType)3, new Vector3(0f, 1.14f, 0f), new Vector3(1.18f, 0.09f, 0.11f), dark);
			array = new float[2] { -0.52f, 0.52f };
			foreach (float num3 in array)
			{
				float[] array2 = new float[2] { -0.32f, 0.32f };
				foreach (float num4 in array2)
				{
					Part("Foot", transform, (PrimitiveType)3, new Vector3(num3, 0.055f, num4), new Vector3(0.16f, 0.11f, 0.13f), dark);
				}
			}
		}

		public static Transform Part(string name, Transform parent, PrimitiveType primitive, Vector3 pos, Vector3 scale, Material material)
		{
			//IL_0000: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.CreatePrimitive(primitive);
			((Object)obj).name = name;
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = pos;
			obj.transform.localScale = scale;
			Object.DestroyImmediate((Object)(object)obj.GetComponent<Collider>());
			obj.GetComponent<Renderer>().sharedMaterial = material;
			return obj.transform;
		}
	}
	[BepInPlugin("ponyfisher.howtofish.coolermod", "Cooler Mod", "0.1.6")]
	[DefaultExecutionOrder(29100)]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "ponyfisher.howtofish.coolermod";

		public static Plugin Instance;

		public List<CoolerData> Current = new List<CoolerData>();

		public bool Open;

		public int Selected;

		public string Status = "Purchase a reusable cooler from an item vendor.";

		private SaveData save = new SaveData();

		private WorldData world;

		private NetworkManager manager;

		private Harmony harmony;

		private string savePath;

		private bool persistenceReady = true;

		private bool registrationFailed;

		private bool catalogReady;

		private float nextTick;

		private float nextSave;

		private float nextState;

		private float nextHello;

		private float nextVendorScan;

		private float nextIconRefresh;

		private int sequence;

		private bool nearMoneyVendor;

		private Component hoveredInteractable;

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

		private readonly Dictionary<int, float> rateLimit = new Dictionary<int, float>();

		private readonly Dictionary<int, Item> coolers = new Dictionary<int, Item>();

		private float useStarted;

		private Item activeTarget;

		private bool holdFired;

		private GUIStyle hintStyle;

		private Rect panel = new Rect(30f, 45f, 1160f, 680f);

		private CursorLockMode oldLock;

		private GUIStyle windowStyle;

		private GUIStyle titleStyle;

		private GUIStyle headerStyle;

		private GUIStyle rowStyle;

		private GUIStyle emptyStyle;

		private GUIStyle buttonStyle;

		private GUIStyle dropStyle;

		private GUIStyle statusStyle;

		private Texture2D navy;

		private Texture2D teal;

		private Texture2D tealHover;

		private Texture2D orange;

		private Texture2D orangeHover;

		private Texture2D rowBg;

		private Texture2D rowAlt;

		private string nameDraft;

		private int nameDraftSerial;

		public static void Log(string text)
		{
			if ((Object)(object)Instance != (Object)null)
			{
				((BaseUnityPlugin)Instance).Logger.LogInfo((object)text);
			}
		}

		private void Awake()
		{
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			Instance = this;
			savePath = Path.Combine(Paths.ConfigPath, "CoolerMod-worlds.json");
			try
			{
				if (File.Exists(savePath))
				{
					save = Codec.FromJson<SaveData>(File.ReadAllText(savePath));
					if (save == null || save.version != 1 || save.worlds == null)
					{
						throw new Exception("Unrecognized save format");
					}
				}
			}
			catch (Exception ex)
			{
				persistenceReady = false;
				Status = "Cooler save data could not be read; storage actions are paused.";
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
			GenericWriter<RequestMessage>.SetWrite((Action<Writer, RequestMessage>)delegate(Writer w, RequestMessage v)
			{
				w.WriteString(v.json);
			});
			GenericReader<RequestMessage>.SetRead((Func<Reader, RequestMessage>)((Reader r) => new RequestMessage
			{
				json = r.ReadStringAllocated()
			}));
			GenericWriter<StateMessage>.SetWrite((Action<Writer, StateMessage>)delegate(Writer w, StateMessage v)
			{
				w.WriteString(v.json);
			});
			GenericReader<StateMessage>.SetRead((Func<Reader, StateMessage>)((Reader r) => new StateMessage
			{
				json = r.ReadStringAllocated()
			}));
			GenericWriter<ReplyMessage>.SetWrite((Action<Writer, ReplyMessage>)delegate(Writer w, ReplyMessage v)
			{
				w.WriteString(v.json);
			});
			GenericReader<ReplyMessage>.SetRead((Func<Reader, ReplyMessage>)((Reader r) => new ReplyMessage
			{
				json = r.ReadStringAllocated()
			}));
			harmony = new Harmony("ponyfisher.howtofish.coolermod");
			harmony.PatchAll(typeof(Plugin).Assembly);
			Log("Cooler Mod 0.1.6 loaded.");
		}

		private void Update()
		{
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: 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_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
			UpdateInteraction();
			if ((Object)(object)manager != (Object)(object)InstanceFinder.NetworkManager)
			{
				RegisterNetwork();
			}
			if (!registrationFailed && (Object)(object)CoolerItem.Prefab == (Object)null)
			{
				try
				{
					CoolerItem.Register();
				}
				catch (Exception ex)
				{
					registrationFailed = true;
					Status = "Cooler item registration failed; see the BepInEx log.";
					((BaseUnityPlugin)this).Logger.LogError((object)ex);
				}
			}
			if ((Object)(object)CoolerItem.Prefab != (Object)null && !catalogReady)
			{
				catalogReady = true;
				Log("Cooler catalog ready.");
			}
			if (catalogReady && Time.unscaledTime >= nextVendorScan)
			{
				nextVendorScan = Time.unscaledTime + 0.15f;
				nearMoneyVendor = (Object)(object)FocusedMoneyVendor(Player.LocalPlayer, 5f) != (Object)null;
			}
			Keyboard current = Keyboard.current;
			if (catalogReady && nearMoneyVendor && !Open && current != null && ((ButtonControl)current.digit8Key).wasPressedThisFrame)
			{
				Send("buy");
			}
			if (catalogReady && Time.unscaledTime >= nextIconRefresh)
			{
				nextIconRefresh = Time.unscaledTime + 0.15f;
				CoolerInventoryIcon.RefreshAll();
			}
			if (InstanceFinder.IsServerStarted && SaveManager.CurServerSave != null)
			{
				string name = SaveManager.CurServerSave.Name;
				if (world == null || world.name != name)
				{
					world = save.worlds.FirstOrDefault((WorldData w) => w.name == name);
					if (world == null)
					{
						world = new WorldData
						{
							name = name
						};
						save.worlds.Add(world);
					}
					Current = world.coolers;
					coolers.Clear();
					lastSequence.Clear();
					rateLimit.Clear();
				}
				if (Time.unscaledTime >= nextTick)
				{
					nextTick = Time.unscaledTime + 0.2f;
					AuditWorld();
				}
				if (Time.unscaledTime >= nextState)
				{
					nextState = Time.unscaledTime + 0.35f;
					Broadcast();
				}
				if (Time.unscaledTime >= nextSave)
				{
					nextSave = Time.unscaledTime + 8f;
					Persist();
				}
			}
			else if (!InstanceFinder.IsClientStarted)
			{
				world = null;
				Current = new List<CoolerData>();
				coolers.Clear();
			}
			if (Open && InstanceFinder.IsClientStarted && !InstanceFinder.IsServerStarted && Time.unscaledTime >= nextHello)
			{
				nextHello = Time.unscaledTime + 3f;
				Send("hello");
			}
		}

		private void LateUpdate()
		{
			if (Open)
			{
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
			}
		}

		private void RegisterNetwork()
		{
			if ((Object)(object)manager != (Object)null)
			{
				manager.ServerManager.UnregisterBroadcast<RequestMessage>((Action<NetworkConnection, RequestMessage, Channel>)Receive);
				manager.ClientManager.UnregisterBroadcast<StateMessage>((Action<StateMessage, Channel>)ReceiveState);
				manager.ClientManager.UnregisterBroadcast<ReplyMessage>((Action<ReplyMessage, Channel>)ReceiveReply);
			}
			manager = InstanceFinder.NetworkManager;
			if (!((Object)(object)manager == (Object)null))
			{
				manager.ServerManager.RegisterBroadcast<RequestMessage>((Action<NetworkConnection, RequestMessage, Channel>)Receive, true);
				manager.ClientManager.RegisterBroadcast<StateMessage>((Action<StateMessage, Channel>)ReceiveState);
				manager.ClientManager.RegisterBroadcast<ReplyMessage>((Action<ReplyMessage, Channel>)ReceiveReply);
			}
		}

		public static string DefaultCoolerName(int serial)
		{
			return "Fishing Cooler " + serial;
		}

		private static string CleanName(string value, int serial)
		{
			if (value == null)
			{
				return DefaultCoolerName(serial);
			}
			string text = new string(value.Where((char c) => !char.IsControl(c)).ToArray()).Trim();
			if (text.Length > 28)
			{
				text = text.Substring(0, 28).Trim();
			}
			if (text.Length != 0)
			{
				return text;
			}
			return DefaultCoolerName(serial);
		}

		private void Normalize(CoolerData data)
		{
			if (data == null)
			{
				return;
			}
			data.name = CleanName(data.name, data.serial);
			if (data.fish == null)
			{
				data.fish = new List<SavedItem>();
			}
			if (data.fishInfo == null)
			{
				data.fishInfo = new List<StoredFishInfo>();
			}
			while (data.fishInfo.Count < data.fish.Count)
			{
				SavedItem fish = data.fish[data.fishInfo.Count];
				data.fishInfo.Add(new StoredFishInfo
				{
					name = FishName(fish),
					value = FishValue(fish)
				});
			}
			if (data.fishInfo.Count > data.fish.Count)
			{
				data.fishInfo.RemoveRange(data.fish.Count, data.fishInfo.Count - data.fish.Count);
			}
			for (int i = 0; i < data.fishInfo.Count; i++)
			{
				if (data.fishInfo[i] == null)
				{
					data.fishInfo[i] = new StoredFishInfo();
				}
				if (string.IsNullOrWhiteSpace(data.fishInfo[i].name))
				{
					data.fishInfo[i].name = FishName(data.fish[i]);
				}
				if (data.fishInfo[i].value < 0)
				{
					data.fishInfo[i].value = 0;
				}
			}
		}

		public CoolerData Find(int serial)
		{
			CoolerData coolerData = Current.FirstOrDefault((CoolerData c) => c.serial == serial);
			Normalize(coolerData);
			return coolerData;
		}

		public string StoredName(CoolerData data, int index)
		{
			Normalize(data);
			if (data == null || index < 0 || index >= data.fishInfo.Count)
			{
				return "Unknown fish";
			}
			return data.fishInfo[index].name;
		}

		public int StoredValue(CoolerData data, int index)
		{
			Normalize(data);
			if (data == null || index < 0 || index >= data.fishInfo.Count)
			{
				return 0;
			}
			return Mathf.Max(0, data.fishInfo[index].value);
		}

		private void RemoveStored(CoolerData data, int index)
		{
			data.fish.RemoveAt(index);
			if (data.fishInfo != null && index < data.fishInfo.Count)
			{
				data.fishInfo.RemoveAt(index);
			}
			FishPreviews.Clear();
		}

		public void Persist()
		{
			if (!persistenceReady || !InstanceFinder.IsServerStarted || world == null)
			{
				return;
			}
			try
			{
				string text = savePath + ".tmp";
				File.WriteAllText(text, Codec.ToJson(save, pretty: true));
				if (File.Exists(savePath))
				{
					File.Replace(text, savePath, savePath + ".bak");
				}
				else
				{
					File.Move(text, savePath);
				}
			}
			catch (Exception ex)
			{
				persistenceReady = false;
				Status = "Cooler Mod could not save; storage actions are paused.";
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
			}
		}

		public void Send(string action, int index = -1, Vector3 position = default(Vector3), Vector3 normal = default(Vector3), int serial = 0, string text = null)
		{
			//IL_004a: 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_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)
			if ((Object)(object)Player.LocalPlayer == (Object)null)
			{
				Status = "Load into a game first.";
				return;
			}
			Command command = new Command
			{
				action = action,
				text = text,
				serial = ((serial > 0) ? serial : Selected),
				index = index,
				position = position,
				normal = normal,
				sequence = ++sequence
			};
			if (InstanceFinder.IsServerStarted)
			{
				Execute(Player.LocalPlayer, command, null);
			}
			else if ((Object)(object)manager != (Object)null && InstanceFinder.IsClientStarted)
			{
				manager.ClientManager.Broadcast<RequestMessage>(new RequestMessage
				{
					json = Codec.ToJson(command)
				}, (Channel)0);
				if (action != "hello")
				{
					Status = "Waiting for the host...";
				}
			}
		}

		private void Receive(NetworkConnection connection, RequestMessage message, Channel channel)
		{
			if (!InstanceFinder.IsServerStarted || message.json == null || message.json.Length > 2048)
			{
				return;
			}
			try
			{
				Command command = Codec.FromJson<Command>(message.json);
				if (command != null && command.protocol == 1 && command.sequence > 0 && (!lastSequence.TryGetValue(connection.ClientId, out var value) || command.sequence > value) && (!rateLimit.TryGetValue(connection.ClientId, out var value2) || !(Time.unscaledTime - value2 < 0.1f)))
				{
					lastSequence[connection.ClientId] = command.sequence;
					rateLimit[connection.ClientId] = Time.unscaledTime;
					Player val = ((IEnumerable<Player>)Object.FindObjectsByType<Player>()).FirstOrDefault((Func<Player, bool>)((Player p) => ((NetworkBehaviour)p).Owner == connection));
					if ((Object)(object)val != (Object)null)
					{
						Execute(val, command, connection);
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Rejected Cooler Mod request: " + ex.Message));
			}
		}

		private void Respond(Command cmd, NetworkConnection connection, string message, int selected = 0)
		{
			Reply value = new Reply
			{
				sequence = cmd.sequence,
				serial = selected,
				message = message
			};
			if (connection == (NetworkConnection)null || connection.IsLocalClient)
			{
				Status = message;
				if (selected > 0)
				{
					Selected = selected;
				}
			}
			else
			{
				manager.ServerManager.Broadcast<ReplyMessage>(connection, new ReplyMessage
				{
					json = Codec.ToJson(value)
				}, true, (Channel)0);
			}
		}

		private void ReceiveReply(ReplyMessage message, Channel channel)
		{
			Reply reply = Codec.FromJson<Reply>(message.json);
			if (reply != null)
			{
				Status = reply.message;
				if (reply.serial > 0)
				{
					Selected = reply.serial;
				}
			}
		}

		private void ReceiveState(StateMessage message, Channel channel)
		{
			if (!InstanceFinder.IsServerStarted && message.json != null && message.json.Length <= 500000)
			{
				Snapshot snapshot = Codec.FromJson<Snapshot>(message.json);
				if (snapshot != null && snapshot.protocol == 1 && snapshot.coolers != null)
				{
					Current = snapshot.coolers;
				}
			}
		}

		private void Broadcast()
		{
			if ((Object)(object)manager != (Object)null && world != null)
			{
				manager.ServerManager.Broadcast<StateMessage>(new StateMessage
				{
					json = Codec.ToJson(new Snapshot
					{
						world = world.name,
						coolers = Current
					})
				}, true, (Channel)0);
			}
		}

		private void ScanCoolers()
		{
			coolers.Clear();
			Item[] array = Object.FindObjectsByType<Item>((FindObjectsInactive)1);
			foreach (Item val in array)
			{
				if (CoolerItem.Is(val) && ((NetworkBehaviour)val).IsSpawned && !((NetworkBehaviour)val).IsDeinitializing)
				{
					int num = CoolerItem.Serial(val);
					if (num > 0 && !coolers.ContainsKey(num))
					{
						coolers.Add(num, val);
					}
				}
			}
		}

		private Item FindCooler(int serial)
		{
			if (coolers.TryGetValue(serial, out var value) && (Object)(object)value != (Object)null && ((NetworkBehaviour)value).IsSpawned && !((NetworkBehaviour)value).IsDeinitializing)
			{
				return value;
			}
			value = ((IEnumerable<Item>)Object.FindObjectsByType<Item>((FindObjectsInactive)1)).FirstOrDefault((Func<Item, bool>)((Item i) => CoolerItem.Is(i) && ((NetworkBehaviour)i).IsSpawned && !((NetworkBehaviour)i).IsDeinitializing && CoolerItem.Serial(i) == serial));
			if ((Object)(object)value != (Object)null)
			{
				coolers[serial] = value;
			}
			return value;
		}

		private void AuditWorld()
		{
			//IL_010c: 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_012a: 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)
			ScanCoolers();
			foreach (KeyValuePair<int, Item> cooler in coolers)
			{
				Item value = cooler.Value;
				CoolerData coolerData = Find(cooler.Key);
				if (coolerData == null)
				{
					Player syncedHolder = value.SyncedHolder;
					coolerData = new CoolerData
					{
						serial = cooler.Key,
						name = DefaultCoolerName(cooler.Key),
						owner = (((Object)(object)syncedHolder == (Object)null) ? 0 : syncedHolder.SteamID),
						ownerName = (((Object)(object)syncedHolder == (Object)null) ? null : syncedHolder.SteamName)
					};
					Current.Add(coolerData);
					save.nextSerial = Math.Max(save.nextSerial, cooler.Key + 1);
				}
				Normalize(coolerData);
				coolerData.available = true;
				if ((Object)(object)value.SyncedHolder != (Object)null)
				{
					coolerData.deployed = false;
				}
				else if (coolerData.deployed)
				{
					value.RigidbodySync.SetKinematic(true);
					if (Vector3.Distance(((Component)value).transform.position, coolerData.position) > 0.05f)
					{
						value.RigidbodySync.TeleportToPosRot(coolerData.position, coolerData.Rotation, (float[])null, (Quaternion[])null);
					}
				}
			}
			foreach (CoolerData item in Current)
			{
				item.available = coolers.ContainsKey(item.serial);
			}
		}

		private int OpenSlot(Player player)
		{
			int num = (int)AccessTools.Method(typeof(PlayerInventory), "GetTotalSlots", (Type[])null, (Type[])null).Invoke(player.Inventory, null);
			Item val = default(Item);
			for (byte b = 0; b < num; b++)
			{
				if (!player.Inventory._items.TryGetValue(b, ref val) || (Object)(object)val == (Object)null)
				{
					return b;
				}
			}
			return -1;
		}

		private Item SpawnSaved(SavedItem state, Vector3 position, Player holder = null, int slot = -1)
		{
			//IL_003d: 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_0094: 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)
			Item val = ((state == null || !state.Exists) ? null : GameInfo.GetSpawnable(state.ItemID));
			if ((Object)(object)val == (Object)null || (Object)(object)((Component)val).GetComponent<Fish>() == (Object)null)
			{
				throw new Exception("Stored fish prefab is unavailable.");
			}
			Item val2 = Object.Instantiate<Item>(val, position, Quaternion.identity, Server.Instance.DynamicObjectsHolder);
			val2.LoadFromSave(state);
			if ((Object)(object)val2.Creature != (Object)null)
			{
				val2.Creature.ServerKillOnSpawn();
				if (state.IsDripCreature)
				{
					val2.Creature.SetDrip();
				}
			}
			InstanceFinder.ServerManager.Spawn(((Component)val2).gameObject, (NetworkConnection)null, default(Scene));
			val2.ServerSetSkin(state.SkinIndex);
			if ((Object)(object)holder != (Object)null && slot >= 0)
			{
				val2.SetSyncedHolder(holder, true);
				holder.Inventory.AddItem((byte)slot, val2);
				if (!holder.Inventory.HasItemInInventory(val2))
				{
					InstanceFinder.ServerManager.Despawn(((Component)val2).gameObject, (DespawnType?)null);
					throw new Exception("Inventory did not accept the fish.");
				}
			}
			else
			{
				val2.SetSyncedHolder((Player)null, true);
				val2.ReconcileLocalHolderWithSyncedHolder();
				val2.RigidbodySync.SetKinematic(false);
				val2.RigidbodySync.ServerSetSyncedSimulator(((NetworkBehaviour)Server.Instance).Owner);
			}
			return val2;
		}

		private Item SpawnCooler(Player player, int slot, int serial)
		{
			//IL_000b: 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_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_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)
			//IL_003c: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0078: 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)
			Item val = Object.Instantiate<Item>(CoolerItem.Prefab, ((Component)player).transform.position + Vector3.up, Quaternion.identity, Server.Instance.DynamicObjectsHolder);
			val.LoadFromSave(new SavedItem
			{
				Exists = true,
				ItemID = 249,
				BettingMultiplier = serial,
				Weight = 1f,
				KillScoreMultiplier = 1f
			});
			InstanceFinder.ServerManager.Spawn(((Component)val).gameObject, (NetworkConnection)null, default(Scene));
			val.SetSyncedHolder(player, true);
			player.Inventory.AddItem((byte)slot, val);
			if (!player.Inventory.HasItemInInventory(val))
			{
				InstanceFinder.ServerManager.Despawn(((Component)val).gameObject, (DespawnType?)null);
				throw new Exception("Inventory did not accept the cooler.");
			}
			return val;
		}

		private static SavedItem Capture(Item item)
		{
			//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_000c: 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_0024: 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_0055: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			return new SavedItem
			{
				Exists = true,
				ItemID = item.ID,
				Cookness = item.Cookness,
				BettingMultiplier = item.BettingMultiplier,
				Weight = (Object.op_Implicit((Object)(object)item.Creature) ? ((Item)item.Creature).RandomizedWeight : 1f),
				KillScoreMultiplier = item.KillScoreMultiplier,
				IsDripCreature = (Object.op_Implicit((Object)(object)item.Creature) && item.Creature.IsDrip),
				SkinIndex = item.CurSkin
			};
		}

		private static void RemoveHeld(Player player, Item item)
		{
			//IL_0076: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			player.Inventory.RemoveItem(item);
			if ((Object)(object)player.Holding.HeldItem == (Object)(object)item)
			{
				player.Hands.DropItem(false, item);
				player.Holding.DropItem(false, item);
				player.Holding.SetHeldItem((Item)null);
			}
			if ((Object)(object)player.Holding.UninitializedHeldItem == (Object)(object)item)
			{
				player.Holding.SetUninitializedHeldItem((Item)null);
			}
			if ((Object)(object)item.Holder != (Object)null)
			{
				item.Drop(false, default(Vector3), default(Vector3));
			}
			item.SpawnFromInventory();
			item.SetSyncedHolder((Player)null, true);
			item.ReconcileLocalHolderWithSyncedHolder();
			InstanceFinder.ServerManager.Despawn(((Component)item).gameObject, (DespawnType?)null);
		}

		private bool Ground(Player player, Command cmd, Item cooler, out RaycastHit hit)
		{
			//IL_0002: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: 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_0091: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			hit = default(RaycastHit);
			if (!Rules.Finite(cmd.position.x) || !Rules.Finite(cmd.position.y) || !Rules.Finite(cmd.position.z) || !Rules.SurfaceAllowed(cmd.normal.y) || Vector3.Distance(cmd.position, player.CamObject.position) > 8.35f)
			{
				return false;
			}
			Vector3 normalized = ((Vector3)(ref cmd.normal)).normalized;
			foreach (RaycastHit item in from h in Physics.RaycastAll(cmd.position + normalized * 0.35f, -normalized, 0.8f, -1, (QueryTriggerInteraction)1)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (((Component)((RaycastHit)(ref current)).collider).gameObject.layer != LayerMask.NameToLayer("Water") && !((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Player>() != (Object)null) && !((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Item>() != (Object)null) && Rules.SurfaceAllowed(((RaycastHit)(ref current)).normal.y) && !(Vector3.Dot(((RaycastHit)(ref current)).normal, normalized) < 0.5f))
				{
					hit = current;
					return true;
				}
			}
			return false;
		}

		private float Distance(Player player, Item item)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			return Mathf.Min(Vector3.Distance(((Component)player).transform.position, ((Component)item).transform.position), ((Object)(object)player.CamObject == (Object)null) ? float.MaxValue : Vector3.Distance(player.CamObject.position, ((Component)item).transform.position));
		}

		private void Execute(Player player, Command cmd, NetworkConnection connection)
		{
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_070d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0712: Unknown result type (might be due to invalid IL or missing references)
			//IL_0717: Unknown result type (might be due to invalid IL or missing references)
			//IL_0721: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0730: Unknown result type (might be due to invalid IL or missing references)
			//IL_0650: Unknown result type (might be due to invalid IL or missing references)
			//IL_0655: Unknown result type (might be due to invalid IL or missing references)
			//IL_065a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			if (cmd.action == "hello")
			{
				Broadcast();
				return;
			}
			if (!persistenceReady || world == null || (Object)(object)CoolerItem.Prefab == (Object)null || player.Dying.IsDead)
			{
				Respond(cmd, connection, "Cooler Mod is not ready on the host.");
				return;
			}
			ScanCoolers();
			try
			{
				if (cmd.action == "buy")
				{
					if ((Object)(object)FocusedMoneyVendor(player, 5f) == (Object)null)
					{
						Respond(cmd, connection, "Move close to and look at a fish-selling vendor to buy a cooler.");
						return;
					}
					int num = OpenSlot(player);
					if (num < 0)
					{
						Respond(cmd, connection, "Free an inventory slot before buying a cooler.");
						return;
					}
					if (!Wallet.Charge(player, 1000))
					{
						Respond(cmd, connection, "You need $" + 1000.ToString("N0") + " to buy a cooler.");
						return;
					}
					int num2 = save.nextSerial++;
					try
					{
						SpawnCooler(player, num, num2);
					}
					catch
					{
						Wallet.Credit(player, 1000);
						throw;
					}
					Current.Add(new CoolerData
					{
						serial = num2,
						name = DefaultCoolerName(num2),
						owner = player.SteamID,
						ownerName = player.SteamName
					});
					Persist();
					Broadcast();
					Respond(cmd, connection, "Reusable cooler purchased and added to your inventory.", num2);
					return;
				}
				CoolerData coolerData = Find(cmd.serial);
				Item val = FindCooler(cmd.serial);
				if (coolerData == null || (Object)(object)val == (Object)null)
				{
					Respond(cmd, connection, "That cooler is unavailable.");
					return;
				}
				bool flag = (Object)(object)val.SyncedHolder == (Object)(object)player;
				float num3 = Distance(player, val);
				if (!flag && num3 > 5.35f)
				{
					Respond(cmd, connection, "Move within " + 5f.ToString("0") + " metres of the cooler.");
					return;
				}
				if (cmd.action == "deploy")
				{
					if (!flag || coolerData.deployed)
					{
						Respond(cmd, connection, "Hold that cooler before deploying it.");
						return;
					}
					if (!Ground(player, cmd, val, out var hit))
					{
						Respond(cmd, connection, "Look at an upward-facing surface within 8 metres.");
						return;
					}
					val.SpawnFromInventory();
					player.Inventory.RemoveItem(val);
					if ((Object)(object)val.Holder != (Object)null)
					{
						val.Drop(false, default(Vector3), default(Vector3));
					}
					val.SetSyncedHolder((Player)null, true);
					val.ReconcileLocalHolderWithSyncedHolder();
					if ((Object)(object)player.Holding.HeldItem == (Object)(object)val)
					{
						player.Hands.DropItem(false, val);
						player.Holding.DropItem(false, val);
					}
					if ((Object)(object)player.Holding.UninitializedHeldItem == (Object)(object)val)
					{
						player.Holding.SetUninitializedHeldItem((Item)null);
					}
					coolerData.position = ((RaycastHit)(ref hit)).point + ((RaycastHit)(ref hit)).normal * 0.015f;
					coolerData.surfaceNormal = ((RaycastHit)(ref hit)).normal;
					Quaternion curPlayerRot = player.CurPlayerRot;
					coolerData.yaw = ((Quaternion)(ref curPlayerRot)).eulerAngles.y;
					coolerData.deployed = true;
					val.RigidbodySync.ServerSetSyncedSimulator(((NetworkBehaviour)Server.Instance).Owner);
					val.RigidbodySync.TeleportToPosRot(coolerData.position, coolerData.Rotation, (float[])null, (Quaternion[])null);
					val.RigidbodySync.SetKinematic(true);
					Status = "Cooler deployed.";
				}
				else if (cmd.action == "pickup")
				{
					if (flag)
					{
						Respond(cmd, connection, "The cooler is already in your inventory.");
						return;
					}
					int num4 = OpenSlot(player);
					bool emptyHands = (Object)(object)player.Holding.HeldItem == (Object)null && (Object)(object)player.Holding.UninitializedHeldItem == (Object)null && (Object)(object)player.Inventory.SyncedCurItem == (Object)null;
					if (!Rules.CanPickUp(num4 >= 0, emptyHands))
					{
						Respond(cmd, connection, "Free an inventory slot or empty your hands first.");
						return;
					}
					coolerData.deployed = false;
					val.RigidbodySync.SetKinematic(false);
					int value = player.Inventory._syncedCurSlot.Value;
					val.SetSyncedHolder(player, true);
					if (num4 >= 0)
					{
						player.Inventory.AddItem((byte)num4, val);
					}
					val.ReconcileLocalHolderWithSyncedHolder();
					if (num4 >= 0)
					{
						player.Inventory.ServerSetSyncedCurSlot(value);
					}
					Status = "Cooler picked up with " + coolerData.fish.Count + " fish inside.";
				}
				else if (cmd.action == "insert")
				{
					if (!coolerData.deployed)
					{
						Respond(cmd, connection, "Deploy the cooler before storing fish.");
						return;
					}
					if (coolerData.fish.Count >= 20)
					{
						Respond(cmd, connection, "The cooler is full (20 / 20).");
						return;
					}
					Item heldItem = player.Holding.HeldItem;
					if ((Object)(object)heldItem == (Object)null || (Object)(object)heldItem.Fish == (Object)null)
					{
						Respond(cmd, connection, "Hold a fish before using Store fish.");
						return;
					}
					string name = heldItem.GetName();
					int value2 = Mathf.Max(0, heldItem.TotalWorth);
					coolerData.fish.Add(Capture(heldItem));
					coolerData.fishInfo.Add(new StoredFishInfo
					{
						name = name,
						value = value2
					});
					RemoveHeld(player, heldItem);
					FishPreviews.Clear();
					Status = name + " stored in the cooler (" + coolerData.fish.Count + " / 20).";
				}
				else if (cmd.action == "take")
				{
					if (cmd.index < 0 || cmd.index >= coolerData.fish.Count)
					{
						Respond(cmd, connection, "That cooler slot is empty.");
						return;
					}
					int num5 = OpenSlot(player);
					if (num5 < 0)
					{
						Respond(cmd, connection, "Free an inventory slot first.");
						return;
					}
					SavedItem state = coolerData.fish[cmd.index];
					string text = StoredName(coolerData, cmd.index);
					SpawnSaved(state, ((Component)player).transform.position + Vector3.up, player, num5);
					RemoveStored(coolerData, cmd.index);
					Status = text + " moved to your inventory.";
				}
				else if (cmd.action == "drop")
				{
					if (cmd.index < 0 || cmd.index >= coolerData.fish.Count)
					{
						Respond(cmd, connection, "That cooler slot is empty.");
						return;
					}
					SavedItem state2 = coolerData.fish[cmd.index];
					string text2 = StoredName(coolerData, cmd.index);
					Vector3 position = ((Component)val).transform.position + ((Component)val).transform.forward * 1.25f + Vector3.up * 0.5f;
					SpawnSaved(state2, position);
					RemoveStored(coolerData, cmd.index);
					Status = text2 + " dropped beside the cooler.";
				}
				else if (cmd.action == "sellall")
				{
					if (!flag || (Object)(object)player.Holding.HeldItem != (Object)(object)val)
					{
						Respond(cmd, connection, "Hold the cooler while interacting with the fish vendor.");
						return;
					}
					if (coolerData.fish.Count == 0)
					{
						Respond(cmd, connection, "The cooler is empty.");
						return;
					}
					if ((Object)(object)FocusedMoneyVendor(player, 5f) == (Object)null)
					{
						Respond(cmd, connection, "Move close to and look at the fish-selling vendor.");
						return;
					}
					long num6 = 0L;
					for (int i = 0; i < coolerData.fish.Count; i++)
					{
						num6 += StoredValue(coolerData, i);
					}
					int num7 = (int)Math.Min(2147483647L, num6);
					int count = coolerData.fish.Count;
					if (num7 <= 0)
					{
						Respond(cmd, connection, "The stored fish have no sale value.");
						return;
					}
					Wallet.Credit(player, num7);
					coolerData.fish.Clear();
					coolerData.fishInfo.Clear();
					FishPreviews.Clear();
					Status = "Sold " + count + " fish from the cooler for $" + num7.ToString("N0") + ". The empty cooler is still in your hands.";
				}
				else
				{
					if (!(cmd.action == "rename"))
					{
						return;
					}
					if (coolerData.owner != 0L && coolerData.owner != player.SteamID)
					{
						Respond(cmd, connection, "Only the cooler owner can rename it.");
						return;
					}
					coolerData.name = CleanName(cmd.text, coolerData.serial);
					Status = "Cooler renamed to " + coolerData.name + ".";
				}
				Persist();
				Broadcast();
				Respond(cmd, connection, Status, coolerData.serial);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)ex);
				Respond(cmd, connection, "Cooler Mod could not complete that action. Check the BepInEx log.");
			}
		}

		public static bool IsMoneyVendor(NPC npc)
		{
			if ((Object)(object)npc == (Object)null)
			{
				return false;
			}
			FieldInfo fieldInfo = AccessTools.Field(typeof(NPC), "_quests");
			return ((fieldInfo == null) ? null : (fieldInfo.GetValue(npc) as IEnumerable<NPCQuest>))?.Any((NPCQuest q) => (Object)(object)q != (Object)null && (int)q.Type == 1) ?? false;
		}

		public void SetHoveredInteractable(Component value, bool active)
		{
			if (active)
			{
				hoveredInteractable = value;
			}
			else if ((Object)(object)hoveredInteractable == (Object)(object)value)
			{
				hoveredInteractable = null;
			}
		}

		private static NPC VendorFrom(Component component)
		{
			if ((Object)(object)component == (Object)null)
			{
				return null;
			}
			NPC componentInParent = component.GetComponentInParent<NPC>();
			if (!((Object)(object)componentInParent != (Object)null))
			{
				return component.GetComponentInChildren<NPC>(true);
			}
			return componentInParent;
		}

		public NPC FocusedMoneyVendor(Player player, float range)
		{
			//IL_0074: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || (Object)(object)player.CamObject == (Object)null)
			{
				return null;
			}
			if ((Object)(object)player == (Object)(object)Player.LocalPlayer && (Object)(object)hoveredInteractable != (Object)null)
			{
				NPC val = VendorFrom(hoveredInteractable);
				if (IsMoneyVendor(val) && Vector3.Distance(((Component)player).transform.position, ((Component)val).transform.position) <= range + 0.35f)
				{
					return val;
				}
			}
			foreach (RaycastHit item in from h in Physics.RaycastAll(player.CamObject.position, player.CamObject.forward, range, -1, (QueryTriggerInteraction)2)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (!((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Player>() == (Object)(object)player))
				{
					NPC componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<NPC>();
					if (IsMoneyVendor(componentInParent))
					{
						return componentInParent;
					}
					if (!((RaycastHit)(ref current)).collider.isTrigger)
					{
						break;
					}
				}
			}
			NPC result = null;
			float num = 0.72f;
			RaycastHit val3 = default(RaycastHit);
			foreach (NPC item2 in Object.FindObjectsByType<NPC>().Where(IsMoneyVendor))
			{
				Vector3 val2 = (((Object)(object)item2.MouthPosForItems != (Object)null) ? item2.MouthPosForItems.position : (((Component)item2).transform.position + Vector3.up)) - player.CamObject.position;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				if (!(magnitude <= 0.01f))
				{
					float num2 = Vector3.Dot(player.CamObject.forward, val2 / magnitude);
					if (Rules.CanUseVendor(magnitude, num2) && !(num2 < num) && Physics.Raycast(player.CamObject.position, val2 / magnitude, ref val3, magnitude + 0.5f, -1, (QueryTriggerInteraction)2) && !((Object)(object)((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<NPC>() != (Object)(object)item2))
					{
						result = item2;
						num = num2;
					}
				}
			}
			return result;
		}

		public static Item FishPrefab(SavedItem fish)
		{
			if (fish == null || !fish.Exists)
			{
				return null;
			}
			Item spawnable = GameInfo.GetSpawnable(fish.ItemID);
			if (!((Object)(object)spawnable != (Object)null) || !((Object)(object)((Component)spawnable).GetComponent<Fish>() != (Object)null))
			{
				return null;
			}
			return spawnable;
		}

		public static string FishName(SavedItem fish)
		{
			Item val = FishPrefab(fish);
			if (!((Object)(object)val == (Object)null))
			{
				return val.GetName();
			}
			return "Unknown fish";
		}

		public static float CookMultiplier(SavedItem fish)
		{
			if (fish != null)
			{
				return GameInfo.CooknessWorthCurve.Evaluate(fish.Cookness);
			}
			return 0f;
		}

		public static float ScoreMultiplier(SavedItem fish)
		{
			return fish?.KillScoreMultiplier ?? 0f;
		}

		public static int FishValue(SavedItem fish)
		{
			Item val = FishPrefab(fish);
			if ((Object)(object)val == (Object)null)
			{
				return 0;
			}
			float num = Mathf.Max(0f, fish.Weight);
			float num2 = Mathf.Max(0f, fish.BettingMultiplier);
			float num3 = Mathf.Max(0f, fish.KillScoreMultiplier);
			int num4 = (int)((float)val.DefaultWorth * num * CookMultiplier(fish) * num2);
			return Mathf.Max(0, (int)((float)num4 * num3));
		}

		public int WholeCoolerValue(Item item)
		{
			CoolerData coolerData = (((Object)(object)item == (Object)null) ? null : Find(CoolerItem.Serial(item)));
			long num = 500L;
			if (coolerData != null && coolerData.fish != null)
			{
				for (int i = 0; i < coolerData.fish.Count; i++)
				{
					num += StoredValue(coolerData, i);
				}
			}
			return (int)Math.Min(2147483647L, num);
		}

		public void CompleteWholeCoolerSale(Item item)
		{
			if (!InstanceFinder.IsServerStarted || (Object)(object)item == (Object)null)
			{
				return;
			}
			int num = CoolerItem.Serial(item);
			CoolerData coolerData = Find(num);
			if (coolerData != null)
			{
				int num2 = ((coolerData.fish != null) ? coolerData.fish.Count : 0);
				int num3 = WholeCoolerValue(item);
				Current.Remove(coolerData);
				coolers.Remove(num);
				if (Selected == num)
				{
					Selected = 0;
					Toggle(show: false);
				}
				Status = "Sold cooler and " + num2 + " stored fish for $" + num3.ToString("N0") + ".";
				Persist();
				Broadcast();
			}
		}

		private void OnDestroy()
		{
			Persist();
			Toggle(show: false);
			VendorDisplays.Clear();
			FishPreviews.Clear();
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Instance = null;
		}

		public static bool IsDeployed(Item item)
		{
			if ((Object)(object)Instance != (Object)null && CoolerItem.Is(item) && (Object)(object)item.SyncedHolder == (Object)null)
			{
				return Instance.Find(CoolerItem.Serial(item))?.deployed ?? false;
			}
			return false;
		}

		private Item RayCooler(float range)
		{
			//IL_0025: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			Player localPlayer = Player.LocalPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)localPlayer.CamObject == (Object)null)
			{
				return null;
			}
			foreach (RaycastHit item in from h in Physics.RaycastAll(localPlayer.CamObject.position, localPlayer.CamObject.forward, range, -1, (QueryTriggerInteraction)2)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if ((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Player>() == (Object)(object)localPlayer)
				{
					continue;
				}
				Item componentInParent = ((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Item>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent.SyncedHolder == (Object)(object)localPlayer)
				{
					continue;
				}
				if (CoolerItem.Is(componentInParent) && (Object)(object)componentInParent.SyncedHolder == (Object)null)
				{
					CoolerData coolerData = Find(CoolerItem.Serial(componentInParent));
					if (coolerData != null && coolerData.deployed)
					{
						return componentInParent;
					}
				}
				if (!((RaycastHit)(ref current)).collider.isTrigger)
				{
					return null;
				}
			}
			return null;
		}

		private NPC RayMoneyVendor(float range)
		{
			return FocusedMoneyVendor(Player.LocalPlayer, range);
		}

		private Item InteractionTarget()
		{
			Player localPlayer = Player.LocalPlayer;
			if ((Object)(object)localPlayer == (Object)null || Open || localPlayer.BlockInputs || localPlayer.Dying.IsDead)
			{
				return null;
			}
			Item heldItem = localPlayer.Holding.HeldItem;
			if (CoolerItem.Is(heldItem))
			{
				return heldItem;
			}
			return RayCooler(5f);
		}

		public bool CapturesInteract()
		{
			if (!((Object)(object)InteractionTarget() != (Object)null))
			{
				return (Object)(object)activeTarget != (Object)null;
			}
			return true;
		}

		private bool CrosshairSurface(Item held, out RaycastHit surface)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			surface = default(RaycastHit);
			Player localPlayer = Player.LocalPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return false;
			}
			foreach (RaycastHit item in from h in Physics.RaycastAll(localPlayer.CamObject.position, localPlayer.CamObject.forward, 8f, -1, (QueryTriggerInteraction)1)
				orderby ((RaycastHit)(ref h)).distance
				select h)
			{
				RaycastHit current = item;
				if (!((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Player>() == (Object)(object)localPlayer) && !((Object)(object)((Component)((RaycastHit)(ref current)).collider).GetComponentInParent<Item>() == (Object)(object)held))
				{
					if (((Component)((RaycastHit)(ref current)).collider).gameObject.layer == LayerMask.NameToLayer("Water") || !Rules.SurfaceAllowed(((RaycastHit)(ref current)).normal.y))
					{
						return false;
					}
					surface = current;
					return true;
				}
			}
			return false;
		}

		private void DeployHeld(Item held)
		{
			//IL_002c: 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)
			Selected = CoolerItem.Serial(held);
			if (!CrosshairSurface(held, out var surface))
			{
				Status = "Look at an upward-facing surface within 8 metres.";
			}
			else
			{
				Send("deploy", -1, ((RaycastHit)(ref surface)).point, ((RaycastHit)(ref surface)).normal);
			}
		}

		private void TapUse(Item target)
		{
			//IL_00d9: 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_00e2: 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_006a: 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_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)
			Player localPlayer = Player.LocalPlayer;
			if ((Object)(object)localPlayer == (Object)null || (Object)(object)target == (Object)null)
			{
				return;
			}
			int serial = (Selected = CoolerItem.Serial(target));
			if ((Object)(object)target.SyncedHolder == (Object)(object)localPlayer)
			{
				CoolerData coolerData = Find(serial);
				if ((Object)(object)RayMoneyVendor(5f) != (Object)null && coolerData != null && coolerData.fish.Count > 0)
				{
					Send("sellall");
				}
				else
				{
					Status = ((coolerData != null && coolerData.fish.Count == 0) ? "The cooler is empty. Hold E while looking at a surface to deploy it." : "Look at the fish-selling vendor and tap E to sell the cooler contents.");
				}
			}
			else if ((Object)(object)localPlayer.Holding.HeldItem != (Object)null && (Object)(object)localPlayer.Holding.HeldItem.Fish != (Object)null)
			{
				Send("insert");
			}
			else
			{
				Toggle(show: true, serial);
			}
		}

		private void UpdateInteraction()
		{
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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)
			Keyboard current = Keyboard.current;
			if (current == null)
			{
				return;
			}
			if (((ButtonControl)current.eKey).wasPressedThisFrame)
			{
				activeTarget = InteractionTarget();
				useStarted = Time.unscaledTime;
				holdFired = false;
			}
			if ((Object)(object)activeTarget != (Object)null && ((ButtonControl)current.eKey).isPressed && !holdFired && Time.unscaledTime - useStarted >= 1f)
			{
				holdFired = true;
				if ((Object)(object)activeTarget.SyncedHolder == (Object)(object)Player.LocalPlayer)
				{
					DeployHeld(activeTarget);
				}
				else
				{
					Selected = CoolerItem.Serial(activeTarget);
					Send("pickup");
				}
			}
			if (((ButtonControl)current.eKey).wasReleasedThisFrame)
			{
				if ((Object)(object)activeTarget != (Object)null && !holdFired)
				{
					TapUse(activeTarget);
				}
				activeTarget = null;
				holdFired = false;
			}
			if (!((ButtonControl)current.eKey).isPressed && !((ButtonControl)current.eKey).wasReleasedThisFrame && (Object)(object)activeTarget != (Object)null && Time.unscaledTime - useStarted > 2f)
			{
				activeTarget = null;
				holdFired = false;
			}
		}

		private void DrawInteractionHint()
		{
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: 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_0172: Expected O, but got Unknown
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			if (Open)
			{
				return;
			}
			Item val = activeTarget ?? InteractionTarget();
			if (!((Object)(object)val == (Object)null))
			{
				Player localPlayer = Player.LocalPlayer;
				CoolerData coolerData = Find(CoolerItem.Serial(val));
				bool num = (Object)(object)val.SyncedHolder == (Object)(object)localPlayer;
				bool flag = num && (Object)(object)RayMoneyVendor(5f) != (Object)null;
				string text = (num ? ((flag && coolerData != null && coolerData.fish.Count > 0) ? ("Tap E: sell all " + coolerData.fish.Count + " fish and keep cooler   |   Hold E: deploy") : "Hold E to deploy cooler") : ((!((Object)(object)localPlayer != (Object)null) || !((Object)(object)localPlayer.Holding.HeldItem != (Object)null) || !((Object)(object)localPlayer.Holding.HeldItem.Fish != (Object)null)) ? "Tap E: open cooler   |   Hold E: pick up cooler" : "Tap E: store held fish   |   Hold E: pick up cooler"));
				if ((Object)(object)activeTarget != (Object)null && (Object)(object)InputSystem.settings != (Object)null && ((ButtonControl)Keyboard.current.eKey).isPressed)
				{
					text = text + "   " + Mathf.Clamp01((Time.unscaledTime - useStarted) / 1f).ToString("P0");
				}
				if (hintStyle == null)
				{
					hintStyle = new GUIStyle(GUI.skin.box)
					{
						fontSize = 15,
						fontStyle = (FontStyle)1,
						alignment = (TextAnchor)4
					};
				}
				float num2 = (flag ? ((float)Screen.height * 0.67f + 82f) : ((float)Screen.height * 0.73f));
				GUI.Box(new Rect((float)Screen.width / 2f - 300f, num2, 600f, 42f), text, hintStyle);
			}
		}

		private Texture2D Solid(Color color)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0012: 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_0020: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, color);
			val.Apply();
			((Texture)val).wrapMode = (TextureWrapMode)1;
			return val;
		}

		private GUIStyle Button(Texture2D normal, Texture2D hover)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: 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_004d: 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_006f: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.button)
			{
				fontSize = 12,
				fontStyle = (FontStyle)1,
				alignment = (TextAnchor)4
			};
			val.normal.background = normal;
			val.normal.textColor = Color.white;
			val.hover.background = hover;
			val.hover.textColor = Color.white;
			val.active.background = orangeHover;
			return val;
		}

		private void InitStyles()
		{
			//IL_001f: 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_005f: 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_009f: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0128: Expected O, but got Unknown
			//IL_012d: Expected O, but got Unknown
			//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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_01ba: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: 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_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: 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_023b: Expected O, but got Unknown
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: 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_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			if (windowStyle == null)
			{
				navy = Solid(new Color(0.035f, 0.075f, 0.095f, 0.985f));
				teal = Solid(new Color(0.03f, 0.46f, 0.54f));
				tealHover = Solid(new Color(0.04f, 0.66f, 0.74f));
				orange = Solid(new Color(0.85f, 0.37f, 0.08f));
				orangeHover = Solid(new Color(1f, 0.52f, 0.1f));
				rowBg = Solid(new Color(0.06f, 0.12f, 0.14f, 0.98f));
				rowAlt = Solid(new Color(0.075f, 0.15f, 0.17f, 0.98f));
				GUIStyle val = new GUIStyle(GUI.skin.window);
				val.normal.background = navy;
				val.padding = new RectOffset(0, 0, 0, 0);
				windowStyle = val;
				GUIStyle val2 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 25,
					fontStyle = (FontStyle)1
				};
				val2.normal.textColor = new Color(0.45f, 1f, 1f);
				titleStyle = val2;
				GUIStyle val3 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 14,
					fontStyle = (FontStyle)1,
					alignment = (TextAnchor)3
				};
				val3.normal.textColor = new Color(1f, 0.66f, 0.25f);
				headerStyle = val3;
				GUIStyle val4 = new GUIStyle(GUI.skin.label)
				{
					fontSize = 12,
					wordWrap = false,
					alignment = (TextAnchor)3
				};
				val4.normal.textColor = new Color(0.9f, 0.96f, 0.96f);
				rowStyle = val4;
				GUIStyle val5 = new GUIStyle(rowStyle)
				{
					alignment = (TextAnchor)4
				};
				val5.normal.textColor = new Color(0.45f, 0.6f, 0.62f);
				emptyStyle = val5;
				GUIStyle val6 = new GUIStyle(rowStyle)
				{
					fontSize = 13,
					fontStyle = (FontStyle)1
				};
				val6.normal.textColor = new Color(0.42f, 1f, 0.7f);
				statusStyle = val6;
				buttonStyle = Button(teal, tealHover);
				dropStyle = Button(orange, orangeHover);
			}
		}

		public void Toggle(bool show, int serial = 0)
		{
			//IL_0063: 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: Invalid comparison between Unknown and I4
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Invalid comparison between Unknown and I4
			if (serial > 0)
			{
				Selected = serial;
			}
			if (Open == show)
			{
				return;
			}
			if (show)
			{
				oldLock = Cursor.lockState;
				Open = true;
				try
				{
					PlayerCamera.ToggleMouse(true);
				}
				catch
				{
				}
				Cursor.lockState = (CursorLockMode)0;
				Cursor.visible = true;
				return;
			}
			Open = false;
			FishPreviews.Trim();
			try
			{
				PlayerCamera.ToggleMouse((int)oldLock != 1);
			}
			catch
			{
				Cursor.lockState = oldLock;
				Cursor.visible = (int)oldLock != 1;
			}
		}

		private void OnGUI()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0106: 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)
			DrawInteractionHint();
			DrawVendorPrompt();
			if (Open)
			{
				InitStyles();
				GUI.depth = -12000;
				float num = Mathf.Min(1f, Mathf.Min((float)Screen.width / 1180f, (float)Screen.height / 710f));
				Matrix4x4 matrix = GUI.matrix;
				GUI.matrix = Matrix4x4.Scale(Vector3.one * num);
				((Rect)(ref panel)).x = Mathf.Clamp(((Rect)(ref panel)).x, 0f, Mathf.Max(0f, (float)Screen.width / num - ((Rect)(ref panel)).width));
				((Rect)(ref panel)).y = Mathf.Clamp(((Rect)(ref panel)).y, 0f, Mathf.Max(0f, (float)Screen.height / num - ((Rect)(ref panel)).height));
				panel = GUI.Window(1129271116, panel, new WindowFunction(DrawPanel), "", windowStyle);
				GUI.matrix = matrix;
			}
		}

		private void DrawVendorPrompt()
		{
			//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_0034: 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_0044: Expected O, but got Unknown
			//IL_0071: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			if (!Open && nearMoneyVendor && !((Object)(object)Player.LocalPlayer == (Object)null))
			{
				GUIStyle val = new GUIStyle(GUI.skin.box)
				{
					alignment = (TextAnchor)4,
					fontSize = 18,
					fontStyle = (FontStyle)1
				};
				val.normal.textColor = (Color)((Wallet.Balance(Player.LocalPlayer) >= 1000) ? Color.white : new Color(1f, 0.45f, 0.35f));
				bool flag = CoolerItem.Is(Player.LocalPlayer.Holding.HeldItem);
				float num = 470f;
				float num2 = ((float)Screen.width - num) * 0.5f;
				float num3 = (float)Screen.height * 0.67f + 82f + (flag ? 46f : 0f);
				string text = (flag ? "[8] Buy Another Cooler - $" : "[8] Buy Cooler - $");
				GUI.Box(new Rect(num2, num3, num, 38f), text + 1000.ToString("N0"), val);
			}
		}

		private void DrawPanel(int id)
		{
			//IL_0014: 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_0096: 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_00e5: 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_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: 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_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			GUI.DrawTexture(new Rect(0f, 0f, 1160f, 48f), (Texture)(object)rowBg);
			GUI.DrawTexture(new Rect(0f, 46f, 1160f, 2f), (Texture)(object)teal);
			CoolerData coolerData = Find(Selected);
			if (coolerData == null)
			{
				GUI.Label(new Rect(25f, 75f, 1100f, 50f), "The selected cooler is no longer available.", headerStyle);
				return;
			}
			GUI.Label(new Rect(20f, 8f, 330f, 34f), "COOLER CONTENTS", titleStyle);
			if (nameDraftSerial != coolerData.serial)
			{
				nameDraftSerial = coolerData.serial;
				nameDraft = coolerData.name;
			}
			GUI.Label(new Rect(350f, 13f, 60f, 25f), "NAME", headerStyle);
			nameDraft = GUI.TextField(new Rect(410f, 10f, 330f, 28f), nameDraft ?? coolerData.name, 28);
			if (GUI.Button(new Rect(750f, 9f, 110f, 30f), "SAVE NAME", buttonStyle))
			{
				string text = nameDraft;
				Send("rename", -1, default(Vector3), default(Vector3), 0, text);
			}
			if (GUI.Button(new Rect(1098f, 9f, 40f, 30f), "X", dropStyle))
			{
				Toggle(show: false);
			}
			int num = ((coolerData.fish != null) ? coolerData.fish.Count : 0);
			int num2 = 0;
			if (coolerData.fish != null)
			{
				for (int i = 0; i < coolerData.fish.Count; i++)
				{
					num2 += StoredValue(coolerData, i);
				}
			}
			GUI.Label(new Rect(22f, 55f, 540f, 30f), "STORAGE  " + num + " / 20", headerStyle);
			GUI.Label(new Rect(590f, 55f, 540f, 30f), "COMBINED FISH VALUE  $" + num2.ToString("N0"), headerStyle);
			DrawColumn(coolerData, 0, 18);
			DrawColumn(coolerData, 10, 588);
			GUI.DrawTexture(new Rect(18f, 622f, 1124f, 42f), (Texture)(object)rowBg);
			GUI.Label(new Rect(30f, 630f, 1098f, 26f), "> " + Status, statusStyle);
			GUI.DragWindow(new Rect(0f, 0f, 1080f, 48f));
		}

		private void DrawColumn(CoolerData data, int start, int x)
		{
			//IL_0021: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: 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_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: 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_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < 10; i++)
			{
				int num = start + i;
				int num2 = 88 + i * 52;
				GUI.DrawTexture(new Rect((float)x, (float)num2, 554f, 47f), (Texture)(object)((i % 2 == 0) ? rowBg : rowAlt));
				if (data.fish == null || num >= data.fish.Count)
				{
					GUI.Label(new Rect((float)(x + 8), (float)(num2 + 5), 538f, 37f), "SLOT " + (num + 1) + "  —  EMPTY", emptyStyle);
					continue;
				}
				SavedItem val = data.fish[num];
				Texture2D val2 = FishPreviews.Get(val);
				if ((Object)(object)val2 != (Object)null)
				{
					GUI.DrawTexture(new Rect((float)(x + 5), (float)(num2 + 4), 54f, 39f), (Texture)(object)val2, (ScaleMode)2, true);
				}
				string text = StoredName(data, num) + "\nCook x" + CookMultiplier(val).ToString("0.00") + "   Score x" + ScoreMultiplier(val).ToString("0.00") + "   $" + StoredValue(data, num).ToString("N0");
				GUI.Label(new Rect((float)(x + 64), (float)(num2 + 3), 300f, 41f), text, rowStyle);
				if (GUI.Button(new Rect((float)(x + 369), (float)(num2 + 8), 82f, 31f), "TAKE OUT", buttonStyle))
				{
					Send("take", num);
				}
				if (GUI.Button(new Rect((float)(x + 458), (float)(num2 + 8), 88f, 31f), "DROP", dropStyle))
				{
					Send("drop", num);
				}
			}
		}
	}
	internal static class Wallet
	{
		private static Type WalletType => Type.GetType("NoSharedMoney.Wallets, NoSharedMoney", throwOnError: false);

		public static int Balance(Player player)
		{
			Type walletType = WalletType;
			if (walletType != null)
			{
				return (int)AccessTools.Method(walletType, "Get", new Type[1] { typeof(Player) }, (Type[])null).Invoke(null, new object[1] { player });
			}
			return MoneyManager.Money;
		}

		public static bool Charge(Player player, int cost)
		{
			Type walletType = WalletType;
			if (walletType != null)
			{
				MethodInfo methodInfo = AccessTools.Method(walletType, "Get", new Type[1] { typeof(Player) }, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(walletType, "Remove", new Type[2]
				{
					typeof(Player),
					typeof(int)
				}, (Type[])null);
				if ((int)methodInfo.Invoke(null, new object[1] { player }) < cost)
				{
					return false;
				}
				methodInfo2.Invoke(null, new object[2] { player, cost });
				return true;
			}
			if ((Object)(object)MoneyManager.Instance == (Object)null || !MoneyManager.CanAfford(cost))
			{
				return false;
			}
			MoneyManager.RemoveMoney(cost, player);
			return true;
		}

		public static void Credit(Player player, int amount)
		{
			Type walletType = WalletType;
			if (walletType != null)
			{
				AccessTools.Method(walletType, "Add", new Type[2]
				{
					typeof(Player),
					typeof(int)
				}, (Type[])null).Invoke(null, new object[2] { player, amount });
			}
			else
			{
				MoneyManager.AddMoney(amount, player);
			}
		}
	}
	public static class VendorDisplays
	{
		private static readonly List<GameObject> displays = new List<GameObject>();

		private static readonly List<Vector3> locations = new List<Vector3>();

		public unsafe static void Refresh()
		{
			//IL_0106: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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_012b: 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_0136: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Expected O, but got Unknown
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: 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_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: 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_0160: 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_035d: Unknown result type (might be due to invalid IL or missing references)
			displays.RemoveAll((GameObject d) => (Object)(object)d == (Object)null);
			if (displays.Count == 0)
			{
				locations.Clear();
			}
			if ((Object)(object)CoolerItem.Prefab == (Object)null)
			{
				return;
			}
			RaycastHit val2 = default(RaycastHit);
			foreach (ItemPurchasable source in from p in Object.FindObjectsByType<ItemPurchasable>((FindObjectsInactive)0)
				orderby ((Component)p).transform.position.x, ((Component)p).transform.position.z
				select p)
			{
				if (!((Object)(object)source == (Object)null) && !((Object)(object)((Component)source).GetComponent<CoolerPurchasable>() != (Object)null) && !locations.Any((Vector3 p) => Vector3.Distance(p, ((Component)source).transform.position) < 18f))
				{
					Vector3 val = ((Component)source).transform.position + ((Component)source).transform.right * 1.6f;
					if (Physics.Raycast(val + Vector3.up * 2f, Vector3.down, ref val2, 6f, LayerMask.op_Implicit(GameInfo.LevelLayer), (QueryTriggerInteraction)1))
					{
						val = ((RaycastHit)(ref val2)).point;
					}
					GameObject val3 = new GameObject("Cooler Mod Vendor Display");
					val3.SetActive(false);
					val3.transform.position = val;
					val3.transform.rotation = Quaternion.Euler(0f, ((Component)source).transform.eulerAngles.y, 0f);
					Transform val4 = CoolerVisual.Part("DisplayPedestal", val3.transform, (PrimitiveType)3, new Vector3(0f, 0.08f, 0f), new Vector3(1.45f, 0.16f, 1f), DisplayMaterial());
					GameObject val5 = new GameObject("CoolerDisplayModel");
					val5.transform.SetParent(val3.transform, false);
					val5.transform.localPosition = new Vector3(0f, 0.16f, 0f);
					val5.AddComponent<CoolerVisual>().Build();
					BoxCollider val6 = val3.AddComponent<BoxCollider>();
					val6.center = new Vector3(0f, 0.7f, 0f);
					val6.size = new Vector3(1.55f, 1.4f, 1.1f);
					((Collider)val6).isTrigger = true;
					Transform transform = new GameObject("TextTarget").transform;
					transform.SetParent(val3.transform, false);
					transform.localPosition = new Vector3(0f, 1.55f, 0f);
					CoolerPurchasable coolerPurchasable = val3.AddComponent<CoolerPurchasable>();
					coolerPurchasable.Configure((Collider)(object)val6, transform, (from r in val5.GetComponentsInChildren<Renderer>(true)
						select ((Component)r).gameObject).Concat((IEnumerable<GameObject>)(object)new GameObject[1] { ((Component)val4).gameObject }).ToArray());
					val3.layer = LayerMask.NameToLayer("Interactable");
					val3.SetActive(true);
					((Interactable)coolerPurchasable).ToggleIsInteractable(true);
					displays.Add(val3);
					locations.Add(((Component)source).transform.position);
					Plugin.Log("Added cooler purchase display near item vendor at " + ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString() + ".");
				}
			}
		}

		private static Material DisplayMaterial()
		{
			//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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			return new Material(Shader.Find("Universal Render Pipeline/Lit") ?? Shader.Find("Standard"))
			{
				color = new Color(0.18f, 0.22f, 0.24f)
			};
		}

		public static bool Near(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return displays.Any((GameObject display) => (Object)(object)display != (Object)null && Vector3.Distance(display.transform.position, position) <= 7f);
		}

		public static void Clear()
		{
			foreach (GameObject display in displays)
			{
				if ((Object)(object)display != (Object)null)
				{
					Object.Destroy((Object)(object)display);
				}
			}
			displays.Clear();
			locations.Clear();
		}
	}
	public sealed class CoolerPurchasable : Purchasable
	{
		public void Configure(Collider collider, Transform textTarget, GameObject[] models)
		{
			((Interactable)this)._modelsToOutline = models;
			base._customCost = 1000;
			base._isFree = false;
			base._hoverString = "Reusable Fishing Cooler\n$" + 1000.ToString("N0") + "\n" + SpriteManager.GetPickUpInput();
			AccessTools.Field(typeof(Interactable), "_interactCol").SetValue(this, collider);
			AccessTools.Field(typeof(Interactable), "_textTarget").SetValue(this, textTarget);
		}

		public override void Hover()
		{
			base._hoverString = "Reusable Fishing Cooler\n$" + 1000.ToString("N0") + "\n" + SpriteManager.GetPickUpInput();
			base._customCost = 1000;
			((Purchasable)this).Hover();
		}

		public override void Interact(Player player)
		{
			//IL_0021: 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_002a: 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)
			((Interactable)this).Interact(player);
			if ((Object)(object)Plugin.Instance != (Object)null)
			{
				Plugin.Instance.Send("buy");
			}
		}
	}
	[HarmonyPatch(typeof(PlayerHolding), "PickUpInput")]
	internal static class CoolerCaptureInteract
	{
		private static bool Prefix()
		{
			if (!((Object)(object)Plugin.Instance == (Object)null))
			{
				return !Plugin.Instance.CapturesInteract();
			}
			return true;
		}
	}
	public static class FishPreviews
	{
		private static readonly Dictionary<string, Texture2D> cache = new Dictionary<string, Texture2D>();

		private static string Key(SavedItem state)
		{
			return state.ItemID + ":" + state.SkinIndex + ":" + Mathf.RoundToInt(state.Cookness * 20f);
		}

		public static Texture2D Get(SavedItem state)
		{
			string key = Key(state);
			if (cache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			try
			{
				value = Render(state);
			}
			catch
			{
				value = Fallback(state);
			}
			cache[key] = value;
			return value;
		}

		private static Texture2D Render(SavedItem state)
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: 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_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing