Decompiled source of MoreTerrainTypes v2.0.0

plugins/MoreTerrainTypes/TerrainHoe.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using LocalizationManager;
using Microsoft.CodeAnalysis;
using ServerSync;
using TMPro;
using UnityEngine;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
using YamlDotNet.Core.ObjectPool;
using YamlDotNet.Core.Tokens;
using YamlDotNet.Helpers;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.BufferedDeserialization;
using YamlDotNet.Serialization.BufferedDeserialization.TypeDiscriminators;
using YamlDotNet.Serialization.Callbacks;
using YamlDotNet.Serialization.Converters;
using YamlDotNet.Serialization.EventEmitters;
using YamlDotNet.Serialization.NamingConventions;
using YamlDotNet.Serialization.NodeDeserializers;
using YamlDotNet.Serialization.NodeTypeResolvers;
using YamlDotNet.Serialization.ObjectFactories;
using YamlDotNet.Serialization.ObjectGraphTraversalStrategies;
using YamlDotNet.Serialization.ObjectGraphVisitors;
using YamlDotNet.Serialization.Schemas;
using YamlDotNet.Serialization.TypeInspectors;
using YamlDotNet.Serialization.TypeResolvers;
using YamlDotNet.Serialization.Utilities;
using YamlDotNet.Serialization.ValueDeserializers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoreTerrainTypes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("JamesJonesTV")]
[assembly: AssemblyProduct("MoreTerrainTypes")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("E0E2F92E-557C-4A05-9D89-AA92A0BD75C4")]
[assembly: AssemblyFileVersion("1.0.4")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class ExtensionMarkerAttribute : Attribute
	{
		private readonly string <Name>k__BackingField;

		public string Name => <Name>k__BackingField;

		public ExtensionMarkerAttribute(string name)
		{
			<Name>k__BackingField = name;
		}
	}
}
namespace TerrainHoe
{
	[BepInPlugin("JamesJonesTV.MoreTerrainTypes", "MoreTerrainTypes", "1.0.4")]
	public class TerrainHoePlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		[HarmonyPatch(typeof(FejdStartup), "Awake")]
		public static class FejdStartup_Awake_Patch
		{
			private static void Prefix(FejdStartup __instance)
			{
				PrefabManager._ZNetScene = __instance.m_objectDBPrefab.GetComponent<ZNetScene>();
				PrefabManager._ObjectDB = __instance.m_objectDBPrefab.GetComponent<ObjectDB>();
				new Lava("piece_paint_lava", "$piece_lava");
				new AshlandsGrass("piece_paint_ashlands_grass", "$piece_ashlands_grass");
				new PavedGrass("piece_paint_paved_grass", "$piece_paved_grass");
				new PavedDark("piece_paint_paved_cultivated", "$piece_paved_dark");
				new MistlandsGrass("piece_paint_mistlands", "$piece_mistlands_grass");
				new MistlandsDirt("piece_paint_mistlands_dirt", "$piece_mistlands_dirt");
				new BlackForestGrass("piece_paint_blackforest_grass", "$piece_blackforest_grass");
				new PlainsGrass("piece_paint_plains_grass", "$piece_plains_grass");
				new Snow("piece_paint_snow", "$piece_snow");
				new SwampGrass("piece_paint_swamp_grass", "$piece_swamp_grass");
				new MeadowsGrass("piece_paint_meadows_grass", "$piece_meadows_grass");
				new Reset("piece_paint_reset", "$piece_reset_all");
				foreach (IPaint value in IPaint.m_paintTools.Values)
				{
					value.SetupConfigs();
				}
			}
		}

		[HarmonyPatch(typeof(Player), "SetupPlacementGhost")]
		private static class Player_SetupPlacementGhost_Patch
		{
			private static void Postfix(Player __instance)
			{
				Piece val = default(Piece);
				if (!((Object)(object)__instance.m_placementGhost == (Object)null) && __instance.m_placementGhost.TryGetComponent<Piece>(ref val) && IPaint.TryGetPaintTool(val.m_name, out var _))
				{
					__instance.m_placementGhost.AddComponent<PaintOptions>();
				}
			}
		}

		[HarmonyPatch(typeof(Player), "CanRotatePiece")]
		private static class Player_CanRotatePiece_Patch
		{
			private static void Postfix(Player __instance, ref bool __result)
			{
				if (!__result)
				{
					Piece selectedPiece = __instance.m_buildPieces.GetSelectedPiece();
					if (!((Object)(object)selectedPiece == (Object)null) && IPaint.IsPaintTool(selectedPiece))
					{
						__result = true;
					}
				}
			}
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;
		}

		internal const string ModName = "MoreTerrainTypes";

		internal const string ModVersion = "1.0.4";

		internal const string Author = "JamesJonesTV";

		private const string ModGUID = "JamesJonesTV.MoreTerrainTypes";

		private static readonly string ConfigFileName = "JamesJonesTV.MoreTerrainTypes.cfg";

		private static readonly string ConfigFileFullPath;

		internal static string ConnectionError;

		public readonly Harmony _harmony = new Harmony("JamesJonesTV.MoreTerrainTypes");

		public static readonly ManualLogSource TerrainHoeLogger;

		private static readonly ConfigSync ConfigSync;

		private static ConfigEntry<Toggle> _serverConfigLocked;

		public static TerrainHoePlugin instance;

		public void Awake()
		{
			Localizer.Load();
			instance = this;
			_serverConfigLocked = config("1 - General", "Lock Configuration", Toggle.On, "If on, the configuration is locked and can be changed by server admins only.");
			ConfigSync.AddLockingConfigEntry<Toggle>(_serverConfigLocked);
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		public static void LogInfo(string msg)
		{
			TerrainHoeLogger.LogInfo((object)msg);
		}

		public static void LogWarning(string msg)
		{
			TerrainHoeLogger.LogWarning((object)msg);
		}

		public static void LogError(string msg)
		{
			TerrainHoeLogger.LogError((object)msg);
		}

		public static void LogDebug(string msg)
		{
			TerrainHoeLogger.LogDebug((object)msg);
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				TerrainHoeLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				TerrainHoeLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				TerrainHoeLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		public ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description, bool synchronizedSetting = true)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]"), description.AcceptableValues, description.Tags);
			ConfigEntry<T> val2 = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
			SyncedConfigEntry<T> syncedConfigEntry = ConfigSync.AddConfigEntry<T>(val2);
			syncedConfigEntry.SynchronizedConfig = synchronizedSetting;
			return val2;
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, string description, bool synchronizedSetting = true)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
		}

		static TerrainHoePlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ConnectionError = "";
			TerrainHoeLogger = Logger.CreateLogSource("MoreTerrainTypes");
			ConfigSync = new ConfigSync("JamesJonesTV.MoreTerrainTypes")
			{
				DisplayName = "MoreTerrainTypes",
				CurrentVersion = "1.0.4",
				MinimumRequiredVersion = "1.0.4"
			};
			_serverConfigLocked = null;
		}
	}
	public static class AssetBundleMan
	{
		private struct BundleId
		{
			[UsedImplicitly]
			public string assetBundleFileName;

			[UsedImplicitly]
			public string folderName;
		}

		private static readonly Dictionary<BundleId, AssetBundle> bundleCache = new Dictionary<BundleId, AssetBundle>();

		private static readonly MethodInfo LoadImage = AccessTools.Method(typeof(ImageConversion), "LoadImage", new Type[2]
		{
			typeof(Texture2D),
			typeof(byte[])
		}, (Type[])null);

		public static AssetBundle RegisterAssetBundle(string assetBundleFileName, string folderName = "assets")
		{
			BundleId key = new BundleId
			{
				assetBundleFileName = assetBundleFileName,
				folderName = folderName
			};
			if (!bundleCache.TryGetValue(key, out var value))
			{
				Dictionary<BundleId, AssetBundle> dictionary = bundleCache;
				AssetBundle? obj = ((IEnumerable<AssetBundle>)Resources.FindObjectsOfTypeAll<AssetBundle>()).FirstOrDefault((Func<AssetBundle, bool>)((AssetBundle a) => ((Object)a).name == assetBundleFileName)) ?? AssetBundle.LoadFromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream(Assembly.GetExecutingAssembly().GetName().Name + "." + folderName + "." + assetBundleFileName));
				AssetBundle result = obj;
				dictionary[key] = obj;
				return result;
			}
			return value;
		}

		public static T Load<T>(string assetBundle, string assetId) where T : Object
		{
			return RegisterAssetBundle(assetBundle).LoadAsset<T>(assetId);
		}

		public static Sprite GetSprite(string fileName, string folderName = "icons")
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//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)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			string name = "TerrainHoe." + folderName + "." + fileName;
			using Stream stream = executingAssembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2);
			Sprite val2 = (val.LoadImage4x(array) ? Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero) : null);
			if ((Object)(object)val2 != (Object)null)
			{
				((Object)val2).name = fileName;
			}
			return val2;
		}

		public static bool LoadImage4x(this Texture2D tex, byte[] data)
		{
			return (bool)LoadImage.Invoke(null, new object[2] { tex, data });
		}
	}
	public static class GrassMan
	{
		[HarmonyPatch(typeof(ClutterSystem), "GetPatchBiomes")]
		private static class ClutterSystem_GetPatchBiomes_Prefix
		{
			private static bool Prefix(Vector3 center, float halfSize, ref Biome __result)
			{
				//IL_0001: 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_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Invalid comparison between Unknown and I4
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Expected I4, but got Unknown
				Biome patchBiomesByMesh = GetPatchBiomesByMesh(center, halfSize);
				if ((int)patchBiomesByMesh == 0)
				{
					return true;
				}
				__result = (Biome)(int)patchBiomesByMesh;
				return false;
			}
		}

		[HarmonyPatch(typeof(ClutterSystem), "GetGroundInfo")]
		private static class ClutterSystem_GetGroundInfo_Prefix
		{
			private static bool Prefix(ClutterSystem __instance, Vector3 p, out Vector3 point, out Vector3 normal, out Heightmap hmap, out Biome biome, ref bool __result)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				bool groundInfoByMesh = __instance.GetGroundInfoByMesh(p, out point, out normal, out hmap, out biome);
				if ((int)biome == 0)
				{
					return true;
				}
				__result = groundInfoByMesh;
				return false;
			}
		}

		[HarmonyPatch(typeof(ClutterSystem), "GenerateVegPatch")]
		private static class ClutterSystem_GenerateVegPatch_Prefix
		{
			private static bool Prefix(ClutterSystem __instance, Vector2Int patchID, float size, ref PatchData __result)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: 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_0055: Unknown result type (might be due to invalid IL or missing references)
				if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return true;
				}
				Vector3 vegPatchCenter = __instance.GetVegPatchCenter(patchID);
				float halfSize = size / 2f;
				bool flag = false;
				if (TerrainColors.TryFindTerrainColors(vegPatchCenter, out var instance))
				{
					flag = instance.HasForcedGrassVertex(vegPatchCenter, halfSize);
				}
				if (!flag)
				{
					return true;
				}
				__result = GenerateVegPatch(__instance, patchID, size);
				return false;
			}
		}

		public static bool GetGroundInfoByMesh(this ClutterSystem cs, Vector3 p, out Vector3 point, out Vector3 normal, out Heightmap hmap, out Biome biome)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0016: 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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_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_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected I4, but got Unknown
			Vector3 val = p + Vector3.up * 500f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val2, 1000f, cs.m_placeRayMask))
			{
				point = ((RaycastHit)(ref val2)).point;
				normal = ((RaycastHit)(ref val2)).normal;
				hmap = ((Component)((RaycastHit)(ref val2)).collider).GetComponent<Heightmap>();
				biome = (Biome)(int)hmap.GetBiomeFromMesh(point);
				return true;
			}
			point = p;
			normal = Vector3.up;
			hmap = null;
			biome = (Biome)0;
			return false;
		}

		private static Biome GetPatchBiomesByMesh(Vector3 center, float halfSize)
		{
			//IL_0001: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_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_0080: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00a3: 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_0099: 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: Invalid comparison between Unknown and I4
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			Biome biomeFromMeshColor = GetBiomeFromMeshColor(new Vector3(center.x - halfSize, 0f, center.z - halfSize));
			Biome biomeFromMeshColor2 = GetBiomeFromMeshColor(new Vector3(center.x + halfSize, 0f, center.z - halfSize));
			Biome biomeFromMeshColor3 = GetBiomeFromMeshColor(new Vector3(center.x - halfSize, 0f, center.z + halfSize));
			Biome biomeFromMeshColor4 = GetBiomeFromMeshColor(new Vector3(center.x + halfSize, 0f, center.z + halfSize));
			if ((int)biomeFromMeshColor == 0 || (int)biomeFromMeshColor2 == 0 || (int)biomeFromMeshColor3 == 0 || (int)biomeFromMeshColor4 == 0)
			{
				return (Biome)0;
			}
			return (Biome)(biomeFromMeshColor | biomeFromMeshColor2 | biomeFromMeshColor4 | biomeFromMeshColor3);
		}

		private static Biome GetBiomeFromMeshColor(Vector3 point)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_003a: 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)
			if (Object.op_Implicit((Object)(object)ZoneSystem.instance) && !ZoneSystem.instance.IsZoneLoaded(point))
			{
				return (Biome)0;
			}
			Heightmap val = Heightmap.FindHeightmap(point);
			if ((Object)(object)val == (Object)null)
			{
				return (Biome)0;
			}
			return val.GetBiomeFromMesh(point);
		}

		public static PatchData GenerateVegPatch(ClutterSystem __instance, Vector2Int patchID, float size)
		{
			//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_0008: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Invalid comparison between Unknown and I4
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0105: Invalid comparison between Unknown and I4
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Invalid comparison between Unknown and I4
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			Vector3 vegPatchCenter = __instance.GetVegPatchCenter(patchID);
			float num = size / 2f;
			Biome patchBiomes = __instance.GetPatchBiomes(vegPatchCenter, num);
			if ((int)patchBiomes == 0)
			{
				return null;
			}
			State state = Random.state;
			PatchData val = __instance.AllocatePatch();
			val.center = vegPatchCenter;
			Vector3 fractalPos = default(Vector3);
			for (int i = 0; i < __instance.m_clutter.Count; i++)
			{
				Clutter val2 = __instance.m_clutter[i];
				if (val2.m_enabled && (patchBiomes & val2.m_biome) > 0)
				{
					int num2 = ((Vector2Int)(ref patchID)).x * (((Vector2Int)(ref patchID)).y * 1374) + i * 9321;
					Random.InitState(num2);
					((Vector3)(ref fractalPos))..ctor(val2.m_fractalOffset, 0f, 0f);
					float maxTilt = Mathf.Cos((float)Math.PI / 180f * val2.m_maxTilt);
					float minTilt = Mathf.Cos((float)Math.PI / 180f * val2.m_minTilt);
					Quality quality = __instance.m_quality;
					if (1 == 0)
					{
					}
					int num3 = (((int)quality == 1) ? (val2.m_amount / 4) : (((int)quality != 2) ? val2.m_amount : (val2.m_amount / 2)));
					if (1 == 0)
					{
					}
					int num4 = num3;
					int num5 = (int)((float)num4 * __instance.m_amountScale);
					GenerateVeg(__instance, vegPatchCenter, num, num5, fractalPos, maxTilt, minTilt, val2, val);
				}
			}
			Random.state = state;
			return val;
		}

		private static void GenerateVeg(ClutterSystem __instance, Vector3 vegPatchCenter, float halfSize, float amount, Vector3 fractalPos, float maxTilt, float minTilt, Clutter clutter, PatchData vegPatch)
		{
			//IL_0009: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Invalid comparison between Unknown and I4
			//IL_00ce: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: 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_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = default(Vector3);
			Vector3 val2 = default(Vector3);
			Vector3 val3 = default(Vector3);
			Heightmap val4 = default(Heightmap);
			Biome val5 = default(Biome);
			for (int i = 0; (float)i < amount; i++)
			{
				float num = Random.Range(vegPatchCenter.x - halfSize, vegPatchCenter.x + halfSize);
				float num2 = Random.Range(vegPatchCenter.z - halfSize, vegPatchCenter.z + halfSize);
				((Vector3)(ref val))..ctor(num, 0f, num2);
				float y = Random.Range(0, 360);
				if (clutter.m_inForest)
				{
					float forestFactor = WorldGenerator.GetForestFactor(val);
					if (forestFactor < clutter.m_forestTresholdMin || forestFactor > clutter.m_forestTresholdMax)
					{
						continue;
					}
				}
				if (!__instance.GetGroundInfo(val, ref val2, ref val3, ref val4, ref val5) || (clutter.m_biome & val5) <= 0 || !(val3.y >= maxTilt) || !(val3.y <= minTilt))
				{
					continue;
				}
				if (!Mathf.Approximately(clutter.m_minOceanDepth, clutter.m_maxOceanDepth))
				{
					float oceanDepth = val4.GetOceanDepth(val);
					if (oceanDepth < clutter.m_minOceanDepth || oceanDepth > clutter.m_maxOceanDepth)
					{
						continue;
					}
				}
				if (!Mathf.Approximately(clutter.m_minVegetation, clutter.m_maxVegetation))
				{
					float vegetationMask = val4.GetVegetationMask(val);
					if (vegetationMask > clutter.m_maxVegetation || vegetationMask < clutter.m_minVegetation)
					{
						continue;
					}
				}
				if (!clutter.m_onCleared || !clutter.m_onUncleared)
				{
					bool flag = val4.IsCleared(val2);
					if ((clutter.m_onCleared && !flag) || (clutter.m_onUncleared && flag))
					{
						continue;
					}
				}
				SpawnVeg(__instance, vegPatchCenter, y, val3, val2, clutter, vegPatch);
			}
		}

		private static void SpawnVeg(ClutterSystem __instance, Vector3 vegPatchCenter, float y, Vector3 normal, Vector3 point, Clutter clutter, PatchData vegPatch)
		{
			//IL_0001: 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_0076: 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_0064: 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_011b: 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_0094: 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_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = point;
			if (clutter.m_snapToWater)
			{
				val.y = __instance.m_waterLevel;
			}
			if ((double)clutter.m_randomOffset != 0.0)
			{
				val.y += Random.Range(0f - clutter.m_randomOffset, clutter.m_randomOffset);
			}
			Quaternion val2 = ((!clutter.m_terrainTilt) ? Quaternion.Euler(0f, y, 0f) : Quaternion.AngleAxis(y, normal));
			if (clutter.m_instanced)
			{
				GameObject val3 = Object.Instantiate<GameObject>(clutter.m_prefab, vegPatchCenter, Quaternion.identity, __instance.m_grassRoot.transform);
				InstanceRenderer component = val3.GetComponent<InstanceRenderer>();
				if ((double)component.m_lodMaxDistance > (double)__instance.m_distance - (double)__instance.m_grassPatchSize / 2.0)
				{
					vegPatch.m_objects.Add(val3);
				}
				float num = Random.Range(clutter.m_scaleMin, clutter.m_scaleMax);
				component.AddInstance(val, val2, num);
			}
			else
			{
				GameObject item = Object.Instantiate<GameObject>(clutter.m_prefab, val, val2, __instance.m_grassRoot.transform);
				vegPatch.m_objects.Add(item);
			}
		}
	}
	public abstract class IPaint
	{
		[HarmonyPatch(typeof(ObjectDB), "Awake")]
		private static class RegisterTerrainOp
		{
			private static void Prefix(ObjectDB __instance)
			{
				foreach (KeyValuePair<Piece, IPaint> paintTool in m_paintTools)
				{
					if (!__instance.m_terrainOps.Contains(paintTool.Value.terrainOp))
					{
						__instance.m_terrainOps.Add(paintTool.Value.terrainOp);
					}
				}
			}
		}

		private class SerializedRequirements
		{
			public readonly List<Requirement> Reqs;

			public SerializedRequirements(List<Requirement> reqs)
			{
				Reqs = reqs;
			}

			public SerializedRequirements(string reqs)
			{
				Reqs = reqs.Split(new char[1] { ',' }).Select(delegate(string r)
				{
					string[] array = r.Split(new char[1] { ':' });
					int result;
					bool result2 = default(bool);
					return new Requirement
					{
						itemName = array[0],
						amount = ((array.Length <= 1 || !int.TryParse(array[1], out result)) ? 1 : result),
						recover = (array.Length <= 2 || !bool.TryParse(array[2], out result2) || result2)
					};
				}).ToList();
			}

			public override string ToString()
			{
				return string.Join(",", Reqs.Select((Requirement r) => $"{r.itemName}:{r.amount}:{r.recover}"));
			}

			public static ItemDrop fetchByName(ObjectDB objectDB, string name)
			{
				GameObject itemPrefab = objectDB.GetItemPrefab(name);
				ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
				if ((Object)(object)val == (Object)null)
				{
					TerrainHoePlugin.LogWarning("The required item '" + name + "' does not exist.");
				}
				return val;
			}

			public static Requirement[] toPieceReqs(SerializedRequirements craft)
			{
				Dictionary<string, Requirement> dictionary = craft.Reqs.Where((Requirement r) => r.itemName != "").ToDictionary((Func<Requirement, string>)((Requirement r) => r.itemName), (Func<Requirement, Requirement>)delegate(Requirement r)
				{
					//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_001e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0025: Unknown result type (might be due to invalid IL or missing references)
					ItemDrop val = ResItem(r);
					return (val == null) ? ((Requirement)null) : new Requirement
					{
						m_amount = r.amount,
						m_resItem = val,
						m_recover = r.recover
					};
				});
				return dictionary.Values.Where((Requirement v) => v != null).ToArray();
				static ItemDrop ResItem(Requirement r)
				{
					GameObject prefab = PrefabManager.GetPrefab(r.itemName);
					return (prefab != null) ? prefab.GetComponent<ItemDrop>() : null;
				}
			}
		}

		public static readonly Dictionary<Piece, IPaint> m_paintTools = new Dictionary<Piece, IPaint>();

		private static readonly Dictionary<PaintType, IPaint> m_paintMask = new Dictionary<PaintType, IPaint>();

		private static readonly Dictionary<string, IPaint> m_paintToolNamed = new Dictionary<string, IPaint>();

		protected readonly Piece piece;

		public readonly TerrainOp terrainOp;

		public bool adminOnly;

		public bool overrideAlpha = true;

		public bool blend = true;

		public bool isBiomePaint;

		public bool blendTerrain = true;

		public bool forceGrass = false;

		public bool reset;

		public readonly RequiredResourcesList RequiredItems = new RequiredResourcesList();

		public ConfigEntry<string> cost = null;

		public static bool IsPaintTool(Piece piece)
		{
			return m_paintTools.ContainsKey(piece);
		}

		public static bool TryGetPaintTool(PaintType type, out IPaint paintTool)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return m_paintMask.TryGetValue(type, out paintTool);
		}

		public static bool TryGetPaintTool(Piece piece, out IPaint paintTool)
		{
			return m_paintTools.TryGetValue(piece, out paintTool);
		}

		public static bool TryGetPaintTool(string name, out IPaint paintTool)
		{
			return m_paintToolNamed.TryGetValue(name, out paintTool);
		}

		protected IPaint(string id, string name, PaintType type, int index = 1)
		{
			//IL_00fa: 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_0123: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			ItemDrop component = PrefabManager.GetPrefab("Cultivator").GetComponent<ItemDrop>();
			ItemDrop component2 = PrefabManager.GetPrefab("Hoe").GetComponent<ItemDrop>();
			List<GameObject> pieces = component.m_itemData.m_shared.m_buildPieces.m_pieces;
			GameObject val = pieces[1];
			GameObject val2 = Object.Instantiate<GameObject>(val.gameObject, MockManager.transform);
			((Object)val2).name = id;
			piece = val2.GetComponent<Piece>();
			piece.m_icon = component2.m_itemData.m_shared.m_icons[0];
			piece.m_name = name;
			piece.m_description = name + "_desc";
			piece.m_vegetationGroundOnly = false;
			piece.m_canRotate = false;
			piece.m_category = (PieceCategory)0;
			piece.m_usage = (UsageTagFlags)1;
			terrainOp = val2.GetComponent<TerrainOp>();
			terrainOp.m_settings.m_paintType = type;
			terrainOp.m_settings.m_level = false;
			terrainOp.m_settings.m_smooth = false;
			terrainOp.m_settings.m_raise = false;
			terrainOp.m_settings.m_smoothPower = 0f;
			m_paintTools[piece] = this;
			m_paintMask[type] = this;
			m_paintToolNamed[piece.m_name] = this;
			terrainOp.m_settings.m_paintRadius = 5f;
			GameObject prefab = PrefabManager.GetPrefab("dverger_guardstone");
			PrivateArea component3 = prefab.GetComponent<PrivateArea>();
			GameObject gameObject = ((Component)component3.m_areaMarker).gameObject;
			GameObject val3 = Object.Instantiate<GameObject>(gameObject, ((Component)piece).transform);
			val3.transform.localPosition = Vector3.zero;
			val3.transform.localRotation = Quaternion.identity;
			((Object)val3).name = "projector";
			val3.SetActive(true);
			PieceTable buildPieces = component2.m_itemData.m_shared.m_buildPieces;
			if (!buildPieces.m_pieces.Contains(val2))
			{
				if (buildPieces.m_pieces.Count <= index)
				{
					buildPieces.m_pieces.Add(val2);
				}
				else
				{
					buildPieces.m_pieces.Insert(index, val2);
				}
			}
		}

		public void SetupConfigs()
		{
			string englishName = piece.m_name;
			cost = itemConfig("Cost", new SerializedRequirements(RequiredItems.Requirements).ToString(), "Item cost to use tool");
			cost.SettingChanged += onConfigChanged;
			onConfigChanged(null, null);
			ConfigEntry<string> itemConfig(string name, string value, string desc)
			{
				//IL_0043: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Expected O, but got Unknown
				ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
				{
					CustomDrawer = DrawConfigTable
				};
				return TerrainHoePlugin.instance.config(englishName, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }));
			}
			void onConfigChanged(object sender, EventArgs args)
			{
				Requirement[] resources = SerializedRequirements.toPieceReqs(new SerializedRequirements(cost.Value));
				piece.m_resources = resources;
			}
		}

		public abstract Color GetColor();

		public virtual Color32 GetBiomeColor()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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)
			return default(Color32);
		}

		public virtual Biome GetBiome()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return (Biome)0;
		}

		private static void DrawConfigTable(ConfigEntryBase cfg)
		{
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Expected O, but got Unknown
			bool valueOrDefault = cfg.Description.Tags.Select((object a) => (a.GetType().Name == "ConfigurationManagerAttributes") ? ((bool?)a.GetType().GetField("ReadOnly")?.GetValue(a)) : ((bool?)null)).FirstOrDefault((bool? v) => v.HasValue) == true;
			List<Requirement> list = new List<Requirement>();
			bool flag = false;
			GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
			foreach (Requirement req in new SerializedRequirements((string)cfg.BoxedValue).Reqs)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				int num = req.amount;
				if (int.TryParse(GUILayout.TextField(num.ToString(), new GUIStyle(GUI.skin.textField)
				{
					fixedWidth = 40f
				}, Array.Empty<GUILayoutOption>()), out var result) && result != num && !valueOrDefault)
				{
					num = result;
					flag = true;
				}
				string text = GUILayout.TextField(req.itemName, new GUIStyle(GUI.skin.textField), Array.Empty<GUILayoutOption>());
				string text2 = (valueOrDefault ? req.itemName : text);
				flag = flag || text2 != req.itemName;
				bool flag2 = req.recover;
				if (GUILayout.Toggle(req.recover, "Recover", new GUIStyle(GUI.skin.toggle)
				{
					fixedWidth = 67f
				}, Array.Empty<GUILayoutOption>()) != req.recover)
				{
					flag2 = !flag2;
					flag = true;
				}
				if (GUILayout.Button("x", new GUIStyle(GUI.skin.button)
				{
					fixedWidth = 21f
				}, Array.Empty<GUILayoutOption>()) && !valueOrDefault)
				{
					flag = true;
				}
				else
				{
					list.Add(new Requirement
					{
						amount = num,
						itemName = text2,
						recover = flag2
					});
				}
				if (GUILayout.Button("+", new GUIStyle(GUI.skin.button)
				{
					fixedWidth = 21f
				}, Array.Empty<GUILayoutOption>()) && !valueOrDefault)
				{
					flag = true;
					list.Add(new Requirement
					{
						amount = 1,
						itemName = "",
						recover = false
					});
				}
				GUILayout.EndHorizontal();
			}
			GUILayout.EndVertical();
			if (flag)
			{
				cfg.BoxedValue = new SerializedRequirements(list).ToString();
			}
		}
	}
	public class ConfigurationManagerAttributes
	{
		[UsedImplicitly]
		public int? Order;

		[UsedImplicitly]
		public bool? Browsable;

		[UsedImplicitly]
		public string? Category;

		[UsedImplicitly]
		public Action<ConfigEntryBase>? CustomDrawer;
	}
	[PublicAPI]
	public class RequiredResourcesList
	{
		public readonly List<Requirement> Requirements = new List<Requirement>();

		public void Add(string item, int amount, bool recover)
		{
			Requirements.Add(new Requirement
			{
				itemName = item,
				amount = amount,
				recover = recover
			});
		}
	}
	public struct Requirement
	{
		public string itemName;

		public int amount;

		public bool recover;
	}
	public static class MockManager
	{
		private static readonly GameObject root;

		public static Transform transform => root.transform;

		static MockManager()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			root = new GameObject("MockManager");
			Object.DontDestroyOnLoad((Object)(object)root);
			root.SetActive(false);
		}
	}
	public static class PaintMan
	{
		[HarmonyPatch(typeof(Enum), "GetValues")]
		private static class Enum_GetValues_Patch
		{
			private static void Postfix(Type enumType, ref Array __result)
			{
				if (!(enumType != typeof(PaintType)) && paintTypes.Count != 0)
				{
					PaintType[] array = (PaintType[])(object)new PaintType[__result.Length + paintTypes.Count];
					__result.CopyTo(array, 0);
					paintTypes.Values.CopyTo(array, __result.Length);
					__result = array;
				}
			}
		}

		[HarmonyPatch(typeof(Enum), "GetNames")]
		private static class Enum_GetNames_Patch
		{
			private static void Postfix(Type enumType, ref string[] __result)
			{
				if (!(enumType != typeof(PaintType)) && paintTypes.Count != 0)
				{
					__result = CollectionExtensions.AddRangeToArray<string>(__result, paintTypes.Keys.ToArray());
				}
			}
		}

		[HarmonyPatch(typeof(Enum), "GetName")]
		private static class Enum_GetName_Patch
		{
			private static bool Prefix(Type enumType, object value, ref string __result)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				if (enumType != typeof(PaintType))
				{
					return true;
				}
				if (customPaintTypes.TryGetValue((PaintType)value, out var value2))
				{
					__result = value2;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(TerrainComp), "PaintCleared")]
		private static class TerrainComp_PaintCleared_Patch
		{
			private static bool Prefix(TerrainComp __instance, Vector3 worldPos, Vector3 rot, Settings settings)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
				if (!IPaint.TryGetPaintTool(settings.m_paintType, out var paintTool))
				{
					return true;
				}
				TerrainColors component = ((Component)__instance).GetComponent<TerrainColors>();
				if (settings.m_halfOffset)
				{
					worldPos.x -= 0.5f;
					worldPos.z -= 0.5f;
				}
				float heightOffset = worldPos.y - ((Component)__instance).transform.position.y;
				int num = default(int);
				int num2 = default(int);
				__instance.m_hmap.WorldToVertexMask(worldPos, ref num, ref num2);
				float num3 = settings.m_paintRadius / __instance.m_hmap.m_scale;
				int num4 = Mathf.CeilToInt(num3);
				Vector2 centerVertex = default(Vector2);
				((Vector2)(ref centerVertex))..ctor((float)num, (float)num2);
				for (int i = num2 - num4; i <= num2 + num4; i++)
				{
					UpdatePaints(__instance, component, paintTool, centerVertex, num, num4, i, settings.m_paintHeightCheck, heightOffset, num3, worldPos);
				}
				if (paintTool.isBiomePaint)
				{
					component.m_terrainComp.m_hmap.RebuildRenderMesh();
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(TerrainComp), "Awake")]
		private static class TerrainComp_Awake_Patch
		{
			private static void Prefix(TerrainComp __instance)
			{
				((Component)__instance).gameObject.AddComponent<TerrainColors>();
			}
		}

		[HarmonyPatch(typeof(TerrainComp), "Initialize")]
		private static class TerrainComp_Initialize_Patch
		{
			private static void Postfix(TerrainComp __instance)
			{
				((Component)__instance).GetComponent<TerrainColors>()?.Initialize();
			}
		}

		[HarmonyPatch(typeof(TerrainComp), "Save")]
		private static class TerrainComp_Save_Patch
		{
			private static void Prefix(TerrainComp __instance)
			{
				((Component)__instance).GetComponent<TerrainColors>()?.Save();
			}
		}

		[HarmonyPatch(typeof(TerrainComp), "Load")]
		private static class TerrainComp_Load_Patch
		{
			private static void Prefix(TerrainComp __instance)
			{
				((Component)__instance).GetComponent<TerrainColors>()?.Load();
			}
		}

		[HarmonyPatch(typeof(Heightmap), "RebuildRenderMesh")]
		private static class Heightmap_RebuildRenderMesh_Patch
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0043: Expected O, but got Unknown
				//IL_004b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Expected O, but got Unknown
				//IL_0054: 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_0078: Expected O, but got Unknown
				MethodInfo methodInfo = AccessTools.Method(typeof(Mesh), "GetVertices", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(PaintMan), "Apply_TerrainColor_Modifiers", (Type[])null, (Type[])null);
				CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[2]
				{
					new CodeInstruction(OpCodes.Ldarg_0, (object)null),
					new CodeInstruction(OpCodes.Call, (object)methodInfo2)
				};
				return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
				{
					new CodeMatch((OpCode?)OpCodes.Callvirt, (object)methodInfo, (string)null)
				}).Insert(array)
					.InstructionEnumeration();
			}
		}

		[HarmonyPatch(typeof(Character), "UpdateLava")]
		private static class Character_UpdateLava_Patch
		{
			private static void Postfix(Character __instance, float dt)
			{
				//IL_0018: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Unknown result type (might be due to invalid IL or missing references)
				if (__instance.m_tolerateFire || !TerrainColors.TryFindTerrainColors(((Component)__instance).transform.position, out var instance) || !instance.m_initialized)
				{
					return;
				}
				int x = default(int);
				int y = default(int);
				instance.m_terrainComp.m_hmap.WorldToVertex(((Component)__instance).transform.position, ref x, ref y);
				int index = Util.GetIndex(x, y, instance.m_terrainComp.m_pitch);
				if (!instance.m_modifiedTerrain[index])
				{
					if (!WorldGenerator.IsAshlands(((Component)__instance).transform.position.x, ((Component)__instance).transform.position.z))
					{
						__instance.m_lavaHeatLevel -= dt * __instance.m_heatCooldownBase;
					}
				}
				else
				{
					Color32 val = instance.m_terrainMask[index];
					Color val2 = instance.m_terrainComp.m_paintMask[index];
					if (val.r > 200 && val.a > 200 && val2.a > 0.6f)
					{
						__instance.m_lavaHeatLevel += dt * __instance.m_heatBuildupBase * (1f - __instance.GetEquipmentHeatResistanceModifier());
					}
					else
					{
						__instance.m_lavaHeatLevel -= dt * __instance.m_heatCooldownBase;
					}
				}
				__instance.m_lavaHeatLevel = Mathf.Clamp(__instance.m_lavaHeatLevel, 0f, 1f);
			}
		}

		private static readonly Dictionary<string, PaintType> paintTypes = new Dictionary<string, PaintType>();

		private static readonly Dictionary<PaintType, string> customPaintTypes = new Dictionary<PaintType, string>();

		public static bool TryGetPaintType(string name, out PaintType paintType)
		{
			if (Enum.TryParse<PaintType>(name, ignoreCase: true, out paintType))
			{
				return true;
			}
			if (paintTypes.TryGetValue(name, out paintType))
			{
				return true;
			}
			return false;
		}

		public static PaintType GetPaintType(string name)
		{
			//IL_000e: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0075: 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_009f: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			if (Enum.TryParse<PaintType>(name, ignoreCase: true, out PaintType result))
			{
				return result;
			}
			if (paintTypes.TryGetValue(name, out result))
			{
				return result;
			}
			Dictionary<PaintType, string> dictionary = GetPaintTypes();
			foreach (KeyValuePair<PaintType, string> item in dictionary)
			{
				if (item.Value != name)
				{
					continue;
				}
				result = item.Key;
				paintTypes[name] = result;
				return result;
			}
			result = (PaintType)StringExtensionMethods.GetStableHashCode(name);
			paintTypes[name] = result;
			customPaintTypes[result] = name;
			return result;
		}

		private static Dictionary<PaintType, string> GetPaintTypes()
		{
			//IL_0034: 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)
			Array values = Enum.GetValues(typeof(PaintType));
			string[] names = Enum.GetNames(typeof(PaintType));
			Dictionary<PaintType, string> dictionary = new Dictionary<PaintType, string>();
			for (int i = 0; i < values.Length; i++)
			{
				dictionary[(PaintType)values.GetValue(i)] = names[i];
			}
			foreach (KeyValuePair<PaintType, string> customPaintType in customPaintTypes)
			{
				dictionary[customPaintType.Key] = customPaintType.Value;
			}
			return dictionary;
		}

		private static void UpdatePaints(TerrainComp comp, TerrainColors terrainColors, IPaint paint, Vector2 centerVertex, int centerVertex_x, int vertexSearchRadius, int vertex_y, bool heightCheck, float heightOffset, float radiusInVertices, Vector3 worldPos)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = centerVertex_x - vertexSearchRadius; i <= centerVertex_x + vertexSearchRadius; i++)
			{
				UpdatePaint(comp, terrainColors, paint, Vector2.op_Implicit(centerVertex), i, vertex_y, heightCheck, heightOffset, radiusInVertices, worldPos);
			}
		}

		private static void UpdatePaint(TerrainComp comp, TerrainColors terrainColors, IPaint paint, Vector3 centerVertex, int vertex_x, int vertex_y, bool heightCheck, float heightOffset, float radiusInVertices, Vector3 worldPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			float distanceFromCenter = Vector2.Distance(Vector2.op_Implicit(centerVertex), new Vector2((float)vertex_x, (float)vertex_y));
			bool flag = vertex_x >= 0 && vertex_y >= 0 && vertex_x < comp.m_pitch && vertex_y < comp.m_pitch;
			bool flag2 = !heightCheck || comp.m_hmap.GetHeight(vertex_x, vertex_y) <= heightOffset;
			if (flag && flag2)
			{
				int index = Util.GetIndex(vertex_x, vertex_y, comp.m_pitch);
				PaintMask(comp, paint, index, vertex_x, vertex_y, distanceFromCenter, radiusInVertices, worldPos);
				PaintTerrain(terrainColors, paint, index, vertex_x, vertex_y, distanceFromCenter, radiusInVertices, worldPos);
				PaintElevation(comp, paint, index);
			}
		}

		private static void PaintMask(TerrainComp comp, IPaint paint, int index, int vertex_x, int vertex_y, float distanceFromCenter, float radiusInVertices, Vector3 worldPos)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_00cc: 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_009b: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			if (paint.reset)
			{
				comp.m_modifiedPaint[index] = false;
				comp.m_paintMask[index] = new Color(0f, 0f, 0f, 1f);
				return;
			}
			Color val = ((comp.m_hmap.m_doLateUpdate != 1) ? comp.m_hmap.GetPaintMask(vertex_x, vertex_y) : comp.m_paintMask[index]);
			Color val2;
			if (paint.blend)
			{
				float num = Mathf.Pow(1f - Mathf.Clamp01(distanceFromCenter / radiusInVertices), 0.1f);
				float a = val.a;
				val2 = Color.Lerp(val, paint.GetColor(), num);
				if (!paint.overrideAlpha)
				{
					val2.a = a;
				}
			}
			else
			{
				val2 = paint.GetColor();
				if (!paint.overrideAlpha)
				{
					val2.a = val.a;
				}
			}
			comp.m_modifiedPaint[index] = true;
			comp.m_paintMask[index] = val2;
		}

		private static void PaintTerrain(TerrainColors colors, IPaint paint, int index, int vertex_x, int vertex_y, float distanceFromCenter, float radiusInVertices, Vector3 worldPos)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			if (!paint.isBiomePaint || (Object)(object)colors == (Object)null)
			{
				return;
			}
			if (paint.reset)
			{
				colors.ResetTerrain(index);
				return;
			}
			Color32 color;
			if (paint.blendTerrain)
			{
				float num = Mathf.Pow(1f - Mathf.Clamp01(distanceFromCenter / radiusInVertices), 0.1f);
				Color32 currentBiomeColor = colors.GetCurrentBiomeColor(index, vertex_x, vertex_y);
				color = Color32.Lerp(currentBiomeColor, paint.GetBiomeColor(), num);
			}
			else
			{
				color = paint.GetBiomeColor();
			}
			colors.SetBiomeColor(index, color, paint.forceGrass);
		}

		private static void PaintElevation(TerrainComp comp, IPaint paint, int index)
		{
			if (paint.reset)
			{
				comp.m_modifiedHeight[index] = false;
				comp.m_levelDelta[index] = 0f;
				comp.m_smoothDelta[index] = 0f;
			}
		}

		private static List<TerrainComp> GetNeighbors(this TerrainComp comp, Vector3 worldPos, int x, int y, float radius)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: 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_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_0181: 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)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			List<TerrainComp> list = new List<TerrainComp>();
			if (x == 0)
			{
				TerrainComp val = comp.TryGetNeighbor(worldPos, 0, 1, radius);
				if (val != null)
				{
					list.Add(val);
				}
				if (y == 0)
				{
					TerrainComp val2 = comp.TryGetNeighbor(worldPos, 0, 0, radius);
					if (val2 != null)
					{
						list.Add(val2);
					}
					TerrainComp val3 = comp.TryGetNeighbor(worldPos, 1, 0, radius);
					if (val3 != null)
					{
						list.Add(val3);
					}
				}
				else if (y == comp.m_width)
				{
					TerrainComp val4 = comp.TryGetNeighbor(worldPos, 0, 2, radius);
					if (val4 != null)
					{
						list.Add(val4);
					}
					TerrainComp val5 = comp.TryGetNeighbor(worldPos, 1, 2, radius);
					if (val5 != null)
					{
						list.Add(val5);
					}
				}
			}
			else if (x == comp.m_width)
			{
				TerrainComp val6 = comp.TryGetNeighbor(worldPos, 2, 1, radius);
				if (val6 != null)
				{
					list.Add(val6);
				}
				if (y == 0)
				{
					TerrainComp val7 = comp.TryGetNeighbor(worldPos, 2, 0, radius);
					if (val7 != null)
					{
						list.Add(val7);
					}
					TerrainComp val8 = comp.TryGetNeighbor(worldPos, 1, 0, radius);
					if (val8 != null)
					{
						list.Add(val8);
					}
				}
				else if (y == comp.m_width)
				{
					TerrainComp val9 = comp.TryGetNeighbor(worldPos, 2, 2, radius);
					if (val9 != null)
					{
						list.Add(val9);
					}
					TerrainComp val10 = comp.TryGetNeighbor(worldPos, 1, 2, radius);
					if (val10 != null)
					{
						list.Add(val10);
					}
				}
			}
			else if (y == 0)
			{
				TerrainComp val11 = comp.TryGetNeighbor(worldPos, 1, 0, radius);
				if (val11 != null)
				{
					list.Add(val11);
				}
			}
			else if (y == comp.m_width)
			{
				TerrainComp val12 = comp.TryGetNeighbor(worldPos, 1, 2, radius);
				if (val12 != null)
				{
					list.Add(val12);
				}
			}
			return list;
		}

		private static void Apply_TerrainColor_Modifiers(Heightmap heightmap)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			if (heightmap.m_isDistantLod || !TerrainColors.TryFindTerrainColors(((Component)heightmap).transform.position, out var instance) || !instance.m_initialized)
			{
				return;
			}
			int num = heightmap.m_width + 1;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					int index = Util.GetIndex(i, j, num);
					if (instance.m_modifiedTerrain[index])
					{
						Color32 value = instance.m_terrainMask[index];
						Heightmap.s_tempColors[index] = value;
					}
				}
			}
		}

		public static Biome GetBiomeFromMesh(this Heightmap hm, Vector3 point, float oceanLevel = 0.02f, bool waterAlwaysOcean = false)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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)
			if (hm.m_isDistantLod || waterAlwaysOcean)
			{
				return WorldGenerator.instance.GetBiome(point.x, point.z, oceanLevel, waterAlwaysOcean);
			}
			if (!TerrainColors.TryFindTerrainColors(((Component)hm).transform.position, out var instance))
			{
				return hm.GetBiome(point, 0.02f, false);
			}
			return instance.GetBiome(hm, point);
		}
	}
	public class PaintOptions : MonoBehaviour
	{
		[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
		private static class Hud_SetupPieceInfo_Patch
		{
			private static void Postfix(Hud __instance, Piece piece)
			{
				if (!((Object)(object)piece == (Object)null) && !((Object)(object)instance == (Object)null))
				{
					__instance.m_pieceDescription.text = instance.m_pieceInfo;
				}
			}
		}

		public static PaintOptions instance;

		public Piece m_piece;

		public float radius;

		public ParticleSystem m_ring;

		public ParticleSystem m_particles;

		public CircleProjector projector;

		private IPaint m_tool;

		public string m_pieceInfo = "";

		private float m_minRadius = 5f;

		private float m_maxRadius = 20f;

		private float m_maxSmooth = 10f;

		private float m_maxRaiseDelta = 20f;

		public void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			TerrainOp val = default(TerrainOp);
			if (!((Component)this).TryGetComponent<TerrainOp>(ref val) || !IPaint.TryGetPaintTool(val.m_settings.m_paintType, out m_tool))
			{
				TerrainHoePlugin.LogWarning("Invalid paint tool");
				Object.Destroy((Object)(object)this);
			}
			m_piece = ((Component)this).GetComponent<Piece>();
			radius = m_tool.terrainOp.m_settings.m_paintRadius;
			m_ring = ((Component)((Component)this).transform.Find("_GhostOnly")).GetComponent<ParticleSystem>();
			m_particles = ((Component)((Component)this).transform.Find("_GhostOnly/particles")).GetComponent<ParticleSystem>();
			projector = ((Component)this).GetComponentInChildren<CircleProjector>(true);
			projector.m_radius = radius;
			projector.m_mask = LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "terrain" }));
			projector.m_nrOfSegments = Mathf.CeilToInt(radius / 2f);
			UpdateHudPieceInfo();
			instance = this;
		}

		public void OnDestroy()
		{
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}

		public void FixedUpdate()
		{
			if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				float mouseScrollWheel = ZInput.GetMouseScrollWheel();
				if (UpdateSmooth(mouseScrollWheel) || UpdateRadius(mouseScrollWheel) || UpdateRaise(mouseScrollWheel) || UpdateLevel(mouseScrollWheel))
				{
					UpdateHudPieceInfo();
				}
			}
		}

		public void UpdateHudPieceInfo()
		{
			if (Object.op_Implicit((Object)(object)Hud.instance))
			{
				StringBuilder stringBuilder = new StringBuilder(256);
				stringBuilder.Append(m_piece.m_description);
				stringBuilder.AppendFormat("\n[<color=orange>{0}</color> + <color=orange>{1}</color>] +- radius\n[<color=orange>{0}</color> + <color=orange>{2}</color>] +- smooth\n[<color=orange>{0}</color> + <color=orange>{3}</color>] +- raise\n[<color=orange>{0}</color> + <color=orange>{4}</color>] +- level\n", "Scroll", (object)(KeyCode)304, (object)(KeyCode)113, (object)(KeyCode)114, (object)(KeyCode)108);
				stringBuilder.Append($"SmoothPower: <color=orange>{m_tool.terrainOp.m_settings.m_smoothPower}</color>");
				stringBuilder.Append($", RaisePower: <color=orange>{m_tool.terrainOp.m_settings.m_raisePower}</color>");
				stringBuilder.Append($", RaiseDelta: <color=orange>{m_tool.terrainOp.m_settings.m_raiseDelta}</color>");
				stringBuilder.Append($", LevelOffset: <color=orange>{m_tool.terrainOp.m_settings.m_levelOffset}</color>");
				m_pieceInfo = Localization.instance.Localize(stringBuilder.ToString());
			}
		}

		private bool UpdateRadius(float scroll)
		{
			if (!ZInput.GetKey((KeyCode)304, true))
			{
				return false;
			}
			bool flag = false;
			if (scroll > Player.m_localPlayer.m_scrollAmountThreshold)
			{
				radius = Mathf.Clamp(radius + 0.5f, m_minRadius, m_maxRadius);
				flag = true;
			}
			if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold)
			{
				radius = Mathf.Clamp(radius - 0.5f, m_minRadius, m_maxRadius);
				flag = true;
			}
			if (!flag)
			{
				return false;
			}
			m_tool.terrainOp.m_settings.m_levelRadius = radius;
			m_tool.terrainOp.m_settings.m_raiseRadius = radius;
			m_tool.terrainOp.m_settings.m_paintRadius = radius;
			m_tool.terrainOp.m_settings.m_smoothRadius = radius + 1f;
			projector.m_radius = radius;
			projector.m_nrOfSegments = Math.Max(Mathf.CeilToInt(radius), 4);
			return true;
		}

		private bool UpdateSmooth(float scroll)
		{
			if (!ZInput.GetKey((KeyCode)113, true))
			{
				return false;
			}
			bool flag = false;
			if (scroll > Player.m_localPlayer.m_scrollAmountThreshold)
			{
				m_tool.terrainOp.m_settings.m_smoothPower = Mathf.Clamp(m_tool.terrainOp.m_settings.m_smoothPower + 0.5f, 0f, m_maxSmooth);
				flag = true;
			}
			if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold)
			{
				m_tool.terrainOp.m_settings.m_smoothPower = Mathf.Clamp(m_tool.terrainOp.m_settings.m_smoothPower - 0.5f, 0f, m_maxSmooth);
				flag = true;
			}
			if (!flag)
			{
				return false;
			}
			m_tool.terrainOp.m_settings.m_smooth = m_tool.terrainOp.m_settings.m_smoothPower > 0f;
			return true;
		}

		private bool UpdateRaise(float scroll)
		{
			if (!ZInput.GetKey((KeyCode)114, true))
			{
				return false;
			}
			bool flag = false;
			if (scroll > Player.m_localPlayer.m_scrollAmountThreshold)
			{
				m_tool.terrainOp.m_settings.m_raisePower = Mathf.Clamp01(m_tool.terrainOp.m_settings.m_raisePower + 0.1f);
				m_tool.terrainOp.m_settings.m_raiseDelta = Mathf.Clamp(m_tool.terrainOp.m_settings.m_raiseDelta + 0.5f, 0f, m_maxRaiseDelta);
				flag = true;
			}
			if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold)
			{
				m_tool.terrainOp.m_settings.m_raisePower = Mathf.Clamp01(m_tool.terrainOp.m_settings.m_raisePower - 0.1f);
				m_tool.terrainOp.m_settings.m_raiseDelta = Mathf.Clamp(m_tool.terrainOp.m_settings.m_raiseDelta - 0.5f, 0f, m_maxRaiseDelta);
				flag = true;
			}
			if (!flag)
			{
				return false;
			}
			m_tool.terrainOp.m_settings.m_raise = m_tool.terrainOp.m_settings.m_raiseDelta > 0f;
			return true;
		}

		private bool UpdateLevel(float scroll)
		{
			if (!ZInput.GetKey((KeyCode)108, true))
			{
				return false;
			}
			bool flag = false;
			if (scroll > Player.m_localPlayer.m_scrollAmountThreshold)
			{
				Settings settings = m_tool.terrainOp.m_settings;
				settings.m_levelOffset += 1f;
				flag = true;
			}
			if (scroll < 0f - Player.m_localPlayer.m_scrollAmountThreshold)
			{
				Settings settings2 = m_tool.terrainOp.m_settings;
				settings2.m_levelOffset -= 1f;
				flag = true;
			}
			if (!flag)
			{
				return false;
			}
			m_tool.terrainOp.m_settings.m_level = m_tool.terrainOp.m_settings.m_levelOffset != 0f;
			return true;
		}
	}
	public class AshlandsGrass : IPaint
	{
		public AshlandsGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("AshlandsGrass"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			overrideAlpha = true;
			forceGrass = true;
			piece.m_icon = AssetBundleMan.GetSprite("ashland_grass_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 0f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue);
		}

		public override Biome GetBiome()
		{
			return (Biome)32;
		}
	}
	public class BlackForestGrass : IPaint
	{
		public BlackForestGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("BlackForestGrass"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("blackforest_grass_icon.png");
			RequiredItems.Add("Resin", 1, recover: false);
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)0, (byte)0, byte.MaxValue, (byte)0);
		}

		public override Biome GetBiome()
		{
			return (Biome)8;
		}
	}
	public class Lava : IPaint
	{
		public Lava(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("Lava"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			overrideAlpha = true;
			piece.m_icon = AssetBundleMan.GetSprite("lava_ground_icon.png");
			RequiredItems.Add("SulfurStone", 1, recover: false);
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Color32(byte.MaxValue, (byte)0, (byte)0, byte.MaxValue);
		}

		public override Biome GetBiome()
		{
			return (Biome)32;
		}
	}
	public class MeadowsGrass : IPaint
	{
		public MeadowsGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("MeadowsGrass"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("meadows_grass_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)0, (byte)0, (byte)0, (byte)0);
		}

		public override Biome GetBiome()
		{
			return (Biome)1;
		}
	}
	public class MistlandsGrass : IPaint
	{
		public MistlandsGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("Mistlands"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("mistlands_grass_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)0, (byte)0, byte.MaxValue, byte.MaxValue);
		}

		public override Biome GetBiome()
		{
			return (Biome)512;
		}
	}
	public class MistlandsDirt : IPaint
	{
		public MistlandsDirt(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("MistlandsDirt"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("mistlands_ground_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(1f, 0f, 0f, 0f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)0, (byte)0, byte.MaxValue, byte.MaxValue);
		}

		public override Biome GetBiome()
		{
			return (Biome)512;
		}
	}
	public class PavedDark : IPaint
	{
		public PavedDark(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("PavedCultivated"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			piece.m_icon = AssetBundleMan.GetSprite("paved_dark_icon.png");
			RequiredItems.Add("Stone", 1, recover: false);
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 1f, 0.5f, 1f);
		}

		public override Biome GetBiome()
		{
			throw new NotImplementedException();
		}
	}
	public class PavedGrass : IPaint
	{
		public PavedGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("PavedGrass"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			piece.m_icon = AssetBundleMan.GetSprite("paved_grass_icon.png");
			RequiredItems.Add("Stone", 1, recover: false);
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0.5f, 0.5f);
		}
	}
	public class PlainsGrass : IPaint
	{
		public PlainsGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("PlainsGrass"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("plains_grass_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)0, (byte)0, (byte)0, byte.MaxValue);
		}

		public override Biome GetBiome()
		{
			return (Biome)16;
		}
	}
	public class Reset : IPaint
	{
		public Reset(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("ResetAll"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			reset = true;
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}
	}
	public class Snow : IPaint
	{
		public Snow(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("Snow"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("snow_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return Color.clear;
		}

		public override Color32 GetBiomeColor()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new Color32((byte)0, byte.MaxValue, (byte)0, (byte)0);
		}

		public override Biome GetBiome()
		{
			return (Biome)4;
		}
	}
	public class SwampGrass : IPaint
	{
		public SwampGrass(string id, string name, int index = 1)
			: base(id, name, PaintMan.GetPaintType("SwampGrass"), index)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			isBiomePaint = true;
			piece.m_icon = AssetBundleMan.GetSprite("swamp_grass_icon.png");
		}

		public override Color GetColor()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			return new Color(0f, 0f, 0f, 1f);
		}

		public override Color32 GetBiomeColor()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return new Color32(byte.MaxValue, (byte)0, (byte)0, (byte)0);
		}

		public override Biome GetBiome()
		{
			return (Biome)2;
		}
	}
	public static class PrefabManager
	{
		public static ZNetScene _ZNetScene;

		public static ObjectDB _ObjectDB;

		internal static GameObject GetPrefab(string prefabName)
		{
			if ((Object)(object)ZNetScene.instance != (Object)null)
			{
				GameObject prefab = ZNetScene.instance.GetPrefab(prefabName);
				if ((Object)(object)prefab != (Object)null)
				{
					return prefab;
				}
			}
			if ((Object)(object)_ZNetScene != (Object)null)
			{
				GameObject prefab = _ZNetScene.m_prefabs.Find((GameObject p) => ((Object)p).name == prefabName);
				if ((Object)(object)prefab != (Object)null)
				{
					return prefab;
				}
			}
			return null;
		}
	}
	public class TerrainColors : MonoBehaviour
	{
		private static readonly List<TerrainColors> instances = new List<TerrainColors>();

		public int m_width;

		public bool[] m_modifiedTerrain;

		public Color32[] m_terrainMask;

		public bool[] m_forceGrass;

		public bool m_initialized;

		public TerrainComp m_terrainComp;

		public ZNetView m_nview;

		public void Awake()
		{
			m_nview = ((Component)this).GetComponent<ZNetView>();
			m_terrainComp = ((Component)this).GetComponent<TerrainComp>();
			instances.Add(this);
		}

		public void OnDestroy()
		{
			instances.Remove(this);
		}

		public void Initialize()
		{
			m_width = m_terrainComp.m_hmap.m_width;
			int num = m_width + 1;
			m_modifiedTerrain = new bool[num * num];
			m_terrainMask = (Color32[])(object)new Color32[num * num];
			m_forceGrass = new bool[num * num];
			m_initialized = true;
		}

		public void Save()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0080: 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_0088: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			if (!m_initialized || !m_nview.IsValid() || !m_nview.IsOwner())
			{
				return;
			}
			ZPackage val = new ZPackage();
			val.Write(m_modifiedTerrain.Length);
			for (int i = 0; i < m_modifiedTerrain.Length; i++)
			{
				bool flag = m_modifiedTerrain[i];
				val.Write(flag);
				bool flag2 = m_forceGrass[i];
				val.Write(flag2);
				if (flag)
				{
					Color32 val2 = m_terrainMask[i];
					val.Write(val2.r);
					val.Write(val2.g);
					val.Write(val2.b);
					val.Write(val2.a);
				}
			}
			byte[] array = Utils.Compress(val.GetArray());
			m_nview.GetZDO().Set(PaintVars.TerrainColors, array);
		}

		public void Load()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_00bf: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			byte[] byteArray = m_nview.GetZDO().GetByteArray(PaintVars.TerrainColors, (byte[])null);
			if (byteArray == null)
			{
				return;
			}
			byte[] array = Utils.Decompress(byteArray);
			ZPackage val = new ZPackage(array);
			int num = val.ReadInt();
			for (int i = 0; i < num; i++)
			{
				bool flag = val.ReadBool();
				bool flag2 = val.ReadBool();
				m_modifiedTerrain[i] = flag;
				m_forceGrass[i] = flag2;
				if (flag)
				{
					byte b = val.ReadByte();
					byte b2 = val.ReadByte();
					byte b3 = val.ReadByte();
					byte b4 = val.ReadByte();
					m_terrainMask[i] = new Color32(b, b2, b3, b4);
				}
				else
				{
					m_terrainMask[i] = default(Color32);
				}
			}
		}

		public void SetBiomeColor(int index, Color32 color, bool forceGrass = false)
		{
			//IL_0020: 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)
			if (m_initialized)
			{
				m_modifiedTerrain[index] = true;
				m_terrainMask[index] = color;
				m_forceGrass[index] = forceGrass;
			}
		}

		public void ResetTerrain(int index)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (m_initialized)
			{
				m_modifiedTerrain[index] = false;
				m_terrainMask[index] = default(Color32);
				m_forceGrass[index] = false;
			}
		}

		public void ApplyToHeightmap(Heightmap hm)
		{
			//IL_005e: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!m_initialized)
			{
				return;
			}
			List<Color32> list = new List<Color32>();
			hm.m_renderMesh.GetColors(list);
			int num = hm.m_width + 1;
			for (int i = 0; i < num; i++)
			{
				for (int j = 0; j < num; j++)
				{
					int num2 = i * num + j;
					if (m_modifiedTerrain[num2])
					{
						Color32 value = m_terrainMask[num2];
						list[num2] = value;
					}
				}
			}
			hm.m_renderMesh.SetColors(list);
		}

		public Color32 GetCurrentBiomeColor(int index, int x, int y)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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)
			if (m_modifiedTerrain[index])
			{
				return m_terrainMask[index];
			}
			return Color32.op_Implicit(m_terrainComp.m_hmap.GetBiomeColor((float)x, (float)y));
		}

		public Biome GetBiome(Heightmap hm, Vector3 point)
		{
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_012a: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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_005e: 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_0077: 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_00ac: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int num = default(int);
				int num2 = default(int);
				hm.WorldToVertex(point, ref num, ref num2);
				int num3 = num2 * (hm.m_width + 1) + num;
				if (!m_modifiedTerrain[num3])
				{
					return hm.GetBiome(point, 0.02f, false);
				}
				Color32 val = m_terrainMask[num3];
				if (val.r > 200 && val.a > 200)
				{
					return (Biome)32;
				}
				if (val.b > 200 && val.a > 200)
				{
					return (Biome)512;
				}
				if (val.r > 200)
				{
					return (Biome)2;
				}
				if (val.g > 200)
				{
					return (Biome)68;
				}
				if (val.b > 200)
				{
					return (Biome)8;
				}
				if (val.a > 200)
				{
					return (Biome)16;
				}
				return (Biome)1;
			}
			catch (IndexOutOfRangeException)
			{
				return hm.GetBiome(point, 0.02f, false);
			}
		}

		public bool HasModifiedVertex(Vector3 center, float halfSize)
		{
			//IL_002e: 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_0043: 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_0060: 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)
			if (!m_initialized)
			{
				return false;
			}
			Heightmap hmap = m_terrainComp.m_hmap;
			int num = hmap.m_width + 1;
			int num2 = default(int);
			int num3 = default(int);
			hmap.WorldToVertex(new Vector3(center.x - halfSize, 0f, center.z - halfSize), ref num2, ref num3);
			int num4 = default(int);
			int num5 = default(int);
			hmap.WorldToVertex(new Vector3(center.x + halfSize, 0f, center.z + halfSize), ref num4, ref num5);
			num2 = Mathf.Max(0, num2);
			num3 = Mathf.Max(0, num3);
			num4 = Mathf.Min(num - 1, num4);
			num5 = Mathf.Min(num - 1, num5);
			for (int i = num3; i <= num5; i++)
			{
				int num6 = i * num;
				for (int j = num2; j <= num4; j++)
				{
					if (m_modifiedTerrain[num6 + j])
					{
						return true;
					}
				}
			}
			return false;
		}

		public bool HasForcedGrassVertex(Vector3 center, float halfSize)
		{
			//IL_002e: 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_0043: 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_0060: 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)
			if (!m_initialized)
			{
				return false;
			}
			Heightmap hmap = m_terrainComp.m_hmap;
			int num = hmap.m_width + 1;
			int num2 = default(int);
			int num3 = default(int);
			hmap.WorldToVertex(new Vector3(center.x - halfSize, 0f, center.z - halfSize), ref num2, ref num3);
			int num4 = default(int);
			int num5 = default(int);
			hmap.WorldToVertex(new Vector3(center.x + halfSize, 0f, center.z + halfSize), ref num4, ref num5);
			num2 = Mathf.Max(0, num2);
			num3 = Mathf.Max(0, num3);
			num4 = Mathf.Min(num - 1, num4);
			num5 = Mathf.Min(num - 1, num5);
			for (int i = num3; i <= num5; i++)
			{
				int num6 = i * num;
				for (int j = num2; j <= num4; j++)
				{
					if (m_forceGrass[num6 + j])
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool TryFindTerrainColors(Vector3 pos, out TerrainColors instance)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0043: 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_0059: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < instances.Count; i++)
			{
				TerrainColors terrainColors = instances[i];
				float num = terrainColors.m_terrainComp.m_size / 2f;
				Vector3 position = ((Component)terrainColors).transform.position;
				if (pos.x >= position.x - num && pos.x <= position.x + num && pos.z >= position.z - num && pos.z <= position.z + num)
				{
					instance = terrainColors;
					return true;
				}
			}
			instance = null;
			return false;
		}

		public static TerrainColors FindTerrainColors(Vector3 pos)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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_0043: 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_0059: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < instances.Count; i++)
			{
				TerrainColors terrainColors = instances[i];
				float num = terrainColors.m_terrainComp.m_size / 2f;
				Vector3 position = ((Component)terrainColors).transform.position;
				if (pos.x >= position.x - num && pos.x <= position.x + num && pos.z >= position.z - num && pos.z <= position.z + num)
				{
					return terrainColors;
				}
			}
			return null;
		}
	}
	public static class TerrainHoe_API
	{
		private static readonly MethodInfo API_GetBiome;

		private static readonly MethodInfo API_GetHeightmapBiome;

		private static bool isLoaded;

		public static bool IsLoaded()
		{
			return isLoaded;
		}

		static TerrainHoe_API()
		{
			isLoaded = false;
			Type type = Type.GetType("TerrainHoe.API, TerrainHoe");
			if (type != null)
			{
				isLoaded = true;
				API_GetBiome = type.GetMethod("GetBiome", BindingFlags.Static | BindingFlags.Public);
				API_GetHeightmapBiome = type.GetMethod("GetHeightmapBiome", BindingFlags.Static | BindingFlags.Public);
			}
		}

		public static Biome GetBiome(Vector3 position)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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)
			return (Biome)(API_GetBiome.Invoke(null, new object[1] { position }) ?? ((object)(Biome)0));
		}

		public static Biome GetBiome(Heightmap heightmap, Vector3 position)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			return (Biome)(API_GetHeightmapBiome.Invoke(null, new object[2] { heightmap, position }) ?? ((object)heightmap.GetBiome(position, 0.02f, false)));
		}
	}
	public static class API
	{
		public static Biome GetBiome(Vector3 position)
		{
			//IL_0001: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			Heightmap val = Heightmap.FindHeightmap(position);
			if ((Object)(object)val == (Object)null)
			{
				return (Biome)0;
			}
			return val.GetBiomeFromMesh(position);
		}

		public static Biome GetHeightmapBiome(Heightmap heightmap, Vector3 position)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			return heightmap.GetBiomeFromMesh(position);
		}
	}
	public static class Util
	{
		[SpecialName]
		public sealed class <G>$43BE4BCC24324796B19A2A5269C80CFE
		{
			[SpecialName]
			public static class <M>$22EBDA12F87EB75B25FA9F3192A4008C
			{
			}

			[ExtensionMarker("<M>$22EBDA12F87EB75B25FA9F3192A4008C")]
			private bool TryGetNeighbor(Vector3 worldPos, int ix, int iy, float radius, out TerrainComp neighbor)
			{
				throw new NotSupportedException();
			}

			[ExtensionMarker("<M>$22EBDA12F87EB75B25FA9F3192A4008C")]
			private bool TryGetNeighborColor(Vector3 worldPos, int ix, int iy, float radius, out TerrainColors colors)
			{
				throw new NotSupportedException();
			}
		}

		public static Color GetColor(Heightmap hmap, TerrainComp tc, int x, int y, int index)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//I