Decompiled source of SeagullSpawner v1.1.0

plugins/SeagullsSpawner/SeagullsSpawner.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using FishNet.Object;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Estonia")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Seagull spawning controls for How to Fish.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SeagullsSpawner")]
[assembly: AssemblyTitle("SeagullsSpawner")]
[assembly: AssemblyVersion("1.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 SeagullsSpawner
{
	[BepInPlugin("estonia.howtofish.seagullsspawner", "Seagulls Spawner", "1.1.0")]
	[BepInProcess("How to Fish.exe")]
	public sealed class SeagullsSpawnerPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(BirdManager), "LookForFood")]
		private static class BirdManagerLookForFoodPatch
		{
			private static bool Prefix()
			{
				return Random.Range(0f, 100f) <= StealAttemptChance;
			}
		}

		private const string PluginGuid = "estonia.howtofish.seagullsspawner";

		private const string PluginName = "Seagulls Spawner";

		private const string PluginVersion = "1.1.0";

		private const string Author = "Estonia";

		private static readonly BindingFlags PrivateStatic = BindingFlags.Static | BindingFlags.NonPublic;

		private static readonly BindingFlags PrivateInstance = BindingFlags.Instance | BindingFlags.NonPublic;

		private static SeagullsSpawnerPlugin _instance;

		private ConfigEntry<bool> _autoSpawn;

		private ConfigEntry<int> _maxFlyingSeagulls;

		private ConfigEntry<float> _spawnInterval;

		private ConfigEntry<int> _spawnBurst;

		private ConfigEntry<float> _spawnRadius;

		private ConfigEntry<float> _spawnHeight;

		private ConfigEntry<float> _stealAttemptChance;

		private Harmony _harmony;

		private PauseManager _pauseManager;

		private GameObject _serverSettingsScreen;

		private GameObject _controlsRoot;

		private GameObject _buttonTemplate;

		private TextMeshProUGUI _textTemplate;

		private TextMeshProUGUI _statusText;

		private TextMeshProUGUI _spawnText;

		private TextMeshProUGUI _autoButtonText;

		private TextMeshProUGUI _spawnBurstButtonText;

		private TextMeshProUGUI _maxMinusText;

		private TextMeshProUGUI _maxPlusText;

		private TextMeshProUGUI _frequencyFasterText;

		private TextMeshProUGUI _frequencySlowerText;

		private TextMeshProUGUI _burstMinusText;

		private TextMeshProUGUI _burstPlusText;

		private TextMeshProUGUI _stealMinusText;

		private TextMeshProUGUI _stealPlusText;

		private Bird _birdPrefab;

		private float _nextSpawnTime;

		private readonly List<Bird> _spawnedBirds = new List<Bird>();

		private readonly List<Button> _hostButtons = new List<Button>();

		private bool IsHost
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Server.Instance))
				{
					return ((NetworkBehaviour)Server.Instance).IsServerInitialized;
				}
				return false;
			}
		}

		private bool CanSpawn
		{
			get
			{
				if (IsHost && Object.op_Implicit((Object)(object)ItemManager.Instance) && Object.op_Implicit((Object)(object)BirdManager.Instance))
				{
					return Object.op_Implicit((Object)(object)FindBirdPrefab());
				}
				return false;
			}
		}

		private int FlyingSeagullCount => GetFlyingBirds()?.Count ?? 0;

		internal static float StealAttemptChance
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)_instance))
				{
					return 100f;
				}
				return _instance._stealAttemptChance.Value;
			}
		}

		private void Awake()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			_instance = this;
			_autoSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "AutoSpawn", true, (ConfigDescription)null);
			_maxFlyingSeagulls = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxFlyingSeagulls", 8, (ConfigDescription)null);
			_spawnInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "SpawnIntervalSeconds", 15f, (ConfigDescription)null);
			_spawnBurst = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "SpawnBurstAmount", 2, (ConfigDescription)null);
			_spawnRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "SpawnRadius", 22f, (ConfigDescription)null);
			_spawnHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "SpawnHeight", 12f, (ConfigDescription)null);
			_stealAttemptChance = ((BaseUnityPlugin)this).Config.Bind<float>("Stealing", "StealAttemptChancePercent", 40f, (ConfigDescription)null);
			_harmony = new Harmony("estonia.howtofish.seagullsspawner");
			_harmony.PatchAll(typeof(SeagullsSpawnerPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Seagulls Spawner 1.1.0 loaded. Author: Estonia.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			if (Object.op_Implicit((Object)(object)_controlsRoot))
			{
				Object.Destroy((Object)(object)_controlsRoot);
			}
		}

		private void Update()
		{
			EnsureServerSettingsUi();
			PruneSpawnedBirds();
			TickSpawner();
			RefreshUi();
		}

		private void EnsureServerSettingsUi()
		{
			PauseManager pauseManager = GetPauseManager();
			if (Object.op_Implicit((Object)(object)pauseManager) && (!((Object)(object)pauseManager == (Object)(object)_pauseManager) || !Object.op_Implicit((Object)(object)_controlsRoot)))
			{
				_pauseManager = pauseManager;
				_serverSettingsScreen = GetPrivateField<GameObject>(_pauseManager, "_serverSettingsScreen");
				if (Object.op_Implicit((Object)(object)_serverSettingsScreen))
				{
					_buttonTemplate = FindButtonTemplate();
					_textTemplate = (Object.op_Implicit((Object)(object)_buttonTemplate) ? _buttonTemplate.GetComponentInChildren<TextMeshProUGUI>(true) : FindTextTemplate());
					BuildServerSettingsControls();
				}
			}
		}

		private void BuildServerSettingsControls()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_controlsRoot))
			{
				Object.Destroy((Object)(object)_controlsRoot);
			}
			_hostButtons.Clear();
			_controlsRoot = new GameObject("SeagullsSpawner_ServerSettingsControls", new Type[1] { typeof(RectTransform) });
			_controlsRoot.transform.SetParent(_serverSettingsScreen.transform, false);
			_controlsRoot.transform.SetAsLastSibling();
			RectTransform component = _controlsRoot.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 0f);
			component.anchorMax = new Vector2(1f, 0f);
			component.pivot = new Vector2(0.5f, 0f);
			component.offsetMin = new Vector2(34f, 166f);
			component.offsetMax = new Vector2(-34f, 510f);
			((TMP_Text)CreateAnchoredText(_controlsRoot.transform, "Seagull Spawner", 22f, 0.93f, 0f, 1f)).alignment = (TextAlignmentOptions)514;
			_statusText = CreateAnchoredText(_controlsRoot.transform, "", 15f, 0.82f, 0f, 1f);
			((TMP_Text)_statusText).alignment = (TextAlignmentOptions)514;
			_spawnText = CreateAnchoredText(_controlsRoot.transform, "", 15f, 0.72f, 0f, 1f);
			((TMP_Text)_spawnText).alignment = (TextAlignmentOptions)514;
			_autoButtonText = CreateAnchoredHostButton(0.59f, 0f, 0.49f, "", ToggleAutoSpawn);
			_spawnBurstButtonText = CreateAnchoredHostButton(0.59f, 0.51f, 1f, "", delegate
			{
				SpawnSeagulls(Mathf.Max(1, _spawnBurst.Value));
			});
			_maxMinusText = CreateAnchoredHostButton(0.46f, 0f, 0.49f, GetMaxMinusLabel(), delegate
			{
				AdjustMax(-1);
			});
			_maxPlusText = CreateAnchoredHostButton(0.46f, 0.51f, 1f, GetMaxPlusLabel(), delegate
			{
				AdjustMax(1);
			});
			_frequencyFasterText = CreateAnchoredHostButton(0.33f, 0f, 0.49f, GetFrequencyFasterLabel(), delegate
			{
				AdjustInterval(-1f);
			});
			_frequencySlowerText = CreateAnchoredHostButton(0.33f, 0.51f, 1f, GetFrequencySlowerLabel(), delegate
			{
				AdjustInterval(1f);
			});
			_burstMinusText = CreateAnchoredHostButton(0.2f, 0f, 0.49f, GetBurstMinusLabel(), delegate
			{
				AdjustBurst(-1);
			});
			_burstPlusText = CreateAnchoredHostButton(0.2f, 0.51f, 1f, GetBurstPlusLabel(), delegate
			{
				AdjustBurst(1);
			});
			_stealMinusText = CreateAnchoredHostButton(0.07f, 0f, 0.49f, GetStealMinusLabel(), delegate
			{
				AdjustStealChance(-10f);
			});
			_stealPlusText = CreateAnchoredHostButton(0.07f, 0.51f, 1f, GetStealPlusLabel(), delegate
			{
				AdjustStealChance(10f);
			});
		}

		private Transform FindBestServerSettingsParent()
		{
			VerticalLayoutGroup[] componentsInChildren = _serverSettingsScreen.GetComponentsInChildren<VerticalLayoutGroup>(true);
			foreach (VerticalLayoutGroup val in componentsInChildren)
			{
				if ((Object)(object)((Component)val).transform != (Object)(object)_serverSettingsScreen.transform)
				{
					return ((Component)val).transform;
				}
			}
			return _serverSettingsScreen.transform;
		}

		private void AddButtonRow(Transform parent, params (Func<string> label, Action action, Action<TextMeshProUGUI> bindText)[] buttons)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			GameObject val = new GameObject("SeagullsSpawner_Row", new Type[3]
			{
				typeof(RectTransform),
				typeof(HorizontalLayoutGroup),
				typeof(LayoutElement)
			});
			val.transform.SetParent(parent, false);
			HorizontalLayoutGroup component = val.GetComponent<HorizontalLayoutGroup>();
			((HorizontalOrVerticalLayoutGroup)component).childControlWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childControlHeight = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandWidth = true;
			((HorizontalOrVerticalLayoutGroup)component).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)component).spacing = 8f;
			LayoutElement component2 = val.GetComponent<LayoutElement>();
			component2.minHeight = 42f;
			component2.preferredHeight = 42f;
			for (int i = 0; i < buttons.Length; i++)
			{
				(Func<string> label, Action action, Action<TextMeshProUGUI> bindText) tuple = buttons[i];
				Func<string> item = tuple.label;
				Action item2 = tuple.action;
				Action<TextMeshProUGUI> item3 = tuple.bindText;
				GameObject val2 = CreateButton(val.transform, item(), item2);
				_hostButtons.Add(val2.GetComponent<Button>());
				item3?.Invoke(val2.GetComponentInChildren<TextMeshProUGUI>(true));
			}
		}

		private TextMeshProUGUI CreateHostButton(Transform parent, string label, Action action)
		{
			GameObject val = CreateButton(parent, label, action);
			_hostButtons.Add(val.GetComponent<Button>());
			return val.GetComponentInChildren<TextMeshProUGUI>(true);
		}

		private TextMeshProUGUI CreateAnchoredHostButton(float y, float xMin, float xMax, string label, Action action)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = CreateButton(_controlsRoot.transform, label, action);
			RectTransform component = obj.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(xMin, y);
			component.anchorMax = new Vector2(xMax, y);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = Vector2.zero;
			component.sizeDelta = new Vector2(0f, 36f);
			LayoutElement component2 = obj.GetComponent<LayoutElement>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.ignoreLayout = true;
			}
			Button component3 = obj.GetComponent<Button>();
			_hostButtons.Add(component3);
			return obj.GetComponentInChildren<TextMeshProUGUI>(true);
		}

		private TextMeshProUGUI CreateAnchoredText(Transform parent, string text, float size, float y, float xMin, float xMax)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = CreateText(parent, text, size);
			RectTransform component = ((Component)obj).GetComponent<RectTransform>();
			component.anchorMin = new Vector2(xMin, y);
			component.anchorMax = new Vector2(xMax, y);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.anchoredPosition = Vector2.zero;
			component.sizeDelta = new Vector2(0f, Mathf.Max(24f, size + 8f));
			LayoutElement component2 = ((Component)obj).GetComponent<LayoutElement>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.ignoreLayout = true;
			}
			return obj;
		}

		private GameObject CreateButton(Transform parent, string label, Action action)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			GameObject val;
			if (Object.op_Implicit((Object)(object)_buttonTemplate))
			{
				val = Object.Instantiate<GameObject>(_buttonTemplate, parent);
				((Object)val).name = "SeagullsSpawner_Button";
				val.SetActive(true);
				Button[] componentsInChildren = val.GetComponentsInChildren<Button>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
				}
				Button obj = val.AddComponent<Button>();
				((Selectable)obj).targetGraphic = val.GetComponent<Graphic>() ?? val.GetComponentInChildren<Graphic>(true);
				((Selectable)obj).transition = (Transition)1;
			}
			else
			{
				val = new GameObject("SeagullsSpawner_Button", new Type[3]
				{
					typeof(RectTransform),
					typeof(Image),
					typeof(Button)
				});
				val.transform.SetParent(parent, false);
				Image component = val.GetComponent<Image>();
				((Graphic)component).color = new Color(0f, 0f, 0f, 0.55f);
				((Selectable)val.GetComponent<Button>()).targetGraphic = (Graphic)(object)component;
			}
			RectTransform component2 = val.GetComponent<RectTransform>();
			component2.sizeDelta = new Vector2(Mathf.Max(component2.sizeDelta.x, 250f), Mathf.Max(component2.sizeDelta.y, 42f));
			LayoutElement obj2 = val.GetComponent<LayoutElement>() ?? val.AddComponent<LayoutElement>();
			obj2.minHeight = Mathf.Max(obj2.minHeight, 42f);
			obj2.preferredHeight = Mathf.Max(obj2.preferredHeight, 42f);
			TextMeshProUGUI val2 = val.GetComponentInChildren<TextMeshProUGUI>(true);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				val2 = CreateText(val.transform, label, 18f);
				RectTransform component3 = ((Component)val2).GetComponent<RectTransform>();
				component3.anchorMin = Vector2.zero;
				component3.anchorMax = Vector2.one;
				component3.offsetMin = new Vector2(8f, 0f);
				component3.offsetMax = new Vector2(-8f, 0f);
			}
			((TMP_Text)val2).text = label;
			((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val2).enableAutoSizing = true;
			((TMP_Text)val2).fontSizeMax = Mathf.Min((((TMP_Text)val2).fontSizeMax <= 0f) ? 18f : ((TMP_Text)val2).fontSizeMax, 18f);
			((TMP_Text)val2).fontSizeMin = 10f;
			Button component4 = val.GetComponent<Button>();
			((UnityEventBase)component4.onClick).RemoveAllListeners();
			((UnityEvent)component4.onClick).AddListener(new UnityAction(action.Invoke));
			return val;
		}

		private TextMeshProUGUI CreateText(Transform parent, string text, float size)
		{
			//IL_0025: 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_0037: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SeagullsSpawner_Text", new Type[2]
			{
				typeof(RectTransform),
				typeof(TextMeshProUGUI)
			});
			val.transform.SetParent(parent, false);
			TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
			if (Object.op_Implicit((Object)(object)_textTemplate))
			{
				((TMP_Text)component).font = ((TMP_Text)_textTemplate).font;
				((Graphic)component).material = ((Graphic)_textTemplate).material;
				((Graphic)component).color = ((Graphic)_textTemplate).color;
			}
			else
			{
				((Graphic)component).color = Color.white;
			}
			((TMP_Text)component).text = text;
			((TMP_Text)component).fontSize = size;
			((TMP_Text)component).enableAutoSizing = true;
			((TMP_Text)component).fontSizeMin = 10f;
			((TMP_Text)component).fontSizeMax = size;
			((TMP_Text)component).alignment = (TextAlignmentOptions)513;
			LayoutElement obj = val.AddComponent<LayoutElement>();
			obj.minHeight = Mathf.Max(26f, size + 8f);
			obj.preferredHeight = Mathf.Max(26f, size + 8f);
			return component;
		}

		private static void CreateSpacer(Transform parent, float height)
		{
			//IL_0025: 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)
			GameObject val = new GameObject("SeagullsSpawner_Spacer", new Type[2]
			{
				typeof(RectTransform),
				typeof(LayoutElement)
			});
			val.transform.SetParent(parent, false);
			val.GetComponent<LayoutElement>().preferredHeight = height;
		}

		private void RefreshUi()
		{
			if (Object.op_Implicit((Object)(object)_controlsRoot))
			{
				if (Object.op_Implicit((Object)(object)_statusText))
				{
					((TMP_Text)_statusText).text = (IsHost ? "Seagulls are controlled by the host" : "Host a server to control seagulls");
				}
				if (Object.op_Implicit((Object)(object)_spawnText))
				{
					((TMP_Text)_spawnText).text = $"Flying: {FlyingSeagullCount}/{_maxFlyingSeagulls.Value}  |  Auto: {OnOff(_autoSpawn.Value)}  |  Every {_spawnInterval.Value:0.0}s  |  Burst: {_spawnBurst.Value}";
				}
				SetText(_autoButtonText, _autoSpawn.Value ? "Disable Automatic Seagull Spawning" : "Enable Automatic Seagull Spawning");
				SetText(_spawnBurstButtonText, $"Spawn {_spawnBurst.Value} Seagulls Now");
				SetText(_maxMinusText, GetMaxMinusLabel());
				SetText(_maxPlusText, GetMaxPlusLabel());
				SetText(_frequencyFasterText, GetFrequencyFasterLabel());
				SetText(_frequencySlowerText, GetFrequencySlowerLabel());
				SetText(_burstMinusText, GetBurstMinusLabel());
				SetText(_burstPlusText, GetBurstPlusLabel());
				SetText(_stealMinusText, GetStealMinusLabel());
				SetText(_stealPlusText, GetStealPlusLabel());
				SetButtonsInteractable(_hostButtons, IsHost);
			}
		}

		private void TickSpawner()
		{
			if (_autoSpawn.Value && IsHost && !(Time.unscaledTime < _nextSpawnTime))
			{
				_nextSpawnTime = Time.unscaledTime + Mathf.Max(0.5f, _spawnInterval.Value);
				SpawnUntilCap();
			}
		}

		private void SpawnUntilCap()
		{
			int num = Mathf.Max(0, _maxFlyingSeagulls.Value - FlyingSeagullCount);
			int amount = Mathf.Min(Mathf.Max(1, _spawnBurst.Value), num);
			SpawnSeagulls(amount);
		}

		private void SpawnSeagulls(int amount)
		{
			//IL_0012: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (amount <= 0 || !CanSpawn)
			{
				return;
			}
			for (int i = 0; i < amount; i++)
			{
				Vector3 spawnPosition = GetSpawnPosition();
				Quaternion val = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
				Item val2 = ItemManager.Instance.SpawnNewItem((Item)(object)_birdPrefab, spawnPosition, val);
				Bird val3 = (Object.op_Implicit((Object)(object)val2) ? val2.Bird : null);
				if (Object.op_Implicit((Object)(object)val3))
				{
					_spawnedBirds.Add(val3);
				}
			}
		}

		private Vector3 GetSpawnPosition()
		{
			//IL_001d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Object.op_Implicit((Object)(object)Player.LocalPlayer) ? Player.LocalPlayer.Transform.position : SpawnManager.PlayerSpawnPos);
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 val2 = ((Vector2)(ref insideUnitCircle)).normalized * Random.Range(8f, Mathf.Max(8f, _spawnRadius.Value));
			float num = Mathf.Max(val.y, WaterManager.WaterHeight) + Mathf.Max(4f, _spawnHeight.Value);
			return new Vector3(val.x + val2.x, num, val.z + val2.y);
		}

		private Bird FindBirdPrefab()
		{
			if (Object.op_Implicit((Object)(object)_birdPrefab))
			{
				return _birdPrefab;
			}
			Bird[] array = Resources.LoadAll<Bird>("Items/Creatures");
			foreach (Bird val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && ((object)val).GetType() == typeof(Bird))
				{
					_birdPrefab = val;
					return _birdPrefab;
				}
			}
			Item[] array2 = Resources.LoadAll<Item>("Items");
			foreach (Item val2 in array2)
			{
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.Bird))
				{
					_birdPrefab = val2.Bird;
					return _birdPrefab;
				}
			}
			return null;
		}

		private List<Bird> GetFlyingBirds()
		{
			if (!Object.op_Implicit((Object)(object)BirdManager.Instance))
			{
				return null;
			}
			return typeof(BirdManager).GetField("_flyingBirds", PrivateInstance)?.GetValue(BirdManager.Instance) as List<Bird>;
		}

		private void PruneSpawnedBirds()
		{
			_spawnedBirds.RemoveAll((Bird bird) => !Object.op_Implicit((Object)(object)bird) || ((Creature)bird).IsDead || ((NetworkBehaviour)bird).IsDeinitializing || ((Item)bird).IsDestroying);
		}

		private void ClearSpawnedSeagulls()
		{
			if (!IsHost)
			{
				return;
			}
			Bird[] array = _spawnedBirds.ToArray();
			foreach (Bird val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && !((Creature)val).IsDead && !((NetworkBehaviour)val).IsDeinitializing && !((Item)val).IsDestroying)
				{
					((NetworkBehaviour)Server.Instance).Despawn(((Component)val).gameObject, (DespawnType?)null);
				}
			}
			_spawnedBirds.Clear();
		}

		private void ToggleAutoSpawn()
		{
			_autoSpawn.Value = !_autoSpawn.Value;
			_nextSpawnTime = Time.unscaledTime + 1f;
		}

		private void AdjustMax(int delta)
		{
			_maxFlyingSeagulls.Value = Mathf.Clamp(_maxFlyingSeagulls.Value + delta, 0, 40);
		}

		private void AdjustInterval(float delta)
		{
			_spawnInterval.Value = Mathf.Clamp(_spawnInterval.Value + delta, 1f, 90f);
			_nextSpawnTime = Mathf.Min(_nextSpawnTime, Time.unscaledTime + _spawnInterval.Value);
		}

		private void AdjustBurst(int delta)
		{
			_spawnBurst.Value = Mathf.Clamp(_spawnBurst.Value + delta, 1, 10);
		}

		private void AdjustStealChance(float delta)
		{
			_stealAttemptChance.Value = Mathf.Clamp(_stealAttemptChance.Value + delta, 0f, 100f);
		}

		private void PresetPeaceful()
		{
			_autoSpawn.Value = false;
			_maxFlyingSeagulls.Value = 0;
			_stealAttemptChance.Value = 0f;
			ClearSpawnedSeagulls();
		}

		private void PresetPractice()
		{
			_autoSpawn.Value = true;
			_maxFlyingSeagulls.Value = 12;
			_spawnInterval.Value = 7f;
			_spawnBurst.Value = 3;
			_stealAttemptChance.Value = 0f;
			_nextSpawnTime = 0f;
		}

		private void PresetChaos()
		{
			_autoSpawn.Value = true;
			_maxFlyingSeagulls.Value = 28;
			_spawnInterval.Value = 2.5f;
			_spawnBurst.Value = 5;
			_stealAttemptChance.Value = 100f;
			_nextSpawnTime = 0f;
		}

		private GameObject FindButtonTemplate()
		{
			Button componentInChildren = _serverSettingsScreen.GetComponentInChildren<Button>(true);
			if (Object.op_Implicit((Object)(object)componentInChildren))
			{
				return ((Component)componentInChildren).gameObject;
			}
			List<GameObject> privateField = GetPrivateField<List<GameObject>>(_pauseManager, "_serverButtons");
			if (privateField != null)
			{
				foreach (GameObject item in privateField)
				{
					if (Object.op_Implicit((Object)(object)item) && Object.op_Implicit((Object)(object)item.GetComponentInChildren<Button>(true)))
					{
						return item;
					}
				}
			}
			return null;
		}

		private static TextMeshProUGUI FindTextTemplate()
		{
			TextMeshProUGUI[] array = Resources.FindObjectsOfTypeAll<TextMeshProUGUI>();
			if (array.Length == 0)
			{
				return null;
			}
			return array[0];
		}

		private static PauseManager GetPauseManager()
		{
			object? obj = typeof(PauseManager).GetField("_instance", PrivateStatic)?.GetValue(null);
			return (PauseManager)((obj is PauseManager) ? obj : null);
		}

		private static T GetPrivateField<T>(object instance, string fieldName) where T : class
		{
			if (instance == null)
			{
				return null;
			}
			return instance.GetType().GetField(fieldName, PrivateInstance)?.GetValue(instance) as T;
		}

		private static void SetButtonsInteractable(List<Button> buttons, bool interactable)
		{
			foreach (Button button in buttons)
			{
				if (Object.op_Implicit((Object)(object)button))
				{
					((Selectable)button).interactable = interactable;
				}
			}
		}

		private static void SetText(TextMeshProUGUI label, string value)
		{
			if (Object.op_Implicit((Object)(object)label))
			{
				((TMP_Text)label).text = value;
			}
		}

		private string GetMaxMinusLabel()
		{
			return $"Max Seagulls -  Now {_maxFlyingSeagulls.Value}";
		}

		private string GetMaxPlusLabel()
		{
			return $"Max Seagulls +  Now {_maxFlyingSeagulls.Value}";
		}

		private string GetFrequencyFasterLabel()
		{
			return $"Spawn Faster  {_spawnInterval.Value:0.0}s";
		}

		private string GetFrequencySlowerLabel()
		{
			return $"Spawn Slower  {_spawnInterval.Value:0.0}s";
		}

		private string GetBurstMinusLabel()
		{
			return $"Birds Per Spawn -  Now {_spawnBurst.Value}";
		}

		private string GetBurstPlusLabel()
		{
			return $"Birds Per Spawn +  Now {_spawnBurst.Value}";
		}

		private string GetStealMinusLabel()
		{
			return $"Steal Chance -10%  Now {_stealAttemptChance.Value:0}%";
		}

		private string GetStealPlusLabel()
		{
			return $"Steal Chance +10%  Now {_stealAttemptChance.Value:0}%";
		}

		private static string OnOff(bool value)
		{
			if (!value)
			{
				return "Off";
			}
			return "On";
		}
	}
}