Decompiled source of ChaosMod v1.37.2

SuperBattleGolfChaosMod.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using FMOD;
using FMODUnity;
using HarmonyLib;
using HoleSizeMod;
using Mirror;
using Steamworks;
using Steamworks.Data;
using SuperBattleGolfChaosMod;
using SuperBattleGolfChaosMod.UI;
using SuperBattleGolfChaosMod.UI.PauseMenuSummary;
using SuperBattleGolfChaosMod.UI.Sections;
using TMPro;
using Unity.Collections;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Super Battle Golf Chaos Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ModsForMe")]
[assembly: AssemblyProduct("Super Battle Golf Chaos Mod")]
[assembly: AssemblyCopyright("Copyright © 2026 ModsForMe")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("ba677b27-3ab1-443f-bbd1-89639b0b3f26")]
[assembly: AssemblyFileVersion("1.37.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.37.2.0")]
namespace HoleSizeMod
{
	[BepInPlugin("com.modsforme.chaosmod.holesize", "ModsForMe Chaos Mod - Hole Size", "1.37.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.modsforme.chaosmod.holesize";

		private const string OldConfigName = "com.yourname.holesizemod.cfg";

		public static ConfigEntry<float> HoleScale;

		public static ConfigEntry<bool> Enabled;

		public static ConfigEntry<bool> Random;

		public static ConfigEntry<bool> Limited;

		public const float LimitedMax = 5f;

		public static Plugin Instance;

		public const float MinScale = 0.25f;

		public const float MaxScale = 15f;

		public const float BallSized = 0.25f;

		public static readonly float[] RandomSizes = new float[17]
		{
			0.25f, 0.5f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f,
			9f, 10f, 11f, 12f, 13f, 14f, 15f
		};

		private static readonly Random rng = new Random();

		private static float lastRandom = -1f;

		public const float RandomMinJump = 2f;

		public static float CurrentHoleScale = 1f;

		public static GolfHole SharedHole;

		public static float SharedScale = 1f;

		private float nextShareCheck;

		public static float RandomMax => LobbySync.EffectiveHolesLimited ? 5f : 15f;

		public static bool IsBallSized(float scale)
		{
			return scale < 0.375f;
		}

		public static float NextRandomScale(float maxScale = 15f)
		{
			List<float> list = new List<float>();
			float[] randomSizes = RandomSizes;
			foreach (float num in randomSizes)
			{
				if (!(num > maxScale + 0.001f) && (lastRandom < 0f || Mathf.Abs(num - lastRandom) > 2.001f))
				{
					list.Add(num);
				}
			}
			if (list.Count == 0)
			{
				float[] randomSizes2 = RandomSizes;
				foreach (float num2 in randomSizes2)
				{
					if (num2 <= maxScale + 0.001f && !Mathf.Approximately(num2, lastRandom))
					{
						list.Add(num2);
					}
				}
			}
			if (list.Count == 0)
			{
				list.Add(Mathf.Min(1f, maxScale));
			}
			return lastRandom = list[rng.Next(list.Count)];
		}

		public static string Describe(float scale, string format = "0.00")
		{
			return IsBallSized(scale) ? "Ball sized" : (scale.ToString(format) + "x");
		}

		private void Update()
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < nextShareCheck)
			{
				return;
			}
			nextShareCheck = Time.unscaledTime + 2f;
			try
			{
				if ((Object)(object)SharedHole != (Object)null && LobbySync.CurrentRole == LobbySync.Role.Host)
				{
					Scene scene = ((Component)SharedHole).gameObject.scene;
					LobbySync.HostEnsureHoleShared(((Scene)(ref scene)).name, SharedScale);
				}
			}
			catch
			{
			}
		}

		private void Awake()
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			CarryOverOldSettings();
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Turn Variable Holes on or off. Takes effect on the next hole that loads.");
			Random = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Random", false, "When Variable Holes is on: give every hole a random size instead of using HoleScale.");
			Limited = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Limited", false, "With Random on: random sizes only go up to " + 5f + "x.");
			HoleScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HoleScale", 4f, new ConfigDescription("Multiplier for hole width. 1 = normal, 0.5 = half width, up to 15. 0.25 = ball sized (just big enough for the ball). Takes effect on the next hole that loads.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 15f), Array.Empty<object>()));
			new Harmony("com.modsforme.chaosmod.holesize").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Chaos Mod hole size loaded. Scale = " + HoleScale.Value));
		}

		private void CarryOverOldSettings()
		{
			try
			{
				string text = Path.Combine(Paths.ConfigPath, "com.yourname.holesizemod.cfg");
				if (File.Exists(text) && !File.Exists(((BaseUnityPlugin)this).Config.ConfigFilePath))
				{
					File.Copy(text, ((BaseUnityPlugin)this).Config.ConfigFilePath);
					((BaseUnityPlugin)this).Config.Reload();
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Copied hole settings from com.yourname.holesizemod.cfg");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Couldn't copy old hole settings: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(GolfHole), "Start")]
	public static class GolfHole_Resize_Patch
	{
		public class HoleState
		{
			public GolfHole Hole;

			public Transform HoleT;

			public CupShape VisualCup;

			public CupShape ColliderCup;

			public float LipMultiplier;

			public float OpeningWorld;

			public float HolePixelWorld;

			public float HeightAboveGround;

			public Vector3 Origin;

			public Coroutine GrassRoutine;

			public GrassClearer.Removed Grass = new GrassClearer.Removed();

			public float[] GreenDist;

			public int GreenLayer;

			public float RimRadius => OpeningWorld * LipMultiplier;
		}

		private class TriggerSnapshot
		{
			public string name;

			public BoxCollider box;

			public Vector3 worldCenter;

			public Vector3 worldSize;
		}

		public class CupShape
		{
			public float OpeningRadius;

			public float InnerRadius;

			public List<Vector2> Wall = new List<Vector2>();

			public bool HasFloor;

			public static CupShape Fallback(float plateRadius, float bottomY)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				CupShape cupShape = new CupShape
				{
					OpeningRadius = plateRadius * 0.5f,
					InnerRadius = plateRadius * 0.41f,
					HasFloor = true
				};
				cupShape.Wall.Add(new Vector2(cupShape.InnerRadius, bottomY));
				return cupShape;
			}

			public static CupShape Read(Mesh mesh, float plateRadius, string label)
			{
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: 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_0072: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_0146: Unknown result type (might be due to invalid IL or missing references)
				//IL_015d: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01fb: 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_021e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0240: 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_02a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0318: Unknown result type (might be due to invalid IL or missing references)
				//IL_031d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0320: Unknown result type (might be due to invalid IL or missing references)
				//IL_0330: 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_038c: 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_03b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_042d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0432: Unknown result type (might be due to invalid IL or missing references)
				//IL_043d: Unknown result type (might be due to invalid IL or missing references)
				Vector3[] array = ReadPositions(mesh, label);
				if (array == null || array.Length == 0)
				{
					Debug.Log((object)("[HoleSizeMod] " + label + " mesh not readable; using standard cup proportions."));
					return null;
				}
				HashSet<long> hashSet = new HashSet<long>();
				List<Vector2> list = new List<Vector2>();
				float num = float.MinValue;
				Vector3[] array2 = array;
				foreach (Vector3 val in array2)
				{
					float num2 = Mathf.Sqrt(val.x * val.x + val.z * val.z);
					int num3 = Mathf.RoundToInt(num2 * 100f);
					int num4 = Mathf.RoundToInt(val.y * 100f);
					if (hashSet.Add(((long)num3 << 32) ^ (uint)num4))
					{
						list.Add(new Vector2((float)num3 / 100f, (float)num4 / 100f));
						num = Mathf.Max(num, (float)num4 / 100f);
					}
				}
				list.Sort((Vector2 a, Vector2 b) => (a.y != b.y) ? b.y.CompareTo(a.y) : b.x.CompareTo(a.x));
				string text = "";
				foreach (Vector2 item in list)
				{
					string[] obj = new string[6] { text, "(", null, null, null, null };
					float x = item.x;
					obj[2] = x.ToString("0.00");
					obj[3] = ",";
					x = item.y;
					obj[4] = x.ToString("0.00");
					obj[5] = ") ";
					text = string.Concat(obj);
				}
				Debug.Log((object)("[HoleSizeMod] " + label + " cup profile (r,y): " + text));
				CupShape cupShape = new CupShape();
				cupShape.OpeningRadius = -1f;
				foreach (Vector2 item2 in list)
				{
					if (Mathf.Abs(item2.y - num) < 0.015f && item2.x > 0.02f && item2.x < plateRadius * 0.9f)
					{
						cupShape.OpeningRadius = Mathf.Max(cupShape.OpeningRadius, item2.x);
					}
				}
				if (cupShape.OpeningRadius <= 0f)
				{
					return null;
				}
				float num5 = float.MaxValue;
				foreach (Vector2 item3 in list)
				{
					if (item3.y < num - 0.015f && item3.x <= cupShape.OpeningRadius + 0.02f)
					{
						num5 = Mathf.Min(num5, item3.y);
					}
				}
				float num6 = float.MaxValue;
				foreach (Vector2 item4 in list)
				{
					if (item4.y >= num - 0.015f || item4.x > cupShape.OpeningRadius + 0.02f)
					{
						continue;
					}
					if (item4.x < 0.02f)
					{
						if (Mathf.Abs(item4.y - num5) < 0.015f)
						{
							cupShape.HasFloor = true;
						}
					}
					else if (!(Mathf.Abs(item4.y - num6) < 0.015f))
					{
						cupShape.Wall.Add(item4);
						num6 = item4.y;
					}
				}
				if (cupShape.Wall.Count == 0 || cupShape.Wall.Count > 16)
				{
					return null;
				}
				cupShape.InnerRadius = cupShape.OpeningRadius;
				foreach (Vector2 item5 in cupShape.Wall)
				{
					cupShape.InnerRadius = Mathf.Min(cupShape.InnerRadius, item5.x);
				}
				return cupShape;
			}
		}

		private const float HostWait = 8f;

		public static readonly Dictionary<GolfHole, HoleState> States = new Dictionary<GolfHole, HoleState>();

		[HarmonyPostfix]
		private static void Postfix(GolfHole __instance)
		{
			//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)
			LobbySync.RefreshNow();
			bool effectiveHolesEnabled = LobbySync.EffectiveHolesEnabled;
			float scale = LobbySync.EffectiveHoleScale;
			bool flag = effectiveHolesEnabled && LobbySync.EffectiveHolesRandom;
			Scene scene = ((Component)__instance).gameObject.scene;
			string name = ((Scene)(ref scene)).name;
			Debug.Log((object)("[HoleSizeMod] Hole loading. role=" + LobbySync.CurrentRole.ToString() + " enabled=" + effectiveHolesEnabled + " random=" + flag + " scale=" + scale + " scene=" + name));
			if (effectiveHolesEnabled && LobbySync.CurrentRole == LobbySync.Role.ClientHostModded)
			{
				Plugin.CurrentHoleScale = 1f;
				if ((Object)(object)Plugin.Instance != (Object)null)
				{
					((MonoBehaviour)Plugin.Instance).StartCoroutine(WaitForHostRandom(__instance, name));
				}
				return;
			}
			if (flag)
			{
				scale = Plugin.NextRandomScale(Plugin.RandomMax);
				Debug.Log((object)("[HoleSizeMod] Random size for this hole: " + Plugin.Describe(scale)));
			}
			Apply(__instance, effectiveHolesEnabled, scale, fromHost: false);
		}

		private static void ShareFinal(GolfHole hole, float scale)
		{
			//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)
			if (!((Object)(object)hole == (Object)null))
			{
				Plugin.SharedHole = hole;
				Plugin.SharedScale = scale;
				if (LobbySync.CurrentRole == LobbySync.Role.Host)
				{
					Scene scene = ((Component)hole).gameObject.scene;
					LobbySync.PublishRandomHole(((Scene)(ref scene)).name, scale);
					Debug.Log((object)("[HoleSizeMod] Shared final hole size with joining players: " + Plugin.Describe(scale)));
				}
			}
		}

		private static IEnumerator WaitForHostRandom(GolfHole hole, string scene)
		{
			float fallbackAt = Time.realtimeSinceStartup + 8f;
			while ((Object)(object)hole != (Object)null && LobbySync.CurrentRole == LobbySync.Role.ClientHostModded)
			{
				LobbySync.RefreshNow();
				bool late = Time.realtimeSinceStartup > fallbackAt;
				if (LobbySync.TryTakeHostRandomHole(scene, late, out var scale))
				{
					Debug.Log((object)("[HoleSizeMod] Host's size for this hole: " + Plugin.Describe(scale) + (late ? " (latest shared)" : "")));
					Apply(hole, enabled: true, scale, fromHost: true);
					break;
				}
				if (late)
				{
					float own = (LobbySync.EffectiveHolesRandom ? Plugin.NextRandomScale(Plugin.RandomMax) : LobbySync.EffectiveHoleScale);
					Debug.LogWarning((object)("[HoleSizeMod] No size from the host; using our own: " + Plugin.Describe(own)));
					Apply(hole, enabled: true, own, fromHost: false);
					break;
				}
				yield return (object)new WaitForSecondsRealtime(0.25f);
			}
		}

		private static void Apply(GolfHole __instance, bool enabled, float scale, bool fromHost)
		{
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Expected O, but got Unknown
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_055e: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_063f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0644: Unknown result type (might be due to invalid IL or missing references)
			//IL_064b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_065c: Unknown result type (might be due to invalid IL or missing references)
			//IL_054f: Unknown result type (might be due to invalid IL or missing references)
			//IL_069d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0722: Unknown result type (might be due to invalid IL or missing references)
			//IL_0727: Unknown result type (might be due to invalid IL or missing references)
			//IL_073c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_075d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			bool effectiveOn = WanderingHole.EffectiveOn;
			if (!enabled)
			{
				scale = 1f;
			}
			Plugin.CurrentHoleScale = scale;
			PauseRulesSummary.Refresh();
			if (!effectiveOn && Mathf.Abs(scale - 1f) < 0.001f)
			{
				if (!fromHost)
				{
					ShareFinal(__instance, scale);
				}
				return;
			}
			Collider collider = __instance.Collider;
			if ((Object)(object)collider == (Object)null)
			{
				return;
			}
			Transform transform = ((Component)collider).transform;
			if (LobbySync.CurrentRole == LobbySync.Role.ClientHostModded)
			{
				Vector3 localScale = transform.localScale;
				if (Mathf.Abs(localScale.y) > 0.0001f && Mathf.Abs(localScale.x - localScale.z) <= Mathf.Abs(localScale.x) * 0.01f)
				{
					float num = localScale.x / localScale.y;
					if (Mathf.Abs(num - 1f) > 0.01f)
					{
						localScale.x /= num;
						localScale.z /= num;
						transform.localScale = localScale;
						Physics.SyncTransforms();
						Debug.Log((object)("[HoleSizeMod] Hole arrived already widened " + num.ToString("0.##") + "x by the host; reset it before resizing."));
					}
				}
			}
			List<TriggerSnapshot> triggers = SnapshotTriggers(__instance, transform);
			LogTriggers("before", triggers);
			float holePixelWorldSize = TerrainHoleMaskGrower.GetHolePixelWorldSize(transform.position);
			float num2 = (Mathf.Abs(transform.lossyScale.x) + Mathf.Abs(transform.lossyScale.z)) * 0.5f;
			float localMeshRadius = GetLocalMeshRadius(transform);
			MeshFilter component = ((Component)transform).GetComponent<MeshFilter>();
			MeshCollider component2 = ((Component)transform).GetComponent<MeshCollider>();
			float y;
			Bounds bounds;
			if (!((Object)(object)component != (Object)null) || !((Object)(object)component.sharedMesh != (Object)null))
			{
				y = transform.position.y;
			}
			else
			{
				bounds = component.sharedMesh.bounds;
				y = transform.TransformPoint(new Vector3(0f, ((Bounds)(ref bounds)).max.y, 0f)).y;
			}
			float cupTopWorldY = y;
			CupShape cupShape = CupShape.Read(((Object)(object)component != (Object)null) ? component.sharedMesh : null, localMeshRadius, "visual");
			CupShape cupShape2 = CupShape.Read(((Object)(object)component2 != (Object)null) ? component2.sharedMesh : null, localMeshRadius, "collider");
			if (cupShape2 == null)
			{
				cupShape2 = cupShape;
			}
			if (cupShape == null)
			{
				float bottomY;
				if (!((Object)(object)component != (Object)null) || !((Object)(object)component.sharedMesh != (Object)null))
				{
					bottomY = -1f;
				}
				else
				{
					bounds = component.sharedMesh.bounds;
					bottomY = ((Bounds)(ref bounds)).min.y;
				}
				cupShape = CupShape.Fallback(localMeshRadius, bottomY);
			}
			if (cupShape2 == null)
			{
				cupShape2 = cupShape;
			}
			int layer;
			float[] array = GreenShape.Measure(transform.position, out layer);
			float baseOpening = cupShape.OpeningRadius * num2;
			float num3 = GreenShape.MaxScaleFor(array, baseOpening, holePixelWorldSize);
			if (!fromHost && !Plugin.IsBallSized(scale) && scale > num3)
			{
				Debug.Log((object)("[HoleSizeMod] Green is small here: hole " + scale.ToString("0.##") + "x capped to " + num3.ToString("0.##") + "x"));
				scale = num3;
				Plugin.CurrentHoleScale = scale;
				PauseRulesSummary.Refresh();
			}
			if (!fromHost)
			{
				ShareFinal(__instance, scale);
			}
			if (Plugin.IsBallSized(scale))
			{
				float num4 = BallRadiusFinder.Find();
				scale = num4 * 1.12f / Mathf.Max(0.01f, cupShape.InnerRadius * num2);
				Debug.Log((object)("[HoleSizeMod] Ball sized hole: ball radius " + num4.ToString("0.000") + " m -> scale " + scale.ToString("0.000")));
			}
			float num5 = cupShape.OpeningRadius * num2 * scale;
			float num6 = cupShape.InnerRadius * num2 * scale;
			float num7 = localMeshRadius * num2;
			float num8 = holePixelWorldSize * 1.7f;
			float num9 = 1f + num8 / Mathf.Max(0.01f, num5);
			Vector3 localScale2 = transform.localScale;
			localScale2.x *= scale;
			localScale2.z *= scale;
			transform.localScale = localScale2;
			foreach (Transform item in transform)
			{
				Transform val = item;
				if (!(((Object)val).name == "Trigger") && !(((Object)val).name == "Backup colliders"))
				{
					Vector3 localScale3 = val.localScale;
					localScale3.x /= scale;
					localScale3.z /= scale;
					val.localScale = localScale3;
					Vector3 localPosition = val.localPosition;
					localPosition.x /= scale;
					localPosition.z /= scale;
					val.localPosition = localPosition;
				}
			}
			ReplaceHoleMesh(transform, num9, cupShape, cupShape2);
			Bounds val2 = (Bounds)(((Object)(object)((Component)transform).GetComponent<MeshFilter>() != (Object)null && (Object)(object)((Component)transform).GetComponent<MeshFilter>().sharedMesh != (Object)null) ? ((Component)transform).GetComponent<MeshFilter>().sharedMesh.bounds : new Bounds(Vector3.zero, Vector3.one));
			float y2 = transform.TransformPoint(new Vector3(0f, ((Bounds)(ref val2)).min.y, 0f)).y;
			ApplyTriggerSizes(triggers, scale, num6 * 2f, y2, cupTopWorldY);
			FixBackupColliders(transform, num5);
			Physics.SyncTransforms();
			LogTriggers("after", triggers);
			TerrainCollarRepainter.Repaint(transform.position, scale, num5 + 3f);
			TerrainHoleMaskGrower.Restore(transform.position, num5 + holePixelWorldSize * 0.8f, num7 * 1.45f + holePixelWorldSize * 3f);
			TerrainHoleMaskGrower.Grow(transform.position, num5 + holePixelWorldSize * 0.8f);
			HoleState holeState = new HoleState
			{
				Hole = __instance,
				HoleT = transform,
				VisualCup = cupShape,
				ColliderCup = cupShape2,
				LipMultiplier = num9,
				OpeningWorld = num5,
				HolePixelWorld = holePixelWorldSize,
				Origin = transform.position,
				HeightAboveGround = transform.position.y - GroundHeightAt(transform.position, transform.position.y),
				GreenDist = array,
				GreenLayer = layer
			};
			if ((Object)(object)Plugin.Instance != (Object)null)
			{
				holeState.GrassRoutine = ((MonoBehaviour)Plugin.Instance).StartCoroutine(GrassClearer.ClearAroundHole(transform.position, num5 * num9, holeState.Grass));
			}
			States[__instance] = holeState;
			if (!Mathf.Approximately(scale, 1f))
			{
				Transform val3 = transform.Find("Object fade plane");
				if ((Object)(object)val3 != (Object)null)
				{
					Renderer component3 = ((Component)val3).GetComponent<Renderer>();
					if ((Object)(object)component3 != (Object)null)
					{
						component3.enabled = false;
					}
				}
			}
			Bounds bounds2 = collider.bounds;
			Debug.Log((object)("[HoleSizeMod] Pit world bounds: center=" + ((object)((Bounds)(ref bounds2)).center/*cast due to .constrained prefix*/).ToString() + " size=" + ((object)((Bounds)(ref bounds2)).size/*cast due to .constrained prefix*/).ToString() + " opening=" + num5 + " inner=" + num6 + " holePixel=" + holePixelWorldSize + " lipMultiplier=" + num9));
		}

		public static HoleState GetState(GolfHole hole)
		{
			if ((Object)(object)hole == (Object)null || !States.TryGetValue(hole, out var value) || (Object)(object)value.HoleT == (Object)null)
			{
				return null;
			}
			return value;
		}

		public static float GroundHeightAt(Vector3 p, float fallback)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			Terrain[] activeTerrains = Terrain.activeTerrains;
			foreach (Terrain val in activeTerrains)
			{
				Vector3 position = ((Component)val).transform.position;
				Vector3 size = val.terrainData.size;
				if (p.x >= position.x && p.x <= position.x + size.x && p.z >= position.z && p.z <= position.z + size.z)
				{
					return val.SampleHeight(p) + position.y;
				}
			}
			return fallback;
		}

		public unsafe static void Relocate(HoleState state, Vector3 target)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_0018: 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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0150: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			Transform holeT = state.HoleT;
			Vector3 position = holeT.position;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(target.x, GroundHeightAt(target, position.y) + state.HeightAboveGround, target.z);
			List<KeyValuePair<Transform, Pose>> list = new List<KeyValuePair<Transform, Pose>>();
			Transform val2 = null;
			try
			{
				val2 = Traverse.Create((object)state.Hole).Field("flag").GetValue<Transform>();
			}
			catch
			{
			}
			foreach (Transform item in holeT)
			{
				Transform val3 = item;
				string name = ((Object)val3).name;
				if (!(name == "Trigger") && !(name == "Backup colliders") && !name.Contains("fade") && !name.Contains("Beam") && (!((Object)(object)val2 != (Object)null) || (!((Object)(object)val3 == (Object)(object)val2) && !val2.IsChildOf(val3))))
				{
					list.Add(new KeyValuePair<Transform, Pose>(val3, new Pose(val3.position, val3.rotation)));
				}
			}
			float restoreRadius = state.OpeningWorld + state.HolePixelWorld * 1.6f;
			TerrainHoleMaskGrower.Restore(position, -1f, restoreRadius);
			holeT.position = val;
			foreach (KeyValuePair<Transform, Pose> item2 in list)
			{
				if ((Object)(object)item2.Key != (Object)null)
				{
					item2.Key.SetPositionAndRotation(item2.Value.position, item2.Value.rotation);
				}
			}
			ReplaceHoleMeshAgain(holeT, state);
			Physics.SyncTransforms();
			TerrainHoleMaskGrower.Grow(val, state.OpeningWorld + state.HolePixelWorld * 0.8f, refreshCollider: false);
			Physics.SyncTransforms();
			Vector2 val4 = new Vector2(position.x - val.x, position.z - val.z);
			bool flag = ((Vector2)(ref val4)).magnitude < state.RimRadius + 0.5f;
			if (TerrainHoleMaskGrower.TerrainStillSolidAt(val) || (!flag && !TerrainHoleMaskGrower.TerrainStillSolidAt(position)))
			{
				Debug.Log((object)"[HoleSizeMod] Terrain collision didn't update by itself; refreshing it.");
				TerrainHoleMaskGrower.RefreshCollidersAround(val);
			}
			if ((Object)(object)Plugin.Instance != (Object)null && state.GrassRoutine != null)
			{
				((MonoBehaviour)Plugin.Instance).StopCoroutine(state.GrassRoutine);
			}
			state.GrassRoutine = null;
			GrassClearer.Move(state.Grass, val, state.RimRadius);
			Debug.Log((object)("[HoleSizeMod] Hole moved from " + ((object)(*(Vector3*)(&position))/*cast due to .constrained prefix*/).ToString() + " to " + ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString()));
		}

		private static void ReplaceHoleMeshAgain(Transform holeT, HoleState state)
		{
			MeshFilter component = ((Component)holeT).GetComponent<MeshFilter>();
			MeshCollider component2 = ((Component)holeT).GetComponent<MeshCollider>();
			float topY = 0f;
			if ((Object)(object)component != (Object)null)
			{
				Mesh sharedMesh = component.sharedMesh;
				Mesh val = GenerateCircularPit(holeT, state.VisualCup.OpeningRadius, topY, 96, state.VisualCup.HasFloor, state.LipMultiplier, new float[3] { 0.01f, 0.01f, 0.005f }, state.VisualCup.Wall);
				((Object)val).name = "GeneratedCircularHoleVisual";
				component.mesh = val;
				if ((Object)(object)sharedMesh != (Object)null && ((Object)sharedMesh).name.StartsWith("Generated"))
				{
					Object.Destroy((Object)(object)sharedMesh);
				}
			}
			if ((Object)(object)component2 != (Object)null)
			{
				Mesh sharedMesh2 = component2.sharedMesh;
				Mesh val2 = GenerateCircularPit(holeT, state.VisualCup.OpeningRadius, topY, 96, state.ColliderCup.HasFloor, state.LipMultiplier, new float[3], state.ColliderCup.Wall);
				((Object)val2).name = "GeneratedCircularHoleCollider";
				component2.sharedMesh = val2;
				if ((Object)(object)sharedMesh2 != (Object)null && ((Object)sharedMesh2).name.StartsWith("Generated"))
				{
					Object.Destroy((Object)(object)sharedMesh2);
				}
			}
		}

		private static List<TriggerSnapshot> SnapshotTriggers(GolfHole hole, Transform holeT)
		{
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			List<TriggerSnapshot> list = new List<TriggerSnapshot>();
			GolfHoleTrigger componentInChildren = ((Component)holeT).GetComponentInChildren<GolfHoleTrigger>(true);
			if ((Object)(object)componentInChildren == (Object)null)
			{
				componentInChildren = ((Component)hole).GetComponentInChildren<GolfHoleTrigger>(true);
			}
			if ((Object)(object)componentInChildren == (Object)null && (Object)(object)((Component)hole).transform.parent != (Object)null)
			{
				componentInChildren = ((Component)((Component)hole).transform.parent).GetComponentInChildren<GolfHoleTrigger>(true);
			}
			if ((Object)(object)componentInChildren == (Object)null)
			{
				Debug.LogWarning((object)("[HoleSizeMod] Could not find GolfHoleTrigger for hole '" + ((Object)hole).name + "'"));
				return list;
			}
			Debug.Log((object)("[HoleSizeMod] Trigger object path: " + GetPath(((Component)componentInChildren).transform) + "  hole collider path: " + GetPath(holeT)));
			Traverse val = Traverse.Create((object)componentInChildren);
			string[] array = new string[3] { "ballTrigger", "golfCartTrigger", "generalTrigger" };
			foreach (string text in array)
			{
				Collider value = val.Field(text).GetValue<Collider>();
				BoxCollider val2 = (BoxCollider)(object)((value is BoxCollider) ? value : null);
				if ((Object)(object)val2 == (Object)null)
				{
					Debug.LogWarning((object)("[HoleSizeMod] " + text + " is " + (((Object)(object)value == (Object)null) ? "missing" : ((object)value).GetType().Name) + ", not a BoxCollider; not resized."));
				}
				else
				{
					Vector3 lossyScale = ((Component)val2).transform.lossyScale;
					list.Add(new TriggerSnapshot
					{
						name = text,
						box = val2,
						worldCenter = ((Component)val2).transform.TransformPoint(val2.center),
						worldSize = new Vector3(Mathf.Abs(val2.size.x * lossyScale.x), Mathf.Abs(val2.size.y * lossyScale.y), Mathf.Abs(val2.size.z * lossyScale.z))
					});
				}
			}
			return list;
		}

		private static void ApplyTriggerSizes(List<TriggerSnapshot> triggers, float scale, float pitDiameter, float floorWorldY, float cupTopWorldY)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0051: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: 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_01e3: 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_01f7: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			foreach (TriggerSnapshot trigger in triggers)
			{
				Transform transform = ((Component)trigger.box).transform;
				Vector3 lossyScale = transform.lossyScale;
				Vector3 worldCenter = trigger.worldCenter;
				Vector3 worldSize = trigger.worldSize;
				if (trigger.name == "golfCartTrigger")
				{
					float num = Mathf.Max(worldSize.x * scale, pitDiameter);
					((Vector3)(ref worldSize))..ctor(num, worldSize.y, num);
				}
				else
				{
					float num2 = Mathf.Max(worldSize.x * scale, pitDiameter * 0.95f);
					((Vector3)(ref worldSize))..ctor(num2, worldSize.y, num2);
					if (trigger.name == "ballTrigger")
					{
						float num3 = worldCenter.y - worldSize.y * 0.5f;
						float num4 = Mathf.Max(worldCenter.y + worldSize.y * 0.5f, cupTopWorldY - 0.3f);
						worldSize.y = num4 - num3;
						worldCenter.y = (num4 + num3) * 0.5f;
					}
					if (trigger.name == "generalTrigger")
					{
						float num5 = worldCenter.y - worldSize.y * 0.5f;
						float num6 = Mathf.Max(worldCenter.y + worldSize.y * 0.5f, floorWorldY + 0.5f);
						worldSize.y = num6 - num5;
						worldCenter.y = (num6 + num5) * 0.5f;
					}
				}
				trigger.box.size = new Vector3(worldSize.x / Mathf.Max(1E-05f, Mathf.Abs(lossyScale.x)), worldSize.y / Mathf.Max(1E-05f, Mathf.Abs(lossyScale.y)), worldSize.z / Mathf.Max(1E-05f, Mathf.Abs(lossyScale.z)));
				trigger.box.center = transform.InverseTransformPoint(worldCenter);
			}
		}

		private static void LogSolidCollidersInHole(Transform holeT, float openingWorld, float cupTopWorldY)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = holeT.position;
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(openingWorld * 0.9f, 3f, openingWorld * 0.9f);
			Collider[] array = Physics.OverlapBox(new Vector3(position.x, cupTopWorldY - 2f, position.z), val, Quaternion.identity, -1, (QueryTriggerInteraction)1);
			foreach (Collider val2 in array)
			{
				if (!(val2 is TerrainCollider) && !((Object)(object)((Component)val2).transform == (Object)(object)holeT) && (!((Object)(object)((Component)val2).transform.parent != (Object)null) || !(((Object)((Component)val2).transform.parent).name == "Backup colliders")) && !(((Object)((Component)val2).transform).name == "Backup colliders"))
				{
					string[] obj = new string[10]
					{
						"[HoleSizeMod] Solid collider in hole: ",
						GetPath(((Component)val2).transform),
						" [",
						((object)val2).GetType().Name,
						"] layer=",
						LayerMask.LayerToName(((Component)val2).gameObject.layer),
						" bounds c=",
						null,
						null,
						null
					};
					Bounds bounds = val2.bounds;
					obj[7] = ((object)((Bounds)(ref bounds)).center/*cast due to .constrained prefix*/).ToString();
					obj[8] = " s=";
					bounds = val2.bounds;
					obj[9] = ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString();
					Debug.Log((object)string.Concat(obj));
				}
			}
		}

		private static void LogTriggers(string when, List<TriggerSnapshot> triggers)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			foreach (TriggerSnapshot trigger in triggers)
			{
				Bounds bounds = ((Collider)trigger.box).bounds;
				Debug.Log((object)("[HoleSizeMod] Trigger " + trigger.name + " (" + when + "): world center=" + ((object)((Bounds)(ref bounds)).center/*cast due to .constrained prefix*/).ToString() + " size=" + ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString() + " enabled=" + ((Collider)trigger.box).enabled + " isTrigger=" + ((Collider)trigger.box).isTrigger));
			}
		}

		private static void FixBackupColliders(Transform holeT, float pitWorldRadius)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_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_0093: 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_00c7: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//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_01ce: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			Transform val = holeT.Find("Backup colliders");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			BoxCollider[] components = ((Component)val).GetComponents<BoxCollider>();
			Vector3 center = default(Vector3);
			foreach (BoxCollider val2 in components)
			{
				Transform transform = ((Component)val2).transform;
				Vector3 lossyScale = transform.lossyScale;
				float num = Mathf.Max(1E-05f, Mathf.Abs(lossyScale.x));
				float num2 = Mathf.Max(1E-05f, Mathf.Abs(lossyScale.z));
				Vector3 val3 = transform.InverseTransformPoint(holeT.position);
				Vector3 val4 = val2.center - val3;
				bool flag = Mathf.Abs(val4.x * num) > Mathf.Abs(val4.z * num2);
				float num3 = (flag ? Mathf.Sign(val4.x) : Mathf.Sign(val4.z));
				float num4 = pitWorldRadius + 0.25f;
				float num5 = 2f * (pitWorldRadius + 0.5f);
				((Vector3)(ref center))..ctor(val3.x, val2.center.y, val3.z);
				Vector3 size = val2.size;
				if (flag)
				{
					center.x += num3 * num4 / num;
					size.x = 0.5f / num;
					size.z = num5 / num2;
				}
				else
				{
					center.z += num3 * num4 / num2;
					size.z = 0.5f / num2;
					size.x = num5 / num;
				}
				val2.center = center;
				val2.size = size;
			}
			Physics.SyncTransforms();
			BoxCollider[] components2 = ((Component)val).GetComponents<BoxCollider>();
			foreach (BoxCollider val5 in components2)
			{
				Bounds bounds = ((Collider)val5).bounds;
				string? text = ((object)((Bounds)(ref bounds)).center/*cast due to .constrained prefix*/).ToString();
				bounds = ((Collider)val5).bounds;
				Debug.Log((object)("[HoleSizeMod] Backup collider moved: c=" + text + " s=" + ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString()));
			}
		}

		private unsafe static void LogMaterial(Material m)
		{
			//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_00c8: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00eb: Expected I4, but got Unknown
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)m == (Object)null)
			{
				return;
			}
			Shader shader = m.shader;
			string text = "[HoleSizeMod] Material '" + ((Object)m).name + "' shader='" + (((Object)(object)shader != (Object)null) ? ((Object)shader).name : "null") + "' renderQueue=" + m.renderQueue + " keywords=" + string.Join(" ", m.shaderKeywords);
			Debug.Log((object)text);
			if ((Object)(object)shader == (Object)null)
			{
				return;
			}
			for (int i = 0; i < shader.GetPropertyCount(); i++)
			{
				string propertyName = shader.GetPropertyName(i);
				ShaderPropertyType propertyType = shader.GetPropertyType(i);
				string text2 = "";
				try
				{
					ShaderPropertyType val = propertyType;
					ShaderPropertyType val2 = val;
					switch ((int)val2)
					{
					case 0:
						text2 = ((object)m.GetColor(propertyName)/*cast due to .constrained prefix*/).ToString();
						break;
					case 1:
						text2 = ((object)m.GetVector(propertyName)/*cast due to .constrained prefix*/).ToString();
						break;
					case 2:
					case 3:
						text2 = m.GetFloat(propertyName).ToString("F3");
						break;
					case 4:
					{
						Texture texture = m.GetTexture(propertyName);
						text2 = (((Object)(object)texture != (Object)null) ? ((Object)texture).name : "none");
						break;
					}
					default:
						text2 = ((object)(*(ShaderPropertyType*)(&propertyType))/*cast due to .constrained prefix*/).ToString();
						break;
					}
				}
				catch
				{
				}
				Debug.Log((object)("[HoleSizeMod]   " + propertyName + " (" + ((object)(*(ShaderPropertyType*)(&propertyType))/*cast due to .constrained prefix*/).ToString() + ") = " + text2));
			}
		}

		private unsafe static void LogEverythingNear(GolfHole hole, Transform holeT, float radius)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: 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_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			Transform val = ((Component)hole).transform;
			while ((Object)(object)val.parent != (Object)null && (Object)(object)((Component)val.parent).GetComponentInParent<GolfHole>() == (Object)null && val.parent.childCount < 50)
			{
				val = val.parent;
			}
			Debug.Log((object)("[HoleSizeMod] ---- Hierarchy under '" + GetPath(val) + "' ----"));
			LogTree(val, 0);
			Vector3 position = holeT.position;
			MeshRenderer component = ((Component)holeT).GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				LogMaterial(((Renderer)component).sharedMaterial);
			}
			Debug.Log((object)("[HoleSizeMod] ---- Colliders within " + radius.ToString("F1") + "m ----"));
			Collider[] array = Physics.OverlapSphere(position, radius, -1, (QueryTriggerInteraction)2);
			Vector3 val3;
			foreach (Collider val2 in array)
			{
				if (!(val2 is TerrainCollider))
				{
					string[] obj = new string[14]
					{
						"[HoleSizeMod]   ",
						GetPath(((Component)val2).transform),
						" [",
						((object)val2).GetType().Name,
						"] trigger=",
						val2.isTrigger.ToString(),
						" enabled=",
						val2.enabled.ToString(),
						" layer=",
						LayerMask.LayerToName(((Component)val2).gameObject.layer),
						" bounds c=",
						null,
						null,
						null
					};
					Bounds bounds = val2.bounds;
					val3 = ((Bounds)(ref bounds)).center;
					obj[11] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
					obj[12] = " s=";
					bounds = val2.bounds;
					val3 = ((Bounds)(ref bounds)).size;
					obj[13] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
					Debug.Log((object)string.Concat(obj));
				}
			}
			Debug.Log((object)("[HoleSizeMod] ---- Renderers within " + radius.ToString("F1") + "m ----"));
			Renderer[] array2 = Object.FindObjectsByType<Renderer>((FindObjectsSortMode)0);
			foreach (Renderer val4 in array2)
			{
				Bounds bounds2 = val4.bounds;
				Vector3 val5 = ((Bounds)(ref bounds2)).ClosestPoint(position);
				val3 = val5 - position;
				if (!(((Vector3)(ref val3)).sqrMagnitude > radius * radius) && !(((Bounds)(ref bounds2)).size.x > 200f) && !(((Bounds)(ref bounds2)).size.z > 200f))
				{
					string text = "";
					Material[] sharedMaterials = val4.sharedMaterials;
					foreach (Material val6 in sharedMaterials)
					{
						text = text + (((Object)(object)val6 != (Object)null) ? ((Object)val6).name : "null") + ",";
					}
					string[] obj2 = new string[14]
					{
						"[HoleSizeMod]   ",
						GetPath(((Component)val4).transform),
						" [",
						((object)val4).GetType().Name,
						"] enabled=",
						val4.enabled.ToString(),
						" active=",
						((Component)val4).gameObject.activeInHierarchy.ToString(),
						" mats=",
						text,
						" bounds c=",
						null,
						null,
						null
					};
					val3 = ((Bounds)(ref bounds2)).center;
					obj2[11] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
					obj2[12] = " s=";
					val3 = ((Bounds)(ref bounds2)).size;
					obj2[13] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
					Debug.Log((object)string.Concat(obj2));
				}
			}
		}

		private static void LogTree(Transform t, int depth)
		{
			//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_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			string text = "";
			Component[] components = ((Component)t).GetComponents<Component>();
			foreach (Component val in components)
			{
				if (!((Object)(object)val == (Object)null) && !(val is Transform))
				{
					text = text + ((object)val).GetType().Name + ",";
				}
			}
			Debug.Log((object)("[HoleSizeMod] " + new string(' ', depth * 2) + ((Object)t).name + " localPos=" + ((object)t.localPosition/*cast due to .constrained prefix*/).ToString() + " localScale=" + ((object)t.localScale/*cast due to .constrained prefix*/).ToString() + " active=" + ((Component)t).gameObject.activeSelf + " {" + text + "}"));
			if (depth >= 6)
			{
				return;
			}
			foreach (Transform item in t)
			{
				Transform t2 = item;
				LogTree(t2, depth + 1);
			}
		}

		private static string GetPath(Transform t)
		{
			string text = ((Object)t).name;
			while ((Object)(object)t.parent != (Object)null)
			{
				t = t.parent;
				text = ((Object)t).name + "/" + text;
			}
			return text;
		}

		private static float GetLocalMeshRadius(Transform holeT)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter component = ((Component)holeT).GetComponent<MeshFilter>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
			{
				return 1.25f;
			}
			Bounds bounds = component.sharedMesh.bounds;
			return (((Bounds)(ref bounds)).extents.x + ((Bounds)(ref bounds)).extents.z) * 0.5f;
		}

		private static void ReplaceHoleMesh(Transform holeT, float lipMultiplier, CupShape visualCup, CupShape colliderCup)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			MeshFilter component = ((Component)holeT).GetComponent<MeshFilter>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
			{
				Debug.LogWarning((object)"[HoleSizeMod] No MeshFilter/sharedMesh found on Hole to replace.");
				return;
			}
			Bounds bounds = component.sharedMesh.bounds;
			float y = ((Bounds)(ref bounds)).max.y;
			Mesh val = GenerateCircularPit(holeT, visualCup.OpeningRadius, y, 96, visualCup.HasFloor, lipMultiplier, new float[3] { 0.01f, 0.01f, 0.005f }, visualCup.Wall);
			((Object)val).name = "GeneratedCircularHoleVisual";
			component.mesh = val;
			MeshCollider component2 = ((Component)holeT).GetComponent<MeshCollider>();
			if ((Object)(object)component2 != (Object)null)
			{
				Mesh val2 = GenerateCircularPit(holeT, visualCup.OpeningRadius, y, 96, colliderCup.HasFloor, lipMultiplier, new float[3], colliderCup.Wall);
				((Object)val2).name = "GeneratedCircularHoleCollider";
				component2.sharedMesh = val2;
			}
			else
			{
				Debug.LogWarning((object)"[HoleSizeMod] No MeshCollider found on Hole — physical shape may not match visual shape.");
			}
			Debug.Log((object)("[HoleSizeMod] Replaced Hole mesh. opening=" + visualCup.OpeningRadius + " inner=" + visualCup.InnerRadius + " visualFloor=" + visualCup.HasFloor + " colliderFloor=" + colliderCup.HasFloor + " colliderDepth=" + colliderCup.Wall[colliderCup.Wall.Count - 1].y));
		}

		private static Vector3[] ReadPositions(Mesh mesh, string label)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)mesh == (Object)null)
			{
				return null;
			}
			if (mesh.isReadable)
			{
				return mesh.vertices;
			}
			try
			{
				if ((int)mesh.GetVertexAttributeFormat((VertexAttribute)0) > 0)
				{
					return null;
				}
				int vertexAttributeStream = mesh.GetVertexAttributeStream((VertexAttribute)0);
				int vertexAttributeOffset = mesh.GetVertexAttributeOffset((VertexAttribute)0);
				int vertexBufferStride = mesh.GetVertexBufferStride(vertexAttributeStream);
				int vertexCount = mesh.vertexCount;
				if (vertexBufferStride % 4 != 0 || vertexAttributeOffset % 4 != 0 || vertexCount <= 0)
				{
					return null;
				}
				float[] array = new float[vertexBufferStride / 4 * vertexCount];
				GraphicsBuffer vertexBuffer = mesh.GetVertexBuffer(vertexAttributeStream);
				try
				{
					if (vertexBuffer == null)
					{
						return null;
					}
					vertexBuffer.GetData((Array)array);
				}
				finally
				{
					((IDisposable)vertexBuffer)?.Dispose();
				}
				Vector3[] array2 = (Vector3[])(object)new Vector3[vertexCount];
				int num = vertexBufferStride / 4;
				int num2 = vertexAttributeOffset / 4;
				for (int i = 0; i < vertexCount; i++)
				{
					array2[i] = new Vector3(array[i * num + num2], array[i * num + num2 + 1], array[i * num + num2 + 2]);
				}
				return array2;
			}
			catch (Exception ex)
			{
				Debug.Log((object)("[HoleSizeMod] Couldn't read " + label + " mesh from the GPU: " + ex.Message));
				return null;
			}
		}

		private static bool MeshHasFloor(Mesh mesh)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00af: 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)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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)
			if (!mesh.isReadable)
			{
				return true;
			}
			Vector3[] vertices = mesh.vertices;
			int[] triangles = mesh.triangles;
			Bounds bounds = mesh.bounds;
			float y = ((Bounds)(ref bounds)).min.y;
			bounds = mesh.bounds;
			float num = Mathf.Max(0.001f, ((Bounds)(ref bounds)).size.y);
			for (int i = 0; i + 2 < triangles.Length; i += 3)
			{
				Vector3 val = vertices[triangles[i]];
				Vector3 val2 = vertices[triangles[i + 1]];
				Vector3 val3 = vertices[triangles[i + 2]];
				if (val.y < y + num * 0.1f && val2.y < y + num * 0.1f && val3.y < y + num * 0.1f)
				{
					Vector3 val4 = Vector3.Cross(val2 - val, val3 - val);
					if (((Vector3)(ref val4)).sqrMagnitude > 1E-10f)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static float GroundLocalY(Transform holeT, float localX, float localZ, float topY, float heightOffsetWorld)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = holeT.TransformPoint(new Vector3(localX, topY, localZ));
			float num = val.y;
			Terrain[] activeTerrains = Terrain.activeTerrains;
			foreach (Terrain val2 in activeTerrains)
			{
				Vector3 position = ((Component)val2).transform.position;
				Vector3 size = val2.terrainData.size;
				if (val.x >= position.x && val.x <= position.x + size.x && val.z >= position.z && val.z <= position.z + size.z)
				{
					num = Mathf.Max(num, val2.SampleHeight(val) + position.y);
				}
			}
			return holeT.InverseTransformPoint(new Vector3(val.x, num + heightOffsetWorld, val.z)).y;
		}

		private static void AddFacing(List<int> tris, Vector3[] v, int a, int b, int c)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			Vector3 val = Vector3.Cross(v[b] - v[a], v[c] - v[a]);
			Vector3 val2 = (v[a] + v[b] + v[c]) / 3f;
			Vector3 val3 = new Vector3(0f - val2.x, 0f, 0f - val2.z);
			Vector3 val4 = ((Vector3)(ref val3)).normalized + Vector3.up;
			if (Vector3.Dot(val, val4) < 0f)
			{
				tris.Add(a);
				tris.Add(c);
				tris.Add(b);
			}
			else
			{
				tris.Add(a);
				tris.Add(b);
				tris.Add(c);
			}
		}

		private static Mesh GenerateCircularPit(Transform holeT, float radius, float topY, int segments, bool includeBottom, float lipMultiplier, float[] ringOffsetsWorld, List<Vector2> wallProfile)
		{
			//IL_0023: 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_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_01a5: 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_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_01c3: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Expected O, but got Unknown
			float num = ((wallProfile != null && wallProfile.Count > 0) ? wallProfile[wallProfile.Count - 1].y : (topY - 1f));
			float[] array = new float[3]
			{
				radius,
				radius * (1f + (lipMultiplier - 1f) * 0.5f),
				radius * lipMultiplier
			};
			int num2 = array.Length;
			if (wallProfile == null || wallProfile.Count == 0)
			{
				wallProfile = new List<Vector2>
				{
					new Vector2(radius, num)
				};
			}
			int num3 = 1 + wallProfile.Count;
			int num4 = num2 * segments;
			int num5 = num4 + num3 * segments;
			Vector3[] array2 = (Vector3[])(object)new Vector3[num5 + 1];
			Vector2[] array3 = (Vector2[])(object)new Vector2[array2.Length];
			for (int i = 0; i < segments; i++)
			{
				float num6 = (float)i / (float)segments * (float)Math.PI * 2f;
				float num7 = Mathf.Cos(num6);
				float num8 = Mathf.Sin(num6);
				for (int j = 0; j < num2; j++)
				{
					float num9 = num7 * array[j];
					float num10 = num8 * array[j];
					array2[j * segments + i] = new Vector3(num9, GroundLocalY(holeT, num9, num10, topY, ringOffsetsWorld[j]), num10);
					array3[j * segments + i] = new Vector2((float)i / (float)segments, 1f);
				}
				array2[num4 + i] = array2[i];
				array3[num4 + i] = array3[i];
				for (int k = 0; k < wallProfile.Count; k++)
				{
					Vector2 val = wallProfile[k];
					int num11 = num4 + (k + 1) * segments + i;
					array2[num11] = new Vector3(num7 * val.x, val.y, num8 * val.x);
					float num12 = Mathf.InverseLerp(num, topY, val.y);
					array3[num11] = new Vector2((float)i / (float)segments, num12);
				}
			}
			float y = wallProfile[wallProfile.Count - 1].y;
			array2[num5] = new Vector3(0f, y, 0f);
			array3[num5] = new Vector2(0.5f, 0.5f);
			List<int> list = new List<int>();
			for (int l = 0; l < num3 - 1; l++)
			{
				for (int m = 0; m < segments; m++)
				{
					int num13 = (m + 1) % segments;
					int a = num4 + l * segments + m;
					int num14 = num4 + l * segments + num13;
					int b = num4 + (l + 1) * segments + m;
					int c = num4 + (l + 1) * segments + num13;
					AddFacing(list, array2, a, b, num14);
					AddFacing(list, array2, num14, b, c);
				}
			}
			if (includeBottom)
			{
				int num15 = num4 + (num3 - 1) * segments;
				for (int n = 0; n < segments; n++)
				{
					int num16 = (n + 1) % segments;
					AddFacing(list, array2, num5, num15 + num16, num15 + n);
				}
			}
			for (int num17 = 0; num17 < num2 - 1; num17++)
			{
				for (int num18 = 0; num18 < segments; num18++)
				{
					int num19 = (num18 + 1) % segments;
					int item = num17 * segments + num18;
					int item2 = num17 * segments + num19;
					int item3 = (num17 + 1) * segments + num18;
					int item4 = (num17 + 1) * segments + num19;
					list.Add(item);
					list.Add(item2);
					list.Add(item3);
					list.Add(item2);
					list.Add(item4);
					list.Add(item3);
				}
			}
			Mesh val2 = new Mesh();
			val2.vertices = array2;
			val2.uv = array3;
			val2.triangles = list.ToArray();
			val2.RecalculateNormals();
			val2.RecalculateBounds();
			return val2;
		}
	}
	public static class GreenShape
	{
		public const int Directions = 36;

		private const float Step = 0.25f;

		private const float MaxDistance = 45f;

		public static float[] Measure(Vector3 center, out int layer)
		{
			//IL_000a: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			float[] array = new float[36];
			layer = DominantLayerAt(center);
			float num = GolfHole_Resize_Patch.GroundHeightAt(center, float.NaN);
			Vector3 val = default(Vector3);
			for (int i = 0; i < 36; i++)
			{
				float num2 = (float)i * (float)Math.PI * 2f / 36f;
				((Vector3)(ref val))..ctor(Mathf.Cos(num2), 0f, Mathf.Sin(num2));
				float num3;
				for (num3 = 0.25f; num3 < 45f; num3 += 0.25f)
				{
					Vector3 p = center + val * num3;
					float num4 = GolfHole_Resize_Patch.GroundHeightAt(p, float.NaN);
					if (float.IsNaN(num4) || float.IsNaN(num) || Mathf.Abs(num4 - num) > 2.5f || DominantLayerAt(p) != layer)
					{
						break;
					}
				}
				array[i] = num3 - 0.25f;
			}
			float[] array2 = (float[])array.Clone();
			Array.Sort(array2);
			Debug.Log((object)("[HoleSizeMod] Green around hole: min " + array2[0].ToString("0.0") + "m, typical " + array2[9].ToString("0.0") + "-" + array2[27].ToString("0.0") + "m, max " + array2[35].ToString("0.0") + "m"));
			return array;
		}

		public static float EdgeToward(float[] dist, Vector3 origin, Vector3 p)
		{
			//IL_0011: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			if (dist == null)
			{
				return float.MaxValue;
			}
			float num = Mathf.Atan2(p.z - origin.z, p.x - origin.x);
			if (num < 0f)
			{
				num += (float)Math.PI * 2f;
			}
			int num2 = Mathf.RoundToInt(num / ((float)Math.PI * 2f) * 36f) % 36;
			return dist[num2];
		}

		public static float MaxScaleFor(float[] dist, float baseOpening, float holePixel)
		{
			if (dist == null || baseOpening <= 0f)
			{
				return 15f;
			}
			float[] array = (float[])dist.Clone();
			Array.Sort(array);
			float num = array[9] * 0.9f - holePixel * 1.7f;
			float num2 = num / baseOpening;
			return Mathf.Clamp(Mathf.Floor(num2 * 4f) / 4f, 1f, 15f);
		}

		public static int DominantLayerAt(Vector3 p)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			Terrain[] activeTerrains = Terrain.activeTerrains;
			foreach (Terrain val in activeTerrains)
			{
				TerrainData terrainData = val.terrainData;
				Vector3 position = ((Component)val).transform.position;
				if (p.x < position.x || p.x > position.x + terrainData.size.x || p.z < position.z || p.z > position.z + terrainData.size.z)
				{
					continue;
				}
				int num = Mathf.Clamp(Mathf.RoundToInt((p.x - position.x) / terrainData.size.x * (float)terrainData.alphamapWidth), 0, terrainData.alphamapWidth - 1);
				int num2 = Mathf.Clamp(Mathf.RoundToInt((p.z - position.z) / terrainData.size.z * (float)terrainData.alphamapHeight), 0, terrainData.alphamapHeight - 1);
				float[,,] alphamaps = terrainData.GetAlphamaps(num, num2, 1, 1);
				int num3 = 0;
				for (int j = 1; j < terrainData.alphamapLayers; j++)
				{
					if (alphamaps[0, 0, j] > alphamaps[0, 0, num3])
					{
						num3 = j;
					}
				}
				return num3;
			}
			return -1;
		}
	}
	public static class BallRadiusFinder
	{
		private static float cached = -1f;

		public static float Find()
		{
			if (cached > 0f)
			{
				return cached;
			}
			float num = -1f;
			try
			{
				GolfBall[] array = Object.FindObjectsByType<GolfBall>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				foreach (GolfBall ball in array)
				{
					num = RadiusOf(ball);
					if (num > 0f)
					{
						break;
					}
				}
				if (num <= 0f && (Object)(object)NetworkManager.singleton != (Object)null)
				{
					foreach (GameObject spawnPrefab in NetworkManager.singleton.spawnPrefabs)
					{
						if ((Object)(object)spawnPrefab == (Object)null)
						{
							continue;
						}
						GolfBall componentInChildren = spawnPrefab.GetComponentInChildren<GolfBall>(true);
						if (!((Object)(object)componentInChildren == (Object)null))
						{
							num = RadiusOf(componentInChildren);
							if (num > 0f)
							{
								break;
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[HoleSizeMod] Couldn't find the ball size: " + ex.Message));
			}
			if (num <= 0f)
			{
				Debug.LogWarning((object)"[HoleSizeMod] No golf ball found; guessing its size.");
				return 0.2f;
			}
			cached = num;
			return num;
		}

		private static float RadiusOf(GolfBall ball)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			SphereCollider component = ((Component)ball).GetComponent<SphereCollider>();
			if ((Object)(object)component == (Object)null)
			{
				return -1f;
			}
			Vector3 lossyScale = ((Component)component).transform.lossyScale;
			return component.radius * Mathf.Max(new float[3]
			{
				Mathf.Abs(lossyScale.x),
				Mathf.Abs(lossyScale.y),
				Mathf.Abs(lossyScale.z)
			});
		}
	}
	public static class GrassClearer
	{
		public class Removed
		{
			public readonly List<KeyValuePair<TerrainGrassRenderer, float3>> Tiles = new List<KeyValuePair<TerrainGrassRenderer, float3>>();
		}

		public static void Move(Removed removed, Vector3 newPos, float rimWorldRadius)
		{
			//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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				foreach (KeyValuePair<TerrainGrassRenderer, float3> tile in removed.Tiles)
				{
					if (!((Object)(object)tile.Key == (Object)null))
					{
						NativeList<float3> value = Traverse.Create((object)tile.Key).Field("nativePositions").GetValue<NativeList<float3>>();
						if (value.IsCreated)
						{
							float3 value2 = tile.Value;
							value.Add(ref value2);
						}
					}
				}
				removed.Tiles.Clear();
				TerrainGrassRenderer[] array = Object.FindObjectsByType<TerrainGrassRenderer>((FindObjectsSortMode)0);
				foreach (TerrainGrassRenderer grass in array)
				{
					ClearOnce(grass, newPos, rimWorldRadius, removed);
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[HoleSizeMod] Moving the grass failed: " + ex.Message));
			}
		}

		private static int ClearOnce(TerrainGrassRenderer grass, Vector3 holeWorldPos, float rimWorldRadius, Removed removed)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)grass);
			if (!val.Field("initialized").GetValue<bool>())
			{
				return 0;
			}
			NativeList<float3> value = val.Field("nativePositions").GetValue<NativeList<float3>>();
			if (!value.IsCreated)
			{
				return 0;
			}
			float num = 1f;
			try
			{
				num = val.Field("settings").Field("tileSize").GetValue<float>();
			}
			catch
			{
			}
			float num2 = rimWorldRadius + num;
			float num3 = num2 * num2;
			int num4 = 0;
			for (int num5 = value.Length - 1; num5 >= 0; num5--)
			{
				float3 val2 = value[num5];
				float num6 = val2.x - holeWorldPos.x;
				float num7 = val2.z - holeWorldPos.z;
				float num8 = num6 + num * 0.5f;
				float num9 = num7 + num * 0.5f;
				if (Mathf.Min(num6 * num6 + num7 * num7, num8 * num8 + num9 * num9) <= num3)
				{
					removed?.Tiles.Add(new KeyValuePair<TerrainGrassRenderer, float3>(grass, val2));
					value.RemoveAtSwapBack(num5);
					num4++;
				}
			}
			return num4;
		}

		public static IEnumerator ClearAroundHole(Vector3 holeWorldPos, float rimWorldRadius, Removed removedSink = null)
		{
			//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)
			float endTime = Time.realtimeSinceStartup + 15f;
			int lastLength = -1;
			while (Time.realtimeSinceStartup < endTime)
			{
				TerrainGrassRenderer[] array = Object.FindObjectsByType<TerrainGrassRenderer>((FindObjectsSortMode)0);
				foreach (TerrainGrassRenderer grass in array)
				{
					try
					{
						Traverse t = Traverse.Create((object)grass);
						if (!t.Field("initialized").GetValue<bool>())
						{
							continue;
						}
						NativeList<float3> positions = t.Field("nativePositions").GetValue<NativeList<float3>>();
						if (!positions.IsCreated)
						{
							continue;
						}
						float tileSize = 1f;
						try
						{
							tileSize = t.Field("settings").Field("tileSize").GetValue<float>();
						}
						catch
						{
						}
						float clearRadius = rimWorldRadius + tileSize;
						float clearSq = clearRadius * clearRadius;
						int removed = 0;
						float nearest = float.MaxValue;
						for (int i2 = positions.Length - 1; i2 >= 0; i2--)
						{
							float3 p = positions[i2];
							float dx = p.x - holeWorldPos.x;
							float dz = p.z - holeWorldPos.z;
							float cx = dx + tileSize * 0.5f;
							float cz = dz + tileSize * 0.5f;
							float d = Mathf.Min(dx * dx + dz * dz, cx * cx + cz * cz);
							if (d < nearest)
							{
								nearest = d;
							}
							if (d <= clearSq)
							{
								removedSink?.Tiles.Add(new KeyValuePair<TerrainGrassRenderer, float3>(grass, p));
								positions.RemoveAtSwapBack(i2);
								removed++;
							}
						}
						if (removed > 0 || positions.Length != lastLength)
						{
							Debug.Log((object)("[HoleSizeMod] Grass clear on '" + ((Object)grass).name + "': removed " + removed + " tiles within " + clearRadius.ToString("F2") + "m (tileSize=" + tileSize + ", nearest remaining " + Mathf.Sqrt(nearest).ToString("F2") + "m, total " + positions.Length + ")"));
							lastLength = positions.Length;
						}
					}
					catch (Exception ex)
					{
						Debug.LogWarning((object)("[HoleSizeMod] Grass clear failed: " + ex.Message));
						yield break;
					}
				}
				yield return (object)new WaitForSeconds(0.5f);
			}
		}
	}
	public static class TerrainHoleMaskGrower
	{
		public static float GetHolePixelWorldSize(Vector3 worldPos)
		{
			//IL_0001: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			Terrain val = FindTerrainAt(worldPos);
			if ((Object)(object)val == (Object)null)
			{
				return 1f;
			}
			TerrainData terrainData = val.terrainData;
			return (terrainData.size.x + terrainData.size.z) * 0.5f / (float)Mathf.Max(1, terrainData.holesResolution);
		}

		public unsafe static void Grow(Vector3 holeWorldPos, float worldRadius, bool refreshCollider = true)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0060: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Terrain[] activeTerrains = Terrain.activeTerrains;
			foreach (Terrain val in activeTerrains)
			{
				Vector3 position = ((Component)val).transform.position;
				Vector3 size = val.terrainData.size;
				if (holeWorldPos.x >= position.x - worldRadius && holeWorldPos.x <= position.x + size.x + worldRadius && holeWorldPos.z >= position.z - worldRadius && holeWorldPos.z <= position.z + size.z + worldRadius)
				{
					flag = true;
					GrowOn(val, holeWorldPos, worldRadius, refreshCollider);
				}
			}
			if (!flag)
			{
				Debug.LogWarning((object)("[HoleSizeMod] TerrainHoleMaskGrower: no terrain found at " + ((object)(*(Vector3*)(&holeWorldPos))/*cast due to .constrained prefix*/).ToString()));
			}
		}

		public static bool TerrainStillSolidAt(Vector3 p)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0017: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit[] array = Physics.RaycastAll(p + Vector3.up * 3f, Vector3.down, 6f, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if (((RaycastHit)(ref val)).collider is TerrainCollider)
				{
					return true;
				}
			}
			return false;
		}

		public static void RefreshCollidersAround(Vector3 p)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Terrain[] activeTerrains = Terrain.activeTerrains;
			foreach (Terrain val in activeTerrains)
			{
				Vector3 position = ((Component)val).transform.position;
				Vector3 size = val.terrainData.size;
				if (!(p.x < position.x - 20f) && !(p.x > position.x + size.x + 20f) && !(p.z < position.z - 20f) && !(p.z > position.z + size.z + 20f))
				{
					TerrainCollider component = ((Component)val).GetComponent<TerrainCollider>();
					if (!((Object)(object)component == (Object)null))
					{
						TerrainData terrainData = component.terrainData;
						component.terrainData = null;
						component.terrainData = terrainData;
					}
				}
			}
		}

		public static void Restore(Vector3 holeWorldPos, float keepRadius, float restoreRadius)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_0060: 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_00aa: 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_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			Terrain[] activeTerrains = Terrain.activeTerrains;
			foreach (Terrain val in activeTerrains)
			{
				TerrainData terrainData = val.terrainData;
				Vector3 position = ((Component)val).transform.position;
				Vector3 size = terrainData.size;
				if (holeWorldPos.x < position.x - restoreRadius || holeWorldPos.x > position.x + size.x + restoreRadius || holeWorldPos.z < position.z - restoreRadius || holeWorldPos.z > position.z + size.z + restoreRadius)
				{
					continue;
				}
				int holesResolution = terrainData.holesResolution;
				float num = (float)holesResolution / size.x;
				float num2 = (float)holesResolution / size.z;
				float num3 = (holeWorldPos.x - position.x) * num;
				float num4 = (holeWorldPos.z - position.z) * num2;
				int num5 = Mathf.CeilToInt(restoreRadius * Mathf.Max(num, num2)) + 2;
				int num6 = Mathf.Clamp(Mathf.FloorToInt(num3) - num5, 0, holesResolution);
				int num7 = Mathf.Clamp(Mathf.FloorToInt(num4) - num5, 0, holesResolution);
				int num8 = Mathf.Clamp(Mathf.FloorToInt(num3) + num5, 0, holesResolution);
				int num9 = Mathf.Clamp(Mathf.FloorToInt(num4) + num5, 0, holesResolution);
				int num10 = num8 - num6;
				int num11 = num9 - num7;
				if (num10 <= 0 || num11 <= 0)
				{
					continue;
				}
				bool[,] holes = terrainData.GetHoles(num6, num7, num10, num11);
				int num12 = 0;
				for (int j = 0; j < num10; j++)
				{
					for (int k = 0; k < num11; k++)
					{
						float num13 = ((float)(num6 + j) + 0.5f - num3) / num;
						float num14 = ((float)(num7 + k) + 0.5f - num4) / num2;
						float num15 = num13 * num13 + num14 * num14;
						if ((keepRadius < 0f || num15 > keepRadius * keepRadius) && num15 <= restoreRadius * restoreRadius