Decompiled source of Worldwright v1.0.0

BepInEx/plugins/Worldwright/Worldwright.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using Candide;
using Candide.CandideUI;
using Candide.CandideUI.Components;
using Candide.CandideUI.Components.Buttons;
using Candide.CandideUI.Containers;
using Candide.CandideUI.Input;
using Candide.CandideUI.Tooltip;
using Candide.CandideUI.UiInput;
using Candide.Entities.PlayerState;
using Candide.GameModels;
using Candide.Graphics;
using Candide.Graphics.Fonts;
using Candide.MainMenu.Ui.Steps;
using Candide.Multiplayer.Network;
using Candide.Save;
using Candide.World;
using CandideCreator.Shared.Graphics;
using CandideServer;
using CandideServer.Data.DataModels;
using CandideServer.Database;
using CandideServer.Game;
using CandideServer.Helpers;
using CandideServer.Models.Boss;
using CandideServer.Models.Dungeons;
using CandideServer.Saving;
using CandideServer.ServerManagers;
using CandideServer.World.Generation;
using FontStashSharp;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ModSettingsMenu.Api;
using RomesteadLocalizationAPI.Api;
using Shared.Data;
using Shared.Entity;
using Shared.Models;
using Worldwright.Configuration;
using Worldwright.Features;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Worldwright")]
[assembly: AssemblyDescription("Worldwright For Romestead by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("Worldwright")]
[assembly: AssemblyCopyright("Copyright (C) 2026 Ice Box Studio All rights reserved.")]
[assembly: ComVisible(false)]
[assembly: Guid("4c66776c-d3be-4474-a6d6-5635401a1394")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Worldwright
{
	internal static class I18n
	{
		public static readonly RomesteadLocalizer L = RomesteadLocalization.For("IceBoxStudio.Romestead.Worldwright");
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.Romestead.Worldwright";

		public const string PLUGIN_NAME = "Worldwright";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string PLUGIN_AUTHOR = "Ice Box Studio";

		public const string PLUGIN_AUTHOR_URL = "https://steamcommunity.com/id/ibox666/";

		public const int NEXUS_MODS_ID = 106;

		public const string THUNDERSTORE_TEAM = "Ice_Box_Studio_Romestead";

		public const string THUNDERSTORE_MOD_NAME = "Worldwright";

		public const string UPDATE_MANIFEST_URL = "https://cdn.jsdelivr.net/gh/ibox233/MyMod_Version@main/Worldwright.json";
	}
	[BepInPlugin("IceBoxStudio.Romestead.Worldwright", "Worldwright", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Worldwright : BasePlugin
	{
		private Harmony _harmony;

		public static Worldwright Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		public override void Load()
		{
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Expected O, but got Unknown
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Expected O, but got Unknown
			Instance = this;
			Logger = ((BasePlugin)this).Log;
			bool flag = default(bool);
			try
			{
				Logger.LogInfo((object)"=============================================");
				ManualLogSource logger = Logger;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Worldwright");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initializing...");
				}
				logger.LogInfo(val);
				ManualLogSource logger2 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Author: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Ice Box Studio");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("https://steamcommunity.com/id/ibox666/");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
				}
				logger2.LogInfo(val);
				I18n.L.RegisterJson(Path.Combine(Paths.PluginPath, "Worldwright", "Localization.json"));
				ConfigManager.Init(((BasePlugin)this).Config);
				ModSettingsMenuRegistration.Register(((BasePlugin)this).Config);
				_harmony = new Harmony("IceBoxStudio.Romestead.Worldwright");
				_harmony.PatchAll(Assembly.GetExecutingAssembly());
				ManualLogSource logger3 = Logger;
				val = new BepInExInfoLogInterpolatedStringHandler(13, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Worldwright");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" initialized.");
				}
				logger3.LogInfo(val);
				Logger.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				ManualLogSource logger4 = Logger;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(24, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("Worldwright");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" initialization error: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.StackTrace);
				}
				logger4.LogError(val2);
			}
		}
	}
}
namespace Worldwright.Patches
{
	[HarmonyPatch(typeof(CreateWorldWindow), "FinishGenerating")]
	internal static class CreateWorldWindowModdedPatch
	{
		private static readonly FieldInfo GameDescriptionField = AccessTools.Field(typeof(CreateWorldWindow), "_gameDescription");

		private static void Prefix(CreateWorldWindow __instance)
		{
			if (ConfigManager.Active)
			{
				object? value = GameDescriptionField.GetValue(__instance);
				GameDescription val = (GameDescription)((value is GameDescription) ? value : null);
				if (val != null)
				{
					val.Modded = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameSaveManager), "SaveNewGameToDirectory")]
	internal static class GameSaveManagerSaveNewGamePatch
	{
		private static void Postfix(string directoryPath, GameDescription gameDescription, bool __result)
		{
			if (__result && ConfigManager.Active && gameDescription != null && gameDescription.Modded)
			{
				WorldwrightSaveMetadata.Save(directoryPath, gameDescription, WorldwrightWorldOptions.LastBoundProfile);
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class CreateWorldWindowPatch
	{
		private sealed class LayoutState
		{
			public CreateWorldWindow Window { get; }

			public CandideGrid Layout { get; }

			public CandideVerticalStackPanel AdvancedPanel { get; }

			public HorizontalAlignment LayoutHorizontalAlignment { get; }

			public int? WindowWidth { get; }

			public int? WindowMaxHeight { get; }

			public int? PanelWidth { get; }

			public CandideThickness PanelMargin { get; }

			public int PanelGridColumn { get; }

			public int PanelGridRow { get; }

			public LayoutState(CreateWorldWindow window, CandideGrid layout, CandideVerticalStackPanel advancedPanel, CandideVerticalStackPanel createMenuPanel)
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Unknown result type (might be due to invalid IL or missing references)
				Window = window;
				Layout = layout;
				AdvancedPanel = advancedPanel;
				LayoutHorizontalAlignment = ((CandideUiElement)layout).HorizontalAlignment;
				WindowWidth = ((CandideUiElement)window).Width;
				WindowMaxHeight = ((CandideUiElement)window).MaxHeight;
				PanelWidth = ((CandideUiElement)createMenuPanel).Width;
				PanelMargin = ((CandideUiElement)createMenuPanel).Margin;
				PanelGridColumn = ((CandideUiElement)createMenuPanel).GridColumn;
				PanelGridRow = ((CandideUiElement)createMenuPanel).GridRow;
			}
		}

		private const string ClickSound = "event:/interface/main menu/ui_mainmenu_click";

		private const int AdvancedPanelWidth = 260;

		private const int ExpandedWindowMaxHeight = 680;

		private static readonly ConditionalWeakTable<CreateWorldWindow, LayoutState> Layouts = new ConditionalWeakTable<CreateWorldWindow, LayoutState>();

		private static readonly float[] AmountValues = new float[9] { 0f, 0.25f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f };

		private static readonly float[] ScaleValues = new float[7] { 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f };

		private static void Postfix(CreateWorldWindow __instance, CandideVerticalStackPanel ____createMenuPanel, CandideIconLabelButton ____saveBtn, CandideIconLabelButton ____backButton)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			WorldwrightWorldOptions.ResetCurrent();
			if (!ConfigManager.Active)
			{
				return;
			}
			bool flag = false;
			bool flag2 = false;
			try
			{
				flag = ((CandideUiContainerMultipleItems)____createMenuPanel).RemoveChild((CandideUiElement)(object)____saveBtn);
				flag2 = ((CandideUiContainerMultipleItems)____createMenuPanel).RemoveChild((CandideUiElement)(object)____backButton);
				AddControls(____createMenuPanel, TryWrapCreateMenuPanel(__instance, ____createMenuPanel));
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Worldwright.Logger;
				bool flag3 = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(49, 1, ref flag3);
				if (flag3)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to add Worldwright create-world controls: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
			finally
			{
				if (flag && ((CandideUiElement)____saveBtn).Parent == null)
				{
					((CandideUiContainerMultipleItems)____createMenuPanel).AddChild((CandideUiElement)(object)____saveBtn, false);
				}
				if (flag2 && ((CandideUiElement)____backButton).Parent == null)
				{
					((CandideUiContainerMultipleItems)____createMenuPanel).AddChild((CandideUiElement)(object)____backButton, false);
				}
			}
		}

		internal static void RestoreCreateMenuPanel(CreateWorldWindow window, CandideVerticalStackPanel panel)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if (Layouts.TryGetValue(window, out var value))
			{
				SetAdvancedExpanded(value, expanded: false);
				if ((object)((CandideUiElement)value.Layout).Parent == ((AbstractStepsWindow)window).MainPanel)
				{
					((CandideUiContainerMultipleItems)((AbstractStepsWindow)window).MainPanel).RemoveChild((CandideUiElement)(object)value.Layout);
				}
				if ((object)((CandideUiElement)panel).Parent == value.Layout)
				{
					((CandideUiContainerMultipleItems)value.Layout).RemoveChild((CandideUiElement)(object)panel);
				}
				((CandideUiElement)panel).Width = value.PanelWidth;
				((CandideUiElement)panel).Margin = value.PanelMargin;
				((CandideUiElement)panel).GridColumn = value.PanelGridColumn;
				((CandideUiElement)panel).GridRow = value.PanelGridRow;
				if ((object)((CandideUiElement)panel).Parent != ((AbstractStepsWindow)window).MainPanel)
				{
					((CandideUiContainerMultipleItems)((AbstractStepsWindow)window).MainPanel).AddChild((CandideUiElement)(object)panel, false);
				}
				Layouts.Remove(window);
			}
		}

		private static LayoutState TryWrapCreateMenuPanel(CreateWorldWindow window, CandideVerticalStackPanel panel)
		{
			//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_001d: 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_0038: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0057: 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_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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (Layouts.TryGetValue(window, out var value))
			{
				return value;
			}
			CandideVerticalStackPanel val = new CandideVerticalStackPanel
			{
				HorizontalAlignment = (HorizontalAlignment)3,
				DefaultColumnProportion = Proportion.Fill,
				Width = 260,
				Margin = new CandideThickness(16, 0, 0, 0),
				GridColumn = 1,
				Visible = false
			};
			CandideGrid val2 = new CandideGrid
			{
				HorizontalAlignment = (HorizontalAlignment)3,
				DefaultColumnProportion = Proportion.Auto,
				DefaultRowProportion = Proportion.Auto,
				Margin = new CandideThickness(0, 12, 0, 0)
			};
			val2.ColumnsProportions.Add(Proportion.Auto);
			val2.ColumnsProportions.Add(Proportion.Auto);
			value = new LayoutState(window, val2, val, panel);
			if (!((CandideUiContainerMultipleItems)((AbstractStepsWindow)window).MainPanel).RemoveChild((CandideUiElement)(object)panel))
			{
				return value;
			}
			((CandideUiElement)panel).Margin = new CandideThickness(0);
			((CandideUiElement)panel).GridColumn = 0;
			((CandideUiContainerMultipleItems)val2).AddChild((CandideUiElement)(object)panel, false);
			((CandideUiContainerMultipleItems)val2).AddChild((CandideUiElement)(object)val, false);
			((CandideUiContainerMultipleItems)((AbstractStepsWindow)window).MainPanel).AddChild((CandideUiElement)(object)val2, false);
			Layouts.Add(window, value);
			return value;
		}

		private static void AddControls(CandideVerticalStackPanel panel, LayoutState state)
		{
			//IL_003c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0074: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			WorldwrightProfile profile = WorldwrightWorldOptions.CurrentProfile.Clone();
			List<CandideUiElement> advancedControls = new List<CandideUiElement>();
			CandideVerticalStackPanel advancedPanel = state.AdvancedPanel;
			bool num = panel != advancedPanel;
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)new CandideTextLabel
			{
				Text = Text("create_world.worldwright"),
				TextStyle = (CandideTextStyle)2,
				HorizontalAlignment = (HorizontalAlignment)3,
				Margin = new CandideThickness(0, 8, 0, 0)
			}, false);
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)(object)Label("create_world.preset"), false);
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)(object)CreatePresetSpinner(profile), false);
			CandideCheckboxLabel val = new CandideCheckboxLabel((CheckboxType)0, (int?)null, false)
			{
				Text = Text("create_world.advanced"),
				HorizontalAlignment = (HorizontalAlignment)3,
				Padding = new CandideThickness(4, 2),
				Margin = new CandideThickness(0, 4)
			};
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)(object)val, false);
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.biome_scale", ScaleValues, profile.BiomeScale, delegate(float value)
			{
				profile.BiomeScale = value;
			});
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.water", AmountValues, profile.Water, delegate(float value)
			{
				profile.Water = value;
			});
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.mountains", AmountValues, profile.Mountains, delegate(float value)
			{
				profile.Mountains = value;
			});
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.forest", AmountValues, profile.Forest, delegate(float value)
			{
				profile.Forest = value;
			});
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.desert", AmountValues, profile.Desert, delegate(float value)
			{
				profile.Desert = value;
			});
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.volcanic", AmountValues, profile.Volcanic, delegate(float value)
			{
				profile.Volcanic = value;
			});
			AddAmountControl(advancedPanel, advancedControls, profile, "create_world.swamp", AmountValues, profile.Swamp, delegate(float value)
			{
				profile.Swamp = value;
			});
			AddToggleControl(advancedPanel, advancedControls, profile, "create_world.rivers", profile.Rivers, delegate(bool value)
			{
				profile.Rivers = value;
			});
			AddToggleControl(advancedPanel, advancedControls, profile, "create_world.roads", profile.Roads, delegate(bool value)
			{
				profile.Roads = value;
			});
			if (num)
			{
				SetAdvancedExpanded(state, expanded: false);
				val.Checkbox.Toggled += delegate(object _, bool visible)
				{
					SetAdvancedExpanded(state, visible);
				};
			}
			else
			{
				SetVisible(advancedControls, visible: false);
				val.Checkbox.Toggled += delegate(object _, bool visible)
				{
					SetVisible(advancedControls, visible);
				};
			}
			WorldwrightWorldOptions.SetCurrent(profile);
		}

		private static void SetAdvancedExpanded(LayoutState state, bool expanded)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			((CandideUiElement)state.AdvancedPanel).Visible = expanded;
			((CandideUiElement)state.Layout).Width = null;
			((CandideUiElement)state.Layout).HorizontalAlignment = state.LayoutHorizontalAlignment;
			((CandideUiElement)state.Window).Width = state.WindowWidth;
			((CandideUiElement)state.Window).MaxHeight = (expanded ? new int?(680) : state.WindowMaxHeight);
		}

		private static CandideValueSpinner<ConfigManager.WorldPreset> CreatePresetSpinner(WorldwrightProfile profile)
		{
			return CreateSpinner(new ValueSpinnerValue<ConfigManager.WorldPreset>[8]
			{
				Preset(ConfigManager.WorldPreset.Balanced, "preset.balanced"),
				Preset(ConfigManager.WorldPreset.Superflat, "preset.superflat"),
				Preset(ConfigManager.WorldPreset.Flattened, "preset.flattened"),
				Preset(ConfigManager.WorldPreset.Mountainous, "preset.mountainous"),
				Preset(ConfigManager.WorldPreset.WaterWorld, "preset.water_world"),
				Preset(ConfigManager.WorldPreset.Drylands, "preset.drylands"),
				Preset(ConfigManager.WorldPreset.Volcanic, "preset.volcanic"),
				Preset(ConfigManager.WorldPreset.Forest, "preset.forest")
			}, profile.Preset, delegate(ConfigManager.WorldPreset value)
			{
				profile.Preset = value;
				WorldwrightWorldOptions.SetCurrent(profile);
			});
		}

		private static void AddAmountControl(CandideVerticalStackPanel panel, List<CandideUiElement> controls, WorldwrightProfile profile, string labelKey, float[] options, float current, Action<float> set)
		{
			float num = Closest(options, current);
			set(num);
			CandideTextLabel val = Label(labelKey);
			CandideValueSpinner<float> val2 = CreateAmountSpinner(options, num, delegate(float value)
			{
				set(value);
				WorldwrightWorldOptions.SetCurrent(profile);
			});
			controls.Add((CandideUiElement)(object)val);
			controls.Add((CandideUiElement)(object)val2);
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)(object)val, false);
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)(object)val2, false);
		}

		private static CandideValueSpinner<float> CreateAmountSpinner(float[] options, float current, Action<float> set)
		{
			ValueSpinnerValue<float>[] array = new ValueSpinnerValue<float>[options.Length];
			for (int i = 0; i < options.Length; i++)
			{
				array[i] = new ValueSpinnerValue<float>
				{
					Name = FormatPercent(options[i]),
					Value = options[i]
				};
			}
			return CreateSpinner(array, Closest(options, current), set);
		}

		private static void AddToggleControl(CandideVerticalStackPanel panel, List<CandideUiElement> controls, WorldwrightProfile profile, string labelKey, bool current, Action<bool> set)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			CandideCheckboxLabel val = new CandideCheckboxLabel((CheckboxType)0, (int?)null, false)
			{
				Text = Text(labelKey),
				HorizontalAlignment = (HorizontalAlignment)3,
				Padding = new CandideThickness(4, 2),
				Margin = new CandideThickness(0, 4)
			};
			val.Checkbox.IsToggledOn = current;
			val.Checkbox.Toggled += delegate(object _, bool value)
			{
				set(value);
				WorldwrightWorldOptions.SetCurrent(profile);
			};
			controls.Add((CandideUiElement)(object)val);
			((CandideUiContainerMultipleItems)panel).AddChild((CandideUiElement)(object)val, false);
		}

		private static CandideValueSpinner<T> CreateSpinner<T>(ValueSpinnerValue<T>[] values, T current, Action<T> set)
		{
			//IL_001d: 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)
			CandideValueSpinner<T> obj = new CandideValueSpinner<T>((IReadOnlyCollection<ValueSpinnerValue<T>>)(object)values);
			((CandideUiElement)obj).HorizontalAlignment = (HorizontalAlignment)3;
			((CandideUiElement)obj).Padding = new CandideThickness(4, 2);
			((CandideUiElement)obj).Margin = new CandideThickness(0, 4);
			obj.OnClickLeftOrRightSoundEvent = "event:/interface/main menu/ui_mainmenu_click";
			obj.Value = Find(values, current);
			obj.OnValueChanged += delegate(object _, ValueSpinnerValue<T> value)
			{
				set(value.Value);
			};
			return obj;
		}

		private static ValueSpinnerValue<T> Find<T>(ValueSpinnerValue<T>[] values, T current)
		{
			foreach (ValueSpinnerValue<T> val in values)
			{
				if (object.Equals(val.Value, current))
				{
					return val;
				}
			}
			return values[0];
		}

		private static ValueSpinnerValue<ConfigManager.WorldPreset> Preset(ConfigManager.WorldPreset preset, string nameKey)
		{
			return new ValueSpinnerValue<ConfigManager.WorldPreset>
			{
				Name = Text(nameKey),
				Value = preset
			};
		}

		private static CandideTextLabel Label(string key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			return new CandideTextLabel
			{
				Text = Text(key),
				HorizontalAlignment = (HorizontalAlignment)3,
				Margin = new CandideThickness(0, 4, 0, 0)
			};
		}

		private static void SetVisible(List<CandideUiElement> elements, bool visible)
		{
			foreach (CandideUiElement element in elements)
			{
				element.Visible = visible;
			}
		}

		private static float Closest(float[] values, float current)
		{
			float num = values[0];
			float num2 = Math.Abs(current - num);
			for (int i = 1; i < values.Length; i++)
			{
				float num3 = Math.Abs(current - values[i]);
				if (num3 < num2)
				{
					num2 = num3;
					num = values[i];
				}
			}
			return num;
		}

		private static string FormatPercent(float value)
		{
			return $"{MathF.Round(value * 100f)}%";
		}

		private static string Text(string key)
		{
			return I18n.L.Text(key, Array.Empty<object>());
		}
	}
	[HarmonyPatch(typeof(CreateWorldWindow), "ShowGeneratingUi")]
	internal static class CreateWorldWindowGeneratingUiPatch
	{
		private static void Prefix(CreateWorldWindow __instance, CandideVerticalStackPanel ____createMenuPanel)
		{
			CreateWorldWindowPatch.RestoreCreateMenuPanel(__instance, ____createMenuPanel);
		}
	}
	[HarmonyPatch(typeof(CandideEngine), "Update")]
	internal static class DebugFeatureUpdatePatch
	{
		private static void Postfix()
		{
			MapTileColorFixes.Apply();
			WorldwrightDebug.Update();
		}
	}
	[HarmonyPatch(typeof(PlayerStateHelper), "UpdateMovement")]
	internal static class PlayerStateHelperPatch
	{
		private static void Prefix(ref float scale)
		{
			scale = WorldwrightDebug.ApplyWalkSpeed(scale);
		}
	}
	[HarmonyPatch(typeof(SharedDataSetup), "Setup")]
	internal static class MapTileColorFixPatch
	{
		private static void Postfix()
		{
			MapTileColorFixes.Apply();
		}
	}
	[HarmonyPatch(typeof(WorldMap), "Draw")]
	internal static class MinimapInfoOverlayPatch
	{
		private static void Postfix(WorldMap __instance, SpriteBatch batch, bool interior)
		{
			MinimapInfoOverlay.Draw(__instance, batch, interior);
		}
	}
	[HarmonyPatch(typeof(WorldGenerationManager), "CreateGameConfig")]
	internal static class WorldGenerationManagerPatch
	{
		private static void Postfix(GameConfig __result)
		{
			if (ConfigManager.Active)
			{
				WorldwrightProfile worldwrightProfile = WorldwrightWorldOptions.CurrentProfile.ForGeneration();
				if (worldwrightProfile.Preset != ConfigManager.WorldPreset.Balanced || worldwrightProfile.HasCustomGeneration())
				{
					__result.GenerateWorld = true;
					__result.SingleBiome = false;
					__result.SingleBiomeId = null;
				}
				WorldwrightWorldOptions.BindCurrent(__result);
			}
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "GenerateBaseMaps")]
	internal static class WorldGeneratorPatch
	{
		private static bool Prefix(WorldGenerator __instance, GameConfig config)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			if (!ConfigManager.Active)
			{
				return true;
			}
			try
			{
				WorldwrightProfile worldwrightProfile = WorldwrightWorldOptions.Get(config).ForGeneration();
				WorldwrightGenerationState.Set(__instance, worldwrightProfile.Preset);
				if (worldwrightProfile.Preset != ConfigManager.WorldPreset.Superflat)
				{
					return true;
				}
				WorldwrightGenerator.Generate(__instance, config);
				return false;
			}
			catch (Exception ex)
			{
				WorldwrightGenerationState.Clear(__instance);
				ManualLogSource logger = Worldwright.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(56, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Worldwright generation failed, falling back to vanilla: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
				return true;
			}
		}

		private static void Postfix(WorldGenerator __instance, GameConfig config)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if (!ConfigManager.Active)
			{
				return;
			}
			try
			{
				WorldwrightGenerator.ApplyVanillaPostProcess(__instance, config);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Worldwright.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(41, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Worldwright vanilla post-process failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "GenerateTiles")]
	internal static class WorldGeneratorGenerateTilesPatch
	{
		private static void Postfix(WorldGenerator __instance, GameConfig config)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if (!ConfigManager.Active)
			{
				return;
			}
			try
			{
				WorldwrightGenerator.CleanUpPresetTiles(__instance, config);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Worldwright.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(36, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Worldwright terrain cleanup failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "CleanUpWorldTiles")]
	internal static class WorldGeneratorCleanUpWorldTilesPatch
	{
		private static void Postfix(WorldGenerator __instance)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			if (!ConfigManager.Active)
			{
				return;
			}
			try
			{
				WorldwrightGenerator.CleanUpPresetTiles(__instance, ServerGameState.Config);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Worldwright.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(54, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Worldwright terrain cleanup failed after second pass: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}
	}
	[HarmonyPatch(typeof(PoiServerManager), "GeneratePois")]
	internal static class PoiServerManagerGeneratePoisPatch
	{
		private static bool Prefix(WorldGenerator worldGenerator)
		{
			if (ConfigManager.Active)
			{
				return !WorldwrightGenerationState.Is(worldGenerator, ConfigManager.WorldPreset.Superflat);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "GenerateSpawnArea")]
	internal static class WorldGeneratorGenerateSpawnAreaPatch
	{
		private static bool Prefix(WorldGenerator __instance, Vector2 estimatedSpawnPosTile)
		{
			if (ConfigManager.Active)
			{
				return !WorldwrightGenerationState.Is(__instance, ConfigManager.WorldPreset.Superflat);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "GenerateEntitySpots")]
	internal static class WorldGeneratorGenerateEntitySpotsPatch
	{
		private static bool Prefix(WorldGenerator __instance)
		{
			if (!ConfigManager.Active || !WorldwrightGenerationState.Is(__instance, ConfigManager.WorldPreset.Superflat))
			{
				return true;
			}
			__instance.EntitySpots = Array.Empty<(Vector2, float)>();
			return false;
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "GenerateEntities")]
	internal static class WorldGeneratorGenerateEntitiesPatch
	{
		private static bool Prefix(WorldGenerator __instance)
		{
			if (ConfigManager.Active)
			{
				return !WorldwrightGenerationState.Is(__instance, ConfigManager.WorldPreset.Superflat);
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(WorldGenerator), "SpawnWildCrops")]
	internal static class WorldGeneratorSpawnWildCropsPatch
	{
		private static bool Prefix(WorldGenerator __instance)
		{
			if (ConfigManager.Active)
			{
				return !WorldwrightGenerationState.Is(__instance, ConfigManager.WorldPreset.Superflat);
			}
			return true;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal static class WorldListItemPatch
	{
		private static void Postfix(WorldListItem __instance, GameDescription worldModel)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			if (worldModel == null || !worldModel.Modded)
			{
				return;
			}
			CandideVerticalStackPanel value = Traverse.Create((object)__instance).Field("StackPanel1").GetValue<CandideVerticalStackPanel>();
			WorldwrightSaveMetadata.Data metadata = WorldwrightSaveMetadata.Load(worldModel);
			if (metadata != null)
			{
				WorldwrightSaveTooltipPosition.Register((CandideUiElement)(object)__instance);
				((CandideToggleButton)__instance).GetTooltipContent = () => WorldwrightSaveMetadata.BuildTooltip(metadata);
				((CandideToggleButton)__instance).GetPreferredTooltipGrowthDirection = () => (CandideTooltipGrowthDirection)1;
			}
			if (value != null)
			{
				((CandideUiContainerMultipleItems)value).AddChild((CandideUiElement)new CandideTextLabel
				{
					Text = WorldwrightSaveMetadata.GetListText(metadata),
					TextStyle = (CandideTextStyle)9,
					TextColor = StyleHelper.TextYellowColor,
					DisabledTextColor = StyleHelper.TextYellowColor,
					Margin = new CandideThickness(0, 2, 0, 0)
				}, false);
			}
		}
	}
	[HarmonyPatch(typeof(CandideTooltipWindow), "Update", new Type[] { typeof(GameTime) })]
	internal static class WorldwrightSaveTooltipWindowPatch
	{
		private static void Postfix(CandideTooltipWindow __instance)
		{
			ITooltipContent tooltipContent = __instance.TooltipContent;
			CandideUiElement val = (CandideUiElement)(object)((tooltipContent is CandideUiElement) ? tooltipContent : null);
			if (val != null && WorldwrightSaveTooltipPosition.IsRegistered(val))
			{
				WorldwrightSaveTooltipPosition.MoveToMouse(__instance);
			}
		}
	}
	internal static class WorldwrightSaveTooltipPosition
	{
		private sealed class Marker
		{
		}

		private static readonly ConditionalWeakTable<CandideUiElement, Marker> Items = new ConditionalWeakTable<CandideUiElement, Marker>();

		public static void Register(CandideUiElement element)
		{
			Items.Remove(element);
			Items.Add(element, new Marker());
		}

		public static bool IsRegistered(CandideUiElement element)
		{
			Marker value;
			return Items.TryGetValue(element, out value);
		}

		public static void MoveToMouse(CandideTooltipWindow window)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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)
			Vector2 cursorWindowPosition = UiCursorNavigationSystem.CursorWindowPosition;
			int num = 12 * CandideUiSystem.Scale;
			CandideDesktop desktop = ((CandideUiElement)window).Desktop;
			int num2 = desktop?.DesktopWidth ?? ((CandideUiElement)window).ContainerBounds.Width;
			int num3 = desktop?.DesktopHeight ?? ((CandideUiElement)window).ContainerBounds.Height;
			int width = ((CandideUiElement)window).LayoutBounds.Width;
			int height = ((CandideUiElement)window).LayoutBounds.Height;
			float num4 = cursorWindowPosition.X + (float)num;
			float num5 = cursorWindowPosition.Y + (float)num;
			if (num4 + (float)width > (float)(num2 - num))
			{
				num4 = cursorWindowPosition.X - (float)width - (float)num;
			}
			if (num5 + (float)height > (float)(num3 - num))
			{
				num5 = cursorWindowPosition.Y - (float)height - (float)num;
			}
			((CandideUiElement)window).Left = ClampToDesktop(num4, width, num2, num);
			((CandideUiElement)window).Top = ClampToDesktop(num5, height, num3, num);
		}

		private static int ClampToDesktop(float value, int size, int desktopSize, int margin)
		{
			int num = Math.Max(margin, desktopSize - size - margin);
			return (int)MathF.Round(Math.Clamp(value, margin, num));
		}
	}
}
namespace Worldwright.Features
{
	internal static class MapTileColorFixes
	{
		public static void Apply()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			StructureTileData val = TileDataBase.Structures[12];
			if (val != null && !val.PlaceholderData)
			{
				val.Color = new Color(72, 112, 96);
			}
		}
	}
	internal static class MinimapInfoOverlay
	{
		public static void Draw(WorldMap worldMap, SpriteBatch batch, bool interior)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: 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_009c: 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_00b6: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: 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_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			ConfigEntry<bool> showMinimapInfo = ConfigManager.ShowMinimapInfo;
			if (showMinimapInfo == null || !showMinimapInfo.Value || interior || (int)worldMap.Mode != 1)
			{
				return;
			}
			EntityWrapper val = Globals.Game?.Player;
			if (val != null && worldMap.World != null)
			{
				Vector3 position = val.Position;
				string biomeId = GetBiomeId(worldMap.World.WorldToTilePosition(new Vector2(position.X, position.Y)));
				if (biomeId != null)
				{
					Viewport viewport = ((GraphicsResource)batch).GraphicsDevice.Viewport;
					Rectangle bounds = ((Viewport)(ref viewport)).Bounds;
					Point size = ((Rectangle)(ref bounds)).Size;
					Vector2 val2 = ((Point)(ref size)).ToVector2() / 4f;
					val2.X = val2.Y;
					Vector2 val3 = new Vector2(8f, 8f) * (float)CandideUiSystem.Scale;
					Vector2 val4 = new Vector2((float)bounds.Width, 0f) - new Vector2(val2.X, 0f) + new Vector2(0f - val3.X, val3.Y);
					float num = val4.Y + val2.Y + 4f * (float)CandideUiSystem.Scale;
					Vector2 val5 = default(Vector2);
					((Vector2)(ref val5))..ctor(FontManager.FontScale * 0.55f);
					float num2 = (float)FontManager.OculiOutline.RenderFont.LineHeight * val5.Y;
					string text = Text("minimap.biome") + ": " + GetBiomeText(biomeId);
					string text2 = $"X: {position.X:0}, Y: {position.Y:0}, Z: {position.Z:0}";
					Rectangle scissorRectangle = ((GraphicsResource)batch).GraphicsDevice.ScissorRectangle;
					((GraphicsResource)batch).GraphicsDevice.ScissorRectangle = bounds;
					batch.Begin((SpriteSortMode)0, Globals.NonPreMultipliedMaxAlpha, SamplerState.LinearClamp, DepthStencilState.Default, (RasterizerState)null, (Effect)null, (Matrix?)null);
					DrawCenteredText(batch, text, val4.X, val2.X, num, val5);
					DrawCenteredText(batch, text2, val4.X, val2.X, num + num2, val5);
					batch.End();
					((GraphicsResource)batch).GraphicsDevice.ScissorRectangle = scissorRectangle;
				}
			}
		}

		private static string GetBiomeId(Point tile)
		{
			//IL_0009: 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_001b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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)
			string[,] biomeIds = GameState.BiomeIds;
			if (biomeIds == null || tile.X < 0 || tile.Y < 0 || tile.X >= biomeIds.GetLength(0) || tile.Y >= biomeIds.GetLength(1))
			{
				return null;
			}
			if (!string.IsNullOrWhiteSpace(biomeIds[tile.X, tile.Y]))
			{
				return biomeIds[tile.X, tile.Y];
			}
			return "unknown";
		}

		private static string GetBiomeText(string biomeId)
		{
			if (string.IsNullOrWhiteSpace(biomeId))
			{
				return Text("minimap.biome.unknown");
			}
			string text = "minimap.biome." + biomeId.Replace("biome:", "").Replace(':', '_');
			string text2 = Text(text);
			if (string.IsNullOrWhiteSpace(text2) || text2 == text || text2 == "IceBoxStudio.Romestead.Worldwright." + text)
			{
				return biomeId;
			}
			return text2;
		}

		private static void DrawCenteredText(SpriteBatch batch, string text, float left, float width, float y, Vector2 scale)
		{
			//IL_000d: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0052: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			SpriteFontBase renderFont = FontManager.OculiOutline.RenderFont;
			Vector2 val = renderFont.MeasureString(text, (Vector2?)scale, 0f, 0f, (FontSystemEffect)0, 0);
			float num = Math.Max(1f, width - 8f * (float)CandideUiSystem.Scale);
			if (val.X > num)
			{
				scale *= num / val.X;
				val = renderFont.MeasureString(text, (Vector2?)scale, 0f, 0f, (FontSystemEffect)0, 0);
			}
			float num2 = left + (width - val.X) * 0.5f;
			DrawText(batch, text, new Vector2(num2, y), scale, val);
		}

		private static void DrawText(SpriteBatch batch, string text, Vector2 position, Vector2 scale)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0026: 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)
			Vector2 bounds = FontManager.OculiOutline.RenderFont.MeasureString(text, (Vector2?)scale, 0f, 0f, (FontSystemEffect)0, 0);
			DrawText(batch, text, position, scale, bounds);
		}

		private static void DrawText(SpriteBatch batch, string text, Vector2 position, Vector2 scale, Vector2 bounds)
		{
			//IL_0014: 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_0026: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_007b: 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_008d: 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)
			SpriteFontBase renderFont = FontManager.OculiOutline.RenderFont;
			Vector2 val = new Vector2(3f, 1f) * (float)CandideUiSystem.Scale;
			PrimitiveRenderer.DrawRect(batch, position - val, bounds.X + val.X * 2f, bounds.Y + val.Y * 2f, new Color(0f, 0f, 0f, 0.45f), 0f);
			renderFont.DrawText(batch, text, position, Color.White, 0f, default(Vector2), (Vector2?)scale, 0f, 0f, 0f, (TextStyle)0, (FontSystemEffect)0, 0, int.MaxValue);
		}

		private static string Text(string key)
		{
			return I18n.L.Text(key, Array.Empty<object>());
		}
	}
	internal static class WorldwrightDebug
	{
		private static string _lastRevealWaitReason;

		private static ChunkedWorld _revealedWorld;

		public static void Update()
		{
			if (ConfigManager.Active)
			{
				ConfigEntry<bool> debugRevealWorldMap = ConfigManager.DebugRevealWorldMap;
				if (debugRevealWorldMap != null && debugRevealWorldMap.Value)
				{
					TryRevealWorldMap();
				}
			}
		}

		public static float ApplyWalkSpeed(float scale)
		{
			if (ConfigManager.Active)
			{
				ConfigEntry<bool> debugFastWalk = ConfigManager.DebugFastWalk;
				if (debugFastWalk != null && debugFastWalk.Value)
				{
					return scale * Math.Clamp(ConfigManager.DebugWalkSpeedMultiplier.Value, 1f, 10f);
				}
			}
			return scale;
		}

		private static void TryRevealWorldMap()
		{
			if (_revealedWorld == ExteriorWorldHandler.World)
			{
				return;
			}
			if (!TryRevealWorldMap(out var reason))
			{
				if (_lastRevealWaitReason != reason)
				{
					_lastRevealWaitReason = reason;
					Worldwright.Logger.LogInfo((object)reason);
				}
			}
			else
			{
				_lastRevealWaitReason = null;
				_revealedWorld = ExteriorWorldHandler.World;
				Worldwright.Logger.LogInfo((object)"World map revealed.");
			}
		}

		private static bool TryRevealWorldMap(out string reason)
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			reason = null;
			if (!LocalHostServerManager.StartedServer)
			{
				reason = "RevealWorldMap is waiting for a local-hosted world.";
				return false;
			}
			ChunkedWorld world = ExteriorWorldHandler.World;
			WorldMap worldMap = ExteriorWorldHandler.WorldMap;
			if (world == null || worldMap == null)
			{
				reason = "RevealWorldMap is waiting for the exterior world map.";
				return false;
			}
			int length = GameState.WorldTiles.GetLength(0);
			int length2 = GameState.WorldTiles.GetLength(1);
			if (!HasSize(GameState.MappedTiles, length, length2) || !HasSize(ServerGameState.WorldTiles, length, length2) || !HasSize(ServerRunState.TileHeights, length, length2))
			{
				reason = "RevealWorldMap is waiting for server world tiles.";
				return false;
			}
			if (!HasCompleteWorldTiles(length, length2))
			{
				reason = "RevealWorldMap is waiting for complete server world tiles.";
				return false;
			}
			DeleteCachedWorldMap();
			for (int i = 0; i < length; i++)
			{
				for (int j = 0; j < length2; j++)
				{
					GameState.WorldTiles[i, j] = ServerGameState.WorldTiles[i, j];
					GameState.TileHeights[i, j] = ServerRunState.TileHeights[i, j];
					GameState.MappedTiles[i, j] = true;
				}
			}
			CopyBiomeIds(length, length2);
			worldMap.UpdateWholeRectangle(0, 0, length, length2);
			RefreshFogOfWar();
			RevealWorldMarkers();
			return true;
		}

		private static bool HasCompleteWorldTiles(int width, int height)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (HasSize(ServerGameState.BiomeIds, width, height))
			{
				int num = Math.Min(30, Math.Max(0, width / 2 - 1));
				for (int i = num; i < width - num; i += 31)
				{
					for (int j = num; j < height - num; j += 31)
					{
						if (string.IsNullOrEmpty(ServerGameState.BiomeIds[i, j]))
						{
							return false;
						}
					}
				}
			}
			int num2 = 0;
			int num3 = 0;
			for (int k = 0; k < width; k += 37)
			{
				for (int l = 0; l < height; l += 37)
				{
					num3++;
					if (ServerGameState.WorldTiles[k, l] == WorldTile.None)
					{
						num2++;
					}
				}
			}
			if (num3 != 0)
			{
				return num2 < num3 / 4;
			}
			return true;
		}

		private static void CopyBiomeIds(int width, int height)
		{
			if (!HasSize(GameState.BiomeIds, width, height) || !HasSize(ServerGameState.BiomeIds, width, height))
			{
				return;
			}
			for (int i = 0; i < width; i++)
			{
				for (int j = 0; j < height; j++)
				{
					GameState.BiomeIds[i, j] = ServerGameState.BiomeIds[i, j];
				}
			}
		}

		private static void RefreshFogOfWar()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			FogOfWarWorldMap fogOfWarWorldMap = ExteriorWorldHandler.FogOfWarWorldMap;
			if (fogOfWarWorldMap != null)
			{
				fogOfWarWorldMap.QueueUpdateWholeMap();
				ChunkedWorld world = fogOfWarWorldMap.World;
				Point val = world.WorldSize * world.TileSize;
				Vector2 val2 = ((Point)(ref val)).ToVector2() * 0.5f;
				int num = Math.Max(world.WorldSize.X, world.WorldSize.Y) * 2;
				fogOfWarWorldMap.Update(val2, num);
			}
		}

		private static void RevealWorldMarkers()
		{
			//IL_001b: 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_005d: 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)
			foreach (DungeonLocationModel value in GameState.DungeonLocations.Values)
			{
				if ((int)value.State == 0)
				{
					value.State = (DungeonState)1;
				}
			}
			foreach (BossLocationModel value2 in GameState.BossLocations.Values)
			{
				if ((int)value2.LocationState == 0)
				{
					value2.LocationState = (BossLocationState)1;
				}
			}
		}

		private static void DeleteCachedWorldMap()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			GameDescription gameDescription = GameState.GameDescription;
			if (gameDescription == null)
			{
				return;
			}
			try
			{
				WorldMapSaveManager.DeleteWorldMap(gameDescription.GameId);
			}
			catch (Exception ex)
			{
				ManualLogSource logger = Worldwright.Logger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(35, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Failed to delete cached world map: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				logger.LogError(val);
			}
		}

		private static bool HasSize<T>(T[,] array, int width, int height)
		{
			if (array != null && array.GetLength(0) == width)
			{
				return array.GetLength(1) == height;
			}
			return false;
		}
	}
	internal static class WorldwrightGenerationState
	{
		private sealed class PresetState
		{
			public ConfigManager.WorldPreset Preset { get; }

			public PresetState(ConfigManager.WorldPreset preset)
			{
				Preset = preset;
			}
		}

		private static readonly ConditionalWeakTable<WorldGenerator, PresetState> Presets = new ConditionalWeakTable<WorldGenerator, PresetState>();

		public static void Set(WorldGenerator generator, ConfigManager.WorldPreset preset)
		{
			if (generator != null)
			{
				Presets.Remove(generator);
				Presets.Add(generator, new PresetState(preset));
			}
		}

		public static bool Is(WorldGenerator generator, ConfigManager.WorldPreset preset)
		{
			if (generator != null && Presets.TryGetValue(generator, out var value))
			{
				return value.Preset == preset;
			}
			return false;
		}

		public static void Clear(WorldGenerator generator)
		{
			if (generator != null)
			{
				Presets.Remove(generator);
			}
		}
	}
	internal static class WorldwrightGenerator
	{
		private sealed class NoisePack
		{
			public float[] Height { get; }

			public float[] Moisture { get; }

			public float[] Heat { get; }

			public float[] Detail { get; }

			public float[] Fine { get; }

			public NoisePack(int width, int height, int seed, float scale)
			{
				//IL_0074: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0128: Unknown result type (might be due to invalid IL or missing references)
				int num = width * height;
				Height = new float[num];
				Moisture = new float[num];
				Heat = new float[num];
				Detail = new float[num];
				Fine = new float[num];
				float num2 = 4096f / (float)width / (430f * scale);
				NoiseHelper val = default(NoiseHelper);
				((NoiseHelper)(ref val))..ctor();
				((NoiseHelper)(ref val)).GenUniformGrid2D(Height.AsSpan(), -48, -48, width, height, num2, seed);
				((NoiseHelper)(ref val)).GenUniformGrid2D(Moisture.AsSpan(), 503, -271, width, height, num2 * 1.3f, seed ^ 0x3F13A95);
				((NoiseHelper)(ref val)).GenUniformGrid2D(Heat.AsSpan(), -719, 331, width, height, num2 * 0.85f, seed ^ 0x57CF341);
				((NoiseHelper)(ref val)).GenUniformGrid2D(Detail.AsSpan(), 139, 941, width, height, num2 * 4.5f, seed ^ 0x6A83B91);
				((NoiseHelper)(ref val)).GenUniformGrid2D(Fine.AsSpan(), -431, 167, width, height, num2 * 9f, seed ^ 0x4B9D2E1);
			}
		}

		private sealed class Biomes
		{
			public BiomeData Plains { get; private set; }

			public BiomeData DryPlains { get; private set; }

			public BiomeData Forest { get; private set; }

			public BiomeData ForestLight { get; private set; }

			public BiomeData ForestDeep { get; private set; }

			public BiomeData Desert { get; private set; }

			public BiomeData Swamp { get; private set; }

			public BiomeData Volcanic { get; private set; }

			public BiomeData VolcanicEdge { get; private set; }

			public BiomeData VolcanicTendril { get; private set; }

			public BiomeData VolcanicTendrilDesert { get; private set; }

			public BiomeData VolcanicTendrilVolcano { get; private set; }

			public BiomeData Mountains { get; private set; }

			public BiomeData Beach { get; private set; }

			public BiomeData Lake { get; private set; }

			public BiomeData LakeSmall { get; private set; }

			public BiomeData Road { get; private set; }

			public BiomeData Flat { get; private set; }

			public static Biomes Load()
			{
				return new Biomes
				{
					Plains = Get("biome:plains"),
					DryPlains = Get("biome:plains_dry"),
					Forest = Get("biome:forest"),
					ForestLight = Get("biome:forest_light"),
					ForestDeep = Get("biome:forest_deep"),
					Desert = Get("biome:desert"),
					Swamp = Get("biome:swamp"),
					Volcanic = Get("biome:volcanic"),
					VolcanicEdge = Get("biome:volcanic_edge"),
					VolcanicTendril = Get("biome:volcanic_tendril"),
					VolcanicTendrilDesert = Get("biome:volcanic_tendril_desert"),
					VolcanicTendrilVolcano = Get("biome:volcanic_tendril_volcano"),
					Mountains = Get("biome:mountains"),
					Beach = Get("biome:beach"),
					Lake = Get("biome:lake"),
					LakeSmall = Get("biome:lake_small"),
					Road = Get("biome:road"),
					Flat = Get("biome:flat")
				};
			}

			private static BiomeData Get(string id)
			{
				return BiomeDataBase.GetBiomeDataOrError(id);
			}
		}

		private sealed class BiomeInfluenceMaps
		{
			private readonly byte[] _water;

			private readonly byte[] _mountains;

			private readonly byte[] _forest;

			private readonly byte[] _desert;

			private readonly byte[] _volcanic;

			private readonly byte[] _swamp;

			private BiomeInfluenceMaps(byte[] water, byte[] mountains, byte[] forest, byte[] desert, byte[] volcanic, byte[] swamp)
			{
				_water = water;
				_mountains = mountains;
				_forest = forest;
				_desert = desert;
				_volcanic = volcanic;
				_swamp = swamp;
			}

			public static BiomeInfluenceMaps Build(WorldGenerator generator, WorldwrightProfile profile)
			{
				int[] queue = new int[generator.Width * generator.Height];
				return new BiomeInfluenceMaps(BuildMap(generator, profile.Water, 0.055f, 42, 220, (string id) => IsSoftWater(id), queue), BuildMap(generator, profile.Mountains, 0.05f, 32, 180, (string id) => IsMountain(id), queue), BuildMap(generator, profile.Forest, 0.07f, 48, 230, (string id) => IsForest(id), queue), BuildMap(generator, profile.Desert, 0.075f, 48, 240, (string id) => IsDesert(id), queue), BuildMap(generator, profile.Volcanic, 0.08f, 48, 240, (string id) => IsVolcanicEdge(id), queue), BuildMap(generator, profile.Swamp, 0.06f, 42, 220, (string id) => id == "biome:swamp", queue));
			}

			public float WaterAt(int index)
			{
				return ValueAt(_water, index);
			}

			public float MountainsAt(int index)
			{
				return ValueAt(_mountains, index);
			}

			public float ForestAt(int index)
			{
				return ValueAt(_forest, index);
			}

			public float DesertAt(int index)
			{
				return ValueAt(_desert, index);
			}

			public float VolcanicAt(int index)
			{
				return ValueAt(_volcanic, index);
			}

			public float SwampAt(int index)
			{
				return ValueAt(_swamp, index);
			}

			private static byte[] BuildMap(WorldGenerator generator, float amount, float widthScale, int minRadius, int maxRadius, Func<string, bool> matches, int[] queue)
			{
				if (amount <= 1.02f)
				{
					return null;
				}
				float num = Clamp01(amount - 1f);
				int num2 = (int)MathF.Round(Math.Clamp((float)generator.Width * widthScale * num, (float)minRadius * num, maxRadius));
				if (num2 <= 0)
				{
					return null;
				}
				byte[] array = new byte[generator.Width * generator.Height];
				int tail = 0;
				int num3 = VanillaBorder(generator.Width);
				for (int i = num3; i < generator.Height - num3; i++)
				{
					for (int j = num3; j < generator.Width - num3; j++)
					{
						int num4 = j + i * generator.Width;
						if (matches(generator.Biomes[num4]?.Id))
						{
							array[num4] = byte.MaxValue;
							queue[tail++] = num4;
						}
					}
				}
				if (tail == 0)
				{
					return array;
				}
				int num5 = Math.Max(1, 255 / num2);
				for (int k = 0; k < tail; k++)
				{
					int num6 = queue[k];
					byte b = array[num6];
					if (b > num5)
					{
						byte value = (byte)(b - num5);
						int num7 = num6 % generator.Width;
						int num8 = num6 / generator.Width;
						TrySpread(generator, array, queue, ref tail, num7 - 1, num8, value, num3);
						TrySpread(generator, array, queue, ref tail, num7 + 1, num8, value, num3);
						TrySpread(generator, array, queue, ref tail, num7, num8 - 1, value, num3);
						TrySpread(generator, array, queue, ref tail, num7, num8 + 1, value, num3);
					}
				}
				return array;
			}

			private static void TrySpread(WorldGenerator generator, byte[] map, int[] queue, ref int tail, int x, int y, byte value, int border)
			{
				if (x >= border && y >= border && x < generator.Width - border && y < generator.Height - border)
				{
					int num = x + y * generator.Width;
					if (value > map[num])
					{
						map[num] = value;
						queue[tail++] = num;
					}
				}
			}

			private static float ValueAt(byte[] map, int index)
			{
				if (map != null)
				{
					return (float)(int)map[index] / 255f;
				}
				return 0f;
			}
		}

		private sealed class Island
		{
			public int Count;

			public long SumX;

			public long SumY;

			public int StartX;

			public int StartY;

			public Vector2 Center => new Vector2((float)SumX / (float)Math.Max(1, Count), (float)SumY / (float)Math.Max(1, Count));

			public void Add(int x, int y)
			{
				if (Count == 0)
				{
					StartX = x;
					StartY = y;
				}
				Count++;
				SumX += x;
				SumY += y;
			}
		}

		private const string Plains = "biome:plains";

		private const string DryPlains = "biome:plains_dry";

		private const string Forest = "biome:forest";

		private const string ForestLight = "biome:forest_light";

		private const string ForestDeep = "biome:forest_deep";

		private const string Desert = "biome:desert";

		private const string DesertEdge = "biome:desert_edge";

		private const string Swamp = "biome:swamp";

		private const string Volcanic = "biome:volcanic";

		private const string VolcanicCenter = "biome:volcanic_center";

		private const string VolcanicEdge = "biome:volcanic_edge";

		private const string VolcanicTendril = "biome:volcanic_tendril";

		private const string VolcanicTendrilDesert = "biome:volcanic_tendril_desert";

		private const string VolcanicTendrilVolcano = "biome:volcanic_tendril_volcano";

		private const string Mountains = "biome:mountains";

		private const string Beach = "biome:beach";

		private const string Lake = "biome:lake";

		private const string LakeSmall = "biome:lake_small";

		private const string LakeIsland = "biome:lake_island";

		private const string Ocean = "biome:ocean";

		private const string Road = "biome:road";

		private const string River = "biome:river";

		private const string Flat = "biome:flat";

		public static void Generate(WorldGenerator generator, GameConfig config)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			WorldwrightProfile worldwrightProfile = WorldwrightWorldOptions.Get(config).ForGeneration();
			WorldwrightGenerationState.Set(generator, worldwrightProfile.Preset);
			Point worldSize = config.WorldSize;
			int x = worldSize.X;
			int y = worldSize.Y;
			int num = x * y;
			generator.Size = worldSize;
			generator.Width = x;
			generator.Height = y;
			generator.Seed = config.WorldSeed;
			generator.Random = new Random(config.WorldSeed);
			generator.TileToWorldScale = 1f / (float)x;
			generator.Biomes = (BiomeData[])(object)new BiomeData[num];
			generator.Difficulty = new float[num];
			generator.Colors = (Color[])(object)new Color[num];
			generator.Humidity = (Color[])(object)new Color[num];
			generator.Terrain = (Color[])(object)new Color[num];
			generator.DifficultyColorMap = (Color[])(object)new Color[num];
			generator.TerrainValues = new float[num];
			generator.HumidityValues = new float[num];
			generator.HumidityValues2 = new float[num];
			GenerateSuperflat(generator, Biomes.Load());
			BuildDebugMaps(generator);
			LogBiomeSummary(generator, worldwrightProfile);
		}

		private static bool IsProtectedBorder(WorldGenerator generator, int x, int y)
		{
			int num = VanillaBorder(generator.Width);
			if (y >= num && x >= num && x < generator.Width - num)
			{
				return y >= generator.Height - num;
			}
			return true;
		}

		private static bool IsNearPoint(Vector2 point, int x, int y, float radius)
		{
			//IL_0000: 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_0009: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			if (point == default(Vector2))
			{
				return false;
			}
			float num = point.X - (float)x;
			float num2 = point.Y - (float)y;
			return num * num + num2 * num2 <= radius * radius;
		}

		private static bool IsMountain(string id)
		{
			return id == "biome:mountains";
		}

		private static bool IsForest(string id)
		{
			if (!(id == "biome:forest") && !(id == "biome:forest_deep"))
			{
				return id == "biome:forest_light";
			}
			return true;
		}

		private static bool IsDesert(string id)
		{
			if (!(id == "biome:desert"))
			{
				return id == "biome:desert_edge";
			}
			return true;
		}

		private static bool IsSoftWater(string id)
		{
			switch (id)
			{
			default:
				return id == "biome:river";
			case "biome:lake":
			case "biome:lake_small":
			case "biome:lake_island":
				return true;
			}
		}

		private static bool IsVolcanicEdge(string id)
		{
			switch (id)
			{
			default:
				return id == "biome:volcanic_tendril_volcano";
			case "biome:volcanic":
			case "biome:volcanic_center":
			case "biome:volcanic_edge":
			case "biome:volcanic_tendril":
			case "biome:volcanic_tendril_desert":
				return true;
			}
		}

		private static float Distance01(WorldGenerator generator, Vector2 point)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)generator.Width * 0.5f, (float)generator.Height * 0.5f);
			float num = MathF.Sqrt(generator.Width * generator.Width + generator.Height * generator.Height) * 0.5f;
			return Clamp01(Vector2.Distance(point, val) / num);
		}

		private static float Inland01(WorldGenerator generator, int x, int y)
		{
			int num = VanillaBorder(generator.Width);
			return Clamp01((float)(Math.Min(Math.Min(x, generator.Width - 1 - x), Math.Min(y, generator.Height - 1 - y)) - num) / ((float)generator.Width * 0.16f));
		}

		private static float VolcanicScore(WorldGenerator generator, int x, int y, float terrain, float heat)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			if (generator.VolcanoCenterTile == default(Vector2))
			{
				return 0f;
			}
			float num = (float)x - generator.VolcanoCenterTile.X;
			float num2 = (float)y - generator.VolcanoCenterTile.Y;
			float num3 = MathF.Sqrt(num * num + num2 * num2);
			float num4 = MathF.Atan2(num2, num);
			float num5 = (float)generator.Seed * 0.00061f;
			float num6 = MathF.Sin(num4 * 5f + num5) * 0.1f + MathF.Sin(num4 * 9f - num5 * 1.7f + num3 * 0.012f) * 0.075f + MathF.Sin(((float)x * 0.021f + (float)y * 0.017f + num5) * (float)Math.PI) * 0.04f;
			float val = (float)generator.Width * (0.48f + num6);
			float num7 = num3 / Math.Max(1f, val);
			return Clamp01((1f - num7) * 0.9f + terrain * 0.07f + heat * 0.08f);
		}

		private static float VolcanicTendrilScore(WorldGenerator generator, int x, int y, float detail, float heat)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			if (generator.VolcanoCenterTile == default(Vector2))
			{
				return 0f;
			}
			float num = (float)x - generator.VolcanoCenterTile.X;
			float num2 = (float)y - generator.VolcanoCenterTile.Y;
			float num3 = MathF.Sqrt(num * num + num2 * num2);
			float num4 = (float)generator.Width * 0.48f;
			if (num3 < (float)generator.Width * 0.06f || num3 > num4)
			{
				return 0f;
			}
			float num5 = MathF.Atan2(num2, num);
			float num6 = (float)generator.Seed * 0.00073f;
			float num7 = 15f;
			float num8 = num5 / ((float)Math.PI * 2f) * num7 + num6 + MathF.Sin(num3 * 0.018f + num6) * 0.42f;
			float num9 = Math.Abs(num8 - MathF.Round(num8));
			float num10 = 0.09f + detail * 0.065f;
			float value = 1f - Math.Abs(num3 / num4 - 0.56f) / 0.56f;
			return Clamp01((num10 - num9) / num10) * Clamp01(value) * (0.86f + heat * 0.14f);
		}

		private static BiomeData FlatFallback(Biomes biomes, WorldwrightProfile profile, float humidity, float heat)
		{
			if (!(heat > 0.7f) || !(humidity < 0.4f))
			{
				return biomes.Plains;
			}
			return biomes.DryPlains;
		}

		private static BiomeData NaturalFallback(Biomes biomes, WorldwrightProfile profile, float humidity, float heat)
		{
			if (heat > 0.68f && humidity < 0.42f)
			{
				return biomes.DryPlains;
			}
			if (!(profile.Forest > 0.001f) || !(humidity > 0.72f))
			{
				return biomes.Plains;
			}
			return biomes.ForestLight;
		}

		private static BiomeData WaterWorldFallback(Biomes biomes, WorldwrightProfile profile, float terrain, float humidity, float detail)
		{
			if (profile.Swamp > 0.001f && humidity > 0.84f && terrain > 0.34f && detail > 0.42f)
			{
				return biomes.Swamp;
			}
			if (terrain > 0.62f && detail > 0.55f)
			{
				return biomes.Beach;
			}
			if (!(detail > 0.62f))
			{
				return biomes.LakeSmall;
			}
			return biomes.Lake;
		}

		private static BiomeData MountainValleyFallback(Biomes biomes, WorldwrightProfile profile, float humidity, float heat)
		{
			if (!(heat > 0.66f) || !(humidity < 0.42f))
			{
				return biomes.Plains;
			}
			return biomes.DryPlains;
		}

		private static float MountainPassScore(WorldGenerator generator, int x, int y, float detail, float humidity, float heat)
		{
			float num = (float)x / Math.Max(1f, (float)generator.Width - 1f);
			float num2 = (float)y / Math.Max(1f, (float)generator.Height - 1f);
			float num3 = (float)generator.Seed * 0.00091f;
			float num4 = (float)Math.PI * 2f;
			float val = Math.Abs(num - num2 + (detail - 0.5f) * 0.2f + MathF.Sin((num * 2.4f + num3) * num4) * 0.025f);
			float val2 = Math.Abs(num + num2 - 1f + (humidity - 0.5f) * 0.18f + MathF.Cos((num2 * 2.1f + num3) * num4) * 0.025f);
			float val3 = Math.Abs(num2 - (0.52f + MathF.Sin((num * 2.8f + num3) * num4) * 0.08f + (detail - 0.5f) * 0.04f));
			return Math.Min(val2: Math.Min(val3, Math.Abs(num - (0.48f + MathF.Cos((num2 * 2.2f + num3) * num4) * 0.08f + (heat - 0.5f) * 0.04f))), val1: Math.Min(val, val2));
		}

		private static float Normalized(float value)
		{
			return Math.Clamp(value * 0.5f + 0.5f, 0f, 1f);
		}

		private static void BuildDebugMaps(WorldGenerator generator)
		{
			//IL_0013: 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)
			for (int i = 0; i < generator.Difficulty.Length; i++)
			{
				generator.DifficultyColorMap[i] = DifficultyColor(generator.Difficulty[i]);
			}
		}

		private static void LogBiomeSummary(WorldGenerator generator, WorldwrightProfile profile)
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			for (int i = 0; i < generator.Biomes.Length; i++)
			{
				string text = generator.Biomes[i]?.Id;
				if (IsMountain(text))
				{
					num++;
				}
				else if (text == "biome:swamp")
				{
					num6++;
				}
				else if (IsSoftWater(text))
				{
					num2++;
				}
				else if (IsDesert(text))
				{
					num3++;
				}
				else if (IsVolcanicEdge(text) || text == "biome:volcanic_center")
				{
					num4++;
				}
				else if (IsForest(text))
				{
					num5++;
				}
			}
			float total = Math.Max(1f, generator.Biomes.Length);
			ManualLogSource logger = Worldwright.Logger;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(70, 7, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Worldwright ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ConfigManager.WorldPreset>(profile.Preset);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": water ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Percent(num2, total));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", mountains ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Percent(num, total));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", forest ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Percent(num5, total));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", desert ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Percent(num3, total));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", volcanic ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Percent(num4, total));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", swamp ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Percent(num6, total));
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
			}
			logger.LogInfo(val);
		}

		private static string Percent(int count, float total)
		{
			return $"{(float)count * 100f / total:0.0}%";
		}

		private static Color DifficultyColor(float difficulty)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_008b: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if (difficulty < 1f)
			{
				return new Color(0f, 0f, 1f);
			}
			if (difficulty < 2f)
			{
				return new Color(0f, 0.5f, 0.5f);
			}
			if (difficulty < 3f)
			{
				return new Color(0.1f, 0.9f, 0.3f);
			}
			if (difficulty < 4f)
			{
				return new Color(0.2f, 0.8f, 0.2f);
			}
			if (difficulty < 5f)
			{
				return new Color(0.4f, 0.6f, 0.15f);
			}
			if (difficulty < 6f)
			{
				return new Color(0.5f, 0.4f, 0.1f);
			}
			if (difficulty < 7f)
			{
				return new Color(0.6f, 0.2f, 0.1f);
			}
			if (difficulty < 8f)
			{
				return new Color(0.7f, 0.1f, 0.05f);
			}
			return new Color(0.9f, 0.5f, 0.5f);
		}

		private static int VanillaBorder(int width)
		{
			return Math.Min(30, Math.Max(0, width / 2 - 1));
		}

		private static float Clamp01(float value)
		{
			return Math.Clamp(value, 0f, 1f);
		}

		public static void ApplyVanillaPostProcess(WorldGenerator generator, GameConfig config)
		{
			WorldwrightProfile worldwrightProfile = WorldwrightWorldOptions.Get(config).ForGeneration();
			if (worldwrightProfile.Preset == ConfigManager.WorldPreset.Superflat || !HasBaseMap(generator) || IsVanillaEquivalent(worldwrightProfile))
			{
				return;
			}
			Biomes biomes = Biomes.Load();
			NoisePack noise = new NoisePack(generator.Width, generator.Height, config.WorldSeed, worldwrightProfile.BiomeScale);
			BiomeInfluenceMaps influence = BiomeInfluenceMaps.Build(generator, worldwrightProfile);
			ClearDisabledKeyPoints(generator, worldwrightProfile);
			for (int i = 0; i < generator.Height; i++)
			{
				for (int j = 0; j < generator.Width; j++)
				{
					int num = j + i * generator.Width;
					BiomeData val = generator.Biomes[num];
					if (val != null && !IsProtectedBorder(generator, j, i))
					{
						BiomeData val2 = ChooseVanillaPostBiome(generator, biomes, worldwrightProfile, noise, influence, j, i, num, val);
						if (val2 != val)
						{
							SetPostBiome(generator, num, val2, worldwrightProfile, noise, j, i);
						}
					}
				}
			}
			GenerateWaterWorldRoads(generator, biomes, worldwrightProfile, config);
			BuildDebugMaps(generator);
			LogBiomeSummary(generator, worldwrightProfile);
		}

		private static BiomeData ChooseVanillaPostBiome(WorldGenerator generator, Biomes biomes, WorldwrightProfile profile, NoisePack noise, BiomeInfluenceMaps influence, int x, int y, int index, BiomeData current)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: 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)
			string id = current.Id;
			float num = Normalized(noise.Height[index]);
			float num2 = Normalized(noise.Moisture[index] - noise.Heat[index] * 0.25f);
			float num3 = Normalized(noise.Detail[index]);
			float fine = Normalized(noise.Fine[index]);
			float num4 = Normalized(noise.Heat[index]);
			float num5 = Distance01(generator, new Vector2((float)x, (float)y));
			float num6 = Inland01(generator, x, y);
			if (profile.Preset == ConfigManager.WorldPreset.Flattened)
			{
				BiomeData val = ChooseFlattenedPresetBiome(biomes, profile, num2, num4, current);
				if (val != null)
				{
					return val;
				}
			}
			if (!profile.Roads && id == "biome:road")
			{
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (!profile.Rivers && id == "biome:river")
			{
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (CanReduce(profile.Mountains, num3) && IsMountain(id))
			{
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (CanReduce(profile.Forest, num3) && IsForest(id))
			{
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (CanReduce(profile.Swamp, num3) && id == "biome:swamp")
			{
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (CanReduce(profile.Water, num3) && IsSoftWater(id))
			{
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (CanReduce(profile.Desert, num3) && IsDesert(id) && !KeepsKeyBiomeCenter(profile, profile.Desert, generator.DesertCenterTile, x, y, (float)generator.Width * 0.1f))
			{
				if (profile.Preset == ConfigManager.WorldPreset.WaterWorld)
				{
					return WaterWorldFallback(biomes, profile, num, num2, num3);
				}
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (CanReduce(profile.Volcanic, num3) && IsVolcanicEdge(id) && !KeepsKeyBiomeCenter(profile, profile.Volcanic, generator.VolcanoCenterTile, x, y, (float)generator.Width * 0.09f))
			{
				if (profile.Preset == ConfigManager.WorldPreset.WaterWorld)
				{
					return WaterWorldFallback(biomes, profile, num, num2, num3);
				}
				return NaturalFallback(biomes, profile, num2, num4);
			}
			if (!CanReplaceWithExtraBiome(id))
			{
				return current;
			}
			float mountainScore = num * 0.62f + num3 * 0.28f + num6 * 0.12f - (1f - num5) * 0.18f;
			float waterScore = (1f - num) * 0.6f + num2 * 0.32f + num3 * 0.08f - num5 * 0.08f;
			float desertScore = num4 * 0.68f + (1f - num2) * 0.32f + num5 * 0.06f;
			float swampScore = num2 * 0.7f + (1f - num) * 0.22f + num3 * 0.08f;
			float forestScore = num2 * 0.55f + num3 * 0.25f + num * 0.2f;
			BiomeData val2 = ChoosePresetBiome(generator, biomes, profile, x, y, index, num, num2, num3, fine, num4, num5, num6, current);
			if (val2 != null)
			{
				return val2;
			}
			return ChooseExtraBiome(generator, biomes, profile, influence, x, y, index, num, num2, num3, fine, num4, mountainScore, waterScore, desertScore, swampScore, forestScore, current) ?? current;
		}

		private static BiomeData ChooseExtraBiome(WorldGenerator generator, Biomes biomes, WorldwrightProfile profile, BiomeInfluenceMaps influence, int x, int y, int index, float terrain, float humidity, float detail, float fine, float heat, float mountainScore, float waterScore, float desertScore, float swampScore, float forestScore, BiomeData current)
		{
			BiomeData best = null;
			float bestScore = 0f;
			float num = MountainPassScore(generator, x, y, detail, humidity, heat);
			float num2 = (detail - 0.5f) * 0.13f + (fine - 0.5f) * 0.1f;
			if (num > 0.105f)
			{
				TryInfluencedCandidate(profile.Mountains, influence.MountainsAt(index), mountainScore + num2, 1.06f, biomes.Mountains, ref best, ref bestScore);
			}
			if (terrain < 0.64f || IsSoftWater(current.Id))
			{
				BiomeData biome = ((detail > 0.66f && terrain < 0.42f) ? biomes.Lake : biomes.LakeSmall);
				TryInfluencedCandidate(profile.Water, influence.WaterAt(index), waterScore + num2 + ((terrain < 0.42f) ? 0.04f : (-0.08f)), 0.86f, biome, ref best, ref bestScore);
			}
			if (humidity > 0.58f && terrain < 0.72f)
			{
				TryInfluencedCandidate(profile.Swamp, influence.SwampAt(index), swampScore + num2 + (humidity - 0.58f) * 0.15f - heat * 0.06f, 0.82f, biomes.Swamp, ref best, ref bestScore);
			}
			if (profile.Desert > 1.5f || generator.Difficulty[index] > 1.25f || (heat > 0.72f && humidity < 0.28f))
			{
				BiomeData biome2 = ((humidity < 0.32f && heat > 0.58f) ? biomes.Desert : biomes.DryPlains);
				TryInfluencedCandidate(profile.Desert, influence.DesertAt(index), desertScore + num2 + ((humidity < 0.34f) ? 0.05f : (-0.05f)), 1f, biome2, ref best, ref bestScore);
			}
			float num3 = VolcanicScore(generator, x, y, terrain, heat);
			float num4 = VolcanicTendrilScore(generator, x, y, detail, heat);
			float num5 = Math.Max(influence.VolcanicAt(index), influence.VolcanicAt(index) * num3);
			if (num3 > 0.16f && num5 > 0f)
			{
				BiomeData biome3 = ((num5 > 0.58f) ? ChooseVolcanicBodyBiome(generator, biomes, profile, x, y) : biomes.VolcanicEdge);
				TryInfluencedCandidate(profile.Volcanic, num5, num3 + num2 + detail * 0.1f + heat * 0.08f, 1.42f, biome3, ref best, ref bestScore);
			}
			if (num4 > 0.08f && num5 > 0f)
			{
				BiomeData biome4 = ChooseVolcanicTendrilBiome(biomes, current);
				TryInfluencedCandidate(profile.Volcanic, num5, num4 + num2 + num3 * 0.16f + heat * 0.04f, 1.12f, biome4, ref best, ref bestScore);
			}
			float num6 = influence.ForestAt(index);
			if (num6 > 0f && humidity > 0.58f && num > 0.055f)
			{
				BiomeData biome5 = ChooseForestExpansionBiome(biomes, profile, current, num6, humidity, detail, num);
				float num7 = ((num < 0.12f) ? ((0.12f - num) * 1.8f) : 0f);
				TryInfluencedCandidate(profile.Forest, num6 * 0.72f, forestScore + num2 + ((humidity > 0.62f) ? 0.02f : (-0.1f)) - num7, 0.78f, biome5, ref best, ref bestScore);
			}
			return best;
		}

		private static void TryInfluencedCandidate(float amount, float influence, float selector, float weight, BiomeData biome, ref BiomeData best, ref float bestScore)
		{
			if (amount <= 1.02f || influence <= 0f)
			{
				return;
			}
			float num = Clamp01((amount - 1f) / Math.Max(0.001f, 1f));
			float num2 = 0.58f - num * 0.34f;
			float num3 = influence * (0.78f + num * 0.18f) + selector * 0.24f;
			if (!(num3 <= num2))
			{
				num3 = (num3 - num2) / Math.Max(0.001f, 1f - num2);
				num3 *= weight;
				if (!(num3 <= bestScore))
				{
					best = biome;
					bestScore = num3;
				}
			}
		}

		private static BiomeData ChoosePresetBiome(WorldGenerator generator, Biomes biomes, WorldwrightProfile profile, int x, int y, int index, float terrain, float humidity, float detail, float fine, float heat, float centerDistance, float inland, BiomeData current)
		{
			return (BiomeData)(profile.Preset switch
			{
				ConfigManager.WorldPreset.Balanced => ChooseBalancedPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.Superflat => ChooseSuperflatPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.Flattened => ChooseFlattenedPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.Mountainous => ChooseMountainousPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.WaterWorld => ChooseWaterWorldPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.Drylands => ChooseDrylandsPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.Volcanic => ChooseVolcanicPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				ConfigManager.WorldPreset.Forest => ChooseForestPresetBiome(generator, biomes, profile, x, y, index, terrain, humidity, detail, fine, heat, centerDistance, inland, current), 
				_ => null, 
			});
		}

		private static void SetPostBiome(WorldGenerator generator, int index, BiomeData biome, WorldwrightProfile profile, NoisePack noise, int x, int y)
		{
			//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_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			generator.Biomes[index] = biome;
			generator.Colors[index] = biome.Color;
			float num = generator.TerrainValues[index];
			float num2 = generator.HumidityValues[index];
			float detail = Normalized(noise.Detail[index]);
			float heat = Normalized(noise.Heat[index]);
			switch (biome.Id)
			{
			case "biome:mountains":
				generator.Difficulty[index] = Math.Max(generator.Difficulty[index], 3.5f);
				break;
			case "biome:desert_edge":
			case "biome:desert":
				generator.Difficulty[index] = Math.Max(generator.Difficulty[index], 3f);
				break;
			case "biome:volcanic":
			case "biome:volcanic_edge":
			case "biome:volcanic_center":
				generator.Difficulty[index] = Math.Max(generator.Difficulty[index], 5f);
				break;
			case "biome:volcanic_tendril":
			case "biome:volcanic_tendril_desert":
			case "biome:volcanic_tendril_volcano":
				generator.Difficulty[index] = Math.Max(generator.Difficulty[index], 5f);
				num = VolcanicTendrilTerrain(generator, x, y, detail, heat);
				break;
			case "biome:lake_island":
			case "biome:river":
			case "biome:lake":
			case "biome:lake_small":
				generator.Difficulty[index] = Math.Min(generator.Difficulty[index], 1.5f);
				break;
			case "biome:swamp":
				generator.Difficulty[index] = Math.Min(generator.Difficulty[index], 4.5f);
				break;
			}
			if (profile.Preset == ConfigManager.WorldPreset.Flattened)
			{
				generator.Difficulty[index] = Math.Min(generator.Difficulty[index], 5.5f);
			}
			generator.TerrainValues[index] = num;
			generator.HumidityValues[index] = num2;
			generator.Terrain[index] = new Color(num, num, num);
		}

		private static bool HasBaseMap(WorldGenerator generator)
		{
			int num = generator.Width * generator.Height;
			if (generator.Width > 0 && generator.Height > 0 && generator.Biomes != null && generator.Biomes.Length == num && generator.Difficulty != null && generator.Difficulty.Length == num && generator.Colors != null)
			{
				return generator.Colors.Length == num;
			}
			return false;
		}

		private static void ClearDisabledKeyPoints(WorldGenerator generator, WorldwrightProfile profile)
		{
			//IL_0013: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			if (IsDisabled(profile.Desert))
			{
				generator.DesertCenterTile = default(Vector2);
				generator.RoadHitDesertWallPoint = default(Point);
			}
			if (IsDisabled(profile.Volcanic))
			{
				generator.VolcanoCenterTile = default(Vector2);
			}
		}

		private static bool CanReduce(float amount, float selector)
		{
			if (!IsDisabled(amount))
			{
				if (amount < 0.98f)
				{
					return selector > amount;
				}
				return false;
			}
			return true;
		}

		private static bool CanAdd(float amount, float maxCoverage, float selector)
		{
			if (amount <= 1.02f)
			{
				return false;
			}
			return selector > 1f - (amount - 1f) * maxCoverage;
		}

		private static BiomeData ChooseVolcanicTendrilBiome(Biomes biomes, BiomeData current)
		{
			if (IsVolcanicEdge(current.Id))
			{
				return biomes.VolcanicTendrilVolcano;
			}
			if (!IsDesert(current.Id))
			{
				return biomes.VolcanicTendril;
			}
			return biomes.VolcanicTendrilDesert;
		}

		private static BiomeData ChooseVolcanicBodyBiome(WorldGenerator generator, Biomes biomes, WorldwrightProfile profile, int x, int y)
		{
			if (!(VolcanoDistance01(generator, x, y) <= VolcanicCoreRadius(profile)))
			{
				return biomes.VolcanicEdge;
			}
			return biomes.Volcanic;
		}

		private static float VolcanicCoreRadius(WorldwrightProfile profile)
		{
			return ((profile.Preset == ConfigManager.WorldPreset.Volcanic) ? 0.14f : 0.115f) + Clamp01(profile.Volcanic - 1f) * 0.015f;
		}

		private static float VolcanoDistance01(WorldGenerator generator, int x, int y)
		{
			//IL_0001: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (generator.VolcanoCenterTile == default(Vector2))
			{
				return float.MaxValue;
			}
			return Vector2.Distance(generator.VolcanoCenterTile, new Vector2((float)x, (float)y)) / Math.Max(1f, generator.Width);
		}

		private static float VolcanicTendrilTerrain(WorldGenerator generator, int x, int y, float detail, float heat)
		{
			float num = VolcanicTendrilScore(generator, x, y, detail, heat);
			return -10f + Math.Clamp(0.08f + (1f - num) * 0.38f, 0.06f, 0.46f);
		}

		private static bool IsDisabled(float amount)
		{
			return amount <= 0.001f;
		}

		private static bool IsVanillaEquivalent(WorldwrightProfile profile)
		{
			if (profile.Preset == ConfigManager.WorldPreset.Balanced && Approximately(profile.BiomeScale, 1f) && Approximately(profile.Water, 1f) && Approximately(profile.Mountains, 1f) && Approximately(profile.Forest, 1f) && Approximately(profile.Desert, 1f) && Approximately(profile.Volcanic, 1f) && Approximately(profile.Swamp, 1f) && profile.Rivers)
			{
				return profile.Roads;
			}
			return false;
		}

		private static bool Approximately(float left, float right)
		{
			return Math.Abs(left - right) < 0.001f;
		}

		private static bool CanReplaceWithExtraBiome(string id)
		{
			switch (id)
			{
			default:
				return id == "biome:volcanic_tendril_volcano";
			case "biome:plains":
			case "biome:plains_dry":
			case "biome:forest_light":
			case "biome:forest":
			case "biome:forest_deep":
			case "biome:mountains":
			case "biome:desert":
			case "biome:desert_edge":
			case "biome:swamp":
			case "biome:lake":
			case "biome:lake_small":
			case "biome:lake_island":
			case "biome:volcanic":
			case "biome:volcanic_edge":
			case "biome:volcanic_tendril":
			case "biome:volcanic_tendril_desert":
				return true;
			}
		}

		private static BiomeData ChooseBalancedPresetBiome(WorldGenerator generator, Biomes biomes, WorldwrightProfile profile, int x, int y, int index, float terrain, float humidity, float detail, float fine, float heat, float centerDistance, float inland, BiomeData current)
		{
			return null;
		}

		private static BiomeData ChooseDrylandsPresetBiome(WorldGenerator generator, Biomes biomes, WorldwrightProfile profile, int x, int y, int index, float terrain, float humidity, float detail, float fine, float heat, float centerDistance, float inland, BiomeData current)
		{
			float num = heat * 0.4f + (1f - humidity) * 0.4f + centerDistance * 0.1f + detail * 0.06f + fine * 0.04f;
			if (CanAdd(profile.Desert, 0.78f, num) && (profile.Desert > 1.5f || generator.Difficulty[index] > 1.1f))
			{
				return biomes.Desert;
			}
			if (num > 0.32f || (IsForest(current.Id) && humidity < 0.62f) || (IsSoftWater(current.Id) && num > 0.4f))
			{
				return biomes.DryPlains;
			}
			return null;
		}

		private static void OpenDrylandsPresetTiles(WorldGenerator generator, GameConfig config, WorldwrightProfile profile, WorldTile[,] tiles)
		{
			//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_0042: 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_00c2: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Invalid comparison between Unknown and I4
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			NoisePack noisePack = new NoisePack(generator.Width, generator.Height, config.WorldSeed, profile.BiomeScale);
			int num = VanillaBorder(generator.Width);
			for (int i = num; i < generator.Height - num; i++)
			{
				for (int j = num; j < generator.Width - num; j++)
				{
					WorldTile val = tiles[j, i];
					if (!IsDrylandsBlockingStructure(val.Structure))
					{
						continue;
					}
					int num2 = j + i * generator.Width;
					float detail = Normalized(noisePack.Detail[num2]);
					float humidity = Normalized(noisePack.Moisture[num2] - noisePack.Heat[num2] *